|
13 | 13 | import fi.helsinki.cs.tmc.ui.PastebinDialog;
|
14 | 14 | import fi.helsinki.cs.tmc.ui.PastebinResponseDialog;
|
15 | 15 | 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; |
16 | 19 | import java.awt.event.ActionEvent;
|
17 | 20 | import java.awt.event.ActionListener;
|
18 | 21 | import java.net.URI;
|
19 | 22 | import java.util.List;
|
| 23 | +import java.util.concurrent.Callable; |
20 | 24 | import java.util.logging.Level;
|
21 | 25 | import java.util.logging.Logger;
|
22 | 26 | import org.netbeans.api.project.Project;
|
@@ -47,7 +51,7 @@ public final class PastebinAction extends AbstractExerciseSensitiveAction {
|
47 | 51 | private NbTmcSettings settings;
|
48 | 52 | private CourseDb courseDb;
|
49 | 53 | private ProjectMediator projectMediator;
|
50 |
| - private ConvenientDialogDisplayer dialogs; |
| 54 | + private final ConvenientDialogDisplayer dialogs; |
51 | 55 |
|
52 | 56 | public PastebinAction() {
|
53 | 57 | this.settings = NbTmcSettings.getDefault();
|
@@ -107,24 +111,37 @@ private void submitPaste(final TmcProjectInfo projectInfo, final Exercise exerci
|
107 | 111 | final String messageForReviewer) {
|
108 | 112 | projectMediator.saveAllFiles();
|
109 | 113 | 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()); |
116 | 129 | }
|
117 | 130 |
|
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 | + } |
119 | 137 |
|
120 | 138 | @Override
|
121 |
| - public void onSuccess(URI ur) { |
122 |
| - new PastebinResponseDialog(ur.toString()).setVisible(true); |
| 139 | + public void bgTaskCancelled() { |
123 | 140 | }
|
124 | 141 |
|
125 | 142 | @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); |
128 | 145 | }
|
129 | 146 | }
|
130 | 147 |
|
|
0 commit comments