1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.ui.dialog;
|
11
|
|
12
|
import java.util.HashMap;
|
13
|
import java.util.List;
|
14
|
import java.util.Map;
|
15
|
|
16
|
import org.eclipse.core.runtime.IProgressMonitor;
|
17
|
import org.eclipse.core.runtime.IStatus;
|
18
|
import org.eclipse.core.runtime.Status;
|
19
|
import org.eclipse.core.runtime.jobs.Job;
|
20
|
import org.eclipse.swt.SWT;
|
21
|
import org.eclipse.swt.custom.StyledText;
|
22
|
import org.eclipse.swt.events.MouseAdapter;
|
23
|
import org.eclipse.swt.events.MouseEvent;
|
24
|
import org.eclipse.swt.events.SelectionAdapter;
|
25
|
import org.eclipse.swt.events.SelectionEvent;
|
26
|
import org.eclipse.swt.graphics.Point;
|
27
|
import org.eclipse.swt.layout.FillLayout;
|
28
|
import org.eclipse.swt.layout.GridData;
|
29
|
import org.eclipse.swt.layout.GridLayout;
|
30
|
import org.eclipse.swt.widgets.Button;
|
31
|
import org.eclipse.swt.widgets.Combo;
|
32
|
import org.eclipse.swt.widgets.Composite;
|
33
|
import org.eclipse.swt.widgets.Dialog;
|
34
|
import org.eclipse.swt.widgets.Display;
|
35
|
import org.eclipse.swt.widgets.Label;
|
36
|
import org.eclipse.swt.widgets.Shell;
|
37
|
import org.eclipse.swt.widgets.Text;
|
38
|
import org.eclipse.ui.forms.events.ExpansionEvent;
|
39
|
import org.eclipse.ui.forms.events.IExpansionListener;
|
40
|
import org.eclipse.ui.forms.widgets.ExpandableComposite;
|
41
|
import org.eclipse.wb.swt.SWTResourceManager;
|
42
|
|
43
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
44
|
import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
|
45
|
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo;
|
46
|
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo.CdmInstanceInfo;
|
47
|
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
|
48
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
49
|
|
50
|
/**
|
51
|
* @author cmathew
|
52
|
* @date 20 Jan 2015
|
53
|
*
|
54
|
*/
|
55
|
public class RemotingLoginDialog extends Dialog {
|
56
|
|
57
|
protected Object result;
|
58
|
protected Shell shlConnect;
|
59
|
private Text txtCdmServerStatus;
|
60
|
private Text txtCdmInstanceStatus;
|
61
|
private Combo comboCdmServer;
|
62
|
private Combo comboCdmInstance;
|
63
|
private Button btnConnect;
|
64
|
|
65
|
private final Map<String, CdmServerInfo> csiiMap = new HashMap<String, CdmServerInfo>();
|
66
|
|
67
|
private final String STATUS_AVAILABLE = "Available";
|
68
|
private final String STATUS_NOT_AVAILABLE = "Not Available";
|
69
|
private final String STATUS_RETRIEVING = "Retrieving ...";
|
70
|
private final String STATUS_CHECKING_AVAILABILITY = "Checking ...";
|
71
|
private final String STATUS_NO_INSTANCES = "No Instances Found";
|
72
|
private final String STATUS_ERROR = "Error";
|
73
|
private final String STATUS_REMOTING_NOT_ACTIVATED = "Remoting not activated";
|
74
|
|
75
|
private Composite remotingComposite;
|
76
|
private CdmServerInfo selectedCsii;
|
77
|
private CdmInstanceInfo selectedCdmInstance;
|
78
|
private Button btnCdmServerRefresh;
|
79
|
private Composite loginComposite;
|
80
|
private Label lblLogin;
|
81
|
private Text txtLogin;
|
82
|
private Label lblPassword;
|
83
|
private Text txtPassword;
|
84
|
private Button btnRememberMe;
|
85
|
private Composite composite;
|
86
|
private Label lblPort;
|
87
|
private Text txtPort;
|
88
|
private Label lblServerVersion;
|
89
|
private Text txtServerVersion;
|
90
|
private ExpandableComposite xpndblcmpstAdvanced;
|
91
|
private StyledText styledTxtMessage;
|
92
|
|
93
|
|
94
|
private final int MIN_WIDTH = 530;
|
95
|
private final int MIN_HEIGHT = 220;
|
96
|
private final int MIN_EXP_HEIGHT = 300;
|
97
|
private final int MESSAGE_HEIGHT = 25;
|
98
|
|
99
|
/**
|
100
|
* Create the dialog.
|
101
|
* @param parent
|
102
|
* @param style
|
103
|
*/
|
104
|
public RemotingLoginDialog(Shell parent, int style) {
|
105
|
super(parent, style);
|
106
|
setText("Login");
|
107
|
}
|
108
|
|
109
|
/**
|
110
|
* Open the dialog.
|
111
|
* @return the result
|
112
|
*/
|
113
|
public Object open() {
|
114
|
// ICdmRemoteSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
|
115
|
// if(devRemoteSource != null) {
|
116
|
// connect(devRemoteSource);
|
117
|
// } else {
|
118
|
createContents();
|
119
|
populateCdmServerCombo();
|
120
|
shlConnect.open();
|
121
|
shlConnect.layout();
|
122
|
|
123
|
xpndblcmpstAdvanced.setExpanded(false);
|
124
|
//setMessage(null);
|
125
|
|
126
|
Display display = getParent().getDisplay();
|
127
|
|
128
|
while (!shlConnect.isDisposed()) {
|
129
|
if (!display.readAndDispatch()) {
|
130
|
display.sleep();
|
131
|
}
|
132
|
}
|
133
|
//}
|
134
|
return result;
|
135
|
}
|
136
|
|
137
|
/**
|
138
|
* Create contents of the dialog.
|
139
|
*/
|
140
|
private void createContents() {
|
141
|
shlConnect = new Shell(getParent(), SWT.DIALOG_TRIM);
|
142
|
shlConnect.setMinimumSize(new Point(MIN_WIDTH, MIN_HEIGHT));
|
143
|
shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
|
144
|
shlConnect.setText("Connect");
|
145
|
shlConnect.setLayout(new FillLayout(SWT.HORIZONTAL));
|
146
|
|
147
|
remotingComposite = new Composite(shlConnect, SWT.NONE);
|
148
|
remotingComposite.setLayout(new GridLayout(1, false));
|
149
|
|
150
|
Composite cdmServerComposite = new Composite(remotingComposite, SWT.NONE);
|
151
|
GridData gd_cdmServerComposite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
|
152
|
gd_cdmServerComposite.heightHint = 68;
|
153
|
cdmServerComposite.setLayoutData(gd_cdmServerComposite);
|
154
|
cdmServerComposite.setLayout(new GridLayout(4, false));
|
155
|
|
156
|
Label lblCdmServer = new Label(cdmServerComposite, SWT.NONE);
|
157
|
lblCdmServer.setText("CDM Server : ");
|
158
|
lblCdmServer.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
|
159
|
lblCdmServer.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
160
|
|
161
|
comboCdmServer = new Combo(cdmServerComposite, SWT.READ_ONLY);
|
162
|
comboCdmServer.addSelectionListener(new SelectionAdapter() {
|
163
|
@Override
|
164
|
public void widgetSelected(SelectionEvent e) {
|
165
|
refreshCdmServer();
|
166
|
}
|
167
|
});
|
168
|
GridData gd_comboCdmServer = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
|
169
|
gd_comboCdmServer.widthHint = 150;
|
170
|
comboCdmServer.setLayoutData(gd_comboCdmServer);
|
171
|
comboCdmServer.select(0);
|
172
|
|
173
|
txtCdmServerStatus = new Text(cdmServerComposite, SWT.BORDER);
|
174
|
txtCdmServerStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
|
175
|
txtCdmServerStatus.setEditable(false);
|
176
|
GridData gd_txtCdmServerStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
|
177
|
gd_txtCdmServerStatus.widthHint = 100;
|
178
|
txtCdmServerStatus.setLayoutData(gd_txtCdmServerStatus);
|
179
|
|
180
|
btnCdmServerRefresh = new Button(cdmServerComposite, SWT.NONE);
|
181
|
btnCdmServerRefresh.addSelectionListener(new SelectionAdapter() {
|
182
|
@Override
|
183
|
public void widgetSelected(SelectionEvent e) {
|
184
|
refreshCdmServer();
|
185
|
}
|
186
|
});
|
187
|
btnCdmServerRefresh.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
|
188
|
btnCdmServerRefresh.setText("Refresh");
|
189
|
|
190
|
Label lblCdmInstance = new Label(cdmServerComposite, SWT.NONE);
|
191
|
GridData gd_lblCdmInstance = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
|
192
|
gd_lblCdmInstance.heightHint = 30;
|
193
|
lblCdmInstance.setLayoutData(gd_lblCdmInstance);
|
194
|
lblCdmInstance.setText("CDM Instance : ");
|
195
|
lblCdmInstance.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
|
196
|
|
197
|
comboCdmInstance = new Combo(cdmServerComposite, SWT.READ_ONLY);
|
198
|
comboCdmInstance.addSelectionListener(new SelectionAdapter() {
|
199
|
@Override
|
200
|
public void widgetSelected(SelectionEvent e) {
|
201
|
updateSelectedCdmInstance();
|
202
|
checkSelectedCdmServerInstance();
|
203
|
}
|
204
|
});
|
205
|
GridData gd_comboCdmInstance = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
|
206
|
gd_comboCdmInstance.widthHint = 150;
|
207
|
comboCdmInstance.setLayoutData(gd_comboCdmInstance);
|
208
|
comboCdmInstance.select(0);
|
209
|
|
210
|
txtCdmInstanceStatus = new Text(cdmServerComposite, SWT.BORDER);
|
211
|
txtCdmInstanceStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
|
212
|
txtCdmInstanceStatus.setEditable(false);
|
213
|
GridData gd_txtCdmInstanceStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
|
214
|
gd_txtCdmInstanceStatus.widthHint = 100;
|
215
|
txtCdmInstanceStatus.setLayoutData(gd_txtCdmInstanceStatus);
|
216
|
|
217
|
Button btnCdmInstanceRefresh = new Button(cdmServerComposite, SWT.FLAT);
|
218
|
btnCdmInstanceRefresh.addSelectionListener(new SelectionAdapter() {
|
219
|
@Override
|
220
|
public void widgetSelected(SelectionEvent e) {
|
221
|
refreshCdmInstance();
|
222
|
}
|
223
|
});
|
224
|
GridData gd_btnCdmInstanceRefresh = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
|
225
|
gd_btnCdmInstanceRefresh.widthHint = 110;
|
226
|
gd_btnCdmInstanceRefresh.heightHint = 30;
|
227
|
btnCdmInstanceRefresh.setLayoutData(gd_btnCdmInstanceRefresh);
|
228
|
btnCdmInstanceRefresh.setText("Refresh");
|
229
|
|
230
|
loginComposite = new Composite(remotingComposite, SWT.NONE);
|
231
|
GridData gd_loginComposite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
|
232
|
gd_loginComposite.widthHint = 487;
|
233
|
gd_loginComposite.heightHint = 70;
|
234
|
loginComposite.setLayoutData(gd_loginComposite);
|
235
|
GridLayout gl_loginComposite = new GridLayout(6, false);
|
236
|
gl_loginComposite.marginTop = 5;
|
237
|
loginComposite.setLayout(gl_loginComposite);
|
238
|
|
239
|
lblLogin = new Label(loginComposite, SWT.CENTER);
|
240
|
GridData gd_lblLogin = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
|
241
|
gd_lblLogin.widthHint = 50;
|
242
|
lblLogin.setLayoutData(gd_lblLogin);
|
243
|
lblLogin.setText("Login : ");
|
244
|
lblLogin.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
|
245
|
|
246
|
txtLogin = new Text(loginComposite, SWT.BORDER);
|
247
|
GridData gd_txtLogin = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
|
248
|
gd_txtLogin.minimumWidth = 80;
|
249
|
gd_txtLogin.widthHint = 80;
|
250
|
gd_txtLogin.heightHint = 15;
|
251
|
txtLogin.setLayoutData(gd_txtLogin);
|
252
|
|
253
|
lblPassword = new Label(loginComposite, SWT.CENTER);
|
254
|
lblPassword.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
255
|
lblPassword.setText("Password : ");
|
256
|
lblPassword.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
|
257
|
|
258
|
txtPassword = new Text(loginComposite, SWT.BORDER | SWT.PASSWORD);
|
259
|
GridData gd_txtPassword = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
|
260
|
gd_txtPassword.minimumWidth = 80;
|
261
|
gd_txtPassword.widthHint = 80;
|
262
|
gd_txtPassword.heightHint = 15;
|
263
|
txtPassword.setLayoutData(gd_txtPassword);
|
264
|
new Label(loginComposite, SWT.NONE);
|
265
|
|
266
|
btnConnect = new Button(loginComposite, SWT.FLAT);
|
267
|
btnConnect.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
|
268
|
btnConnect.addMouseListener(new MouseAdapter() {
|
269
|
@Override
|
270
|
public void mouseUp(MouseEvent e) {
|
271
|
int selInstanceIndex = comboCdmInstance.getSelectionIndex();
|
272
|
String instance = comboCdmInstance.getItem(selInstanceIndex);
|
273
|
checkSelectedCdmServerInstance();
|
274
|
connect(selectedCsii.getCdmRemoteSource(selectedCdmInstance));
|
275
|
}
|
276
|
});
|
277
|
btnConnect.setText("Connect");
|
278
|
|
279
|
btnRememberMe = new Button(loginComposite, SWT.CHECK);
|
280
|
GridData gd_btnRememberMe = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);
|
281
|
gd_btnRememberMe.widthHint = 107;
|
282
|
btnRememberMe.setLayoutData(gd_btnRememberMe);
|
283
|
btnRememberMe.setEnabled(false);
|
284
|
btnRememberMe.setText("Remember Me");
|
285
|
|
286
|
styledTxtMessage = new StyledText(remotingComposite, SWT.NONE);
|
287
|
styledTxtMessage.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
|
288
|
styledTxtMessage.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));
|
289
|
styledTxtMessage.setFont(SWTResourceManager.getFont("Ubuntu", 12, SWT.BOLD));
|
290
|
styledTxtMessage.setSelectionBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_SELECTION_TEXT));
|
291
|
styledTxtMessage.setSelectionForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));
|
292
|
styledTxtMessage.setDoubleClickEnabled(false);
|
293
|
styledTxtMessage.setEditable(false);
|
294
|
GridData gd_styledTxtMessage = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
|
295
|
gd_styledTxtMessage.exclude = true;
|
296
|
gd_styledTxtMessage.minimumHeight = MESSAGE_HEIGHT;
|
297
|
gd_styledTxtMessage.heightHint = MESSAGE_HEIGHT;
|
298
|
styledTxtMessage.setLayoutData(gd_styledTxtMessage);
|
299
|
|
300
|
xpndblcmpstAdvanced = new ExpandableComposite(remotingComposite, SWT.NONE, ExpandableComposite.TWISTIE);
|
301
|
GridData gd_xpndblcmpstAdvanced = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
|
302
|
gd_xpndblcmpstAdvanced.heightHint = 19;
|
303
|
xpndblcmpstAdvanced.setLayoutData(gd_xpndblcmpstAdvanced);
|
304
|
xpndblcmpstAdvanced.addExpansionListener(new IExpansionListener() {
|
305
|
@Override
|
306
|
public void expansionStateChanged(ExpansionEvent e) {
|
307
|
GridData gridData = (GridData) xpndblcmpstAdvanced.getLayoutData();
|
308
|
if(e.getState()) {
|
309
|
shlConnect.setSize(MIN_WIDTH, MIN_EXP_HEIGHT);
|
310
|
} else {
|
311
|
shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
|
312
|
}
|
313
|
|
314
|
}
|
315
|
@Override
|
316
|
public void expansionStateChanging(ExpansionEvent e) {
|
317
|
}
|
318
|
});
|
319
|
xpndblcmpstAdvanced.setText("advanced");
|
320
|
xpndblcmpstAdvanced.setExpanded(false);
|
321
|
|
322
|
composite = new Composite(xpndblcmpstAdvanced, SWT.NONE);
|
323
|
xpndblcmpstAdvanced.setClient(composite);
|
324
|
composite.setLayout(new GridLayout(2, false));
|
325
|
|
326
|
lblPort = new Label(composite, SWT.CENTER);
|
327
|
lblPort.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
328
|
lblPort.setSize(0, 0);
|
329
|
lblPort.setText("Port : ");
|
330
|
lblPort.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
|
331
|
|
332
|
txtPort = new Text(composite, SWT.BORDER);
|
333
|
txtPort.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
|
334
|
|
335
|
lblServerVersion = new Label(composite, SWT.CENTER);
|
336
|
lblServerVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
337
|
lblServerVersion.setText("Server Version :");
|
338
|
lblServerVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
|
339
|
|
340
|
txtServerVersion = new Text(composite, SWT.BORDER);
|
341
|
txtServerVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
|
342
|
|
343
|
}
|
344
|
|
345
|
private void populateCdmServerCombo() {
|
346
|
Job job = new Job("Retrieve Server Instances") {
|
347
|
@Override
|
348
|
protected IStatus run(IProgressMonitor monitor) {
|
349
|
Display.getDefault().asyncExec(new Runnable() {
|
350
|
@Override
|
351
|
public void run() {
|
352
|
for(CdmServerInfo csii : CdmServerInfo.getCdmServers()) {
|
353
|
csiiMap.put(csii.getName(), csii);
|
354
|
comboCdmServer.add(csii.getName());
|
355
|
}
|
356
|
comboCdmServer.select(0);
|
357
|
refreshCdmServer();
|
358
|
}
|
359
|
});
|
360
|
return Status.OK_STATUS;
|
361
|
}
|
362
|
};
|
363
|
job.schedule();
|
364
|
}
|
365
|
|
366
|
|
367
|
private void refreshCdmServer() {
|
368
|
txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
|
369
|
updateSelectedCdmServer();
|
370
|
updatePort();
|
371
|
checkSelectedCdmServer();
|
372
|
}
|
373
|
|
374
|
private void updateSelectedCdmServer() {
|
375
|
int selIndex = comboCdmServer.getSelectionIndex();
|
376
|
if(selIndex != -1) {
|
377
|
selectedCsii = csiiMap.get(comboCdmServer.getItem(selIndex));
|
378
|
}
|
379
|
}
|
380
|
|
381
|
private void updatePort() {
|
382
|
txtPort.setText("");
|
383
|
if(selectedCsii != null) {
|
384
|
txtPort.setText(String.valueOf(selectedCsii.getPort()));
|
385
|
}
|
386
|
}
|
387
|
|
388
|
private void checkSelectedCdmServer() {
|
389
|
int selIndex = comboCdmServer.getSelectionIndex();
|
390
|
txtCdmInstanceStatus.setText("");
|
391
|
if(selectedCsii != null) {
|
392
|
if(selectedCsii.pingServer()) {
|
393
|
txtCdmServerStatus.setText(STATUS_AVAILABLE);
|
394
|
populateCdmInstanceCombo(true);
|
395
|
} else {
|
396
|
txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
|
397
|
comboCdmInstance.removeAll();
|
398
|
}
|
399
|
}
|
400
|
}
|
401
|
|
402
|
|
403
|
private void populateCdmInstanceCombo(final boolean forceRefresh) {
|
404
|
comboCdmInstance.removeAll();
|
405
|
comboCdmInstance.setEnabled(false);
|
406
|
btnConnect.setEnabled(false);
|
407
|
txtCdmInstanceStatus.setText(STATUS_RETRIEVING);
|
408
|
Job job = new Job("Retrieve Server Instances") {
|
409
|
@Override
|
410
|
protected IStatus run(IProgressMonitor monitor) {
|
411
|
try {
|
412
|
if(selectedCsii != null) {
|
413
|
if(forceRefresh) {
|
414
|
selectedCsii.refreshInstances();
|
415
|
}
|
416
|
final List<CdmInstanceInfo> instances = selectedCsii.getInstances();
|
417
|
Display.getDefault().asyncExec(new Runnable() {
|
418
|
@Override
|
419
|
public void run() {
|
420
|
if(!instances.isEmpty()) {
|
421
|
for(CdmInstanceInfo cdmInstance : instances) {
|
422
|
comboCdmInstance.add(cdmInstance.getName());
|
423
|
}
|
424
|
comboCdmInstance.select(0);
|
425
|
updateSelectedCdmInstance();
|
426
|
checkSelectedCdmServerInstance();
|
427
|
comboCdmInstance.setEnabled(true);
|
428
|
} else {
|
429
|
txtCdmInstanceStatus.setText(STATUS_NO_INSTANCES);
|
430
|
btnConnect.setEnabled(false);
|
431
|
}
|
432
|
}
|
433
|
});
|
434
|
}
|
435
|
} catch (CDMServerException e) {
|
436
|
MessagingUtils.warn(getClass(), e);
|
437
|
Display.getDefault().asyncExec(new Runnable() {
|
438
|
@Override
|
439
|
public void run() {
|
440
|
txtCdmInstanceStatus.setText(STATUS_REMOTING_NOT_ACTIVATED);
|
441
|
comboCdmInstance.setEnabled(false);
|
442
|
btnConnect.setEnabled(false);
|
443
|
}
|
444
|
});
|
445
|
}
|
446
|
return Status.OK_STATUS;
|
447
|
}
|
448
|
};
|
449
|
|
450
|
if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
|
451
|
// Start the Job
|
452
|
job.schedule();
|
453
|
}
|
454
|
|
455
|
}
|
456
|
|
457
|
private void refreshCdmInstance() {
|
458
|
txtCdmInstanceStatus.setText(STATUS_CHECKING_AVAILABILITY);
|
459
|
updateSelectedCdmInstance();
|
460
|
checkSelectedCdmServerInstance();
|
461
|
}
|
462
|
|
463
|
private void updateSelectedCdmInstance() {
|
464
|
int selIndex = comboCdmInstance.getSelectionIndex();
|
465
|
if(selIndex != -1) {
|
466
|
selectedCdmInstance = selectedCsii.getInstanceFromName(comboCdmInstance.getItem(selIndex));
|
467
|
}
|
468
|
}
|
469
|
|
470
|
private void checkSelectedCdmServerInstance() {
|
471
|
if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
|
472
|
try {
|
473
|
if(selectedCsii.pingInstance(selectedCdmInstance)) {
|
474
|
txtCdmInstanceStatus.setText(STATUS_AVAILABLE);
|
475
|
btnConnect.setEnabled(true);
|
476
|
} else {
|
477
|
txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
|
478
|
btnConnect.setEnabled(false);
|
479
|
}
|
480
|
} catch (Exception e) {
|
481
|
txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
|
482
|
MessagingUtils.warn(this.getClass(), e);
|
483
|
}
|
484
|
}
|
485
|
|
486
|
}
|
487
|
|
488
|
private void connect(ICdmRemoteSource source) {
|
489
|
|
490
|
|
491
|
if(!validateLogin()) {
|
492
|
return;
|
493
|
}
|
494
|
|
495
|
if(CdmStore.isConnecting()){
|
496
|
MessagingUtils.warningDialog("Already connecting", this, "You are currently connecting to a different CDM Instance already.");
|
497
|
return;
|
498
|
}
|
499
|
|
500
|
try {
|
501
|
CdmStore.connect(source, this);
|
502
|
} catch (Exception e) {
|
503
|
// Do not expect anything to go wrong at this point, so we throw a runtime exception
|
504
|
// if any problems
|
505
|
throw new RuntimeException(e);
|
506
|
}
|
507
|
|
508
|
}
|
509
|
|
510
|
private boolean validateLogin() {
|
511
|
if(getUsername() == null || getUsername().isEmpty()) {
|
512
|
setMessage("User login cannot be empty");
|
513
|
return false;
|
514
|
}
|
515
|
if(getPassword() == null || getPassword().isEmpty()) {
|
516
|
setMessage("Password cannot be empty");
|
517
|
return false;
|
518
|
}
|
519
|
return true;
|
520
|
}
|
521
|
public String getUsername() {
|
522
|
return txtLogin.getText();
|
523
|
}
|
524
|
|
525
|
public String getPassword() {
|
526
|
return txtPassword.getText();
|
527
|
}
|
528
|
|
529
|
public void setMessage(String message) {
|
530
|
if(message != null && !message.isEmpty()) {
|
531
|
styledTxtMessage.setText(message);
|
532
|
styledTxtMessage.setVisible(true);
|
533
|
((GridData)styledTxtMessage.getLayoutData()).exclude = false;
|
534
|
shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT+MESSAGE_HEIGHT);
|
535
|
shlConnect.setMinimumSize(MIN_WIDTH, MIN_HEIGHT+MESSAGE_HEIGHT);
|
536
|
} else {
|
537
|
styledTxtMessage.setText("");
|
538
|
styledTxtMessage.setVisible(false);
|
539
|
((GridData)styledTxtMessage.getLayoutData()).exclude = true;
|
540
|
shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
|
541
|
shlConnect.setMinimumSize(MIN_WIDTH, MIN_HEIGHT);
|
542
|
}
|
543
|
remotingComposite.layout();
|
544
|
}
|
545
|
|
546
|
public void hide(boolean isHidden) {
|
547
|
if(shlConnect != null) {
|
548
|
shlConnect.setVisible(!isHidden);
|
549
|
}
|
550
|
}
|
551
|
public void dispose() {
|
552
|
if(shlConnect != null) {
|
553
|
shlConnect.dispose();
|
554
|
}
|
555
|
}
|
556
|
}
|