|
@@ -41,7 +41,6 @@ import java.util.Set;
|
41
|
41
|
|
42
|
42
|
import javax.inject.Inject;
|
43
|
43
|
import javax.inject.Singleton;
|
44
|
|
-import javax.swing.Icon;
|
45
|
44
|
import javax.swing.JLabel;
|
46
|
45
|
import javax.swing.JPopupMenu;
|
47
|
46
|
|
|
@@ -55,8 +54,6 @@ public class ErrorPanel extends StatusbarPopupPanel<JLabel> {
|
55
|
54
|
|
56
|
55
|
/** Serial version UID. */
|
57
|
56
|
private static final long serialVersionUID = 2;
|
58
|
|
- /** non error state image icon. */
|
59
|
|
- private final Icon defaultIcon;
|
60
|
57
|
/** Parent window that will own popups. */
|
61
|
58
|
private final Window parentWindow;
|
62
|
59
|
/** The manager to use to retrieve icons. */
|
|
@@ -67,11 +64,6 @@ public class ErrorPanel extends StatusbarPopupPanel<JLabel> {
|
67
|
64
|
private final JPopupMenu menu;
|
68
|
65
|
/** Error list dialog provider. */
|
69
|
66
|
private final DialogProvider<ErrorsDialog> errorListDialogProvider;
|
70
|
|
- /** The event bus to listen to error changes on .*/
|
71
|
|
- private final DMDircMBassador eventBus;
|
72
|
|
- /** Currently showing error level. */
|
73
|
|
- private ErrorLevel errorLevel;
|
74
|
|
- private boolean hasBeenVisible;
|
75
|
67
|
|
76
|
68
|
/**
|
77
|
69
|
* Creates a new ErrorPanel for the specified status bar.
|
|
@@ -92,12 +84,8 @@ public class ErrorPanel extends StatusbarPopupPanel<JLabel> {
|
92
|
84
|
this.iconManager = iconManager;
|
93
|
85
|
this.errorListDialogProvider = errorListDialogProvider;
|
94
|
86
|
this.errorManager = errorManager;
|
95
|
|
- this.eventBus = eventBus;
|
96
|
|
- defaultIcon = iconManager.getIcon("normal");
|
97
|
87
|
|
98
|
88
|
menu = new JPopupMenu();
|
99
|
|
- label.setIcon(defaultIcon);
|
100
|
|
- setVisible(errorManager.getErrorCount() > 0);
|
101
|
89
|
menu.add(JMenuItemBuilder.create().setText("Open")
|
102
|
90
|
.addActionListener(e -> errorListDialogProvider.displayOrRequestFocus()).build());
|
103
|
91
|
menu.add(JMenuItemBuilder.create()
|
|
@@ -105,6 +93,7 @@ public class ErrorPanel extends StatusbarPopupPanel<JLabel> {
|
105
|
93
|
.addActionListener(e -> errorManager.getErrors().forEach(errorManager::deleteError))
|
106
|
94
|
.build());
|
107
|
95
|
checkErrors();
|
|
96
|
+ eventBus.subscribe(this);
|
108
|
97
|
}
|
109
|
98
|
|
110
|
99
|
@Override
|
|
@@ -112,15 +101,6 @@ public class ErrorPanel extends StatusbarPopupPanel<JLabel> {
|
112
|
101
|
return new ErrorPopup(errorManager, iconManager, this, parentWindow);
|
113
|
102
|
}
|
114
|
103
|
|
115
|
|
- @Override
|
116
|
|
- public void setVisible(final boolean visible) {
|
117
|
|
- if (!hasBeenVisible) {
|
118
|
|
- hasBeenVisible = true;
|
119
|
|
- eventBus.subscribe(this);
|
120
|
|
- }
|
121
|
|
- super.setVisible(visible);
|
122
|
|
- }
|
123
|
|
-
|
124
|
104
|
@Handler(invocation = EdtHandlerInvocation.class)
|
125
|
105
|
public void errorAdded(final NonFatalProgramErrorEvent event) {
|
126
|
106
|
checkErrors();
|
|
@@ -133,20 +113,10 @@ public class ErrorPanel extends StatusbarPopupPanel<JLabel> {
|
133
|
113
|
|
134
|
114
|
/** Checks all the errors for the most significant error. */
|
135
|
115
|
private void checkErrors() {
|
136
|
|
- label.setIcon(defaultIcon);
|
137
|
|
- errorLevel = null;
|
138
|
116
|
final Set<ProgramError> errors = errorManager.getErrors();
|
139
|
|
-
|
140
|
|
- if (errors.isEmpty()) {
|
141
|
|
- setVisible(false);
|
142
|
|
- } else {
|
143
|
|
- errors.stream().filter(error -> errorLevel == null ||
|
144
|
|
- !error.getLevel().moreImportant(errorLevel)).forEach(error -> {
|
145
|
|
- errorLevel = error.getLevel();
|
146
|
|
- label.setIcon(iconManager.getIcon(errorLevel.getIcon()));
|
147
|
|
- });
|
148
|
|
- setVisible(true);
|
149
|
|
- }
|
|
117
|
+ label.setIcon(iconManager.getIcon(errors.stream().map(ProgramError::getLevel)
|
|
118
|
+ .reduce(ErrorLevel.UNKNOWN, ErrorLevel::getMoreImportant).getIcon()));
|
|
119
|
+ setVisible(!errors.isEmpty());
|
150
|
120
|
}
|
151
|
121
|
|
152
|
122
|
@Override
|