Skip to content

Commit b967a63

Browse files
committed
Cleanup and TODOs
1 parent 241d299 commit b967a63

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
package fi.helsinki.cs.tmc.actions;
22

3-
import com.google.common.util.concurrent.FutureCallback;
43
import fi.helsinki.cs.tmc.core.domain.Course;
5-
import fi.helsinki.cs.tmc.data.CourseListUtils;
64
import fi.helsinki.cs.tmc.core.domain.Exercise;
75
import fi.helsinki.cs.tmc.model.CourseDb;
86
import fi.helsinki.cs.tmc.model.LocalExerciseStatus;
97
import fi.helsinki.cs.tmc.model.ServerAccess;
108
import fi.helsinki.cs.tmc.ui.ConvenientDialogDisplayer;
119
import fi.helsinki.cs.tmc.ui.DownloadOrUpdateExercisesDialog;
12-
import fi.helsinki.cs.tmc.utilities.BgTask;
1310
import fi.helsinki.cs.tmc.utilities.BgTaskListener;
14-
import fi.helsinki.cs.tmc.core.exceptions.TmcCoreException;
15-
import java.awt.event.ActionEvent;
16-
import java.awt.event.ActionListener;
17-
import java.util.Collections;
18-
import java.util.List;
11+
1912
import org.openide.awt.ActionID;
2013
import org.openide.awt.ActionReference;
2114
import org.openide.awt.ActionRegistration;
22-
import org.openide.util.Exceptions;
2315
import org.openide.util.NbBundle.Messages;
2416

17+
import java.awt.event.ActionEvent;
18+
import java.awt.event.ActionListener;
19+
import java.util.Collections;
20+
import java.util.List;
21+
2522
@ActionID(category = "TMC", id = "fi.helsinki.cs.tmc.actions.DownloadCompletedExercises")
2623
@ActionRegistration(displayName = "#CTL_DownloadCompletedExercises")
2724
@ActionReference(path = "Menu/TM&C", position = -45)
@@ -40,7 +37,6 @@ public DownloadCompletedExercises() {
4037

4138
@Override
4239
public void actionPerformed(ActionEvent e) {
43-
// TODO(jamo): use bg task
4440
final Course currentCourse = courseDb.getCurrentCourse();
4541
if (currentCourse == null) {
4642
dialogs.displayMessage("Please select a course in TMC -> Settings.");

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package fi.helsinki.cs.tmc.actions;
22

3-
import com.google.common.base.Function;
43
import fi.helsinki.cs.tmc.core.domain.Exercise;
54
import fi.helsinki.cs.tmc.model.CourseDb;
65
import fi.helsinki.cs.tmc.model.ProjectMediator;
@@ -13,11 +12,9 @@
1312
import fi.helsinki.cs.tmc.utilities.CancellableCallable;
1413
import fi.helsinki.cs.tmc.utilities.zip.NbProjectUnzipper;
1514
import fi.helsinki.cs.tmc.utilities.zip.NbProjectUnzipper.OverwritingDecider;
16-
import java.util.concurrent.Callable;
17-
import java.util.logging.Level;
18-
import java.util.logging.Logger;
19-
import javax.swing.JComponent;
20-
import javax.swing.JMenuItem;
15+
16+
import com.google.common.base.Function;
17+
2118
import org.netbeans.api.project.Project;
2219
import org.openide.awt.ActionID;
2320
import org.openide.awt.ActionReference;
@@ -28,6 +25,12 @@
2825
import org.openide.util.HelpCtx;
2926
import org.openide.util.NbBundle.Messages;
3027

28+
import java.util.concurrent.Callable;
29+
import java.util.logging.Level;
30+
import java.util.logging.Logger;
31+
import javax.swing.JComponent;
32+
import javax.swing.JMenuItem;
33+
3134
@ActionID(category = "TMC",
3235
id = "fi.helsinki.cs.tmc.actions.DownloadSolutionAction")
3336
@ActionRegistration(displayName = "#CTL_DownloadSolutionAction", lazy = false)
@@ -46,7 +49,7 @@ public DownloadSolutionAction() {
4649
this.courseDb = CourseDb.getInstance();
4750
this.dialogs = ConvenientDialogDisplayer.getDefault();
4851
}
49-
52+
5053
@Override
5154
public String getName() {
5255
return "Download suggested &solution";
@@ -66,7 +69,7 @@ protected boolean enabledFor(Exercise exercise) {
6669
protected boolean enabledForMultipleProjects() {
6770
return true;
6871
}
69-
72+
7073
@Override
7174
protected boolean asynchronous() {
7275
return false;
@@ -76,7 +79,7 @@ protected boolean asynchronous() {
7679
public JMenuItem getMenuPresenter() {
7780
return new ActionMenuItem();
7881
}
79-
82+
8083
private JMenuItem getOriginalMenuPresenter() {
8184
return super.getMenuPresenter();
8285
}
@@ -93,9 +96,8 @@ protected CourseDb getCourseDb() {
9396

9497
@Override
9598
protected void performAction(Node[] nodes) {
96-
// TODO(jamo): use bg task
9799
projectMediator.saveAllFiles();
98-
100+
99101
for (final Project project : projectsFromNodes(nodes)) {
100102
final Exercise ex = exerciseForProject(project);
101103
if (ex.getSolutionDownloadUrl() == null) {
@@ -104,7 +106,7 @@ protected void performAction(Node[] nodes) {
104106
this.setEnabled(false);
105107
return;
106108
}
107-
109+
108110
String question = "Are you sure you want to OVERWRITE your copy of\n" + ex.getName() + " with the suggested solution?";
109111
String title = "Replace with solution?";
110112
dialogs.askYesNo(question, title, new Function<Boolean, Void>() {
@@ -121,6 +123,8 @@ public Void apply(Boolean yes) {
121123

122124
private void downloadSolution(final Exercise ex, final TmcProjectInfo proj) {
123125
ServerAccess serverAccess = new ServerAccess(NbTmcSettings.getDefault());
126+
127+
// TODO: Use tmc-core.
124128
CancellableCallable<byte[]> downloadTask = serverAccess.getDownloadingExerciseSolutionZipTask(ex);
125129
BgTask.start("Downloading solution for " + ex.getName(), downloadTask, new BgTaskListener<byte[]>() {
126130
@Override
@@ -139,7 +143,7 @@ public void bgTaskFailed(Throwable ex) {
139143
}
140144
});
141145
}
142-
146+
143147
private void unzipSolution(final Exercise ex, final TmcProjectInfo proj, final byte[] data) {
144148
Callable<Object> task = new Callable<Object>() {
145149
@Override
@@ -149,7 +153,7 @@ public Object call() throws Exception {
149153
return null;
150154
}
151155
};
152-
156+
153157
BgTask.start("Extracting solution", task, new BgTaskListener<Object>() {
154158
@Override
155159
public void bgTaskReady(Object result) {
@@ -167,7 +171,7 @@ public void bgTaskFailed(Throwable ex) {
167171
}
168172
});
169173
}
170-
174+
171175
private OverwritingDecider solutionOverwriting = new OverwritingDecider() {
172176
@Override
173177
public boolean mayOverwrite(String relPath) {
@@ -178,12 +182,12 @@ public boolean mayDelete(String relPath) {
178182
return false;
179183
}
180184
};
181-
185+
182186
private class ActionMenuItem extends JMenuItem implements DynamicMenuContent {
183187
public ActionMenuItem() {
184188
super(DownloadSolutionAction.this);
185189
}
186-
190+
187191
@Override
188192
public JComponent[] getMenuPresenters() {
189193
if (DownloadSolutionAction.this.isEnabled()) {
@@ -197,6 +201,6 @@ public JComponent[] getMenuPresenters() {
197201
public JComponent[] synchMenuPresenters(JComponent[] jcs) {
198202
return getMenuPresenters();
199203
}
200-
204+
201205
}
202206
}

0 commit comments

Comments
 (0)