3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.ui
.dialog
;
12 import java
.text
.SimpleDateFormat
;
13 import java
.util
.Date
;
14 import java
.util
.HashMap
;
15 import java
.util
.List
;
18 import org
.apache
.commons
.lang
.StringUtils
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.core
.runtime
.IStatus
;
21 import org
.eclipse
.core
.runtime
.Status
;
22 import org
.eclipse
.core
.runtime
.jobs
.Job
;
23 import org
.eclipse
.core
.runtime
.preferences
.ConfigurationScope
;
24 import org
.eclipse
.core
.runtime
.preferences
.IEclipsePreferences
;
25 import org
.eclipse
.swt
.SWT
;
26 import org
.eclipse
.swt
.custom
.StyledText
;
27 import org
.eclipse
.swt
.events
.MouseAdapter
;
28 import org
.eclipse
.swt
.events
.MouseEvent
;
29 import org
.eclipse
.swt
.events
.SelectionAdapter
;
30 import org
.eclipse
.swt
.events
.SelectionEvent
;
31 import org
.eclipse
.swt
.graphics
.Point
;
32 import org
.eclipse
.swt
.layout
.FillLayout
;
33 import org
.eclipse
.swt
.layout
.GridData
;
34 import org
.eclipse
.swt
.layout
.GridLayout
;
35 import org
.eclipse
.swt
.widgets
.Button
;
36 import org
.eclipse
.swt
.widgets
.Combo
;
37 import org
.eclipse
.swt
.widgets
.Composite
;
38 import org
.eclipse
.swt
.widgets
.Dialog
;
39 import org
.eclipse
.swt
.widgets
.Display
;
40 import org
.eclipse
.swt
.widgets
.Label
;
41 import org
.eclipse
.swt
.widgets
.Shell
;
42 import org
.eclipse
.swt
.widgets
.Text
;
43 import org
.eclipse
.ui
.forms
.events
.ExpansionEvent
;
44 import org
.eclipse
.ui
.forms
.events
.IExpansionListener
;
45 import org
.eclipse
.ui
.forms
.widgets
.ExpandableComposite
;
46 import org
.eclipse
.wb
.swt
.SWTResourceManager
;
47 import org
.osgi
.service
.prefs
.BackingStoreException
;
48 import org
.osgi
.service
.prefs
.Preferences
;
50 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
51 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
;
52 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
53 import eu
.etaxonomy
.taxeditor
.remoting
.server
.CDMServerException
;
54 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmRemoteSource
;
55 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
;
56 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
.CdmInstanceInfo
;
57 import eu
.etaxonomy
.taxeditor
.remoting
.source
.ICdmRemoteSource
;
58 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
65 public class RemotingLoginDialog
extends Dialog
{
67 protected Object result
;
68 protected Shell shlConnect
;
69 private Text txtCdmServerStatus
;
70 private Text txtCdmInstanceStatus
;
71 private Combo comboCdmServer
;
72 private Combo comboCdmInstance
;
73 private Button btnConnect
;
75 private final Map
<String
, CdmServerInfo
> csiiMap
= new HashMap
<String
, CdmServerInfo
>();
77 private final static String STATUS_AVAILABLE
= "Available";
78 private final static String STATUS_NOT_AVAILABLE
= "Not Available";
79 private final static String STATUS_RETRIEVING
= "Retrieving ...";
80 private final static String STATUS_CHECKING_AVAILABILITY
= "Checking ...";
81 private final static String STATUS_NO_INSTANCES
= "No Instances Found";
82 private final static String STATUS_ERROR
= "Error";
83 private final static String STATUS_REMOTING_NOT_ACTIVATED
= "Remoting not activated";
84 private final static String STATUS_NOT_COMPATIBLE
= "Not Compatible";
86 private final static String MESG_COMPATIBLE_EDITOR_OLD
= "Please update the Taxonomic Editor (Help->Check for Updates) or choose a compatible cdm-server";
87 private final static String MESG_COMPATIBLE_SERVER_OLD
= "Please choose a compatible cdm-server or update the chosen cdm-server";
89 private final static String STORE_PREFERENCES_NODE
= "eu.etaxonomy.taxeditor.store";
91 private final static String LOGIN_NODE
= "login";
92 private final static String USERNAME_SUFFIX
= "_username";
93 private final static String PASSWORD_SUFFIX
= "_password";
95 private final static String LAST_SERVER_INSTANCE_NODE
= "lastServerInstance";
96 private final static String LAST_SERVER_KEY
= "lastServerKey";
97 private final static String LAST_INSTANCE_KEY
= "lastInstanceKey";
100 private Composite remotingComposite
;
101 private CdmServerInfo selectedCsii
;
102 private CdmInstanceInfo selectedCdmInstance
;
103 private Button btnCdmServerRefresh
;
104 private Composite loginComposite
;
105 private Label lblLogin
;
106 private Text txtLogin
;
107 private Label lblPassword
;
108 private Text txtPassword
;
109 private Button btnRememberMe
;
110 private Composite compAdvanced
;
111 private Label lblPort
;
112 private Text txtPort
;
113 private Label lblServerVersion
;
114 private Text txtServerVersion
;
115 private ExpandableComposite xpndblcmpstAdvanced
;
116 private StyledText styledTxtMessage
;
119 private final int MIN_WIDTH
= 530;
120 private final int MIN_HEIGHT
= 220;
121 private final int MIN_EXP_HEIGHT
= 380;
122 private final int MESSAGE_HEIGHT
= 25;
123 private Label lblEditorVersion
;
124 private Text txtEditorVersion
;
125 private Label lblServerCDMVersion
;
126 private Text txtServerCDMVersion
;
127 private Label lblEditorCDMVersion
;
128 private Text txtEditorCDMVersion
;
130 private String serverName
, instanceName
;
131 private boolean autoConnect
= false;
132 private boolean loadLoginPrefs
= true;
133 private boolean isDevRemoteSource
= false;
140 public RemotingLoginDialog(Shell parent
, int style
) {
141 super(parent
, style
);
145 public Object
open(CdmRemoteSource source
, boolean loadLoginPrefs
, boolean autoConnect
) {
146 this.loadLoginPrefs
= loadLoginPrefs
;
147 this.serverName
= source
.getName();
148 String contextPath
= source
.getContextPath();
149 this.instanceName
= contextPath
.substring(contextPath
.lastIndexOf("/") + 1);
150 return open(serverName
, instanceName
, loadLoginPrefs
, autoConnect
);
154 public Object
open(String serverName
, String instanceName
, boolean loadLoginPrefs
, boolean autoConnect
) {
155 this.serverName
= serverName
;
156 this.instanceName
= instanceName
;
157 this.loadLoginPrefs
= loadLoginPrefs
;
158 this.autoConnect
= autoConnect
;
166 public Object
open() {
167 // ICdmRemoteSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
168 // if(devRemoteSource != null) {
169 // connect(devRemoteSource);
172 if(serverName
== null && instanceName
== null) {
173 readPrefLastServerInstance();
177 populateCdmServerCombo();
181 xpndblcmpstAdvanced
.setExpanded(false);
183 Display display
= getParent().getDisplay();
185 while (!shlConnect
.isDisposed()) {
186 if (!display
.readAndDispatch()) {
195 * Create contents of the dialog.
197 private void createContents() {
198 shlConnect
= new Shell(getParent(), SWT
.DIALOG_TRIM
);
199 shlConnect
.setMinimumSize(new Point(MIN_WIDTH
, MIN_HEIGHT
));
200 shlConnect
.setSize(MIN_WIDTH
, MIN_HEIGHT
);
201 shlConnect
.setText("Connect");
202 shlConnect
.setLayout(new FillLayout(SWT
.HORIZONTAL
));
204 remotingComposite
= new Composite(shlConnect
, SWT
.NONE
);
205 remotingComposite
.setLayout(new GridLayout(1, false));
207 Composite cdmServerComposite
= new Composite(remotingComposite
, SWT
.NONE
);
208 GridData gd_cdmServerComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
209 gd_cdmServerComposite
.heightHint
= 68;
210 cdmServerComposite
.setLayoutData(gd_cdmServerComposite
);
211 cdmServerComposite
.setLayout(new GridLayout(4, false));
213 Label lblCdmServer
= new Label(cdmServerComposite
, SWT
.NONE
);
214 lblCdmServer
.setText("CDM Server : ");
215 lblCdmServer
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
216 lblCdmServer
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
218 comboCdmServer
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
219 comboCdmServer
.addSelectionListener(new SelectionAdapter() {
221 public void widgetSelected(SelectionEvent e
) {
226 GridData gd_comboCdmServer
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
227 gd_comboCdmServer
.widthHint
= 150;
228 comboCdmServer
.setLayoutData(gd_comboCdmServer
);
229 comboCdmServer
.select(0);
231 txtCdmServerStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
232 txtCdmServerStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
233 txtCdmServerStatus
.setEditable(false);
234 GridData gd_txtCdmServerStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
235 gd_txtCdmServerStatus
.widthHint
= 100;
236 txtCdmServerStatus
.setLayoutData(gd_txtCdmServerStatus
);
238 btnCdmServerRefresh
= new Button(cdmServerComposite
, SWT
.NONE
);
239 btnCdmServerRefresh
.addSelectionListener(new SelectionAdapter() {
241 public void widgetSelected(SelectionEvent e
) {
245 btnCdmServerRefresh
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
246 btnCdmServerRefresh
.setText("Refresh");
248 Label lblCdmInstance
= new Label(cdmServerComposite
, SWT
.NONE
);
249 GridData gd_lblCdmInstance
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
250 gd_lblCdmInstance
.heightHint
= 30;
251 lblCdmInstance
.setLayoutData(gd_lblCdmInstance
);
252 lblCdmInstance
.setText("CDM Instance : ");
253 lblCdmInstance
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
255 comboCdmInstance
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
256 comboCdmInstance
.addSelectionListener(new SelectionAdapter() {
258 public void widgetSelected(SelectionEvent e
) {
259 updateSelectedCdmInstance();
260 checkSelectedCdmInstance();
263 GridData gd_comboCdmInstance
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
264 gd_comboCdmInstance
.widthHint
= 150;
265 comboCdmInstance
.setLayoutData(gd_comboCdmInstance
);
266 comboCdmInstance
.select(0);
268 txtCdmInstanceStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
269 txtCdmInstanceStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
270 txtCdmInstanceStatus
.setEditable(false);
271 GridData gd_txtCdmInstanceStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
272 gd_txtCdmInstanceStatus
.widthHint
= 100;
273 txtCdmInstanceStatus
.setLayoutData(gd_txtCdmInstanceStatus
);
275 Button btnCdmInstanceRefresh
= new Button(cdmServerComposite
, SWT
.FLAT
);
276 btnCdmInstanceRefresh
.addSelectionListener(new SelectionAdapter() {
278 public void widgetSelected(SelectionEvent e
) {
279 refreshCdmInstance();
282 GridData gd_btnCdmInstanceRefresh
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
283 gd_btnCdmInstanceRefresh
.widthHint
= 110;
284 gd_btnCdmInstanceRefresh
.heightHint
= 30;
285 btnCdmInstanceRefresh
.setLayoutData(gd_btnCdmInstanceRefresh
);
286 btnCdmInstanceRefresh
.setText("Refresh");
288 loginComposite
= new Composite(remotingComposite
, SWT
.NONE
);
289 GridData gd_loginComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
290 gd_loginComposite
.widthHint
= 487;
291 gd_loginComposite
.heightHint
= 70;
292 loginComposite
.setLayoutData(gd_loginComposite
);
293 GridLayout gl_loginComposite
= new GridLayout(6, false);
294 gl_loginComposite
.marginTop
= 5;
295 loginComposite
.setLayout(gl_loginComposite
);
297 lblLogin
= new Label(loginComposite
, SWT
.CENTER
);
298 GridData gd_lblLogin
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
299 gd_lblLogin
.widthHint
= 50;
300 lblLogin
.setLayoutData(gd_lblLogin
);
301 lblLogin
.setText("Login : ");
302 lblLogin
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
304 txtLogin
= new Text(loginComposite
, SWT
.BORDER
);
305 GridData gd_txtLogin
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
306 gd_txtLogin
.minimumWidth
= 80;
307 gd_txtLogin
.widthHint
= 80;
308 gd_txtLogin
.heightHint
= 15;
309 txtLogin
.setLayoutData(gd_txtLogin
);
311 lblPassword
= new Label(loginComposite
, SWT
.CENTER
);
312 lblPassword
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
313 lblPassword
.setText("Password : ");
314 lblPassword
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
316 txtPassword
= new Text(loginComposite
, SWT
.BORDER
| SWT
.PASSWORD
);
317 GridData gd_txtPassword
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
318 gd_txtPassword
.minimumWidth
= 80;
319 gd_txtPassword
.widthHint
= 80;
320 gd_txtPassword
.heightHint
= 15;
321 txtPassword
.setLayoutData(gd_txtPassword
);
322 new Label(loginComposite
, SWT
.NONE
);
324 btnConnect
= new Button(loginComposite
, SWT
.FLAT
);
325 btnConnect
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1));
326 btnConnect
.addMouseListener(new MouseAdapter() {
328 public void mouseUp(MouseEvent e
) {
332 btnConnect
.setText("Connect");
334 btnRememberMe
= new Button(loginComposite
, SWT
.CHECK
);
335 btnRememberMe
.setSelection(true);
336 GridData gd_btnRememberMe
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 2, 1);
337 gd_btnRememberMe
.widthHint
= 107;
338 btnRememberMe
.setLayoutData(gd_btnRememberMe
);
339 btnRememberMe
.setText("Remember Me");
340 new Label(loginComposite
, SWT
.NONE
);
341 new Label(loginComposite
, SWT
.NONE
);
342 new Label(loginComposite
, SWT
.NONE
);
343 new Label(loginComposite
, SWT
.NONE
);
345 styledTxtMessage
= new StyledText(remotingComposite
, SWT
.NONE
);
346 styledTxtMessage
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
347 styledTxtMessage
.setForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
348 styledTxtMessage
.setFont(SWTResourceManager
.getFont("Ubuntu", 12, SWT
.BOLD
));
349 styledTxtMessage
.setSelectionBackground(SWTResourceManager
.getColor(SWT
.COLOR_LIST_SELECTION_TEXT
));
350 styledTxtMessage
.setSelectionForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
351 styledTxtMessage
.setDoubleClickEnabled(false);
352 styledTxtMessage
.setEditable(false);
353 GridData gd_styledTxtMessage
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
354 gd_styledTxtMessage
.exclude
= true;
355 gd_styledTxtMessage
.minimumHeight
= MESSAGE_HEIGHT
;
356 gd_styledTxtMessage
.heightHint
= MESSAGE_HEIGHT
;
357 styledTxtMessage
.setLayoutData(gd_styledTxtMessage
);
359 xpndblcmpstAdvanced
= new ExpandableComposite(remotingComposite
, SWT
.NONE
, ExpandableComposite
.TWISTIE
);
360 GridData gd_xpndblcmpstAdvanced
= new GridData(SWT
.FILL
, SWT
.FILL
, false, true, 1, 1);
361 gd_xpndblcmpstAdvanced
.heightHint
= 19;
362 xpndblcmpstAdvanced
.setLayoutData(gd_xpndblcmpstAdvanced
);
363 xpndblcmpstAdvanced
.addExpansionListener(new IExpansionListener() {
365 public void expansionStateChanged(ExpansionEvent e
) {
366 GridData gridData
= (GridData
) xpndblcmpstAdvanced
.getLayoutData();
368 shlConnect
.setSize(MIN_WIDTH
, MIN_EXP_HEIGHT
);
370 shlConnect
.setSize(MIN_WIDTH
, MIN_HEIGHT
);
375 public void expansionStateChanging(ExpansionEvent e
) {
378 xpndblcmpstAdvanced
.setText("advanced");
379 xpndblcmpstAdvanced
.setExpanded(true);
381 compAdvanced
= new Composite(xpndblcmpstAdvanced
, SWT
.NONE
);
382 xpndblcmpstAdvanced
.setClient(compAdvanced
);
383 compAdvanced
.setLayout(new GridLayout(4, false));
385 lblPort
= new Label(compAdvanced
, SWT
.CENTER
);
386 lblPort
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
387 lblPort
.setSize(0, 0);
388 lblPort
.setText("Port : ");
389 lblPort
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
391 txtPort
= new Text(compAdvanced
, SWT
.BORDER
);
392 GridData gd_txtPort
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1);
393 gd_txtPort
.minimumWidth
= 50;
394 gd_txtPort
.widthHint
= 50;
395 txtPort
.setLayoutData(gd_txtPort
);
397 lblServerVersion
= new Label(compAdvanced
, SWT
.CENTER
);
398 lblServerVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
399 lblServerVersion
.setText("Server Cdmlib Version :");
400 lblServerVersion
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
402 txtServerVersion
= new Text(compAdvanced
, SWT
.BORDER
);
403 txtServerVersion
.setEditable(false);
404 txtServerVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
405 new Label(compAdvanced
, SWT
.NONE
);
406 new Label(compAdvanced
, SWT
.NONE
);
408 lblEditorVersion
= new Label(compAdvanced
, SWT
.CENTER
);
409 lblEditorVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
410 lblEditorVersion
.setText("Editor Cdmlib Version :");
411 lblEditorVersion
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
413 txtEditorVersion
= new Text(compAdvanced
, SWT
.BORDER
);
414 txtEditorVersion
.setEditable(false);
415 txtEditorVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
416 new Label(compAdvanced
, SWT
.NONE
);
417 new Label(compAdvanced
, SWT
.NONE
);
419 lblServerCDMVersion
= new Label(compAdvanced
, SWT
.CENTER
);
420 lblServerCDMVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
421 lblServerCDMVersion
.setText("Server CDM Version :");
422 lblServerCDMVersion
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
424 txtServerCDMVersion
= new Text(compAdvanced
, SWT
.BORDER
);
425 txtServerCDMVersion
.setEditable(false);
426 txtServerCDMVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
427 new Label(compAdvanced
, SWT
.NONE
);
428 new Label(compAdvanced
, SWT
.NONE
);
430 lblEditorCDMVersion
= new Label(compAdvanced
, SWT
.CENTER
);
431 lblEditorCDMVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
432 lblEditorCDMVersion
.setText("Editor CDM Version :");
433 lblEditorCDMVersion
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
435 txtEditorCDMVersion
= new Text(compAdvanced
, SWT
.BORDER
);
436 txtEditorCDMVersion
.setEditable(false);
437 txtEditorCDMVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
443 private void populateCdmServerCombo() {
444 Job job
= new Job("Retrieve Server Instances") {
446 protected IStatus
run(IProgressMonitor monitor
) {
447 Display
.getDefault().syncExec(new Runnable() {
450 for(CdmServerInfo csii
: CdmServerInfo
.getCdmServers()) {
451 csiiMap
.put(csii
.getName(), csii
);
452 comboCdmServer
.add(csii
.getName());
454 int serverIndex
= -1;
455 if(serverName
!= null) {
456 serverIndex
= comboCdmServer
.indexOf(serverName
);
458 if(serverIndex
== -1) {
459 comboCdmServer
.select(0);
462 comboCdmServer
.select(serverIndex
);
464 CdmRemoteSource devRemoteSource
= CdmServerInfo
.getDevServerRemoteSource();
465 if(devRemoteSource
!= null) {
466 isDevRemoteSource
= true;
471 if(devRemoteSource
!= null) {
472 String username
= System
.getProperty("cdm.server.dev.username");
473 String password
= System
.getProperty("cdm.server.dev.password");
474 if(username
!= null && !username
.isEmpty() && password
!= null && !password
.isEmpty()) {
475 txtLogin
.setText(username
);
476 txtPassword
.setText(password
);
477 CdmStore
.connect(devRemoteSource
, RemotingLoginDialog
.this);
482 return Status
.OK_STATUS
;
489 private void refreshCdmServer() {
490 txtCdmServerStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
491 updateSelectedCdmServer();
492 checkSelectedCdmServer();
495 private void updateSelectedCdmServer() {
496 int selIndex
= comboCdmServer
.getSelectionIndex();
498 selectedCsii
= csiiMap
.get(comboCdmServer
.getItem(selIndex
));
502 private void updatePort() {
504 if(selectedCsii
!= null) {
505 txtPort
.setText(String
.valueOf(selectedCsii
.getPort()));
509 private int getPort() {
512 port
= Integer
.valueOf(txtPort
.getText());
513 } catch (NumberFormatException nfe
) {
514 setMessage("Port should be an integer");
519 private void checkSelectedCdmServer() {
521 clearOnServerChange();
524 if(selectedCsii
!= null) {
525 if(selectedCsii
.isLocalhost()) {
526 txtPort
.setEditable(true);
527 txtPort
.setEnabled(true);
529 if(selectedCsii
.pingServer()) {
530 txtCdmServerStatus
.setText(STATUS_AVAILABLE
);
531 populateCdmInstanceCombo(true);
532 txtServerVersion
.setText(selectedCsii
.getCdmlibServicesVersion());
533 txtServerVersion
.setToolTipText(generateLastModifiedTooltip(selectedCsii
.getCdmlibLastModified()));
536 txtCdmServerStatus
.setText(STATUS_NOT_AVAILABLE
);
537 comboCdmInstance
.removeAll();
543 private void populateCdmInstanceCombo(final boolean forceRefresh
) {
544 comboCdmInstance
.removeAll();
545 comboCdmInstance
.setEnabled(false);
546 btnConnect
.setEnabled(false);
547 txtCdmInstanceStatus
.setText(STATUS_RETRIEVING
);
548 txtCdmInstanceStatus
.setToolTipText("");
550 Job job
= new Job("Retrieve Server Instances") {
552 protected IStatus
run(IProgressMonitor monitor
) {
554 if(selectedCsii
!= null) {
556 selectedCsii
.refreshInstances();
558 final List
<CdmInstanceInfo
> instances
= selectedCsii
.getInstances();
559 Display
.getDefault().asyncExec(new Runnable() {
562 if(!instances
.isEmpty()) {
563 for(CdmInstanceInfo cdmInstance
: instances
) {
564 comboCdmInstance
.add(cdmInstance
.getName());
566 int instanceIndex
= -1;
567 if(instanceName
!= null) {
568 instanceIndex
= comboCdmInstance
.indexOf(instanceName
);
570 if(instanceIndex
== -1) {
571 comboCdmInstance
.select(0);
574 comboCdmInstance
.select(instanceIndex
);
576 updateSelectedCdmInstance();
577 checkSelectedCdmInstance();
578 comboCdmInstance
.setEnabled(true);
584 txtCdmInstanceStatus
.setText(STATUS_NO_INSTANCES
);
585 btnConnect
.setEnabled(false);
590 } catch (final CDMServerException e
) {
591 MessagingUtils
.warn(getClass(), e
);
592 Display
.getDefault().asyncExec(new Runnable() {
595 txtCdmInstanceStatus
.setText(STATUS_NOT_AVAILABLE
);
596 txtCdmInstanceStatus
.setToolTipText(e
.getMessage());
597 comboCdmInstance
.setEnabled(false);
598 btnConnect
.setEnabled(false);
602 return Status
.OK_STATUS
;
606 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
) && !isDevRemoteSource
) {
613 private void refreshCdmInstance() {
614 txtCdmInstanceStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
615 clearOnInstanceChange();
616 updateSelectedCdmInstance();
617 checkSelectedCdmInstance();
620 private void updateSelectedCdmInstance() {
621 int selIndex
= comboCdmInstance
.getSelectionIndex();
623 selectedCdmInstance
= selectedCsii
.getInstanceFromName(comboCdmInstance
.getItem(selIndex
));
624 if(loadLoginPrefs
&& !isDevRemoteSource
) {
625 readPrefCredentials();
630 private void checkSelectedCdmInstance() {
631 boolean available
= false;
632 String status
= STATUS_NOT_AVAILABLE
;
633 String message
= null;
635 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
)) {
637 if(selectedCsii
.pingInstance(selectedCdmInstance
, getPort())) {
638 status
= STATUS_AVAILABLE
;
641 status
= STATUS_NOT_AVAILABLE
;
646 txtServerCDMVersion
.setText(selectedCsii
.getCdmRemoteSource(selectedCdmInstance
, getPort()).getDbSchemaVersion());
647 int compareDbSchemaVersion
= selectedCsii
.compareDbSchemaVersion(selectedCdmInstance
, getPort());
648 int compareCdmlibServicesVersion
= selectedCsii
.compareCdmlibServicesVersion();
650 if(compareDbSchemaVersion
> 0 || compareCdmlibServicesVersion
> 0) {
651 status
= STATUS_NOT_COMPATIBLE
;
653 message
= MESG_COMPATIBLE_EDITOR_OLD
;
654 } else if(compareDbSchemaVersion
< 0 || compareCdmlibServicesVersion
< 0) {
655 status
= STATUS_NOT_COMPATIBLE
;
657 message
= MESG_COMPATIBLE_SERVER_OLD
;
659 status
= STATUS_AVAILABLE
;
667 } catch (Exception e
) {
668 txtCdmInstanceStatus
.setToolTipText(e
.getMessage());
670 btnConnect
.setEnabled(available
);
671 txtCdmInstanceStatus
.setText(status
);
672 if(!StringUtils
.isBlank(message
)) {
681 private void connect() {
682 checkSelectedCdmInstance();
684 if(!txtCdmInstanceStatus
.getText().equals(STATUS_AVAILABLE
)) {
688 ICdmRemoteSource source
= selectedCsii
.getCdmRemoteSource(selectedCdmInstance
, getPort());
690 if(!validateLogin()) {
695 CdmStore
.connect(source
, this);
696 } catch (Exception e
) {
697 // Do not expect anything to go wrong at this point, so we throw a runtime exception
699 throw new RuntimeException(e
);
705 public boolean isRememberMe() {
706 return btnRememberMe
.getSelection();
709 private void persistPrefLastServerInstance() {
710 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
711 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
713 lastServerInstancePrefs
.put(LAST_SERVER_KEY
, selectedCsii
.getName());
714 lastServerInstancePrefs
.put(LAST_INSTANCE_KEY
, selectedCdmInstance
.getName());
716 flushPreferences(lastServerInstancePrefs
);
719 private void persistPrefCredentials() {
720 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
721 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
722 credentialsPrefs
.put(getUsernamePrefKey(), txtLogin
.getText());
723 credentialsPrefs
.put(getPasswordPrefKey(), txtPassword
.getText());
724 flushPreferences(credentialsPrefs
);
727 private void flushPreferences(Preferences prefs
) {
730 } catch (BackingStoreException bse
) {
731 setMessage(bse
.getMessage());
735 private void readPrefCredentials() {
736 String username
, password
;
737 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
738 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
739 username
= credentialsPrefs
.get(getUsernamePrefKey(), "");
740 txtLogin
.setText(username
);
741 password
= credentialsPrefs
.get(getPasswordPrefKey(),"");
742 txtPassword
.setText(password
);
743 if(username
.isEmpty() || password
.isEmpty()) {
748 private void readPrefLastServerInstance() {
749 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
750 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
752 serverName
= lastServerInstancePrefs
.get(LAST_SERVER_KEY
, null);
753 instanceName
= lastServerInstancePrefs
.get(LAST_INSTANCE_KEY
, null);
756 private void emptyCredentials() {
757 txtLogin
.setText("");
758 txtPassword
.setText("");
761 private String
getUsernamePrefKey() {
762 return selectedCsii
.toString(selectedCdmInstance
.getName(), getPort()) + USERNAME_SUFFIX
;
765 private String
getPasswordPrefKey() {
766 return selectedCsii
.toString(selectedCdmInstance
.getName(), getPort()) + PASSWORD_SUFFIX
;
769 private boolean validateLogin() {
770 if(getUsername() == null || getUsername().isEmpty()) {
771 setMessage("User login cannot be empty");
774 if(getPassword() == null || getPassword().isEmpty()) {
775 setMessage("Password cannot be empty");
780 public String
getUsername() {
781 return txtLogin
.getText();
784 public String
getPassword() {
785 return txtPassword
.getText();
788 public void setMessage(String message
) {
789 if(message
!= null && !message
.isEmpty()) {
790 if(message
.length() > 60) {
791 styledTxtMessage
.setToolTipText(message
);
792 message
= message
.substring(0, 60) + "...";
794 styledTxtMessage
.setText(message
);
795 styledTxtMessage
.setVisible(true);
796 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= false;
797 shlConnect
.setSize(MIN_WIDTH
, getHeightWithoutMessage() + MESSAGE_HEIGHT
);
798 shlConnect
.setMinimumSize(MIN_WIDTH
, getHeightWithoutMessage() + MESSAGE_HEIGHT
);
800 styledTxtMessage
.setText("");
801 styledTxtMessage
.setVisible(false);
802 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= true;
803 shlConnect
.setSize(MIN_WIDTH
, getHeightWithoutMessage());
804 shlConnect
.setMinimumSize(MIN_WIDTH
, getHeightWithoutMessage());
806 remotingComposite
.layout();
809 private int getHeightWithoutMessage() {
810 if(xpndblcmpstAdvanced
.isExpanded()) {
811 return MIN_EXP_HEIGHT
;
818 public void hide(boolean isHidden
) {
819 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
820 shlConnect
.setVisible(!isHidden
);
823 public void dispose() {
824 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
825 shlConnect
.dispose();
829 public void onComplete() {
830 Display
.getDefault().asyncExec(new Runnable() {
833 if(!isDevRemoteSource
) {
835 persistPrefCredentials();
837 persistPrefLastServerInstance();
844 private String
generateLastModifiedTooltip(String cdmlibLastModified
) {
845 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z");
846 Date cdmlibLastModifiedDate
;
847 String cdmlibLastModifiedTimestamp
= "";
849 cdmlibLastModifiedDate
= new Date(Long
.valueOf(cdmlibLastModified
));
850 cdmlibLastModifiedTimestamp
= sdf
.format(cdmlibLastModifiedDate
);
852 return "last modified : " + cdmlibLastModifiedTimestamp
;
855 private void setEditorInfo() {
856 txtEditorCDMVersion
.setText(CdmMetaData
.getDbSchemaVersion());
857 txtEditorVersion
.setText(CdmApplicationState
.getCdmlibVersion());
858 txtEditorVersion
.setToolTipText(generateLastModifiedTooltip(CdmApplicationState
.getCdmlibLastModified()));
861 private void clearOnServerChange() {
863 txtServerCDMVersion
.setText("");
864 txtServerVersion
.setText("");
865 txtServerVersion
.setToolTipText("");
866 txtServerCDMVersion
.setText("");
867 txtPort
.setEditable(false);
868 txtPort
.setEnabled(false);
871 private void clearOnInstanceChange() {
873 txtServerCDMVersion
.setText("");
876 private void updateOnServerChange(String serverVersion
, String serverVersionTooltip
) {