1
1
package fi .helsinki .cs .tmc .actions ;
2
2
3
+ import com .google .common .util .concurrent .FutureCallback ;
4
+ import com .google .common .util .concurrent .Futures ;
5
+ import com .google .common .util .concurrent .ListenableFuture ;
3
6
import hy .tmc .core .domain .Exercise ;
4
7
import fi .helsinki .cs .tmc .model .CourseDb ;
5
8
import fi .helsinki .cs .tmc .model .ProjectMediator ;
6
9
import fi .helsinki .cs .tmc .model .ServerAccess ;
7
10
import fi .helsinki .cs .tmc .model .TmcProjectInfo ;
8
11
import fi .helsinki .cs .tmc .model .NBTmcSettings ;
12
+ import fi .helsinki .cs .tmc .model .TmcCoreSingleton ;
9
13
import fi .helsinki .cs .tmc .ui .ConvenientDialogDisplayer ;
10
14
import fi .helsinki .cs .tmc .ui .PastebinDialog ;
11
15
import fi .helsinki .cs .tmc .ui .PastebinResponseDialog ;
12
16
import fi .helsinki .cs .tmc .utilities .BgTask ;
13
17
import fi .helsinki .cs .tmc .utilities .BgTaskListener ;
14
18
import fi .helsinki .cs .tmc .utilities .CancellableCallable ;
15
19
import fi .helsinki .cs .tmc .utilities .zip .RecursiveZipper ;
20
+ import hy .tmc .core .exceptions .TmcCoreException ;
16
21
import java .awt .event .ActionEvent ;
17
22
import java .awt .event .ActionListener ;
18
23
import java .net .URI ;
28
33
import org .openide .awt .ActionReferences ;
29
34
import org .openide .awt .ActionRegistration ;
30
35
import org .openide .nodes .Node ;
36
+ import org .openide .util .Exceptions ;
31
37
import org .openide .util .NbBundle .Messages ;
32
38
33
39
@ ActionID (
38
44
@ ActionReferences ({
39
45
@ ActionReference (path = "Menu/TM&C" , position = -17 ),
40
46
@ ActionReference (path = "Projects/Actions" , position = 1340 , separatorBefore = 1330 ,
41
- separatorAfter = 1360 )
47
+ separatorAfter = 1360 )
42
48
})
43
49
@ Messages ("CTL_PastebinAction=Send code to Pastebin" )
44
50
//TODO: This is a horribly copypasted, then mangled version of RequestReviewAction
@@ -108,59 +114,30 @@ public void actionPerformed(ActionEvent e) {
108
114
private void submitPaste (final TmcProjectInfo projectInfo , final Exercise exercise ,
109
115
final String messageForReviewer ) {
110
116
projectMediator .saveAllFiles ();
111
-
112
117
final String errorMsgLocale = settings .getErrorMsgLocale ().toString ();
118
+ try {
119
+ ListenableFuture <URI > result = TmcCoreSingleton .getInstance ().pasteWithComment (projectInfo .getProjectDirAbsPath (), settings , messageForReviewer );
120
+ Futures .addCallback (result , new PasteResult ());
121
+ } catch (TmcCoreException ex ) {
122
+ Exceptions .printStackTrace (ex );
123
+ }
124
+ }
113
125
114
- BgTask .start ("Zipping up " + exercise .getName (), new Callable <byte []>() {
115
- @ Override
116
- public byte [] call () throws Exception {
117
- RecursiveZipper zipper = new RecursiveZipper (projectInfo .getProjectDirAsFile (), projectInfo .getZippingDecider ());
118
- return zipper .zipProjectSources ();
119
- }
120
- }, new BgTaskListener <byte []>() {
121
- @ Override
122
- public void bgTaskReady (byte [] zipData ) {
123
- Map <String , String > extraParams = new HashMap <String , String >();
124
- extraParams .put ("error_msg_locale" , errorMsgLocale );
125
- extraParams .put ("paste" , "1" );
126
- if (!messageForReviewer .isEmpty ()) {
127
- extraParams .put ("message_for_paste" , messageForReviewer );
128
- }
129
-
130
- final ServerAccess sa = new ServerAccess ();
131
- CancellableCallable <ServerAccess .SubmissionResponse > submitTask = sa
132
- .getSubmittingExerciseTask (exercise , zipData , extraParams );
133
-
134
- BgTask .start ("Sending " + exercise .getName (), submitTask , new BgTaskListener <ServerAccess .SubmissionResponse >() {
135
- @ Override
136
- public void bgTaskReady (ServerAccess .SubmissionResponse result ) {
137
- new PastebinResponseDialog (result .pasteUrl .toString ()).setVisible (true );
138
- }
139
-
140
- @ Override
141
- public void bgTaskCancelled () {
142
- }
143
-
144
- @ Override
145
- public void bgTaskFailed (Throwable ex ) {
146
- dialogs .displayError ("Failed to send exercise to pastebin" , ex );
147
- }
148
- });
149
- }
126
+ class PasteResult implements FutureCallback <URI > {
150
127
151
- @ Override
152
- public void bgTaskCancelled () {
153
- }
128
+ @ Override
129
+ public void onSuccess (URI ur ) {
130
+ new PastebinResponseDialog (ur .toString ()).setVisible (true );
131
+ }
154
132
155
- @ Override
156
- public void bgTaskFailed (Throwable ex ) {
157
- dialogs .displayError ("Failed to zip up exercise" , ex );
158
- }
159
- });
133
+ @ Override
134
+ public void onFailure (Throwable thrwbl ) {
135
+ dialogs .displayError ("Failed to send exercise to pastebin" , thrwbl );
136
+ }
160
137
}
161
138
162
139
@ Override
163
140
public String getName () {
164
141
return "Send code to TMC Pastebin" ;
165
142
}
166
- }
143
+ }
0 commit comments