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