Ver código fonte

Make preferences manager use current UI

Fixes issue 4415

Change-Id: I52c7f76361f8b2fe4ebd38b00795e28ca4eee9e5
Reviewed-on: http://gerrit.dmdirc.com/1460
Automatic-Compile: Gregory Holmes <greg@dmdirc.com>
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
tags/0.6.5b1
Chris Smith 14 anos atrás
pai
commit
eafec02238

+ 25
- 10
src/com/dmdirc/config/prefs/PreferencesManager.java Ver arquivo

22
 
22
 
23
 package com.dmdirc.config.prefs;
23
 package com.dmdirc.config.prefs;
24
 
24
 
25
-import com.dmdirc.Main;
26
 import com.dmdirc.actions.ActionManager;
25
 import com.dmdirc.actions.ActionManager;
27
 import com.dmdirc.actions.CoreActionType;
26
 import com.dmdirc.actions.CoreActionType;
28
 import com.dmdirc.util.validators.NumericalValidator;
27
 import com.dmdirc.util.validators.NumericalValidator;
29
 import com.dmdirc.util.validators.OptionalValidator;
28
 import com.dmdirc.util.validators.OptionalValidator;
30
 import com.dmdirc.plugins.PluginManager;
29
 import com.dmdirc.plugins.PluginManager;
31
 import com.dmdirc.plugins.Service;
30
 import com.dmdirc.plugins.Service;
31
+import com.dmdirc.ui.interfaces.UIController;
32
 import com.dmdirc.util.ListenerList;
32
 import com.dmdirc.util.ListenerList;
33
 
33
 
34
 import java.util.ArrayList;
34
 import java.util.ArrayList;
35
+import java.util.Collections;
35
 import java.util.HashMap;
36
 import java.util.HashMap;
36
 import java.util.List;
37
 import java.util.List;
37
 import java.util.Map;
38
 import java.util.Map;
43
  */
44
  */
44
 public class PreferencesManager {
45
 public class PreferencesManager {
45
 
46
 
47
+    /** The UI controller to use for custom categories. */
48
+    private final UIController controller;
49
+
46
     /** A list of categories. */
50
     /** A list of categories. */
47
     private final List<PreferencesCategory> categories
51
     private final List<PreferencesCategory> categories
48
             = new ArrayList<PreferencesCategory>();
52
             = new ArrayList<PreferencesCategory>();
52
 
56
 
53
     /**
57
     /**
54
      * Creates a new instance of PreferencesManager.
58
      * Creates a new instance of PreferencesManager.
59
+     *
60
+     * @param controller The UI controller to use to retrieve custom UIs for
61
+     * preferences panels.
55
      */
62
      */
56
-    public PreferencesManager() {
63
+    public PreferencesManager(final UIController controller) {
64
+        this.controller = controller;
65
+
57
         addDefaultCategories();
66
         addDefaultCategories();
58
 
67
 
59
         ActionManager.processEvent(CoreActionType.CLIENT_PREFS_OPENED, null, this);
68
         ActionManager.processEvent(CoreActionType.CLIENT_PREFS_OPENED, null, this);
74
      * @return An ordered list of categories
83
      * @return An ordered list of categories
75
      */
84
      */
76
     public List<PreferencesCategory> getCategories() {
85
     public List<PreferencesCategory> getCategories() {
77
-        return categories;
86
+        return Collections.unmodifiableList(categories);
78
     }
87
     }
79
 
88
 
80
     /**
89
     /**
104
         boolean restart = false;
113
         boolean restart = false;
105
         for (PreferencesCategory category : categories) {
114
         for (PreferencesCategory category : categories) {
106
             if (category.save()) {
115
             if (category.save()) {
107
-                restart = true;
116
+                restart |= true;
108
             }
117
             }
109
         }
118
         }
110
 
119
 
174
 
183
 
175
     /**
184
     /**
176
      * Creates and adds the "Tab Completion" category.
185
      * Creates and adds the "Tab Completion" category.
186
+     *
187
+     * @param parent Parent category to add this category to
177
      * @since 0.6.4
188
      * @since 0.6.4
178
      */
189
      */
179
-    private void addTabCompletionCategory(PreferencesCategory parent) {
190
+    private void addTabCompletionCategory(final PreferencesCategory parent) {
180
         final PreferencesCategory category = new PreferencesCategory("Tab Completion", "");
191
         final PreferencesCategory category = new PreferencesCategory("Tab Completion", "");
181
         final Map<String, String> taboptions = new HashMap<String, String>();
192
         final Map<String, String> taboptions = new HashMap<String, String>();
182
 
193
 
251
 
262
 
252
     /**
263
     /**
253
      * Creates and adds the "SSL" category.
264
      * Creates and adds the "SSL" category.
265
+     *
266
+     * @param parent Parent category to add this category to
254
      */
267
      */
255
     private void addSSLCategory(final PreferencesCategory parent) {
268
     private void addSSLCategory(final PreferencesCategory parent) {
256
         final PreferencesCategory category = new PreferencesCategory("SSL",
269
         final PreferencesCategory category = new PreferencesCategory("SSL",
454
 
467
 
455
     /**
468
     /**
456
      * Creates the Style subcategory in "GUI".
469
      * Creates the Style subcategory in "GUI".
470
+     *
457
      * @since 0.6.4
471
      * @since 0.6.4
472
+     * @param parent Parent category to add this category to
458
      */
473
      */
459
-    private void addStyleSubCategory(PreferencesCategory parent) {
474
+    private void addStyleSubCategory(final PreferencesCategory parent) {
460
         final PreferencesCategory category = new PreferencesCategory("Link styles"
475
         final PreferencesCategory category = new PreferencesCategory("Link styles"
461
                 + " and colours", "");
476
                 + " and colours", "");
462
         category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
477
         category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
481
      */
496
      */
482
     private void addThemesCategory(final PreferencesCategory parent) {
497
     private void addThemesCategory(final PreferencesCategory parent) {
483
         parent.addSubCategory(new PreferencesCategory("Themes", "",
498
         parent.addSubCategory(new PreferencesCategory("Themes", "",
484
-                "category-addons", Main.getUI().getThemesPrefsPanel()));
499
+                "category-addons", controller.getThemesPrefsPanel()));
485
     }
500
     }
486
 
501
 
487
     /**
502
     /**
489
      */
504
      */
490
     private void addPluginsCategory() {
505
     private void addPluginsCategory() {
491
         addCategory(new PreferencesCategory("Plugins", "", "category-addons",
506
         addCategory(new PreferencesCategory("Plugins", "", "category-addons",
492
-                Main.getUI().getPluginPrefsPanel()));
507
+                controller.getPluginPrefsPanel()));
493
     }
508
     }
494
 
509
 
495
     /**
510
     /**
497
      */
512
      */
498
     private void addUpdatesCategory() {
513
     private void addUpdatesCategory() {
499
         addCategory(new PreferencesCategory("Updates", "", "category-updates",
514
         addCategory(new PreferencesCategory("Updates", "", "category-updates",
500
-                Main.getUI().getUpdatesPrefsPanel()));
515
+                controller.getUpdatesPrefsPanel()));
501
     }
516
     }
502
 
517
 
503
     /**
518
     /**
506
     private void addUrlHandlerCategory() {
521
     private void addUrlHandlerCategory() {
507
         addCategory(new PreferencesCategory("URL Handlers",
522
         addCategory(new PreferencesCategory("URL Handlers",
508
                 "Configure how DMDirc handles different types of URLs",
523
                 "Configure how DMDirc handles different types of URLs",
509
-                "category-urlhandlers", Main.getUI().getUrlHandlersPrefsPanel()));
524
+                "category-urlhandlers", controller.getUrlHandlersPrefsPanel()));
510
     }
525
     }
511
 
526
 
512
     /**
527
     /**

+ 13
- 9
test/com/dmdirc/config/prefs/PreferencesManagerTest.java Ver arquivo

29
 import com.dmdirc.interfaces.ActionListener;
29
 import com.dmdirc.interfaces.ActionListener;
30
 
30
 
31
 import com.dmdirc.plugins.PluginManager;
31
 import com.dmdirc.plugins.PluginManager;
32
+import com.dmdirc.ui.interfaces.UIController;
32
 import org.junit.BeforeClass;
33
 import org.junit.BeforeClass;
33
 import org.junit.Test;
34
 import org.junit.Test;
34
 import static org.junit.Assert.*;
35
 import static org.junit.Assert.*;
36
 
37
 
37
 public class PreferencesManagerTest {
38
 public class PreferencesManagerTest {
38
 
39
 
40
+    private static UIController controller;
41
+
39
     @BeforeClass
42
     @BeforeClass
40
     public static void setUp() throws Exception {
43
     public static void setUp() throws Exception {
41
         IdentityManager.load();
44
         IdentityManager.load();
42
         Main.extractCorePlugins("ui_");
45
         Main.extractCorePlugins("ui_");
43
         Main.setUI(new SwingController());
46
         Main.setUI(new SwingController());
44
         PluginManager.getPluginManager();
47
         PluginManager.getPluginManager();
48
+        controller = mock(UIController.class);
45
     }
49
     }
46
 
50
 
47
     @Test
51
     @Test
48
     public void testDefaults() {
52
     public void testDefaults() {
49
-        final PreferencesManager pm = new PreferencesManager();
53
+        final PreferencesManager pm = new PreferencesManager(controller);
50
         assertNotNull(pm.getCategory("General"));
54
         assertNotNull(pm.getCategory("General"));
51
         assertNotNull(pm.getCategory("Connection"));
55
         assertNotNull(pm.getCategory("Connection"));
52
         assertNotNull(pm.getCategory("Messages"));
56
         assertNotNull(pm.getCategory("Messages"));
60
     @Test
64
     @Test
61
     public void testDismiss() {
65
     public void testDismiss() {
62
         final PreferencesCategory category = mock(PreferencesCategory.class);
66
         final PreferencesCategory category = mock(PreferencesCategory.class);
63
-        final PreferencesManager pm = new PreferencesManager();
67
+        final PreferencesManager pm = new PreferencesManager(controller);
64
         pm.addCategory(category);
68
         pm.addCategory(category);
65
         pm.dismiss();
69
         pm.dismiss();
66
 
70
 
72
         final PreferencesCategory category = mock(PreferencesCategory.class);
76
         final PreferencesCategory category = mock(PreferencesCategory.class);
73
         when(category.save()).thenReturn(false);
77
         when(category.save()).thenReturn(false);
74
 
78
 
75
-        final PreferencesManager pm = new PreferencesManager();
79
+        final PreferencesManager pm = new PreferencesManager(controller);
76
         pm.addCategory(category);
80
         pm.addCategory(category);
77
         assertFalse(pm.save());
81
         assertFalse(pm.save());
78
 
82
 
84
         final PreferencesCategory category = mock(PreferencesCategory.class);
88
         final PreferencesCategory category = mock(PreferencesCategory.class);
85
         when(category.save()).thenReturn(true);
89
         when(category.save()).thenReturn(true);
86
 
90
 
87
-        final PreferencesManager pm = new PreferencesManager();
91
+        final PreferencesManager pm = new PreferencesManager(controller);
88
         pm.addCategory(category);
92
         pm.addCategory(category);
89
         assertTrue(pm.save());
93
         assertTrue(pm.save());
90
 
94
 
93
 
97
 
94
     @Test
98
     @Test
95
     public void testGetCategory() {
99
     public void testGetCategory() {
96
-        final PreferencesManager pm = new PreferencesManager();
100
+        final PreferencesManager pm = new PreferencesManager(controller);
97
         assertNull(pm.getCategory("unittest123"));
101
         assertNull(pm.getCategory("unittest123"));
98
     }
102
     }
99
 
103
 
100
     @Test
104
     @Test
101
     public void testGetCategories() {
105
     public void testGetCategories() {
102
-        final PreferencesManager pm = new PreferencesManager();
106
+        final PreferencesManager pm = new PreferencesManager(controller);
103
         assertNotNull(pm.getCategories());
107
         assertNotNull(pm.getCategories());
104
         assertFalse(pm.getCategories().isEmpty());
108
         assertFalse(pm.getCategories().isEmpty());
105
 
109
 
110
 
114
 
111
     @Test
115
     @Test
112
     public void testSaveListener() {
116
     public void testSaveListener() {
113
-        final PreferencesManager pm = new PreferencesManager();
117
+        final PreferencesManager pm = new PreferencesManager(controller);
114
         final PreferencesInterface tpi = mock(PreferencesInterface.class);
118
         final PreferencesInterface tpi = mock(PreferencesInterface.class);
115
 
119
 
116
         pm.registerSaveListener(tpi);
120
         pm.registerSaveListener(tpi);
125
         ActionManager.init();
129
         ActionManager.init();
126
         ActionManager.addListener(tal, CoreActionType.CLIENT_PREFS_OPENED);
130
         ActionManager.addListener(tal, CoreActionType.CLIENT_PREFS_OPENED);
127
 
131
 
128
-        final PreferencesManager pm = new PreferencesManager();
132
+        final PreferencesManager pm = new PreferencesManager(controller);
129
 
133
 
130
         verify(tal).processEvent(eq(CoreActionType.CLIENT_PREFS_OPENED),
134
         verify(tal).processEvent(eq(CoreActionType.CLIENT_PREFS_OPENED),
131
                 (StringBuffer) same(null), same(pm));
135
                 (StringBuffer) same(null), same(pm));
138
         ActionManager.init();
142
         ActionManager.init();
139
         ActionManager.addListener(tal, CoreActionType.CLIENT_PREFS_CLOSED);
143
         ActionManager.addListener(tal, CoreActionType.CLIENT_PREFS_CLOSED);
140
 
144
 
141
-        final PreferencesManager pm = new PreferencesManager();
145
+        final PreferencesManager pm = new PreferencesManager(controller);
142
         pm.close();
146
         pm.close();
143
 
147
 
144
         verify(tal).processEvent(eq(CoreActionType.CLIENT_PREFS_CLOSED),
148
         verify(tal).processEvent(eq(CoreActionType.CLIENT_PREFS_CLOSED),

Carregando…
Cancelar
Salvar