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