Skip to content

Commit 90aede0

Browse files
committed
Open projects right after downloading it
1 parent 808ea59 commit 90aede0

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616

1717
import com.google.common.collect.Lists;
1818
import com.google.common.util.concurrent.ListenableFuture;
19+
import fi.helsinki.cs.tmc.model.CourseDb;
20+
import java.util.ArrayList;
1921

2022
import java.util.Collection;
2123
import java.util.List;
2224
import java.util.logging.Logger;
25+
import javax.swing.SwingUtilities;
2326

2427
/**
2528
* Downloads and opens the given exercises in the background.
@@ -31,6 +34,7 @@ public class DownloadExercisesAction {
3134
private final List<Exercise> exercisesToDownload;
3235
private final TmcCore tmcCore;
3336
private final NbTmcSettings settings;
37+
private CourseDb courseDb;
3438

3539
private ProjectMediator projectMediator;
3640
private ConvenientDialogDisplayer dialogs;
@@ -42,45 +46,52 @@ public class DownloadExercisesAction {
4246
public DownloadExercisesAction(List<Exercise> exercisesToOpen) {
4347
this.projectMediator = ProjectMediator.getInstance();
4448
this.dialogs = ConvenientDialogDisplayer.getDefault();
49+
this.courseDb = CourseDb.getInstance();
4550

4651
this.exercisesToDownload = exercisesToOpen;
4752
this.tmcCore = TmcCoreSingleton.getInstance();
4853
this.settings = NbTmcSettings.getDefault();
4954
}
5055

5156
public void run() {
52-
final AggregatingBgTaskListener<TmcProjectInfo> aggregator
53-
= new AggregatingBgTaskListener<TmcProjectInfo>(exercisesToDownload.size(), whenAllDownloadsFinished);
57+
// final AggregatingBgTaskListener<TmcProjectInfo> aggregator
58+
// = new AggregatingBgTaskListener<TmcProjectInfo>(exercisesToDownload.size(), whenAllDownloadsFinished);
5459

5560
for (final Exercise exercise : exercisesToDownload) {
56-
startDownloading(exercise, aggregator);
61+
startDownloading(exercise, whenDownloadsFinished);
5762
}
5863
}
5964

60-
private void startDownloading(final Exercise exercise, final BgTaskListener<TmcProjectInfo> listener) {
61-
BgTask.start("Downloading " + exercise.getName(), new CancellableCallable<Void>() {
65+
private void startDownloading(final Exercise exercise, final BgTaskListener<Collection<Exercise>> listener) {
66+
BgTask.start("Downloading " + exercise.getName(), new CancellableCallable<List<Exercise>>() {
6267

6368
ListenableFuture<List<Exercise>> dlFuture;
69+
6470
@Override
65-
public Void call() throws Exception {
71+
public List<Exercise> call() throws Exception {
6672
dlFuture = tmcCore.downloadExercises(Lists.newArrayList(exercise));
67-
dlFuture.get(); // block the call till the task has completed.
68-
return null;
73+
74+
return dlFuture.get();
6975
}
7076

7177
@Override
7278
public boolean cancel() {
7379
logger.info("Exercise download was cancelled.");
7480
return dlFuture.cancel(true);
7581
}
76-
});
82+
}, listener);
7783
}
7884

79-
private BgTaskListener<Collection<TmcProjectInfo>> whenAllDownloadsFinished = new BgTaskListener<Collection<TmcProjectInfo>>() {
85+
private BgTaskListener<Collection<Exercise>> whenDownloadsFinished = new BgTaskListener<Collection<Exercise>>() {
8086
@Override
81-
public void bgTaskReady(Collection<TmcProjectInfo> projects) {
87+
public void bgTaskReady(Collection<Exercise> exercises) {
88+
logger.log(INFO, "1Opening projects.");
89+
List<TmcProjectInfo> projects = new ArrayList<TmcProjectInfo>(exercises.size());
90+
for (Exercise ex : exercises) {
91+
projects.add(projectMediator.tryGetProjectForExercise(ex));
92+
}
8293
projectMediator.openProjects(projects);
83-
logger.log(INFO, "Opening projects.");
94+
logger.log(INFO, "2Opening projects.");
8495
}
8596

8697
@Override
@@ -94,4 +105,4 @@ public void bgTaskFailed(Throwable ex) {
94105
dialogs.displayError("Failed to download exercises.\n" + ServerErrorHelper.getServerExceptionMsg(ex));
95106
}
96107
};
97-
}
108+
}

0 commit comments

Comments
 (0)