1
|
/**
|
2
|
* Copyright (C) 2015 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.webapp.server;
|
10
|
|
11
|
import java.io.File;
|
12
|
import java.io.IOException;
|
13
|
import java.net.SocketTimeoutException;
|
14
|
import java.text.SimpleDateFormat;
|
15
|
import java.util.Date;
|
16
|
import java.util.HashMap;
|
17
|
import java.util.List;
|
18
|
import java.util.Map;
|
19
|
|
20
|
import org.apache.commons.lang3.StringUtils;
|
21
|
import org.apache.log4j.Logger;
|
22
|
import org.eclipse.core.runtime.IProgressMonitor;
|
23
|
import org.eclipse.core.runtime.IStatus;
|
24
|
import org.eclipse.core.runtime.Status;
|
25
|
import org.eclipse.core.runtime.jobs.Job;
|
26
|
import org.eclipse.core.runtime.preferences.ConfigurationScope;
|
27
|
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
28
|
import org.eclipse.jface.layout.GridDataFactory;
|
29
|
import org.eclipse.swt.SWT;
|
30
|
import org.eclipse.swt.SWTException;
|
31
|
import org.eclipse.swt.custom.StyledText;
|
32
|
import org.eclipse.swt.events.KeyAdapter;
|
33
|
import org.eclipse.swt.events.KeyEvent;
|
34
|
import org.eclipse.swt.events.MouseAdapter;
|
35
|
import org.eclipse.swt.events.MouseEvent;
|
36
|
import org.eclipse.swt.events.SelectionAdapter;
|
37
|
import org.eclipse.swt.events.SelectionEvent;
|
38
|
import org.eclipse.swt.graphics.Color;
|
39
|
import org.eclipse.swt.graphics.Point;
|
40
|
import org.eclipse.swt.graphics.Rectangle;
|
41
|
import org.eclipse.swt.layout.FillLayout;
|
42
|
import org.eclipse.swt.layout.GridData;
|
43
|
import org.eclipse.swt.layout.GridLayout;
|
44
|
import org.eclipse.swt.widgets.Button;
|
45
|
import org.eclipse.swt.widgets.Combo;
|
46
|
import org.eclipse.swt.widgets.Composite;
|
47
|
import org.eclipse.swt.widgets.Display;
|
48
|
import org.eclipse.swt.widgets.Label;
|
49
|
import org.eclipse.swt.widgets.Shell;
|
50
|
import org.eclipse.swt.widgets.Text;
|
51
|
import org.eclipse.ui.forms.events.ExpansionEvent;
|
52
|
import org.eclipse.ui.forms.events.IExpansionListener;
|
53
|
import org.eclipse.ui.forms.widgets.ExpandableComposite;
|
54
|
import org.eclipse.ui.progress.IProgressConstants;
|
55
|
import org.eclipse.wb.swt.SWTResourceManager;
|
56
|
import org.osgi.service.prefs.BackingStoreException;
|
57
|
import org.osgi.service.prefs.Preferences;
|
58
|
import org.springframework.security.authentication.BadCredentialsException;
|
59
|
import org.springframework.security.authentication.LockedException;
|
60
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
61
|
|
62
|
import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteConfiguration;
|
63
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
64
|
import eu.etaxonomy.cdm.api.service.IUserService;
|
65
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
66
|
import eu.etaxonomy.cdm.config.CdmSourceException;
|
67
|
import eu.etaxonomy.cdm.config.ICdmSource;
|
68
|
import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
|
69
|
import eu.etaxonomy.cdm.persistence.permission.Role;
|
70
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
71
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
72
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
73
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
74
|
import eu.etaxonomy.taxeditor.remoting.server.CdmServerException;
|
75
|
import eu.etaxonomy.taxeditor.remoting.server.CdmServerUtils;
|
76
|
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteLocalhostSource;
|
77
|
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo;
|
78
|
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo.CdmInstanceInfo;
|
79
|
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
|
80
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
81
|
import eu.etaxonomy.taxeditor.store.LoginManager;
|
82
|
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
|
83
|
import eu.etaxonomy.taxeditor.ui.dialog.RemotingLoginDialog;
|
84
|
import eu.etaxonomy.taxeditor.webapp.CdmEmbeddedServerException;
|
85
|
import eu.etaxonomy.taxeditor.webapp.CdmServer;
|
86
|
|
87
|
|
88
|
|
89
|
/**
|
90
|
* @author cmathew
|
91
|
* @date 20 Jan 2015
|
92
|
*/
|
93
|
public class RemotingLoginDialogLocal extends RemotingLoginDialog {
|
94
|
|
95
|
private Logger logger = Logger.getLogger(getClass());
|
96
|
|
97
|
|
98
|
|
99
|
protected Shell shlConnect;
|
100
|
private Text txtCdmServerStatus;
|
101
|
private Text txtCdmInstanceStatus;
|
102
|
private Combo comboCdmServer;
|
103
|
private Combo comboCdmInstance;
|
104
|
private Button btnConnect;
|
105
|
|
106
|
private Composite remotingComposite;
|
107
|
private Button btnCdmServerRefresh;
|
108
|
private Button btnCdmInstanceRefresh;
|
109
|
private Button btnStopServer;
|
110
|
private Composite loginComposite;
|
111
|
private Label lblLogin;
|
112
|
private Text txtLogin;
|
113
|
private Label lblPassword;
|
114
|
private Text txtPassword;
|
115
|
private Button btnRememberMe;
|
116
|
private Label lblDefaultLogin;
|
117
|
private Composite compAdvanced;
|
118
|
private Label lblPort;
|
119
|
private Text txtPort;
|
120
|
private Label lblServerCdmlibVersion;
|
121
|
private Text txtServerCdmlibVersion;
|
122
|
private ExpandableComposite expandableCompositeAdvanced;
|
123
|
private StyledText styledTxtMessage;
|
124
|
|
125
|
private Label lblEditorCdmlibVersion;
|
126
|
private Text txtEditorCdmlibVersion;
|
127
|
private Label lblServerSchemaVersion;
|
128
|
private Text txtServerSchemaVersion;
|
129
|
private Label lblEditorCdmVersion;
|
130
|
private Text txtEditorCdmVersion;
|
131
|
|
132
|
private final int MESSAGE_HEIGHT = 50;
|
133
|
private final int COMBO_MIN_WIDTH =200;
|
134
|
private final int CONTROLS_MIN_HEIGHT = 23; //does not seem to work yet
|
135
|
// private final int MIN_EXP_HEIGHT = 380;
|
136
|
|
137
|
private boolean autoConnect = false;
|
138
|
private boolean loadLoginPrefs = true;
|
139
|
private boolean isDevRemoteSource = false;
|
140
|
|
141
|
private Job serverJob;
|
142
|
protected Object result;
|
143
|
|
144
|
private final Map<String, CdmServerInfo> serverInfoMap = new HashMap<>();
|
145
|
|
146
|
private String serverName;
|
147
|
private String instanceName;
|
148
|
private CdmServerInfo selectedServerInfo;
|
149
|
private CdmInstanceInfo selectedCdmInstance;
|
150
|
private String login;
|
151
|
private String password;
|
152
|
|
153
|
/**
|
154
|
* Create the dialog.
|
155
|
* @param parent
|
156
|
* @param style
|
157
|
*/
|
158
|
public RemotingLoginDialogLocal(Shell parent, int style) {
|
159
|
super(parent, style);
|
160
|
setText(Messages.RemotingLoginDialog_LABEL_LOGIN);
|
161
|
}
|
162
|
|
163
|
|
164
|
@Override
|
165
|
public Object open(ICdmRemoteSource source, boolean loadLoginPrefs, boolean autoConnect) {
|
166
|
this.loadLoginPrefs = loadLoginPrefs;
|
167
|
this.serverName = source.getName();
|
168
|
if (source instanceof CdmRemoteLocalhostSource){
|
169
|
this.instanceName = ((CdmRemoteLocalhostSource)source).getDatasourceName();
|
170
|
}else{
|
171
|
String contextPath = source.getContext();
|
172
|
this.instanceName = contextPath == null? "" : contextPath.substring(contextPath.lastIndexOf("/") + 1); //$NON-NLS-1$
|
173
|
}
|
174
|
return open(serverName, instanceName, loadLoginPrefs, autoConnect);
|
175
|
}
|
176
|
|
177
|
|
178
|
@Override
|
179
|
public Object open(String serverName, String instanceName, boolean loadLoginPrefs, boolean autoConnect) {
|
180
|
this.serverName = serverName;
|
181
|
this.instanceName = instanceName;
|
182
|
this.loadLoginPrefs = loadLoginPrefs;
|
183
|
this.autoConnect = autoConnect;
|
184
|
return open();
|
185
|
}
|
186
|
|
187
|
/**
|
188
|
* Open the dialog.
|
189
|
* @return the dialog result
|
190
|
*/
|
191
|
|
192
|
@Override
|
193
|
public Object open() {
|
194
|
|
195
|
createContents();
|
196
|
if(serverName == null && instanceName == null) {
|
197
|
readPrefLastServerInstance();
|
198
|
}
|
199
|
expandableCompositeAdvanced.setExpanded(false);
|
200
|
|
201
|
setEditorInfo();
|
202
|
populateCdmServerCombo();
|
203
|
shlConnect.pack(true);
|
204
|
|
205
|
setCenterPoint();
|
206
|
shlConnect.open();
|
207
|
|
208
|
Display display = getParent().getDisplay();
|
209
|
while (!shlConnect.isDisposed()) {
|
210
|
if (!display.isDisposed()){
|
211
|
if (!display.readAndDispatch()) {
|
212
|
display.sleep();
|
213
|
}
|
214
|
}
|
215
|
}
|
216
|
return result;
|
217
|
}
|
218
|
|
219
|
/**
|
220
|
* Create contents of the dialog.
|
221
|
*/
|
222
|
@Override
|
223
|
protected void createContents() {
|
224
|
shlConnect = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE | SWT.CENTER);
|
225
|
shlConnect.setText(LABEL_CONNECT);
|
226
|
shlConnect.setLayout(new FillLayout(SWT.HORIZONTAL));
|
227
|
|
228
|
remotingComposite = new Composite(shlConnect, SWT.NONE);
|
229
|
remotingComposite.setLayout(new GridLayout(1, false));
|
230
|
|
231
|
//server
|
232
|
Composite cdmServerComposite = new Composite(remotingComposite, SWT.NONE);
|
233
|
GridData gd_cdmServerComposite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
|
234
|
cdmServerComposite.setLayoutData(gd_cdmServerComposite);
|
235
|
cdmServerComposite.setLayout(new GridLayout(4, false));
|
236
|
|
237
|
Label lblCdmServer = new Label(cdmServerComposite, SWT.NONE);
|
238
|
lblCdmServer.setText(Messages.RemotingLoginDialog_LABEL_CDM_SERVER);
|
239
|
lblCdmServer.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
240
|
|
241
|
comboCdmServer = new Combo(cdmServerComposite, SWT.READ_ONLY);
|
242
|
comboCdmServer.addSelectionListener(new SelectionAdapter() {
|
243
|
@Override
|
244
|
public void widgetSelected(SelectionEvent e) {
|
245
|
onRefreshCdmServer();
|
246
|
}
|
247
|
});
|
248
|
|
249
|
GridData gd_comboCdmServer = new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1);
|
250
|
|
251
|
comboCdmServer.setLayoutData(gd_comboCdmServer);
|
252
|
comboCdmServer.select(0);
|
253
|
|
254
|
txtCdmServerStatus = new Text(cdmServerComposite, SWT.BORDER);
|
255
|
txtCdmServerStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
|
256
|
txtCdmServerStatus.setEditable(false);
|
257
|
GridData gd_txtCdmServerStatus = new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1);
|
258
|
gd_txtCdmServerStatus.minimumHeight = CONTROLS_MIN_HEIGHT;
|
259
|
txtCdmServerStatus.setLayoutData(gd_txtCdmServerStatus);
|
260
|
|
261
|
btnCdmServerRefresh = new Button(cdmServerComposite, SWT.NONE);
|
262
|
btnCdmServerRefresh.addSelectionListener(new SelectionAdapter() {
|
263
|
@Override
|
264
|
public void widgetSelected(SelectionEvent e) {
|
265
|
onRefreshCdmServer();
|
266
|
}
|
267
|
});
|
268
|
GridData gd_btnCdmServerRefresh = new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1);
|
269
|
gd_btnCdmServerRefresh.minimumHeight = CONTROLS_MIN_HEIGHT;
|
270
|
btnCdmServerRefresh.setLayoutData(gd_btnCdmServerRefresh);
|
271
|
btnCdmServerRefresh.setText(Messages.RemotingLoginDialog_LABEL_REFRESH);
|
272
|
|
273
|
//instance
|
274
|
Label lblCdmInstance = new Label(cdmServerComposite, SWT.NONE);
|
275
|
GridData gd_lblCdmInstance = new GridData(SWT.RIGHT, SWT.CENTER, false, true, 1, 1);
|
276
|
//gd_lblCdmInstance.heightHint = 30;
|
277
|
lblCdmInstance.setLayoutData(gd_lblCdmInstance);
|
278
|
lblCdmInstance.setText(Messages.RemotingLoginDialog_LABEL_CDM_INSTANCE);
|
279
|
|
280
|
comboCdmInstance = new Combo(cdmServerComposite, SWT.READ_ONLY);
|
281
|
comboCdmInstance.addSelectionListener(new SelectionAdapter() {
|
282
|
@Override
|
283
|
public void widgetSelected(SelectionEvent e) {
|
284
|
onRefreshCdmInstance();
|
285
|
}
|
286
|
});
|
287
|
|
288
|
GridData gd_comboCdmInstance = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
|
289
|
gd_comboCdmInstance.minimumWidth = COMBO_MIN_WIDTH;
|
290
|
|
291
|
comboCdmInstance.setLayoutData(gd_comboCdmInstance);
|
292
|
comboCdmInstance.select(0);
|
293
|
|
294
|
txtCdmInstanceStatus = new Text(cdmServerComposite, SWT.BORDER);
|
295
|
txtCdmInstanceStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
|
296
|
txtCdmInstanceStatus.setEditable(false);
|
297
|
GridData gd_txtCdmInstanceStatus = new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1);
|
298
|
gd_txtCdmInstanceStatus.minimumHeight = CONTROLS_MIN_HEIGHT;
|
299
|
txtCdmInstanceStatus.setLayoutData(gd_txtCdmInstanceStatus);
|
300
|
|
301
|
btnCdmInstanceRefresh = new Button(cdmServerComposite, SWT.FLAT);
|
302
|
btnCdmInstanceRefresh.addSelectionListener(new SelectionAdapter() {
|
303
|
@Override
|
304
|
public void widgetSelected(SelectionEvent e) {
|
305
|
onRefreshCdmInstance();
|
306
|
}
|
307
|
});
|
308
|
GridData gd_btnCdmInstanceRefresh = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
|
309
|
gd_btnCdmInstanceRefresh.minimumHeight = CONTROLS_MIN_HEIGHT;
|
310
|
btnCdmInstanceRefresh.setLayoutData(gd_btnCdmInstanceRefresh);
|
311
|
btnCdmInstanceRefresh.setText(Messages.RemotingLoginDialog_LABEL_REFRESH);
|
312
|
|
313
|
//login + connect
|
314
|
loginComposite = new Composite(remotingComposite, SWT.NONE);
|
315
|
GridData gd_loginComposite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
|
316
|
loginComposite.setLayoutData(gd_loginComposite);
|
317
|
GridLayout gl_loginComposite = new GridLayout(6, false);
|
318
|
gl_loginComposite.marginTop = 5;
|
319
|
loginComposite.setLayout(gl_loginComposite);
|
320
|
|
321
|
lblLogin = new Label(loginComposite, SWT.CENTER);
|
322
|
GridData gd_lblLogin = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
|
323
|
lblLogin.setLayoutData(gd_lblLogin);
|
324
|
lblLogin.setText(Messages.RemotingLoginDialog_LABEL_LOGIN_COLON);
|
325
|
|
326
|
txtLogin = new Text(loginComposite, SWT.BORDER);
|
327
|
GridData gd_txtLogin = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
|
328
|
gd_txtLogin.minimumWidth = 80;
|
329
|
txtLogin.setLayoutData(gd_txtLogin);
|
330
|
|
331
|
lblPassword = new Label(loginComposite, SWT.CENTER);
|
332
|
lblPassword.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
333
|
lblPassword.setText(Messages.RemotingLoginDialog_LABEL_PASSWORD);
|
334
|
|
335
|
txtPassword = new Text(loginComposite, SWT.BORDER | SWT.PASSWORD);
|
336
|
GridData gd_txtPassword = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
|
337
|
gd_txtPassword.minimumWidth = 80;
|
338
|
txtPassword.setLayoutData(gd_txtPassword);
|
339
|
@SuppressWarnings("unused")
|
340
|
Label nope = new Label(loginComposite, SWT.NONE);
|
341
|
txtPassword.addKeyListener(new KeyAdapter() {
|
342
|
@Override
|
343
|
public void keyPressed(KeyEvent e) {
|
344
|
if(e.character==SWT.CR){
|
345
|
if(btnConnect.getText().equals(LABEL_CONNECT)){
|
346
|
onConnectButtonPressed();
|
347
|
}
|
348
|
}
|
349
|
}
|
350
|
});
|
351
|
|
352
|
btnConnect = new Button(loginComposite, SWT.FLAT);
|
353
|
btnConnect.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
|
354
|
btnConnect.addSelectionListener(new SelectionAdapter() {
|
355
|
@Override
|
356
|
public void widgetSelected(SelectionEvent e) {
|
357
|
onConnectButtonPressed();
|
358
|
}
|
359
|
});
|
360
|
btnConnect.setText(LABEL_CONNECT);
|
361
|
|
362
|
//rememberMe + default values
|
363
|
btnRememberMe = new Button(loginComposite, SWT.CHECK);
|
364
|
btnRememberMe.setSelection(true);
|
365
|
GridData gd_btnRememberMe = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);
|
366
|
btnRememberMe.setLayoutData(gd_btnRememberMe);
|
367
|
btnRememberMe.setText(Messages.RemotingLoginDialog_LABEL_REMEMBER_ME);
|
368
|
|
369
|
lblDefaultLogin = new Label(loginComposite, SWT.NONE);
|
370
|
GridDataFactory.fillDefaults().span(4, 1).align(SWT.TRAIL, SWT.CENTER).applyTo(lblDefaultLogin);
|
371
|
lblDefaultLogin.setText(String.format(Messages.RemotingLoginDialog_DEFAULT_LOGIN, DEFAULT_USER, DEFAULT_PASS));
|
372
|
lblDefaultLogin.setVisible(false);
|
373
|
|
374
|
styledTxtMessage = new StyledText(remotingComposite, SWT.NONE);
|
375
|
styledTxtMessage.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
|
376
|
styledTxtMessage.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));
|
377
|
styledTxtMessage.setSelectionBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_SELECTION_TEXT));
|
378
|
styledTxtMessage.setSelectionForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));
|
379
|
styledTxtMessage.setDoubleClickEnabled(false);
|
380
|
styledTxtMessage.setEditable(false);
|
381
|
styledTxtMessage.setWordWrap(true);
|
382
|
|
383
|
GridData gd_styledTxtMessage = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
|
384
|
gd_styledTxtMessage.exclude = true;
|
385
|
gd_styledTxtMessage.minimumHeight = MESSAGE_HEIGHT;
|
386
|
|
387
|
styledTxtMessage.setLayoutData(gd_styledTxtMessage);
|
388
|
|
389
|
//Advanced
|
390
|
expandableCompositeAdvanced = new ExpandableComposite(remotingComposite, SWT.NONE, ExpandableComposite.TWISTIE);
|
391
|
GridData gd_xpndblcmpstAdvanced = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
|
392
|
expandableCompositeAdvanced.setLayoutData(gd_xpndblcmpstAdvanced);
|
393
|
expandableCompositeAdvanced.addExpansionListener(new IExpansionListener() {
|
394
|
@Override
|
395
|
public void expansionStateChanged(ExpansionEvent e) {
|
396
|
shlConnect.pack(true);
|
397
|
}
|
398
|
@Override
|
399
|
public void expansionStateChanging(ExpansionEvent e) {
|
400
|
}
|
401
|
});
|
402
|
expandableCompositeAdvanced.setText(Messages.RemotingLoginDialog_LABEL_ADVANCED);
|
403
|
expandableCompositeAdvanced.setExpanded(true);
|
404
|
|
405
|
compAdvanced = new Composite(expandableCompositeAdvanced, SWT.NONE);
|
406
|
expandableCompositeAdvanced.setClient(compAdvanced);
|
407
|
compAdvanced.setLayout(new GridLayout(4, false));
|
408
|
|
409
|
lblPort = new Label(compAdvanced, SWT.CENTER);
|
410
|
lblPort.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
411
|
lblPort.setText(Messages.RemotingLoginDialog_LABEL_PORT);
|
412
|
|
413
|
txtPort = new Text(compAdvanced, SWT.BORDER);
|
414
|
GridData gd_txtPort = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
|
415
|
gd_txtPort.minimumWidth = 50;
|
416
|
txtPort.setLayoutData(gd_txtPort);
|
417
|
|
418
|
lblServerCdmlibVersion = new Label(compAdvanced, SWT.CENTER);
|
419
|
lblServerCdmlibVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
420
|
lblServerCdmlibVersion.setText(Messages.RemotingLoginDialog_LABEL_SERVER_CDMLIB_VERSION);
|
421
|
|
422
|
txtServerCdmlibVersion = new Text(compAdvanced, SWT.BORDER);
|
423
|
txtServerCdmlibVersion.setEditable(false);
|
424
|
txtServerCdmlibVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
|
425
|
|
426
|
btnStopServer = new Button(compAdvanced, SWT.FLAT);
|
427
|
btnStopServer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
|
428
|
btnStopServer.addMouseListener(new MouseAdapter() {
|
429
|
@Override
|
430
|
public void mouseUp(MouseEvent e) {
|
431
|
onStopManagedServer();
|
432
|
}
|
433
|
});
|
434
|
btnStopServer.setText(Messages.RemotingLoginDialog_LABEL_STOP_MANAGED_SERVER);
|
435
|
|
436
|
lblEditorCdmlibVersion = new Label(compAdvanced, SWT.CENTER);
|
437
|
lblEditorCdmlibVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
438
|
lblEditorCdmlibVersion.setText(Messages.RemotingLoginDialog_LABEL_EDITOR_CDMLIB_VERSION);
|
439
|
|
440
|
txtEditorCdmlibVersion = new Text(compAdvanced, SWT.BORDER);
|
441
|
txtEditorCdmlibVersion.setEditable(false);
|
442
|
txtEditorCdmlibVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
443
|
addEmptyCells(2);
|
444
|
|
445
|
lblServerSchemaVersion = new Label(compAdvanced, SWT.CENTER);
|
446
|
lblServerSchemaVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
447
|
lblServerSchemaVersion.setText(Messages.RemotingLoginDialog_LABEL_SERVER_CDM_VERSION);
|
448
|
|
449
|
txtServerSchemaVersion = new Text(compAdvanced, SWT.BORDER);
|
450
|
txtServerSchemaVersion.setEditable(false);
|
451
|
txtServerSchemaVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
452
|
addEmptyCells(2);
|
453
|
|
454
|
lblEditorCdmVersion = new Label(compAdvanced, SWT.CENTER);
|
455
|
lblEditorCdmVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
456
|
lblEditorCdmVersion.setText(Messages.RemotingLoginDialog_LABEL_EDITOR_CDM_VERSION);
|
457
|
|
458
|
txtEditorCdmVersion = new Text(compAdvanced, SWT.BORDER);
|
459
|
txtEditorCdmVersion.setEditable(false);
|
460
|
txtEditorCdmVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
461
|
}
|
462
|
|
463
|
|
464
|
@Override
|
465
|
public void setCenterPoint() {
|
466
|
Rectangle parentSize = getParent().getBounds();
|
467
|
Rectangle shellSize = shlConnect.getBounds();
|
468
|
int locationX = (parentSize.width - shellSize.width)/2+parentSize.x;
|
469
|
int locationY = (parentSize.height - shellSize.height)/2+parentSize.y;
|
470
|
shlConnect.setLocation(new Point(locationX, locationY));
|
471
|
|
472
|
}
|
473
|
|
474
|
|
475
|
|
476
|
|
477
|
|
478
|
|
479
|
@SuppressWarnings("unused")
|
480
|
private void addEmptyCells(int cnt) {
|
481
|
for (int i = 0; i < cnt; i++) {
|
482
|
new Label(compAdvanced, SWT.NONE);
|
483
|
}
|
484
|
}
|
485
|
|
486
|
@Override
|
487
|
protected void onConnectButtonPressed() {
|
488
|
if(selectedServerInfo.isLocalhostMgd() && !isSelectedCdmInstanceRunningInManagedServer()) {
|
489
|
startManagedServer();
|
490
|
} else {
|
491
|
connect();
|
492
|
if (CdmStore.isActive() && CdmStore.currentAuthentiationHasOneOfRoles(Role.ROLE_REMOTING)){
|
493
|
PreferencesUtil.setNomenclaturalCodePreferences();
|
494
|
}
|
495
|
}
|
496
|
}
|
497
|
|
498
|
private void populateCdmServerCombo() {
|
499
|
Job job = new Job(Messages.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES) {
|
500
|
@Override
|
501
|
protected IStatus run(IProgressMonitor monitor) {
|
502
|
Display.getDefault().syncExec(new Runnable() {
|
503
|
@Override
|
504
|
public void run() {
|
505
|
//TODO performance
|
506
|
for(CdmServerInfo csii : CdmServerInfoLocal.getCdmServers()) {
|
507
|
serverInfoMap.put(csii.getName(), csii);
|
508
|
comboCdmServer.add(csii.getName());
|
509
|
}
|
510
|
int serverIndex = -1;
|
511
|
if(serverName != null) {
|
512
|
serverIndex = comboCdmServer.indexOf(serverName);
|
513
|
}
|
514
|
if(serverIndex == -1) {
|
515
|
comboCdmServer.select(0);
|
516
|
autoConnect = false;
|
517
|
} else {
|
518
|
comboCdmServer.select(serverIndex);
|
519
|
}
|
520
|
ICdmSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
|
521
|
if(devRemoteSource != null) {
|
522
|
isDevRemoteSource = true;
|
523
|
String username = System.getProperty("cdm.server.dev.username"); //$NON-NLS-1$
|
524
|
String password = System.getProperty("cdm.server.dev.password"); //$NON-NLS-1$
|
525
|
if(username != null && !username.isEmpty() && password != null && !password.isEmpty()) {
|
526
|
txtLogin.setText(username);
|
527
|
txtPassword.setText(password);
|
528
|
CdmStoreLocal.connect(devRemoteSource, RemotingLoginDialogLocal.this);
|
529
|
}
|
530
|
} else {
|
531
|
onRefreshCdmServer();
|
532
|
}
|
533
|
}
|
534
|
});
|
535
|
return Status.OK_STATUS;
|
536
|
}
|
537
|
};
|
538
|
job.schedule();
|
539
|
}
|
540
|
|
541
|
@Override
|
542
|
public void onRefreshCdmServer() {
|
543
|
try{
|
544
|
txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
|
545
|
clearOnServerChange();
|
546
|
emptyCredentials();
|
547
|
updateSelectedCdmServer();
|
548
|
Display.getDefault().asyncExec(new Runnable() {
|
549
|
@Override
|
550
|
public void run() {
|
551
|
checkSelectedCdmServer();
|
552
|
}
|
553
|
});
|
554
|
}
|
555
|
catch(SWTException e){
|
556
|
//catch widget is disposed exception which may occur if
|
557
|
//dialog is closed but the runnable tries to update
|
558
|
}
|
559
|
}
|
560
|
|
561
|
@Override
|
562
|
protected void updateSelectedCdmServer() {
|
563
|
int selIndex = comboCdmServer.getSelectionIndex();
|
564
|
if(selIndex != -1) {
|
565
|
selectedServerInfo = serverInfoMap.get(comboCdmServer.getItem(selIndex));
|
566
|
}
|
567
|
}
|
568
|
|
569
|
@Override
|
570
|
protected void updatePort() {
|
571
|
txtPort.setText(""); //$NON-NLS-1$
|
572
|
if(selectedServerInfo != null) {
|
573
|
int port = selectedServerInfo.getPort();
|
574
|
if(port == CdmServerInfo.NULL_PORT) {
|
575
|
txtPort.setText(CdmServerInfo.NULL_PORT_STRING);
|
576
|
} else {
|
577
|
txtPort.setText(String.valueOf(port));
|
578
|
}
|
579
|
}
|
580
|
}
|
581
|
|
582
|
@Override
|
583
|
private int getPort() {
|
584
|
int port = CdmServerInfo.NULL_PORT;
|
585
|
try {
|
586
|
port = Integer.valueOf(txtPort.getText());
|
587
|
} catch (NumberFormatException nfe) {
|
588
|
if(!CdmServerInfo.NULL_PORT_STRING.equals(txtPort.getText())) {
|
589
|
setMessage(Messages.RemotingLoginDialog_MESSAGE_PORT_SHOULD_BE_INTEGER);
|
590
|
}
|
591
|
}
|
592
|
return port;
|
593
|
}
|
594
|
|
595
|
private void checkSelectedCdmServer() {
|
596
|
try{
|
597
|
if(selectedServerInfo != null) {
|
598
|
if(selectedServerInfo.isLocalhost()) {
|
599
|
txtPort.setEditable(true);
|
600
|
txtPort.setEnabled(true);
|
601
|
}
|
602
|
try {
|
603
|
if(selectedServerInfo.pingServer()) {
|
604
|
txtCdmServerStatus.setText(STATUS_AVAILABLE);
|
605
|
populateCdmInstanceCombo(true);
|
606
|
if(selectedServerInfo.isLocalhost()){
|
607
|
setCdmlibVersion(txtServerCdmlibVersion);
|
608
|
}else{
|
609
|
String serverVersionTimestamp = generateLastModifiedTooltip(selectedServerInfo.getCdmlibLastModified());
|
610
|
txtServerCdmlibVersion.setText(selectedServerInfo.getCdmlibServicesVersion() + ":" + serverVersionTimestamp); //$NON-NLS-1$
|
611
|
}
|
612
|
} else {
|
613
|
txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
|
614
|
comboCdmInstance.removeAll();
|
615
|
disableCdmInstanceControls("", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
616
|
}
|
617
|
} catch (CdmServerException | IOException e) {
|
618
|
txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
|
619
|
// TODO distinguish java.net.ConnectException: Connection refused, java.net.SocketTimeoutException: Read timed out
|
620
|
Throwable cause = e;
|
621
|
if(e instanceof CdmServerException && e.getCause() != null){
|
622
|
cause = e.getCause();
|
623
|
}
|
624
|
String message = Messages.RemotingLoginDialog_CONNECTION_FAILED_MESSAGE;
|
625
|
if(cause instanceof SocketTimeoutException){
|
626
|
message = Messages.RemotingLoginDialog_CONNECTION_TIMEOUT_MESSAGE;
|
627
|
}
|
628
|
MessagingUtils.warningDialog(Messages.RemotingLoginDialog_CONNECTION_FAILED_TITLE, this,
|
629
|
message);
|
630
|
logger.warn(Messages.RemotingLoginDialog_CONNECTION_FAILED_TITLE, e);
|
631
|
}
|
632
|
}
|
633
|
updatePort();
|
634
|
}
|
635
|
catch(SWTException e){
|
636
|
//catch widget is disposed exception which may occur if
|
637
|
//dialog is closed but the runnable tries to update
|
638
|
}
|
639
|
}
|
640
|
|
641
|
@Override
|
642
|
private void populateCdmInstanceCombo(final boolean forceRefresh) {
|
643
|
comboCdmInstance.removeAll();
|
644
|
comboCdmInstance.setEnabled(false);
|
645
|
btnConnect.setEnabled(false);
|
646
|
txtCdmInstanceStatus.setText(STATUS_RETRIEVING);
|
647
|
txtCdmInstanceStatus.setToolTipText(""); //$NON-NLS-1$
|
648
|
|
649
|
serverJob = new Job(Messages.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES) {
|
650
|
@Override
|
651
|
protected IStatus run(IProgressMonitor monitor) {
|
652
|
try {
|
653
|
if(selectedServerInfo != null) {
|
654
|
if(forceRefresh) {
|
655
|
selectedServerInfo.refreshInstances();
|
656
|
}
|
657
|
final List<CdmInstanceInfo> instances = selectedServerInfo.getInstances();
|
658
|
Display.getDefault().asyncExec(new Runnable() {
|
659
|
@Override
|
660
|
public void run() {
|
661
|
if(!instances.isEmpty()) {
|
662
|
for(CdmInstanceInfo cdmInstance : instances) {
|
663
|
comboCdmInstance.add(cdmInstance.getName());
|
664
|
}
|
665
|
int instanceIndex = -1;
|
666
|
if(instanceName != null) {
|
667
|
instanceIndex = comboCdmInstance.indexOf(instanceName);
|
668
|
}
|
669
|
if(instanceIndex == -1) {
|
670
|
comboCdmInstance.select(0);
|
671
|
autoConnect = false;
|
672
|
} else {
|
673
|
comboCdmInstance.select(instanceIndex);
|
674
|
}
|
675
|
onRefreshCdmInstance();
|
676
|
comboCdmInstance.setEnabled(true);
|
677
|
if(autoConnect) {
|
678
|
connect();
|
679
|
}
|
680
|
} else {
|
681
|
txtCdmInstanceStatus.setText(STATUS_NO_INSTANCES);
|
682
|
btnConnect.setEnabled(false);
|
683
|
}
|
684
|
}
|
685
|
});
|
686
|
}
|
687
|
} catch (final CdmServerException e) {
|
688
|
MessagingUtils.warn(getClass(), e);
|
689
|
Display.getDefault().asyncExec(new Runnable() {
|
690
|
@Override
|
691
|
public void run() {
|
692
|
disableCdmInstanceControls(STATUS_NOT_AVAILABLE, e.getMessage());
|
693
|
}
|
694
|
});
|
695
|
}
|
696
|
return Status.OK_STATUS;
|
697
|
}
|
698
|
};
|
699
|
|
700
|
if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE) && !isDevRemoteSource) {
|
701
|
// Start the Job
|
702
|
serverJob.schedule();
|
703
|
}
|
704
|
}
|
705
|
|
706
|
@Override
|
707
|
public void disableCdmInstanceControls(String cdmInstanceStatus, String tooltip) {
|
708
|
txtCdmInstanceStatus.setText(cdmInstanceStatus);
|
709
|
txtCdmInstanceStatus.setToolTipText(tooltip);
|
710
|
comboCdmInstance.setEnabled(false);
|
711
|
btnConnect.setEnabled(false);
|
712
|
}
|
713
|
|
714
|
@Override
|
715
|
public void onRefreshCdmInstance() {
|
716
|
txtCdmInstanceStatus.setText(STATUS_CHECKING_AVAILABILITY);
|
717
|
clearOnInstanceChange();
|
718
|
updateSelectedCdmInstance();
|
719
|
checkSelectedCdmInstance();
|
720
|
updateManagedServerControls();
|
721
|
}
|
722
|
|
723
|
@Override
|
724
|
protected void updateSelectedCdmInstance() {
|
725
|
int selIndex = comboCdmInstance.getSelectionIndex();
|
726
|
if(selIndex != -1) {
|
727
|
selectedCdmInstance = selectedServerInfo.getInstanceFromName(comboCdmInstance.getItem(selIndex));
|
728
|
if(loadLoginPrefs) {
|
729
|
readPrefCredentials();
|
730
|
}
|
731
|
}
|
732
|
}
|
733
|
|
734
|
private void updateManagedServerControls() {
|
735
|
if(selectedServerInfo.isLocalhostMgd()) {
|
736
|
if(isSelectedCdmInstanceRunningInManagedServer()) {
|
737
|
txtCdmInstanceStatus.setText(STATUS_STARTED);
|
738
|
} else {
|
739
|
txtCdmInstanceStatus.setText(STATUS_NOT_STARTED);
|
740
|
}
|
741
|
btnConnect.setEnabled(true);
|
742
|
selectedServerInfo.setPort(getManagedServerPort());
|
743
|
updatePort();
|
744
|
}
|
745
|
|
746
|
if(isManagedServerRunning()) {
|
747
|
btnStopServer.setEnabled(true);
|
748
|
} else {
|
749
|
btnStopServer.setEnabled(false);
|
750
|
}
|
751
|
}
|
752
|
|
753
|
private boolean isManagedServerRunning() {
|
754
|
return CdmStoreLocal.getManagedServer() != null && CdmStoreLocal.getManagedServer().isAlive();
|
755
|
}
|
756
|
|
757
|
private boolean isSelectedCdmInstanceRunningInManagedServer() {
|
758
|
return CdmStoreLocal.getManagedServer() != null &&
|
759
|
CdmStoreLocal.getManagedServer().isAlive() &&
|
760
|
selectedServerInfo.isLocalhostMgd() &&
|
761
|
CdmStoreLocal.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName());
|
762
|
}
|
763
|
|
764
|
private void startManagedServer() {
|
765
|
if(isManagedServerRunning()) {
|
766
|
if(CdmStoreLocal.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName())) {
|
767
|
return;
|
768
|
} else {
|
769
|
Display.getDefault().syncExec(new Runnable() {
|
770
|
@Override
|
771
|
public void run() {
|
772
|
onStopManagedServer();
|
773
|
}
|
774
|
});
|
775
|
}
|
776
|
}
|
777
|
|
778
|
boolean forceSchemaCreate = !schemaExists(selectedCdmInstance);
|
779
|
boolean forceSchemaUpdate = LABEL_UPDATE_SCHEMA_VERSION.equals(btnConnect.getText());
|
780
|
|
781
|
Job job = new Job(Messages.RemotingLoginDialog_JOB_SERVER_LAUNCH) {
|
782
|
|
783
|
@Override
|
784
|
public IStatus run(IProgressMonitor monitor) {
|
785
|
String mgdServerConfigFileName = "mgd.datasources.xml"; //$NON-NLS-1$
|
786
|
String config = CdmServerUtils.convertEditorToServerConfig();
|
787
|
int maxUnits = 50;
|
788
|
monitor.beginTask(Messages.RemotingLoginDialog_TASK_LAUNCHING_SERVER, maxUnits);
|
789
|
try {
|
790
|
monitor.subTask(String.format(Messages.RemotingLoginDialog_GENERATING_CONFIG_FILE, selectedCdmInstance.getName()));
|
791
|
File managedServerConfigFile = CdmServerUtils.writeManagedServerConfig(config, mgdServerConfigFileName);
|
792
|
monitor.worked(1);
|
793
|
|
794
|
Class ref = Class.forName("CdmServer");
|
795
|
CdmServer cdmServer = new CdmServer(selectedCdmInstance.getName(), managedServerConfigFile);
|
796
|
|
797
|
// ICdmServer cdmServer = new CdmServer(selectedCdmInstance.getName(), managedServerConfigFile);
|
798
|
cdmServer.setForceSchemaCreate(forceSchemaCreate);
|
799
|
cdmServer.setForceSchemaUpdate(forceSchemaUpdate);
|
800
|
CdmStoreLocal.setManagedServer(cdmServer);
|
801
|
monitor.subTask(Messages.RemotingLoginDialog_STARTING_MGD_SERVER);
|
802
|
cdmServer.start(false, RemotingLoginDialogLocal.this);
|
803
|
int serverUnits = 0;
|
804
|
|
805
|
// the following loop is a 'fake' progress monitoring where the progress
|
806
|
// bar is advanced by one unit every second until maxUnits -2
|
807
|
while(!CdmStore.getManagedServer().isStarted() && !CdmStore.getManagedServer().isFailed()) {
|
808
|
if(serverUnits < maxUnits - 2) {
|
809
|
try {
|
810
|
Thread.sleep(1000);
|
811
|
} catch (InterruptedException e) {
|
812
|
}
|
813
|
monitor.worked(1);
|
814
|
serverUnits++;
|
815
|
}
|
816
|
}
|
817
|
Display.getDefault().syncExec(()->{
|
818
|
hide(false);
|
819
|
updateManagedServerControls();
|
820
|
connect();
|
821
|
});
|
822
|
} catch (IOException ioe) {
|
823
|
MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_GENERATING_CONFIG_FILE,
|
824
|
this,
|
825
|
ioe.getMessage(),
|
826
|
TaxeditorStorePlugin.PLUGIN_ID,
|
827
|
ioe,
|
828
|
true);
|
829
|
} catch (CdmEmbeddedServerException cese) {
|
830
|
MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_STARTING_SERVER,
|
831
|
this,
|
832
|
cese.getMessage(),
|
833
|
TaxeditorStorePlugin.PLUGIN_ID,
|
834
|
cese,
|
835
|
true);
|
836
|
} catch (ClassNotFoundException e1) {
|
837
|
MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_STARTING_SERVER,
|
838
|
this,
|
839
|
e1.getMessage(),
|
840
|
TaxeditorStorePlugin.PLUGIN_ID,
|
841
|
e1,
|
842
|
true);
|
843
|
} catch (InstantiationException e1) {
|
844
|
MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_STARTING_SERVER,
|
845
|
this,
|
846
|
e1.getMessage(),
|
847
|
TaxeditorStorePlugin.PLUGIN_ID,
|
848
|
e1,
|
849
|
true);
|
850
|
} catch (IllegalAccessException e1) {
|
851
|
MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_STARTING_SERVER,
|
852
|
this,
|
853
|
e1.getMessage(),
|
854
|
TaxeditorStorePlugin.PLUGIN_ID,
|
855
|
e1,
|
856
|
true);
|
857
|
} finally {
|
858
|
monitor.done();
|
859
|
}
|
860
|
// NOTE: Errors thrown during server startup are passed to the handleError() implementation
|
861
|
// TODO: is the above catch clause for CdmEmbeddedServerException still valuable?
|
862
|
|
863
|
return Status.OK_STATUS;
|
864
|
}
|
865
|
};
|
866
|
|
867
|
// configure the job
|
868
|
job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
|
869
|
job.setUser(true);
|
870
|
// schedule job
|
871
|
hide(true);
|
872
|
job.schedule();
|
873
|
}
|
874
|
|
875
|
private boolean schemaExists(CdmInstanceInfo instanceInfo) {
|
876
|
if (instanceInfo.getDataSource() != null){
|
877
|
try {
|
878
|
//TODO we need a new method in cdmlib to check for existing schema
|
879
|
String schemaVersion = instanceInfo.getDataSource().getDbSchemaVersion();
|
880
|
return schemaVersion != null;
|
881
|
} catch (CdmSourceException e) {
|
882
|
return false;
|
883
|
}
|
884
|
}else{
|
885
|
return true;
|
886
|
}
|
887
|
}
|
888
|
|
889
|
private String managedSchemaVersion(CdmInstanceInfo instanceInfo) throws CdmSourceException{
|
890
|
if (instanceInfo.getDataSource() != null){
|
891
|
return instanceInfo.getDataSource().getDbSchemaVersion();
|
892
|
}else{
|
893
|
throw new RuntimeException("ManagedSchemaVersion only available for managed server instances.");
|
894
|
}
|
895
|
}
|
896
|
private int compareSchemaVersion(CdmInstanceInfo instanceInfo) throws CdmSourceException {
|
897
|
return CdmMetaData.compareVersion(managedSchemaVersion(instanceInfo), CdmMetaData.getDbSchemaVersion(), 3, null);
|
898
|
}
|
899
|
|
900
|
|
901
|
@Override
|
902
|
public void handleError(final Throwable t) {
|
903
|
|
904
|
Display.getDefault().syncExec(()-> {
|
905
|
serverJob.cancel();
|
906
|
|
907
|
String title = Messages.RemotingLoginDialog_SERVER_LAUNCH_ERROR;
|
908
|
String message = t.getMessage();
|
909
|
|
910
|
MessagingUtils.errorDialog(title,
|
911
|
this,
|
912
|
message,
|
913
|
TaxeditorStorePlugin.PLUGIN_ID,
|
914
|
t,
|
915
|
true);
|
916
|
});
|
917
|
}
|
918
|
|
919
|
private void onStopManagedServer() {
|
920
|
try {
|
921
|
CdmStoreLocal.getManagedServer().stop();
|
922
|
} catch (Exception e) {
|
923
|
MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_STOPPING_SERVER,
|
924
|
this,
|
925
|
String.format(Messages.RemotingLoginDialog_COULD_NOT_STOP_SERVER, CdmStoreLocal.getManagedServer().getPort()),
|
926
|
TaxeditorStorePlugin.PLUGIN_ID,
|
927
|
e,
|
928
|
true);
|
929
|
}
|
930
|
CdmStoreLocal.setManagedServer(null);
|
931
|
updateManagedServerControls();
|
932
|
}
|
933
|
|
934
|
private int getManagedServerPort() {
|
935
|
return CdmStoreLocal.getManagedServer() == null ? CdmServerInfo.NULL_PORT : CdmStoreLocal.getManagedServer().getPort();
|
936
|
}
|
937
|
|
938
|
@Override
|
939
|
protected void checkSelectedCdmInstance() {
|
940
|
|
941
|
if (selectedServerInfo.isLocalhostMgd()){
|
942
|
checkManagedSelectedInstance();
|
943
|
}else if (txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
|
944
|
|
945
|
boolean available = false;
|
946
|
String instanceStatus = STATUS_NOT_AVAILABLE;
|
947
|
String message = null;
|
948
|
try {
|
949
|
if(selectedServerInfo.pingInstance(selectedCdmInstance, getPort())) {
|
950
|
instanceStatus = STATUS_AVAILABLE;
|
951
|
available = true;
|
952
|
} else {
|
953
|
instanceStatus = STATUS_NOT_AVAILABLE;
|
954
|
available = false;
|
955
|
}
|
956
|
|
957
|
if(available) {
|
958
|
txtServerSchemaVersion.setText(selectedServerInfo.getCdmRemoteSource(selectedCdmInstance, getPort()).getDbSchemaVersion());
|
959
|
|
960
|
int compareDbSchemaVersion = selectedServerInfo.compareDbSchemaVersion(selectedCdmInstance, getPort());
|
961
|
|
962
|
int compareCdmlibServicesVersion = 0;
|
963
|
boolean disableServicesApiTimestampCheck =
|
964
|
PreferencesUtil.getBooleanValue((IPreferenceKeys.DISABLE_SERVICES_API_TIMESTAMP_CHECK));
|
965
|
if(!disableServicesApiTimestampCheck) {
|
966
|
compareCdmlibServicesVersion = selectedServerInfo.compareCdmlibServicesVersion();
|
967
|
}
|
968
|
|
969
|
if(compareDbSchemaVersion > 0 || compareCdmlibServicesVersion > 0) {
|
970
|
instanceStatus = STATUS_NOT_COMPATIBLE;
|
971
|
available = false;
|
972
|
message = MESG_COMPATIBLE_EDITOR_OLD;
|
973
|
} else if(compareDbSchemaVersion < 0 || compareCdmlibServicesVersion < 0) {
|
974
|
instanceStatus = STATUS_NOT_COMPATIBLE;
|
975
|
available = false;
|
976
|
message = MESG_COMPATIBLE_SERVER_OLD;
|
977
|
} else {
|
978
|
instanceStatus = STATUS_AVAILABLE;
|
979
|
available = true;
|
980
|
message = ""; //$NON-NLS-1$
|
981
|
}
|
982
|
}
|
983
|
} catch (Exception e) {
|
984
|
txtCdmInstanceStatus.setToolTipText(e.getMessage());
|
985
|
} finally {
|
986
|
lblDefaultLogin.setVisible(false);
|
987
|
btnConnect.setEnabled(available);
|
988
|
txtCdmInstanceStatus.setText(instanceStatus);
|
989
|
if(!StringUtils.isBlank(message)) {
|
990
|
setMessage(message);
|
991
|
}
|
992
|
}
|
993
|
}
|
994
|
}
|
995
|
|
996
|
private void checkManagedSelectedInstance() {
|
997
|
boolean available = false;
|
998
|
String instanceStatus = STATUS_NOT_AVAILABLE;
|
999
|
String message = null;
|
1000
|
String connect = LABEL_CONNECT;
|
1001
|
Integer color = null;
|
1002
|
String schemaVersion = CdmMetaData.getDbSchemaVersion();
|
1003
|
|
1004
|
if (!schemaExists(selectedCdmInstance)){
|
1005
|
message = MESG_SCHEMA_MISSING;
|
1006
|
connect = LABEL_CREATE_SCHEMA;
|
1007
|
color = BTN_COLOR_ATTENTION;
|
1008
|
schemaVersion = MESG_NO_SCHEMA;
|
1009
|
} else {
|
1010
|
int compare;
|
1011
|
try {
|
1012
|
schemaVersion = managedSchemaVersion(selectedCdmInstance);
|
1013
|
compare = compareSchemaVersion(selectedCdmInstance);
|
1014
|
if (compare > 0){
|
1015
|
instanceStatus = STATUS_NOT_COMPATIBLE;
|
1016
|
message = MESG_COMPATIBLE_EDITOR_OLD;
|
1017
|
available = false;
|
1018
|
}else if (compare < 0){
|
1019
|
instanceStatus = STATUS_NOT_COMPATIBLE;
|
1020
|
message = MESG_UPDATE_SCHEMA_VERSION;
|
1021
|
available = true;
|
1022
|
connect = LABEL_UPDATE_SCHEMA_VERSION;
|
1023
|
color = BTN_COLOR_ATTENTION;
|
1024
|
}else{
|
1025
|
available = true;
|
1026
|
instanceStatus = STATUS_AVAILABLE;
|
1027
|
}
|
1028
|
} catch (CdmSourceException e) {
|
1029
|
available = false;
|
1030
|
}
|
1031
|
}
|
1032
|
|
1033
|
setManagedValues(available, instanceStatus, connect, color, schemaVersion);
|
1034
|
setMessage(message);
|
1035
|
}
|
1036
|
|
1037
|
private void setManagedValues(boolean available, String instanceStatus, String connect, Integer color,
|
1038
|
String schemaVersion) {
|
1039
|
Display.getDefault().syncExec(()->{
|
1040
|
btnConnect.setEnabled(available);
|
1041
|
btnConnect.setText(connect);
|
1042
|
Color systemColor = null;
|
1043
|
if(color != null) {
|
1044
|
systemColor = Display.getCurrent().getSystemColor(color);
|
1045
|
}
|
1046
|
btnConnect.setBackground(systemColor);
|
1047
|
btnConnect.requestLayout();
|
1048
|
txtCdmInstanceStatus.setText(instanceStatus);
|
1049
|
txtServerSchemaVersion.setText(schemaVersion);
|
1050
|
lblDefaultLogin.setVisible(true);
|
1051
|
});
|
1052
|
}
|
1053
|
|
1054
|
@Override
|
1055
|
private void connect() {
|
1056
|
checkSelectedCdmInstance();
|
1057
|
|
1058
|
if(!txtCdmInstanceStatus.getText().equals(STATUS_AVAILABLE)) {
|
1059
|
return;
|
1060
|
}
|
1061
|
|
1062
|
ICdmRemoteSource source = selectedServerInfo.getCdmRemoteSource(selectedCdmInstance, getPort());
|
1063
|
|
1064
|
if(!validateLogin(source)) {
|
1065
|
return;
|
1066
|
}
|
1067
|
|
1068
|
try {
|
1069
|
CdmStoreLocal.connect(source, RemotingLoginDialogLocal.this);
|
1070
|
} catch (Exception e) {
|
1071
|
// Do not expect anything to go wrong at this point, so we throw a runtime exception
|
1072
|
// if any problems
|
1073
|
throw new RuntimeException(e);
|
1074
|
}
|
1075
|
}
|
1076
|
|
1077
|
|
1078
|
@Override
|
1079
|
public boolean isRememberMe() {
|
1080
|
return btnRememberMe.getSelection();
|
1081
|
}
|
1082
|
|
1083
|
private void persistPrefLastServerInstance() {
|
1084
|
IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
|
1085
|
Preferences lastServerInstancePrefs = preferences.node(LAST_SERVER_INSTANCE_NODE);
|
1086
|
|
1087
|
lastServerInstancePrefs.put(LAST_SERVER_KEY, selectedServerInfo.getName());
|
1088
|
lastServerInstancePrefs.put(LAST_INSTANCE_KEY, selectedCdmInstance.getName());
|
1089
|
|
1090
|
flushPreferences(lastServerInstancePrefs);
|
1091
|
}
|
1092
|
|
1093
|
private void persistPrefCredentials() {
|
1094
|
IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
|
1095
|
Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
|
1096
|
credentialsPrefs.put(getUsernamePrefKey(), txtLogin.getText());
|
1097
|
credentialsPrefs.put(getPasswordPrefKey(), txtPassword.getText());
|
1098
|
flushPreferences(credentialsPrefs);
|
1099
|
}
|
1100
|
|
1101
|
private void removePrefCredentials() {
|
1102
|
IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
|
1103
|
Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
|
1104
|
credentialsPrefs.put(getUsernamePrefKey(), txtLogin.getText());
|
1105
|
credentialsPrefs.put(getPasswordPrefKey(), txtPassword.getText());
|
1106
|
removePreferences(credentialsPrefs);
|
1107
|
}
|
1108
|
|
1109
|
private void removePreferences(Preferences prefs) {
|
1110
|
try {
|
1111
|
prefs.removeNode();
|
1112
|
} catch (BackingStoreException bse) {
|
1113
|
setMessage(bse.getMessage());
|
1114
|
}
|
1115
|
}
|
1116
|
|
1117
|
private void flushPreferences(Preferences prefs) {
|
1118
|
try {
|
1119
|
prefs.flush();
|
1120
|
} catch (BackingStoreException bse) {
|
1121
|
setMessage(bse.getMessage());
|
1122
|
}
|
1123
|
}
|
1124
|
|
1125
|
@Override
|
1126
|
private void readPrefCredentials() {
|
1127
|
String username, password;
|
1128
|
IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
|
1129
|
Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
|
1130
|
username = credentialsPrefs.get(getUsernamePrefKey(), ""); //$NON-NLS-1$
|
1131
|
txtLogin.setText(username);
|
1132
|
password = credentialsPrefs.get(getPasswordPrefKey(),""); //$NON-NLS-1$
|
1133
|
txtPassword.setText(password);
|
1134
|
if(username.isEmpty() || password.isEmpty()) {
|
1135
|
autoConnect = false;
|
1136
|
}
|
1137
|
}
|
1138
|
|
1139
|
private void readPrefLastServerInstance() {
|
1140
|
IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
|
1141
|
Preferences lastServerInstancePrefs = preferences.node(LAST_SERVER_INSTANCE_NODE);
|
1142
|
|
1143
|
serverName = lastServerInstancePrefs.get(LAST_SERVER_KEY, null);
|
1144
|
instanceName = lastServerInstancePrefs.get(LAST_INSTANCE_KEY, null);
|
1145
|
}
|
1146
|
|
1147
|
private void emptyCredentials() {
|
1148
|
txtLogin.setText(""); //$NON-NLS-1$
|
1149
|
txtPassword.setText(""); //$NON-NLS-1$
|
1150
|
}
|
1151
|
|
1152
|
private String getUsernamePrefKey() {
|
1153
|
return selectedServerInfo.toString(selectedCdmInstance.getName(), isDevRemoteSource?getPort():-1) + USERNAME_SUFFIX;
|
1154
|
}
|
1155
|
|
1156
|
private String getPasswordPrefKey() {
|
1157
|
return selectedServerInfo.toString(selectedCdmInstance.getName(), isDevRemoteSource?getPort():-1) + PASSWORD_SUFFIX;
|
1158
|
}
|
1159
|
|
1160
|
private boolean validateLogin(ICdmRemoteSource remoteSource) {
|
1161
|
if(getUsername() == null || getUsername().isEmpty()) {
|
1162
|
setMessage(Messages.RemotingLoginDialog_LOGIN_CANNOT_BE_EMPTY);
|
1163
|
return false;
|
1164
|
}
|
1165
|
if(getPassword() == null || getPassword().isEmpty()) {
|
1166
|
setMessage(Messages.RemotingLoginDialog_PASSWORD_CANNOT_BE_EMPTY);
|
1167
|
return false;
|
1168
|
}
|
1169
|
|
1170
|
try {
|
1171
|
IUserService userService = CdmApplicationRemoteConfiguration.getUserService(remoteSource);
|
1172
|
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(getUsername(), getPassword());
|
1173
|
CdmApplicationRemoteConfiguration.getAuthenticationManager(userService).authenticate(token);
|
1174
|
} catch(BadCredentialsException e){
|
1175
|
setMessage(LoginManager.INCORRECT_CREDENTIALS_MESSAGE);
|
1176
|
return false;
|
1177
|
} catch(LockedException e){
|
1178
|
setMessage(LoginManager.ACCOUNT_LOCKED_MESSAGE);
|
1179
|
return false;
|
1180
|
} catch(IllegalArgumentException e){
|
1181
|
setMessage(LoginManager.INCORRECT_CREDENTIALS_MESSAGE);
|
1182
|
return false;
|
1183
|
}
|
1184
|
return true;
|
1185
|
}
|
1186
|
|
1187
|
|
1188
|
@Override
|
1189
|
public String getUsername() {
|
1190
|
return txtLogin.getText();
|
1191
|
}
|
1192
|
|
1193
|
|
1194
|
@Override
|
1195
|
public String getPassword() {
|
1196
|
return txtPassword.getText();
|
1197
|
}
|
1198
|
|
1199
|
|
1200
|
@Override
|
1201
|
public void setMessage(String message) {
|
1202
|
if(CdmUtils.isNotBlank(message)) {
|
1203
|
// if(message.length() > 50) {
|
1204
|
// styledTxtMessage.setToolTipText(message);
|
1205
|
// message = message.substring(0,50) + "..."; //$NON-NLS-1$
|
1206
|
// }
|
1207
|
styledTxtMessage.setText(message);
|
1208
|
styledTxtMessage.setVisible(true);
|
1209
|
((GridData)styledTxtMessage.getLayoutData()).exclude = false;
|
1210
|
// shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
|
1211
|
shlConnect.pack(true);
|
1212
|
} else {
|
1213
|
if (!styledTxtMessage.isDisposed()){
|
1214
|
styledTxtMessage.setText(""); //$NON-NLS-1$
|
1215
|
styledTxtMessage.setVisible(false);
|
1216
|
((GridData)styledTxtMessage.getLayoutData()).exclude = true;
|
1217
|
}
|
1218
|
if(!shlConnect.isDisposed()){
|
1219
|
shlConnect.pack(true);
|
1220
|
}
|
1221
|
}
|
1222
|
if (!remotingComposite.isDisposed()){
|
1223
|
remotingComposite.layout();
|
1224
|
}
|
1225
|
}
|
1226
|
|
1227
|
// private int getHeightWithoutMessage() {
|
1228
|
// if(xpndblcmpstAdvanced.isExpanded()) {
|
1229
|
// return MIN_EXP_HEIGHT;
|
1230
|
// } else {
|
1231
|
// return MIN_HEIGHT;
|
1232
|
// }
|
1233
|
// }
|
1234
|
|
1235
|
@Override
|
1236
|
public void hide(boolean isHidden) {
|
1237
|
if (!shlConnect.isDisposed()){
|
1238
|
if(shlConnect != null && shlConnect.getDisplay() != null) {
|
1239
|
shlConnect.setVisible(!isHidden);
|
1240
|
}
|
1241
|
}
|
1242
|
}
|
1243
|
|
1244
|
|
1245
|
@Override
|
1246
|
public void dispose() {
|
1247
|
if (!shlConnect.isDisposed()){
|
1248
|
if(shlConnect != null && shlConnect.getDisplay() != null) {
|
1249
|
shlConnect.dispose();
|
1250
|
}
|
1251
|
}
|
1252
|
}
|
1253
|
|
1254
|
|
1255
|
@Override
|
1256
|
public void onComplete() {
|
1257
|
Display.getDefault().asyncExec(new Runnable() {
|
1258
|
@Override
|
1259
|
public void run() {
|
1260
|
if(selectedCdmInstance!=null){
|
1261
|
if(isRememberMe()) {
|
1262
|
persistPrefCredentials();
|
1263
|
}else{
|
1264
|
removePrefCredentials();
|
1265
|
}
|
1266
|
persistPrefLastServerInstance();
|
1267
|
}
|
1268
|
dispose();
|
1269
|
}
|
1270
|
});
|
1271
|
}
|
1272
|
|
1273
|
private String generateLastModifiedTooltip(String cdmlibLastModified) {
|
1274
|
if(StringUtils.isBlank(cdmlibLastModified)) {
|
1275
|
return ""; //$NON-NLS-1$
|
1276
|
}
|
1277
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm.z"); //$NON-NLS-1$
|
1278
|
Date cdmlibLastModifiedDate;
|
1279
|
String cdmlibLastModifiedTimestamp = ""; //$NON-NLS-1$
|
1280
|
|
1281
|
cdmlibLastModifiedDate = new Date(Long.valueOf(cdmlibLastModified));
|
1282
|
cdmlibLastModifiedTimestamp = sdf.format(cdmlibLastModifiedDate);
|
1283
|
|
1284
|
return cdmlibLastModifiedTimestamp;
|
1285
|
}
|
1286
|
|
1287
|
private void setEditorInfo() {
|
1288
|
txtEditorCdmVersion.setText(CdmMetaData.getDbSchemaVersion());
|
1289
|
setCdmlibVersion(txtEditorCdmlibVersion);
|
1290
|
}
|
1291
|
|
1292
|
private void setCdmlibVersion(Text txt) {
|
1293
|
String editorVersionTimestamp = generateLastModifiedTooltip(CdmApplicationState.getCdmlibLastModified());
|
1294
|
txt.setText(CdmApplicationState.getCdmlibVersion() + ":" + editorVersionTimestamp); //$NON-NLS-1$
|
1295
|
}
|
1296
|
|
1297
|
private void clearOnServerChange() {
|
1298
|
setMessage(""); //$NON-NLS-1$
|
1299
|
txtServerSchemaVersion.setText(""); //$NON-NLS-1$
|
1300
|
txtServerCdmlibVersion.setText(""); //$NON-NLS-1$
|
1301
|
txtServerCdmlibVersion.setToolTipText(""); //$NON-NLS-1$
|
1302
|
txtServerSchemaVersion.setText(""); //$NON-NLS-1$
|
1303
|
comboCdmInstance.removeAll();
|
1304
|
txtCdmInstanceStatus.setText(""); //$NON-NLS-1$
|
1305
|
txtPort.setEditable(false);
|
1306
|
txtPort.setEnabled(false);
|
1307
|
}
|
1308
|
|
1309
|
private void clearOnInstanceChange() {
|
1310
|
setMessage(""); //$NON-NLS-1$
|
1311
|
txtServerSchemaVersion.setText(""); //$NON-NLS-1$
|
1312
|
btnConnect.setText(LABEL_CONNECT);
|
1313
|
btnConnect.setBackground(null);
|
1314
|
btnConnect.requestLayout();
|
1315
|
}
|
1316
|
|
1317
|
@SuppressWarnings("unused") //in work, for future centralized handling of control's status
|
1318
|
private void updateControls(){
|
1319
|
|
1320
|
//server
|
1321
|
// comboCdmServer; //nothing to change
|
1322
|
String strServerStatus = this.selectedServerInfo != null? STATUS_NOT_AVAILABLE : STATUS_AVAILABLE;
|
1323
|
txtCdmServerStatus.setText(strServerStatus);
|
1324
|
// btnCdmServerRefresh; //nothing to change
|
1325
|
|
1326
|
//database
|
1327
|
// comboCdmInstance
|
1328
|
String strInstanceStatus = this.selectedCdmInstance != null? STATUS_NOT_AVAILABLE : STATUS_AVAILABLE;
|
1329
|
txtCdmInstanceStatus.setText(strInstanceStatus);
|
1330
|
// btnCdmInstanceRefresh; //nothing to change
|
1331
|
|
1332
|
//login + connect
|
1333
|
txtLogin.setText(Nz(login));
|
1334
|
txtPassword.setText(Nz(password));
|
1335
|
btnConnect.setText(LABEL_CONNECT); //TODO
|
1336
|
btnConnect.setEnabled(true);
|
1337
|
|
1338
|
//rememberMe + defaultValues
|
1339
|
// btnRememberMe;
|
1340
|
// lblDefaultLogin;
|
1341
|
|
1342
|
//message
|
1343
|
// styledTxtMessage;
|
1344
|
|
1345
|
//Advanced
|
1346
|
// txtPort
|
1347
|
// btnStopServer;
|
1348
|
|
1349
|
// txtServerCdmlibVersion;
|
1350
|
// txtEditorCdmlibVersion;
|
1351
|
// txtServerSchemaVersion;
|
1352
|
// txtEditorCdmVersion;
|
1353
|
}
|
1354
|
|
1355
|
private String Nz(String value) {
|
1356
|
return CdmUtils.Nz(value);
|
1357
|
}
|
1358
|
}
|