Skip to content

Commit 38bd558

Browse files
committed
Don't push exceptions to users face
1 parent 59503c2 commit 38bd558

File tree

4 files changed

+47
-26
lines changed

4 files changed

+47
-26
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void actionPerformed(ActionEvent e) {
7979

8080
public void run() {
8181
final Course currentCourseBeforeUpdate = courseDb.getCurrentCourse();
82-
82+
8383
if (backgroundCheck && !((TmcCoreSettingsImpl)TmcSettingsHolder.get()).isCheckingForUpdatesInTheBackground()) {
8484
return;
8585
}

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

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

3+
import fi.helsinki.cs.tmc.core.TmcCore;
34
import fi.helsinki.cs.tmc.core.domain.Course;
45
import fi.helsinki.cs.tmc.core.domain.Exercise;
6+
import fi.helsinki.cs.tmc.core.domain.ProgressObserver;
57
import fi.helsinki.cs.tmc.core.utilities.ServerErrorHelper;
68
import fi.helsinki.cs.tmc.core.events.TmcEvent;
9+
import fi.helsinki.cs.tmc.core.exceptions.ObsoleteClientException;
710
import fi.helsinki.cs.tmc.events.TmcEventBus;
811
import fi.helsinki.cs.tmc.model.CourseDb;
912
import fi.helsinki.cs.tmc.model.LocalExerciseStatus;
1013
import fi.helsinki.cs.tmc.ui.ConvenientDialogDisplayer;
1114
import fi.helsinki.cs.tmc.ui.DownloadOrUpdateExercisesDialog;
15+
import fi.helsinki.cs.tmc.utilities.BgTask;
1216
import fi.helsinki.cs.tmc.utilities.BgTaskListener;
1317

1418
import org.openide.awt.ActionID;
@@ -20,6 +24,7 @@
2024
import java.awt.event.ActionListener;
2125
import java.util.Collections;
2226
import java.util.List;
27+
import java.util.concurrent.Callable;
2328

2429
@ActionID(category = "TMC", id = "fi.helsinki.cs.tmc.actions.DownloadCompletedExercises")
2530
@ActionRegistration(displayName = "#CTL_DownloadCompletedExercises")
@@ -46,17 +51,22 @@ public void actionPerformed(ActionEvent e) {
4651
}
4752

4853
eventBus.post(new InvokedEvent(currentCourse));
49-
RefreshCoursesAction action = new RefreshCoursesAction();
50-
action.addDefaultListener(true, true);
51-
action.addListener(new BgTaskListener<List<Course>>() {
54+
55+
Callable<Course> getFullCourseInfoTask = TmcCore.get().getCourseDetails(ProgressObserver.NULL_OBSERVER, courseDb.getCurrentCourse());
56+
BgTask.start("Checking for new exercises", getFullCourseInfoTask, new BgTaskListener<Course>() {
5257
@Override
53-
public void bgTaskReady(List<Course> receivedCourseList) {
54-
LocalExerciseStatus status = LocalExerciseStatus.get(courseDb.getCurrentCourseExercises());
55-
if (!status.downloadableCompleted.isEmpty()) {
56-
List<Exercise> emptyList = Collections.emptyList();
57-
DownloadOrUpdateExercisesDialog.display(emptyList, status.downloadableCompleted, emptyList);
58-
} else {
59-
dialogs.displayMessage("No completed exercises to download.\nDid you only close them and not delete them?");
58+
public void bgTaskReady(Course receivedCourse) {
59+
if (receivedCourse != null) {
60+
courseDb.putDetailedCourse(receivedCourse);
61+
62+
final LocalExerciseStatus status = LocalExerciseStatus.get(receivedCourse.getExercises());
63+
64+
if (!status.downloadableCompleted.isEmpty()) {
65+
List<Exercise> emptyList = Collections.emptyList();
66+
DownloadOrUpdateExercisesDialog.display(emptyList, status.downloadableCompleted, emptyList);
67+
} else {
68+
dialogs.displayMessage("No completed exercises to download.\nDid you only close them and not delete them?");
69+
}
6070
}
6171
}
6272

@@ -69,7 +79,6 @@ public void bgTaskFailed(Throwable ex) {
6979
dialogs.displayError("Failed to check for new exercises.\n" + ServerErrorHelper.getServerExceptionMsg(ex));
7080
}
7181
});
72-
action.run();
7382
}
7483

7584
public static class InvokedEvent implements TmcEvent {
@@ -80,4 +89,4 @@ public InvokedEvent(Course currentCourse) {
8089
this.course = currentCourse;
8190
}
8291
}
83-
}
92+
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
* Refreshes the course list in the background.
2323
*/
2424
public final class RefreshCoursesAction {
25+
2526
private final static Logger log = Logger.getLogger(RefreshCoursesAction.class.getName());
2627

2728
private CourseDb courseDb;
2829
private ConvenientDialogDisplayer dialogs;
29-
30+
3031
private BgTaskListenerList<List<Course>> listeners;
3132

3233
public RefreshCoursesAction() {
@@ -48,9 +49,9 @@ public RefreshCoursesAction addListener(BgTaskListener<List<Course>> listener) {
4849
}
4950

5051
public void run() {
51-
log.warning("Running list courses");
52+
log.log(Level.INFO, "Running list courses");
5253
Callable<List<Course>> courseListTask = TmcCore.get().listCourses(ProgressObserver.NULL_OBSERVER);
53-
54+
5455
BgTask.start("Refreshing course list", courseListTask, new BgTaskListener<List<Course>>() {
5556

5657
@Override
@@ -86,7 +87,7 @@ public void bgTaskFailed(Throwable ex) {
8687
listeners.bgTaskFailed(ex);
8788
}
8889
});
89-
90+
9091
} else {
9192
listeners.bgTaskReady(courses);
9293
}
@@ -99,13 +100,14 @@ public void bgTaskCancelled() {
99100

100101
@Override
101102
public void bgTaskFailed(Throwable ex) {
102-
log.log(Level.WARNING, "Failed to download course list.", ex);
103+
log.log(Level.INFO, "Failed to download course list.", ex);
103104
listeners.bgTaskFailed(ex);
104105
}
105106
});
106107
}
107108

108109
private class DefaultListener implements BgTaskListener<List<Course>> {
110+
109111
private final boolean showDialogOnError;
110112
private final boolean updateCourseDb;
111113

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

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

3+
import fi.helsinki.cs.tmc.core.exceptions.TmcCoreException;
4+
35
import java.util.concurrent.Callable;
46
import java.util.concurrent.Future;
57
import javax.swing.SwingUtilities;
@@ -15,17 +17,17 @@
1517
* also {@link Cancellable}.
1618
*/
1719
public class BgTask<V> implements CancellableCallable<V> {
18-
20+
1921
private RequestProcessor requestProcessor;
2022
private String label;
2123
private BgTaskListener<? super V> listener;
2224
private Callable<V> callable;
2325
private ProgressHandle progressHandle;
24-
26+
2527
private final Object cancelLock = new Object();
2628
private boolean cancelled;
2729
private Thread executingThread;
28-
30+
2931
public static <V> Future<V> start(String label, Callable<V> callable) {
3032
return new BgTask<V>(label, callable).start();
3133
}
@@ -43,7 +45,7 @@ public static Future<Object> start(String label, Runnable runnable, BgTaskListen
4345
Callable<Object> callable = runnableToCallable(runnable);
4446
return start(label, callable, listener);
4547
}
46-
48+
4749
private static Callable<Object> runnableToCallable(final Runnable runnable) {
4850
if (runnable instanceof Cancellable) {
4951
return new CancellableCallable<Object>() {
@@ -72,15 +74,15 @@ public Object call() throws Exception {
7274
public BgTask(String label, Callable<V> callable) {
7375
this(label, callable, EmptyBgTaskListener.get());
7476
}
75-
77+
7678
public BgTask(String label, Callable<V> callable, BgTaskListener<? super V> listener) {
7779
this.requestProcessor = TmcRequestProcessor.instance;
7880
this.label = label;
7981
this.listener = listener;
8082
this.callable = callable;
8183
this.progressHandle = null;
8284
}
83-
85+
8486
public Future<V> start() {
8587
return requestProcessor.submit(this);
8688
}
@@ -104,11 +106,11 @@ public void run() {
104106
executingThread = Thread.currentThread();
105107
}
106108
}
107-
109+
108110
if (progressHandle == null) {
109111
progressHandle = ProgressHandleFactory.createSystemHandle(label, this);
110112
}
111-
113+
112114
progressHandle.start();
113115
try {
114116
final V result = callable.call();
@@ -128,6 +130,14 @@ public void run() {
128130
}
129131
});
130132
return null;
133+
} catch (final Exception ex) {
134+
:wingUtilities.invokeLater(new Runnable() {
135+
@Override
136+
public void run() {
137+
listener.bgTaskFailed(ex);
138+
}
139+
});
140+
return null;
131141
} catch (final Throwable ex) {
132142
SwingUtilities.invokeLater(new Runnable() {
133143
@Override

0 commit comments

Comments
 (0)