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