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
;
13 import java
.io
.IOException
;
14 import java
.text
.SimpleDateFormat
;
15 import java
.util
.Date
;
16 import java
.util
.HashMap
;
17 import java
.util
.List
;
20 import org
.apache
.commons
.lang
.StringUtils
;
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
.swt
.SWT
;
28 import org
.eclipse
.swt
.custom
.StyledText
;
29 import org
.eclipse
.swt
.events
.MouseAdapter
;
30 import org
.eclipse
.swt
.events
.MouseEvent
;
31 import org
.eclipse
.swt
.events
.SelectionAdapter
;
32 import org
.eclipse
.swt
.events
.SelectionEvent
;
33 import org
.eclipse
.swt
.graphics
.Point
;
34 import org
.eclipse
.swt
.layout
.FillLayout
;
35 import org
.eclipse
.swt
.layout
.GridData
;
36 import org
.eclipse
.swt
.layout
.GridLayout
;
37 import org
.eclipse
.swt
.widgets
.Button
;
38 import org
.eclipse
.swt
.widgets
.Combo
;
39 import org
.eclipse
.swt
.widgets
.Composite
;
40 import org
.eclipse
.swt
.widgets
.Dialog
;
41 import org
.eclipse
.swt
.widgets
.Display
;
42 import org
.eclipse
.swt
.widgets
.Label
;
43 import org
.eclipse
.swt
.widgets
.Shell
;
44 import org
.eclipse
.swt
.widgets
.Text
;
45 import org
.eclipse
.ui
.forms
.events
.ExpansionEvent
;
46 import org
.eclipse
.ui
.forms
.events
.IExpansionListener
;
47 import org
.eclipse
.ui
.forms
.widgets
.ExpandableComposite
;
48 import org
.eclipse
.ui
.progress
.IProgressConstants
;
49 import org
.eclipse
.wb
.swt
.SWTResourceManager
;
50 import org
.osgi
.service
.prefs
.BackingStoreException
;
51 import org
.osgi
.service
.prefs
.Preferences
;
53 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
54 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
;
55 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
56 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
57 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
58 import eu
.etaxonomy
.taxeditor
.remoting
.server
.CDMServerException
;
59 import eu
.etaxonomy
.taxeditor
.remoting
.server
.CDMServerUtils
;
60 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmRemoteSource
;
61 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
;
62 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
.CdmInstanceInfo
;
63 import eu
.etaxonomy
.taxeditor
.remoting
.source
.ICdmRemoteSource
;
64 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
65 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
66 import eu
.etaxonomy
.taxeditor
.webapp
.CDMEmbeddedServerException
;
67 import eu
.etaxonomy
.taxeditor
.webapp
.CDMServer
;
68 import eu
.etaxonomy
.taxeditor
.webapp
.ICDMServerError
;
76 public class RemotingLoginDialog
extends Dialog
implements ICDMServerError
{
78 protected Object result
;
79 protected Shell shlConnect
;
80 private Text txtCdmServerStatus
;
81 private Text txtCdmInstanceStatus
;
82 private Combo comboCdmServer
;
83 private Combo comboCdmInstance
;
84 private Button btnConnect
;
86 private final Map
<String
, CdmServerInfo
> csiiMap
= new HashMap
<String
, CdmServerInfo
>();
88 private final static String STATUS_AVAILABLE
= "Available";
89 private final static String STATUS_NOT_AVAILABLE
= "Not Available";
90 private final static String STATUS_STARTED
= "Started";
91 private final static String STATUS_NOT_STARTED
= "Not Started";
92 private final static String STATUS_RETRIEVING
= "Retrieving ...";
93 private final static String STATUS_CHECKING_AVAILABILITY
= "Checking ...";
94 private final static String STATUS_NO_INSTANCES
= "No Instances Found";
95 private final static String STATUS_ERROR
= "Error";
96 private final static String STATUS_REMOTING_NOT_ACTIVATED
= "Remoting not activated";
97 private final static String STATUS_NOT_COMPATIBLE
= "Not Compatible";
99 private final static String MESG_COMPATIBLE_EDITOR_OLD
= "Please update the Taxonomic Editor (Help->Check for Updates) or choose a compatible cdm-server";
100 private final static String MESG_COMPATIBLE_SERVER_OLD
= "Please choose a compatible cdm-server or update the chosen cdm-server";
102 private final static String STORE_PREFERENCES_NODE
= "eu.etaxonomy.taxeditor.store";
104 private final static String LOGIN_NODE
= "login";
105 private final static String USERNAME_SUFFIX
= "_username";
106 private final static String PASSWORD_SUFFIX
= "_password";
108 private final static String LAST_SERVER_INSTANCE_NODE
= "lastServerInstance";
109 private final static String LAST_SERVER_KEY
= "lastServerKey";
110 private final static String LAST_INSTANCE_KEY
= "lastInstanceKey";
112 private final static String REFRESH_LABEL
= "Refresh";
114 private Composite remotingComposite
;
115 private CdmServerInfo selectedCsii
;
116 private CdmInstanceInfo selectedCdmInstance
;
117 private Button btnCdmServerRefresh
;
118 private Button btnCdmInstanceRefresh
;
119 private Button btnStopServer
;
120 private Composite loginComposite
;
121 private Label lblLogin
;
122 private Text txtLogin
;
123 private Label lblPassword
;
124 private Text txtPassword
;
125 private Button btnRememberMe
;
126 private Composite compAdvanced
;
127 private Label lblPort
;
128 private Text txtPort
;
129 private Label lblServerVersion
;
130 private Text txtServerVersion
;
131 private ExpandableComposite xpndblcmpstAdvanced
;
132 private StyledText styledTxtMessage
;
135 private final int MIN_WIDTH
= 530;
136 private final int MIN_HEIGHT
= 220;
137 private final int MIN_EXP_HEIGHT
= 380;
138 private final int MESSAGE_HEIGHT
= 25;
139 private Label lblEditorVersion
;
140 private Text txtEditorVersion
;
141 private Label lblServerCDMVersion
;
142 private Text txtServerCDMVersion
;
143 private Label lblEditorCDMVersion
;
144 private Text txtEditorCDMVersion
;
146 private String serverName
, instanceName
;
147 private boolean autoConnect
= false;
148 private boolean loadLoginPrefs
= true;
149 private boolean isDevRemoteSource
= false;
150 private Job serverJob
;
156 public RemotingLoginDialog(Shell parent
, int style
) {
157 super(parent
, style
);
161 public Object
open(CdmRemoteSource source
, boolean loadLoginPrefs
, boolean autoConnect
) {
162 this.loadLoginPrefs
= loadLoginPrefs
;
163 this.serverName
= source
.getName();
164 String contextPath
= source
.getContextPath();
165 this.instanceName
= contextPath
.substring(contextPath
.lastIndexOf("/") + 1);
166 return open(serverName
, instanceName
, loadLoginPrefs
, autoConnect
);
170 public Object
open(String serverName
, String instanceName
, boolean loadLoginPrefs
, boolean autoConnect
) {
171 this.serverName
= serverName
;
172 this.instanceName
= instanceName
;
173 this.loadLoginPrefs
= loadLoginPrefs
;
174 this.autoConnect
= autoConnect
;
182 public Object
open() {
185 if(serverName
== null && instanceName
== null) {
186 readPrefLastServerInstance();
190 populateCdmServerCombo();
194 xpndblcmpstAdvanced
.setExpanded(false);
196 Display display
= getParent().getDisplay();
198 while (!shlConnect
.isDisposed()) {
199 if (!display
.readAndDispatch()) {
208 * Create contents of the dialog.
210 private void createContents() {
211 shlConnect
= new Shell(getParent(), SWT
.DIALOG_TRIM
);
212 shlConnect
.setMinimumSize(new Point(MIN_WIDTH
, MIN_HEIGHT
));
213 shlConnect
.setSize(MIN_WIDTH
, MIN_HEIGHT
);
214 shlConnect
.setText("Connect");
215 shlConnect
.setLayout(new FillLayout(SWT
.HORIZONTAL
));
217 remotingComposite
= new Composite(shlConnect
, SWT
.NONE
);
218 remotingComposite
.setLayout(new GridLayout(1, false));
220 Composite cdmServerComposite
= new Composite(remotingComposite
, SWT
.NONE
);
221 GridData gd_cdmServerComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
222 gd_cdmServerComposite
.heightHint
= 68;
223 cdmServerComposite
.setLayoutData(gd_cdmServerComposite
);
224 cdmServerComposite
.setLayout(new GridLayout(4, false));
226 Label lblCdmServer
= new Label(cdmServerComposite
, SWT
.NONE
);
227 lblCdmServer
.setText("CDM Server : ");
228 lblCdmServer
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
229 lblCdmServer
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
231 comboCdmServer
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
232 comboCdmServer
.addSelectionListener(new SelectionAdapter() {
234 public void widgetSelected(SelectionEvent e
) {
239 GridData gd_comboCdmServer
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
240 gd_comboCdmServer
.widthHint
= 150;
241 comboCdmServer
.setLayoutData(gd_comboCdmServer
);
242 comboCdmServer
.select(0);
244 txtCdmServerStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
245 txtCdmServerStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
246 txtCdmServerStatus
.setEditable(false);
247 GridData gd_txtCdmServerStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
248 gd_txtCdmServerStatus
.widthHint
= 100;
249 txtCdmServerStatus
.setLayoutData(gd_txtCdmServerStatus
);
251 btnCdmServerRefresh
= new Button(cdmServerComposite
, SWT
.NONE
);
252 btnCdmServerRefresh
.addSelectionListener(new SelectionAdapter() {
254 public void widgetSelected(SelectionEvent e
) {
258 btnCdmServerRefresh
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
259 btnCdmServerRefresh
.setText("Refresh");
261 Label lblCdmInstance
= new Label(cdmServerComposite
, SWT
.NONE
);
262 GridData gd_lblCdmInstance
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
263 gd_lblCdmInstance
.heightHint
= 30;
264 lblCdmInstance
.setLayoutData(gd_lblCdmInstance
);
265 lblCdmInstance
.setText("CDM Instance : ");
266 lblCdmInstance
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
268 comboCdmInstance
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
269 comboCdmInstance
.addSelectionListener(new SelectionAdapter() {
271 public void widgetSelected(SelectionEvent e
) {
272 refreshCdmInstance();
275 GridData gd_comboCdmInstance
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
276 gd_comboCdmInstance
.widthHint
= 150;
277 comboCdmInstance
.setLayoutData(gd_comboCdmInstance
);
278 comboCdmInstance
.select(0);
280 txtCdmInstanceStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
281 txtCdmInstanceStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
282 txtCdmInstanceStatus
.setEditable(false);
283 GridData gd_txtCdmInstanceStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
284 gd_txtCdmInstanceStatus
.widthHint
= 100;
285 txtCdmInstanceStatus
.setLayoutData(gd_txtCdmInstanceStatus
);
287 btnCdmInstanceRefresh
= new Button(cdmServerComposite
, SWT
.FLAT
);
288 btnCdmInstanceRefresh
.addSelectionListener(new SelectionAdapter() {
290 public void widgetSelected(SelectionEvent e
) {
291 refreshCdmInstance();
294 GridData gd_btnCdmInstanceRefresh
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
295 gd_btnCdmInstanceRefresh
.widthHint
= 110;
296 gd_btnCdmInstanceRefresh
.heightHint
= 30;
297 btnCdmInstanceRefresh
.setLayoutData(gd_btnCdmInstanceRefresh
);
298 btnCdmInstanceRefresh
.setText("Refresh");
300 loginComposite
= new Composite(remotingComposite
, SWT
.NONE
);
301 GridData gd_loginComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
302 gd_loginComposite
.widthHint
= 487;
303 gd_loginComposite
.heightHint
= 70;
304 loginComposite
.setLayoutData(gd_loginComposite
);
305 GridLayout gl_loginComposite
= new GridLayout(6, false);
306 gl_loginComposite
.marginTop
= 5;
307 loginComposite
.setLayout(gl_loginComposite
);
309 lblLogin
= new Label(loginComposite
, SWT
.CENTER
);
310 GridData gd_lblLogin
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
311 gd_lblLogin
.widthHint
= 50;
312 lblLogin
.setLayoutData(gd_lblLogin
);
313 lblLogin
.setText("Login : ");
314 lblLogin
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
316 txtLogin
= new Text(loginComposite
, SWT
.BORDER
);
317 GridData gd_txtLogin
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
318 gd_txtLogin
.minimumWidth
= 80;
319 gd_txtLogin
.widthHint
= 80;
320 gd_txtLogin
.heightHint
= 15;
321 txtLogin
.setLayoutData(gd_txtLogin
);
323 lblPassword
= new Label(loginComposite
, SWT
.CENTER
);
324 lblPassword
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
325 lblPassword
.setText("Password : ");
326 lblPassword
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
328 txtPassword
= new Text(loginComposite
, SWT
.BORDER
| SWT
.PASSWORD
);
329 GridData gd_txtPassword
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
330 gd_txtPassword
.minimumWidth
= 80;
331 gd_txtPassword
.widthHint
= 80;
332 gd_txtPassword
.heightHint
= 15;
333 txtPassword
.setLayoutData(gd_txtPassword
);
334 new Label(loginComposite
, SWT
.NONE
);
336 btnConnect
= new Button(loginComposite
, SWT
.FLAT
);
337 btnConnect
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1));
338 btnConnect
.addMouseListener(new MouseAdapter() {
340 public void mouseUp(MouseEvent e
) {
341 if(selectedCsii
.isLocalhostMgd() && !isSelectedCdmInstanceRunningInManagedServer()) {
342 startManagedServer();
348 btnConnect
.setText("Connect");
350 btnRememberMe
= new Button(loginComposite
, SWT
.CHECK
);
351 btnRememberMe
.setSelection(true);
352 GridData gd_btnRememberMe
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 2, 1);
353 gd_btnRememberMe
.widthHint
= 107;
354 btnRememberMe
.setLayoutData(gd_btnRememberMe
);
355 btnRememberMe
.setText("Remember Me");
356 new Label(loginComposite
, SWT
.NONE
);
357 new Label(loginComposite
, SWT
.NONE
);
358 new Label(loginComposite
, SWT
.NONE
);
359 new Label(loginComposite
, SWT
.NONE
);
361 styledTxtMessage
= new StyledText(remotingComposite
, SWT
.NONE
);
362 styledTxtMessage
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
363 styledTxtMessage
.setForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
364 styledTxtMessage
.setFont(SWTResourceManager
.getFont("Ubuntu", 12, SWT
.BOLD
));
365 styledTxtMessage
.setSelectionBackground(SWTResourceManager
.getColor(SWT
.COLOR_LIST_SELECTION_TEXT
));
366 styledTxtMessage
.setSelectionForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
367 styledTxtMessage
.setDoubleClickEnabled(false);
368 styledTxtMessage
.setEditable(false);
369 GridData gd_styledTxtMessage
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
370 gd_styledTxtMessage
.exclude
= true;
371 gd_styledTxtMessage
.minimumHeight
= MESSAGE_HEIGHT
;
372 gd_styledTxtMessage
.heightHint
= MESSAGE_HEIGHT
;
373 styledTxtMessage
.setLayoutData(gd_styledTxtMessage
);
375 xpndblcmpstAdvanced
= new ExpandableComposite(remotingComposite
, SWT
.NONE
, ExpandableComposite
.TWISTIE
);
376 GridData gd_xpndblcmpstAdvanced
= new GridData(SWT
.FILL
, SWT
.FILL
, false, true, 1, 1);
377 gd_xpndblcmpstAdvanced
.heightHint
= 19;
378 xpndblcmpstAdvanced
.setLayoutData(gd_xpndblcmpstAdvanced
);
379 xpndblcmpstAdvanced
.addExpansionListener(new IExpansionListener() {
381 public void expansionStateChanged(ExpansionEvent e
) {
382 GridData gridData
= (GridData
) xpndblcmpstAdvanced
.getLayoutData();
384 shlConnect
.setSize(MIN_WIDTH
, MIN_EXP_HEIGHT
);
386 shlConnect
.setSize(MIN_WIDTH
, MIN_HEIGHT
);
391 public void expansionStateChanging(ExpansionEvent e
) {
394 xpndblcmpstAdvanced
.setText("advanced");
395 xpndblcmpstAdvanced
.setExpanded(true);
397 compAdvanced
= new Composite(xpndblcmpstAdvanced
, SWT
.NONE
);
398 xpndblcmpstAdvanced
.setClient(compAdvanced
);
399 compAdvanced
.setLayout(new GridLayout(4, false));
401 lblPort
= new Label(compAdvanced
, SWT
.CENTER
);
402 lblPort
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
403 lblPort
.setSize(0, 0);
404 lblPort
.setText("Port : ");
405 lblPort
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
407 txtPort
= new Text(compAdvanced
, SWT
.BORDER
);
408 GridData gd_txtPort
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1);
409 gd_txtPort
.minimumWidth
= 50;
410 gd_txtPort
.widthHint
= 50;
411 txtPort
.setLayoutData(gd_txtPort
);
413 lblServerVersion
= new Label(compAdvanced
, SWT
.CENTER
);
414 lblServerVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
415 lblServerVersion
.setText("Server Cdmlib Version :");
416 lblServerVersion
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
418 txtServerVersion
= new Text(compAdvanced
, SWT
.BORDER
);
419 txtServerVersion
.setEditable(false);
420 txtServerVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
421 btnStopServer
= new Button(compAdvanced
, SWT
.FLAT
);
422 btnStopServer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 2, 1));
423 btnStopServer
.addMouseListener(new MouseAdapter() {
425 public void mouseUp(MouseEvent e
) {
429 btnStopServer
.setText("Stop Managed Server");
431 lblEditorVersion
= new Label(compAdvanced
, SWT
.CENTER
);
432 lblEditorVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
433 lblEditorVersion
.setText("Editor Cdmlib Version :");
434 lblEditorVersion
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
436 txtEditorVersion
= new Text(compAdvanced
, SWT
.BORDER
);
437 txtEditorVersion
.setEditable(false);
438 txtEditorVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
439 new Label(compAdvanced
, SWT
.NONE
);
440 new Label(compAdvanced
, SWT
.NONE
);
442 lblServerCDMVersion
= new Label(compAdvanced
, SWT
.CENTER
);
443 lblServerCDMVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
444 lblServerCDMVersion
.setText("Server CDM Version :");
445 lblServerCDMVersion
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
447 txtServerCDMVersion
= new Text(compAdvanced
, SWT
.BORDER
);
448 txtServerCDMVersion
.setEditable(false);
449 txtServerCDMVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
450 new Label(compAdvanced
, SWT
.NONE
);
451 new Label(compAdvanced
, SWT
.NONE
);
453 lblEditorCDMVersion
= new Label(compAdvanced
, SWT
.CENTER
);
454 lblEditorCDMVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
455 lblEditorCDMVersion
.setText("Editor CDM Version :");
456 lblEditorCDMVersion
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
458 txtEditorCDMVersion
= new Text(compAdvanced
, SWT
.BORDER
);
459 txtEditorCDMVersion
.setEditable(false);
460 txtEditorCDMVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
466 private void populateCdmServerCombo() {
467 Job job
= new Job("Retrieve Server Instances") {
469 protected IStatus
run(IProgressMonitor monitor
) {
470 Display
.getDefault().syncExec(new Runnable() {
473 for(CdmServerInfo csii
: CdmServerInfo
.getCdmServers()) {
474 csiiMap
.put(csii
.getName(), csii
);
475 comboCdmServer
.add(csii
.getName());
477 int serverIndex
= -1;
478 if(serverName
!= null) {
479 serverIndex
= comboCdmServer
.indexOf(serverName
);
481 if(serverIndex
== -1) {
482 comboCdmServer
.select(0);
485 comboCdmServer
.select(serverIndex
);
487 CdmRemoteSource devRemoteSource
= CdmServerInfo
.getDevServerRemoteSource();
488 if(devRemoteSource
!= null) {
489 isDevRemoteSource
= true;
494 if(devRemoteSource
!= null) {
495 String username
= System
.getProperty("cdm.server.dev.username");
496 String password
= System
.getProperty("cdm.server.dev.password");
497 if(username
!= null && !username
.isEmpty() && password
!= null && !password
.isEmpty()) {
498 txtLogin
.setText(username
);
499 txtPassword
.setText(password
);
500 CdmStore
.connect(devRemoteSource
, RemotingLoginDialog
.this);
505 return Status
.OK_STATUS
;
512 private void refreshCdmServer() {
513 txtCdmServerStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
514 updateSelectedCdmServer();
515 checkSelectedCdmServer();
518 private void updateSelectedCdmServer() {
519 int selIndex
= comboCdmServer
.getSelectionIndex();
521 selectedCsii
= csiiMap
.get(comboCdmServer
.getItem(selIndex
));
525 private void updatePort() {
527 if(selectedCsii
!= null) {
528 int port
= selectedCsii
.getPort();
529 if(port
== CdmServerInfo
.NULL_PORT
) {
530 txtPort
.setText(CdmServerInfo
.NULL_PORT_STRING
);
532 txtPort
.setText(String
.valueOf(port
));
537 private int getPort() {
538 int port
= CdmServerInfo
.NULL_PORT
;
540 port
= Integer
.valueOf(txtPort
.getText());
541 } catch (NumberFormatException nfe
) {
542 if(!CdmServerInfo
.NULL_PORT_STRING
.equals(txtPort
.getText())) {
543 setMessage("Port should be an integer");
549 private void checkSelectedCdmServer() {
551 clearOnServerChange();
554 if(selectedCsii
!= null) {
555 if(selectedCsii
.isLocalhost()) {
556 txtPort
.setEditable(true);
557 txtPort
.setEnabled(true);
559 if(selectedCsii
.pingServer()) {
560 txtCdmServerStatus
.setText(STATUS_AVAILABLE
);
561 populateCdmInstanceCombo(true);
562 String serverVersionTimestamp
= generateLastModifiedTooltip(selectedCsii
.getCdmlibLastModified());
563 txtServerVersion
.setText(selectedCsii
.getCdmlibServicesVersion() + ":" + serverVersionTimestamp
);
565 txtCdmServerStatus
.setText(STATUS_NOT_AVAILABLE
);
566 comboCdmInstance
.removeAll();
572 private void populateCdmInstanceCombo(final boolean forceRefresh
) {
573 comboCdmInstance
.removeAll();
574 comboCdmInstance
.setEnabled(false);
575 btnConnect
.setEnabled(false);
576 txtCdmInstanceStatus
.setText(STATUS_RETRIEVING
);
577 txtCdmInstanceStatus
.setToolTipText("");
579 serverJob
= new Job("Retrieve Server Instances") {
581 protected IStatus
run(IProgressMonitor monitor
) {
583 if(selectedCsii
!= null) {
585 selectedCsii
.refreshInstances();
587 final List
<CdmInstanceInfo
> instances
= selectedCsii
.getInstances();
588 Display
.getDefault().asyncExec(new Runnable() {
591 if(!instances
.isEmpty()) {
592 for(CdmInstanceInfo cdmInstance
: instances
) {
593 comboCdmInstance
.add(cdmInstance
.getName());
595 int instanceIndex
= -1;
596 if(instanceName
!= null) {
597 instanceIndex
= comboCdmInstance
.indexOf(instanceName
);
599 if(instanceIndex
== -1) {
600 comboCdmInstance
.select(0);
603 comboCdmInstance
.select(instanceIndex
);
605 refreshCdmInstance();
606 comboCdmInstance
.setEnabled(true);
612 txtCdmInstanceStatus
.setText(STATUS_NO_INSTANCES
);
613 btnConnect
.setEnabled(false);
618 } catch (final CDMServerException e
) {
619 MessagingUtils
.warn(getClass(), e
);
620 Display
.getDefault().asyncExec(new Runnable() {
623 txtCdmInstanceStatus
.setText(STATUS_NOT_AVAILABLE
);
624 txtCdmInstanceStatus
.setToolTipText(e
.getMessage());
625 comboCdmInstance
.setEnabled(false);
626 btnConnect
.setEnabled(false);
630 return Status
.OK_STATUS
;
634 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
) && !isDevRemoteSource
) {
636 serverJob
.schedule();
642 private void refreshCdmInstance() {
643 txtCdmInstanceStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
644 clearOnInstanceChange();
645 updateSelectedCdmInstance();
646 checkSelectedCdmInstance();
647 updateManagedServerControls();
650 private void updateSelectedCdmInstance() {
651 int selIndex
= comboCdmInstance
.getSelectionIndex();
653 selectedCdmInstance
= selectedCsii
.getInstanceFromName(comboCdmInstance
.getItem(selIndex
));
655 if(loadLoginPrefs
&& !isDevRemoteSource
) {
656 readPrefCredentials();
661 private void updateManagedServerControls() {
662 if(selectedCsii
.isLocalhostMgd()) {
663 if(isSelectedCdmInstanceRunningInManagedServer()) {
664 txtCdmInstanceStatus
.setText(STATUS_STARTED
);
666 txtCdmInstanceStatus
.setText(STATUS_NOT_STARTED
);
668 btnConnect
.setEnabled(true);
669 selectedCsii
.setPort(getManagedServerPort());
674 if(isManagedServerRunning()) {
675 btnStopServer
.setEnabled(true);
677 btnStopServer
.setEnabled(false);
681 private boolean isManagedServerRunning() {
682 return CdmStore
.getManagedServer() != null && CdmStore
.getManagedServer().isAlive();
685 private boolean isSelectedCdmInstanceRunningInManagedServer() {
686 return CdmStore
.getManagedServer() != null &&
687 CdmStore
.getManagedServer().isAlive() &&
688 selectedCsii
.isLocalhostMgd() &&
689 CdmStore
.getManagedServer().getDataSourceName().equals(selectedCdmInstance
.getName());
692 private boolean isActiveCdmInstanceRunningInManagedServer() {
693 return CdmStore
.getManagedServer() != null &&
694 CdmStore
.getManagedServer().isAlive() &&
695 CdmStore
.isActive() &&
696 CdmServerInfo
.NAME_LOCALHOST_MGD
.equals(CdmStore
.getActiveCdmSource().getName());
700 private void startManagedServer() {
701 if(isManagedServerRunning()) {
702 if(CdmStore
.getManagedServer().getDataSourceName().equals(selectedCdmInstance
.getName())) {
705 Display
.getDefault().syncExec(new Runnable() {
715 Job job
= new Job("Managed CDM Server Launch") {
718 public IStatus
run(IProgressMonitor monitor
) {
719 String mgdServerConfigFileName
= "mgd.datasources.xml";
720 String config
= CDMServerUtils
.convertEditorToServerConfig();
721 File managedServerConfigFile
;
723 monitor
.beginTask("Launching Managed CDM Server", maxUnits
);
725 monitor
.subTask("Generating datasources config file for " + selectedCdmInstance
.getName());
726 managedServerConfigFile
= CDMServerUtils
.writeManagedServerConfig(config
, mgdServerConfigFileName
);
728 CdmStore
.setManagedServer(new CDMServer(selectedCdmInstance
.getName(), managedServerConfigFile
));
729 monitor
.subTask("Starting Managed CDM Server. This may take a while.");
730 CdmStore
.getManagedServer().start(false, RemotingLoginDialog
.this);
733 // the following loop is a 'fake' progress monitoring where the progress
734 // bar is advanced by one unit every second until maxUnits -2
735 while(!CdmStore
.getManagedServer().isStarted()) {
736 if(serverUnits
< maxUnits
- 2) {
739 } catch (InterruptedException e
) {
745 Display
.getDefault().asyncExec(new Runnable() {
749 updateManagedServerControls();
753 } catch (IOException ioe
) {
754 MessagingUtils
.errorDialog("Error generating server config file",
757 TaxeditorStorePlugin
.PLUGIN_ID
,
760 } catch (CDMEmbeddedServerException cse
) {
761 MessagingUtils
.errorDialog("Error starting managed server",
764 TaxeditorStorePlugin
.PLUGIN_ID
,
770 return Status
.OK_STATUS
;
775 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);
782 private void stopManagedServer() {
784 CdmStore
.getManagedServer().stop();
785 } catch (Exception e
) {
786 MessagingUtils
.errorDialog("Error stopping managed server",
788 "Could not stop managed server running at port " + CdmStore
.getManagedServer().getPort() + ". Please stop it manually",
789 TaxeditorStorePlugin
.PLUGIN_ID
,
793 CdmStore
.setManagedServer(null);
794 updateManagedServerControls();
797 private int getManagedServerPort() {
798 return CdmStore
.getManagedServer() == null ? CdmServerInfo
.NULL_PORT
: CdmStore
.getManagedServer().getPort();
801 private void checkSelectedCdmInstance() {
802 boolean available
= false;
803 String status
= STATUS_NOT_AVAILABLE
;
804 String message
= null;
806 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
)) {
808 if(selectedCsii
.pingInstance(selectedCdmInstance
, getPort())) {
809 status
= STATUS_AVAILABLE
;
812 status
= STATUS_NOT_AVAILABLE
;
817 txtServerCDMVersion
.setText(selectedCsii
.getCdmRemoteSource(selectedCdmInstance
, getPort()).getDbSchemaVersion());
818 int compareDbSchemaVersion
= selectedCsii
.compareDbSchemaVersion(selectedCdmInstance
, getPort());
819 int compareCdmlibServicesVersion
= 0;
820 boolean disableServicesApiTimestampCheck
=
821 PreferencesUtil
.getPreferenceStore().getBoolean((IPreferenceKeys
.DISABLE_SERVICES_API_TIMESTAMP_CHECK
));
822 if(!disableServicesApiTimestampCheck
) {
823 compareCdmlibServicesVersion
= selectedCsii
.compareCdmlibServicesVersion();
825 if(compareDbSchemaVersion
> 0 || compareCdmlibServicesVersion
> 0) {
826 status
= STATUS_NOT_COMPATIBLE
;
828 message
= MESG_COMPATIBLE_EDITOR_OLD
;
829 } else if(compareDbSchemaVersion
< 0 || compareCdmlibServicesVersion
< 0) {
830 status
= STATUS_NOT_COMPATIBLE
;
832 message
= MESG_COMPATIBLE_SERVER_OLD
;
834 status
= STATUS_AVAILABLE
;
839 } catch (Exception e
) {
840 txtCdmInstanceStatus
.setToolTipText(e
.getMessage());
842 btnConnect
.setEnabled(available
);
843 txtCdmInstanceStatus
.setText(status
);
844 if(!StringUtils
.isBlank(message
)) {
851 private void connect() {
852 checkSelectedCdmInstance();
854 if(!txtCdmInstanceStatus
.getText().equals(STATUS_AVAILABLE
)) {
858 ICdmRemoteSource source
= selectedCsii
.getCdmRemoteSource(selectedCdmInstance
, getPort());
860 if(!validateLogin()) {
865 CdmStore
.connect(source
, this);
866 } catch (Exception e
) {
867 // Do not expect anything to go wrong at this point, so we throw a runtime exception
869 throw new RuntimeException(e
);
875 public boolean isRememberMe() {
876 return btnRememberMe
.getSelection();
879 private void persistPrefLastServerInstance() {
880 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
881 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
883 lastServerInstancePrefs
.put(LAST_SERVER_KEY
, selectedCsii
.getName());
884 lastServerInstancePrefs
.put(LAST_INSTANCE_KEY
, selectedCdmInstance
.getName());
886 flushPreferences(lastServerInstancePrefs
);
889 private void persistPrefCredentials() {
890 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
891 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
892 credentialsPrefs
.put(getUsernamePrefKey(), txtLogin
.getText());
893 credentialsPrefs
.put(getPasswordPrefKey(), txtPassword
.getText());
894 flushPreferences(credentialsPrefs
);
897 private void flushPreferences(Preferences prefs
) {
900 } catch (BackingStoreException bse
) {
901 setMessage(bse
.getMessage());
905 private void readPrefCredentials() {
906 String username
, password
;
907 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
908 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
909 username
= credentialsPrefs
.get(getUsernamePrefKey(), "");
910 txtLogin
.setText(username
);
911 password
= credentialsPrefs
.get(getPasswordPrefKey(),"");
912 txtPassword
.setText(password
);
913 if(username
.isEmpty() || password
.isEmpty()) {
918 private void readPrefLastServerInstance() {
919 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
920 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
922 serverName
= lastServerInstancePrefs
.get(LAST_SERVER_KEY
, null);
923 instanceName
= lastServerInstancePrefs
.get(LAST_INSTANCE_KEY
, null);
926 private void emptyCredentials() {
927 txtLogin
.setText("");
928 txtPassword
.setText("");
931 private String
getUsernamePrefKey() {
932 return selectedCsii
.toString(selectedCdmInstance
.getName(), getPort()) + USERNAME_SUFFIX
;
935 private String
getPasswordPrefKey() {
936 return selectedCsii
.toString(selectedCdmInstance
.getName(), getPort()) + PASSWORD_SUFFIX
;
939 private boolean validateLogin() {
940 if(getUsername() == null || getUsername().isEmpty()) {
941 setMessage("User login cannot be empty");
944 if(getPassword() == null || getPassword().isEmpty()) {
945 setMessage("Password cannot be empty");
950 public String
getUsername() {
951 return txtLogin
.getText();
954 public String
getPassword() {
955 return txtPassword
.getText();
958 public void setMessage(String message
) {
959 if(message
!= null && !message
.isEmpty()) {
960 if(message
.length() > 60) {
961 styledTxtMessage
.setToolTipText(message
);
962 message
= message
.substring(0, 60) + "...";
964 styledTxtMessage
.setText(message
);
965 styledTxtMessage
.setVisible(true);
966 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= false;
967 shlConnect
.setSize(MIN_WIDTH
, getHeightWithoutMessage() + MESSAGE_HEIGHT
);
968 shlConnect
.setMinimumSize(MIN_WIDTH
, getHeightWithoutMessage() + MESSAGE_HEIGHT
);
970 styledTxtMessage
.setText("");
971 styledTxtMessage
.setVisible(false);
972 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= true;
973 shlConnect
.setSize(MIN_WIDTH
, getHeightWithoutMessage());
974 shlConnect
.setMinimumSize(MIN_WIDTH
, getHeightWithoutMessage());
976 remotingComposite
.layout();
979 private int getHeightWithoutMessage() {
980 if(xpndblcmpstAdvanced
.isExpanded()) {
981 return MIN_EXP_HEIGHT
;
988 public void hide(boolean isHidden
) {
989 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
990 shlConnect
.setVisible(!isHidden
);
993 public void dispose() {
994 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
995 shlConnect
.dispose();
999 public void onComplete() {
1000 Display
.getDefault().asyncExec(new Runnable() {
1003 if(!isDevRemoteSource
) {
1004 if(isRememberMe()) {
1005 persistPrefCredentials();
1007 persistPrefLastServerInstance();
1014 private String
generateLastModifiedTooltip(String cdmlibLastModified
) {
1015 if(StringUtils
.isBlank(cdmlibLastModified
)) {
1018 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy.MM.dd.HH.mm.z");
1019 Date cdmlibLastModifiedDate
;
1020 String cdmlibLastModifiedTimestamp
= "";
1022 cdmlibLastModifiedDate
= new Date(Long
.valueOf(cdmlibLastModified
));
1023 cdmlibLastModifiedTimestamp
= sdf
.format(cdmlibLastModifiedDate
);
1025 return cdmlibLastModifiedTimestamp
;
1028 private void setEditorInfo() {
1029 txtEditorCDMVersion
.setText(CdmMetaData
.getDbSchemaVersion());
1030 String editorVersionTimestamp
= generateLastModifiedTooltip(CdmApplicationState
.getCdmlibLastModified());
1031 txtEditorVersion
.setText(CdmApplicationState
.getCdmlibVersion() + ":" + editorVersionTimestamp
);
1034 private void clearOnServerChange() {
1036 txtServerCDMVersion
.setText("");
1037 txtServerVersion
.setText("");
1038 txtServerVersion
.setToolTipText("");
1039 txtServerCDMVersion
.setText("");
1040 txtPort
.setEditable(false);
1041 txtPort
.setEnabled(false);
1044 private void clearOnInstanceChange() {
1046 txtServerCDMVersion
.setText("");
1053 public void handleError(final Throwable t
) {
1055 Display
.getDefault().syncExec(new Runnable() {
1060 String title
= "CDM Server launch error";
1061 String message
= t
.getMessage();
1064 MessagingUtils
.errorDialog(title
,
1067 TaxeditorStorePlugin
.PLUGIN_ID
,