Skip to content

Commit f5bf0c5

Browse files
committed
Paste uses tmc-core
1 parent b967a63 commit f5bf0c5

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

tmc-plugin/src/fi/helsinki/cs/tmc/actions/PastebinAction.java

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
import fi.helsinki.cs.tmc.ui.PastebinDialog;
1414
import fi.helsinki.cs.tmc.ui.PastebinResponseDialog;
1515
import fi.helsinki.cs.tmc.core.exceptions.TmcCoreException;
16+
import fi.helsinki.cs.tmc.utilities.BgTask;
17+
import fi.helsinki.cs.tmc.utilities.BgTaskListener;
18+
import fi.helsinki.cs.tmc.utilities.CancellableCallable;
1619
import java.awt.event.ActionEvent;
1720
import java.awt.event.ActionListener;
1821
import java.net.URI;
1922
import java.util.List;
23+
import java.util.concurrent.Callable;
2024
import java.util.logging.Level;
2125
import java.util.logging.Logger;
2226
import org.netbeans.api.project.Project;
@@ -47,7 +51,7 @@ public final class PastebinAction extends AbstractExerciseSensitiveAction {
4751
private NbTmcSettings settings;
4852
private CourseDb courseDb;
4953
private ProjectMediator projectMediator;
50-
private ConvenientDialogDisplayer dialogs;
54+
private final ConvenientDialogDisplayer dialogs;
5155

5256
public PastebinAction() {
5357
this.settings = NbTmcSettings.getDefault();
@@ -107,24 +111,37 @@ private void submitPaste(final TmcProjectInfo projectInfo, final Exercise exerci
107111
final String messageForReviewer) {
108112
projectMediator.saveAllFiles();
109113
final String errorMsgLocale = settings.getErrorMsgLocale().toString();
110-
try {
111-
ListenableFuture<URI> result = TmcCoreSingleton.getInstance().pasteWithComment(projectInfo.getProjectDirAsPath(), messageForReviewer);
112-
Futures.addCallback(result, new PasteResult());
113-
} catch (TmcCoreException ex) {
114-
Exceptions.printStackTrace(ex);
115-
}
114+
BgTask.start("Sending tmc-paste", new CancellableCallable<URI>() {
115+
ListenableFuture<URI> result;
116+
117+
@Override
118+
public URI call() throws Exception {
119+
log.log(Level.INFO, "Pre submit");
120+
result = TmcCoreSingleton.getInstance().pasteWithComment(projectInfo.getProjectDirAsPath(), messageForReviewer);
121+
return result.get();
122+
}
123+
124+
@Override
125+
public boolean cancel() {
126+
return result.cancel(true);
127+
}
128+
}, new PasteResult());
116129
}
117130

118-
class PasteResult implements FutureCallback<URI> {
131+
class PasteResult implements BgTaskListener<URI> {
132+
133+
@Override
134+
public void bgTaskReady(URI uri) {
135+
new PastebinResponseDialog(uri.toString()).setVisible(true);
136+
}
119137

120138
@Override
121-
public void onSuccess(URI ur) {
122-
new PastebinResponseDialog(ur.toString()).setVisible(true);
139+
public void bgTaskCancelled() {
123140
}
124141

125142
@Override
126-
public void onFailure(Throwable thrwbl) {
127-
dialogs.displayError("Failed to send exercise to pastebin", thrwbl);
143+
public void bgTaskFailed(Throwable ex) {
144+
dialogs.displayError("Failed to send exercise to pastebin", ex);
128145
}
129146
}
130147

0 commit comments

Comments
 (0)