3333import java .util .logging .Level ;
3434import java .util .logging .Logger ;
3535
36- @ ActionID (
37- category = "TMC" ,
38- id = "fi.helsinki.cs.tmc.actions.PastebinAction" )
39- @ ActionRegistration (
40- displayName = "#CTL_PastebinAction" , lazy = false )
36+ @ ActionID (category = "TMC" , id = "fi.helsinki.cs.tmc.actions.PastebinAction" )
37+ @ ActionRegistration (displayName = "#CTL_PastebinAction" , lazy = false )
4138@ ActionReferences ({
4239 @ ActionReference (path = "Menu/TM&C" , position = -17 ),
43- @ ActionReference (path = "Projects/Actions" , position = 1340 , separatorBefore = 1330 ,
44- separatorAfter = 1360 )
40+ @ ActionReference (
41+ path = "Projects/Actions" ,
42+ position = 1340 ,
43+ separatorBefore = 1330 ,
44+ separatorAfter = 1360
45+ )
4546})
4647@ Messages ("CTL_PastebinAction=Send code to Pastebin" )
4748//TODO: This is a horribly copypasted, then mangled version of RequestReviewAction
@@ -55,7 +56,6 @@ public final class PastebinAction extends AbstractExerciseSensitiveAction {
5556 private ConvenientDialogDisplayer dialogs ;
5657 private TmcEventBus eventBus ;
5758
58-
5959 public PastebinAction () {
6060 this .settings = TmcSettings .getDefault ();
6161 this .courseDb = CourseDb .getInstance ();
@@ -93,77 +93,95 @@ protected void performAction(Node[] nodes) {
9393 eventBus .post (new PastebinAction .InvokedEvent (projectInfo ));
9494 showPasteRequestDialog (projectInfo , exercise );
9595 } else {
96- log .log (Level .WARNING , "PastebinAction called in a context without a valid TMC project." );
96+ log .log (
97+ Level .WARNING ,
98+ "PastebinAction called in a context without a valid TMC project." );
9799 }
98100 } else {
99- log .log (Level .WARNING , "PastebinAction called in a context with {0} projects" , project .size ());
101+ log .log (
102+ Level .WARNING ,
103+ "PastebinAction called in a context with {0} projects" ,
104+ project .size ());
100105 }
101106 }
102107
103108 private void showPasteRequestDialog (final TmcProjectInfo projectInfo , final Exercise exercise ) {
104109 final PastebinDialog dialog = new PastebinDialog (exercise );
105- dialog .setOkListener (new ActionListener () {
106- @ Override
107- public void actionPerformed (ActionEvent e ) {
108- String message = dialog .getMessageForReviewer ().trim ();
109- submitPaste (projectInfo , exercise , message );
110- }
111- });
110+ dialog .setOkListener (
111+ new ActionListener () {
112+ @ Override
113+ public void actionPerformed (ActionEvent e ) {
114+ String message = dialog .getMessageForReviewer ().trim ();
115+ submitPaste (projectInfo , exercise , message );
116+ }
117+ });
112118 dialog .setVisible (true );
113119 }
114120
115- private void submitPaste (final TmcProjectInfo projectInfo , final Exercise exercise ,
121+ private void submitPaste (
122+ final TmcProjectInfo projectInfo ,
123+ final Exercise exercise ,
116124 final String messageForReviewer ) {
117125 projectMediator .saveAllFiles ();
118126
119127 final String errorMsgLocale = settings .getErrorMsgLocale ().toString ();
120128
121- BgTask .start ("Zipping up " + exercise .getName (), new Callable <byte []>() {
122- @ Override
123- public byte [] call () throws Exception {
124- RecursiveZipper zipper = new RecursiveZipper (projectInfo .getProjectDirAsFile (), projectInfo .getZippingDecider ());
125- return zipper .zipProjectSources ();
126- }
127- }, new BgTaskListener <byte []>() {
128- @ Override
129- public void bgTaskReady (byte [] zipData ) {
130- Map <String , String > extraParams = new HashMap <String , String >();
131- extraParams .put ("error_msg_locale" , errorMsgLocale );
132- extraParams .put ("paste" , "1" );
133- if (!messageForReviewer .isEmpty ()) {
134- extraParams .put ("message_for_paste" , messageForReviewer );
135- }
136-
137- final ServerAccess sa = new ServerAccess ();
138- CancellableCallable <ServerAccess .SubmissionResponse > submitTask = sa
139- .getSubmittingExerciseTask (exercise , zipData , extraParams );
140-
141- BgTask .start ("Sending " + exercise .getName (), submitTask , new BgTaskListener <ServerAccess .SubmissionResponse >() {
129+ BgTask .start (
130+ "Zipping up " + exercise .getName (),
131+ new Callable <byte []>() {
142132 @ Override
143- public void bgTaskReady (ServerAccess .SubmissionResponse result ) {
144- new PastebinResponseDialog (result .pasteUrl .toString ()).setVisible (true );
133+ public byte [] call () throws Exception {
134+ RecursiveZipper zipper =
135+ new RecursiveZipper (
136+ projectInfo .getProjectDirAsFile (),
137+ projectInfo .getZippingDecider ());
138+ return zipper .zipProjectSources ();
145139 }
146-
140+ },
141+ new BgTaskListener <byte []>() {
147142 @ Override
148- public void bgTaskCancelled () {
143+ public void bgTaskReady (byte [] zipData ) {
144+ Map <String , String > extraParams = new HashMap <String , String >();
145+ extraParams .put ("error_msg_locale" , errorMsgLocale );
146+ extraParams .put ("paste" , "1" );
147+ if (!messageForReviewer .isEmpty ()) {
148+ extraParams .put ("message_for_paste" , messageForReviewer );
149+ }
150+
151+ final ServerAccess sa = new ServerAccess ();
152+ CancellableCallable <ServerAccess .SubmissionResponse > submitTask =
153+ sa .getSubmittingExerciseTask (exercise , zipData , extraParams );
154+
155+ BgTask .start (
156+ "Sending " + exercise .getName (),
157+ submitTask ,
158+ new BgTaskListener <ServerAccess .SubmissionResponse >() {
159+ @ Override
160+ public void bgTaskReady (
161+ ServerAccess .SubmissionResponse result ) {
162+ new PastebinResponseDialog (result .pasteUrl .toString ())
163+ .setVisible (true );
164+ }
165+
166+ @ Override
167+ public void bgTaskCancelled () {}
168+
169+ @ Override
170+ public void bgTaskFailed (Throwable ex ) {
171+ dialogs .displayError (
172+ "Failed to send exercise to pastebin" , ex );
173+ }
174+ });
149175 }
150176
177+ @ Override
178+ public void bgTaskCancelled () {}
179+
151180 @ Override
152181 public void bgTaskFailed (Throwable ex ) {
153- dialogs .displayError ("Failed to send exercise to pastebin " , ex );
182+ dialogs .displayError ("Failed to zip up exercise " , ex );
154183 }
155184 });
156- }
157-
158- @ Override
159- public void bgTaskCancelled () {
160- }
161-
162- @ Override
163- public void bgTaskFailed (Throwable ex ) {
164- dialogs .displayError ("Failed to zip up exercise" , ex );
165- }
166- });
167185 }
168186
169187 @ Override
0 commit comments