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
.util
.HashMap
;
13 import java
.util
.List
;
16 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
17 import org
.eclipse
.core
.runtime
.IStatus
;
18 import org
.eclipse
.core
.runtime
.Status
;
19 import org
.eclipse
.core
.runtime
.jobs
.Job
;
20 import org
.eclipse
.core
.runtime
.preferences
.ConfigurationScope
;
21 import org
.eclipse
.core
.runtime
.preferences
.IEclipsePreferences
;
22 import org
.eclipse
.swt
.SWT
;
23 import org
.eclipse
.swt
.custom
.StyledText
;
24 import org
.eclipse
.swt
.events
.MouseAdapter
;
25 import org
.eclipse
.swt
.events
.MouseEvent
;
26 import org
.eclipse
.swt
.events
.SelectionAdapter
;
27 import org
.eclipse
.swt
.events
.SelectionEvent
;
28 import org
.eclipse
.swt
.graphics
.Point
;
29 import org
.eclipse
.swt
.layout
.FillLayout
;
30 import org
.eclipse
.swt
.layout
.GridData
;
31 import org
.eclipse
.swt
.layout
.GridLayout
;
32 import org
.eclipse
.swt
.widgets
.Button
;
33 import org
.eclipse
.swt
.widgets
.Combo
;
34 import org
.eclipse
.swt
.widgets
.Composite
;
35 import org
.eclipse
.swt
.widgets
.Dialog
;
36 import org
.eclipse
.swt
.widgets
.Display
;
37 import org
.eclipse
.swt
.widgets
.Label
;
38 import org
.eclipse
.swt
.widgets
.Shell
;
39 import org
.eclipse
.swt
.widgets
.Text
;
40 import org
.eclipse
.ui
.forms
.events
.ExpansionEvent
;
41 import org
.eclipse
.ui
.forms
.events
.IExpansionListener
;
42 import org
.eclipse
.ui
.forms
.widgets
.ExpandableComposite
;
43 import org
.eclipse
.wb
.swt
.SWTResourceManager
;
44 import org
.osgi
.service
.prefs
.BackingStoreException
;
45 import org
.osgi
.service
.prefs
.Preferences
;
47 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
48 import eu
.etaxonomy
.taxeditor
.remoting
.server
.CDMServerException
;
49 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmRemoteSource
;
50 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
;
51 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
.CdmInstanceInfo
;
52 import eu
.etaxonomy
.taxeditor
.remoting
.source
.ICdmRemoteSource
;
53 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
60 public class RemotingLoginDialog
extends Dialog
{
62 protected Object result
;
63 protected Shell shlConnect
;
64 private Text txtCdmServerStatus
;
65 private Text txtCdmInstanceStatus
;
66 private Combo comboCdmServer
;
67 private Combo comboCdmInstance
;
68 private Button btnConnect
;
70 private final Map
<String
, CdmServerInfo
> csiiMap
= new HashMap
<String
, CdmServerInfo
>();
72 private final static String STATUS_AVAILABLE
= "Available";
73 private final static String STATUS_NOT_AVAILABLE
= "Not Available";
74 private final static String STATUS_RETRIEVING
= "Retrieving ...";
75 private final static String STATUS_CHECKING_AVAILABILITY
= "Checking ...";
76 private final static String STATUS_NO_INSTANCES
= "No Instances Found";
77 private final static String STATUS_ERROR
= "Error";
78 private final static String STATUS_REMOTING_NOT_ACTIVATED
= "Remoting not activated";
79 private final static String STORE_PREFERENCES_NODE
= "eu.etaxonomy.taxeditor.store";
81 private final static String LOGIN_NODE
= "login";
82 private final static String USERNAME_SUFFIX
= "_username";
83 private final static String PASSWORD_SUFFIX
= "_password";
85 private final static String LAST_SERVER_INSTANCE_NODE
= "lastServerInstance";
86 private final static String LAST_SERVER_KEY
= "lastServerKey";
87 private final static String LAST_INSTANCE_KEY
= "lastInstanceKey";
90 private Composite remotingComposite
;
91 private CdmServerInfo selectedCsii
;
92 private CdmInstanceInfo selectedCdmInstance
;
93 private Button btnCdmServerRefresh
;
94 private Composite loginComposite
;
95 private Label lblLogin
;
96 private Text txtLogin
;
97 private Label lblPassword
;
98 private Text txtPassword
;
99 private Button btnRememberMe
;
100 private Composite compAdvanced
;
101 private Label lblPort
;
102 private Text txtPort
;
103 private Label lblServerVersion
;
104 private Text txtServerVersion
;
105 private ExpandableComposite xpndblcmpstAdvanced
;
106 private StyledText styledTxtMessage
;
109 private final int MIN_WIDTH
= 530;
110 private final int MIN_HEIGHT
= 220;
111 private final int MIN_EXP_HEIGHT
= 350;
112 private final int MESSAGE_HEIGHT
= 25;
113 private Label lblEditorVersion
;
114 private Text txtEditorVersion
;
115 private Label lblServerCDMVersion
;
116 private Text txtServerCDMVersion
;
117 private Label lblEditorCDMVersion
;
118 private Text txtEditorCDMVersion
;
120 private String serverName
, instanceName
;
121 private boolean autoConnect
= false;
122 private boolean loadLoginPrefs
= true;
123 private boolean isDevRemoteSource
= false;
130 public RemotingLoginDialog(Shell parent
, int style
) {
131 super(parent
, style
);
135 public Object
open(CdmRemoteSource source
, boolean loadLoginPrefs
, boolean autoConnect
) {
136 this.loadLoginPrefs
= loadLoginPrefs
;
137 this.serverName
= source
.getName();
138 String contextPath
= source
.getContextPath();
139 this.instanceName
= contextPath
.substring(contextPath
.lastIndexOf("/") + 1);
140 return open(serverName
, instanceName
, loadLoginPrefs
, autoConnect
);
144 public Object
open(String serverName
, String instanceName
, boolean loadLoginPrefs
, boolean autoConnect
) {
145 this.serverName
= serverName
;
146 this.instanceName
= instanceName
;
147 this.loadLoginPrefs
= loadLoginPrefs
;
148 this.autoConnect
= autoConnect
;
156 public Object
open() {
157 // ICdmRemoteSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
158 // if(devRemoteSource != null) {
159 // connect(devRemoteSource);
162 if(serverName
== null && instanceName
== null) {
163 readPrefLastServerInstance();
166 populateCdmServerCombo();
170 xpndblcmpstAdvanced
.setExpanded(false);
172 CdmRemoteSource devRemoteSource
= CdmServerInfo
.getDevServerRemoteSource();
173 if(devRemoteSource
!= null) {
174 CdmStore
.connect(devRemoteSource
, this);
175 isDevRemoteSource
= true;
178 Display display
= getParent().getDisplay();
180 while (!shlConnect
.isDisposed()) {
181 if (!display
.readAndDispatch()) {
190 * Create contents of the dialog.
192 private void createContents() {
193 shlConnect
= new Shell(getParent(), SWT
.DIALOG_TRIM
);
194 shlConnect
.setMinimumSize(new Point(MIN_WIDTH
, MIN_HEIGHT
));
195 shlConnect
.setSize(MIN_WIDTH
, MIN_HEIGHT
);
196 shlConnect
.setText("Connect");
197 shlConnect
.setLayout(new FillLayout(SWT
.HORIZONTAL
));
199 remotingComposite
= new Composite(shlConnect
, SWT
.NONE
);
200 remotingComposite
.setLayout(new GridLayout(1, false));
202 Composite cdmServerComposite
= new Composite(remotingComposite
, SWT
.NONE
);
203 GridData gd_cdmServerComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
204 gd_cdmServerComposite
.heightHint
= 68;
205 cdmServerComposite
.setLayoutData(gd_cdmServerComposite
);
206 cdmServerComposite
.setLayout(new GridLayout(4, false));
208 Label lblCdmServer
= new Label(cdmServerComposite
, SWT
.NONE
);
209 lblCdmServer
.setText("CDM Server : ");
210 lblCdmServer
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
211 lblCdmServer
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
213 comboCdmServer
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
214 comboCdmServer
.addSelectionListener(new SelectionAdapter() {
216 public void widgetSelected(SelectionEvent e
) {
221 GridData gd_comboCdmServer
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
222 gd_comboCdmServer
.widthHint
= 150;
223 comboCdmServer
.setLayoutData(gd_comboCdmServer
);
224 comboCdmServer
.select(0);
226 txtCdmServerStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
227 txtCdmServerStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
228 txtCdmServerStatus
.setEditable(false);
229 GridData gd_txtCdmServerStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
230 gd_txtCdmServerStatus
.widthHint
= 100;
231 txtCdmServerStatus
.setLayoutData(gd_txtCdmServerStatus
);
233 btnCdmServerRefresh
= new Button(cdmServerComposite
, SWT
.NONE
);
234 btnCdmServerRefresh
.addSelectionListener(new SelectionAdapter() {
236 public void widgetSelected(SelectionEvent e
) {
240 btnCdmServerRefresh
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
241 btnCdmServerRefresh
.setText("Refresh");
243 Label lblCdmInstance
= new Label(cdmServerComposite
, SWT
.NONE
);
244 GridData gd_lblCdmInstance
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
245 gd_lblCdmInstance
.heightHint
= 30;
246 lblCdmInstance
.setLayoutData(gd_lblCdmInstance
);
247 lblCdmInstance
.setText("CDM Instance : ");
248 lblCdmInstance
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
250 comboCdmInstance
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
251 comboCdmInstance
.addSelectionListener(new SelectionAdapter() {
253 public void widgetSelected(SelectionEvent e
) {
254 updateSelectedCdmInstance();
255 checkSelectedCdmInstance();
258 GridData gd_comboCdmInstance
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
259 gd_comboCdmInstance
.widthHint
= 150;
260 comboCdmInstance
.setLayoutData(gd_comboCdmInstance
);
261 comboCdmInstance
.select(0);
263 txtCdmInstanceStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
264 txtCdmInstanceStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
265 txtCdmInstanceStatus
.setEditable(false);
266 GridData gd_txtCdmInstanceStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
267 gd_txtCdmInstanceStatus
.widthHint
= 100;
268 txtCdmInstanceStatus
.setLayoutData(gd_txtCdmInstanceStatus
);
270 Button btnCdmInstanceRefresh
= new Button(cdmServerComposite
, SWT
.FLAT
);
271 btnCdmInstanceRefresh
.addSelectionListener(new SelectionAdapter() {
273 public void widgetSelected(SelectionEvent e
) {
274 refreshCdmInstance();
277 GridData gd_btnCdmInstanceRefresh
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
278 gd_btnCdmInstanceRefresh
.widthHint
= 110;
279 gd_btnCdmInstanceRefresh
.heightHint
= 30;
280 btnCdmInstanceRefresh
.setLayoutData(gd_btnCdmInstanceRefresh
);
281 btnCdmInstanceRefresh
.setText("Refresh");
283 loginComposite
= new Composite(remotingComposite
, SWT
.NONE
);
284 GridData gd_loginComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
285 gd_loginComposite
.widthHint
= 487;
286 gd_loginComposite
.heightHint
= 70;
287 loginComposite
.setLayoutData(gd_loginComposite
);
288 GridLayout gl_loginComposite
= new GridLayout(6, false);
289 gl_loginComposite
.marginTop
= 5;
290 loginComposite
.setLayout(gl_loginComposite
);
292 lblLogin
= new Label(loginComposite
, SWT
.CENTER
);
293 GridData gd_lblLogin
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
294 gd_lblLogin
.widthHint
= 50;
295 lblLogin
.setLayoutData(gd_lblLogin
);
296 lblLogin
.setText("Login : ");
297 lblLogin
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
299 txtLogin
= new Text(loginComposite
, SWT
.BORDER
);
300 GridData gd_txtLogin
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
301 gd_txtLogin
.minimumWidth
= 80;
302 gd_txtLogin
.widthHint
= 80;
303 gd_txtLogin
.heightHint
= 15;
304 txtLogin
.setLayoutData(gd_txtLogin
);
306 lblPassword
= new Label(loginComposite
, SWT
.CENTER
);
307 lblPassword
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
308 lblPassword
.setText("Password : ");
309 lblPassword
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
311 txtPassword
= new Text(loginComposite
, SWT
.BORDER
| SWT
.PASSWORD
);
312 GridData gd_txtPassword
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
313 gd_txtPassword
.minimumWidth
= 80;
314 gd_txtPassword
.widthHint
= 80;
315 gd_txtPassword
.heightHint
= 15;
316 txtPassword
.setLayoutData(gd_txtPassword
);
317 new Label(loginComposite
, SWT
.NONE
);
319 btnConnect
= new Button(loginComposite
, SWT
.FLAT
);
320 btnConnect
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1));
321 btnConnect
.addMouseListener(new MouseAdapter() {
323 public void mouseUp(MouseEvent e
) {
327 btnConnect
.setText("Connect");
329 btnRememberMe
= new Button(loginComposite
, SWT
.CHECK
);
330 btnRememberMe
.setSelection(true);
331 GridData gd_btnRememberMe
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 2, 1);
332 gd_btnRememberMe
.widthHint
= 107;
333 btnRememberMe
.setLayoutData(gd_btnRememberMe
);
334 btnRememberMe
.setText("Remember Me");
335 new Label(loginComposite
, SWT
.NONE
);
336 new Label(loginComposite
, SWT
.NONE
);
337 new Label(loginComposite
, SWT
.NONE
);
338 new Label(loginComposite
, SWT
.NONE
);
340 styledTxtMessage
= new StyledText(remotingComposite
, SWT
.NONE
);
341 styledTxtMessage
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
342 styledTxtMessage
.setForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
343 styledTxtMessage
.setFont(SWTResourceManager
.getFont("Ubuntu", 12, SWT
.BOLD
));
344 styledTxtMessage
.setSelectionBackground(SWTResourceManager
.getColor(SWT
.COLOR_LIST_SELECTION_TEXT
));
345 styledTxtMessage
.setSelectionForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
346 styledTxtMessage
.setDoubleClickEnabled(false);
347 styledTxtMessage
.setEditable(false);
348 GridData gd_styledTxtMessage
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
349 gd_styledTxtMessage
.exclude
= true;
350 gd_styledTxtMessage
.minimumHeight
= MESSAGE_HEIGHT
;
351 gd_styledTxtMessage
.heightHint
= MESSAGE_HEIGHT
;
352 styledTxtMessage
.setLayoutData(gd_styledTxtMessage
);
354 xpndblcmpstAdvanced
= new ExpandableComposite(remotingComposite
, SWT
.NONE
, ExpandableComposite
.TWISTIE
);
355 GridData gd_xpndblcmpstAdvanced
= new GridData(SWT
.FILL
, SWT
.FILL
, false, true, 1, 1);
356 gd_xpndblcmpstAdvanced
.heightHint
= 19;
357 xpndblcmpstAdvanced
.setLayoutData(gd_xpndblcmpstAdvanced
);
358 xpndblcmpstAdvanced
.addExpansionListener(new IExpansionListener() {
360 public void expansionStateChanged(ExpansionEvent e
) {
361 GridData gridData
= (GridData
) xpndblcmpstAdvanced
.getLayoutData();
363 shlConnect
.setSize(MIN_WIDTH
, MIN_EXP_HEIGHT
);
365 shlConnect
.setSize(MIN_WIDTH
, MIN_HEIGHT
);
370 public void expansionStateChanging(ExpansionEvent e
) {
373 xpndblcmpstAdvanced
.setText("advanced");
374 xpndblcmpstAdvanced
.setExpanded(true);
376 compAdvanced
= new Composite(xpndblcmpstAdvanced
, SWT
.NONE
);
377 xpndblcmpstAdvanced
.setClient(compAdvanced
);
378 compAdvanced
.setLayout(new GridLayout(4, false));
380 lblPort
= new Label(compAdvanced
, SWT
.CENTER
);
381 lblPort
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
382 lblPort
.setSize(0, 0);
383 lblPort
.setText("Port : ");
384 lblPort
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
386 txtPort
= new Text(compAdvanced
, SWT
.BORDER
);
387 GridData gd_txtPort
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1);
388 gd_txtPort
.minimumWidth
= 50;
389 gd_txtPort
.widthHint
= 50;
390 txtPort
.setLayoutData(gd_txtPort
);
392 lblServerVersion
= new Label(compAdvanced
, SWT
.CENTER
);
393 lblServerVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
394 lblServerVersion
.setText("Server Version :");
395 lblServerVersion
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
397 txtServerVersion
= new Text(compAdvanced
, SWT
.BORDER
);
398 txtServerVersion
.setEnabled(false);
399 txtServerVersion
.setEditable(false);
400 txtServerVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
401 new Label(compAdvanced
, SWT
.NONE
);
402 new Label(compAdvanced
, SWT
.NONE
);
404 lblEditorVersion
= new Label(compAdvanced
, SWT
.CENTER
);
405 lblEditorVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
406 lblEditorVersion
.setText("Editor Version :");
407 lblEditorVersion
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
409 txtEditorVersion
= new Text(compAdvanced
, SWT
.BORDER
);
410 txtEditorVersion
.setEnabled(false);
411 txtEditorVersion
.setEditable(false);
412 txtEditorVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
413 new Label(compAdvanced
, SWT
.NONE
);
414 new Label(compAdvanced
, SWT
.NONE
);
416 lblServerCDMVersion
= new Label(compAdvanced
, SWT
.CENTER
);
417 lblServerCDMVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
418 lblServerCDMVersion
.setText("Server CDM Version :");
419 lblServerCDMVersion
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
421 txtServerCDMVersion
= new Text(compAdvanced
, SWT
.BORDER
);
422 txtServerCDMVersion
.setEnabled(false);
423 txtServerCDMVersion
.setEditable(false);
424 txtServerCDMVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
425 new Label(compAdvanced
, SWT
.NONE
);
426 new Label(compAdvanced
, SWT
.NONE
);
428 lblEditorCDMVersion
= new Label(compAdvanced
, SWT
.CENTER
);
429 lblEditorCDMVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
430 lblEditorCDMVersion
.setText("Editor CDM Version :");
431 lblEditorCDMVersion
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
433 txtEditorCDMVersion
= new Text(compAdvanced
, SWT
.BORDER
);
434 txtEditorCDMVersion
.setEnabled(false);
435 txtEditorCDMVersion
.setEditable(false);
436 txtEditorCDMVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
442 private void populateCdmServerCombo() {
443 Job job
= new Job("Retrieve Server Instances") {
445 protected IStatus
run(IProgressMonitor monitor
) {
446 Display
.getDefault().syncExec(new Runnable() {
449 for(CdmServerInfo csii
: CdmServerInfo
.getCdmServers()) {
450 csiiMap
.put(csii
.getName(), csii
);
451 comboCdmServer
.add(csii
.getName());
453 int serverIndex
= -1;
454 if(serverName
!= null) {
455 serverIndex
= comboCdmServer
.indexOf(serverName
);
457 if(serverIndex
== -1) {
458 comboCdmServer
.select(0);
461 comboCdmServer
.select(serverIndex
);
467 return Status
.OK_STATUS
;
474 private void refreshCdmServer() {
475 txtCdmServerStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
476 updateSelectedCdmServer();
477 checkSelectedCdmServer();
480 private void updateSelectedCdmServer() {
481 int selIndex
= comboCdmServer
.getSelectionIndex();
483 selectedCsii
= csiiMap
.get(comboCdmServer
.getItem(selIndex
));
487 private void updatePort() {
489 if(selectedCsii
!= null) {
490 txtPort
.setText(String
.valueOf(selectedCsii
.getPort()));
494 private int getPort() {
497 port
= Integer
.valueOf(txtPort
.getText());
498 } catch (NumberFormatException nfe
) {
499 setMessage("Port should be an integer");
504 private void checkSelectedCdmServer() {
506 txtCdmInstanceStatus
.setText("");
507 txtPort
.setEditable(false);
508 txtPort
.setEnabled(false);
511 if(selectedCsii
!= null) {
512 if(selectedCsii
.isLocalhost()) {
513 txtPort
.setEditable(true);
514 txtPort
.setEnabled(true);
516 if(selectedCsii
.pingServer()) {
517 txtCdmServerStatus
.setText(STATUS_AVAILABLE
);
518 populateCdmInstanceCombo(true);
521 txtCdmServerStatus
.setText(STATUS_NOT_AVAILABLE
);
522 comboCdmInstance
.removeAll();
528 private void populateCdmInstanceCombo(final boolean forceRefresh
) {
529 comboCdmInstance
.removeAll();
530 comboCdmInstance
.setEnabled(false);
531 btnConnect
.setEnabled(false);
532 txtCdmInstanceStatus
.setText(STATUS_RETRIEVING
);
534 Job job
= new Job("Retrieve Server Instances") {
536 protected IStatus
run(IProgressMonitor monitor
) {
538 if(selectedCsii
!= null) {
540 selectedCsii
.refreshInstances();
542 final List
<CdmInstanceInfo
> instances
= selectedCsii
.getInstances();
543 Display
.getDefault().asyncExec(new Runnable() {
546 if(!instances
.isEmpty()) {
547 for(CdmInstanceInfo cdmInstance
: instances
) {
548 comboCdmInstance
.add(cdmInstance
.getName());
550 int instanceIndex
= -1;
551 if(instanceName
!= null) {
552 instanceIndex
= comboCdmInstance
.indexOf(instanceName
);
554 if(instanceIndex
== -1) {
555 comboCdmInstance
.select(0);
558 comboCdmInstance
.select(instanceIndex
);
560 updateSelectedCdmInstance();
561 checkSelectedCdmInstance();
562 comboCdmInstance
.setEnabled(true);
568 txtCdmInstanceStatus
.setText(STATUS_NO_INSTANCES
);
569 btnConnect
.setEnabled(false);
574 } catch (CDMServerException e
) {
575 MessagingUtils
.warn(getClass(), e
);
576 Display
.getDefault().asyncExec(new Runnable() {
579 txtCdmInstanceStatus
.setText(STATUS_REMOTING_NOT_ACTIVATED
);
580 comboCdmInstance
.setEnabled(false);
581 btnConnect
.setEnabled(false);
585 return Status
.OK_STATUS
;
589 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
)) {
596 private void refreshCdmInstance() {
597 txtCdmInstanceStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
598 updateSelectedCdmInstance();
599 checkSelectedCdmInstance();
602 private void updateSelectedCdmInstance() {
603 int selIndex
= comboCdmInstance
.getSelectionIndex();
605 selectedCdmInstance
= selectedCsii
.getInstanceFromName(comboCdmInstance
.getItem(selIndex
));
607 readPrefCredentials();
612 private void checkSelectedCdmInstance() {
613 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
)) {
615 if(selectedCsii
.pingInstance(selectedCdmInstance
, getPort())) {
616 txtCdmInstanceStatus
.setText(STATUS_AVAILABLE
);
617 btnConnect
.setEnabled(true);
619 txtCdmInstanceStatus
.setText(STATUS_NOT_AVAILABLE
);
620 btnConnect
.setEnabled(false);
622 } catch (Exception e
) {
623 txtCdmInstanceStatus
.setText(STATUS_NOT_AVAILABLE
);
624 txtCdmInstanceStatus
.setToolTipText(e
.getMessage());
630 private void connect() {
631 checkSelectedCdmInstance();
633 if(!txtCdmInstanceStatus
.getText().equals(STATUS_AVAILABLE
)) {
637 ICdmRemoteSource source
= selectedCsii
.getCdmRemoteSource(selectedCdmInstance
, getPort());
639 if(!validateLogin()) {
644 CdmStore
.connect(source
, this);
645 } catch (Exception e
) {
646 // Do not expect anything to go wrong at this point, so we throw a runtime exception
648 throw new RuntimeException(e
);
654 public boolean isRememberMe() {
655 return btnRememberMe
.getSelection();
658 private void persistPrefLastServerInstance() {
659 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
660 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
662 lastServerInstancePrefs
.put(LAST_SERVER_KEY
, selectedCsii
.getName());
663 lastServerInstancePrefs
.put(LAST_INSTANCE_KEY
, selectedCdmInstance
.getName());
665 flushPreferences(lastServerInstancePrefs
);
668 private void persistPrefCredentials() {
669 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
670 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
671 credentialsPrefs
.put(getUsernamePrefKey(), txtLogin
.getText());
672 credentialsPrefs
.put(getPasswordPrefKey(), txtPassword
.getText());
673 flushPreferences(credentialsPrefs
);
676 private void flushPreferences(Preferences prefs
) {
679 } catch (BackingStoreException bse
) {
680 setMessage(bse
.getMessage());
684 private void readPrefCredentials() {
685 String username
, password
;
686 if(isDevRemoteSource
) {
687 username
= System
.getProperty("cdm.server.dev.username");
688 password
= System
.getProperty("cdm.server.dev.password");
689 if(username
!= null && !username
.isEmpty() && password
!= null && !password
.isEmpty()) {
690 txtLogin
.setText(username
);
691 txtPassword
.setText(password
);
695 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
696 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
697 username
= credentialsPrefs
.get(getUsernamePrefKey(), "");
698 txtLogin
.setText(username
);
699 password
= credentialsPrefs
.get(getPasswordPrefKey(), "");
700 txtPassword
.setText(password
);
701 if(username
.isEmpty() || password
.isEmpty()) {
706 private void readPrefLastServerInstance() {
707 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
708 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
710 serverName
= lastServerInstancePrefs
.get(LAST_SERVER_KEY
, null);
711 instanceName
= lastServerInstancePrefs
.get(LAST_INSTANCE_KEY
, null);
714 private void emptyCredentials() {
715 txtLogin
.setText("");
716 txtLogin
.setText("");
719 private String
getUsernamePrefKey() {
720 return selectedCsii
.toString(selectedCdmInstance
.getName(), getPort()) + USERNAME_SUFFIX
;
723 private String
getPasswordPrefKey() {
724 return selectedCsii
.toString(selectedCdmInstance
.getName(), getPort()) + PASSWORD_SUFFIX
;
727 private boolean validateLogin() {
728 if(getUsername() == null || getUsername().isEmpty()) {
729 setMessage("User login cannot be empty");
732 if(getPassword() == null || getPassword().isEmpty()) {
733 setMessage("Password cannot be empty");
738 public String
getUsername() {
739 return txtLogin
.getText();
742 public String
getPassword() {
743 return txtPassword
.getText();
746 public void setMessage(String message
) {
747 if(message
!= null && !message
.isEmpty()) {
748 if(message
.length() > 60) {
749 styledTxtMessage
.setToolTipText(message
);
750 message
= message
.substring(0, 60) + "...";
752 styledTxtMessage
.setText(message
);
753 styledTxtMessage
.setVisible(true);
754 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= false;
755 shlConnect
.setSize(MIN_WIDTH
, MIN_HEIGHT
+MESSAGE_HEIGHT
);
756 shlConnect
.setMinimumSize(MIN_WIDTH
, MIN_HEIGHT
+MESSAGE_HEIGHT
);
758 styledTxtMessage
.setText("");
759 styledTxtMessage
.setVisible(false);
760 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= true;
761 shlConnect
.setSize(MIN_WIDTH
, MIN_HEIGHT
);
762 shlConnect
.setMinimumSize(MIN_WIDTH
, MIN_HEIGHT
);
764 remotingComposite
.layout();
769 public void hide(boolean isHidden
) {
770 if(shlConnect
!= null) {
771 shlConnect
.setVisible(!isHidden
);
774 public void dispose() {
775 if(shlConnect
!= null) {
776 shlConnect
.dispose();
780 public void onComplete() {
781 Display
.getDefault().asyncExec(new Runnable() {
785 persistPrefCredentials();
787 persistPrefLastServerInstance();