|
1 | 1 | package fi.helsinki.cs.tmc.actions;
|
2 | 2 |
|
3 | 3 | import fi.helsinki.cs.tmc.model.ProjectMediator;
|
| 4 | +import fi.helsinki.cs.tmc.ui.ConvenientDialogDisplayer; |
4 | 5 | import fi.helsinki.cs.tmc.ui.TmcNotificationDisplayer;
|
| 6 | + |
| 7 | +import javax.swing.ImageIcon; |
| 8 | + |
| 9 | +import org.openide.NotifyDescriptor; |
5 | 10 | import org.openide.util.ImageUtilities;
|
6 | 11 |
|
7 | 12 | public class CheckProjectCount {
|
8 | 13 | private final ProjectMediator projects;
|
9 | 14 | 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; |
11 | 18 |
|
12 | 19 | public CheckProjectCount() {
|
13 | 20 | this.projects = ProjectMediator.getInstance();
|
14 | 21 | this.notifyer = TmcNotificationDisplayer.getDefault();
|
| 22 | + this.displayer = new ConvenientDialogDisplayer(); |
15 | 23 | }
|
16 | 24 |
|
17 | 25 | 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(); |
20 | 30 | }
|
21 | 31 | }
|
22 | 32 |
|
23 | 33 | public int getProjectCount() {
|
24 | 34 | return this.projects.getOpenProjects().size();
|
25 | 35 | }
|
26 | 36 |
|
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"); |
29 | 50 | }
|
| 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 | + |
30 | 59 | }
|
0 commit comments