Rename vocabulary wizard
[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.apache.log4j.Logger;
21 import org.eclipse.core.runtime.IProgressMonitor;
22 import org.eclipse.core.runtime.IStatus;
23 import org.eclipse.core.runtime.Status;
24 import org.eclipse.core.runtime.jobs.Job;
25 import org.eclipse.core.runtime.preferences.ConfigurationScope;
26 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
27 import org.eclipse.jface.layout.GridDataFactory;
28 import org.eclipse.swt.SWT;
29 import org.eclipse.swt.SWTException;
30 import org.eclipse.swt.custom.StyledText;
31 import org.eclipse.swt.events.KeyAdapter;
32 import org.eclipse.swt.events.KeyEvent;
33 import org.eclipse.swt.events.MouseAdapter;
34 import org.eclipse.swt.events.MouseEvent;
35 import org.eclipse.swt.events.SelectionAdapter;
36 import org.eclipse.swt.events.SelectionEvent;
37 import org.eclipse.swt.graphics.Point;
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 private final int MESSAGE_HEIGHT = 75;
153 private Label lblEditorVersion;
154 private Text txtEditorVersion;
155 private Label lblServerCDMVersion;
156 private Text txtServerCDMVersion;
157 private Label lblEditorCDMVersion;
158 private Text txtEditorCDMVersion;
159
160 private String serverName, instanceName;
161 private boolean autoConnect = false;
162 private boolean loadLoginPrefs = true;
163 private boolean isDevRemoteSource = false;
164 private Job serverJob;
165 /**
166 * Create the dialog.
167 * @param parent
168 * @param style
169 */
170 public RemotingLoginDialog(Shell parent, int style) {
171 super(parent, style);
172 setText(Messages.RemotingLoginDialog_LABEL_LOGIN);
173 }
174
175 public Object open(CdmRemoteSource source, boolean loadLoginPrefs, boolean autoConnect) {
176 this.loadLoginPrefs = loadLoginPrefs;
177 this.serverName = source.getName();
178 String contextPath = source.getContextPath();
179 this.instanceName = contextPath.substring(contextPath.lastIndexOf("/") + 1); //$NON-NLS-1$
180 return open(serverName, instanceName, loadLoginPrefs, autoConnect);
181 }
182
183
184 public Object open(String serverName, String instanceName, boolean loadLoginPrefs, boolean autoConnect) {
185 this.serverName = serverName;
186 this.instanceName = instanceName;
187 this.loadLoginPrefs = loadLoginPrefs;
188 this.autoConnect = autoConnect;
189 return open();
190 }
191
192 /**
193 * Open the dialog.
194 * @return the result
195 */
196 public Object open() {
197
198 createContents();
199 if(serverName == null && instanceName == null) {
200 readPrefLastServerInstance();
201 }
202
203 setEditorInfo();
204 populateCdmServerCombo();
205 shlConnect.open();
206 shlConnect.layout();
207
208 xpndblcmpstAdvanced.setExpanded(false);
209
210 Display display = getParent().getDisplay();
211
212 while (!shlConnect.isDisposed()) {
213 if (!display.isDisposed()){
214 if (!display.readAndDispatch()) {
215 display.sleep();
216 }
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() && CdmStore.currentAuthentiationHasOneOfRoles(Role.ROLE_REMOTING)){
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 try{
589 if(selectedCsii != null) {
590 if(selectedCsii.isLocalhost()) {
591 txtPort.setEditable(true);
592 txtPort.setEnabled(true);
593 }
594 try {
595 if(selectedCsii.pingServer()) {
596 txtCdmServerStatus.setText(STATUS_AVAILABLE);
597 populateCdmInstanceCombo(true);
598 String serverVersionTimestamp = generateLastModifiedTooltip(selectedCsii.getCdmlibLastModified());
599 txtServerVersion.setText(selectedCsii.getCdmlibServicesVersion() + ":" + serverVersionTimestamp); //$NON-NLS-1$
600 } else {
601 txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
602 comboCdmInstance.removeAll();
603 disableCdmInstanceControls("", ""); //$NON-NLS-1$ //$NON-NLS-2$
604 }
605 } catch (CDMServerException | IOException e) {
606 txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
607 MessagingUtils.warningDialog(Messages.RemotingLoginDialog_CONNECTION_FAILED_TITLE, this,
608 Messages.RemotingLoginDialog_CONNECTION_FAILED_MESSAGE);
609 logger.warn(Messages.RemotingLoginDialog_CONNECTION_FAILED_TITLE, e);
610 }
611 }
612 updatePort();
613 }
614 catch(SWTException e){
615 //catch widget is disposed exception which may occurr if
616 //dialog is closed but the runnable tries to update
617 }
618 }
619
620
621 private void populateCdmInstanceCombo(final boolean forceRefresh) {
622 comboCdmInstance.removeAll();
623 comboCdmInstance.setEnabled(false);
624 btnConnect.setEnabled(false);
625 txtCdmInstanceStatus.setText(STATUS_RETRIEVING);
626 txtCdmInstanceStatus.setToolTipText(""); //$NON-NLS-1$
627
628 serverJob = new Job(Messages.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES) {
629 @Override
630 protected IStatus run(IProgressMonitor monitor) {
631 try {
632 if(selectedCsii != null) {
633 if(forceRefresh) {
634 selectedCsii.refreshInstances();
635 }
636 final List<CdmInstanceInfo> instances = selectedCsii.getInstances();
637 Display.getDefault().asyncExec(new Runnable() {
638 @Override
639 public void run() {
640 if(!instances.isEmpty()) {
641 for(CdmInstanceInfo cdmInstance : instances) {
642 comboCdmInstance.add(cdmInstance.getName());
643 }
644 int instanceIndex = -1;
645 if(instanceName != null) {
646 instanceIndex = comboCdmInstance.indexOf(instanceName);
647 }
648 if(instanceIndex == -1) {
649 comboCdmInstance.select(0);
650 autoConnect = false;
651 } else {
652 comboCdmInstance.select(instanceIndex);
653 }
654 refreshCdmInstance();
655 comboCdmInstance.setEnabled(true);
656 if(autoConnect) {
657 connect();
658 }
659
660 } else {
661 txtCdmInstanceStatus.setText(STATUS_NO_INSTANCES);
662 btnConnect.setEnabled(false);
663 }
664 }
665 });
666 }
667 } catch (final CDMServerException e) {
668 MessagingUtils.warn(getClass(), e);
669 Display.getDefault().asyncExec(new Runnable() {
670 @Override
671 public void run() {
672 disableCdmInstanceControls(STATUS_NOT_AVAILABLE, e.getMessage());
673 }
674 });
675 }
676 return Status.OK_STATUS;
677 }
678 };
679
680 if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE) && !isDevRemoteSource) {
681 // Start the Job
682 serverJob.schedule();
683 }
684 }
685
686 private void disableCdmInstanceControls(String cdmInstanceStatus, String tooltip) {
687 txtCdmInstanceStatus.setText(cdmInstanceStatus);
688 txtCdmInstanceStatus.setToolTipText(tooltip);
689 comboCdmInstance.setEnabled(false);
690 btnConnect.setEnabled(false);
691
692 }
693 private void refreshCdmInstance() {
694 txtCdmInstanceStatus.setText(STATUS_CHECKING_AVAILABILITY);
695 clearOnInstanceChange();
696 updateSelectedCdmInstance();
697 checkSelectedCdmInstance();
698 updateManagedServerControls();
699 }
700
701 private void updateSelectedCdmInstance() {
702 int selIndex = comboCdmInstance.getSelectionIndex();
703 if(selIndex != -1) {
704 selectedCdmInstance = selectedCsii.getInstanceFromName(comboCdmInstance.getItem(selIndex));
705
706 if(loadLoginPrefs && !isDevRemoteSource) {
707 readPrefCredentials();
708 }
709 }
710 }
711
712 private void updateManagedServerControls() {
713 if(selectedCsii.isLocalhostMgd()) {
714 if(isSelectedCdmInstanceRunningInManagedServer()) {
715 txtCdmInstanceStatus.setText(STATUS_STARTED);
716 } else {
717 txtCdmInstanceStatus.setText(STATUS_NOT_STARTED);
718 }
719 btnConnect.setEnabled(true);
720 selectedCsii.setPort(getManagedServerPort());
721 updatePort();
722 }
723
724
725 if(isManagedServerRunning()) {
726 btnStopServer.setEnabled(true);
727 } else {
728 btnStopServer.setEnabled(false);
729 }
730 }
731
732 private boolean isManagedServerRunning() {
733 return CdmStore.getManagedServer() != null && CdmStore.getManagedServer().isAlive();
734 }
735
736 private boolean isSelectedCdmInstanceRunningInManagedServer() {
737 return CdmStore.getManagedServer() != null &&
738 CdmStore.getManagedServer().isAlive() &&
739 selectedCsii.isLocalhostMgd() &&
740 CdmStore.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName());
741 }
742
743 private void startManagedServer() {
744 if(isManagedServerRunning()) {
745 if(CdmStore.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName())) {
746 return;
747 } else {
748 Display.getDefault().syncExec(new Runnable() {
749 @Override
750 public void run() {
751 stopManagedServer();
752 }
753 });
754 }
755 }
756
757
758 Job job = new Job(Messages.RemotingLoginDialog_JOB_SERVER_LAUNCH) {
759
760 @Override
761 public IStatus run(IProgressMonitor monitor) {
762 String mgdServerConfigFileName = "mgd.datasources.xml"; //$NON-NLS-1$
763 String config = CDMServerUtils.convertEditorToServerConfig();
764 File managedServerConfigFile;
765 int maxUnits = 50;
766 monitor.beginTask(Messages.RemotingLoginDialog_TASK_LAUNCHING_SERVER, maxUnits);
767 try {
768 monitor.subTask(String.format(Messages.RemotingLoginDialog_GENERATING_CONFIG_FILE, selectedCdmInstance.getName()));
769 managedServerConfigFile = CDMServerUtils.writeManagedServerConfig(config, mgdServerConfigFileName);
770 monitor.worked(1);
771 CdmStore.setManagedServer(new CDMServer(selectedCdmInstance.getName(), managedServerConfigFile));
772 monitor.subTask(Messages.RemotingLoginDialog_STARTING_MGD_SERVER);
773 CdmStore.getManagedServer().start(false, RemotingLoginDialog.this);
774 int serverUnits = 0;
775
776 // the following loop is a 'fake' progress monitoring where the progress
777 // bar is advanced by one unit every second until maxUnits -2
778 while(!CdmStore.getManagedServer().isStarted() && !CdmStore.getManagedServer().isFailed()) {
779 if(serverUnits < maxUnits - 2) {
780 try {
781 Thread.sleep(1000);
782 } catch (InterruptedException e) {
783 }
784 monitor.worked(1);
785 serverUnits++;
786 }
787 }
788 Display.getDefault().asyncExec(new Runnable() {
789 @Override
790 public void run() {
791 hide(false);
792 updateManagedServerControls();
793 connect();
794 }
795 });
796 } catch (IOException ioe) {
797 MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_GENERATING_CONFIG_FILE,
798 this,
799 ioe.getMessage(),
800 TaxeditorStorePlugin.PLUGIN_ID,
801 ioe,
802 true);
803 } catch (CDMEmbeddedServerException cse) {
804 MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_STARTING_SERVER,
805 this,
806 cse.getMessage(),
807 TaxeditorStorePlugin.PLUGIN_ID,
808 cse,
809 true);
810 } finally {
811 monitor.done();
812 }
813 return Status.OK_STATUS;
814 }
815 };
816
817 // configure the job
818 job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
819 job.setUser(true);
820 // schedule job
821 hide(true);
822 job.schedule();
823 }
824
825 private void stopManagedServer() {
826 try {
827 CdmStore.getManagedServer().stop();
828 } catch (Exception e) {
829 MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_STOPPING_SERVER,
830 this,
831 String.format(Messages.RemotingLoginDialog_COULD_NOT_STOP_SERVER, CdmStore.getManagedServer().getPort()),
832 TaxeditorStorePlugin.PLUGIN_ID,
833 e,
834 true);
835 }
836 CdmStore.setManagedServer(null);
837 updateManagedServerControls();
838 }
839
840 private int getManagedServerPort() {
841 return CdmStore.getManagedServer() == null ? CdmServerInfo.NULL_PORT : CdmStore.getManagedServer().getPort();
842 }
843
844 private void checkSelectedCdmInstance() {
845 boolean available = false;
846 String status = STATUS_NOT_AVAILABLE;
847 String message = null;
848
849 if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
850 try {
851 if(selectedCsii.pingInstance(selectedCdmInstance, getPort())) {
852 status = STATUS_AVAILABLE;
853 available = true;
854 } else {
855 status = STATUS_NOT_AVAILABLE;
856 available = false;
857 }
858
859 if(available) {
860 txtServerCDMVersion.setText(selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort()).getDbSchemaVersion());
861 int compareDbSchemaVersion = selectedCsii.compareDbSchemaVersion(selectedCdmInstance, getPort());
862 int compareCdmlibServicesVersion = 0;
863 boolean disableServicesApiTimestampCheck =
864 PreferencesUtil.getBooleanValue((IPreferenceKeys.DISABLE_SERVICES_API_TIMESTAMP_CHECK));
865 if(!disableServicesApiTimestampCheck) {
866 compareCdmlibServicesVersion = selectedCsii.compareCdmlibServicesVersion();
867 }
868 if(compareDbSchemaVersion > 0 || compareCdmlibServicesVersion > 0) {
869 status = STATUS_NOT_COMPATIBLE;
870 available = false;
871 message = MESG_COMPATIBLE_EDITOR_OLD;
872 } else if(compareDbSchemaVersion < 0 || compareCdmlibServicesVersion < 0) {
873 status = STATUS_NOT_COMPATIBLE;
874 available = false;
875 message = MESG_COMPATIBLE_SERVER_OLD;
876 } else {
877 status = STATUS_AVAILABLE;
878 available = true;
879 message = ""; //$NON-NLS-1$
880 }
881 }
882 } catch (Exception e) {
883 txtCdmInstanceStatus.setToolTipText(e.getMessage());
884 } finally {
885 btnConnect.setEnabled(available);
886 txtCdmInstanceStatus.setText(status);
887 if(!StringUtils.isBlank(message)) {
888 setMessage(message);
889 }
890 }
891 }
892 }
893
894 private void connect() {
895 checkSelectedCdmInstance();
896
897 if(!txtCdmInstanceStatus.getText().equals(STATUS_AVAILABLE)) {
898 return;
899 }
900
901 ICdmRemoteSource source = selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort());
902
903 if(!validateLogin(source)) {
904 return;
905 }
906
907 try {
908 CdmStore.connect(source, this);
909 } catch (Exception e) {
910 // Do not expect anything to go wrong at this point, so we throw a runtime exception
911 // if any problems
912 throw new RuntimeException(e);
913 }
914
915 }
916
917
918 public boolean isRememberMe() {
919 return btnRememberMe.getSelection();
920 }
921
922 private void persistPrefLastServerInstance() {
923 IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
924 Preferences lastServerInstancePrefs = preferences.node(LAST_SERVER_INSTANCE_NODE);
925
926 lastServerInstancePrefs.put(LAST_SERVER_KEY, selectedCsii.getName());
927 lastServerInstancePrefs.put(LAST_INSTANCE_KEY, selectedCdmInstance.getName());
928
929 flushPreferences(lastServerInstancePrefs);
930 }
931
932 private void persistPrefCredentials() {
933 IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
934 Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
935 credentialsPrefs.put(getUsernamePrefKey(), txtLogin.getText());
936 credentialsPrefs.put(getPasswordPrefKey(), txtPassword.getText());
937 flushPreferences(credentialsPrefs);
938 }
939
940 private void removePrefCredentials() {
941 IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
942 Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
943 credentialsPrefs.put(getUsernamePrefKey(), txtLogin.getText());
944 credentialsPrefs.put(getPasswordPrefKey(), txtPassword.getText());
945 removePreferences(credentialsPrefs);
946 }
947 private void removePreferences(Preferences prefs) {
948 try {
949 prefs.removeNode();
950 } catch (BackingStoreException bse) {
951 setMessage(bse.getMessage());
952 }
953 }
954 private void flushPreferences(Preferences prefs) {
955 try {
956 prefs.flush();
957 } catch (BackingStoreException bse) {
958 setMessage(bse.getMessage());
959 }
960 }
961
962
963
964 private void readPrefCredentials() {
965 String username, password;
966 IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
967 Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
968 username = credentialsPrefs.get(getUsernamePrefKey(), ""); //$NON-NLS-1$
969 txtLogin.setText(username);
970 password = credentialsPrefs.get(getPasswordPrefKey(),""); //$NON-NLS-1$
971 txtPassword.setText(password);
972 if(username.isEmpty() || password.isEmpty()) {
973 autoConnect = false;
974 }
975 }
976
977 private void readPrefLastServerInstance() {
978 IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
979 Preferences lastServerInstancePrefs = preferences.node(LAST_SERVER_INSTANCE_NODE);
980
981 serverName = lastServerInstancePrefs.get(LAST_SERVER_KEY, null);
982 instanceName = lastServerInstancePrefs.get(LAST_INSTANCE_KEY, null);
983 }
984
985 private void emptyCredentials() {
986 txtLogin.setText(""); //$NON-NLS-1$
987 txtPassword.setText(""); //$NON-NLS-1$
988 }
989
990 private String getUsernamePrefKey() {
991 return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + USERNAME_SUFFIX;
992 }
993
994 private String getPasswordPrefKey() {
995 return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + PASSWORD_SUFFIX;
996 }
997
998 private boolean validateLogin(ICdmRemoteSource remoteSource) {
999 if(getUsername() == null || getUsername().isEmpty()) {
1000 setMessage(Messages.RemotingLoginDialog_LOGIN_CANNOT_BE_EMPTY);
1001 return false;
1002 }
1003 if(getPassword() == null || getPassword().isEmpty()) {
1004 setMessage(Messages.RemotingLoginDialog_PASSWORD_CANNOT_BE_EMPTY);
1005 return false;
1006 }
1007
1008
1009 try {
1010 IUserService userService = CdmApplicationRemoteConfiguration.getUserService(remoteSource);
1011 UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(getUsername(), getPassword());
1012 CdmApplicationRemoteConfiguration.getAuthenticationManager(userService).authenticate(token);
1013 } catch(BadCredentialsException e){
1014 setMessage(LoginManager.INCORRECT_CREDENTIALS_MESSAGE);
1015 return false;
1016 } catch(LockedException e){
1017 setMessage(LoginManager.ACCOUNT_LOCKED_MESSAGE);
1018 return false;
1019 } catch(IllegalArgumentException e){
1020 setMessage(LoginManager.INCORRECT_CREDENTIALS_MESSAGE);
1021 return false;
1022 }
1023 return true;
1024 }
1025
1026 public String getUsername() {
1027 return txtLogin.getText();
1028 }
1029
1030 public String getPassword() {
1031 return txtPassword.getText();
1032 }
1033
1034 public void setMessage(String message) {
1035 if(message != null && !message.isEmpty()) {
1036 // if(message.length() > 50) {
1037 // styledTxtMessage.setToolTipText(message);
1038 // message = message.substring(0,50) + "..."; //$NON-NLS-1$
1039 // }
1040 styledTxtMessage.setText(message);
1041 styledTxtMessage.setVisible(true);
1042 ((GridData)styledTxtMessage.getLayoutData()).exclude = false;
1043 shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
1044 shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
1045 } else {
1046 if (!styledTxtMessage.isDisposed()){
1047 styledTxtMessage.setText(""); //$NON-NLS-1$
1048 styledTxtMessage.setVisible(false);
1049 ((GridData)styledTxtMessage.getLayoutData()).exclude = true;
1050 }
1051 if(!shlConnect.isDisposed()){
1052 shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage());
1053 shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage());
1054 }
1055 }
1056 if (!remotingComposite.isDisposed()){
1057 remotingComposite.layout();
1058 }
1059 }
1060
1061 private int getHeightWithoutMessage() {
1062 if(xpndblcmpstAdvanced.isExpanded()) {
1063 return MIN_EXP_HEIGHT;
1064 } else {
1065 return MIN_HEIGHT;
1066 }
1067 }
1068
1069
1070 public void hide(boolean isHidden) {
1071 if (!shlConnect.isDisposed()){
1072 if(shlConnect != null && shlConnect.getDisplay() != null) {
1073 shlConnect.setVisible(!isHidden);
1074 }
1075 }
1076 }
1077 public void dispose() {
1078 if (!shlConnect.isDisposed()){
1079 if(shlConnect != null && shlConnect.getDisplay() != null) {
1080 shlConnect.dispose();
1081 }
1082 }
1083 }
1084
1085 public void onComplete() {
1086 Display.getDefault().asyncExec(new Runnable() {
1087 @Override
1088 public void run() {
1089 if(!isDevRemoteSource) {
1090 if(isRememberMe()) {
1091 persistPrefCredentials();
1092 }else{
1093 removePrefCredentials();
1094 }
1095 persistPrefLastServerInstance();
1096 }
1097 dispose();
1098 }
1099 });
1100 }
1101
1102 private String generateLastModifiedTooltip(String cdmlibLastModified) {
1103 if(StringUtils.isBlank(cdmlibLastModified)) {
1104 return ""; //$NON-NLS-1$
1105 }
1106 SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm.z"); //$NON-NLS-1$
1107 Date cdmlibLastModifiedDate;
1108 String cdmlibLastModifiedTimestamp = ""; //$NON-NLS-1$
1109
1110 cdmlibLastModifiedDate = new Date(Long.valueOf(cdmlibLastModified));
1111 cdmlibLastModifiedTimestamp = sdf.format(cdmlibLastModifiedDate);
1112
1113 return cdmlibLastModifiedTimestamp;
1114 }
1115
1116 private void setEditorInfo() {
1117 txtEditorCDMVersion.setText(CdmMetaData.getDbSchemaVersion());
1118 String editorVersionTimestamp = generateLastModifiedTooltip(CdmApplicationState.getCdmlibLastModified());
1119 txtEditorVersion.setText(CdmApplicationState.getCdmlibVersion() + ":" + editorVersionTimestamp); //$NON-NLS-1$
1120 }
1121
1122 private void clearOnServerChange() {
1123 setMessage(""); //$NON-NLS-1$
1124 txtServerCDMVersion.setText(""); //$NON-NLS-1$
1125 txtServerVersion.setText(""); //$NON-NLS-1$
1126 txtServerVersion.setToolTipText(""); //$NON-NLS-1$
1127 txtServerCDMVersion.setText(""); //$NON-NLS-1$
1128 comboCdmInstance.removeAll();
1129 txtCdmInstanceStatus.setText(""); //$NON-NLS-1$
1130 txtPort.setEditable(false);
1131 txtPort.setEnabled(false);
1132 }
1133
1134 private void clearOnInstanceChange() {
1135 setMessage(""); //$NON-NLS-1$
1136 txtServerCDMVersion.setText(""); //$NON-NLS-1$
1137 }
1138
1139 /**
1140 * {@inheritDoc}
1141 */
1142 @Override
1143 public void handleError(final Throwable t) {
1144
1145 Display.getDefault().syncExec(new Runnable() {
1146 @Override
1147 public void run() {
1148 serverJob.cancel();
1149
1150 String title = Messages.RemotingLoginDialog_SERVER_LAUNCH_ERROR;
1151 String message = t.getMessage();
1152
1153
1154 MessagingUtils.errorDialog(title,
1155 this,
1156 message,
1157 TaxeditorStorePlugin.PLUGIN_ID,
1158 t,
1159 true);
1160 }
1161 });
1162 }
1163
1164
1165 }