Bläddra i källkod

Make CommandParser use WindowModel.

pull/535/head
Chris Smith 9 år sedan
förälder
incheckning
a5b74d14f8

+ 2
- 2
src/com/dmdirc/commandparser/commands/context/ChannelCommandContext.java Visa fil

@@ -22,9 +22,9 @@
22 22
 
23 23
 package com.dmdirc.commandparser.commands.context;
24 24
 
25
-import com.dmdirc.FrameContainer;
26 25
 import com.dmdirc.commandparser.CommandInfo;
27 26
 import com.dmdirc.interfaces.GroupChat;
27
+import com.dmdirc.interfaces.WindowModel;
28 28
 
29 29
 /**
30 30
  * A specialised {@link CommandContext} for commands executed in channels.
@@ -43,7 +43,7 @@ public class ChannelCommandContext extends ChatCommandContext {
43 43
      * @param commandInfo The command info object which associated the command with the input
44 44
      * @param groupChat  The group chat associated with the command
45 45
      */
46
-    public ChannelCommandContext(final FrameContainer source,
46
+    public ChannelCommandContext(final WindowModel source,
47 47
             final CommandInfo commandInfo, final GroupChat groupChat) {
48 48
         super(source, commandInfo, groupChat);
49 49
         this.groupChat = groupChat;

+ 3
- 3
src/com/dmdirc/commandparser/commands/context/ChatCommandContext.java Visa fil

@@ -22,9 +22,9 @@
22 22
 
23 23
 package com.dmdirc.commandparser.commands.context;
24 24
 
25
-import com.dmdirc.FrameContainer;
26 25
 import com.dmdirc.commandparser.CommandInfo;
27 26
 import com.dmdirc.interfaces.Chat;
27
+import com.dmdirc.interfaces.WindowModel;
28 28
 
29 29
 import java.util.Optional;
30 30
 
@@ -45,11 +45,11 @@ public class ChatCommandContext extends ServerCommandContext {
45 45
      * @param commandInfo The command info object which associated the command with the input
46 46
      * @param chat        The chat container associated with the command
47 47
      */
48
-    public ChatCommandContext(final FrameContainer source,
48
+    public ChatCommandContext(final WindowModel source,
49 49
             final CommandInfo commandInfo, final Chat chat) {
50 50
         super(source, commandInfo,
51 51
                 Optional.ofNullable(source)
52
-                        .flatMap(FrameContainer::getConnection)
52
+                        .flatMap(WindowModel::getConnection)
53 53
                         .orElse(null));
54 54
         this.chat = chat;
55 55
     }

+ 4
- 4
src/com/dmdirc/commandparser/commands/context/CommandContext.java Visa fil

@@ -22,8 +22,8 @@
22 22
 
23 23
 package com.dmdirc.commandparser.commands.context;
24 24
 
25
-import com.dmdirc.FrameContainer;
26 25
 import com.dmdirc.commandparser.CommandInfo;
26
+import com.dmdirc.interfaces.WindowModel;
27 27
 
28 28
 /**
29 29
  * Provides information relating to the context that a command was executed in.
@@ -35,7 +35,7 @@ public class CommandContext {
35 35
     /** The command info object which associated the command with the input. */
36 36
     protected final CommandInfo commandInfo;
37 37
     /** The source of this command. */
38
-    protected final FrameContainer source;
38
+    protected final WindowModel source;
39 39
 
40 40
     /**
41 41
      * Creates a new command context.
@@ -43,7 +43,7 @@ public class CommandContext {
43 43
      * @param source      The source of the command
44 44
      * @param commandInfo The command info object which associated the command with the input
45 45
      */
46
-    public CommandContext(final FrameContainer source, final CommandInfo commandInfo) {
46
+    public CommandContext(final WindowModel source, final CommandInfo commandInfo) {
47 47
         this.source = source;
48 48
         this.commandInfo = commandInfo;
49 49
     }
@@ -63,7 +63,7 @@ public class CommandContext {
63 63
      *
64 64
      * @return The window the command came from, or null
65 65
      */
66
-    public FrameContainer getSource() {
66
+    public WindowModel getSource() {
67 67
         return source;
68 68
     }
69 69
 

+ 2
- 2
src/com/dmdirc/commandparser/commands/context/QueryCommandContext.java Visa fil

@@ -22,9 +22,9 @@
22 22
 
23 23
 package com.dmdirc.commandparser.commands.context;
24 24
 
25
-import com.dmdirc.FrameContainer;
26 25
 import com.dmdirc.Query;
27 26
 import com.dmdirc.commandparser.CommandInfo;
27
+import com.dmdirc.interfaces.WindowModel;
28 28
 
29 29
 /**
30 30
  * A query-specific command context.
@@ -43,7 +43,7 @@ public class QueryCommandContext extends ChatCommandContext {
43 43
      * @param commandInfo The command info object which associated the command with the input
44 44
      * @param query       The query associated with the command
45 45
      */
46
-    public QueryCommandContext(final FrameContainer source,
46
+    public QueryCommandContext(final WindowModel source,
47 47
             final CommandInfo commandInfo, final Query query) {
48 48
         super(source, commandInfo, query);
49 49
         this.query = query;

+ 2
- 2
src/com/dmdirc/commandparser/commands/context/ServerCommandContext.java Visa fil

@@ -22,9 +22,9 @@
22 22
 
23 23
 package com.dmdirc.commandparser.commands.context;
24 24
 
25
-import com.dmdirc.FrameContainer;
26 25
 import com.dmdirc.commandparser.CommandInfo;
27 26
 import com.dmdirc.interfaces.Connection;
27
+import com.dmdirc.interfaces.WindowModel;
28 28
 
29 29
 /**
30 30
  * A command context for connection commands.
@@ -43,7 +43,7 @@ public class ServerCommandContext extends CommandContext {
43 43
      * @param commandInfo The command info object which associated the command with the input
44 44
      * @param connection      The connection associated with the command
45 45
      */
46
-    public ServerCommandContext(final FrameContainer source, final CommandInfo commandInfo,
46
+    public ServerCommandContext(final WindowModel source, final CommandInfo commandInfo,
47 47
             final Connection connection) {
48 48
         super(source, commandInfo);
49 49
         this.connection = connection;

+ 4
- 3
src/com/dmdirc/commandparser/parsers/ChannelCommandParser.java Visa fil

@@ -32,6 +32,7 @@ import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
32 32
 import com.dmdirc.commandparser.commands.context.CommandContext;
33 33
 import com.dmdirc.interfaces.CommandController;
34 34
 import com.dmdirc.interfaces.GroupChat;
35
+import com.dmdirc.interfaces.WindowModel;
35 36
 
36 37
 import javax.annotation.Nonnull;
37 38
 
@@ -59,7 +60,7 @@ public class ChannelCommandParser extends ChatCommandParser {
59 60
     }
60 61
 
61 62
     @Override
62
-    public void setOwner(final FrameContainer owner) {
63
+    public void setOwner(final WindowModel owner) {
63 64
         if (groupChat == null) {
64 65
             // TODO: Can't assume that framecontainers may be group chats.
65 66
             groupChat = (GroupChat) owner;
@@ -76,7 +77,7 @@ public class ChannelCommandParser extends ChatCommandParser {
76 77
 
77 78
     @Override
78 79
     protected CommandContext getCommandContext(
79
-            final FrameContainer origin,
80
+            final WindowModel origin,
80 81
             final CommandInfo commandInfo,
81 82
             final Command command,
82 83
             final CommandArguments args) {
@@ -85,7 +86,7 @@ public class ChannelCommandParser extends ChatCommandParser {
85 86
 
86 87
     @Override
87 88
     protected void executeCommand(
88
-            @Nonnull final FrameContainer origin,
89
+            @Nonnull final WindowModel origin,
89 90
             final CommandInfo commandInfo,
90 91
             final Command command,
91 92
             final CommandArguments args,

+ 5
- 4
src/com/dmdirc/commandparser/parsers/ChatCommandParser.java Visa fil

@@ -32,6 +32,7 @@ import com.dmdirc.commandparser.commands.context.ChatCommandContext;
32 32
 import com.dmdirc.commandparser.commands.context.CommandContext;
33 33
 import com.dmdirc.interfaces.Chat;
34 34
 import com.dmdirc.interfaces.CommandController;
35
+import com.dmdirc.interfaces.WindowModel;
35 36
 
36 37
 import javax.annotation.Nonnull;
37 38
 
@@ -61,7 +62,7 @@ public class ChatCommandParser extends ServerCommandParser {
61 62
     }
62 63
 
63 64
     @Override
64
-    public void setOwner(final FrameContainer owner) {
65
+    public void setOwner(final WindowModel owner) {
65 66
         if (this.owner == null && owner instanceof Chat) {
66 67
             this.owner = (Chat) owner;
67 68
         }
@@ -69,7 +70,7 @@ public class ChatCommandParser extends ServerCommandParser {
69 70
 
70 71
     @Override
71 72
     protected CommandContext getCommandContext(
72
-            final FrameContainer origin,
73
+            final WindowModel origin,
73 74
             final CommandInfo commandInfo,
74 75
             final Command command,
75 76
             final CommandArguments args) {
@@ -78,7 +79,7 @@ public class ChatCommandParser extends ServerCommandParser {
78 79
 
79 80
     @Override
80 81
     protected void executeCommand(
81
-            @Nonnull final FrameContainer origin,
82
+            @Nonnull final WindowModel origin,
82 83
             final CommandInfo commandInfo,
83 84
             final Command command,
84 85
             final CommandArguments args,
@@ -91,7 +92,7 @@ public class ChatCommandParser extends ServerCommandParser {
91 92
     }
92 93
 
93 94
     @Override
94
-    protected void handleNonCommand(final FrameContainer origin,
95
+    protected void handleNonCommand(final WindowModel origin,
95 96
             final String line) {
96 97
         owner.sendLine(line);
97 98
     }

+ 12
- 10
src/com/dmdirc/commandparser/parsers/CommandParser.java Visa fil

@@ -38,6 +38,7 @@ import com.dmdirc.events.UnknownCommandEvent;
38 38
 import com.dmdirc.interfaces.CommandController;
39 39
 import com.dmdirc.interfaces.Connection;
40 40
 import com.dmdirc.interfaces.GroupChat;
41
+import com.dmdirc.interfaces.WindowModel;
41 42
 import com.dmdirc.interfaces.config.ReadOnlyConfigProvider;
42 43
 import com.dmdirc.util.EventUtils;
43 44
 import com.dmdirc.util.collections.RollingList;
@@ -94,7 +95,7 @@ public abstract class CommandParser implements Serializable {
94 95
      *
95 96
      * @since 0.6.4
96 97
      */
97
-    public abstract void setOwner(final FrameContainer owner);
98
+    public abstract void setOwner(final WindowModel owner);
98 99
 
99 100
     /** Loads the relevant commands into the parser. */
100 101
     protected abstract void loadCommands();
@@ -140,7 +141,7 @@ public abstract class CommandParser implements Serializable {
140 141
      *
141 142
      * @since 0.6.4
142 143
      */
143
-    public final void parseCommand(@Nonnull final FrameContainer origin, final String line,
144
+    public final void parseCommand(@Nonnull final WindowModel origin, final String line,
144 145
             final boolean parseChannel) {
145 146
         checkNotNull(origin);
146 147
 
@@ -176,7 +177,7 @@ public abstract class CommandParser implements Serializable {
176 177
      *
177 178
      * @return True iff the command was handled, false otherwise
178 179
      */
179
-    protected boolean handleChannelCommand(@Nonnull final FrameContainer origin,
180
+    protected boolean handleChannelCommand(@Nonnull final WindowModel origin,
180 181
             final CommandArguments args, final boolean parseChannel) {
181 182
         final boolean silent = args.isSilent();
182 183
         final String command = args.getCommandName();
@@ -200,7 +201,8 @@ public abstract class CommandParser implements Serializable {
200 201
         if (someValid) {
201 202
             for (String channelName : parts) {
202 203
                 if (!server.getGroupChatManager().isValidChannelName(channelName)) {
203
-                    origin.getEventBus().publishAsync(new CommandErrorEvent(origin,
204
+                    origin.getEventBus().publishAsync(new CommandErrorEvent(
205
+                            (FrameContainer) origin,
204 206
                             "Invalid channel name: " + channelName));
205 207
                     continue;
206 208
                 }
@@ -301,7 +303,7 @@ public abstract class CommandParser implements Serializable {
301 303
      * @return The context for the command.
302 304
      */
303 305
     protected abstract CommandContext getCommandContext(
304
-            final FrameContainer origin,
306
+            final WindowModel origin,
305 307
             final CommandInfo commandInfo,
306 308
             final Command command,
307 309
             final CommandArguments args);
@@ -316,7 +318,7 @@ public abstract class CommandParser implements Serializable {
316 318
      * @param context     The context to use when executing the command
317 319
      */
318 320
     protected abstract void executeCommand(
319
-            @Nonnull final FrameContainer origin,
321
+            @Nonnull final WindowModel origin,
320 322
             final CommandInfo commandInfo, final Command command,
321 323
             final CommandArguments args, final CommandContext context);
322 324
 
@@ -330,13 +332,13 @@ public abstract class CommandParser implements Serializable {
330 332
      *
331 333
      * @since 0.6.3m1
332 334
      */
333
-    protected void handleInvalidCommand(final FrameContainer origin,
335
+    protected void handleInvalidCommand(final WindowModel origin,
334 336
             final CommandArguments args) {
335 337
         if (origin == null) {
336 338
             eventBus.publish(new UnknownCommandEvent(null, args.getCommandName(), args.getArguments()));
337 339
         } else {
338
-            final UnknownCommandEvent event = new UnknownCommandEvent(origin, args.getCommandName(),
339
-                    args.getArguments());
340
+            final UnknownCommandEvent event = new UnknownCommandEvent((FrameContainer) origin,
341
+                    args.getCommandName(), args.getArguments());
340 342
             final String format = EventUtils.postDisplayable(eventBus, event, "unknownCommand");
341 343
 
342 344
             origin.addLine(format, args.getCommandName());
@@ -350,7 +352,7 @@ public abstract class CommandParser implements Serializable {
350 352
      * @param origin The window in which the command was typed
351 353
      * @param line   The line input by the user
352 354
      */
353
-    protected abstract void handleNonCommand(final FrameContainer origin,
355
+    protected abstract void handleNonCommand(final WindowModel origin,
354 356
             final String line);
355 357
 
356 358
     /**

+ 7
- 5
src/com/dmdirc/commandparser/parsers/GlobalCommandParser.java Visa fil

@@ -33,6 +33,7 @@ import com.dmdirc.commandparser.commands.context.CommandContext;
33 33
 import com.dmdirc.events.CommandErrorEvent;
34 34
 import com.dmdirc.events.UserErrorEvent;
35 35
 import com.dmdirc.interfaces.CommandController;
36
+import com.dmdirc.interfaces.WindowModel;
36 37
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
37 38
 import com.dmdirc.logger.ErrorLevel;
38 39
 
@@ -67,7 +68,7 @@ public class GlobalCommandParser extends CommandParser {
67 68
     }
68 69
 
69 70
     @Override
70
-    public void setOwner(final FrameContainer owner) {
71
+    public void setOwner(final WindowModel owner) {
71 72
         // Don't care
72 73
     }
73 74
 
@@ -79,7 +80,7 @@ public class GlobalCommandParser extends CommandParser {
79 80
 
80 81
     @Override
81 82
     protected CommandContext getCommandContext(
82
-            final FrameContainer origin,
83
+            final WindowModel origin,
83 84
             final CommandInfo commandInfo,
84 85
             final Command command,
85 86
             final CommandArguments args) {
@@ -88,7 +89,7 @@ public class GlobalCommandParser extends CommandParser {
88 89
 
89 90
     @Override
90 91
     protected void executeCommand(
91
-            @Nonnull final FrameContainer origin,
92
+            @Nonnull final WindowModel origin,
92 93
             final CommandInfo commandInfo,
93 94
             final Command command,
94 95
             final CommandArguments args,
@@ -104,14 +105,15 @@ public class GlobalCommandParser extends CommandParser {
104 105
      * @param line   The line input by the user
105 106
      */
106 107
     @Override
107
-    protected void handleNonCommand(final FrameContainer origin, final String line) {
108
+    protected void handleNonCommand(final WindowModel origin, final String line) {
108 109
         if (origin == null) {
109 110
             eventBus.publish(new UserErrorEvent(ErrorLevel.MEDIUM,
110 111
                     new IllegalArgumentException("Invalid Global Command: " + line),
111 112
                     "Invalid Global Command: " + line, ""));
112 113
         } else {
113 114
             origin.getEventBus().publishAsync(
114
-                    new CommandErrorEvent(origin, "Invalid global command: " + line));
115
+                    new CommandErrorEvent((FrameContainer) origin,
116
+                            "Invalid global command: " + line));
115 117
         }
116 118
     }
117 119
 

+ 4
- 3
src/com/dmdirc/commandparser/parsers/QueryCommandParser.java Visa fil

@@ -32,6 +32,7 @@ import com.dmdirc.commandparser.commands.Command;
32 32
 import com.dmdirc.commandparser.commands.context.CommandContext;
33 33
 import com.dmdirc.commandparser.commands.context.QueryCommandContext;
34 34
 import com.dmdirc.interfaces.CommandController;
35
+import com.dmdirc.interfaces.WindowModel;
35 36
 
36 37
 import javax.annotation.Nonnull;
37 38
 
@@ -61,7 +62,7 @@ public class QueryCommandParser extends ChatCommandParser {
61 62
     }
62 63
 
63 64
     @Override
64
-    public void setOwner(final FrameContainer owner) {
65
+    public void setOwner(final WindowModel owner) {
65 66
         if (query == null) {
66 67
             query = (Query) owner;
67 68
         }
@@ -78,7 +79,7 @@ public class QueryCommandParser extends ChatCommandParser {
78 79
 
79 80
     @Override
80 81
     protected CommandContext getCommandContext(
81
-            final FrameContainer origin,
82
+            final WindowModel origin,
82 83
             final CommandInfo commandInfo,
83 84
             final Command command,
84 85
             final CommandArguments args) {
@@ -87,7 +88,7 @@ public class QueryCommandParser extends ChatCommandParser {
87 88
 
88 89
     @Override
89 90
     protected void executeCommand(
90
-            @Nonnull final FrameContainer origin,
91
+            @Nonnull final WindowModel origin,
91 92
             final CommandInfo commandInfo,
92 93
             final Command command,
93 94
             final CommandArguments args,

+ 7
- 5
src/com/dmdirc/commandparser/parsers/ServerCommandParser.java Visa fil

@@ -34,6 +34,7 @@ import com.dmdirc.commandparser.commands.context.ServerCommandContext;
34 34
 import com.dmdirc.events.CommandErrorEvent;
35 35
 import com.dmdirc.interfaces.CommandController;
36 36
 import com.dmdirc.interfaces.Connection;
37
+import com.dmdirc.interfaces.WindowModel;
37 38
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
38 39
 
39 40
 import javax.annotation.Nonnull;
@@ -65,7 +66,7 @@ public class ServerCommandParser extends GlobalCommandParser {
65 66
     private Connection server;
66 67
 
67 68
     @Override
68
-    public void setOwner(final FrameContainer owner) {
69
+    public void setOwner(final WindowModel owner) {
69 70
         if (server == null && owner instanceof Connection) {
70 71
             server = (Connection) owner;
71 72
         }
@@ -81,7 +82,7 @@ public class ServerCommandParser extends GlobalCommandParser {
81 82
 
82 83
     @Override
83 84
     protected CommandContext getCommandContext(
84
-            final FrameContainer origin,
85
+            final WindowModel origin,
85 86
             final CommandInfo commandInfo,
86 87
             final Command command,
87 88
             final CommandArguments args) {
@@ -90,7 +91,7 @@ public class ServerCommandParser extends GlobalCommandParser {
90 91
 
91 92
     @Override
92 93
     protected void executeCommand(
93
-            @Nonnull final FrameContainer origin,
94
+            @Nonnull final WindowModel origin,
94 95
             final CommandInfo commandInfo,
95 96
             final Command command,
96 97
             final CommandArguments args,
@@ -101,7 +102,8 @@ public class ServerCommandParser extends GlobalCommandParser {
101 102
                     && server.getState() != ServerState.CONNECTING)
102 103
                     || !server.getParser().isPresent())) {
103 104
                 if (!args.isSilent()) {
104
-                    origin.getEventBus().publishAsync(new CommandErrorEvent(origin,
105
+                    origin.getEventBus().publishAsync(new CommandErrorEvent(
106
+                            (FrameContainer) origin,
105 107
                             "You must be connected to use this command"));
106 108
                 }
107 109
             } else {
@@ -120,7 +122,7 @@ public class ServerCommandParser extends GlobalCommandParser {
120 122
      * @param line   The line input by the user
121 123
      */
122 124
     @Override
123
-    protected void handleNonCommand(final FrameContainer origin, final String line) {
125
+    protected void handleNonCommand(final WindowModel origin, final String line) {
124 126
         server.sendLine(line);
125 127
     }
126 128
 

+ 6
- 6
test/com/dmdirc/harness/TestCommandParser.java Visa fil

@@ -23,13 +23,13 @@
23 23
 package com.dmdirc.harness;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.FrameContainer;
27 26
 import com.dmdirc.commandparser.CommandArguments;
28 27
 import com.dmdirc.commandparser.CommandInfo;
29 28
 import com.dmdirc.commandparser.commands.Command;
30 29
 import com.dmdirc.commandparser.commands.context.CommandContext;
31 30
 import com.dmdirc.commandparser.parsers.CommandParser;
32 31
 import com.dmdirc.interfaces.CommandController;
32
+import com.dmdirc.interfaces.WindowModel;
33 33
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
34 34
 
35 35
 import javax.annotation.Nonnull;
@@ -59,7 +59,7 @@ public class TestCommandParser extends CommandParser {
59 59
     }
60 60
 
61 61
     @Override
62
-    protected void executeCommand(@Nonnull final FrameContainer origin, final CommandInfo commandInfo, final Command command,
62
+    protected void executeCommand(@Nonnull final WindowModel origin, final CommandInfo commandInfo, final Command command,
63 63
             final CommandArguments args, final CommandContext context) {
64 64
         executedCommand = command;
65 65
         wasSilent = args.isSilent();
@@ -67,24 +67,24 @@ public class TestCommandParser extends CommandParser {
67 67
     }
68 68
 
69 69
     @Override
70
-    protected CommandContext getCommandContext(final FrameContainer origin, final CommandInfo commandInfo,
70
+    protected CommandContext getCommandContext(final WindowModel origin, final CommandInfo commandInfo,
71 71
             final Command command, final CommandArguments args) {
72 72
         return new CommandContext(origin, commandInfo);
73 73
     }
74 74
 
75 75
     @Override
76
-    protected void handleNonCommand(final FrameContainer origin, final String line) {
76
+    protected void handleNonCommand(final WindowModel origin, final String line) {
77 77
         nonCommandLine = line;
78 78
     }
79 79
 
80 80
     @Override
81
-    protected void handleInvalidCommand(final FrameContainer origin,
81
+    protected void handleInvalidCommand(final WindowModel origin,
82 82
             final CommandArguments args) {
83 83
         invalidCommand = args.getCommandName();
84 84
     }
85 85
 
86 86
     @Override
87
-    public void setOwner(final FrameContainer owner) {
87
+    public void setOwner(final WindowModel owner) {
88 88
         // Don't care
89 89
     }
90 90
 

Laddar…
Avbryt
Spara