16
16
17
17
import com .google .common .collect .Lists ;
18
18
import com .google .common .util .concurrent .ListenableFuture ;
19
+ import fi .helsinki .cs .tmc .model .CourseDb ;
20
+ import java .util .ArrayList ;
19
21
20
22
import java .util .Collection ;
21
23
import java .util .List ;
22
24
import java .util .logging .Logger ;
25
+ import javax .swing .SwingUtilities ;
23
26
24
27
/**
25
28
* Downloads and opens the given exercises in the background.
@@ -31,6 +34,7 @@ public class DownloadExercisesAction {
31
34
private final List <Exercise > exercisesToDownload ;
32
35
private final TmcCore tmcCore ;
33
36
private final NbTmcSettings settings ;
37
+ private CourseDb courseDb ;
34
38
35
39
private ProjectMediator projectMediator ;
36
40
private ConvenientDialogDisplayer dialogs ;
@@ -42,45 +46,52 @@ public class DownloadExercisesAction {
42
46
public DownloadExercisesAction (List <Exercise > exercisesToOpen ) {
43
47
this .projectMediator = ProjectMediator .getInstance ();
44
48
this .dialogs = ConvenientDialogDisplayer .getDefault ();
49
+ this .courseDb = CourseDb .getInstance ();
45
50
46
51
this .exercisesToDownload = exercisesToOpen ;
47
52
this .tmcCore = TmcCoreSingleton .getInstance ();
48
53
this .settings = NbTmcSettings .getDefault ();
49
54
}
50
55
51
56
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);
54
59
55
60
for (final Exercise exercise : exercisesToDownload ) {
56
- startDownloading (exercise , aggregator );
61
+ startDownloading (exercise , whenDownloadsFinished );
57
62
}
58
63
}
59
64
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 > >() {
62
67
63
68
ListenableFuture <List <Exercise >> dlFuture ;
69
+
64
70
@ Override
65
- public Void call () throws Exception {
71
+ public List < Exercise > call () throws Exception {
66
72
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 () ;
69
75
}
70
76
71
77
@ Override
72
78
public boolean cancel () {
73
79
logger .info ("Exercise download was cancelled." );
74
80
return dlFuture .cancel (true );
75
81
}
76
- });
82
+ }, listener );
77
83
}
78
84
79
- private BgTaskListener <Collection <TmcProjectInfo >> whenAllDownloadsFinished = new BgTaskListener <Collection <TmcProjectInfo >>() {
85
+ private BgTaskListener <Collection <Exercise >> whenDownloadsFinished = new BgTaskListener <Collection <Exercise >>() {
80
86
@ 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
+ }
82
93
projectMediator .openProjects (projects );
83
- logger .log (INFO , "Opening projects." );
94
+ logger .log (INFO , "2Opening projects." );
84
95
}
85
96
86
97
@ Override
@@ -94,4 +105,4 @@ public void bgTaskFailed(Throwable ex) {
94
105
dialogs .displayError ("Failed to download exercises.\n " + ServerErrorHelper .getServerExceptionMsg (ex ));
95
106
}
96
107
};
97
- }
108
+ }
0 commit comments