Skip to content

Commit 3e0fafa

Browse files
committed
Update exercises with core
1 parent 6824e43 commit 3e0fafa

File tree

4 files changed

+22
-30
lines changed

4 files changed

+22
-30
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static void startTimer() {
5050
timer.start();
5151
}
5252

53-
private static final TmcNotificationDisplayer.SingletonToken notifierToken = TmcNotificationDisplayer.createSingletonToken();
53+
private static final TmcNotificationDisplayer.SingletonToken NOTIFIER_TOKEN = TmcNotificationDisplayer.createSingletonToken();
5454

5555
private CourseDb courseDb;
5656
private TmcNotificationDisplayer notifier;
@@ -158,7 +158,7 @@ private void displayNotification(LocalExerciseStatus status, ActionListener acti
158158

159159
String prompt = "Click here to " + TmcStringUtils.joinCommaAnd(actions) + ".";
160160

161-
notifier.notify(notifierToken, msg, getNotificationIcon(), prompt, action);
161+
notifier.notify(NOTIFIER_TOKEN, msg, getNotificationIcon(), prompt, action);
162162
}
163163

164164
private Icon getNotificationIcon() {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
import fi.helsinki.cs.tmc.utilities.TmcSwingUtilities;
1717

1818
import com.google.common.collect.Lists;
19-
import java.lang.reflect.InvocationTargetException;
2019
import java.util.Collection;
2120
import java.util.List;
2221
import java.util.concurrent.Callable;
2322
import java.util.logging.Level;
2423
import java.util.logging.Logger;
25-
import javax.swing.SwingUtilities;
2624
import org.openide.util.Exceptions;
2725

2826
/**

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

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

3+
import fi.helsinki.cs.tmc.core.TmcCore;
34
import fi.helsinki.cs.tmc.core.communication.TmcServerCommunicationTaskFactory;
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;
79
import fi.helsinki.cs.tmc.events.TmcEventBus;
@@ -15,13 +17,15 @@
1517
import fi.helsinki.cs.tmc.utilities.BgTaskListener;
1618
import fi.helsinki.cs.tmc.utilities.zip.NbProjectUnzipper;
1719

20+
import com.google.common.collect.ImmutableList;
1821
import java.awt.event.ActionEvent;
1922
import java.awt.event.ActionListener;
2023
import java.io.File;
2124
import java.io.IOException;
2225
import java.util.ArrayList;
2326
import java.util.Collection;
2427
import java.util.List;
28+
import java.util.concurrent.Callable;
2529
import java.util.logging.Logger;
2630

2731
public class UpdateExercisesAction implements ActionListener {
@@ -77,27 +81,14 @@ public void bgTaskFailed(Throwable ex) {
7781
final File projectDir = projectMediator.getProjectDirForExercise(exercise);
7882
eventBus.post(new InvokedEvent(exercise));
7983

80-
BgTask.start("Downloading " + exercise.getName(), new TmcServerCommunicationTaskFactory().getDownloadingExerciseZipTask(exercise), new BgTaskListener<byte[]>() {
84+
Callable<List<Exercise>> downloadAndExtractExerciseTask = TmcCore.get().downloadOrUpdateExercises(ProgressObserver.NULL_OBSERVER, ImmutableList.of(exercise));
85+
BgTask.start("Downloading " + exercise.getName(), downloadAndExtractExerciseTask, new BgTaskListener<List<Exercise>>() {
8186

8287
@Override
83-
public void bgTaskReady(byte[] data) {
84-
TmcProjectInfo project = null;
85-
try {
86-
try {
87-
ExerciseUpdateOverwritingDecider overwriter = new ExerciseUpdateOverwritingDecider(projectDir);
88-
NbProjectUnzipper unzipper = new NbProjectUnzipper(overwriter);
89-
NbProjectUnzipper.Result result = unzipper.unzipProject(data, projectDir);
90-
log.info("== Exercise unzip result ==\n" + result);
91-
} catch (IOException ex) {
92-
dialogDisplayer.displayError("Failed to update project.", ex);
93-
return;
94-
}
95-
courseDb.exerciseDownloaded(exercise);
96-
97-
project = projectMediator.tryGetProjectForExercise(exercise);
98-
} finally {
99-
projectOpener.bgTaskReady(project);
100-
}
88+
public void bgTaskReady(List<Exercise> exercises) {
89+
courseDb.exerciseDownloaded(exercise);
90+
TmcProjectInfo project = projectMediator.tryGetProjectForExercise(exercise);
91+
projectOpener.bgTaskReady(project);
10192
}
10293

10394
@Override

tmc-plugin/src/fi/helsinki/cs/tmc/spyware/eventsources/WindowStatechangesEventSource.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,15 @@ private String toStringWithObjects(Object object) {
171171
return ((Mode) object).getName();
172172
} else if (object instanceof Accessible) {
173173
try {
174-
Accessible acc = (Accessible) object;
175-
if (acc != null) {
176-
AccessibleContext context = acc.getAccessibleContext();
177-
if (context != null) {
178-
String str = context.getAccessibleName();
179-
if (str != null) {
180-
return str;
174+
if (object != null) {
175+
Accessible acc = (Accessible) object;
176+
if (acc != null) {
177+
AccessibleContext context = acc.getAccessibleContext();
178+
if (context != null) {
179+
String str = context.getAccessibleName();
180+
if (str != null) {
181+
return str;
182+
}
181183
}
182184
}
183185
}
@@ -188,6 +190,7 @@ private String toStringWithObjects(Object object) {
188190
}
189191
return object.toString();
190192
} catch (Exception e) {
193+
log.log(Level.WARNING, "Error in window state change event source listener:", e);
191194
return "error";
192195
}
193196
}

0 commit comments

Comments
 (0)