Skip to content

Commit 1322387

Browse files
committed
Add a button to tmc menu where students can open closed projects
1 parent 7d5c72d commit 1322387

11 files changed

+1538
-19
lines changed

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

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import fi.helsinki.cs.tmc.model.CourseDb;
77
import fi.helsinki.cs.tmc.model.ProjectMediator;
88
import fi.helsinki.cs.tmc.model.TmcProjectInfo;
9+
import fi.helsinki.cs.tmc.ui.OpenClosedExercisesDialog;
910
import fi.helsinki.cs.tmc.ui.TmcNotificationDisplayer;
1011

1112
import java.awt.event.ActionEvent;
@@ -42,23 +43,27 @@ public void run() {
4243
projects.callWhenProjectsCompletelyOpened(new Runnable() {
4344
@Override
4445
public void run() {
45-
List<Exercise> unopenedExercises = new ArrayList<Exercise>();
46-
for (Exercise ex : courseDb.getCurrentCourseExercises()) {
47-
TmcProjectInfo project = projects.tryGetProjectForExercise(ex);
48-
if (project != null && !projects.isProjectOpen(project)) {
49-
unopenedExercises.add(ex);
50-
}
51-
}
52-
53-
if (!unopenedExercises.isEmpty()) {
46+
List<Exercise> unopenedExercises = unopenedExercises();
47+
if (countUncompleted(unopenedExercises) > 0) {
5448
showNotification(unopenedExercises);
5549
}
5650
}
5751
});
5852
}
53+
54+
private List<Exercise> unopenedExercises() {
55+
List<Exercise> unopenedExercises = new ArrayList<>();
56+
for (Exercise ex : courseDb.getCurrentCourseExercises()) {
57+
TmcProjectInfo project = projects.tryGetProjectForExercise(ex);
58+
if (project != null && !projects.isProjectOpen(project)) {
59+
unopenedExercises.add(ex);
60+
}
61+
}
62+
return unopenedExercises;
63+
}
5964

6065
private void showNotification(List<Exercise> unopenedExercises) {
61-
int count = unopenedExercises.size();
66+
int count = countUncompleted(unopenedExercises);
6267
String msg;
6368
String prompt;
6469
if (count == 1) {
@@ -68,19 +73,24 @@ private void showNotification(List<Exercise> unopenedExercises) {
6873
msg = "There are " + count + " exercises that are downloaded but not opened.";
6974
prompt = "Click here to open them.";
7075
}
71-
notifier.notify(NOTIFIER_TOKEN, msg, getNotificationIcon(), prompt, openAction(unopenedExercises), NotificationDisplayer.Priority.LOW);
76+
notifier.notify(NOTIFIER_TOKEN, msg, getNotificationIcon(), prompt, openAction(), NotificationDisplayer.Priority.LOW);
7277
}
7378

74-
private ActionListener openAction(final List<Exercise> exercises) {
79+
private int countUncompleted(List<Exercise> unopenedExercises) {
80+
int count = 0;
81+
for (Exercise ex : unopenedExercises) {
82+
if (!ex.isCompleted() && !ex.hasDeadlinePassed()) {
83+
count++;
84+
}
85+
}
86+
return count;
87+
}
88+
89+
private ActionListener openAction() {
7590
return new ActionListener() {
7691
@Override
7792
public void actionPerformed(ActionEvent e) {
78-
for (Exercise ex : exercises) {
79-
TmcProjectInfo project = projects.tryGetProjectForExercise(ex);
80-
if (project != null && !projects.isProjectOpen(project)) {
81-
projects.openProject(project);
82-
}
83-
}
93+
OpenClosedExercisesDialog.display(unopenedExercises());
8494
}
8595
};
8696
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package fi.helsinki.cs.tmc.actions;
2+
3+
import fi.helsinki.cs.tmc.model.ProjectMediator;
4+
import fi.helsinki.cs.tmc.ui.TmcNotificationDisplayer;
5+
import org.openide.util.ImageUtilities;
6+
7+
public class CheckProjectCount {
8+
private final ProjectMediator projects;
9+
private final TmcNotificationDisplayer notifyer;
10+
private static final int DESIRED_COUNT = 50;
11+
12+
public CheckProjectCount() {
13+
this.projects = ProjectMediator.getInstance();
14+
this.notifyer = TmcNotificationDisplayer.getDefault();
15+
}
16+
17+
public void checkAndNotifyIfOver() {
18+
if (this.getProjectCount() > DESIRED_COUNT) {
19+
this.notifyer().notify("Too many projects open!", ImageUtilities.loadImageIcon("fi/helsinki/cs/tmc/ui/infobubble.png", false), "Please close some projects to make Netbeans faster.", null);
20+
}
21+
}
22+
23+
public int getProjectCount() {
24+
return this.projects.getOpenProjects().size();
25+
}
26+
27+
private TmcNotificationDisplayer notifyer() {
28+
return this.notifyer;
29+
}
30+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public void bgTaskFailed(Throwable ex) {
109109
@Override
110110
public void bgTaskReady(Collection<TmcProjectInfo> projects) {
111111
projectMediator.openProjects(projects);
112+
new CheckProjectCount().checkAndNotifyIfOver();
112113
}
113114

114115
@Override
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package fi.helsinki.cs.tmc.actions;
2+
3+
import fi.helsinki.cs.tmc.core.domain.Exercise;
4+
import fi.helsinki.cs.tmc.model.ProjectMediator;
5+
import fi.helsinki.cs.tmc.model.TmcProjectInfo;
6+
import fi.helsinki.cs.tmc.utilities.BgTask;
7+
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
import java.util.concurrent.Callable;
11+
12+
public class OpenClosedExercisesAction {
13+
private final ProjectMediator projects;
14+
15+
public OpenClosedExercisesAction() {
16+
this.projects = ProjectMediator.getInstance();
17+
}
18+
19+
public void run(final List<Exercise> exercisesToOpen) {
20+
BgTask.start("Opening closed exercises", new Callable() {
21+
@Override
22+
public Void call() {
23+
List<Exercise> unopenedExercises = new ArrayList<>();
24+
for (Exercise ex : exercisesToOpen) {
25+
TmcProjectInfo project = projects.tryGetProjectForExercise(ex);
26+
if (project != null && !projects.isProjectOpen(project)) {
27+
unopenedExercises.add(ex);
28+
}
29+
}
30+
31+
if (!unopenedExercises.isEmpty()) {
32+
openAction(unopenedExercises);
33+
}
34+
35+
return null;
36+
}
37+
});
38+
}
39+
40+
private void openAction(final List<Exercise> exercises) {
41+
for (Exercise ex : exercises) {
42+
TmcProjectInfo project = projects.tryGetProjectForExercise(ex);
43+
if (project != null && !projects.isProjectOpen(project)) {
44+
projects.openProject(project);
45+
}
46+
}
47+
}
48+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package fi.helsinki.cs.tmc.actions;
2+
3+
import fi.helsinki.cs.tmc.core.domain.Course;
4+
import fi.helsinki.cs.tmc.model.CourseDb;
5+
import fi.helsinki.cs.tmc.model.LocalExerciseStatus;
6+
import fi.helsinki.cs.tmc.ui.OpenClosedExercisesDialog;
7+
8+
import java.awt.event.ActionEvent;
9+
import javax.swing.AbstractAction;
10+
import org.openide.awt.ActionID;
11+
import org.openide.awt.ActionReference;
12+
import org.openide.awt.ActionReferences;
13+
import org.openide.awt.ActionRegistration;
14+
import org.openide.util.NbBundle;
15+
16+
@ActionID(category = "TMC",
17+
id = "fi.helsinki.cs.tmc.actions.OpenClosedExercisesFromMenu")
18+
@ActionRegistration(displayName = "#CTL_OpenClosedExercisesFromMenu")
19+
@ActionReferences({
20+
@ActionReference(path = "Menu/TM&C", position = -43)
21+
})
22+
@NbBundle.Messages("CTL_OpenClosedExercisesFromMenu=&Open closed exercises")
23+
public class OpenClosedExercisesFromMenu extends AbstractAction {
24+
25+
@Override
26+
public void actionPerformed(ActionEvent e) {
27+
Course course = CourseDb.getInstance().getCurrentCourse();
28+
final LocalExerciseStatus status = LocalExerciseStatus.get(course.getExercises());
29+
OpenClosedExercisesDialog.display(status.closed);
30+
}
31+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import fi.helsinki.cs.tmc.coreimpl.TmcCoreSettingsImpl;
1010
import fi.helsinki.cs.tmc.langs.util.TaskExecutorImpl;
1111
import fi.helsinki.cs.tmc.model.CourseDb;
12-
import fi.helsinki.cs.tmc.model.PushEventListener;
1312
import fi.helsinki.cs.tmc.spywareLocal.SpywareFacade;
1413
import fi.helsinki.cs.tmc.ui.LoginDialog;
1514
import fi.helsinki.cs.tmc.utilities.BgTaskListener;
@@ -90,6 +89,7 @@ public void bgTaskReady(List<Course> result) {
9089
if (CheckForUnopenedExercises.shouldRunOnStartup()) {
9190
new CheckForUnopenedExercises().run();
9291
}
92+
new CheckProjectCount().checkAndNotifyIfOver();
9393
}
9494

9595
@Override

tmc-plugin/src/fi/helsinki/cs/tmc/ui/Bundle.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,11 @@ PreferencesPanel.resolveDependencies.toolTipText=Leave this on if you want to be
7777
PreferencesPanel.resolveDependencies.text=Ensure Netbeans is configured to resolve project dependencies
7878
PreferencesPanel.sendDiagnostics.toolTipText=This information helps us to helps us to fix crashes and other problems with this plugin.
7979
PreferencesPanel.sendDiagnostics.text=Automatically send crash reports and diagnostics for plugin development
80+
OpenClosedExercisesDialog.closeButton.text=Close
81+
OpenClosedExercisesDialog.title=Open closed exercises
82+
OpenClosedExercisesDialog.uncompletedLabel.text=Uncompleted exercises
83+
OpenClosedExercisesDialog.titleLabel.text=Please select which exercises to open:
84+
OpenClosedExercisesDialog.completedOrExpiredLabel.text=Completed / expired exercises
85+
OpenClosedExercisesDialog.openExercisesButton.text=Open exercises
86+
OpenClosedExercisesDialog.selectCompletedOrExpiredButton.text=Select all
87+
OpenClosedExercisesDialog.selectUncompletedButton.text=Select all

0 commit comments

Comments
 (0)