Browse Source

Initial work on new errors dialog.

pull/276/head
Greg Holmes 9 years ago
parent
commit
0da4cd84d4

+ 0
- 10
ui_swing/src/com/dmdirc/addons/ui_swing/SwingManager.java View File

@@ -26,12 +26,10 @@ import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.addons.ui_swing.components.menubar.MenuBar;
27 27
 import com.dmdirc.addons.ui_swing.components.statusbar.FeedbackNag;
28 28
 import com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar;
29
-import com.dmdirc.addons.ui_swing.dialogs.error.ErrorListDialog;
30 29
 import com.dmdirc.addons.ui_swing.dialogs.url.URLDialogFactory;
31 30
 import com.dmdirc.addons.ui_swing.events.SwingEventBus;
32 31
 import com.dmdirc.addons.ui_swing.framemanager.ctrltab.CtrlTabWindowManager;
33 32
 import com.dmdirc.addons.ui_swing.framemanager.tree.TreeFrameManagerProvider;
34
-import com.dmdirc.addons.ui_swing.injection.DialogProvider;
35 33
 import com.dmdirc.addons.ui_swing.wizard.firstrun.FirstRunWizardExecutor;
36 34
 import com.dmdirc.events.FeedbackNagEvent;
37 35
 import com.dmdirc.events.FirstRunEvent;
@@ -43,7 +41,6 @@ import java.awt.Window;
43 41
 import javax.inject.Inject;
44 42
 import javax.inject.Provider;
45 43
 import javax.inject.Singleton;
46
-import javax.swing.SwingUtilities;
47 44
 
48 45
 import net.engio.mbassy.listener.Handler;
49 46
 
@@ -79,8 +76,6 @@ public class SwingManager {
79 76
     private final Provider<MainFrame> mainFrameProvider;
80 77
     /** Swing window manager. */
81 78
     private final Provider<SwingWindowManager> swingWindowManager;
82
-    /** Error list dialog provider. */
83
-    private final DialogProvider<ErrorListDialog> errorListDialogProvider;
84 79
     /** The main frame of the Swing UI. */
85 80
     private MainFrame mainFrame;
86 81
     /** Swing UI initialiser. */
@@ -103,7 +98,6 @@ public class SwingManager {
103 98
      * @param swingEventBus           The swing event bus to listen on for swing events.
104 99
      * @param treeProvider            Provider to use for tree-based frame managers.
105 100
      * @param swingWindowManager      Swing window manager
106
-     * @param errorListDialogProvider Error list dialog provider
107 101
      * @param uiInitialiser           Initialiser to set system/swing settings.
108 102
      */
109 103
     @Inject
@@ -122,7 +116,6 @@ public class SwingManager {
122 116
             final SwingEventBus swingEventBus,
123 117
             final TreeFrameManagerProvider treeProvider,
124 118
             final Provider<SwingWindowManager> swingWindowManager,
125
-            final DialogProvider<ErrorListDialog> errorListDialogProvider,
126 119
             final SwingUIInitialiser uiInitialiser) {
127 120
         this.windowFactory = windowFactory;
128 121
         this.windowManager = windowManager;
@@ -138,7 +131,6 @@ public class SwingManager {
138 131
         this.swingEventBus = swingEventBus;
139 132
         this.treeProvider = treeProvider;
140 133
         this.swingWindowManager = swingWindowManager;
141
-        this.errorListDialogProvider = errorListDialogProvider;
142 134
         this.uiInitialiser = uiInitialiser;
143 135
     }
144 136
 
@@ -160,7 +152,6 @@ public class SwingManager {
160 152
         eventBus.subscribe(this);
161 153
         eventBus.subscribe(mainFrame);
162 154
         eventBus.subscribe(linkHandler);
163
-        SwingUtilities.invokeLater(() -> errorListDialogProvider.get().load());
164 155
     }
165 156
 
166 157
     /**
@@ -170,7 +161,6 @@ public class SwingManager {
170 161
         swingWindowManager.get().getTopLevelWindows().forEach(Window::dispose);
171 162
         windowManager.removeListener(windowFactory.get());
172 163
         windowFactory.get().dispose();
173
-        SwingUtilities.invokeLater(() -> errorListDialogProvider.get().dispose());
174 164
         swingEventBus.unsubscribe(mainFrame);
175 165
         swingEventBus.unsubscribe(ctrlTabManager);
176 166
         mainFrame.dispose();

+ 5
- 5
ui_swing/src/com/dmdirc/addons/ui_swing/components/statusbar/ErrorPanel.java View File

@@ -23,7 +23,7 @@
23 23
 package com.dmdirc.addons.ui_swing.components.statusbar;
24 24
 
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26
-import com.dmdirc.addons.ui_swing.dialogs.error.ErrorListDialog;
26
+import com.dmdirc.addons.ui_swing.dialogs.newerror.ErrorsDialog;
27 27
 import com.dmdirc.addons.ui_swing.injection.DialogProvider;
28 28
 import com.dmdirc.addons.ui_swing.injection.MainWindow;
29 29
 import com.dmdirc.logger.ErrorLevel;
@@ -36,7 +36,7 @@ import java.awt.Window;
36 36
 import java.awt.event.ActionEvent;
37 37
 import java.awt.event.ActionListener;
38 38
 import java.awt.event.MouseEvent;
39
-import java.util.List;
39
+import java.util.Set;
40 40
 
41 41
 import javax.inject.Inject;
42 42
 import javax.inject.Provider;
@@ -73,7 +73,7 @@ public class ErrorPanel extends StatusbarPopupPanel<JLabel> implements
73 73
     /** Show menu item. */
74 74
     private final JMenuItem show;
75 75
     /** Error list dialog provider. */
76
-    private final DialogProvider<ErrorListDialog> errorListDialogProvider;
76
+    private final DialogProvider<ErrorsDialog> errorListDialogProvider;
77 77
     /** Currently showing error level. */
78 78
     private ErrorLevel errorLevel;
79 79
 
@@ -90,7 +90,7 @@ public class ErrorPanel extends StatusbarPopupPanel<JLabel> implements
90 90
             @GlobalConfig final IconManager iconManager,
91 91
             @MainWindow final Window parentWindow,
92 92
             final Provider<SwingStatusBar> statusBar,
93
-            final DialogProvider<ErrorListDialog> errorListDialogProvider,
93
+            final DialogProvider<ErrorsDialog> errorListDialogProvider,
94 94
             final ErrorManager errorManager) {
95 95
         super(new JLabel());
96 96
 
@@ -144,7 +144,7 @@ public class ErrorPanel extends StatusbarPopupPanel<JLabel> implements
144 144
     private void checkErrors() {
145 145
         SwingUtilities.invokeLater(() -> {
146 146
             clearError();
147
-            final List<ProgramError> errors = errorManager.getErrors();
147
+            final Set<ProgramError> errors = errorManager.getErrors();
148 148
 
149 149
             if (errors.isEmpty()) {
150 150
                 setVisible(false);

+ 2
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/components/statusbar/ErrorPopup.java View File

@@ -31,7 +31,7 @@ import com.dmdirc.util.collections.MapList;
31 31
 
32 32
 import java.awt.Font;
33 33
 import java.awt.Window;
34
-import java.util.List;
34
+import java.util.Set;
35 35
 
36 36
 import javax.swing.JLabel;
37 37
 import javax.swing.JPanel;
@@ -72,7 +72,7 @@ public class ErrorPopup extends StatusbarPopupWindow {
72 72
 
73 73
     @Override
74 74
     protected void initContent(final JPanel panel) {
75
-        final List<ProgramError> errors = errorManager.getErrors();
75
+        final Set<ProgramError> errors = errorManager.getErrors();
76 76
         final MapList<ErrorLevel, ProgramError> buckets = new MapList<>();
77 77
         final MapList<ErrorReportStatus, ProgramError> statuses = new MapList<>();
78 78
 

+ 0
- 189
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/error/ErrorDetailPanel.java View File

@@ -1,189 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.addons.ui_swing.dialogs.error;
24
-
25
-import com.dmdirc.addons.ui_swing.UIUtilities;
26
-import com.dmdirc.logger.ErrorListener;
27
-import com.dmdirc.logger.ErrorManager;
28
-import com.dmdirc.logger.ProgramError;
29
-
30
-import java.text.SimpleDateFormat;
31
-import java.util.List;
32
-
33
-import javax.swing.JLabel;
34
-import javax.swing.JPanel;
35
-import javax.swing.JScrollPane;
36
-import javax.swing.JTextArea;
37
-import javax.swing.JTextField;
38
-import javax.swing.SwingUtilities;
39
-import javax.swing.text.BadLocationException;
40
-
41
-import net.miginfocom.swing.MigLayout;
42
-
43
-/**
44
- * Shows information about an error.
45
- */
46
-public final class ErrorDetailPanel extends JPanel implements ErrorListener {
47
-
48
-    /** A version number for this class. */
49
-    private static final long serialVersionUID = 3;
50
-    /** The error manager to retrieve errors from. */
51
-    private final ErrorManager errorManager;
52
-    /** Error to show. */
53
-    private ProgramError error;
54
-    /** Date field. */
55
-    private JTextField date;
56
-    /** Severity field. */
57
-    private JTextField level;
58
-    /** Report Status field. */
59
-    private JTextField reportStatus;
60
-    /** Details field. */
61
-    private JTextArea details;
62
-    /** Details scrollpane. */
63
-    private JScrollPane scrollPane;
64
-
65
-    /** Creates a new instance of ErrorDetailPanel. */
66
-    public ErrorDetailPanel(final ErrorManager errorManager) {
67
-        this(errorManager, null);
68
-    }
69
-
70
-    /**
71
-     * Creates a new instance of ErrorDetailPanel.
72
-     *
73
-     * @param errorManager The error manager to retrieve errors from
74
-     * @param error        Error to be displayed
75
-     */
76
-    public ErrorDetailPanel(final ErrorManager errorManager, final ProgramError error) {
77
-        this.errorManager = errorManager;
78
-        this.error = error;
79
-
80
-        initComponents();
81
-
82
-        updateDetails();
83
-
84
-        layoutComponents();
85
-    }
86
-
87
-    /**
88
-     * Sets the error used for this panel.
89
-     *
90
-     * @param newError New ProgramError
91
-     */
92
-    public void setError(final ProgramError newError) {
93
-        error = newError;
94
-        updateDetails();
95
-    }
96
-
97
-    /** Initialises the components. */
98
-    private void initComponents() {
99
-        date = new JTextField();
100
-        level = new JTextField();
101
-        reportStatus = new JTextField();
102
-        details = new JTextArea();
103
-        scrollPane = new JScrollPane(details);
104
-
105
-        date.setEditable(false);
106
-        level.setEditable(false);
107
-        reportStatus.setEditable(false);
108
-        details.setEditable(false);
109
-        details.setRows(5);
110
-        details.setWrapStyleWord(true);
111
-
112
-        errorManager.addErrorListener(this);
113
-    }
114
-
115
-    /** Updates the panels details. */
116
-    private void updateDetails() {
117
-        SwingUtilities.invokeLater(() -> {
118
-            details.setText("");
119
-            if (error == null) {
120
-                date.setText("");
121
-                level.setText("");
122
-                reportStatus.setText("");
123
-
124
-                return;
125
-            }
126
-
127
-            date.setText(new SimpleDateFormat("MMM dd hh:mm aa").format(error.getDate()));
128
-            level.setText(error.getLevel().toString());
129
-            reportStatus.setText(error.getReportStatus().toString());
130
-
131
-            details.append(error.getMessage() + '\n');
132
-            final List<String> trace = error.getTrace();
133
-            if (!trace.isEmpty()) {
134
-                details.append("\n");
135
-            }
136
-            for (String traceLine : trace) {
137
-                details.append(traceLine + '\n');
138
-            }
139
-            try {
140
-                details.getDocument().remove(details.getDocument().getLength() - 1, 1);
141
-            } catch (BadLocationException ex) {
142
-                //Ignore
143
-            }
144
-
145
-            UIUtilities.resetScrollPane(scrollPane);
146
-        });
147
-    }
148
-
149
-    /** Lays out the components. */
150
-    private void layoutComponents() {
151
-        setLayout(new MigLayout("fill, wrap 2", "[right]rel[grow,fill]", ""));
152
-
153
-        add(new JLabel("Date: "));
154
-        add(date);
155
-
156
-        add(new JLabel("Severity: "));
157
-        add(level);
158
-
159
-        add(new JLabel("Report status: "));
160
-        add(reportStatus);
161
-
162
-        add(new JLabel("Details: "));
163
-        add(scrollPane, "grow, push");
164
-    }
165
-
166
-    @Override
167
-    public void errorAdded(final ProgramError error) {
168
-        //Ignore
169
-    }
170
-
171
-    @Override
172
-    public void errorDeleted(final ProgramError error) {
173
-        //Ignore
174
-    }
175
-
176
-    @Override
177
-    public void errorStatusChanged(final ProgramError error) {
178
-        if (this.error != null && this.error.equals(error)) {
179
-            reportStatus.setText(error.getReportStatus().toString());
180
-            date.setText(new SimpleDateFormat("MMM dd hh:mm aa").format(error.getDate()));
181
-        }
182
-    }
183
-
184
-    @Override
185
-    public boolean isReady() {
186
-        return isVisible();
187
-    }
188
-
189
-}

+ 0
- 308
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/error/ErrorListDialog.java View File

@@ -1,308 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.addons.ui_swing.dialogs.error;
24
-
25
-import com.dmdirc.ClientModule.GlobalConfig;
26
-import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
27
-import com.dmdirc.addons.ui_swing.injection.MainWindow;
28
-import com.dmdirc.logger.ErrorManager;
29
-import com.dmdirc.logger.ErrorReportStatus;
30
-import com.dmdirc.logger.ProgramError;
31
-import com.dmdirc.ui.IconManager;
32
-
33
-import java.awt.Dimension;
34
-import java.awt.Window;
35
-import java.awt.event.ActionEvent;
36
-import java.awt.event.ActionListener;
37
-import java.util.concurrent.atomic.AtomicInteger;
38
-
39
-import javax.inject.Inject;
40
-import javax.swing.JButton;
41
-import javax.swing.JPanel;
42
-import javax.swing.JScrollPane;
43
-import javax.swing.JSplitPane;
44
-import javax.swing.event.ListSelectionEvent;
45
-import javax.swing.event.ListSelectionListener;
46
-import javax.swing.event.TableModelEvent;
47
-import javax.swing.event.TableModelListener;
48
-
49
-import net.miginfocom.layout.PlatformDefaults;
50
-import net.miginfocom.swing.MigLayout;
51
-
52
-/**
53
- * Error list dialog.
54
- */
55
-public final class ErrorListDialog extends StandardDialog implements
56
-        ActionListener, ListSelectionListener, TableModelListener {
57
-
58
-    /** Serial version UID. */
59
-    private static final long serialVersionUID = 5;
60
-    /** Row selection change lock. */
61
-    private final Object selectionLock = new Object();
62
-    /** Table model. */
63
-    private final ErrorTableModel tableModel;
64
-    /** Error manager to retrieve errors from. */
65
-    private final ErrorManager errorManager;
66
-    /** Table scrollpane. */
67
-    private JScrollPane scrollPane;
68
-    /** Error table. */
69
-    private ErrorTable table;
70
-    /** Error detail panel. */
71
-    private ErrorDetailPanel errorDetails;
72
-    /** Send button. */
73
-    private JButton sendButton;
74
-    /** Delete button. */
75
-    private JButton deleteButton;
76
-    /** Delete all button. */
77
-    private JButton deleteAllButton;
78
-    /** Selected row. */
79
-    private final AtomicInteger selectedRow = new AtomicInteger(-1);
80
-    /** Row being deleted. */
81
-    private boolean rowBeingDeleted = false;
82
-
83
-    /**
84
-     * Creates a new instance of ErrorListDialog.
85
-     *
86
-     * @param parentWindow The parent window.
87
-     * @param iconManager The manager to use to load icons.
88
-     */
89
-    @Inject
90
-    public ErrorListDialog(
91
-            final ErrorManager errorManager,
92
-            @MainWindow final Window parentWindow,
93
-            @GlobalConfig final IconManager iconManager) {
94
-        super(parentWindow, ModalityType.MODELESS);
95
-        this.errorManager = errorManager;
96
-
97
-        setTitle("Error list");
98
-        setMinimumSize(new Dimension(600, 550));
99
-
100
-        tableModel = new ErrorTableModel(errorManager);
101
-
102
-        initComponents(errorManager, iconManager);
103
-        layoutComponents();
104
-        initListeners();
105
-
106
-        selectedRow.set(table.getSelectedRow());
107
-    }
108
-
109
-    /**
110
-     * Loads the dialog and sets it as ready.
111
-     */
112
-    public void load() {
113
-        tableModel.load();
114
-    }
115
-
116
-    /** Initialises the components. */
117
-    private void initComponents(final ErrorManager errorManager, final IconManager iconManager) {
118
-        initButtons();
119
-
120
-        scrollPane = new JScrollPane();
121
-
122
-        table = new ErrorTable(iconManager, tableModel, scrollPane);
123
-
124
-        table.setPreferredScrollableViewportSize(new Dimension(600, 150));
125
-        scrollPane.setMinimumSize(new Dimension(150, 100));
126
-
127
-        scrollPane.setViewportView(table);
128
-
129
-        errorDetails = new ErrorDetailPanel(errorManager);
130
-    }
131
-
132
-    /** Initialises the buttons. */
133
-    private void initButtons() {
134
-        orderButtons(new JButton(), new JButton());
135
-
136
-        getCancelButton().setText("Close");
137
-        sendButton = new JButton("Send");
138
-        deleteButton = new JButton("Delete");
139
-        deleteAllButton = new JButton("Delete All");
140
-
141
-        sendButton.setEnabled(false);
142
-        deleteButton.setEnabled(false);
143
-        if (tableModel.getRowCount() > 0) {
144
-            deleteAllButton.setEnabled(true);
145
-        } else {
146
-            deleteAllButton.setEnabled(false);
147
-        }
148
-    }
149
-
150
-    /** Initialises the listeners. */
151
-    private void initListeners() {
152
-        tableModel.addTableModelListener(this);
153
-        table.getSelectionModel().addListSelectionListener(this);
154
-        sendButton.addActionListener(this);
155
-        deleteButton.addActionListener(this);
156
-        deleteAllButton.addActionListener(this);
157
-        getOkButton().addActionListener(this);
158
-        getCancelButton().addActionListener(this);
159
-    }
160
-
161
-    /** Lays out the components. */
162
-    private void layoutComponents() {
163
-        final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
164
-                true);
165
-        final JPanel panel = new JPanel();
166
-
167
-        panel.setLayout(new MigLayout("fill"));
168
-
169
-        panel.add(errorDetails, "wrap, grow, push");
170
-        panel.add(deleteAllButton, "split 4, tag left, sg button");
171
-        panel.add(deleteButton, "tag other, sg button");
172
-        panel.add(sendButton, "tag other, sg button");
173
-        panel.add(getCancelButton(), "tag ok, sg button");
174
-
175
-        splitPane.setTopComponent(scrollPane);
176
-        splitPane.setBottomComponent(panel);
177
-
178
-        splitPane.setDividerSize((int) PlatformDefaults.getPanelInsets(0).
179
-                getValue());
180
-
181
-        getContentPane().add(splitPane);
182
-    }
183
-
184
-    @Override
185
-    public void valueChanged(final ListSelectionEvent e) {
186
-        if (!e.getValueIsAdjusting()) {
187
-            final int localRow = table.getSelectedRow();
188
-            if (localRow > -1) {
189
-                final ProgramError error;
190
-                try {
191
-                    error = tableModel.getError(table.getRowSorter()
192
-                            .convertRowIndexToModel(localRow));
193
-                } catch (final IndexOutOfBoundsException ex) {
194
-                    //In the extremely rare case the error gets deleted whilst
195
-                    //we're changing the value, bail out gracefully
196
-                    return;
197
-                }
198
-                errorDetails.setError(error);
199
-                deleteButton.setEnabled(true);
200
-                if (error.getReportStatus() == ErrorReportStatus.NOT_APPLICABLE || error.
201
-                        getReportStatus() == ErrorReportStatus.FINISHED) {
202
-                    sendButton.setEnabled(false);
203
-                } else {
204
-                    sendButton.setEnabled(true);
205
-                }
206
-            } else {
207
-                errorDetails.setError(null);
208
-                deleteButton.setEnabled(false);
209
-                sendButton.setEnabled(false);
210
-            }
211
-            synchronized (selectionLock) {
212
-                if (rowBeingDeleted) {
213
-                    table.getSelectionModel().setSelectionInterval(selectedRow.
214
-                            get(), selectedRow.get());
215
-                    rowBeingDeleted = false;
216
-                }
217
-                selectedRow.set(localRow);
218
-            }
219
-        }
220
-    }
221
-
222
-    /**
223
-     * {@inheritDoc}.
224
-     *
225
-     * @param e Action event
226
-     */
227
-    @Override
228
-    public void actionPerformed(final ActionEvent e) {
229
-        if (e.getSource() == getCancelButton()) {
230
-            setVisible(false);
231
-        } else if (e.getSource() == deleteButton) {
232
-            synchronized (selectionLock) {
233
-                errorManager.deleteError(tableModel.getError(
234
-                        table.getRowSorter().convertRowIndexToModel(table.getSelectedRow())));
235
-            }
236
-        } else if (e.getSource() == sendButton) {
237
-            synchronized (selectionLock) {
238
-                errorManager.sendError(tableModel.getError(
239
-                        table.getRowSorter().convertRowIndexToModel(table.getSelectedRow())));
240
-            }
241
-        } else if (e.getSource() == deleteAllButton) {
242
-            errorManager.deleteAll();
243
-        }
244
-    }
245
-
246
-    @Override
247
-    public boolean enterPressed() {
248
-        executeAction(getOkButton());
249
-        return true;
250
-    }
251
-
252
-    @Override
253
-    public void tableChanged(final TableModelEvent e) {
254
-        if (tableModel.getRowCount() == 0) {
255
-            return;
256
-        }
257
-        switch (e.getType()) {
258
-            case TableModelEvent.DELETE:
259
-                synchronized (selectionLock) {
260
-                    if (selectedRow.get() >= tableModel.getRowCount()) {
261
-                        selectedRow.set(tableModel.getRowCount() - 1);
262
-                    }
263
-                    table.getSelectionModel().setSelectionInterval(selectedRow.
264
-                            get(),
265
-                            selectedRow.get());
266
-                    rowBeingDeleted = true;
267
-                }
268
-                break;
269
-            case TableModelEvent.INSERT:
270
-                synchronized (selectionLock) {
271
-                    table.getSelectionModel().setSelectionInterval(selectedRow.
272
-                            get(),
273
-                            selectedRow.get());
274
-                }
275
-                break;
276
-            case TableModelEvent.UPDATE:
277
-                final int errorRow = e.getFirstRow();
278
-                final ProgramError error = tableModel.getError(errorRow);
279
-                if (errorRow == table.getSelectedRow()) {
280
-                    if (error.getReportStatus() == ErrorReportStatus.NOT_APPLICABLE || error.
281
-                            getReportStatus() == ErrorReportStatus.FINISHED) {
282
-                        sendButton.setEnabled(false);
283
-                    } else {
284
-                        sendButton.setEnabled(true);
285
-                    }
286
-                }
287
-                break;
288
-        }
289
-        if (tableModel.getRowCount() > 0) {
290
-            deleteAllButton.setEnabled(true);
291
-        } else {
292
-            deleteAllButton.setEnabled(false);
293
-        }
294
-    }
295
-
296
-    @Override
297
-    public void display() {
298
-        super.display();
299
-        setSize(new Dimension(600, 550));
300
-    }
301
-
302
-    @Override
303
-    public void dispose() {
304
-        tableModel.dispose();
305
-        super.dispose();
306
-    }
307
-
308
-}

+ 0
- 77
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/error/ErrorTable.java View File

@@ -1,77 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.addons.ui_swing.dialogs.error;
24
-
25
-import com.dmdirc.addons.ui_swing.components.PackingTable;
26
-import com.dmdirc.ui.IconManager;
27
-
28
-import javax.swing.JScrollPane;
29
-import javax.swing.ListSelectionModel;
30
-import javax.swing.table.TableCellRenderer;
31
-
32
-/**
33
- * Table listing ProgramErrors in the client.
34
- */
35
-public class ErrorTable extends PackingTable {
36
-
37
-    /** Serial version UID. */
38
-    private static final long serialVersionUID = 3994014806819705247L;
39
-    /** Icon manager. */
40
-    private final IconManager iconManager;
41
-
42
-    /**
43
-     * Table listing ProgramErrors in the client.
44
-     *
45
-     * @param iconManager Icon manager
46
-     * @param tableModel  Table model
47
-     * @param scrollPane  Parent scrollpane
48
-     */
49
-    public ErrorTable(final IconManager iconManager,
50
-            final ErrorTableModel tableModel, final JScrollPane scrollPane) {
51
-        super(tableModel, scrollPane, true);
52
-        this.iconManager = iconManager;
53
-
54
-        setAutoCreateRowSorter(true);
55
-        setAutoCreateColumnsFromModel(true);
56
-        setColumnSelectionAllowed(false);
57
-        setCellSelectionEnabled(false);
58
-        setDragEnabled(false);
59
-        setFillsViewportHeight(false);
60
-        setRowSelectionAllowed(true);
61
-        setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
62
-        getRowSorter().toggleSortOrder(0);
63
-        getTableHeader().setReorderingAllowed(false);
64
-    }
65
-
66
-    @Override
67
-    public TableCellRenderer getCellRenderer(final int row,
68
-            final int column) {
69
-        switch (column) {
70
-            case 0:
71
-                return new ErrorLevelIconCellRenderer(iconManager);
72
-            default:
73
-                return super.getCellRenderer(row, column);
74
-        }
75
-    }
76
-
77
-}

+ 0
- 230
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/error/ErrorTableModel.java View File

@@ -1,230 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.addons.ui_swing.dialogs.error;
24
-
25
-import com.dmdirc.addons.ui_swing.UIUtilities;
26
-import com.dmdirc.logger.ErrorLevel;
27
-import com.dmdirc.logger.ErrorListener;
28
-import com.dmdirc.logger.ErrorManager;
29
-import com.dmdirc.logger.ErrorReportStatus;
30
-import com.dmdirc.logger.ProgramError;
31
-
32
-import java.util.ArrayList;
33
-import java.util.Collection;
34
-import java.util.Collections;
35
-import java.util.List;
36
-
37
-import javax.swing.table.AbstractTableModel;
38
-
39
-/**
40
- * Table model for displaying program errors.
41
- */
42
-public final class ErrorTableModel extends AbstractTableModel implements ErrorListener {
43
-
44
-    /** A version number for this class. */
45
-    private static final long serialVersionUID = 2;
46
-    /** Data list. */
47
-    private final List<ProgramError> errors;
48
-    /** Error manager to add listeners to. */
49
-    private final ErrorManager errorManager;
50
-    /** Are we ready? */
51
-    private boolean ready;
52
-
53
-    /**
54
-     * Creates a new instance of ErrorTableModel.
55
-     */
56
-    public ErrorTableModel(final ErrorManager errorManager) {
57
-        this.errors = Collections.synchronizedList(new ArrayList<>());
58
-        this.errorManager = errorManager;
59
-    }
60
-
61
-    public void load() {
62
-        errorManager.addErrorListener(this);
63
-        setErrors(errorManager.getErrors());
64
-        ready = true;
65
-    }
66
-
67
-    /**
68
-     * Sets the list of errors.
69
-     *
70
-     * @param errors List of errors
71
-     */
72
-    public void setErrors(final Collection<ProgramError> errors) {
73
-        synchronized (this.errors) {
74
-            this.errors.clear();
75
-            this.errors.addAll(errors);
76
-        }
77
-
78
-        fireTableDataChanged();
79
-    }
80
-
81
-    @Override
82
-    public int getRowCount() {
83
-        synchronized (errors) {
84
-            return errors.size();
85
-        }
86
-    }
87
-
88
-    @Override
89
-    public int getColumnCount() {
90
-        return 3;
91
-    }
92
-
93
-    @Override
94
-    public String getColumnName(final int columnIndex) {
95
-        switch (columnIndex) {
96
-            case 0:
97
-                return "Severity";
98
-            case 1:
99
-                return "Report Status";
100
-            case 2:
101
-                return "Message";
102
-            default:
103
-                throw new IndexOutOfBoundsException(columnIndex + ">= 3");
104
-        }
105
-    }
106
-
107
-    @Override
108
-    public Class<?> getColumnClass(final int columnIndex) {
109
-        switch (columnIndex) {
110
-            case 0:
111
-                return ErrorLevel.class;
112
-            case 1:
113
-                return ErrorReportStatus.class;
114
-            case 2:
115
-                return String.class;
116
-            default:
117
-                throw new IndexOutOfBoundsException(columnIndex + ">= 3");
118
-        }
119
-    }
120
-
121
-    @Override
122
-    public boolean isCellEditable(final int rowIndex, final int columnIndex) {
123
-        return false;
124
-    }
125
-
126
-    @Override
127
-    public Object getValueAt(final int rowIndex, final int columnIndex) {
128
-        synchronized (errors) {
129
-            switch (columnIndex) {
130
-                case 0:
131
-                    return errors.get(rowIndex).getLevel();
132
-                case 1:
133
-                    return errors.get(rowIndex).getReportStatus();
134
-                case 2:
135
-                    return errors.get(rowIndex).getMessage();
136
-                default:
137
-                    throw new IndexOutOfBoundsException(columnIndex + ">= 3");
138
-            }
139
-        }
140
-    }
141
-
142
-    /**
143
-     * Gets the error at the specified row.
144
-     *
145
-     * @param rowIndex Row to retrieve
146
-     *
147
-     * @return Specified error
148
-     */
149
-    public ProgramError getError(final int rowIndex) {
150
-        synchronized (errors) {
151
-            return errors.get(rowIndex);
152
-        }
153
-    }
154
-
155
-    /**
156
-     * Returns the index of the specified error or -1 if the error is not found.
157
-     *
158
-     * @param error ProgramError to locate
159
-     *
160
-     * @return Error index or -1 if not found
161
-     */
162
-    public int indexOf(final ProgramError error) {
163
-        synchronized (errors) {
164
-            return errors.indexOf(error);
165
-        }
166
-    }
167
-
168
-    /**
169
-     * Adds an error to the list.
170
-     *
171
-     * @param error ProgramError to add
172
-     */
173
-    public void addRow(final ProgramError error) {
174
-        synchronized (errors) {
175
-            errors.add(error);
176
-            fireTableRowsInserted(errors.indexOf(error), errors.indexOf(error));
177
-        }
178
-    }
179
-
180
-    /**
181
-     * Removes a specified error from the list.
182
-     *
183
-     * @param error ProgramError to remove
184
-     */
185
-    public void removeRow(final ProgramError error) {
186
-        synchronized (errors) {
187
-            if (errors.contains(error)) {
188
-                final int row = errors.indexOf(error);
189
-                errors.remove(row);
190
-                fireTableRowsDeleted(row, row);
191
-            }
192
-        }
193
-    }
194
-
195
-    @Override
196
-    public void errorAdded(final ProgramError error) {
197
-        UIUtilities.invokeLater(() -> addRow(error));
198
-    }
199
-
200
-    @Override
201
-    public void errorDeleted(final ProgramError error) {
202
-        UIUtilities.invokeLater(() -> removeRow(error));
203
-    }
204
-
205
-    @Override
206
-    public void errorStatusChanged(final ProgramError error) {
207
-        UIUtilities.invokeLater(() -> {
208
-            synchronized (errors) {
209
-                final int errorRow = indexOf(error);
210
-                if (errorRow != -1 && errorRow < getRowCount()) {
211
-                    fireTableRowsUpdated(errorRow, errorRow);
212
-                }
213
-            }
214
-        });
215
-    }
216
-
217
-    @Override
218
-    public boolean isReady() {
219
-        return ready;
220
-    }
221
-
222
-    /**
223
-     * Disposes of this model, removing any added listeners.
224
-     */
225
-    public void dispose() {
226
-        errorManager.removeErrorListener(this);
227
-        ready = false;
228
-    }
229
-
230
-}

+ 0
- 26
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/error/package-info.java View File

@@ -1,26 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2015 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-/**
24
- * Error dialogs.
25
- */
26
-package com.dmdirc.addons.ui_swing.dialogs.error;

ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/error/ErrorLevelIconCellRenderer.java → ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/newerror/ErrorLevelIconCellRenderer.java View File

@@ -20,12 +20,12 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.addons.ui_swing.dialogs.error;
23
+package com.dmdirc.addons.ui_swing.dialogs.newerror;
24 24
 
25 25
 import com.dmdirc.logger.ErrorLevel;
26 26
 import com.dmdirc.ui.IconManager;
27 27
 
28
-import javax.swing.JLabel;
28
+import javax.swing.SwingConstants;
29 29
 import javax.swing.table.DefaultTableCellRenderer;
30 30
 
31 31
 /** List cell renderer for dates. */
@@ -47,7 +47,7 @@ public final class ErrorLevelIconCellRenderer extends DefaultTableCellRenderer {
47 47
 
48 48
     @Override
49 49
     public void setValue(final Object value) {
50
-        setHorizontalAlignment(JLabel.CENTER);
50
+        setHorizontalAlignment(SwingConstants.CENTER);
51 51
         setIcon(iconManager.getIcon(((ErrorLevel) value).getIcon()));
52 52
     }
53 53
 

+ 7
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/newerror/ErrorsDialog.java View File

@@ -25,7 +25,6 @@ package com.dmdirc.addons.ui_swing.dialogs.newerror;
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26 26
 import com.dmdirc.addons.ui_swing.components.GenericTableModel;
27 27
 import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
28
-import com.dmdirc.addons.ui_swing.dialogs.error.ErrorLevelIconCellRenderer;
29 28
 import com.dmdirc.addons.ui_swing.injection.MainWindow;
30 29
 import com.dmdirc.interfaces.ui.ErrorsDialogModel;
31 30
 import com.dmdirc.logger.ErrorLevel;
@@ -82,7 +81,6 @@ public class ErrorsDialog extends StandardDialog {
82 81
         layoutComponents();
83 82
         setTitle("Error list");
84 83
         setMinimumSize(new Dimension(600, 550));
85
-
86 84
     }
87 85
 
88 86
     @Override
@@ -93,6 +91,12 @@ public class ErrorsDialog extends StandardDialog {
93 91
         super.display();
94 92
     }
95 93
 
94
+    @Override
95
+    public void dispose() {
96
+        model.unload();
97
+        super.dispose();
98
+    }
99
+
96 100
     private void initComponents() {
97 101
         deleteAll = new JButton("Delete All");
98 102
         delete = new JButton("Delete");
@@ -108,6 +112,7 @@ public class ErrorsDialog extends StandardDialog {
108 112
         tableScrollPane = new JScrollPane();
109 113
         splitPane = getSplitPane();
110 114
         table = new JTable(tableModel);
115
+        table.setAutoCreateRowSorter(true);
111 116
         table.getModel().addTableModelListener(table);
112 117
         tableScrollPane.setViewportView(table);
113 118
         table.setPreferredScrollableViewportSize(new Dimension(600, 150));

+ 16
- 9
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/newerror/ErrorsDialogController.java View File

@@ -45,9 +45,10 @@ import javax.swing.ListSelectionModel;
45 45
 /**
46 46
  * Controller linking the {@link ErrorsDialogModel} to the {@link ErrorsDialog}.
47 47
  */
48
-public class ErrorsDialogController implements ErrorsDialogModelListener {
48
+class ErrorsDialogController implements ErrorsDialogModelListener {
49 49
 
50 50
     private final ErrorsDialogModel model;
51
+    private JTable table;
51 52
     private GenericTableModel<ProgramError> tableModel;
52 53
     private JTextField date;
53 54
     private JTextField severity;
@@ -66,6 +67,7 @@ public class ErrorsDialogController implements ErrorsDialogModelListener {
66 67
             final JTextField reportStatus, final JTextArea details, final JButton deleteAll,
67 68
             final JButton delete, final JButton send, final JButton close) {
68 69
         this.tableModel = tableModel;
70
+        this.table = table;
69 71
         this.date = date;
70 72
         this.severity = severity;
71 73
         this.reportStatus = reportStatus;
@@ -93,13 +95,13 @@ public class ErrorsDialogController implements ErrorsDialogModelListener {
93 95
         delete.addActionListener(e -> model.deleteSelectedError());
94 96
         send.addActionListener(e -> model.sendSelectedError());
95 97
         close.addActionListener(e -> dialog.dispose());
98
+        checkEnabledStates();
96 99
     }
97 100
 
98 101
     @Override
99 102
     public void errorDeleted(final ProgramError error) {
100
-        UIUtilities.invokeAndWait(() -> {
103
+        UIUtilities.invokeLater(() -> {
101 104
             tableModel.removeValue(error);
102
-            deleteAll.setEnabled(model.isDeleteAllAllowed());
103 105
             checkEnabledStates();
104 106
         });
105 107
     }
@@ -114,15 +116,20 @@ public class ErrorsDialogController implements ErrorsDialogModelListener {
114 116
 
115 117
     @Override
116 118
     public void selectedErrorChanged(final Optional<ProgramError> selectedError) {
119
+        if (selectedError.isPresent()) {
120
+            final int index = tableModel.getIndex(selectedError.get());
121
+            table.getSelectionModel().setSelectionInterval(index, index);
122
+        } else {
123
+            table.getSelectionModel().setSelectionInterval(-1, -1);
124
+        }
117 125
         UIUtilities.invokeLater(() -> {
118 126
             date.setText(selectedError.map(ProgramError::getDate)
119 127
                     .map(d -> new SimpleDateFormat("MMM dd hh:mm aa").format(d)).orElse(""));
120
-            severity.setText(selectedError
121
-                    .map(ProgramError::getLevel)
122
-                    .map(ErrorLevel::name).orElse(""));
123
-            reportStatus.setText(selectedError
124
-                    .map(ProgramError::getReportStatus)
125
-                    .map(ErrorReportStatus::name).orElse(""));
128
+            severity.setText(
129
+                    selectedError.map(ProgramError::getLevel).map(ErrorLevel::name).orElse(""));
130
+            reportStatus.setText(
131
+                    selectedError.map(ProgramError::getReportStatus).map(ErrorReportStatus::name)
132
+                            .orElse(""));
126 133
             details.setText(selectedError.map(ProgramError::getDetails).orElse(""));
127 134
             details.append(Joiner.on('\n').skipNulls()
128 135
                     .join(selectedError.map(ProgramError::getTrace).orElse(Lists.newArrayList())));

+ 0
- 8
ui_swing/src/com/dmdirc/addons/ui_swing/injection/DialogModule.java View File

@@ -32,7 +32,6 @@ import com.dmdirc.addons.ui_swing.dialogs.about.AboutDialog;
32 32
 import com.dmdirc.addons.ui_swing.dialogs.aliases.AliasManagerDialog;
33 33
 import com.dmdirc.addons.ui_swing.dialogs.channellist.ChannelListDialog;
34 34
 import com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog;
35
-import com.dmdirc.addons.ui_swing.dialogs.error.ErrorListDialog;
36 35
 import com.dmdirc.addons.ui_swing.dialogs.feedback.FeedbackDialog;
37 36
 import com.dmdirc.addons.ui_swing.dialogs.newserver.NewServerDialog;
38 37
 import com.dmdirc.addons.ui_swing.dialogs.prefs.SwingPreferencesDialog;
@@ -137,13 +136,6 @@ public class DialogModule {
137 136
         return new DialogProvider<>(provider);
138 137
     }
139 138
 
140
-    @Provides
141
-    @Singleton
142
-    public DialogProvider<ErrorListDialog> getErrorListDialogProvider(
143
-            final Provider<ErrorListDialog> provider) {
144
-        return new DialogProvider<>(provider);
145
-    }
146
-
147 139
     @Provides
148 140
     @Singleton
149 141
     public DialogProvider<FeedbackDialog> getFeedbackDialogProvider(

Loading…
Cancel
Save