Browse Source

Dependency inject message sinks.

Change-Id: I124087eeaac00d68892c5d425618c80f853fb6a7
Reviewed-on: http://gerrit.dmdirc.com/3641
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
pull/1/head
Chris Smith 10 years ago
parent
commit
c57658f07d

+ 2
- 14
src/com/dmdirc/ClientModule.java View File

@@ -46,7 +46,7 @@ import com.dmdirc.interfaces.config.IdentityFactory;
46 46
 import com.dmdirc.logger.ErrorLevel;
47 47
 import com.dmdirc.logger.ErrorManager;
48 48
 import com.dmdirc.logger.Logger;
49
-import com.dmdirc.messages.MessageSinkManager;
49
+import com.dmdirc.messages.MessagesModule;
50 50
 import com.dmdirc.plugins.LegacyServiceLocator;
51 51
 import com.dmdirc.plugins.PluginInjectorInitialiser;
52 52
 import com.dmdirc.plugins.PluginManager;
@@ -55,8 +55,6 @@ import com.dmdirc.plugins.ServiceLocator;
55 55
 import com.dmdirc.plugins.ServiceManager;
56 56
 import com.dmdirc.ui.IconManager;
57 57
 import com.dmdirc.ui.WarningDialog;
58
-import com.dmdirc.ui.WindowManager;
59
-import com.dmdirc.ui.core.components.StatusBarManager;
60 58
 import com.dmdirc.ui.messages.ColourManager;
61 59
 import com.dmdirc.ui.themes.ThemeManager;
62 60
 import com.dmdirc.updater.UpdaterModule;
@@ -90,6 +88,7 @@ import dagger.Provides;
90 88
             AliasesModule.class,
91 89
             CommandLineOptionsModule.class,
92 90
             CommandModule.class,
91
+            MessagesModule.class,
93 92
             UpdaterModule.class
94 93
         },
95 94
         library = true)
@@ -197,17 +196,6 @@ public class ClientModule {
197 196
         return controller;
198 197
     }
199 198
 
200
-    @Provides
201
-    @Singleton
202
-    public MessageSinkManager getMessageSinkManager(
203
-            final StatusBarManager statusBarManager,
204
-            final WindowManager windowManager,
205
-            final URLBuilder urlBuilder) {
206
-        final MessageSinkManager messageSinkManager = new MessageSinkManager();
207
-        messageSinkManager.loadDefaultSinks(statusBarManager, windowManager, urlBuilder);
208
-        return messageSinkManager;
209
-    }
210
-
211 199
     @Provides
212 200
     @Singleton
213 201
     public CommandManager getCommandManager(

+ 6
- 0
src/com/dmdirc/messages/AllMessageSink.java View File

@@ -27,6 +27,8 @@ import com.dmdirc.FrameContainer;
27 27
 import java.util.Date;
28 28
 import java.util.regex.Pattern;
29 29
 
30
+import javax.inject.Inject;
31
+
30 32
 /**
31 33
  * A message sink which adds the message to all of the container's server's children.
32 34
  */
@@ -35,6 +37,10 @@ public class AllMessageSink implements MessageSink {
35 37
     /** The pattern to use to match this sink. */
36 38
     private static final Pattern PATTERN = Pattern.compile("all");
37 39
 
40
+    @Inject
41
+    public AllMessageSink() {
42
+    }
43
+
38 44
     @Override
39 45
     public Pattern getPattern() {
40 46
         return PATTERN;

+ 6
- 0
src/com/dmdirc/messages/ChannelMessageSink.java View File

@@ -28,6 +28,8 @@ import com.dmdirc.FrameContainer;
28 28
 import java.util.Date;
29 29
 import java.util.regex.Pattern;
30 30
 
31
+import javax.inject.Inject;
32
+
31 33
 /**
32 34
  * A message sink which adds the message to a named channel. An optional fallback may be specified
33 35
  * for use if the channel does not exist. If no fallback is specified and the channel does not
@@ -38,6 +40,10 @@ public class ChannelMessageSink implements MessageSink {
38 40
     /** The pattern to use to match this sink. */
39 41
     private static final Pattern PATTERN = Pattern.compile("channel:(.*?)(?:\\s(.*))?");
40 42
 
43
+    @Inject
44
+    public ChannelMessageSink() {
45
+    }
46
+
41 47
     @Override
42 48
     public Pattern getPattern() {
43 49
         return PATTERN;

+ 6
- 0
src/com/dmdirc/messages/CommonChanelsMessageSink.java View File

@@ -28,6 +28,8 @@ import com.dmdirc.FrameContainer;
28 28
 import java.util.Date;
29 29
 import java.util.regex.Pattern;
30 30
 
31
+import javax.inject.Inject;
32
+
31 33
 /**
32 34
  * A message sink which adds the message to all channels the local user has in common with a
33 35
  * specified remote user. An optional fallback may be specified for use if there are no common
@@ -39,6 +41,10 @@ public class CommonChanelsMessageSink implements MessageSink {
39 41
     /** The pattern to use to match this sink. */
40 42
     private static final Pattern PATTERN = Pattern.compile("comchans:(.*?)(?:\\s(.*))?");
41 43
 
44
+    @Inject
45
+    public CommonChanelsMessageSink() {
46
+    }
47
+
42 48
     @Override
43 49
     public Pattern getPattern() {
44 50
         return PATTERN;

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

@@ -31,6 +31,8 @@ import com.dmdirc.util.URLBuilder;
31 31
 import java.util.Date;
32 32
 import java.util.regex.Pattern;
33 33
 
34
+import javax.inject.Inject;
35
+
34 36
 /**
35 37
  * A message sink which adds the message to a custom window, creating it if necessary.
36 38
  */
@@ -49,6 +51,7 @@ public class CustomWindowMessageSink implements MessageSink {
49 51
      * @param windowManager Window management
50 52
      * @param urlBuilder    The URL builder to use when finding icons.
51 53
      */
54
+    @Inject
52 55
     public CustomWindowMessageSink(
53 56
             final WindowManager windowManager,
54 57
             final URLBuilder urlBuilder) {

+ 6
- 0
src/com/dmdirc/messages/ForkMessageSink.java View File

@@ -27,6 +27,8 @@ import com.dmdirc.FrameContainer;
27 27
 import java.util.Date;
28 28
 import java.util.regex.Pattern;
29 29
 
30
+import javax.inject.Inject;
31
+
30 32
 /**
31 33
  * A message sink which allows the message to be forked into multiple other sinks.
32 34
  */
@@ -35,6 +37,10 @@ public class ForkMessageSink implements MessageSink {
35 37
     /** The pattern to use to match this sink. */
36 38
     private static final Pattern PATTERN = Pattern.compile("fork:(.*)");
37 39
 
40
+    @Inject
41
+    public ForkMessageSink() {
42
+    }
43
+
38 44
     @Override
39 45
     public Pattern getPattern() {
40 46
         return PATTERN;

+ 6
- 0
src/com/dmdirc/messages/FormatMessageSink.java View File

@@ -27,6 +27,8 @@ import com.dmdirc.FrameContainer;
27 27
 import java.util.Date;
28 28
 import java.util.regex.Pattern;
29 29
 
30
+import javax.inject.Inject;
31
+
30 32
 /**
31 33
  * A message sink which changes the format of the message and then redespatches it.
32 34
  */
@@ -35,6 +37,10 @@ public class FormatMessageSink implements MessageSink {
35 37
     /** The pattern to use to match this sink. */
36 38
     private static final Pattern PATTERN = Pattern.compile("format:(.*?):(.*)");
37 39
 
40
+    @Inject
41
+    public FormatMessageSink() {
42
+    }
43
+
38 44
     @Override
39 45
     public Pattern getPattern() {
40 46
         return PATTERN;

+ 6
- 0
src/com/dmdirc/messages/GroupMessageSink.java View File

@@ -27,6 +27,8 @@ import com.dmdirc.FrameContainer;
27 27
 import java.util.Date;
28 28
 import java.util.regex.Pattern;
29 29
 
30
+import javax.inject.Inject;
31
+
30 32
 /**
31 33
  * A message sink which changes the sink to the value of a named configuration setting to allow
32 34
  * grouping of sinks.
@@ -36,6 +38,10 @@ public class GroupMessageSink implements MessageSink {
36 38
     /** The pattern to use to match this sink. */
37 39
     private static final Pattern PATTERN = Pattern.compile("group:(.*)");
38 40
 
41
+    @Inject
42
+    public GroupMessageSink() {
43
+    }
44
+
39 45
     /** {@inheritDoc} */
40 46
     @Override
41 47
     public Pattern getPattern() {

+ 6
- 0
src/com/dmdirc/messages/LastCommandMessageSink.java View File

@@ -30,6 +30,8 @@ import java.util.Date;
30 30
 import java.util.List;
31 31
 import java.util.regex.Pattern;
32 32
 
33
+import javax.inject.Inject;
34
+
33 35
 /**
34 36
  * A message sink which adds the message to the window where a command matching the provided regex
35 37
  * was most recently executed. If no such window is found, falls back to the source.
@@ -39,6 +41,10 @@ public class LastCommandMessageSink implements MessageSink {
39 41
     /** The pattern to use to match this sink. */
40 42
     private static final Pattern PATTERN = Pattern.compile("lastcommand:(.*)");
41 43
 
44
+    @Inject
45
+    public LastCommandMessageSink() {
46
+    }
47
+
42 48
     /** {@inheritDoc} */
43 49
     @Override
44 50
     public Pattern getPattern() {

+ 0
- 29
src/com/dmdirc/messages/MessageSinkManager.java View File

@@ -25,9 +25,6 @@ package com.dmdirc.messages;
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.logger.ErrorLevel;
27 27
 import com.dmdirc.logger.Logger;
28
-import com.dmdirc.ui.WindowManager;
29
-import com.dmdirc.ui.core.components.StatusBarManager;
30
-import com.dmdirc.util.URLBuilder;
31 28
 
32 29
 import java.util.ArrayList;
33 30
 import java.util.Date;
@@ -121,30 +118,4 @@ public class MessageSinkManager {
121 118
         }
122 119
     }
123 120
 
124
-    /**
125
-     * Loads the default message sinks into this manager.
126
-     *
127
-     * @param statusBarManager The status bar manager to give to status-bar related sinks.
128
-     * @param windowManager    The window manager to give to sinks that iterate windows.
129
-     * @param urlBuilder       The URL builder to use when finding icons.
130
-     */
131
-    public void loadDefaultSinks(
132
-            final StatusBarManager statusBarManager,
133
-            final WindowManager windowManager,
134
-            final URLBuilder urlBuilder) {
135
-        // TODO: Dependency inject all these.
136
-        addSink(new AllMessageSink());
137
-        addSink(new ChannelMessageSink());
138
-        addSink(new CommonChanelsMessageSink());
139
-        addSink(new CustomWindowMessageSink(windowManager, urlBuilder));
140
-        addSink(new ForkMessageSink());
141
-        addSink(new FormatMessageSink());
142
-        addSink(new GroupMessageSink());
143
-        addSink(new LastCommandMessageSink());
144
-        addSink(new NullMessageSink());
145
-        addSink(new SelfMessageSink());
146
-        addSink(new ServerMessageSink());
147
-        addSink(new StatusBarMessageSink(statusBarManager));
148
-    }
149
-
150 121
 }

+ 108
- 0
src/com/dmdirc/messages/MessagesModule.java View File

@@ -0,0 +1,108 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
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.messages;
24
+
25
+import java.util.Set;
26
+
27
+import javax.inject.Singleton;
28
+
29
+import dagger.Module;
30
+import dagger.Provides;
31
+
32
+/**
33
+ * Module for dependency injecting the {@link MessageSinkManager} and its default sinks.
34
+ */
35
+@Module(library = true, complete = false)
36
+public class MessagesModule {
37
+
38
+    @Provides
39
+    @Singleton
40
+    public MessageSinkManager getMessageSinkManager(final Set<MessageSink> defaultSinks) {
41
+        final MessageSinkManager messageSinkManager = new MessageSinkManager();
42
+        for (MessageSink sink : defaultSinks) {
43
+            messageSinkManager.addSink(sink);
44
+        }
45
+        return messageSinkManager;
46
+    }
47
+
48
+    @Provides(type = Provides.Type.SET)
49
+    public MessageSink getMessageSink(final AllMessageSink sink) {
50
+        return sink;
51
+    }
52
+
53
+    @Provides(type = Provides.Type.SET)
54
+    public MessageSink getMessageSink(final ChannelMessageSink sink) {
55
+        return sink;
56
+    }
57
+
58
+    @Provides(type = Provides.Type.SET)
59
+    public MessageSink getMessageSink(final CommonChanelsMessageSink sink) {
60
+        return sink;
61
+    }
62
+
63
+    @Provides(type = Provides.Type.SET)
64
+    public MessageSink getMessageSink(final CustomWindowMessageSink sink) {
65
+        return sink;
66
+    }
67
+
68
+    @Provides(type = Provides.Type.SET)
69
+    public MessageSink getMessageSink(final ForkMessageSink sink) {
70
+        return sink;
71
+    }
72
+
73
+    @Provides(type = Provides.Type.SET)
74
+    public MessageSink getMessageSink(final FormatMessageSink sink) {
75
+        return sink;
76
+    }
77
+
78
+    @Provides(type = Provides.Type.SET)
79
+    public MessageSink getMessageSink(final GroupMessageSink sink) {
80
+        return sink;
81
+    }
82
+
83
+    @Provides(type = Provides.Type.SET)
84
+    public MessageSink getMessageSink(final LastCommandMessageSink sink) {
85
+        return sink;
86
+    }
87
+
88
+    @Provides(type = Provides.Type.SET)
89
+    public MessageSink getMessageSink(final NullMessageSink sink) {
90
+        return sink;
91
+    }
92
+
93
+    @Provides(type = Provides.Type.SET)
94
+    public MessageSink getMessageSink(final SelfMessageSink sink) {
95
+        return sink;
96
+    }
97
+
98
+    @Provides(type = Provides.Type.SET)
99
+    public MessageSink getMessageSink(final ServerMessageSink sink) {
100
+        return sink;
101
+    }
102
+
103
+    @Provides(type = Provides.Type.SET)
104
+    public MessageSink getMessageSink(final StatusBarMessageSink sink) {
105
+        return sink;
106
+    }
107
+
108
+}

+ 6
- 0
src/com/dmdirc/messages/NullMessageSink.java View File

@@ -27,6 +27,8 @@ import com.dmdirc.FrameContainer;
27 27
 import java.util.Date;
28 28
 import java.util.regex.Pattern;
29 29
 
30
+import javax.inject.Inject;
31
+
30 32
 /**
31 33
  * A message sink which does nothing with the message.
32 34
  */
@@ -35,6 +37,10 @@ public class NullMessageSink implements MessageSink {
35 37
     /** The pattern to use to match this sink. */
36 38
     private static final Pattern PATTERN = Pattern.compile("none");
37 39
 
40
+    @Inject
41
+    public NullMessageSink() {
42
+    }
43
+
38 44
     /** {@inheritDoc} */
39 45
     @Override
40 46
     public Pattern getPattern() {

+ 6
- 0
src/com/dmdirc/messages/SelfMessageSink.java View File

@@ -27,6 +27,8 @@ import com.dmdirc.FrameContainer;
27 27
 import java.util.Date;
28 28
 import java.util.regex.Pattern;
29 29
 
30
+import javax.inject.Inject;
31
+
30 32
 /**
31 33
  * A message sink which adds the message to the container that despatched it.
32 34
  */
@@ -35,6 +37,10 @@ public class SelfMessageSink implements MessageSink {
35 37
     /** The pattern to use to match this sink. */
36 38
     private static final Pattern PATTERN = Pattern.compile("self");
37 39
 
40
+    @Inject
41
+    public SelfMessageSink() {
42
+    }
43
+
38 44
     /** {@inheritDoc} */
39 45
     @Override
40 46
     public Pattern getPattern() {

+ 6
- 0
src/com/dmdirc/messages/ServerMessageSink.java View File

@@ -28,6 +28,8 @@ import com.dmdirc.Server;
28 28
 import java.util.Date;
29 29
 import java.util.regex.Pattern;
30 30
 
31
+import javax.inject.Inject;
32
+
31 33
 /**
32 34
  * A message sink which adds the message to the container's server.
33 35
  */
@@ -36,6 +38,10 @@ public class ServerMessageSink implements MessageSink {
36 38
     /** The pattern to use to match this sink. */
37 39
     private static final Pattern PATTERN = Pattern.compile("server");
38 40
 
41
+    @Inject
42
+    public ServerMessageSink() {
43
+    }
44
+
39 45
     /** {@inheritDoc} */
40 46
     @Override
41 47
     public Pattern getPattern() {

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

@@ -30,6 +30,8 @@ import com.dmdirc.ui.messages.Formatter;
30 30
 import java.util.Date;
31 31
 import java.util.regex.Pattern;
32 32
 
33
+import javax.inject.Inject;
34
+
33 35
 /**
34 36
  * A message sink which adds the message to the status bar.
35 37
  */
@@ -45,6 +47,7 @@ public class StatusBarMessageSink implements MessageSink {
45 47
      *
46 48
      * @param statusBarManager The status bar manager to add messages to.
47 49
      */
50
+    @Inject
48 51
     public StatusBarMessageSink(final StatusBarManager statusBarManager) {
49 52
         this.statusBarManager = statusBarManager;
50 53
     }

Loading…
Cancel
Save