Skip to content

Commit c1eed2c

Browse files
committed
Show popup if student has 50 or more projects open
1 parent c69e592 commit c1eed2c

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed
Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,59 @@
11
package fi.helsinki.cs.tmc.actions;
22

33
import fi.helsinki.cs.tmc.model.ProjectMediator;
4+
import fi.helsinki.cs.tmc.ui.ConvenientDialogDisplayer;
45
import fi.helsinki.cs.tmc.ui.TmcNotificationDisplayer;
6+
7+
import javax.swing.ImageIcon;
8+
9+
import org.openide.NotifyDescriptor;
510
import org.openide.util.ImageUtilities;
611

712
public class CheckProjectCount {
813
private final ProjectMediator projects;
914
private final TmcNotificationDisplayer notifyer;
10-
private static final int DESIRED_COUNT = 50;
15+
private final ConvenientDialogDisplayer displayer;
16+
private static final int BALLOON_LIMIT = 20;
17+
private static final int POPUP_LIMIT = 50;
1118

1219
public CheckProjectCount() {
1320
this.projects = ProjectMediator.getInstance();
1421
this.notifyer = TmcNotificationDisplayer.getDefault();
22+
this.displayer = new ConvenientDialogDisplayer();
1523
}
1624

1725
public void checkAndNotifyIfOver() {
18-
if (this.getProjectCount() > DESIRED_COUNT) {
19-
this.notifyer().notify("Netbeans slow? Close some projects!", ImageUtilities.loadImageIcon("fi/helsinki/cs/tmc/ui/infobubble.png", false), "Right-click completed projects from the Projects -sidebar on the left and select 'Close project'.", null);
26+
if (this.getProjectCount() >= POPUP_LIMIT) {
27+
this.displayPopup();
28+
} else if (this.getProjectCount() >= BALLOON_LIMIT) {
29+
this.displayBalloon();
2030
}
2131
}
2232

2333
public int getProjectCount() {
2434
return this.projects.getOpenProjects().size();
2535
}
2636

27-
private TmcNotificationDisplayer notifyer() {
28-
return this.notifyer;
37+
private void displayPopup() {
38+
StringBuilder htmlBuilder = new StringBuilder();
39+
htmlBuilder.append("<html><body>");
40+
htmlBuilder.append("<h1>Too many projects open!</h1>");
41+
htmlBuilder.append("<div>Netbeans does background processing on open projects. When there's many projects open, Netbeans is slowed down significantly.<br>Please close some projects to make Netbeans faster. Instructions for closing projects:</div>");
42+
htmlBuilder.append("<ol>");
43+
htmlBuilder.append("<li>Right click the project you want to close on the \"Projects\"-sidebar on the left.</li>");
44+
htmlBuilder.append("<li>Select \"Close project\".</li>");
45+
htmlBuilder.append("<li>You can select multiple exercises at once by pressing down the shift button on your keyboard.<br>While pressing shift, select the first and the last exercise of the ones you want to close.</li>");
46+
htmlBuilder.append("</ol>");
47+
htmlBuilder.append("</body></html>");
48+
String errorMsg = htmlBuilder.toString();
49+
this.displayer.showDialog(errorMsg, NotifyDescriptor.WARNING_MESSAGE, "/fi/helsinki/cs/tmc/ui/close_projects.png");
2950
}
51+
52+
private void displayBalloon() {
53+
final String header = "Netbeans slow? Close some projects!";
54+
final ImageIcon icon = ImageUtilities.loadImageIcon("fi/helsinki/cs/tmc/ui/infobubble.png", false);
55+
final String info = "Right-click completed projects from the Projects -sidebar on the left and select 'Close project'.";
56+
this.notifyer.notify(header, icon, info, null);
57+
}
58+
3059
}

tmc-plugin/src/fi/helsinki/cs/tmc/ui/ConvenientDialogDisplayer.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.openide.DialogDescriptor;
1111
import org.openide.DialogDisplayer;
1212
import org.openide.NotifyDescriptor;
13+
import org.openide.util.ImageUtilities;
1314

1415
public class ConvenientDialogDisplayer {
1516
private static ConvenientDialogDisplayer defaultDisplayer;
@@ -57,7 +58,14 @@ protected void displayMessage(String msg, int notifyType) {
5758
public void showDialog(Component content, int notifyType) {
5859
showDialog(content, notifyType, "", true);
5960
}
60-
61+
62+
public void showDialog(String msg, int notifyType, String imgPath) {
63+
ImageIcon img = ImageUtilities.loadImageIcon(imgPath, false);
64+
JLabel content = new JLabel(msg, img, JLabel.CENTER);
65+
content.setIconTextGap(50);
66+
showDialog(content, notifyType, "", true);
67+
}
68+
6169
public void showDialog(Component content, int notifyType, String title, boolean modal) {
6270
DialogDescriptor desc = new DialogDescriptor(content,title);
6371
desc.setModal(modal);
30.5 KB
Loading

0 commit comments

Comments
 (0)