Browse Source

Pass FrameContainer their parents when constructed

There's no reason for the parent to ever change, and this simplifies
a lot of things going forward.

Change-Id: I0dc9f767840ce0989739ea28f08254c78ef0d565
Depends-On: I3c0dc4b6cf42b5c6b69a499ac11195271c0aa846
Reviewed-on: http://gerrit.dmdirc.com/3466
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
pull/1/head
Chris Smith 10 years ago
parent
commit
d67ae3ae27

+ 1
- 1
src/com/dmdirc/Channel.java View File

@@ -117,7 +117,7 @@ public class Channel extends MessageTarget implements ConfigChangeListener, Grou
117 117
             final MessageSinkManager messageSinkManager,
118 118
             final URLBuilder urlBuilder,
119 119
             final EventBus eventBus) {
120
-        super("channel-inactive", newChannelInfo.getName(),
120
+        super(newServer, "channel-inactive", newChannelInfo.getName(),
121 121
                 Styliser.stipControlCodes(newChannelInfo.getName()),
122 122
                 configMigrator.getConfigProvider(),
123 123
                 new ChannelCommandParser(newServer, commandController),

+ 2
- 2
src/com/dmdirc/CustomWindow.java View File

@@ -51,7 +51,7 @@ public class CustomWindow extends FrameContainer {
51 51
             final FrameContainer parent,
52 52
             final URLBuilder urlBuilder,
53 53
             final EventBus eventBus) {
54
-        super("custom", name, title, parent.getConfigManager(), urlBuilder, eventBus,
54
+        super(parent, "custom", name, title, parent.getConfigManager(), urlBuilder, eventBus,
55 55
                 Arrays.asList(WindowComponent.TEXTAREA.getIdentifier()));
56 56
     }
57 57
 
@@ -70,7 +70,7 @@ public class CustomWindow extends FrameContainer {
70 70
             final AggregateConfigProvider configProvider,
71 71
             final URLBuilder urlBuilder,
72 72
             final EventBus eventBus) {
73
-        super("custom", name, title, configProvider, urlBuilder, eventBus,
73
+        super(null, "custom", name, title, configProvider, urlBuilder, eventBus,
74 74
                 Arrays.asList(WindowComponent.TEXTAREA.getIdentifier()));
75 75
     }
76 76
 

+ 9
- 18
src/com/dmdirc/FrameContainer.java View File

@@ -55,6 +55,8 @@ import java.util.List;
55 55
 import java.util.Set;
56 56
 import java.util.concurrent.CopyOnWriteArrayList;
57 57
 
58
+import javax.annotation.Nullable;
59
+
58 60
 import static com.google.common.base.Preconditions.checkState;
59 61
 
60 62
 /**
@@ -72,7 +74,7 @@ public abstract class FrameContainer {
72 74
     /** The children of this frame. */
73 75
     private final Collection<FrameContainer> children = new CopyOnWriteArrayList<>();
74 76
     /** The parent of this frame. */
75
-    private FrameContainer parent;
77
+    private final FrameContainer parent;
76 78
     /** The name of the icon being used for this container's frame. */
77 79
     private String icon;
78 80
     /** The name of this container. */
@@ -119,6 +121,7 @@ public abstract class FrameContainer {
119 121
     /**
120 122
      * Instantiate new frame container.
121 123
      *
124
+     * @param parent     The parent of this frame container, if any.
122 125
      * @param icon       The icon to use for this container
123 126
      * @param name       The name of this container
124 127
      * @param title      The title of this container
@@ -130,6 +133,7 @@ public abstract class FrameContainer {
130 133
      * @since 0.6.4
131 134
      */
132 135
     protected FrameContainer(
136
+            @Nullable final FrameContainer parent,
133 137
             final String icon,
134 138
             final String name,
135 139
             final String title,
@@ -137,6 +141,7 @@ public abstract class FrameContainer {
137 141
             final URLBuilder urlBuilder,
138 142
             final EventBus eventBus,
139 143
             final Collection<String> components) {
144
+        this.parent = parent;
140 145
         this.configManager = config;
141 146
         this.name = name;
142 147
         this.title = title;
@@ -154,6 +159,7 @@ public abstract class FrameContainer {
154 159
     /**
155 160
      * Instantiate new frame container that accepts user input.
156 161
      *
162
+     * @param parent             The parent of this frame container, if any.
157 163
      * @param icon               The icon to use for this container
158 164
      * @param name               The name of this container
159 165
      * @param title              The title of this container
@@ -168,6 +174,7 @@ public abstract class FrameContainer {
168 174
      * @since 0.6.4
169 175
      */
170 176
     protected FrameContainer(
177
+            @Nullable final FrameContainer parent,
171 178
             final String icon,
172 179
             final String name,
173 180
             final String title,
@@ -178,6 +185,7 @@ public abstract class FrameContainer {
178 185
             final MessageSinkManager messageSinkManager,
179 186
             final EventBus eventbus,
180 187
             final Collection<String> components) {
188
+        this.parent = parent;
181 189
         this.configManager = config;
182 190
         this.name = name;
183 191
         this.title = title;
@@ -241,7 +249,6 @@ public abstract class FrameContainer {
241 249
      */
242 250
     public void addChild(final FrameContainer child) {
243 251
         children.add(child);
244
-        child.setParent(this);
245 252
     }
246 253
 
247 254
     /**
@@ -255,22 +262,6 @@ public abstract class FrameContainer {
255 262
         children.remove(child);
256 263
     }
257 264
 
258
-    /**
259
-     * Sets the parent of this container to the one specified. If this container already had a
260
-     * parent, it will deregister itself with the old parent.
261
-     *
262
-     * @param parent The new parent for this container
263
-     *
264
-     * @since 0.6.4
265
-     */
266
-    public synchronized void setParent(final FrameContainer parent) {
267
-        if (this.parent != null && (parent == null || !parent.equals(this.parent))) {
268
-            this.parent.removeChild(this);
269
-        }
270
-
271
-        this.parent = parent;
272
-    }
273
-
274 265
     /**
275 266
      * Gets an icon manager for this container.
276 267
      *

+ 1
- 1
src/com/dmdirc/GlobalWindow.java View File

@@ -67,7 +67,7 @@ public class GlobalWindow extends FrameContainer {
67 67
             final MessageSinkManager messageSinkManager,
68 68
             final URLBuilder urlBuilder,
69 69
             final EventBus eventBus) {
70
-        super("icon", "Global", "(Global)", config, urlBuilder, parser,
70
+        super(null, "icon", "Global", "(Global)", config, urlBuilder, parser,
71 71
                 tabCompleterFactory.getTabCompleter(config, CommandType.TYPE_GLOBAL),
72 72
                 messageSinkManager, eventBus,
73 73
                 Arrays.asList(

+ 6
- 2
src/com/dmdirc/MessageTarget.java View File

@@ -32,6 +32,8 @@ import com.google.common.eventbus.EventBus;
32 32
 
33 33
 import java.util.Collection;
34 34
 
35
+import javax.annotation.Nullable;
36
+
35 37
 /**
36 38
  * Defines common methods for objects that you can send messages to (such as channels and queries).
37 39
  */
@@ -40,6 +42,7 @@ public abstract class MessageTarget extends FrameContainer {
40 42
     /**
41 43
      * Creates a new MessageTarget.
42 44
      *
45
+     * @param parent             The parent of this frame container, if any.
43 46
      * @param icon               The icon to use for this target
44 47
      * @param name               The name of this target
45 48
      * @param title              The title of this target
@@ -54,6 +57,7 @@ public abstract class MessageTarget extends FrameContainer {
54 57
      * @since 0.6.4
55 58
      */
56 59
     public MessageTarget(
60
+            @Nullable final FrameContainer parent,
57 61
             final String icon,
58 62
             final String name,
59 63
             final String title,
@@ -64,8 +68,8 @@ public abstract class MessageTarget extends FrameContainer {
64 68
             final URLBuilder urlBuilder,
65 69
             final EventBus eventBus,
66 70
             final Collection<String> components) {
67
-        super(icon, name, title, config, urlBuilder, parser, tabCompleter, messageSinkManager,
68
-                eventBus, components);
71
+        super(parent, icon, name, title, config, urlBuilder, parser, tabCompleter,
72
+                messageSinkManager, eventBus, components);
69 73
     }
70 74
 
71 75
     /**

+ 1
- 1
src/com/dmdirc/Query.java View File

@@ -102,7 +102,7 @@ public class Query extends MessageTarget implements PrivateActionListener,
102 102
             final MessageSinkManager messageSinkManager,
103 103
             final URLBuilder urlBuilder,
104 104
             final EventBus eventBus) {
105
-        super("query", newServer.parseHostmask(newHost)[0],
105
+        super(newServer, "query", newServer.parseHostmask(newHost)[0],
106 106
                 newServer.parseHostmask(newHost)[0],
107 107
                 newServer.getConfigManager(),
108 108
                 new QueryCommandParser(newServer, commandController),

+ 1
- 1
src/com/dmdirc/Raw.java View File

@@ -67,7 +67,7 @@ public class Raw extends FrameContainer implements DataInListener, DataOutListen
67 67
             final MessageSinkManager messageSinkManager,
68 68
             final EventBus eventBus,
69 69
             final URLBuilder urlBuilder) {
70
-        super("raw", "Raw", "(Raw log)", newServer.getConfigManager(), urlBuilder,
70
+        super(newServer, "raw", "Raw", "(Raw log)", newServer.getConfigManager(), urlBuilder,
71 71
                 new ServerCommandParser(newServer.getConfigManager(), commandController),
72 72
                 newServer.getTabCompleter(),
73 73
                 messageSinkManager,

+ 1
- 1
src/com/dmdirc/Server.java View File

@@ -230,7 +230,7 @@ public class Server extends FrameContainer implements ConfigChangeListener,
230 230
             @Unbound final ScheduledExecutorService executorService,
231 231
             @Unbound final URI uri,
232 232
             @Unbound final ConfigProvider profile) {
233
-        super("server-disconnected",
233
+        super(null, "server-disconnected",
234 234
                 getHost(uri),
235 235
                 getHost(uri),
236 236
                 configMigrator.getConfigProvider(),

+ 1
- 1
test/com/dmdirc/harness/TestWritableFrameContainer.java View File

@@ -46,7 +46,7 @@ public class TestWritableFrameContainer extends FrameContainer {
46 46
             final AggregateConfigProvider cm, final CommandManager commandManager,
47 47
             final MessageSinkManager messageSinkManager,
48 48
             final URLBuilder urlBuilder, final EventBus eventBus) {
49
-        super("raw", "Raw", "(Raw)", cm, urlBuilder,
49
+        super(null, "raw", "Raw", "(Raw)", cm, urlBuilder,
50 50
                 new GlobalCommandParser(cm, commandManager),
51 51
                 new TabCompleter(mock(CommandController.class), cm),
52 52
                 messageSinkManager,

Loading…
Cancel
Save