1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
|
// **********************************************************************
//
// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
package IceGrid.TreeNode;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.CellConstraints;
import IceGrid.ListDialog;
import IceGrid.Model;
import IceGrid.ServerDescriptor;
import IceGrid.TableDialog;
import IceGrid.Utils;
class ServerSubEditor extends CommunicatorSubEditor
{
ServerSubEditor(Editor mainEditor, JFrame parentFrame)
{
super(mainEditor, parentFrame);
_id.getDocument().addDocumentListener(
_mainEditor.getUpdateListener());
_id.setToolTipText("Must be unique within this IceGrid deployment");
_exe.getDocument().addDocumentListener(
_mainEditor.getUpdateListener());
_exe.setToolTipText("<html>Path to this server's executable, e.g.:<br>"
+ "icebox<br>"
+ "java<br>"
+ "myHelloServer<br>"
+ "C:\\testbed\\hello\\server</html>");
_pwd.getDocument().addDocumentListener(
_mainEditor.getUpdateListener());
_pwd.setToolTipText(
"<html>If not set, the server will start in "
+ "<i>node data dir</i>/servers/<i>server-id</i>;<br>"
+ "relative directories are relative to the current directory"
+ " of the icegridnode process.</html>");
_options.setEditable(false);
_envs.setEditable(false);
_activation = new JComboBox(new Object[]{ON_DEMAND, MANUAL});
_activation.setToolTipText("Select 'on-demand' to have IceGrid start your server on-demand");
JTextField activationTextField = (JTextField)
_activation.getEditor().getEditorComponent();
activationTextField.getDocument().addDocumentListener(
_mainEditor.getUpdateListener());
_activationTimeout.getDocument().addDocumentListener(
_mainEditor.getUpdateListener());
_activationTimeout.setToolTipText("<html>Number of seconds; if not set or set to 0, "
+ "the IceGrid Node<br> uses the value of its "
+ "IceGrid.Node.WaitTime property</html>");
_deactivationTimeout.getDocument().addDocumentListener(
_mainEditor.getUpdateListener());
_deactivationTimeout.setToolTipText("<html>Number of seconds; if not set or set to 0, "
+ "the IceGrid Node<br> uses the value of its "
+ "IceGrid.Node.WaitTime property</html>");
_envDialog = new TableDialog(parentFrame, "Environment Variables",
"Name", "Value", true);
Action openEnvDialog = new AbstractAction("...")
{
public void actionPerformed(ActionEvent e)
{
java.util.Map result = _envDialog.show(
_envMap, _mainEditor.getProperties());
if(result != null)
{
_mainEditor.updated();
_envMap = result;
setEnvsField();
}
}
};
openEnvDialog.putValue(Action.SHORT_DESCRIPTION,
"Edit environment variables");
_envButton = new JButton(openEnvDialog);
_optionDialog = new ListDialog(parentFrame,
"Command Arguments", false);
Action openOptionDialog = new AbstractAction("...")
{
public void actionPerformed(ActionEvent e)
{
java.util.LinkedList result = _optionDialog.show(
_optionList, _mainEditor.getProperties());
if(result != null)
{
_mainEditor.updated();
_optionList = result;
setOptionsField();
}
}
};
openOptionDialog.putValue(Action.SHORT_DESCRIPTION,
"Edit command-line arguments");
_optionButton = new JButton(openOptionDialog);
Action appDistrib = new AbstractAction("Depends on the application distribution")
{
public void actionPerformed(ActionEvent e)
{
_mainEditor.updated();
}
};
appDistrib.putValue(Action.SHORT_DESCRIPTION,
"<html>Check this box if this server needs to be restarted<br>"
+ "each time the distribution for your application is refreshed.</html>");
_applicationDistrib = new JCheckBox(appDistrib);
_distrib = new JComboBox(new Object[]{NO_DISTRIB, DEFAULT_DISTRIB});
_distrib.setToolTipText(
"The proxy to the IcePatch2 server holding your files");
JTextField distribTextField = (JTextField)
_distrib.getEditor().getEditorComponent();
distribTextField.getDocument().addDocumentListener(
_mainEditor.getUpdateListener());
_distribDirs.setEditable(false);
_distribDirsDialog = new ListDialog(parentFrame,
"Directories", true);
Action openDistribDirsDialog = new AbstractAction("...")
{
public void actionPerformed(ActionEvent e)
{
java.util.LinkedList result = _distribDirsDialog.show(
_distribDirsList, _mainEditor.getProperties());
if(result != null)
{
_mainEditor.updated();
_distribDirsList = result;
setDistribDirsField();
}
}
};
openDistribDirsDialog.putValue(Action.SHORT_DESCRIPTION,
"Edit directory list");
_distribDirsButton = new JButton(openDistribDirsDialog);
}
ServerDescriptor getServerDescriptor()
{
return (ServerDescriptor)
_mainEditor.getSubDescriptor();
}
void appendProperties(DefaultFormBuilder builder)
{
builder.append("Server ID");
builder.append(_id, 3);
builder.nextLine();
//
// Add Communicator fields
//
super.appendProperties(builder);
builder.appendSeparator("Activation");
builder.append("Path to Executable");
builder.append(_exe, 3);
builder.nextLine();
builder.append("Working Directory");
builder.append(_pwd, 3);
builder.nextLine();
builder.append("Command Arguments");
builder.append(_options, _optionButton);
builder.nextLine();
builder.append("Environment Variables");
builder.append(_envs, _envButton);
builder.nextLine();
builder.append("Activation Mode");
builder.append(_activation, 3);
builder.nextLine();
builder.append("Activation Timeout");
builder.append(_activationTimeout, 3);
builder.nextLine();
builder.append("Deactivation Timeout");
builder.append(_deactivationTimeout, 3);
builder.nextLine();
JComponent c = builder.appendSeparator("Distribution");
c.setToolTipText("Files specific to this server");
builder.append("", _applicationDistrib);
builder.nextLine();
builder.append("IcePatch2 Proxy");
builder.append(_distrib, 3);
builder.nextLine();
builder.append("Directories");
builder.append(_distribDirs, _distribDirsButton);
builder.nextLine();
}
void writeDescriptor()
{
ServerDescriptor descriptor = getServerDescriptor();
descriptor.id = _id.getText();
descriptor.exe = _exe.getText();
descriptor.pwd = _pwd.getText();
descriptor.options = _optionList;
descriptor.envs = new java.util.LinkedList();
java.util.Iterator p = _envMap.entrySet().iterator();
while(p.hasNext())
{
java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
descriptor.envs.add(entry.getKey().toString()
+ "=" + entry.getValue().toString());
}
descriptor.activation = _activation.getSelectedItem().toString();
descriptor.activationTimeout = _activationTimeout.getText();
descriptor.deactivationTimeout = _deactivationTimeout.getText();
descriptor.applicationDistrib = _applicationDistrib.isSelected();
if(_distrib.getSelectedItem() == NO_DISTRIB)
{
descriptor.distrib.icepatch = "";
}
else
{
descriptor.distrib.icepatch = _distrib.getSelectedItem().toString();
}
descriptor.distrib.directories = _distribDirsList;
super.writeDescriptor(descriptor);
}
boolean isSimpleUpdate()
{
return getServerDescriptor().id.equals(_id.getText());
}
void show(boolean isEditable)
{
ServerDescriptor descriptor = getServerDescriptor();
Utils.Resolver detailResolver = _mainEditor.getDetailResolver();
isEditable = isEditable && (detailResolver == null);
if(detailResolver != null)
{
_id.setText(detailResolver.find("server"));
}
else
{
_id.setText(descriptor.id);
}
_id.setEditable(isEditable);
_exe.setText(
Utils.substitute(descriptor.exe, detailResolver));
_exe.setEditable(isEditable);
_pwd.setText(
Utils.substitute(descriptor.pwd, detailResolver));
_pwd.setEditable(isEditable);
_optionList = descriptor.options;
setOptionsField();
_optionButton.setEnabled(isEditable);
_envMap = new java.util.TreeMap();
java.util.Iterator p = descriptor.envs.iterator();
while(p.hasNext())
{
String env = (String)p.next();
int equal = env.indexOf('=');
if(equal == -1 || equal == env.length() - 1)
{
_envMap.put(env, "");
}
else
{
_envMap.put(env.substring(0, equal),
env.substring(equal + 1));
}
}
setEnvsField();
_envButton.setEnabled(isEditable);
String activation = Utils.substitute(descriptor.activation,
detailResolver);
_activation.setEnabled(true);
_activation.setEditable(true);
if(activation.equals(ON_DEMAND))
{
_activation.setSelectedItem(ON_DEMAND);
}
else if(activation.equals(MANUAL))
{
_activation.setSelectedItem(MANUAL);
}
else
{
_activation.setSelectedItem(activation);
}
_activation.setEnabled(isEditable);
_activation.setEditable(isEditable);
_activationTimeout.setText(
Utils.substitute(descriptor.activationTimeout, detailResolver));
_activationTimeout.setEditable(isEditable);
_deactivationTimeout.setText(
Utils.substitute(descriptor.deactivationTimeout, detailResolver));
_deactivationTimeout.setEditable(isEditable);
_applicationDistrib.setSelected(descriptor.applicationDistrib);
_applicationDistrib.setEnabled(isEditable);
_distrib.setEnabled(true);
_distrib.setEditable(true);
String icepatch = Utils.substitute(descriptor.distrib.icepatch,
detailResolver);
if(icepatch.equals(""))
{
_distrib.setSelectedItem(NO_DISTRIB);
}
else
{
_distrib.setSelectedItem(icepatch);
}
_distrib.setEnabled(isEditable);
_distrib.setEditable(isEditable);
_distribDirsList = new java.util.LinkedList(descriptor.distrib.directories);
setDistribDirsField();
_distribDirsButton.setEnabled(isEditable);
show(descriptor, isEditable);
}
private void setEnvsField()
{
final Utils.Resolver resolver = _mainEditor.getDetailResolver();
Ice.StringHolder toolTipHolder = new Ice.StringHolder();
Utils.Stringifier stringifier = new Utils.Stringifier()
{
public String toString(Object obj)
{
java.util.Map.Entry entry = (java.util.Map.Entry)obj;
return Utils.substitute((String)entry.getKey(), resolver)
+ "="
+ Utils.substitute((String)entry.getValue(), resolver);
}
};
_envs.setText(
Utils.stringify(_envMap.entrySet(), stringifier,
", ", toolTipHolder));
_envs.setToolTipText(toolTipHolder.value);
}
private void setOptionsField()
{
final Utils.Resolver resolver = _mainEditor.getDetailResolver();
Ice.StringHolder toolTipHolder = new Ice.StringHolder();
Utils.Stringifier stringifier = new Utils.Stringifier()
{
public String toString(Object obj)
{
return Utils.substitute((String)obj, resolver);
}
};
_options.setText(
Utils.stringify(_optionList, stringifier, " ", toolTipHolder));
_options.setToolTipText(toolTipHolder.value);
}
private void setDistribDirsField()
{
final Utils.Resolver resolver = _mainEditor.getDetailResolver();
Ice.StringHolder toolTipHolder = new Ice.StringHolder();
Utils.Stringifier stringifier = new Utils.Stringifier()
{
public String toString(Object obj)
{
return Utils.substitute((String)obj, resolver);
}
};
_distribDirs.setText(
Utils.stringify(_distribDirsList, stringifier, ", ",
toolTipHolder));
String toolTip = "<html>Include only these directories";
if(toolTipHolder.value != null)
{
toolTip += ":<br>" + toolTipHolder.value;
}
toolTip += "</html>";
_distribDirs.setToolTipText(toolTip);
}
static private final String ON_DEMAND = "on-demand";
static private final String MANUAL = "manual";
static private final Object NO_DISTRIB = new Object()
{
public String toString()
{
return "None selected";
}
};
static private final String DEFAULT_DISTRIB = "${application}.IcePatch2/server";
private JTextField _id = new JTextField(20);
private JTextField _exe = new JTextField(20);
private JTextField _pwd = new JTextField(20);
private JComboBox _activation;
private JTextField _activationTimeout = new JTextField(20);
private JTextField _deactivationTimeout = new JTextField(20);
private JTextField _envs = new JTextField(20);
private java.util.Map _envMap;
private TableDialog _envDialog;
private JButton _envButton;
private JTextField _options = new JTextField(20);
private java.util.LinkedList _optionList;
private ListDialog _optionDialog;
private JButton _optionButton;
private JCheckBox _applicationDistrib;
private JComboBox _distrib;
private JTextField _distribDirs = new JTextField(20);
private java.util.LinkedList _distribDirsList;
private ListDialog _distribDirsDialog;
private JButton _distribDirsButton;
}
|