瀏覽代碼

EventBus some more logging.

Change-Id: I24148b4038b822f030aa6c222a5fbb1169205cb1
Reviewed-on: http://gerrit.dmdirc.com/3709
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
changes/09/3709/2
Greg Holmes 9 年之前
父節點
當前提交
d6596c0a41

+ 16
- 12
src/com/dmdirc/addons/ui_swing/framemanager/ctrltab/CtrlTabWindowManager.java 查看文件

@@ -35,10 +35,12 @@ import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
35 35
 import com.dmdirc.addons.ui_swing.framemanager.tree.TreeViewModel;
36 36
 import com.dmdirc.addons.ui_swing.framemanager.tree.TreeViewNode;
37 37
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
38
+import com.dmdirc.events.UserErrorEvent;
38 39
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
39 40
 import com.dmdirc.interfaces.ui.Window;
40 41
 import com.dmdirc.logger.ErrorLevel;
41
-import com.dmdirc.logger.Logger;
42
+
43
+import com.google.common.eventbus.EventBus;
42 44
 
43 45
 import java.awt.event.KeyEvent;
44 46
 import java.util.HashMap;
@@ -57,8 +59,7 @@ import javax.swing.tree.TreeSelectionModel;
57 59
  * A Window manager to handle ctrl[+shift]+tab switching between windows.
58 60
  */
59 61
 @Singleton
60
-public class CtrlTabWindowManager implements SwingWindowListener,
61
-        SelectionListener {
62
+public class CtrlTabWindowManager implements SwingWindowListener, SelectionListener {
62 63
 
63 64
     /** Node storage, used for adding and deleting nodes correctly. */
64 65
     private final Map<Window, TreeViewNode> nodes;
@@ -68,21 +69,26 @@ public class CtrlTabWindowManager implements SwingWindowListener,
68 69
     private final TreeScroller treeScroller;
69 70
     /** Selection model for the tree scroller. */
70 71
     private final TreeSelectionModel selectionModel;
72
+    /** The event bus to post errors to. */
73
+    private final EventBus eventBus;
71 74
 
72 75
     /**
73 76
      * Creates a new ctrl tab window manager.
74 77
      *
75 78
      * @param globalConfig       The configuration to read settings from.
76 79
      * @param windowFactory      The window factory to use to create and listen for windows.
77
-     * @param mainFrame     The main frame that owns this window manager
80
+     * @param mainFrame          The main frame that owns this window manager
78 81
      * @param activeFrameManager Active frame manager.
82
+     * @param eventBus           The eventBus to post errors to
79 83
      */
80 84
     @Inject
81 85
     public CtrlTabWindowManager(
82 86
             @GlobalConfig final AggregateConfigProvider globalConfig,
83 87
             final SwingWindowFactory windowFactory,
84 88
             final ActiveFrameManager activeFrameManager,
85
-            final MainFrame mainFrame) {
89
+            final MainFrame mainFrame,
90
+            final EventBus eventBus) {
91
+        this.eventBus = eventBus;
86 92
         nodes = new HashMap<>();
87 93
         model = new TreeViewModel(globalConfig, new TreeViewNode(null, null));
88 94
         selectionModel = new DefaultTreeSelectionModel();
@@ -126,8 +132,7 @@ public class CtrlTabWindowManager implements SwingWindowListener,
126 132
 
127 133
             @Override
128 134
             public void run() {
129
-                final TreeViewNode node = new TreeViewNode(null, window.
130
-                        getContainer());
135
+                final TreeViewNode node = new TreeViewNode(null, window.getContainer());
131 136
                 synchronized (nodes) {
132 137
                     nodes.put(window, node);
133 138
                 }
@@ -144,15 +149,14 @@ public class CtrlTabWindowManager implements SwingWindowListener,
144 149
 
145 150
             @Override
146 151
             public void run() {
147
-                if (nodes == null || nodes.get(window) == null) {
152
+                if (nodes.get(window) == null) {
148 153
                     return;
149 154
                 }
150 155
                 final TreeViewNode node = nodes.get(window);
151 156
                 if (node.getLevel() == 0) {
152
-                    Logger.appError(ErrorLevel.MEDIUM,
153
-                            "delServer triggered for root node"
154
-                            + node.toString(),
155
-                            new IllegalArgumentException());
157
+                    eventBus.post(new UserErrorEvent(ErrorLevel.MEDIUM,
158
+                            new IllegalArgumentException(),
159
+                            "delServer triggered for root node" + node.toString(), ""));
156 160
                 } else {
157 161
                     model.removeNodeFromParent(nodes.get(window));
158 162
                 }

+ 16
- 12
src/com/dmdirc/addons/ui_swing/framemanager/tree/TreeFrameManager.java 查看文件

@@ -31,17 +31,19 @@ import com.dmdirc.addons.ui_swing.components.TreeScroller;
31 31
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
32 32
 import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
33 33
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
34
+import com.dmdirc.events.UserErrorEvent;
34 35
 import com.dmdirc.interfaces.FrameInfoListener;
35 36
 import com.dmdirc.interfaces.NotificationListener;
36 37
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
37 38
 import com.dmdirc.interfaces.config.ConfigChangeListener;
38 39
 import com.dmdirc.logger.ErrorLevel;
39
-import com.dmdirc.logger.Logger;
40 40
 import com.dmdirc.plugins.PluginDomain;
41 41
 import com.dmdirc.ui.Colour;
42 42
 import com.dmdirc.ui.WindowManager;
43 43
 import com.dmdirc.ui.messages.ColourManager;
44 44
 
45
+import com.google.common.eventbus.EventBus;
46
+
45 47
 import java.awt.Rectangle;
46 48
 import java.awt.event.MouseEvent;
47 49
 import java.io.Serializable;
@@ -65,9 +67,8 @@ import net.miginfocom.swing.MigLayout;
65 67
 /**
66 68
  * Manages open windows in the application in a tree style view.
67 69
  */
68
-public class TreeFrameManager implements FrameManager,
69
-        Serializable, ConfigChangeListener, NotificationListener,
70
-        FrameInfoListener {
70
+public class TreeFrameManager implements FrameManager, Serializable, ConfigChangeListener,
71
+        NotificationListener, FrameInfoListener {
71 72
 
72 73
     /** Serial version UID. */
73 74
     private static final long serialVersionUID = 5;
@@ -89,6 +90,8 @@ public class TreeFrameManager implements FrameManager,
89 90
     private final WindowManager windowManager;
90 91
     /** Active frame manager. */
91 92
     private final ActiveFrameManager activeFrameManager;
93
+    /** The event bus to post errors to. */
94
+    private final EventBus eventBus;
92 95
 
93 96
     /**
94 97
      * Creates a new instance of the TreeFrameManager.
@@ -99,6 +102,7 @@ public class TreeFrameManager implements FrameManager,
99 102
      * @param activeFrameManager The active window manager
100 103
      * @param windowFactory      The factory to use to retrieve swing windows.
101 104
      * @param domain             The domain to read settings from.
105
+     * @param eventBus           The event bus to post errors to
102 106
      */
103 107
     @Inject
104 108
     public TreeFrameManager(
@@ -107,13 +111,15 @@ public class TreeFrameManager implements FrameManager,
107 111
             final ColourManager colourManager,
108 112
             final ActiveFrameManager activeFrameManager,
109 113
             final SwingWindowFactory windowFactory,
110
-            @PluginDomain(SwingController.class) final String domain) {
114
+            @PluginDomain(SwingController.class) final String domain,
115
+            final EventBus eventBus) {
111 116
         this.windowFactory = windowFactory;
112 117
         this.windowManager = windowManager;
113 118
         this.nodes = new HashMap<>();
114 119
         this.config = globalConfig;
115 120
         this.colourManager = colourManager;
116 121
         this.activeFrameManager = activeFrameManager;
122
+        this.eventBus = eventBus;
117 123
 
118 124
         UIUtilities.invokeLater(new Runnable() {
119 125
             @Override
@@ -186,15 +192,14 @@ public class TreeFrameManager implements FrameManager,
186 192
 
187 193
             @Override
188 194
             public void run() {
189
-                if (nodes == null || nodes.get(window.getContainer()) == null) {
195
+                if (nodes.get(window.getContainer()) == null) {
190 196
                     return;
191 197
                 }
192 198
                 final DefaultMutableTreeNode node = nodes.get(window.getContainer());
193 199
                 if (node.getLevel() == 0) {
194
-                    Logger.appError(ErrorLevel.MEDIUM,
195
-                            "delServer triggered for root node"
196
-                            + node.toString(),
197
-                            new IllegalArgumentException());
200
+                    eventBus.post(new UserErrorEvent(ErrorLevel.MEDIUM,
201
+                            new IllegalArgumentException(),
202
+                            "delServer triggered for root node" + node.toString(), ""));
198 203
                 } else {
199 204
                     model.removeNodeFromParent(nodes.get(window.getContainer()));
200 205
                 }
@@ -321,8 +326,7 @@ public class TreeFrameManager implements FrameManager,
321 326
 
322 327
                 for (FrameContainer window : windowManager.getRootWindows()) {
323 328
                     addWindow(null, window);
324
-                    final Collection<FrameContainer> childWindows = window
325
-                            .getChildren();
329
+                    final Collection<FrameContainer> childWindows = window.getChildren();
326 330
                     for (FrameContainer childWindow : childWindows) {
327 331
                         addWindow(nodes.get(window), childWindow);
328 332
                     }

+ 21
- 16
src/com/dmdirc/addons/ui_swing/wizard/firstrun/SwingFirstRunWizard.java 查看文件

@@ -34,13 +34,15 @@ import com.dmdirc.addons.ui_swing.wizard.WizardDialog;
34 34
 import com.dmdirc.addons.ui_swing.wizard.WizardListener;
35 35
 import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
36 36
 import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
37
+import com.dmdirc.events.UserErrorEvent;
37 38
 import com.dmdirc.interfaces.config.ConfigProvider;
38 39
 import com.dmdirc.interfaces.ui.FirstRunWizard;
39 40
 import com.dmdirc.logger.ErrorLevel;
40
-import com.dmdirc.logger.Logger;
41 41
 import com.dmdirc.ui.IconManager;
42 42
 import com.dmdirc.util.resourcemanager.ResourceManager;
43 43
 
44
+import com.google.common.eventbus.EventBus;
45
+
44 46
 import java.awt.Dialog.ModalityType;
45 47
 import java.awt.Dimension;
46 48
 import java.awt.Window;
@@ -67,6 +69,8 @@ public class SwingFirstRunWizard implements WizardListener, FirstRunWizard {
67 69
     private final String actionsDirectory;
68 70
     /** Provider to use to obtain PMDs. */
69 71
     private final DialogProvider<ProfileManagerDialog> profileDialogProvider;
72
+    /** The event bus to post errors to. */
73
+    private final EventBus eventBus;
70 74
 
71 75
     /**
72 76
      * Instantiate the wizard.
@@ -77,22 +81,23 @@ public class SwingFirstRunWizard implements WizardListener, FirstRunWizard {
77 81
      * @param pluginExtractor       Plugin extractor to use.
78 82
      * @param iconManager           Manager to use to find icons.
79 83
      * @param profileDialogProvider Provider to use to obtain PMDs.
84
+     * @param eventBus              The event bus to post errors to.
80 85
      */
81 86
     @Inject
82
-    public SwingFirstRunWizard(
83
-            @MainWindow final Window parentWindow,
87
+    public SwingFirstRunWizard(@MainWindow final Window parentWindow,
84 88
             @UserConfig final ConfigProvider config,
85 89
             @Directory(DirectoryType.ACTIONS) final String actionsDirectory,
86
-            final CorePluginExtractor pluginExtractor,
87
-            @GlobalConfig final IconManager iconManager,
88
-            final DialogProvider<ProfileManagerDialog> profileDialogProvider) {
90
+            final CorePluginExtractor pluginExtractor, @GlobalConfig final IconManager iconManager,
91
+            final DialogProvider<ProfileManagerDialog> profileDialogProvider,
92
+            final EventBus eventBus) {
89 93
         this.corePluginExtractor = pluginExtractor;
90 94
         this.config = config;
91 95
         this.actionsDirectory = actionsDirectory;
92 96
         this.profileDialogProvider = profileDialogProvider;
97
+        this.eventBus = eventBus;
93 98
 
94
-        wizardDialog = new WizardDialog("Setup wizard", new ArrayList<Step>(),
95
-                parentWindow, ModalityType.APPLICATION_MODAL);
99
+        wizardDialog = new WizardDialog("Setup wizard", new ArrayList<Step>(), parentWindow,
100
+                ModalityType.APPLICATION_MODAL);
96 101
         wizardDialog.setIconImage(iconManager.getImage("icon"));
97 102
         wizardDialog.addWizardListener(this);
98 103
         if (Apple.isAppleUI()) {
@@ -147,25 +152,25 @@ public class SwingFirstRunWizard implements WizardListener, FirstRunWizard {
147 152
                 getResourcesStartingWithAsBytes("com/dmdirc/actions/defaults");
148 153
         for (Entry<String, byte[]> resource : resources.entrySet()) {
149 154
             try {
150
-                final String resourceName = actionsDirectory + resource.getKey()
151
-                        .substring(27, resource.getKey().length());
152
-                final File newDir = new File(resourceName.substring(0,
153
-                        resourceName.lastIndexOf('/')) + "/");
155
+                final String resourceName = actionsDirectory +
156
+                        resource.getKey().substring(27, resource.getKey().length());
157
+                final File newDir =
158
+                        new File(resourceName.substring(0, resourceName.lastIndexOf('/')) + "/");
154 159
 
155 160
                 if (!newDir.exists()) {
156 161
                     newDir.mkdirs();
157 162
                 }
158 163
 
159
-                final File newFile = new File(newDir,
160
-                        resourceName.substring(resourceName.lastIndexOf('/') + 1,
161
-                                resourceName.length()));
164
+                final File newFile = new File(newDir, resourceName
165
+                        .substring(resourceName.lastIndexOf('/') + 1, resourceName.length()));
162 166
 
163 167
                 if (!newFile.isDirectory()) {
164 168
                     ResourceManager.getResourceManager().
165 169
                             resourceToFile(resource.getValue(), newFile);
166 170
                 }
167 171
             } catch (IOException ex) {
168
-                Logger.userError(ErrorLevel.LOW, "Failed to extract actions");
172
+                eventBus.post(new UserErrorEvent(ErrorLevel.LOW, ex,
173
+                        "Failed to extract actions", ""));
169 174
             }
170 175
         }
171 176
     }

Loading…
取消
儲存