Переглянути джерело

Fixes issue 2688: Expose per-profile performs in SSD

Change-Id: I27a7f70cfbc0dd8e37f3152923cd419c74a76c47
Reviewed-on: http://gerrit.dmdirc.com/655
Automatic-Compile: Chris Smith <chris@dmdirc.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.3
Gregory Holmes 14 роки тому
джерело
коміт
e491b1fc51

+ 125
- 53
src/com/dmdirc/addons/ui_swing/dialogs/serversetting/PerformPanel.java Переглянути файл

42
  * Perform panel.
42
  * Perform panel.
43
  */
43
  */
44
 public final class PerformPanel extends JPanel implements ActionListener {
44
 public final class PerformPanel extends JPanel implements ActionListener {
45
-    
45
+
46
     /**
46
     /**
47
      * A version number for this class. It should be changed whenever the class
47
      * A version number for this class. It should be changed whenever the class
48
      * structure is changed (or anything else that would prevent serialized
48
      * structure is changed (or anything else that would prevent serialized
49
      * objects being unserialized with the new class).
49
      * objects being unserialized with the new class).
50
      */
50
      */
51
     private static final long serialVersionUID = 1;
51
     private static final long serialVersionUID = 1;
52
-    
52
+
53
     /** Parent server. */
53
     /** Parent server. */
54
     private final Server server;
54
     private final Server server;
55
-    
55
+
56
     /** The action used for server performs. */
56
     /** The action used for server performs. */
57
     private Action serverAction;
57
     private Action serverAction;
58
     /** The action used for network performs. */
58
     /** The action used for network performs. */
59
     private Action networkAction;
59
     private Action networkAction;
60
-    
60
+    /** The action used for profile server performs. */
61
+    private Action profileServerAction;
62
+    /** The action used for profile network performs. */
63
+    private Action profileNetworkAction;
64
+
61
     /** The server perform string. */
65
     /** The server perform string. */
62
     private String serverPerform;
66
     private String serverPerform;
63
     /** The network perform string. */
67
     /** The network perform string. */
64
     private String networkPerform;
68
     private String networkPerform;
65
-    
66
-    /** Keeps track of which perform we're editing. */
67
-    private boolean isNetworkPerform;
68
-    
69
+    /** The profile's server perform string. */
70
+    private String profileServerPerform;
71
+    /** The profile's network perform string. */
72
+    private String profileNetworkPerform;
73
+
69
     /** Network/server combo box. */
74
     /** Network/server combo box. */
70
     private JComboBox target;
75
     private JComboBox target;
71
-    
76
+
72
     /** Perform text area. */
77
     /** Perform text area. */
73
     private JTextArea textarea;
78
     private JTextArea textarea;
74
-    
79
+
75
     /**
80
     /**
76
      * Creates a new instance of IgnoreList.
81
      * Creates a new instance of IgnoreList.
77
      *
82
      *
79
      */
84
      */
80
     public PerformPanel(final Server server) {
85
     public PerformPanel(final Server server) {
81
         super();
86
         super();
82
-        
87
+
83
         this.server = server;
88
         this.server = server;
84
-        
89
+
85
         this.setOpaque(UIUtilities.getTabbedPaneOpaque());
90
         this.setOpaque(UIUtilities.getTabbedPaneOpaque());
86
         initComponents();
91
         initComponents();
87
         addListeners();
92
         addListeners();
88
         loadPerforms();
93
         loadPerforms();
89
         populatePerform();
94
         populatePerform();
90
     }
95
     }
91
-    
96
+
92
     /** Initialises teh components. */
97
     /** Initialises teh components. */
93
     private void initComponents() {
98
     private void initComponents() {
94
         setLayout(new MigLayout("fill"));
99
         setLayout(new MigLayout("fill"));
95
-        
100
+
96
         final DefaultComboBoxModel model = new DefaultComboBoxModel();
101
         final DefaultComboBoxModel model = new DefaultComboBoxModel();
97
         target = new JComboBox(model);
102
         target = new JComboBox(model);
98
-        
99
-        if (!server.getNetwork().isEmpty()) {
100
-            model.addElement("Network perform (" + server.getNetwork() + ")");
101
-        }
102
-        if (!server.getName().isEmpty()) {
103
-            model.addElement("Server perform (" + server.getName() + ")");
104
-        }
105
-        
103
+
104
+        model.addElement("Network perform (" + server.getNetwork()
105
+                + ") Any profile");
106
+        model.addElement("Network perform (" + server.getNetwork()
107
+                + ") This profile (" + server.getProfile().getName() + ")");
108
+        model.addElement("Server perform (" + server.getName()
109
+                + ") Any profile");
110
+        model.addElement("Server perform (" + server.getName()
111
+                + ") This profile (" + server.getProfile().getName() + ")");
112
+
106
         add(target, "growx, pushx, wrap");
113
         add(target, "growx, pushx, wrap");
107
-        
114
+
108
         textarea = new JTextArea();
115
         textarea = new JTextArea();
109
         textarea.setColumns(40);
116
         textarea.setColumns(40);
110
-        
117
+
111
         add(new JScrollPane(textarea), "grow, push");
118
         add(new JScrollPane(textarea), "grow, push");
112
     }
119
     }
113
-    
120
+
114
     /** Adds listeners to the components. */
121
     /** Adds listeners to the components. */
115
     private void addListeners() {
122
     private void addListeners() {
116
         target.addActionListener(this);
123
         target.addActionListener(this);
117
     }
124
     }
118
-    
125
+
119
     /** Loads the perform actions. */
126
     /** Loads the perform actions. */
120
     private void loadPerforms() {
127
     private void loadPerforms() {
121
-        serverAction = PerformWrapper.getPerformWrapper().getActionForServer(server.getName());
122
-        networkAction = PerformWrapper.getPerformWrapper().getActionForNetwork(server.getNetwork());
123
-        
128
+        serverAction = PerformWrapper.getPerformWrapper().
129
+                getActionForServer(server.getName());
130
+        networkAction = PerformWrapper.getPerformWrapper().
131
+                getActionForNetwork(server.getNetwork());
132
+        profileServerAction = PerformWrapper.getPerformWrapper().
133
+                getActionForServer(server.getName(), server.getProfile().getName());
134
+        profileNetworkAction = PerformWrapper.getPerformWrapper().
135
+                getActionForNetwork(server.getNetwork(), server.getProfile().getName());
136
+
124
         if (serverAction == null) {
137
         if (serverAction == null) {
125
             serverPerform = "";
138
             serverPerform = "";
126
         } else {
139
         } else {
127
             serverPerform = implode(serverAction.getResponse());
140
             serverPerform = implode(serverAction.getResponse());
128
         }
141
         }
129
-        
142
+
130
         if (networkAction == null) {
143
         if (networkAction == null) {
131
             networkPerform = "";
144
             networkPerform = "";
132
         } else {
145
         } else {
133
             networkPerform = implode(networkAction.getResponse());
146
             networkPerform = implode(networkAction.getResponse());
134
         }
147
         }
148
+
149
+        if (profileServerAction == null) {
150
+            profileServerPerform = "";
151
+        } else {
152
+            profileServerPerform = implode(profileServerAction.getResponse());
153
+        }
154
+
155
+        if (profileNetworkAction == null) {
156
+            profileNetworkPerform = "";
157
+        } else {
158
+            profileNetworkPerform = implode(profileServerAction.getResponse());
159
+        }
135
     }
160
     }
136
-    
161
+
137
     /**
162
     /**
138
      * Implodes the specified string array, joining each line with a LF.
163
      * Implodes the specified string array, joining each line with a LF.
139
      *
164
      *
142
      */
167
      */
143
     private String implode(final String[] lines) {
168
     private String implode(final String[] lines) {
144
         final StringBuilder res = new StringBuilder();
169
         final StringBuilder res = new StringBuilder();
145
-        
170
+
146
         for (String line : lines) {
171
         for (String line : lines) {
147
             res.append('\n');
172
             res.append('\n');
148
             res.append(line);
173
             res.append(line);
149
         }
174
         }
150
-        
175
+
151
         return res.length() == 0 ? "" : res.substring(1);
176
         return res.length() == 0 ? "" : res.substring(1);
152
     }
177
     }
153
-    
178
+
154
     /** Populates the perform text area. */
179
     /** Populates the perform text area. */
155
     private void populatePerform() {
180
     private void populatePerform() {
156
-        if (target.getSelectedIndex() == 0) {
157
-            isNetworkPerform = true;
158
-            textarea.setText(networkPerform);
159
-        } else {
160
-            isNetworkPerform = false;
161
-            textarea.setText(serverPerform);
181
+        switch (target.getSelectedIndex()) {
182
+            case 0:
183
+                textarea.setText(networkPerform);
184
+                break;
185
+            case 1:
186
+                textarea.setText(profileNetworkPerform);
187
+                break;
188
+            case 2:
189
+                textarea.setText(serverPerform);
190
+                break;
191
+            case 3:
192
+                textarea.setText(profileServerPerform);
193
+                break;
194
+            default:
195
+                break;
162
         }
196
         }
163
     }
197
     }
164
-    
198
+
165
     /** Stores the text currently in the textarea into the perform strings. */
199
     /** Stores the text currently in the textarea into the perform strings. */
166
     private void storeText() {
200
     private void storeText() {
167
-        if (isNetworkPerform) {
168
-            networkPerform = textarea.getText();
169
-        } else {
170
-            serverPerform = textarea.getText();
201
+        switch (target.getSelectedIndex()) {
202
+            case 0:
203
+                networkPerform = textarea.getText();
204
+                break;
205
+            case 1:
206
+                profileNetworkPerform = textarea.getText();
207
+                break;
208
+            case 2:
209
+                serverPerform = textarea.getText();
210
+                break;
211
+            case 3:
212
+                profileServerPerform = textarea.getText();
213
+                break;
214
+            default:
215
+                break;
171
         }
216
         }
172
     }
217
     }
173
-    
218
+
174
     /** Saves the performs. */
219
     /** Saves the performs. */
175
     public void savePerforms() {
220
     public void savePerforms() {
176
         storeText();
221
         storeText();
177
-        
222
+
178
         if (!serverPerform.isEmpty() || serverAction != null) {
223
         if (!serverPerform.isEmpty() || serverAction != null) {
179
             if (serverAction == null) {
224
             if (serverAction == null) {
180
-                serverAction = PerformWrapper.getPerformWrapper().createActionForServer(server.getName());
225
+                serverAction = PerformWrapper.getPerformWrapper().
226
+                        createActionForServer(server.getName());
181
             }
227
             }
182
             serverAction.setResponse(serverPerform.split("\n"));
228
             serverAction.setResponse(serverPerform.split("\n"));
183
             serverAction.save();
229
             serverAction.save();
184
         }
230
         }
185
-        
231
+
186
         if (!networkPerform.isEmpty() || networkAction != null) {
232
         if (!networkPerform.isEmpty() || networkAction != null) {
187
             if (networkAction == null) {
233
             if (networkAction == null) {
188
-                networkAction = PerformWrapper.getPerformWrapper().createActionForNetwork(server.getNetwork());
234
+                networkAction = PerformWrapper.getPerformWrapper().
235
+                        createActionForNetwork(server.getNetwork());
189
             }
236
             }
190
             networkAction.setResponse(networkPerform.split("\n"));
237
             networkAction.setResponse(networkPerform.split("\n"));
191
             networkAction.save();
238
             networkAction.save();
192
         }
239
         }
240
+
241
+        if (!profileNetworkPerform.isEmpty() || profileNetworkAction != null) {
242
+            if (profileNetworkAction == null) {
243
+                profileNetworkAction = PerformWrapper.getPerformWrapper().
244
+                        createActionForNetwork(server.getNetwork(),
245
+                        server.getProfile().getName());
246
+            }
247
+            profileNetworkAction.setResponse(profileNetworkPerform.split("\n"));
248
+            profileNetworkAction.save();
249
+        }
250
+
251
+        if (!profileServerPerform.isEmpty() || profileServerAction != null) {
252
+            if (profileServerAction == null) {
253
+                profileServerAction = PerformWrapper.getPerformWrapper().
254
+                        createActionForServer(server.getName(),
255
+                        server.getProfile().getName());
256
+            }
257
+            profileServerAction.setResponse(profileServerPerform.split("\n"));
258
+            profileServerAction.save();
259
+        }
193
     }
260
     }
194
-    
195
-    /** {@inheritDoc} */
261
+
262
+    /**
263
+     * {@inheritDoc}
264
+     *
265
+     * @param e Action event
266
+     */
267
+    @Override
196
     public void actionPerformed(final ActionEvent e) {
268
     public void actionPerformed(final ActionEvent e) {
197
         storeText();
269
         storeText();
198
         populatePerform();
270
         populatePerform();
199
     }
271
     }
200
-    
272
+
201
 }
273
 }

Завантаження…
Відмінити
Зберегти