Skip to content

Commit a821553

Browse files
committed
Reformat and cleanup
1 parent 6048cbb commit a821553

File tree

3 files changed

+152
-129
lines changed

3 files changed

+152
-129
lines changed

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

Lines changed: 79 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,9 @@
3333
import javax.swing.JComponent;
3434
import javax.swing.JMenuItem;
3535

36-
@ActionID(category = "TMC",
37-
id = "fi.helsinki.cs.tmc.actions.DownloadSolutionAction")
36+
@ActionID(category = "TMC", id = "fi.helsinki.cs.tmc.actions.DownloadSolutionAction")
3837
@ActionRegistration(displayName = "#CTL_DownloadSolutionAction", lazy = false)
39-
@ActionReferences({
40-
@ActionReference(path = "Menu/TM&C", position = -35, separatorAfter = -30)
41-
})
38+
@ActionReferences({@ActionReference(path = "Menu/TM&C", position = -35, separatorAfter = -30)})
4239
@Messages("CTL_DownloadSolutionAction=Download suggested &solution")
4340
public class DownloadSolutionAction extends AbstractExerciseSensitiveAction {
4441

@@ -112,81 +109,98 @@ protected void performAction(Node[] nodes) {
112109
return;
113110
}
114111

115-
String question = "Are you sure you want to OVERWRITE your copy of\n" + ex.getName() + " with the suggested solution?";
112+
String question =
113+
"Are you sure you want to OVERWRITE your copy of\n"
114+
+ ex.getName()
115+
+ " with the suggested solution?";
116116
String title = "Replace with solution?";
117-
dialogs.askYesNo(question, title, new Function<Boolean, Void>() {
118-
@Override
119-
public Void apply(Boolean yes) {
120-
if (yes) {
121-
eventBus.post(new InvokedEvent(ex));
122-
downloadSolution(ex, projectMediator.wrapProject(project));
123-
}
124-
return null;
125-
}
126-
});
117+
dialogs.askYesNo(
118+
question,
119+
title,
120+
new Function<Boolean, Void>() {
121+
@Override
122+
public Void apply(Boolean yes) {
123+
if (yes) {
124+
eventBus.post(new InvokedEvent(ex));
125+
downloadSolution(ex, projectMediator.wrapProject(project));
126+
}
127+
return null;
128+
}
129+
});
127130
}
128131
}
129132

130133
private void downloadSolution(final Exercise ex, final TmcProjectInfo proj) {
131134
ServerAccess serverAccess = new ServerAccess(TmcSettings.getDefault());
132-
CancellableCallable<byte[]> downloadTask = serverAccess.getDownloadingExerciseSolutionZipTask(ex);
133-
BgTask.start("Downloading solution for " + ex.getName(), downloadTask, new BgTaskListener<byte[]>() {
134-
@Override
135-
public void bgTaskReady(byte[] result) {
136-
unzipSolution(ex, proj, result);
137-
}
135+
CancellableCallable<byte[]> downloadTask =
136+
serverAccess.getDownloadingExerciseSolutionZipTask(ex);
137+
BgTask.start(
138+
"Downloading solution for " + ex.getName(),
139+
downloadTask,
140+
new BgTaskListener<byte[]>() {
141+
@Override
142+
public void bgTaskReady(byte[] result) {
143+
unzipSolution(ex, proj, result);
144+
}
138145

139-
@Override
140-
public void bgTaskCancelled() {
141-
}
146+
@Override
147+
public void bgTaskCancelled() {}
142148

143-
@Override
144-
public void bgTaskFailed(Throwable ex) {
145-
logger.log(Level.INFO, "Failed to download solution.", ex);
146-
dialogs.displayError("Failed to download solution.\n" + ServerErrorHelper.getServerExceptionMsg(ex));
147-
}
148-
});
149+
@Override
150+
public void bgTaskFailed(Throwable ex) {
151+
logger.log(Level.INFO, "Failed to download solution.", ex);
152+
dialogs.displayError(
153+
"Failed to download solution.\n"
154+
+ ServerErrorHelper.getServerExceptionMsg(ex));
155+
}
156+
});
149157
}
150158

151159
private void unzipSolution(final Exercise ex, final TmcProjectInfo proj, final byte[] data) {
152-
Callable<Object> task = new Callable<Object>() {
153-
@Override
154-
public Object call() throws Exception {
155-
NbProjectUnzipper unzipper = new NbProjectUnzipper(solutionOverwriting);
156-
unzipper.unzipProject(data, proj.getProjectDirAsFile());
157-
return null;
158-
}
159-
};
160+
Callable<Object> task =
161+
new Callable<Object>() {
162+
@Override
163+
public Object call() throws Exception {
164+
NbProjectUnzipper unzipper = new NbProjectUnzipper(solutionOverwriting);
165+
unzipper.unzipProject(data, proj.getProjectDirAsFile());
166+
return null;
167+
}
168+
};
169+
170+
BgTask.start(
171+
"Extracting solution",
172+
task,
173+
new BgTaskListener<Object>() {
174+
@Override
175+
public void bgTaskReady(Object result) {
176+
projectMediator.scanForExternalChanges(proj);
177+
}
160178

161-
BgTask.start("Extracting solution", task, new BgTaskListener<Object>() {
162-
@Override
163-
public void bgTaskReady(Object result) {
164-
projectMediator.scanForExternalChanges(proj);
165-
}
179+
@Override
180+
public void bgTaskCancelled() {}
166181

167-
@Override
168-
public void bgTaskCancelled() {
169-
}
170-
171-
@Override
172-
public void bgTaskFailed(Throwable ex) {
173-
logger.log(Level.INFO, "Failed to extract solution.", ex);
174-
dialogs.displayError("Failed to extract solution.\n" + ServerErrorHelper.getServerExceptionMsg(ex));
175-
}
176-
});
182+
@Override
183+
public void bgTaskFailed(Throwable ex) {
184+
logger.log(Level.INFO, "Failed to extract solution.", ex);
185+
dialogs.displayError(
186+
"Failed to extract solution.\n"
187+
+ ServerErrorHelper.getServerExceptionMsg(ex));
188+
}
189+
});
177190
}
178191

179-
private OverwritingDecider solutionOverwriting = new OverwritingDecider() {
180-
@Override
181-
public boolean mayOverwrite(String relPath) {
182-
return true;
183-
}
192+
private OverwritingDecider solutionOverwriting =
193+
new OverwritingDecider() {
194+
@Override
195+
public boolean mayOverwrite(String relPath) {
196+
return true;
197+
}
184198

185-
@Override
186-
public boolean mayDelete(String relPath) {
187-
return false;
188-
}
189-
};
199+
@Override
200+
public boolean mayDelete(String relPath) {
201+
return false;
202+
}
203+
};
190204

191205
private class ActionMenuItem extends JMenuItem implements DynamicMenuContent {
192206

@@ -197,7 +211,7 @@ public ActionMenuItem() {
197211
@Override
198212
public JComponent[] getMenuPresenters() {
199213
if (DownloadSolutionAction.this.isEnabled()) {
200-
return new JComponent[]{getOriginalMenuPresenter()};
214+
return new JComponent[] {getOriginalMenuPresenter()};
201215
} else {
202216
return new JComponent[0];
203217
}
@@ -207,7 +221,6 @@ public JComponent[] getMenuPresenters() {
207221
public JComponent[] synchMenuPresenters(JComponent[] jcs) {
208222
return getMenuPresenters();
209223
}
210-
211224
}
212225

213226
public static class InvokedEvent implements TmcEvent {

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

Lines changed: 73 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@
3333
import java.util.logging.Level;
3434
import 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

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,4 @@ protected String iconResource() {
5050
// The setting in layer.xml doesn't work with NodeAction
5151
return "fi/helsinki/cs/tmc/actions/submit.png";
5252
}
53-
<<<<<<< HEAD
54-
<<<<<<< HEAD
5553
}
56-
=======
57-
}
58-
>>>>>>> 7fd9e4e... Send snapshots on each submit to make sure to have all relevant
59-
=======
60-
}
61-
>>>>>>> Send snapshots on each submit to make sure to have all relevant

0 commit comments

Comments
 (0)