Browse Source

Tidy how CommandParsers are created.

Instead of passing them in to the FrameContainer ctor, create
them afterwards.

This means the reference in FrameContainer can't be final but
removes the horrible setOwner() kludge that was previously in
CommandParser, and cuts down the deps needed to pass in to the
FrameContainer ctor.
pull/548/head
Chris Smith 9 years ago
parent
commit
deaf4b232f

+ 0
- 7
src/com/dmdirc/Channel.java View File

23
 package com.dmdirc;
23
 package com.dmdirc;
24
 
24
 
25
 import com.dmdirc.commandparser.CommandType;
25
 import com.dmdirc.commandparser.CommandType;
26
-import com.dmdirc.commandparser.parsers.ChannelCommandParser;
27
 import com.dmdirc.config.ConfigBinding;
26
 import com.dmdirc.config.ConfigBinding;
28
 import com.dmdirc.events.ChannelClosedEvent;
27
 import com.dmdirc.events.ChannelClosedEvent;
29
 import com.dmdirc.events.ChannelSelfActionEvent;
28
 import com.dmdirc.events.ChannelSelfActionEvent;
35
 import com.dmdirc.events.NickListClientRemovedEvent;
34
 import com.dmdirc.events.NickListClientRemovedEvent;
36
 import com.dmdirc.events.NickListClientsChangedEvent;
35
 import com.dmdirc.events.NickListClientsChangedEvent;
37
 import com.dmdirc.events.NickListUpdatedEvent;
36
 import com.dmdirc.events.NickListUpdatedEvent;
38
-import com.dmdirc.interfaces.CommandController;
39
 import com.dmdirc.interfaces.Connection;
37
 import com.dmdirc.interfaces.Connection;
40
 import com.dmdirc.interfaces.GroupChat;
38
 import com.dmdirc.interfaces.GroupChat;
41
 import com.dmdirc.interfaces.GroupChatUser;
39
 import com.dmdirc.interfaces.GroupChatUser;
103
      * @param newChannelInfo      The parser's channel object that corresponds to this channel
101
      * @param newChannelInfo      The parser's channel object that corresponds to this channel
104
      * @param configMigrator      The config migrator which provides the config for this channel.
102
      * @param configMigrator      The config migrator which provides the config for this channel.
105
      * @param tabCompleterFactory The factory to use to create tab completers.
103
      * @param tabCompleterFactory The factory to use to create tab completers.
106
-     * @param commandController   The controller to load commands from.
107
      * @param messageSinkManager  The sink manager to use to despatch messages.
104
      * @param messageSinkManager  The sink manager to use to despatch messages.
108
-     * @param eventBus            The bus to despatch events onto.
109
      */
105
      */
110
     public Channel(
106
     public Channel(
111
             final Connection connection,
107
             final Connection connection,
112
             final ChannelInfo newChannelInfo,
108
             final ChannelInfo newChannelInfo,
113
             final ConfigProviderMigrator configMigrator,
109
             final ConfigProviderMigrator configMigrator,
114
             final TabCompleterFactory tabCompleterFactory,
110
             final TabCompleterFactory tabCompleterFactory,
115
-            final CommandController commandController,
116
             final MessageSinkManager messageSinkManager,
111
             final MessageSinkManager messageSinkManager,
117
-            final DMDircMBassador eventBus,
118
             final BackBufferFactory backBufferFactory,
112
             final BackBufferFactory backBufferFactory,
119
             final GroupChatUserManager groupChatUserManager) {
113
             final GroupChatUserManager groupChatUserManager) {
120
         super(connection.getWindowModel(), "channel-inactive",
114
         super(connection.getWindowModel(), "channel-inactive",
122
                 Styliser.stipControlCodes(newChannelInfo.getName()),
116
                 Styliser.stipControlCodes(newChannelInfo.getName()),
123
                 configMigrator.getConfigProvider(),
117
                 configMigrator.getConfigProvider(),
124
                 backBufferFactory,
118
                 backBufferFactory,
125
-                new ChannelCommandParser(connection.getWindowModel(), commandController,  eventBus),
126
                 tabCompleterFactory.getTabCompleter(connection.getWindowModel().getTabCompleter(),
119
                 tabCompleterFactory.getTabCompleter(connection.getWindowModel().getTabCompleter(),
127
                         configMigrator.getConfigProvider(), CommandType.TYPE_CHANNEL,
120
                         configMigrator.getConfigProvider(), CommandType.TYPE_CHANNEL,
128
                         CommandType.TYPE_CHAT),
121
                         CommandType.TYPE_CHAT),

+ 4
- 2
src/com/dmdirc/ChannelFactory.java View File

22
 
22
 
23
 package com.dmdirc;
23
 package com.dmdirc;
24
 
24
 
25
+import com.dmdirc.commandparser.parsers.ChannelCommandParser;
25
 import com.dmdirc.events.ChannelOpenedEvent;
26
 import com.dmdirc.events.ChannelOpenedEvent;
26
 import com.dmdirc.interfaces.CommandController;
27
 import com.dmdirc.interfaces.CommandController;
27
 import com.dmdirc.interfaces.Connection;
28
 import com.dmdirc.interfaces.Connection;
67
             final ChannelInfo channelInfo,
68
             final ChannelInfo channelInfo,
68
             final ConfigProviderMigrator configMigrator) {
69
             final ConfigProviderMigrator configMigrator) {
69
         final Channel channel = new Channel(connection, channelInfo, configMigrator,
70
         final Channel channel = new Channel(connection, channelInfo, configMigrator,
70
-                tabCompleterFactory, commandController, messageSinkManager, eventBus,
71
-                backBufferFactory, groupChatUserManager);
71
+                tabCompleterFactory, messageSinkManager, backBufferFactory, groupChatUserManager);
72
+        channel.setCommandParser(new ChannelCommandParser(connection.getWindowModel(),
73
+                commandController, eventBus, channel));
72
         windowManager.addWindow(connection.getWindowModel(), channel);
74
         windowManager.addWindow(connection.getWindowModel(), channel);
73
         connection.getWindowModel().getEventBus().publish(new ChannelOpenedEvent(channel));
75
         connection.getWindowModel().getEventBus().publish(new ChannelOpenedEvent(channel));
74
         return channel;
76
         return channel;

+ 11
- 10
src/com/dmdirc/FrameContainer.java View File

95
     /** The back buffer for this container. */
95
     /** The back buffer for this container. */
96
     private BackBuffer backBuffer;
96
     private BackBuffer backBuffer;
97
 
97
 
98
-    /**
99
-     * The command parser used for commands in this container.
100
-     * <p>
101
-     * Only defined if this container is {@link #writable}.
102
-     */
103
-    private final Optional<CommandParser> commandParser;
104
     /**
98
     /**
105
      * The manager to use to dispatch messages to sinks.
99
      * The manager to use to dispatch messages to sinks.
106
      * <p>
100
      * <p>
114
      */
108
      */
115
     private final Optional<TabCompleter> tabCompleter;
109
     private final Optional<TabCompleter> tabCompleter;
116
 
110
 
111
+    /**
112
+     * The command parser used for commands in this container.
113
+     * <p>
114
+     * Only defined if this container is {@link #writable}.
115
+     */
116
+    private Optional<CommandParser> commandParser = Optional.empty();
117
+
117
     /**
118
     /**
118
      * Instantiate new frame container.
119
      * Instantiate new frame container.
119
      */
120
      */
132
         this.title = title;
133
         this.title = title;
133
         this.components = new HashSet<>(components);
134
         this.components = new HashSet<>(components);
134
         this.writable = false;
135
         this.writable = false;
135
-        this.commandParser = Optional.empty();
136
         this.tabCompleter = Optional.empty();
136
         this.tabCompleter = Optional.empty();
137
         this.messageSinkManager = Optional.empty();
137
         this.messageSinkManager = Optional.empty();
138
         this.backBufferFactory = backBufferFactory;
138
         this.backBufferFactory = backBufferFactory;
157
             final String title,
157
             final String title,
158
             final AggregateConfigProvider config,
158
             final AggregateConfigProvider config,
159
             final BackBufferFactory backBufferFactory,
159
             final BackBufferFactory backBufferFactory,
160
-            final CommandParser commandParser,
161
             final TabCompleter tabCompleter,
160
             final TabCompleter tabCompleter,
162
             final MessageSinkManager messageSinkManager,
161
             final MessageSinkManager messageSinkManager,
163
             final DMDircMBassador eventBus,
162
             final DMDircMBassador eventBus,
168
         this.title = title;
167
         this.title = title;
169
         this.components = new HashSet<>(components);
168
         this.components = new HashSet<>(components);
170
         this.writable = true;
169
         this.writable = true;
171
-        this.commandParser = Optional.of(commandParser);
172
         this.tabCompleter = Optional.of(tabCompleter);
170
         this.tabCompleter = Optional.of(tabCompleter);
173
         this.messageSinkManager = Optional.of(messageSinkManager);
171
         this.messageSinkManager = Optional.of(messageSinkManager);
174
         this.backBufferFactory = backBufferFactory;
172
         this.backBufferFactory = backBufferFactory;
175
-        commandParser.setOwner(this);
176
 
173
 
177
         eventBusManager = new ChildEventBusManager(eventBus);
174
         eventBusManager = new ChildEventBusManager(eventBus);
178
         eventBusManager.connect();
175
         eventBusManager.connect();
189
         backBuffer.startAddingEvents();
186
         backBuffer.startAddingEvents();
190
     }
187
     }
191
 
188
 
189
+    public void setCommandParser(final CommandParser commandParser) {
190
+        this.commandParser = Optional.ofNullable(commandParser);
191
+    }
192
+
192
     @Override
193
     @Override
193
     public Optional<WindowModel> getParent() {
194
     public Optional<WindowModel> getParent() {
194
         return parent;
195
         return parent;

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

56
             final GlobalCommandParser parser, final TabCompleterFactory tabCompleterFactory,
56
             final GlobalCommandParser parser, final TabCompleterFactory tabCompleterFactory,
57
             final MessageSinkManager messageSinkManager,
57
             final MessageSinkManager messageSinkManager,
58
             final DMDircMBassador eventBus, final BackBufferFactory backBufferFactory) {
58
             final DMDircMBassador eventBus, final BackBufferFactory backBufferFactory) {
59
-        super(null, "icon", "Global", "(Global)", config, backBufferFactory, parser,
59
+        super(null, "icon", "Global", "(Global)", config, backBufferFactory,
60
                 tabCompleterFactory.getTabCompleter(config, CommandType.TYPE_GLOBAL),
60
                 tabCompleterFactory.getTabCompleter(config, CommandType.TYPE_GLOBAL),
61
                 messageSinkManager, eventBus,
61
                 messageSinkManager, eventBus,
62
                 Arrays.asList(WindowComponent.TEXTAREA.getIdentifier(),
62
                 Arrays.asList(WindowComponent.TEXTAREA.getIdentifier(),
63
                         WindowComponent.INPUTFIELD.getIdentifier()));
63
                         WindowComponent.INPUTFIELD.getIdentifier()));
64
         initBackBuffer();
64
         initBackBuffer();
65
+        setCommandParser(parser);
65
     }
66
     }
66
 
67
 
67
     @Override
68
     @Override

+ 0
- 5
src/com/dmdirc/Query.java View File

23
 package com.dmdirc;
23
 package com.dmdirc;
24
 
24
 
25
 import com.dmdirc.commandparser.CommandType;
25
 import com.dmdirc.commandparser.CommandType;
26
-import com.dmdirc.commandparser.parsers.QueryCommandParser;
27
 import com.dmdirc.events.AppErrorEvent;
26
 import com.dmdirc.events.AppErrorEvent;
28
 import com.dmdirc.events.CommandErrorEvent;
27
 import com.dmdirc.events.CommandErrorEvent;
29
 import com.dmdirc.events.QueryActionEvent;
28
 import com.dmdirc.events.QueryActionEvent;
33
 import com.dmdirc.events.QueryQuitEvent;
32
 import com.dmdirc.events.QueryQuitEvent;
34
 import com.dmdirc.events.QuerySelfActionEvent;
33
 import com.dmdirc.events.QuerySelfActionEvent;
35
 import com.dmdirc.events.QuerySelfMessageEvent;
34
 import com.dmdirc.events.QuerySelfMessageEvent;
36
-import com.dmdirc.interfaces.CommandController;
37
 import com.dmdirc.interfaces.Connection;
35
 import com.dmdirc.interfaces.Connection;
38
 import com.dmdirc.interfaces.PrivateChat;
36
 import com.dmdirc.interfaces.PrivateChat;
39
 import com.dmdirc.interfaces.User;
37
 import com.dmdirc.interfaces.User;
78
             final Connection connection,
76
             final Connection connection,
79
             final User user,
77
             final User user,
80
             final TabCompleterFactory tabCompleterFactory,
78
             final TabCompleterFactory tabCompleterFactory,
81
-            final CommandController commandController,
82
             final MessageSinkManager messageSinkManager,
79
             final MessageSinkManager messageSinkManager,
83
             final BackBufferFactory backBufferFactory) {
80
             final BackBufferFactory backBufferFactory) {
84
         super(connection.getWindowModel(), "query",
81
         super(connection.getWindowModel(), "query",
86
                 user.getNickname(),
83
                 user.getNickname(),
87
                 connection.getWindowModel().getConfigManager(),
84
                 connection.getWindowModel().getConfigManager(),
88
                 backBufferFactory,
85
                 backBufferFactory,
89
-                new QueryCommandParser(connection.getWindowModel(),
90
-                        commandController, connection.getWindowModel().getEventBus()),
91
                 tabCompleterFactory.getTabCompleter(connection.getWindowModel().getTabCompleter(),
86
                 tabCompleterFactory.getTabCompleter(connection.getWindowModel().getTabCompleter(),
92
                         connection.getWindowModel().getConfigManager(),
87
                         connection.getWindowModel().getConfigManager(),
93
                         CommandType.TYPE_QUERY, CommandType.TYPE_CHAT),
88
                         CommandType.TYPE_QUERY, CommandType.TYPE_CHAT),

+ 4
- 1
src/com/dmdirc/QueryFactory.java View File

22
 
22
 
23
 package com.dmdirc;
23
 package com.dmdirc;
24
 
24
 
25
+import com.dmdirc.commandparser.parsers.QueryCommandParser;
25
 import com.dmdirc.events.QueryOpenedEvent;
26
 import com.dmdirc.events.QueryOpenedEvent;
26
 import com.dmdirc.interfaces.CommandController;
27
 import com.dmdirc.interfaces.CommandController;
27
 import com.dmdirc.interfaces.Connection;
28
 import com.dmdirc.interfaces.Connection;
58
     }
59
     }
59
 
60
 
60
     public Query getQuery(final Connection connection, final User user) {
61
     public Query getQuery(final Connection connection, final User user) {
61
-        final Query query = new Query(connection, user, tabCompleterFactory, commandController,
62
+        final Query query = new Query(connection, user, tabCompleterFactory,
62
                 messageSinkManager, backBufferFactory);
63
                 messageSinkManager, backBufferFactory);
64
+        query.setCommandParser(new QueryCommandParser(connection.getWindowModel(),
65
+                commandController, connection.getWindowModel().getEventBus(), query));
63
         windowManager.addWindow(connection.getWindowModel(), query);
66
         windowManager.addWindow(connection.getWindowModel(), query);
64
         connection.getWindowModel().getEventBus().publish(new QueryOpenedEvent(query));
67
         connection.getWindowModel().getEventBus().publish(new QueryOpenedEvent(query));
65
         return query;
68
         return query;

+ 0
- 3
src/com/dmdirc/Server.java View File

23
 package com.dmdirc;
23
 package com.dmdirc;
24
 
24
 
25
 import com.dmdirc.commandparser.CommandType;
25
 import com.dmdirc.commandparser.CommandType;
26
-import com.dmdirc.commandparser.parsers.CommandParser;
27
 import com.dmdirc.config.profiles.Profile;
26
 import com.dmdirc.config.profiles.Profile;
28
 import com.dmdirc.events.AppErrorEvent;
27
 import com.dmdirc.events.AppErrorEvent;
29
 import com.dmdirc.events.ServerConnectErrorEvent;
28
 import com.dmdirc.events.ServerConnectErrorEvent;
177
      */
176
      */
178
     public Server(
177
     public Server(
179
             final ConfigProviderMigrator configMigrator,
178
             final ConfigProviderMigrator configMigrator,
180
-            final CommandParser commandParser,
181
             final ParserFactory parserFactory,
179
             final ParserFactory parserFactory,
182
             final TabCompleterFactory tabCompleterFactory,
180
             final TabCompleterFactory tabCompleterFactory,
183
             final IdentityFactory identityFactory,
181
             final IdentityFactory identityFactory,
197
                 getHost(uri),
195
                 getHost(uri),
198
                 configMigrator.getConfigProvider(),
196
                 configMigrator.getConfigProvider(),
199
                 backBufferFactory,
197
                 backBufferFactory,
200
-                commandParser,
201
                 tabCompleterFactory.getTabCompleter(configMigrator.getConfigProvider(),
198
                 tabCompleterFactory.getTabCompleter(configMigrator.getConfigProvider(),
202
                         CommandType.TYPE_SERVER, CommandType.TYPE_GLOBAL),
199
                         CommandType.TYPE_SERVER, CommandType.TYPE_GLOBAL),
203
                 messageSinkManager,
200
                 messageSinkManager,

+ 9
- 3
src/com/dmdirc/ServerFactoryImpl.java View File

22
 
22
 
23
 package com.dmdirc;
23
 package com.dmdirc;
24
 
24
 
25
-import com.dmdirc.commandparser.parsers.CommandParser;
25
+import com.dmdirc.commandparser.parsers.ServerCommandParser;
26
 import com.dmdirc.config.profiles.Profile;
26
 import com.dmdirc.config.profiles.Profile;
27
+import com.dmdirc.interfaces.CommandController;
27
 import com.dmdirc.interfaces.config.ConfigProvider;
28
 import com.dmdirc.interfaces.config.ConfigProvider;
28
 import com.dmdirc.interfaces.config.ConfigProviderMigrator;
29
 import com.dmdirc.interfaces.config.ConfigProviderMigrator;
29
 import com.dmdirc.interfaces.config.IdentityFactory;
30
 import com.dmdirc.interfaces.config.IdentityFactory;
49
     private final IdentityFactory identityFactory;
50
     private final IdentityFactory identityFactory;
50
     private final MessageSinkManager messageSinkManager;
51
     private final MessageSinkManager messageSinkManager;
51
     private final Provider<QueryFactory> queryFactory;
52
     private final Provider<QueryFactory> queryFactory;
53
+    private final Provider<CommandController> commandController;
52
     private final DMDircMBassador eventBus;
54
     private final DMDircMBassador eventBus;
53
     private final MessageEncoderFactory messageEncoderFactory;
55
     private final MessageEncoderFactory messageEncoderFactory;
54
     private final ConfigProvider userSettings;
56
     private final ConfigProvider userSettings;
63
             final IdentityFactory identityFactory,
65
             final IdentityFactory identityFactory,
64
             final MessageSinkManager messageSinkManager,
66
             final MessageSinkManager messageSinkManager,
65
             final Provider<QueryFactory> queryFactory,
67
             final Provider<QueryFactory> queryFactory,
68
+            final Provider<CommandController> commandController,
66
             final DMDircMBassador eventBus,
69
             final DMDircMBassador eventBus,
67
             final MessageEncoderFactory messageEncoderFactory,
70
             final MessageEncoderFactory messageEncoderFactory,
68
             @ClientModule.UserConfig final ConfigProvider userSettings,
71
             @ClientModule.UserConfig final ConfigProvider userSettings,
74
         this.identityFactory = identityFactory;
77
         this.identityFactory = identityFactory;
75
         this.messageSinkManager = messageSinkManager;
78
         this.messageSinkManager = messageSinkManager;
76
         this.queryFactory = queryFactory;
79
         this.queryFactory = queryFactory;
80
+        this.commandController = commandController;
77
         this.eventBus = eventBus;
81
         this.eventBus = eventBus;
78
         this.messageEncoderFactory = messageEncoderFactory;
82
         this.messageEncoderFactory = messageEncoderFactory;
79
         this.userSettings = userSettings;
83
         this.userSettings = userSettings;
84
 
88
 
85
     public Server getServer(
89
     public Server getServer(
86
             final ConfigProviderMigrator configMigrator,
90
             final ConfigProviderMigrator configMigrator,
87
-            final CommandParser commandParser,
88
             final ScheduledExecutorService executorService,
91
             final ScheduledExecutorService executorService,
89
             final URI uri,
92
             final URI uri,
90
             final Profile profile) {
93
             final Profile profile) {
91
-        return new Server(configMigrator, commandParser, parserFactory,
94
+        final Server server = new Server(configMigrator, parserFactory,
92
                 tabCompleterFactory, identityFactory, messageSinkManager,
95
                 tabCompleterFactory, identityFactory, messageSinkManager,
93
                 queryFactory.get(), eventBus, messageEncoderFactory, userSettings,
96
                 queryFactory.get(), eventBus, messageEncoderFactory, userSettings,
94
                 groupChatManagerFactory, executorService, uri, profile, backBufferFactory,
97
                 groupChatManagerFactory, executorService, uri, profile, backBufferFactory,
95
                 userManager);
98
                 userManager);
99
+        server.setCommandParser(new ServerCommandParser(server.getConfigManager(),
100
+                commandController.get(), eventBus, server));
101
+        return server;
96
     }
102
     }
97
 }
103
 }

+ 0
- 2
src/com/dmdirc/ServerManager.java View File

110
 
110
 
111
         final Server server = serverFactoryImpl.getServer(
111
         final Server server = serverFactoryImpl.getServer(
112
                 configProvider,
112
                 configProvider,
113
-                new ServerCommandParser(configProvider.getConfigProvider(), commandController.get(),
114
-                        eventBus),
115
                 Executors.newScheduledThreadPool(1,
113
                 Executors.newScheduledThreadPool(1,
116
                         new ThreadFactoryBuilder().setNameFormat("server-timer-%d").build()),
114
                         new ThreadFactoryBuilder().setNameFormat("server-timer-%d").build()),
117
                 uri,
115
                 uri,

+ 7
- 13
src/com/dmdirc/commandparser/parsers/ChannelCommandParser.java View File

43
     /** A version number for this class. */
43
     /** A version number for this class. */
44
     private static final long serialVersionUID = 1;
44
     private static final long serialVersionUID = 1;
45
     /** The group chat instance that this parser is attached to. */
45
     /** The group chat instance that this parser is attached to. */
46
-    private GroupChat groupChat;
46
+    private final GroupChat groupChat;
47
 
47
 
48
     /**
48
     /**
49
      * Creates a new instance of ChannelCommandParser.
49
      * Creates a new instance of ChannelCommandParser.
52
      * @param commandController The controller to load commands from.
52
      * @param commandController The controller to load commands from.
53
      * @param eventBus          Event bus to post events on
53
      * @param eventBus          Event bus to post events on
54
      */
54
      */
55
-    public ChannelCommandParser(final WindowModel owner,
55
+    public ChannelCommandParser(
56
+            final WindowModel owner,
56
             final CommandController commandController,
57
             final CommandController commandController,
57
-            final DMDircMBassador eventBus) {
58
-        super(owner, commandController, eventBus);
59
-    }
60
-
61
-    @Override
62
-    public void setOwner(final WindowModel owner) {
63
-        if (groupChat == null) {
64
-            // TODO: Can't assume that framecontainers may be group chats.
65
-            groupChat = (GroupChat) owner;
66
-        }
58
+            final DMDircMBassador eventBus,
59
+            final GroupChat groupChat) {
60
+        super(owner, commandController, eventBus, groupChat);
67
 
61
 
68
-        super.setOwner(owner);
62
+        this.groupChat = groupChat;
69
     }
63
     }
70
 
64
 
71
     @Override
65
     @Override

+ 8
- 12
src/com/dmdirc/commandparser/parsers/ChatCommandParser.java View File

45
     /** A version number for this class. */
45
     /** A version number for this class. */
46
     private static final long serialVersionUID = 1;
46
     private static final long serialVersionUID = 1;
47
     /** The container that owns this parser. */
47
     /** The container that owns this parser. */
48
-    private Chat owner;
48
+    private final Chat owner;
49
 
49
 
50
     /**
50
     /**
51
      * Creates a new chat command parser that belongs to a child of the specified server.
51
      * Creates a new chat command parser that belongs to a child of the specified server.
54
      * @param commandController The controller to load commands from.
54
      * @param commandController The controller to load commands from.
55
      * @param eventBus          Event but to post events on
55
      * @param eventBus          Event but to post events on
56
      */
56
      */
57
-    public ChatCommandParser(final WindowModel owner, final CommandController commandController,
58
-            final DMDircMBassador eventBus) {
59
-        super(owner.getConfigManager(), commandController, eventBus);
60
-        super.setOwner(owner);
61
-    }
62
-
63
-    @Override
64
-    public void setOwner(final WindowModel owner) {
65
-        if (this.owner == null && owner instanceof Chat) {
66
-            this.owner = (Chat) owner;
67
-        }
57
+    public ChatCommandParser(
58
+            final WindowModel owner,
59
+            final CommandController commandController,
60
+            final DMDircMBassador eventBus,
61
+            final Chat chat) {
62
+        super(owner.getConfigManager(), commandController, eventBus, chat.getConnection().get());
63
+        this.owner = chat;
68
     }
64
     }
69
 
65
 
70
     @Override
66
     @Override

+ 0
- 9
src/com/dmdirc/commandparser/parsers/CommandParser.java View File

87
         loadCommands();
87
         loadCommands();
88
     }
88
     }
89
 
89
 
90
-    /**
91
-     * Sets the owner of this command parser.
92
-     *
93
-     * @param owner The container which owns this parser
94
-     *
95
-     * @since 0.6.4
96
-     */
97
-    public abstract void setOwner(final WindowModel owner);
98
-
99
     /** Loads the relevant commands into the parser. */
90
     /** Loads the relevant commands into the parser. */
100
     protected abstract void loadCommands();
91
     protected abstract void loadCommands();
101
 
92
 

+ 0
- 5
src/com/dmdirc/commandparser/parsers/GlobalCommandParser.java View File

66
         this.eventBus = eventBus;
66
         this.eventBus = eventBus;
67
     }
67
     }
68
 
68
 
69
-    @Override
70
-    public void setOwner(final WindowModel owner) {
71
-        // Don't care
72
-    }
73
-
74
     /** Loads the relevant commands into the parser. */
69
     /** Loads the relevant commands into the parser. */
75
     @Override
70
     @Override
76
     protected void loadCommands() {
71
     protected void loadCommands() {

+ 4
- 12
src/com/dmdirc/commandparser/parsers/QueryCommandParser.java View File

46
     /**
46
     /**
47
      * The query instance that this parser is attached to.
47
      * The query instance that this parser is attached to.
48
      */
48
      */
49
-    private Query query;
49
+    private final Query query;
50
 
50
 
51
     /**
51
     /**
52
      * Creates a new instance of QueryCommandParser.
52
      * Creates a new instance of QueryCommandParser.
56
      * @param eventBus          Event bus to post events on
56
      * @param eventBus          Event bus to post events on
57
      */
57
      */
58
     public QueryCommandParser(final WindowModel owner, final CommandController commandController,
58
     public QueryCommandParser(final WindowModel owner, final CommandController commandController,
59
-            final DMDircMBassador eventBus) {
60
-        super(owner, commandController, eventBus);
61
-    }
62
-
63
-    @Override
64
-    public void setOwner(final WindowModel owner) {
65
-        if (query == null) {
66
-            query = (Query) owner;
67
-        }
68
-
69
-        super.setOwner(query);
59
+            final DMDircMBassador eventBus, final Query query) {
60
+        super(owner, commandController, eventBus, query);
61
+        this.query = query;
70
     }
62
     }
71
 
63
 
72
     /** Loads the relevant commands into the parser. */
64
     /** Loads the relevant commands into the parser. */

+ 8
- 14
src/com/dmdirc/commandparser/parsers/ServerCommandParser.java View File

46
     /** A version number for this class. */
46
     /** A version number for this class. */
47
     private static final long serialVersionUID = 1;
47
     private static final long serialVersionUID = 1;
48
 
48
 
49
+    /**
50
+     * The server instance that this parser is attached to.
51
+     */
52
+    private final Connection server;
53
+
49
     /**
54
     /**
50
      * Creates a new command parser for server commands.
55
      * Creates a new command parser for server commands.
51
      *
56
      *
56
     public ServerCommandParser(
61
     public ServerCommandParser(
57
             final AggregateConfigProvider configManager,
62
             final AggregateConfigProvider configManager,
58
             final CommandController commandController,
63
             final CommandController commandController,
59
-            final DMDircMBassador eventBus) {
64
+            final DMDircMBassador eventBus,
65
+            final Connection connection) {
60
         super(configManager, commandController, eventBus);
66
         super(configManager, commandController, eventBus);
61
-    }
62
-    /**
63
-     * The server instance that this parser is attached to.
64
-     */
65
-    private Connection server;
66
-
67
-    @Override
68
-    public void setOwner(final WindowModel owner) {
69
-        if (server == null && owner instanceof Connection) {
70
-            server = (Connection) owner;
71
-        }
72
-
73
-        super.setOwner(owner);
67
+        this.server = connection;
74
     }
68
     }
75
 
69
 
76
     /** Loads the relevant commands into the parser. */
70
     /** Loads the relevant commands into the parser. */

+ 1
- 2
test/com/dmdirc/ServerManagerTest.java View File

22
 
22
 
23
 package com.dmdirc;
23
 package com.dmdirc;
24
 
24
 
25
-import com.dmdirc.commandparser.parsers.CommandParser;
26
 import com.dmdirc.config.profiles.Profile;
25
 import com.dmdirc.config.profiles.Profile;
27
 import com.dmdirc.config.profiles.ProfileManager;
26
 import com.dmdirc.config.profiles.ProfileManager;
28
 import com.dmdirc.interfaces.CommandController;
27
 import com.dmdirc.interfaces.CommandController;
92
                 anyString())).thenReturn(configProviderMigrator);
91
                 anyString())).thenReturn(configProviderMigrator);
93
         when(configProviderMigrator.getConfigProvider()).thenReturn(configProvider);
92
         when(configProviderMigrator.getConfigProvider()).thenReturn(configProvider);
94
 
93
 
95
-        when(serverFactoryImpl.getServer(eq(configProviderMigrator), any(CommandParser.class),
94
+        when(serverFactoryImpl.getServer(eq(configProviderMigrator),
96
                 any(ScheduledExecutorService.class), uriCaptor.capture(), eq(profile)))
95
                 any(ScheduledExecutorService.class), uriCaptor.capture(), eq(profile)))
97
                 .thenReturn(server);
96
                 .thenReturn(server);
98
     }
97
     }

+ 0
- 5
test/com/dmdirc/harness/TestCommandParser.java View File

83
         invalidCommand = args.getCommandName();
83
         invalidCommand = args.getCommandName();
84
     }
84
     }
85
 
85
 
86
-    @Override
87
-    public void setOwner(final WindowModel owner) {
88
-        // Don't care
89
-    }
90
-
91
 }
86
 }

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

48
             final DMDircMBassador eventBus,
48
             final DMDircMBassador eventBus,
49
             final BackBufferFactory backBufferFactory) {
49
             final BackBufferFactory backBufferFactory) {
50
         super(null, "raw", "Raw", "(Raw)", cm, backBufferFactory,
50
         super(null, "raw", "Raw", "(Raw)", cm, backBufferFactory,
51
-                new GlobalCommandParser(cm, commandManager, eventBus),
52
                 new TabCompleter(mock(CommandController.class), cm),
51
                 new TabCompleter(mock(CommandController.class), cm),
53
                 messageSinkManager,
52
                 messageSinkManager,
54
                 eventBus,
53
                 eventBus,
55
                 Collections.<String>emptySet());
54
                 Collections.<String>emptySet());
56
 
55
 
56
+        setCommandParser(new GlobalCommandParser(cm, commandManager, eventBus));
57
         this.lineLength = lineLength;
57
         this.lineLength = lineLength;
58
     }
58
     }
59
 
59
 

Loading…
Cancel
Save