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