Bladeren bron

Initial work on making web UI work again

Change-Id: I5756228bd66dd6d62c82ef89b9e3aab2bf9bb0cc
Reviewed-on: http://gerrit.dmdirc.com/1427
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
tags/0.6.4
Chris Smith 14 jaren geleden
bovenliggende
commit
2c5106dd96

+ 3
- 2
src/com/dmdirc/addons/ui_web/Client.java Bestand weergeven

@@ -44,7 +44,7 @@ public class Client {
44 44
 
45 45
     private final List<Event> events = new LinkedList<Event>();
46 46
 
47
-    public Client(final String ip) {
47
+    public Client(final WebInterfaceUI controller, final String ip) {
48 48
         events.add(new Event("statusbar", "Welcome to the DMDirc web interface"));
49 49
 
50 50
         this.ip = ip;
@@ -54,7 +54,8 @@ public class Client {
54 54
 
55 55
         while (!queued.isEmpty()) {
56 56
             final Window window = queued.remove(0);
57
-            final Window parent = window.getContainer().getParent().getFrame();
57
+            final Window parent = controller.getWindowManager()
58
+                    .getWindow(window.getContainer().getParent());
58 59
 
59 60
             if (parent == null) {
60 61
                 events.add(new Event("newwindow", window));

+ 10
- 5
src/com/dmdirc/addons/ui_web/DynamicRequestHandler.java Bestand weergeven

@@ -67,13 +67,18 @@ public class DynamicRequestHandler extends AbstractHandler {
67 67
     /** The last time each client was seen. */
68 68
     private static final Map<String, Client> CLIENTS = new HashMap<String, Client>();
69 69
 
70
+    /** The controller which owns this request handler. */
71
+    private final WebInterfaceUI controller;
72
+
70 73
     /**
71 74
      * Creates a new instance of DynamicRequestHandler. Registers object
72 75
      * convertors with the JSON serialiser.
73 76
      */
74
-    public DynamicRequestHandler() {
77
+    public DynamicRequestHandler(final WebInterfaceUI controller) {
75 78
         super();
76 79
 
80
+        this.controller = controller;
81
+
77 82
         JSON.registerConvertor(Event.class, new JSONObjectConvertor());
78 83
         JSON.registerConvertor(WebWindow.class, new JSONObjectConvertor());
79 84
         JSON.registerConvertor(Message.class, new JSONObjectConvertor());
@@ -108,7 +113,7 @@ public class DynamicRequestHandler extends AbstractHandler {
108 113
             final String clientID = request.getParameter("clientID");
109 114
             
110 115
             if (!CLIENTS.containsKey(clientID)) {
111
-                CLIENTS.put(clientID, new Client(request.getRemoteHost()));
116
+                CLIENTS.put(clientID, new Client(controller, request.getRemoteHost()));
112 117
             }
113 118
 
114 119
             synchronized (CLIENTS) {
@@ -273,9 +278,9 @@ public class DynamicRequestHandler extends AbstractHandler {
273 278
 
274 279
         nickEvents.add(new Event("clearnicklist", false));
275 280
 
276
-        for (ChannelClientInfo cci : ((Channel) ((WebChannelWindow)
277
-                WebInterfaceUI.active).getContainer()).getChannelInfo()
278
-                .getChannelClients()) {
281
+        for (ChannelClientInfo cci : ((Channel) (WebWindow.getWindow(
282
+                request.getParameter("window"))).getContainer())
283
+                .getChannelInfo().getChannelClients()) {
279 284
             nickEvents.add(new Event("addnicklist",
280 285
                     cci.getClient().getNickname()));
281 286
         }

+ 10
- 0
src/com/dmdirc/addons/ui_web/WebInterfacePlugin.java Bestand weergeven

@@ -24,6 +24,7 @@ package com.dmdirc.addons.ui_web;
24 24
 
25 25
 import com.dmdirc.Main;
26 26
 import com.dmdirc.plugins.Plugin;
27
+import com.dmdirc.ui.interfaces.UIController;
27 28
 
28 29
 import org.mortbay.jetty.Handler;
29 30
 
@@ -54,6 +55,15 @@ public class WebInterfacePlugin extends Plugin {
54 55
         Main.setUI(ui);
55 56
     }
56 57
 
58
+    /**
59
+     * Returns the UI Controller for the web interface.
60
+     *
61
+     * @return The web interface's UI controller
62
+     */
63
+    public UIController getController() {
64
+        return ui;
65
+    }
66
+
57 67
     /** {@inheritDoc} */
58 68
     @Override
59 69
     public void onUnload() {

+ 26
- 13
src/com/dmdirc/addons/ui_web/WebInterfaceUI.java Bestand weergeven

@@ -27,16 +27,20 @@ import com.dmdirc.FrameContainer;
27 27
 import com.dmdirc.Query;
28 28
 import com.dmdirc.Server;
29 29
 import com.dmdirc.WritableFrameContainer;
30
-import com.dmdirc.addons.ui_web.uicomponents.WebChannelWindow;
31
-import com.dmdirc.addons.ui_web.uicomponents.WebInputWindow;
32 30
 import com.dmdirc.addons.ui_web.uicomponents.WebMainWindow;
33
-import com.dmdirc.addons.ui_web.uicomponents.WebQueryWindow;
34
-import com.dmdirc.addons.ui_web.uicomponents.WebServerWindow;
35 31
 import com.dmdirc.addons.ui_web.uicomponents.WebStatusBar;
36 32
 import com.dmdirc.addons.ui_web.uicomponents.WebWindow;
37 33
 import com.dmdirc.config.prefs.PreferencesInterface;
38 34
 import com.dmdirc.ui.core.dialogs.sslcertificate.SSLCertificateDialogModel;
39
-import com.dmdirc.ui.interfaces.*;
35
+import com.dmdirc.ui.interfaces.ChannelWindow;
36
+import com.dmdirc.ui.interfaces.InputWindow;
37
+import com.dmdirc.ui.interfaces.MainWindow;
38
+import com.dmdirc.ui.interfaces.QueryWindow;
39
+import com.dmdirc.ui.interfaces.ServerWindow;
40
+import com.dmdirc.ui.interfaces.StatusBar;
41
+import com.dmdirc.ui.interfaces.UIController;
42
+import com.dmdirc.ui.interfaces.UpdaterDialog;
43
+import com.dmdirc.ui.interfaces.Window;
40 44
 import com.dmdirc.updater.Update;
41 45
 
42 46
 import java.net.URI;
@@ -66,9 +70,12 @@ public class WebInterfaceUI implements UIController {
66 70
     /** The web server we're using. */
67 71
     private final org.mortbay.jetty.Server webServer;
68 72
 
73
+    /** The window manager for this UI. */
74
+    private final WebWindowManager windowManager;
75
+
69 76
     /**
70 77
      * Creates a new WebInterfaceUI belonging to the specified plugin.
71
-     * 
78
+     *
72 79
      * @param plugin The plugin which owns this Web UI
73 80
      */
74 81
     public WebInterfaceUI(final WebInterfacePlugin plugin) {       
@@ -93,7 +100,7 @@ public class WebInterfaceUI implements UIController {
93 100
             new RootRequestHandler(),
94 101
             new StaticRequestHandler(),
95 102
             new DMDircRequestHandler(),
96
-            new DynamicRequestHandler(),
103
+            new DynamicRequestHandler(this),
97 104
         });
98 105
         
99 106
         try {
@@ -101,11 +108,17 @@ public class WebInterfaceUI implements UIController {
101 108
         } catch (Exception ex) {
102 109
             // Break horribly!
103 110
         }
111
+
112
+        windowManager = new WebWindowManager(this);
113
+    }
114
+
115
+    public WebWindowManager getWindowManager() {
116
+        return windowManager;
104 117
     }
105 118
     
106 119
     /**
107 120
      * Adds the specified handler to the webserver.
108
-     * 
121
+     *
109 122
      * @param newHandler The handler to add.
110 123
      */
111 124
     public void addWebHandler(final Handler newHandler) {
@@ -132,7 +145,7 @@ public class WebInterfaceUI implements UIController {
132 145
      */
133 146
     @Override @Deprecated
134 147
     public ChannelWindow getChannel(final Channel channel) {
135
-        return new WebChannelWindow(channel);
148
+        throw new UnsupportedOperationException();
136 149
     }
137 150
 
138 151
     /**
@@ -143,7 +156,7 @@ public class WebInterfaceUI implements UIController {
143 156
      */
144 157
     @Override @Deprecated
145 158
     public ServerWindow getServer(final Server server) {
146
-        return new WebServerWindow(server);
159
+        throw new UnsupportedOperationException();
147 160
     }
148 161
 
149 162
     /**
@@ -154,7 +167,7 @@ public class WebInterfaceUI implements UIController {
154 167
      */
155 168
     @Override @Deprecated
156 169
     public QueryWindow getQuery(final Query query) {
157
-        return new WebQueryWindow(query);
170
+        throw new UnsupportedOperationException();
158 171
     }
159 172
 
160 173
     /**
@@ -165,7 +178,7 @@ public class WebInterfaceUI implements UIController {
165 178
      */
166 179
     @Override @Deprecated
167 180
     public Window getWindow(final FrameContainer<?> owner) {
168
-        return new WebWindow(owner);
181
+        throw new UnsupportedOperationException();
169 182
     }
170 183
 
171 184
     /**
@@ -176,7 +189,7 @@ public class WebInterfaceUI implements UIController {
176 189
      */
177 190
     @Override @Deprecated
178 191
     public InputWindow getInputWindow(final WritableFrameContainer<?> owner) {
179
-        return new WebInputWindow(owner, owner.getCommandParser());
192
+        throw new UnsupportedOperationException();
180 193
     }
181 194
 
182 195
     /** {@inheritDoc} */

+ 147
- 0
src/com/dmdirc/addons/ui_web/WebWindowManager.java Bestand weergeven

@@ -0,0 +1,147 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
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_web;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.ui_web.uicomponents.WebChannelWindow;
27
+import com.dmdirc.addons.ui_web.uicomponents.WebInputWindow;
28
+import com.dmdirc.addons.ui_web.uicomponents.WebQueryWindow;
29
+import com.dmdirc.addons.ui_web.uicomponents.WebServerWindow;
30
+import com.dmdirc.addons.ui_web.uicomponents.WebWindow;
31
+import com.dmdirc.logger.ErrorLevel;
32
+import com.dmdirc.logger.Logger;
33
+import com.dmdirc.ui.WindowManager;
34
+import com.dmdirc.ui.interfaces.ChannelWindow;
35
+import com.dmdirc.ui.interfaces.FrameListener;
36
+import com.dmdirc.ui.interfaces.InputWindow;
37
+import com.dmdirc.ui.interfaces.QueryWindow;
38
+import com.dmdirc.ui.interfaces.ServerWindow;
39
+import com.dmdirc.ui.interfaces.Window;
40
+import java.util.HashMap;
41
+import java.util.Map;
42
+
43
+/**
44
+ * Manages WebUI windows.
45
+ *
46
+ * @author chris
47
+ */
48
+public class WebWindowManager implements FrameListener {
49
+
50
+    /** A map of known implementations of window interfaces. */
51
+    private static final Map<Class<? extends Window>, Class<? extends Window>> IMPLEMENTATIONS
52
+            = new HashMap<Class<? extends Window>, Class<? extends Window>>();
53
+
54
+    static {
55
+        IMPLEMENTATIONS.put(Window.class, WebWindow.class);
56
+        IMPLEMENTATIONS.put(InputWindow.class, WebInputWindow.class);
57
+        IMPLEMENTATIONS.put(ServerWindow.class, WebServerWindow.class);
58
+        IMPLEMENTATIONS.put(QueryWindow.class, WebQueryWindow.class);
59
+        IMPLEMENTATIONS.put(ChannelWindow.class, WebChannelWindow.class);
60
+    }
61
+
62
+    /** The controller that owns this manager. */
63
+    private final WebInterfaceUI controller;
64
+
65
+    /** Map of known windows. */
66
+    private final Map<FrameContainer<?>, Window> windows
67
+            = new HashMap<FrameContainer<?>, Window>();
68
+
69
+    public WebWindowManager(final WebInterfaceUI controller) {
70
+        this.controller = controller;
71
+        
72
+        WindowManager.addFrameListener(this);
73
+
74
+        for (FrameContainer<?> container : WindowManager.getRootWindows()) {
75
+            recursiveAdd(container);
76
+        }
77
+    }
78
+
79
+    public Window getWindow(final FrameContainer<?> window) {
80
+        return windows.get(window);
81
+    }
82
+
83
+    private void recursiveAdd(final FrameContainer<?> window) {
84
+        addWindow(window, false);
85
+
86
+        for (FrameContainer<?> child : window.getChildren()) {
87
+            recursiveAdd(child);
88
+        }
89
+    }
90
+
91
+    /** {@inheritDoc} */
92
+    @Override
93
+    public void addWindow(final FrameContainer<?> window, final boolean focus) {
94
+        windows.put(window, doAddWindow(window, focus));
95
+    }
96
+
97
+    /** {@inheritDoc} */
98
+    @Override
99
+    public void delWindow(final FrameContainer<?> window) {
100
+        windows.get(window).close();
101
+        windows.remove(window);
102
+    }
103
+
104
+    /** {@inheritDoc} */
105
+    @Override
106
+    public void addWindow(final FrameContainer<?> parent, final FrameContainer<?> window,
107
+            final boolean focus) {
108
+        addWindow(window, focus);
109
+    }
110
+
111
+    /** {@inheritDoc} */
112
+    @Override
113
+    public void delWindow(final FrameContainer<?> parent, final FrameContainer<?> window) {
114
+        delWindow(window);
115
+    }
116
+
117
+    /**
118
+     * Creates a new window for the specified container.
119
+     *
120
+     * @param <T> The type of window that should be created
121
+     * @param window The container that owns the window
122
+     * @param focus Whether the window should be focused initially
123
+     * @return The created window or null on error
124
+     */
125
+    @SuppressWarnings("unchecked")
126
+    protected <T extends Window> T doAddWindow(final FrameContainer<T> window,
127
+            final boolean focus) {
128
+        final Class<T> clazz;
129
+
130
+        if (IMPLEMENTATIONS.containsKey(window.getWindowClass())) {
131
+            clazz = (Class<T>) IMPLEMENTATIONS.get(window.getWindowClass());
132
+        } else {
133
+            clazz = window.getWindowClass();
134
+        }
135
+
136
+        try {
137
+            final T frame = (T) clazz.getConstructors()[0].newInstance(controller, window);
138
+            window.addWindow(frame);
139
+
140
+            return frame;
141
+        } catch (Exception ex) {
142
+            Logger.appError(ErrorLevel.HIGH, "Unable to create window", ex);
143
+            return null;
144
+        }
145
+    }
146
+
147
+}

+ 3
- 0
src/com/dmdirc/addons/ui_web/plugin.config Bestand weergeven

@@ -27,3 +27,6 @@ updates:
27 27
   id=29
28 28
 
29 29
 defaults:
30
+
31
+exports:
32
+  getController in com.dmdirc.addons.ui_web.WebInterfacePlugin as getController

+ 5
- 4
src/com/dmdirc/addons/ui_web/res/javascript/dmdirc.js Bestand weergeven

@@ -46,7 +46,7 @@ function treeview_add(name, id, type, parent) {
46 46
     var wrapperNode = document.createElement('div');
47 47
     wrapperNode.innerHTML = name;
48 48
     wrapperNode.style.cursor = 'pointer';
49
-    wrapperNode.onclick = function() { treeview_click(newNode); };
49
+    wrapperNode.onclick = function() {treeview_click(newNode);};
50 50
     newNode.appendChild(wrapperNode);
51 51
 
52 52
     parentNode.appendChild(newNode);
@@ -92,7 +92,7 @@ function wus_show() {
92 92
     wus_open = true;
93 93
     
94 94
     new Ajax.Updater('wus', '/static/webuistatus.html', {onSuccess:function() {
95
-            setTimeout('wus_init()', 200); }});
95
+            setTimeout('wus_init()', 200);}});
96 96
     new Effect.Appear('wus');
97 97
     
98 98
     wus_query();
@@ -193,7 +193,7 @@ function nsd_show() {
193 193
     }
194 194
 
195 195
     new Ajax.Updater('nsd', '/static/newserverdialog.html', {onSuccess:function() {
196
-            setTimeout('draggable("nsd")', 200); }});
196
+            setTimeout('draggable("nsd")', 200);}});
197 197
     new Ajax.Request('/dynamic/getprofiles',
198 198
     {onFailure:errFunc, onSuccess:handlerFunc, onException:excFunc});
199 199
     new Effect.Appear('nsd');
@@ -267,7 +267,8 @@ function nicklist_show() {
267 267
         document.getElementById('content').style.right = '240px';
268 268
         nicklist.style.display = 'block';
269 269
         new Ajax.Request('/dynamic/nicklistrefresh',
270
-        {onFailure:errFunc})
270
+        {parameters: {window: activeWindow}, onFailure: errFunc,
271
+            onSuccess: handlerFunc})
271 272
     }
272 273
 }
273 274
 

+ 3
- 2
src/com/dmdirc/addons/ui_web/uicomponents/WebChannelWindow.java Bestand weergeven

@@ -25,6 +25,7 @@ package com.dmdirc.addons.ui_web.uicomponents;
25 25
 import com.dmdirc.Channel;
26 26
 import com.dmdirc.addons.ui_web.DynamicRequestHandler;
27 27
 import com.dmdirc.addons.ui_web.Event;
28
+import com.dmdirc.addons.ui_web.WebInterfaceUI;
28 29
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
29 30
 import com.dmdirc.ui.interfaces.ChannelWindow;
30 31
 
@@ -38,8 +39,8 @@ public class WebChannelWindow extends WebInputWindow implements ChannelWindow {
38 39
     
39 40
     private final Channel channel;
40 41
 
41
-    public WebChannelWindow(Channel channel) {
42
-        super(channel, channel.getCommandParser());
42
+    public WebChannelWindow(final WebInterfaceUI controller, Channel channel) {
43
+        super(controller, channel);
43 44
         this.channel = channel;
44 45
     }
45 46
 

+ 4
- 3
src/com/dmdirc/addons/ui_web/uicomponents/WebInputWindow.java Bestand weergeven

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.addons.ui_web.uicomponents;
24 24
 
25 25
 import com.dmdirc.WritableFrameContainer;
26
+import com.dmdirc.addons.ui_web.WebInterfaceUI;
26 27
 import com.dmdirc.commandparser.parsers.CommandParser;
27 28
 import com.dmdirc.ui.input.InputHandler;
28 29
 import com.dmdirc.ui.interfaces.InputWindow;
@@ -45,10 +46,10 @@ public class WebInputWindow extends WebWindow implements InputWindow {
45 46
     private final Map<String, WebInputHandler> inputHandlers
46 47
             = new HashMap<String, WebInputHandler>();
47 48
 
48
-    public WebInputWindow(WritableFrameContainer<?> parent, CommandParser parser) {
49
-        super(parent);
49
+    public WebInputWindow(WebInterfaceUI controller, WritableFrameContainer<?> parent) {
50
+        super(controller, parent);
50 51
         this.parent = parent;
51
-        this.commandparser = parser;
52
+        this.commandparser = parent.getCommandParser();
52 53
         this.inputhandler = new WebInputHandler(new WebInputField(), commandparser, this);
53 54
     }
54 55
 

+ 3
- 2
src/com/dmdirc/addons/ui_web/uicomponents/WebQueryWindow.java Bestand weergeven

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.addons.ui_web.uicomponents;
24 24
 
25 25
 import com.dmdirc.Query;
26
+import com.dmdirc.addons.ui_web.WebInterfaceUI;
26 27
 import com.dmdirc.ui.interfaces.QueryWindow;
27 28
 
28 29
 /**
@@ -33,8 +34,8 @@ public class WebQueryWindow extends WebInputWindow implements QueryWindow {
33 34
     
34 35
     private final Query query;
35 36
 
36
-    public WebQueryWindow(final Query parent) {
37
-        super(parent, parent.getCommandParser());
37
+    public WebQueryWindow(final WebInterfaceUI controller, final Query parent) {
38
+        super(controller, parent);
38 39
         this.query = parent;
39 40
     }
40 41
 

+ 3
- 2
src/com/dmdirc/addons/ui_web/uicomponents/WebServerWindow.java Bestand weergeven

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.addons.ui_web.uicomponents;
24 24
 
25 25
 import com.dmdirc.Server;
26
+import com.dmdirc.addons.ui_web.WebInterfaceUI;
26 27
 import com.dmdirc.ui.interfaces.ServerWindow;
27 28
 
28 29
 /**
@@ -33,8 +34,8 @@ public class WebServerWindow extends WebInputWindow implements ServerWindow {
33 34
  
34 35
     private final Server server;
35 36
 
36
-    public WebServerWindow(Server server) {
37
-        super(server, server.getCommandParser());
37
+    public WebServerWindow(WebInterfaceUI controller, Server server) {
38
+        super(controller, server);
38 39
         
39 40
         this.server = server;
40 41
     }

+ 2
- 1
src/com/dmdirc/addons/ui_web/uicomponents/WebWindow.java Bestand weergeven

@@ -26,6 +26,7 @@ import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.addons.ui_web.DynamicRequestHandler;
27 27
 import com.dmdirc.addons.ui_web.Event;
28 28
 import com.dmdirc.addons.ui_web.Message;
29
+import com.dmdirc.addons.ui_web.WebInterfaceUI;
29 30
 import com.dmdirc.config.ConfigManager;
30 31
 import com.dmdirc.ui.core.util.Utils;
31 32
 import com.dmdirc.ui.interfaces.UIController;
@@ -66,7 +67,7 @@ public class WebWindow implements Window {
66 67
 
67 68
     private String title;
68 69
 
69
-    public WebWindow(final FrameContainer<?> parent) {
70
+    public WebWindow(final WebInterfaceUI controller, final FrameContainer<?> parent) {
70 71
         super();
71 72
 
72 73
         this.parent = parent;

Laden…
Annuleren
Opslaan