Skip to content

Commit bf0de9b

Browse files
committed
Give a more detailed progress when checking for new exercises and updates
1 parent 0e54312 commit bf0de9b

File tree

4 files changed

+83
-34
lines changed

4 files changed

+83
-34
lines changed

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

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void actionPerformed(ActionEvent e) {
8080
public void run() {
8181
final Course currentCourseBeforeUpdate = courseDb.getCurrentCourse();
8282

83-
if (backgroundCheck && !((TmcCoreSettingsImpl)TmcSettingsHolder.get()).isCheckingForUpdatesInTheBackground()) {
83+
if (backgroundCheck && !((TmcCoreSettingsImpl) TmcSettingsHolder.get()).isCheckingForUpdatesInTheBackground()) {
8484
return;
8585
}
8686

@@ -97,29 +97,46 @@ public void run() {
9797
BgTask.start("Checking for new exercises", getFullCourseInfoTask, observer, new BgTaskListener<Course>() {
9898
@Override
9999
public void bgTaskReady(Course receivedCourse) {
100-
if (receivedCourse != null) {
101-
courseDb.putDetailedCourse(receivedCourse);
102-
103-
final LocalExerciseStatus status = LocalExerciseStatus.get(receivedCourse.getExercises());
104-
if (status.thereIsSomethingToDownload(false)) {
105-
if (beQuiet) {
106-
displayNotification(status, new ActionListener() {
107-
@Override
108-
public void actionPerformed(ActionEvent e) {
109-
SwingUtilities.invokeLater(() -> {
110-
DownloadOrUpdateExercisesDialog.display(status.unlockable, status.downloadableUncompleted, status.updateable);
111-
});
112-
}
113-
});
114-
} else {
115-
SwingUtilities.invokeLater(() -> {
116-
DownloadOrUpdateExercisesDialog.display(status.unlockable, status.downloadableUncompleted, status.updateable);
117-
});
100+
Callable<Void> task = () -> {
101+
if (receivedCourse != null) {
102+
courseDb.putDetailedCourse(receivedCourse);
103+
104+
final LocalExerciseStatus status = LocalExerciseStatus.get(receivedCourse.getExercises());
105+
if (status.thereIsSomethingToDownload(false)) {
106+
if (beQuiet) {
107+
displayNotification(status, new ActionListener() {
108+
@Override
109+
public void actionPerformed(ActionEvent e) {
110+
SwingUtilities.invokeLater(() -> {
111+
DownloadOrUpdateExercisesDialog.display(status.unlockable, status.downloadableUncompleted, status.updateable);
112+
});
113+
}
114+
});
115+
} else {
116+
SwingUtilities.invokeLater(() -> {
117+
DownloadOrUpdateExercisesDialog.display(status.unlockable, status.downloadableUncompleted, status.updateable);
118+
});
119+
}
120+
} else if (!beQuiet) {
121+
dialogs.displayMessage("No new exercises or updates to download.");
118122
}
119-
} else if (!beQuiet) {
120-
dialogs.displayMessage("No new exercises or updates to download.");
121123
}
122-
}
124+
return null;
125+
};
126+
BgTask.start("Calculating status of local exercises", task, ProgressObserver.NULL_OBSERVER, new BgTaskListener<Void>() {
127+
@Override
128+
public void bgTaskReady(Void result) {
129+
}
130+
131+
@Override
132+
public void bgTaskCancelled() {
133+
}
134+
135+
@Override
136+
public void bgTaskFailed(Throwable ex) {
137+
}
138+
139+
}, "If this takes time, your hard drive might be slow.");
123140
}
124141

125142
@Override

tmc-plugin/src/fi/helsinki/cs/tmc/exerciseSubmitter/ExerciseSubmitter.java

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

3-
import fi.helsinki.cs.tmc.actions.CheckForNewExercisesOrUpdates;
43
import fi.helsinki.cs.tmc.core.TmcCore;
54
import fi.helsinki.cs.tmc.core.domain.Exercise;
65
import fi.helsinki.cs.tmc.core.domain.submission.SubmissionResult;
@@ -22,7 +21,6 @@
2221
import java.util.logging.Level;
2322
import java.util.logging.Logger;
2423
import javax.swing.SwingUtilities;
25-
import javax.swing.SwingWorker;
2624

2725
import org.netbeans.api.project.Project;
2826

@@ -97,15 +95,6 @@ public void bgTaskReady(SubmissionResult result) {
9795
}
9896

9997
dialog.close();
100-
101-
new SwingWorker<Void, Void>() {
102-
@Override
103-
protected Void doInBackground() throws Exception {
104-
courseDb.save();
105-
new CheckForNewExercisesOrUpdates(true, false).run();
106-
return null;
107-
}
108-
}.run();
10998
}
11099

111100
@Override

tmc-plugin/src/fi/helsinki/cs/tmc/ui/TestResultDisplayer.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package fi.helsinki.cs.tmc.ui;
22

3+
import fi.helsinki.cs.tmc.actions.CheckForNewExercisesOrUpdates;
34
import fi.helsinki.cs.tmc.core.communication.TmcServerCommunicationTaskFactory;
45
import fi.helsinki.cs.tmc.core.domain.Exercise;
56
import fi.helsinki.cs.tmc.core.domain.submission.FeedbackAnswer;
67
import fi.helsinki.cs.tmc.langs.abstraction.Strategy;
78
import fi.helsinki.cs.tmc.langs.domain.TestResult;
9+
import fi.helsinki.cs.tmc.model.CourseDb;
810
import fi.helsinki.cs.tmc.utilities.BgTask;
911
import fi.helsinki.cs.tmc.utilities.BgTaskListener;
1012
import fi.helsinki.cs.tmc.utilities.ExceptionUtils;
@@ -13,10 +15,13 @@
1315
import fi.helsinki.cs.tmc.langs.domain.RunResult;
1416

1517
import com.google.common.collect.ImmutableList;
18+
import fi.helsinki.cs.tmc.core.domain.ProgressObserver;
1619

1720
import java.awt.Dialog;
1821
import java.awt.event.ActionEvent;
1922
import java.awt.event.ActionListener;
23+
import java.awt.event.WindowAdapter;
24+
import java.awt.event.WindowEvent;
2025
import java.net.URI;
2126
import java.util.List;
2227
import java.util.concurrent.Callable;
@@ -98,12 +103,33 @@ public void bgTaskFailed(Throwable ex) {
98103
}
99104
});
100105

106+
dialog.addWindowListener(new WindowAdapter() {
107+
@Override
108+
public void windowClosed(WindowEvent e) {
109+
saveCourseDbAndCheckForNewExercisesOrUpdates();
110+
}
111+
112+
@Override
113+
public void windowClosing(WindowEvent e) {
114+
saveCourseDbAndCheckForNewExercisesOrUpdates();
115+
}
116+
});
117+
101118
dialog.setModalityType(Dialog.ModalityType.MODELESS);
102119
dialog.setLocationRelativeTo(null);
103120
dialog.setAlwaysOnTop(true);
104121
dialog.setVisible(true);
105122
}
106123

124+
private void saveCourseDbAndCheckForNewExercisesOrUpdates() {
125+
Callable<Void> c = () -> {
126+
CourseDb.getInstance().save();
127+
new CheckForNewExercisesOrUpdates(true, false).run();
128+
return null;
129+
};
130+
BgTask.start("Saving local exercise progress", c);
131+
}
132+
107133
private void displayFailedTestsMsg(Exercise exercise, SubmissionResult result) {
108134

109135
String msg;

tmc-plugin/src/fi/helsinki/cs/tmc/utilities/BgTask.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class BgTask<V> implements CancellableCallable<V> {
3232
private Callable<V> callable;
3333
private ProgressHandle progressHandle;
3434
private ProgressObserver proressObserver;
35+
private String initialDetails;
3536

3637
private final Object cancelLock = new Object();
3738
private boolean cancelled;
@@ -49,6 +50,10 @@ public static <V> Future<V> start(String label, Callable<V> callable, BgTaskList
4950
return new BgTask<V>(label, callable, ProgressObserver.NULL_OBSERVER, listener).start();
5051
}
5152

53+
public static <V> Future<V> start(String label, Callable<V> callable, ProgressObserver observer, BgTaskListener<V> listener, String initialDetails) {
54+
return new BgTask<V>(label, callable, observer, listener, initialDetails).start();
55+
}
56+
5257
public static Future<Object> start(String label, Runnable runnable) {
5358
Callable<Object> callable = runnableToCallable(runnable);
5459
return start(label, callable);
@@ -64,6 +69,11 @@ public static Future<Object> start(String label, Runnable runnable, ProgressObse
6469
return start(label, callable, observer, listener);
6570
}
6671

72+
public static Future<Object> start(String label, Runnable runnable, ProgressObserver observer, BgTaskListener<Object> listener, String initialDetails) {
73+
Callable<Object> callable = runnableToCallable(runnable);
74+
return start(label, callable, observer, listener, initialDetails);
75+
}
76+
6777
private static Callable<Object> runnableToCallable(final Runnable runnable) {
6878
if (runnable instanceof Cancellable) {
6979
return new CancellableCallable<Object>() {
@@ -90,16 +100,21 @@ public Object call() throws Exception {
90100
}
91101

92102
public BgTask(String label, Callable<V> callable) {
93-
this(label, callable, ProgressObserver.NULL_OBSERVER, EmptyBgTaskListener.get());
103+
this(label, callable, ProgressObserver.NULL_OBSERVER, EmptyBgTaskListener.get(), "");
94104
}
95105

96106
public BgTask(String label, Callable<V> callable, ProgressObserver observer, BgTaskListener<? super V> listener) {
107+
this(label, callable, observer, listener, "");
108+
}
109+
110+
public BgTask(String label, Callable<V> callable, ProgressObserver observer, BgTaskListener<? super V> listener, String initialDetails) {
97111
this.requestProcessor = TmcRequestProcessor.instance;
98112
this.label = label;
99113
this.listener = listener;
100114
this.callable = callable;
101115
this.proressObserver = observer;
102116
this.progressHandle = null;
117+
this.initialDetails = initialDetails;
103118
}
104119

105120
public Future<V> start() {
@@ -131,6 +146,8 @@ public V call() {
131146
}
132147

133148
progressHandle.start();
149+
progressHandle.progress(initialDetails);
150+
134151
try {
135152
V resultTemp = null;
136153
boolean successful;

0 commit comments

Comments
 (0)