1
1
package fi .helsinki .cs .tmc .actions ;
2
2
3
+ import fi .helsinki .cs .tmc .core .TmcCore ;
3
4
import fi .helsinki .cs .tmc .core .domain .Exercise ;
5
+ import fi .helsinki .cs .tmc .core .domain .ProgressObserver ;
4
6
import fi .helsinki .cs .tmc .core .holders .TmcSettingsHolder ;
5
7
import fi .helsinki .cs .tmc .coreimpl .TmcCoreSettingsImpl ;
6
8
import fi .helsinki .cs .tmc .events .TmcEvent ;
7
9
import fi .helsinki .cs .tmc .events .TmcEventBus ;
8
10
import fi .helsinki .cs .tmc .model .CourseDb ;
9
11
import fi .helsinki .cs .tmc .model .ProjectMediator ;
10
- import fi .helsinki .cs .tmc .model .ServerAccess ;
11
12
import fi .helsinki .cs .tmc .model .TmcProjectInfo ;
12
13
import fi .helsinki .cs .tmc .ui .ConvenientDialogDisplayer ;
13
14
import fi .helsinki .cs .tmc .ui .PastebinDialog ;
14
15
import fi .helsinki .cs .tmc .ui .PastebinResponseDialog ;
15
16
import fi .helsinki .cs .tmc .utilities .BgTask ;
16
17
import fi .helsinki .cs .tmc .utilities .BgTaskListener ;
17
- import fi .helsinki .cs .tmc .utilities .CancellableCallable ;
18
- import fi .helsinki .cs .tmc .utilities .zip .RecursiveZipper ;
19
18
20
19
import org .netbeans .api .project .Project ;
21
20
import org .openide .awt .ActionID ;
27
26
28
27
import java .awt .event .ActionEvent ;
29
28
import java .awt .event .ActionListener ;
30
- import java .util . HashMap ;
29
+ import java .net . URI ;
31
30
import java .util .List ;
32
- import java .util .Map ;
33
31
import java .util .concurrent .Callable ;
34
32
import java .util .logging .Level ;
35
33
import java .util .logging .Logger ;
39
37
@ ActionReferences ({
40
38
@ ActionReference (path = "Menu/TM&C" , position = -17 ),
41
39
@ ActionReference (
42
- path = "Projects/Actions" ,
43
- position = 1340 ,
44
- separatorBefore = 1330 ,
45
- separatorAfter = 1360
40
+ path = "Projects/Actions" ,
41
+ position = 1340 ,
42
+ separatorBefore = 1330 ,
43
+ separatorAfter = 1360
46
44
)
47
45
})
48
46
@ Messages ("CTL_PastebinAction=Send code to Pastebin" )
49
- //TODO: This is a horribly copypasted, then mangled version of RequestReviewAction
50
- //plz remove everything that isn't needed here. --kviiri
51
47
public final class PastebinAction extends AbstractExerciseSensitiveAction {
52
48
53
49
private static final Logger log = Logger .getLogger (RequestReviewAction .class .getName ());
@@ -58,7 +54,7 @@ public final class PastebinAction extends AbstractExerciseSensitiveAction {
58
54
private TmcEventBus eventBus ;
59
55
60
56
public PastebinAction () {
61
- this .settings = ((TmcCoreSettingsImpl )TmcSettingsHolder .get ());
57
+ this .settings = ((TmcCoreSettingsImpl ) TmcSettingsHolder .get ());
62
58
this .courseDb = CourseDb .getInstance ();
63
59
this .projectMediator = ProjectMediator .getInstance ();
64
60
this .dialogs = ConvenientDialogDisplayer .getDefault ();
@@ -92,7 +88,7 @@ protected void performAction(Node[] nodes) {
92
88
Exercise exercise = projectMediator .tryGetExerciseForProject (projectInfo , courseDb );
93
89
if (exercise != null ) {
94
90
eventBus .post (new PastebinAction .InvokedEvent (projectInfo ));
95
- showPasteRequestDialog (projectInfo , exercise );
91
+ showPasteRequestDialog (exercise );
96
92
} else {
97
93
log .log (
98
94
Level .WARNING ,
@@ -106,83 +102,45 @@ protected void performAction(Node[] nodes) {
106
102
}
107
103
}
108
104
109
- private void showPasteRequestDialog (final TmcProjectInfo projectInfo , final Exercise exercise ) {
105
+ private void showPasteRequestDialog (final Exercise exercise ) {
110
106
final PastebinDialog dialog = new PastebinDialog (exercise );
111
107
dialog .setOkListener (
112
108
new ActionListener () {
113
- @ Override
114
- public void actionPerformed (ActionEvent e ) {
115
- String message = dialog .getMessageForReviewer ().trim ();
116
- submitPaste (projectInfo , exercise , message );
117
- }
118
- });
109
+ @ Override
110
+ public void actionPerformed (ActionEvent e ) {
111
+ String message = dialog .getMessageForReviewer ().trim ();
112
+ submitPaste (exercise , message );
113
+ }
114
+ });
119
115
dialog .setVisible (true );
120
116
}
121
117
122
118
private void submitPaste (
123
- final TmcProjectInfo projectInfo ,
124
119
final Exercise exercise ,
125
120
final String messageForReviewer ) {
126
121
projectMediator .saveAllFiles ();
127
122
128
- final String errorMsgLocale = settings .getErrorMsgLocale ().toString ();
123
+ Callable <URI > pasteTask = TmcCore .get ()
124
+ .pasteWithComment (ProgressObserver .NULL_OBSERVER , exercise , messageForReviewer );
129
125
130
126
BgTask .start (
131
- "Zipping up " + exercise .getName (),
132
- new Callable <byte []>() {
133
- @ Override
134
- public byte [] call () throws Exception {
135
- RecursiveZipper zipper =
136
- new RecursiveZipper (
137
- projectInfo .getProjectDirAsFile (),
138
- projectInfo .getZippingDecider ());
139
- return zipper .zipProjectSources ();
140
- }
141
- },
142
- new BgTaskListener <byte []>() {
143
- @ Override
144
- public void bgTaskReady (byte [] zipData ) {
145
- Map <String , String > extraParams = new HashMap <String , String >();
146
- extraParams .put ("error_msg_locale" , errorMsgLocale );
147
- extraParams .put ("paste" , "1" );
148
- if (!messageForReviewer .isEmpty ()) {
149
- extraParams .put ("message_for_paste" , messageForReviewer );
150
- }
151
-
152
- final ServerAccess sa = new ServerAccess ();
153
- CancellableCallable <ServerAccess .SubmissionResponse > submitTask =
154
- sa .getSubmittingExerciseTask (exercise , zipData , extraParams );
155
-
156
- BgTask .start (
157
- "Sending " + exercise .getName (),
158
- submitTask ,
159
- new BgTaskListener <ServerAccess .SubmissionResponse >() {
160
- @ Override
161
- public void bgTaskReady (
162
- ServerAccess .SubmissionResponse result ) {
163
- new PastebinResponseDialog (result .pasteUrl .toString ())
164
- .setVisible (true );
165
- }
166
-
167
- @ Override
168
- public void bgTaskCancelled () {}
169
-
170
- @ Override
171
- public void bgTaskFailed (Throwable ex ) {
172
- dialogs .displayError (
173
- "Failed to send exercise to pastebin" , ex );
174
- }
175
- });
176
- }
177
-
178
- @ Override
179
- public void bgTaskCancelled () {}
180
-
181
- @ Override
182
- public void bgTaskFailed (Throwable ex ) {
183
- dialogs .displayError ("Failed to zip up exercise" , ex );
184
- }
185
- });
127
+ "Sending " + exercise .getName (), pasteTask , new BgTaskListener <URI >() {
128
+ @ Override
129
+ public void bgTaskReady (URI result ) {
130
+ new PastebinResponseDialog (result .toString ())
131
+ .setVisible (true );
132
+ }
133
+
134
+ @ Override
135
+ public void bgTaskCancelled () {
136
+ }
137
+
138
+ @ Override
139
+ public void bgTaskFailed (Throwable ex ) {
140
+ dialogs .displayError (
141
+ "Failed to send exercise to pastebin" , ex );
142
+ }
143
+ });
186
144
}
187
145
188
146
@ Override
0 commit comments