2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.dialog
;
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
;
19 import org
.apache
.commons
.lang
.StringUtils
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.core
.runtime
.IStatus
;
22 import org
.eclipse
.core
.runtime
.Status
;
23 import org
.eclipse
.core
.runtime
.jobs
.Job
;
24 import org
.eclipse
.core
.runtime
.preferences
.ConfigurationScope
;
25 import org
.eclipse
.core
.runtime
.preferences
.IEclipsePreferences
;
26 import org
.eclipse
.swt
.SWT
;
27 import org
.eclipse
.swt
.custom
.StyledText
;
28 import org
.eclipse
.swt
.events
.KeyAdapter
;
29 import org
.eclipse
.swt
.events
.KeyEvent
;
30 import org
.eclipse
.swt
.events
.MouseAdapter
;
31 import org
.eclipse
.swt
.events
.MouseEvent
;
32 import org
.eclipse
.swt
.events
.SelectionAdapter
;
33 import org
.eclipse
.swt
.events
.SelectionEvent
;
34 import org
.eclipse
.swt
.graphics
.Point
;
35 import org
.eclipse
.swt
.layout
.FillLayout
;
36 import org
.eclipse
.swt
.layout
.GridData
;
37 import org
.eclipse
.swt
.layout
.GridLayout
;
38 import org
.eclipse
.swt
.widgets
.Button
;
39 import org
.eclipse
.swt
.widgets
.Combo
;
40 import org
.eclipse
.swt
.widgets
.Composite
;
41 import org
.eclipse
.swt
.widgets
.Dialog
;
42 import org
.eclipse
.swt
.widgets
.Display
;
43 import org
.eclipse
.swt
.widgets
.Label
;
44 import org
.eclipse
.swt
.widgets
.Shell
;
45 import org
.eclipse
.swt
.widgets
.Text
;
46 import org
.eclipse
.ui
.forms
.events
.ExpansionEvent
;
47 import org
.eclipse
.ui
.forms
.events
.IExpansionListener
;
48 import org
.eclipse
.ui
.forms
.widgets
.ExpandableComposite
;
49 import org
.eclipse
.ui
.progress
.IProgressConstants
;
50 import org
.eclipse
.wb
.swt
.SWTResourceManager
;
51 import org
.osgi
.service
.prefs
.BackingStoreException
;
52 import org
.osgi
.service
.prefs
.Preferences
;
53 import org
.springframework
.security
.authentication
.BadCredentialsException
;
54 import org
.springframework
.security
.authentication
.LockedException
;
55 import org
.springframework
.security
.authentication
.UsernamePasswordAuthenticationToken
;
57 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationRemoteConfiguration
;
58 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
59 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
60 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
;
61 import eu
.etaxonomy
.taxeditor
.Messages
;
62 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
63 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
64 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
65 import eu
.etaxonomy
.taxeditor
.remoting
.server
.CDMServerException
;
66 import eu
.etaxonomy
.taxeditor
.remoting
.server
.CDMServerUtils
;
67 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmRemoteSource
;
68 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
;
69 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
.CdmInstanceInfo
;
70 import eu
.etaxonomy
.taxeditor
.remoting
.source
.ICdmRemoteSource
;
71 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
72 import eu
.etaxonomy
.taxeditor
.store
.LoginManager
;
73 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
74 import eu
.etaxonomy
.taxeditor
.webapp
.CDMEmbeddedServerException
;
75 import eu
.etaxonomy
.taxeditor
.webapp
.CDMServer
;
76 import eu
.etaxonomy
.taxeditor
.webapp
.ICDMServerError
;
84 public class RemotingLoginDialog
extends Dialog
implements ICDMServerError
{
86 private static final String UBUNTU
= "Ubuntu"; //$NON-NLS-1$
87 protected Object result
;
88 protected Shell shlConnect
;
89 private Text txtCdmServerStatus
;
90 private Text txtCdmInstanceStatus
;
91 private Combo comboCdmServer
;
92 private Combo comboCdmInstance
;
93 private Button btnConnect
;
95 private final Map
<String
, CdmServerInfo
> csiiMap
= new HashMap
<String
, CdmServerInfo
>();
97 private final static String STATUS_AVAILABLE
= Messages
.RemotingLoginDialog_STATUS_AVAILABLE
;
98 private final static String STATUS_NOT_AVAILABLE
= Messages
.RemotingLoginDialog_STATUS_NOT_AVAILABLE
;
99 private final static String STATUS_STARTED
= Messages
.RemotingLoginDialog_STATUS_STARTED
;
100 private final static String STATUS_NOT_STARTED
= Messages
.RemotingLoginDialog_STATUS_NOT_STARTED
;
101 private final static String STATUS_RETRIEVING
= Messages
.RemotingLoginDialog_STATUS_RETRIEVING
;
102 private final static String STATUS_CHECKING_AVAILABILITY
= Messages
.RemotingLoginDialog_STATUS_CHECKING
;
103 private final static String STATUS_NO_INSTANCES
= Messages
.RemotingLoginDialog_STATUS_NO_INSTANCES_FOUND
;
104 private final static String STATUS_ERROR
= Messages
.RemotingLoginDialog_STATUS_ERROR
;
105 private final static String STATUS_REMOTING_NOT_ACTIVATED
= Messages
.RemotingLoginDialog_STATUS_REMOTING_NOT_ACTIVATED
;
106 private final static String STATUS_NOT_COMPATIBLE
= Messages
.RemotingLoginDialog_STATUS_NOT_COMPATIBLE
;
108 private final static String MESG_COMPATIBLE_EDITOR_OLD
= Messages
.RemotingLoginDialog_UPDATE_EDITOR
;
109 private final static String MESG_COMPATIBLE_SERVER_OLD
= Messages
.RemotingLoginDialog_CHOOSE_COMPATIBLE_CDM_SERVER
;
111 private final static String STORE_PREFERENCES_NODE
= "eu.etaxonomy.taxeditor.store"; //$NON-NLS-1$
113 private final static String LOGIN_NODE
= "login"; //$NON-NLS-1$
114 private final static String USERNAME_SUFFIX
= "_username"; //$NON-NLS-1$
115 private final static String PASSWORD_SUFFIX
= "_password"; //$NON-NLS-1$
117 private final static String LAST_SERVER_INSTANCE_NODE
= "lastServerInstance"; //$NON-NLS-1$
118 private final static String LAST_SERVER_KEY
= "lastServerKey"; //$NON-NLS-1$
119 private final static String LAST_INSTANCE_KEY
= "lastInstanceKey"; //$NON-NLS-1$
121 private final static String REFRESH_LABEL
= Messages
.RemotingLoginDialog_LABEL_REFRESH
;
123 private Composite remotingComposite
;
124 private CdmServerInfo selectedCsii
;
125 private CdmInstanceInfo selectedCdmInstance
;
126 private Button btnCdmServerRefresh
;
127 private Button btnCdmInstanceRefresh
;
128 private Button btnStopServer
;
129 private Composite loginComposite
;
130 private Label lblLogin
;
131 private Text txtLogin
;
132 private Label lblPassword
;
133 private Text txtPassword
;
134 private Button btnRememberMe
;
135 private Composite compAdvanced
;
136 private Label lblPort
;
137 private Text txtPort
;
138 private Label lblServerVersion
;
139 private Text txtServerVersion
;
140 private ExpandableComposite xpndblcmpstAdvanced
;
141 private StyledText styledTxtMessage
;
144 private final int MIN_WIDTH
= 530;
145 private final int MIN_HEIGHT
= 220;
146 private final int MIN_EXP_HEIGHT
= 380;
147 private final int MESSAGE_HEIGHT
= 25;
148 private Label lblEditorVersion
;
149 private Text txtEditorVersion
;
150 private Label lblServerCDMVersion
;
151 private Text txtServerCDMVersion
;
152 private Label lblEditorCDMVersion
;
153 private Text txtEditorCDMVersion
;
155 private String serverName
, instanceName
;
156 private boolean autoConnect
= false;
157 private boolean loadLoginPrefs
= true;
158 private boolean isDevRemoteSource
= false;
159 private Job serverJob
;
165 public RemotingLoginDialog(Shell parent
, int style
) {
166 super(parent
, style
);
167 setText(Messages
.RemotingLoginDialog_LABEL_LOGIN
);
170 public Object
open(CdmRemoteSource source
, boolean loadLoginPrefs
, boolean autoConnect
) {
171 this.loadLoginPrefs
= loadLoginPrefs
;
172 this.serverName
= source
.getName();
173 String contextPath
= source
.getContextPath();
174 this.instanceName
= contextPath
.substring(contextPath
.lastIndexOf("/") + 1); //$NON-NLS-1$
175 return open(serverName
, instanceName
, loadLoginPrefs
, autoConnect
);
179 public Object
open(String serverName
, String instanceName
, boolean loadLoginPrefs
, boolean autoConnect
) {
180 this.serverName
= serverName
;
181 this.instanceName
= instanceName
;
182 this.loadLoginPrefs
= loadLoginPrefs
;
183 this.autoConnect
= autoConnect
;
191 public Object
open() {
194 if(serverName
== null && instanceName
== null) {
195 readPrefLastServerInstance();
199 populateCdmServerCombo();
203 xpndblcmpstAdvanced
.setExpanded(false);
205 Display display
= getParent().getDisplay();
207 while (!shlConnect
.isDisposed()) {
208 if (!display
.readAndDispatch()) {
217 * Create contents of the dialog.
219 private void createContents() {
220 shlConnect
= new Shell(getParent(), SWT
.DIALOG_TRIM
);
221 shlConnect
.setMinimumSize(new Point(MIN_WIDTH
, MIN_HEIGHT
));
222 shlConnect
.setSize(MIN_WIDTH
, MIN_HEIGHT
);
223 shlConnect
.setText(Messages
.RemotingLoginDialog_LABEL_CONNECT
);
224 shlConnect
.setLayout(new FillLayout(SWT
.HORIZONTAL
));
226 remotingComposite
= new Composite(shlConnect
, SWT
.NONE
);
227 remotingComposite
.setLayout(new GridLayout(1, false));
229 Composite cdmServerComposite
= new Composite(remotingComposite
, SWT
.NONE
);
230 GridData gd_cdmServerComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
231 gd_cdmServerComposite
.heightHint
= 68;
232 cdmServerComposite
.setLayoutData(gd_cdmServerComposite
);
233 cdmServerComposite
.setLayout(new GridLayout(4, false));
235 Label lblCdmServer
= new Label(cdmServerComposite
, SWT
.NONE
);
236 lblCdmServer
.setText(Messages
.RemotingLoginDialog_LABEL_CDM_SERVER
);
237 lblCdmServer
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
238 lblCdmServer
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
240 comboCdmServer
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
241 comboCdmServer
.addSelectionListener(new SelectionAdapter() {
243 public void widgetSelected(SelectionEvent e
) {
248 GridData gd_comboCdmServer
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
249 gd_comboCdmServer
.widthHint
= 150;
250 comboCdmServer
.setLayoutData(gd_comboCdmServer
);
251 comboCdmServer
.select(0);
253 txtCdmServerStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
254 txtCdmServerStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
255 txtCdmServerStatus
.setEditable(false);
256 GridData gd_txtCdmServerStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
257 gd_txtCdmServerStatus
.widthHint
= 100;
258 txtCdmServerStatus
.setLayoutData(gd_txtCdmServerStatus
);
260 btnCdmServerRefresh
= new Button(cdmServerComposite
, SWT
.NONE
);
261 btnCdmServerRefresh
.addSelectionListener(new SelectionAdapter() {
263 public void widgetSelected(SelectionEvent e
) {
267 btnCdmServerRefresh
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
268 btnCdmServerRefresh
.setText(Messages
.RemotingLoginDialog_LABEL_REFRESH
);
270 Label lblCdmInstance
= new Label(cdmServerComposite
, SWT
.NONE
);
271 GridData gd_lblCdmInstance
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
272 gd_lblCdmInstance
.heightHint
= 30;
273 lblCdmInstance
.setLayoutData(gd_lblCdmInstance
);
274 lblCdmInstance
.setText(Messages
.RemotingLoginDialog_LABEL_CDM_INSTANCE
);
275 lblCdmInstance
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
277 comboCdmInstance
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
278 comboCdmInstance
.addSelectionListener(new SelectionAdapter() {
280 public void widgetSelected(SelectionEvent e
) {
281 refreshCdmInstance();
284 GridData gd_comboCdmInstance
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
285 gd_comboCdmInstance
.widthHint
= 150;
286 comboCdmInstance
.setLayoutData(gd_comboCdmInstance
);
287 comboCdmInstance
.select(0);
289 txtCdmInstanceStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
290 txtCdmInstanceStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
291 txtCdmInstanceStatus
.setEditable(false);
292 GridData gd_txtCdmInstanceStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
293 gd_txtCdmInstanceStatus
.widthHint
= 100;
294 txtCdmInstanceStatus
.setLayoutData(gd_txtCdmInstanceStatus
);
296 btnCdmInstanceRefresh
= new Button(cdmServerComposite
, SWT
.FLAT
);
297 btnCdmInstanceRefresh
.addSelectionListener(new SelectionAdapter() {
299 public void widgetSelected(SelectionEvent e
) {
300 refreshCdmInstance();
303 GridData gd_btnCdmInstanceRefresh
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
304 gd_btnCdmInstanceRefresh
.widthHint
= 110;
305 gd_btnCdmInstanceRefresh
.heightHint
= 30;
306 btnCdmInstanceRefresh
.setLayoutData(gd_btnCdmInstanceRefresh
);
307 btnCdmInstanceRefresh
.setText(Messages
.RemotingLoginDialog_LABEL_REFRESH
);
309 loginComposite
= new Composite(remotingComposite
, SWT
.NONE
);
310 GridData gd_loginComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
311 gd_loginComposite
.widthHint
= 487;
312 gd_loginComposite
.heightHint
= 70;
313 loginComposite
.setLayoutData(gd_loginComposite
);
314 GridLayout gl_loginComposite
= new GridLayout(6, false);
315 gl_loginComposite
.marginTop
= 5;
316 loginComposite
.setLayout(gl_loginComposite
);
318 lblLogin
= new Label(loginComposite
, SWT
.CENTER
);
319 GridData gd_lblLogin
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
320 gd_lblLogin
.widthHint
= 50;
321 lblLogin
.setLayoutData(gd_lblLogin
);
322 lblLogin
.setText(Messages
.RemotingLoginDialog_LABEL_LOGIN_COLON
);
323 lblLogin
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
325 txtLogin
= new Text(loginComposite
, SWT
.BORDER
);
326 GridData gd_txtLogin
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
327 gd_txtLogin
.minimumWidth
= 80;
328 gd_txtLogin
.widthHint
= 80;
329 gd_txtLogin
.heightHint
= 15;
330 txtLogin
.setLayoutData(gd_txtLogin
);
332 lblPassword
= new Label(loginComposite
, SWT
.CENTER
);
333 lblPassword
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
334 lblPassword
.setText(Messages
.RemotingLoginDialog_LABEL_PASSWORD
);
335 lblPassword
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
337 txtPassword
= new Text(loginComposite
, SWT
.BORDER
| SWT
.PASSWORD
);
338 GridData gd_txtPassword
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
339 gd_txtPassword
.minimumWidth
= 80;
340 gd_txtPassword
.widthHint
= 80;
341 gd_txtPassword
.heightHint
= 15;
342 txtPassword
.setLayoutData(gd_txtPassword
);
343 new Label(loginComposite
, SWT
.NONE
);
344 txtPassword
.addKeyListener(new KeyAdapter() {
346 public void keyPressed(KeyEvent e
) {
347 if(e
.character
==SWT
.CR
){
348 connectButtonPressed();
353 btnConnect
= new Button(loginComposite
, SWT
.FLAT
);
354 btnConnect
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1));
355 btnConnect
.addSelectionListener(new SelectionAdapter() {
357 public void widgetSelected(SelectionEvent e
) {
358 connectButtonPressed();
361 btnConnect
.setText(Messages
.RemotingLoginDialog_LABEL_CONNECT
);
363 btnRememberMe
= new Button(loginComposite
, SWT
.CHECK
);
364 btnRememberMe
.setSelection(true);
365 GridData gd_btnRememberMe
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 2, 1);
366 btnRememberMe
.setLayoutData(gd_btnRememberMe
);
367 btnRememberMe
.setText(Messages
.RemotingLoginDialog_LABEL_REMEMBER_ME
);
368 new Label(loginComposite
, SWT
.NONE
);
369 new Label(loginComposite
, SWT
.NONE
);
370 new Label(loginComposite
, SWT
.NONE
);
371 new Label(loginComposite
, SWT
.NONE
);
373 styledTxtMessage
= new StyledText(remotingComposite
, SWT
.NONE
);
374 styledTxtMessage
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
375 styledTxtMessage
.setForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
376 styledTxtMessage
.setFont(SWTResourceManager
.getFont(UBUNTU
, 12, SWT
.BOLD
));
377 styledTxtMessage
.setSelectionBackground(SWTResourceManager
.getColor(SWT
.COLOR_LIST_SELECTION_TEXT
));
378 styledTxtMessage
.setSelectionForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
379 styledTxtMessage
.setDoubleClickEnabled(false);
380 styledTxtMessage
.setEditable(false);
381 GridData gd_styledTxtMessage
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
382 gd_styledTxtMessage
.exclude
= true;
383 gd_styledTxtMessage
.minimumHeight
= MESSAGE_HEIGHT
;
384 gd_styledTxtMessage
.heightHint
= MESSAGE_HEIGHT
;
385 styledTxtMessage
.setLayoutData(gd_styledTxtMessage
);
387 xpndblcmpstAdvanced
= new ExpandableComposite(remotingComposite
, SWT
.NONE
, ExpandableComposite
.TWISTIE
);
388 GridData gd_xpndblcmpstAdvanced
= new GridData(SWT
.FILL
, SWT
.FILL
, false, true, 1, 1);
389 gd_xpndblcmpstAdvanced
.heightHint
= 19;
390 xpndblcmpstAdvanced
.setLayoutData(gd_xpndblcmpstAdvanced
);
391 xpndblcmpstAdvanced
.addExpansionListener(new IExpansionListener() {
393 public void expansionStateChanged(ExpansionEvent e
) {
394 GridData gridData
= (GridData
) xpndblcmpstAdvanced
.getLayoutData();
396 shlConnect
.setSize(MIN_WIDTH
, MIN_EXP_HEIGHT
);
398 shlConnect
.setSize(MIN_WIDTH
, MIN_HEIGHT
);
403 public void expansionStateChanging(ExpansionEvent e
) {
406 xpndblcmpstAdvanced
.setText(Messages
.RemotingLoginDialog_LABEL_ADVANCED
);
407 xpndblcmpstAdvanced
.setExpanded(true);
409 compAdvanced
= new Composite(xpndblcmpstAdvanced
, SWT
.NONE
);
410 xpndblcmpstAdvanced
.setClient(compAdvanced
);
411 compAdvanced
.setLayout(new GridLayout(4, false));
413 lblPort
= new Label(compAdvanced
, SWT
.CENTER
);
414 lblPort
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
415 lblPort
.setSize(0, 0);
416 lblPort
.setText(Messages
.RemotingLoginDialog_LABEL_PORT
);
417 lblPort
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
419 txtPort
= new Text(compAdvanced
, SWT
.BORDER
);
420 GridData gd_txtPort
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1);
421 gd_txtPort
.minimumWidth
= 50;
422 gd_txtPort
.widthHint
= 50;
423 txtPort
.setLayoutData(gd_txtPort
);
425 lblServerVersion
= new Label(compAdvanced
, SWT
.CENTER
);
426 lblServerVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
427 lblServerVersion
.setText(Messages
.RemotingLoginDialog_LABEL_SERVER_CDMLIB_VERSION
);
428 lblServerVersion
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
430 txtServerVersion
= new Text(compAdvanced
, SWT
.BORDER
);
431 txtServerVersion
.setEditable(false);
432 txtServerVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
433 btnStopServer
= new Button(compAdvanced
, SWT
.FLAT
);
434 btnStopServer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 2, 1));
435 btnStopServer
.addMouseListener(new MouseAdapter() {
437 public void mouseUp(MouseEvent e
) {
441 btnStopServer
.setText(Messages
.RemotingLoginDialog_LABEL_STOP_MANAGED_SERVER
);
443 lblEditorVersion
= new Label(compAdvanced
, SWT
.CENTER
);
444 lblEditorVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
445 lblEditorVersion
.setText(Messages
.RemotingLoginDialog_LABEL_EDITOR_CDMLIB_VERSION
);
446 lblEditorVersion
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
448 txtEditorVersion
= new Text(compAdvanced
, SWT
.BORDER
);
449 txtEditorVersion
.setEditable(false);
450 txtEditorVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
451 new Label(compAdvanced
, SWT
.NONE
);
452 new Label(compAdvanced
, SWT
.NONE
);
454 lblServerCDMVersion
= new Label(compAdvanced
, SWT
.CENTER
);
455 lblServerCDMVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
456 lblServerCDMVersion
.setText(Messages
.RemotingLoginDialog_LABEL_SERVER_CDM_VERSION
);
457 lblServerCDMVersion
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
459 txtServerCDMVersion
= new Text(compAdvanced
, SWT
.BORDER
);
460 txtServerCDMVersion
.setEditable(false);
461 txtServerCDMVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
462 new Label(compAdvanced
, SWT
.NONE
);
463 new Label(compAdvanced
, SWT
.NONE
);
465 lblEditorCDMVersion
= new Label(compAdvanced
, SWT
.CENTER
);
466 lblEditorCDMVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
467 lblEditorCDMVersion
.setText(Messages
.RemotingLoginDialog_LABEL_EDITOR_CDM_VERSION
);
468 lblEditorCDMVersion
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
470 txtEditorCDMVersion
= new Text(compAdvanced
, SWT
.BORDER
);
471 txtEditorCDMVersion
.setEditable(false);
472 txtEditorCDMVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
476 private void connectButtonPressed() {
477 if(selectedCsii
.isLocalhostMgd() && !isSelectedCdmInstanceRunningInManagedServer()) {
478 startManagedServer();
481 if (CdmStore
.isActive()){
482 PreferencesUtil
.setNomenclaturalCodePreferences();
488 private void populateCdmServerCombo() {
489 Job job
= new Job(Messages
.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES
) {
491 protected IStatus
run(IProgressMonitor monitor
) {
492 Display
.getDefault().syncExec(new Runnable() {
495 for(CdmServerInfo csii
: CdmServerInfo
.getCdmServers()) {
496 csiiMap
.put(csii
.getName(), csii
);
497 comboCdmServer
.add(csii
.getName());
499 int serverIndex
= -1;
500 if(serverName
!= null) {
501 serverIndex
= comboCdmServer
.indexOf(serverName
);
503 if(serverIndex
== -1) {
504 comboCdmServer
.select(0);
507 comboCdmServer
.select(serverIndex
);
509 CdmRemoteSource devRemoteSource
= CdmServerInfo
.getDevServerRemoteSource();
510 if(devRemoteSource
!= null) {
511 isDevRemoteSource
= true;
512 String username
= System
.getProperty("cdm.server.dev.username"); //$NON-NLS-1$
513 String password
= System
.getProperty("cdm.server.dev.password"); //$NON-NLS-1$
514 if(username
!= null && !username
.isEmpty() && password
!= null && !password
.isEmpty()) {
515 txtLogin
.setText(username
);
516 txtPassword
.setText(password
);
517 CdmStore
.connect(devRemoteSource
, RemotingLoginDialog
.this);
524 return Status
.OK_STATUS
;
531 private void refreshCdmServer() {
532 txtCdmServerStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
533 clearOnServerChange();
535 updateSelectedCdmServer();
536 Display
.getDefault().asyncExec(new Runnable() {
539 checkSelectedCdmServer();
545 private void updateSelectedCdmServer() {
546 int selIndex
= comboCdmServer
.getSelectionIndex();
548 selectedCsii
= csiiMap
.get(comboCdmServer
.getItem(selIndex
));
552 private void updatePort() {
554 if(selectedCsii
!= null) {
555 int port
= selectedCsii
.getPort();
556 if(port
== CdmServerInfo
.NULL_PORT
) {
557 txtPort
.setText(CdmServerInfo
.NULL_PORT_STRING
);
559 txtPort
.setText(String
.valueOf(port
));
564 private int getPort() {
565 int port
= CdmServerInfo
.NULL_PORT
;
567 port
= Integer
.valueOf(txtPort
.getText());
568 } catch (NumberFormatException nfe
) {
569 if(!CdmServerInfo
.NULL_PORT_STRING
.equals(txtPort
.getText())) {
570 setMessage(Messages
.RemotingLoginDialog_MESSAGE_PORT_SHOULD_BE_INTEGER
);
576 private void checkSelectedCdmServer() {
577 if(selectedCsii
!= null) {
578 if(selectedCsii
.isLocalhost()) {
579 txtPort
.setEditable(true);
580 txtPort
.setEnabled(true);
582 if(selectedCsii
.pingServer()) {
583 txtCdmServerStatus
.setText(STATUS_AVAILABLE
);
584 populateCdmInstanceCombo(true);
585 String serverVersionTimestamp
= generateLastModifiedTooltip(selectedCsii
.getCdmlibLastModified());
586 txtServerVersion
.setText(selectedCsii
.getCdmlibServicesVersion() + ":" + serverVersionTimestamp
); //$NON-NLS-1$
588 txtCdmServerStatus
.setText(STATUS_NOT_AVAILABLE
);
589 comboCdmInstance
.removeAll();
590 disableCdmInstanceControls("", "");
597 private void populateCdmInstanceCombo(final boolean forceRefresh
) {
598 comboCdmInstance
.removeAll();
599 comboCdmInstance
.setEnabled(false);
600 btnConnect
.setEnabled(false);
601 txtCdmInstanceStatus
.setText(STATUS_RETRIEVING
);
602 txtCdmInstanceStatus
.setToolTipText("");
604 serverJob
= new Job(Messages
.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES
) {
606 protected IStatus
run(IProgressMonitor monitor
) {
608 if(selectedCsii
!= null) {
610 selectedCsii
.refreshInstances();
612 final List
<CdmInstanceInfo
> instances
= selectedCsii
.getInstances();
613 Display
.getDefault().asyncExec(new Runnable() {
616 if(!instances
.isEmpty()) {
617 for(CdmInstanceInfo cdmInstance
: instances
) {
618 comboCdmInstance
.add(cdmInstance
.getName());
620 int instanceIndex
= -1;
621 if(instanceName
!= null) {
622 instanceIndex
= comboCdmInstance
.indexOf(instanceName
);
624 if(instanceIndex
== -1) {
625 comboCdmInstance
.select(0);
628 comboCdmInstance
.select(instanceIndex
);
630 refreshCdmInstance();
631 comboCdmInstance
.setEnabled(true);
637 txtCdmInstanceStatus
.setText(STATUS_NO_INSTANCES
);
638 btnConnect
.setEnabled(false);
643 } catch (final CDMServerException e
) {
644 MessagingUtils
.warn(getClass(), e
);
645 Display
.getDefault().asyncExec(new Runnable() {
648 disableCdmInstanceControls(STATUS_NOT_AVAILABLE
, e
.getMessage());
652 return Status
.OK_STATUS
;
656 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
) && !isDevRemoteSource
) {
658 serverJob
.schedule();
662 private void disableCdmInstanceControls(String cdmInstanceStatus
, String tooltip
) {
663 txtCdmInstanceStatus
.setText(cdmInstanceStatus
);
664 txtCdmInstanceStatus
.setToolTipText(tooltip
);
665 comboCdmInstance
.setEnabled(false);
666 btnConnect
.setEnabled(false);
669 private void refreshCdmInstance() {
670 txtCdmInstanceStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
671 clearOnInstanceChange();
672 updateSelectedCdmInstance();
673 checkSelectedCdmInstance();
674 updateManagedServerControls();
677 private void updateSelectedCdmInstance() {
678 int selIndex
= comboCdmInstance
.getSelectionIndex();
680 selectedCdmInstance
= selectedCsii
.getInstanceFromName(comboCdmInstance
.getItem(selIndex
));
682 if(loadLoginPrefs
&& !isDevRemoteSource
) {
683 readPrefCredentials();
688 private void updateManagedServerControls() {
689 if(selectedCsii
.isLocalhostMgd()) {
690 if(isSelectedCdmInstanceRunningInManagedServer()) {
691 txtCdmInstanceStatus
.setText(STATUS_STARTED
);
693 txtCdmInstanceStatus
.setText(STATUS_NOT_STARTED
);
695 btnConnect
.setEnabled(true);
696 selectedCsii
.setPort(getManagedServerPort());
701 if(isManagedServerRunning()) {
702 btnStopServer
.setEnabled(true);
704 btnStopServer
.setEnabled(false);
708 private boolean isManagedServerRunning() {
709 return CdmStore
.getManagedServer() != null && CdmStore
.getManagedServer().isAlive();
712 private boolean isSelectedCdmInstanceRunningInManagedServer() {
713 return CdmStore
.getManagedServer() != null &&
714 CdmStore
.getManagedServer().isAlive() &&
715 selectedCsii
.isLocalhostMgd() &&
716 CdmStore
.getManagedServer().getDataSourceName().equals(selectedCdmInstance
.getName());
719 private void startManagedServer() {
720 if(isManagedServerRunning()) {
721 if(CdmStore
.getManagedServer().getDataSourceName().equals(selectedCdmInstance
.getName())) {
724 Display
.getDefault().syncExec(new Runnable() {
734 Job job
= new Job(Messages
.RemotingLoginDialog_JOB_SERVER_LAUNCH
) {
737 public IStatus
run(IProgressMonitor monitor
) {
738 String mgdServerConfigFileName
= "mgd.datasources.xml"; //$NON-NLS-1$
739 String config
= CDMServerUtils
.convertEditorToServerConfig();
740 File managedServerConfigFile
;
742 monitor
.beginTask(Messages
.RemotingLoginDialog_TASK_LAUNCHING_SERVER
, maxUnits
);
744 monitor
.subTask(String
.format(Messages
.RemotingLoginDialog_GENERATING_CONFIG_FILE
, selectedCdmInstance
.getName()));
745 managedServerConfigFile
= CDMServerUtils
.writeManagedServerConfig(config
, mgdServerConfigFileName
);
747 CdmStore
.setManagedServer(new CDMServer(selectedCdmInstance
.getName(), managedServerConfigFile
));
748 monitor
.subTask(Messages
.RemotingLoginDialog_STARTING_MGD_SERVER
);
749 CdmStore
.getManagedServer().start(false, RemotingLoginDialog
.this);
752 // the following loop is a 'fake' progress monitoring where the progress
753 // bar is advanced by one unit every second until maxUnits -2
754 while(!CdmStore
.getManagedServer().isStarted() && !CdmStore
.getManagedServer().isFailed()) {
755 if(serverUnits
< maxUnits
- 2) {
758 } catch (InterruptedException e
) {
764 Display
.getDefault().asyncExec(new Runnable() {
768 updateManagedServerControls();
772 } catch (IOException ioe
) {
773 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_GENERATING_CONFIG_FILE
,
776 TaxeditorStorePlugin
.PLUGIN_ID
,
779 } catch (CDMEmbeddedServerException cse
) {
780 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_STARTING_SERVER
,
783 TaxeditorStorePlugin
.PLUGIN_ID
,
789 return Status
.OK_STATUS
;
794 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);
801 private void stopManagedServer() {
803 CdmStore
.getManagedServer().stop();
804 } catch (Exception e
) {
805 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_STOPPING_SERVER
,
807 String
.format(Messages
.RemotingLoginDialog_COULD_NOT_STOP_SERVER
, CdmStore
.getManagedServer().getPort()),
808 TaxeditorStorePlugin
.PLUGIN_ID
,
812 CdmStore
.setManagedServer(null);
813 updateManagedServerControls();
816 private int getManagedServerPort() {
817 return CdmStore
.getManagedServer() == null ? CdmServerInfo
.NULL_PORT
: CdmStore
.getManagedServer().getPort();
820 private void checkSelectedCdmInstance() {
821 boolean available
= false;
822 String status
= STATUS_NOT_AVAILABLE
;
823 String message
= null;
825 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
)) {
827 if(selectedCsii
.pingInstance(selectedCdmInstance
, getPort())) {
828 status
= STATUS_AVAILABLE
;
831 status
= STATUS_NOT_AVAILABLE
;
836 txtServerCDMVersion
.setText(selectedCsii
.getCdmRemoteSource(selectedCdmInstance
, getPort()).getDbSchemaVersion());
837 int compareDbSchemaVersion
= selectedCsii
.compareDbSchemaVersion(selectedCdmInstance
, getPort());
838 int compareCdmlibServicesVersion
= 0;
839 boolean disableServicesApiTimestampCheck
=
840 PreferencesUtil
.getPreferenceStore().getBoolean((IPreferenceKeys
.DISABLE_SERVICES_API_TIMESTAMP_CHECK
));
841 if(!disableServicesApiTimestampCheck
) {
842 compareCdmlibServicesVersion
= selectedCsii
.compareCdmlibServicesVersion();
844 if(compareDbSchemaVersion
> 0 || compareCdmlibServicesVersion
> 0) {
845 status
= STATUS_NOT_COMPATIBLE
;
847 message
= MESG_COMPATIBLE_EDITOR_OLD
;
848 } else if(compareDbSchemaVersion
< 0 || compareCdmlibServicesVersion
< 0) {
849 status
= STATUS_NOT_COMPATIBLE
;
851 message
= MESG_COMPATIBLE_SERVER_OLD
;
853 status
= STATUS_AVAILABLE
;
855 message
= ""; //$NON-NLS-1$
858 } catch (Exception e
) {
859 txtCdmInstanceStatus
.setToolTipText(e
.getMessage());
861 btnConnect
.setEnabled(available
);
862 txtCdmInstanceStatus
.setText(status
);
863 if(!StringUtils
.isBlank(message
)) {
870 private void connect() {
871 checkSelectedCdmInstance();
873 if(!txtCdmInstanceStatus
.getText().equals(STATUS_AVAILABLE
)) {
877 ICdmRemoteSource source
= selectedCsii
.getCdmRemoteSource(selectedCdmInstance
, getPort());
879 if(!validateLogin(source
)) {
884 CdmStore
.connect(source
, this);
885 } catch (Exception e
) {
886 // Do not expect anything to go wrong at this point, so we throw a runtime exception
888 throw new RuntimeException(e
);
894 public boolean isRememberMe() {
895 return btnRememberMe
.getSelection();
898 private void persistPrefLastServerInstance() {
899 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
900 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
902 lastServerInstancePrefs
.put(LAST_SERVER_KEY
, selectedCsii
.getName());
903 lastServerInstancePrefs
.put(LAST_INSTANCE_KEY
, selectedCdmInstance
.getName());
905 flushPreferences(lastServerInstancePrefs
);
908 private void persistPrefCredentials() {
909 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
910 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
911 credentialsPrefs
.put(getUsernamePrefKey(), txtLogin
.getText());
912 credentialsPrefs
.put(getPasswordPrefKey(), txtPassword
.getText());
913 flushPreferences(credentialsPrefs
);
916 private void flushPreferences(Preferences prefs
) {
919 } catch (BackingStoreException bse
) {
920 setMessage(bse
.getMessage());
924 private void readPrefCredentials() {
925 String username
, password
;
926 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
927 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
928 username
= credentialsPrefs
.get(getUsernamePrefKey(), ""); //$NON-NLS-1$
929 txtLogin
.setText(username
);
930 password
= credentialsPrefs
.get(getPasswordPrefKey(),""); //$NON-NLS-1$
931 txtPassword
.setText(password
);
932 if(username
.isEmpty() || password
.isEmpty()) {
937 private void readPrefLastServerInstance() {
938 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
939 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
941 serverName
= lastServerInstancePrefs
.get(LAST_SERVER_KEY
, null);
942 instanceName
= lastServerInstancePrefs
.get(LAST_INSTANCE_KEY
, null);
945 private void emptyCredentials() {
946 txtLogin
.setText("");
947 txtPassword
.setText("");
950 private String
getUsernamePrefKey() {
951 return selectedCsii
.toString(selectedCdmInstance
.getName(), getPort()) + USERNAME_SUFFIX
;
954 private String
getPasswordPrefKey() {
955 return selectedCsii
.toString(selectedCdmInstance
.getName(), getPort()) + PASSWORD_SUFFIX
;
958 private boolean validateLogin(ICdmRemoteSource remoteSource
) {
959 if(getUsername() == null || getUsername().isEmpty()) {
960 setMessage(Messages
.RemotingLoginDialog_LOGIN_CANNOT_BE_EMPTY
);
963 if(getPassword() == null || getPassword().isEmpty()) {
964 setMessage(Messages
.RemotingLoginDialog_PASSWORD_CANNOT_BE_EMPTY
);
970 IUserService userService
= CdmApplicationRemoteConfiguration
.getUserService(remoteSource
);
971 UsernamePasswordAuthenticationToken token
= new UsernamePasswordAuthenticationToken(getUsername(), getPassword());
972 CdmApplicationRemoteConfiguration
.getAuthenticationManager(userService
).authenticate(token
);
973 } catch(BadCredentialsException e
){
974 setMessage(LoginManager
.INCORRECT_CREDENTIALS_MESSAGE
);
976 } catch(LockedException e
){
977 setMessage(LoginManager
.ACCOUNT_LOCKED_MESSAGE
);
979 } catch(IllegalArgumentException e
){
980 setMessage(LoginManager
.INCORRECT_CREDENTIALS_MESSAGE
);
986 public String
getUsername() {
987 return txtLogin
.getText();
990 public String
getPassword() {
991 return txtPassword
.getText();
994 public void setMessage(String message
) {
995 if(message
!= null && !message
.isEmpty()) {
996 if(message
.length() > 60) {
997 styledTxtMessage
.setToolTipText(message
);
998 message
= message
.substring(0, 60) + "..."; //$NON-NLS-1$
1000 styledTxtMessage
.setText(message
);
1001 styledTxtMessage
.setVisible(true);
1002 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= false;
1003 shlConnect
.setSize(MIN_WIDTH
, getHeightWithoutMessage() + MESSAGE_HEIGHT
);
1004 shlConnect
.setMinimumSize(MIN_WIDTH
, getHeightWithoutMessage() + MESSAGE_HEIGHT
);
1006 styledTxtMessage
.setText(""); //$NON-NLS-1$
1007 styledTxtMessage
.setVisible(false);
1008 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= true;
1009 shlConnect
.setSize(MIN_WIDTH
, getHeightWithoutMessage());
1010 shlConnect
.setMinimumSize(MIN_WIDTH
, getHeightWithoutMessage());
1012 remotingComposite
.layout();
1015 private int getHeightWithoutMessage() {
1016 if(xpndblcmpstAdvanced
.isExpanded()) {
1017 return MIN_EXP_HEIGHT
;
1024 public void hide(boolean isHidden
) {
1025 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
1026 shlConnect
.setVisible(!isHidden
);
1029 public void dispose() {
1030 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
1031 shlConnect
.dispose();
1035 public void onComplete() {
1036 Display
.getDefault().asyncExec(new Runnable() {
1039 if(!isDevRemoteSource
) {
1040 if(isRememberMe()) {
1041 persistPrefCredentials();
1043 persistPrefLastServerInstance();
1050 private String
generateLastModifiedTooltip(String cdmlibLastModified
) {
1051 if(StringUtils
.isBlank(cdmlibLastModified
)) {
1052 return ""; //$NON-NLS-1$
1054 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy.MM.dd.HH.mm.z"); //$NON-NLS-1$
1055 Date cdmlibLastModifiedDate
;
1056 String cdmlibLastModifiedTimestamp
= ""; //$NON-NLS-1$
1058 cdmlibLastModifiedDate
= new Date(Long
.valueOf(cdmlibLastModified
));
1059 cdmlibLastModifiedTimestamp
= sdf
.format(cdmlibLastModifiedDate
);
1061 return cdmlibLastModifiedTimestamp
;
1064 private void setEditorInfo() {
1065 txtEditorCDMVersion
.setText(CdmMetaData
.getDbSchemaVersion());
1066 String editorVersionTimestamp
= generateLastModifiedTooltip(CdmApplicationState
.getCdmlibLastModified());
1067 txtEditorVersion
.setText(CdmApplicationState
.getCdmlibVersion() + ":" + editorVersionTimestamp
); //$NON-NLS-1$
1070 private void clearOnServerChange() {
1071 setMessage(""); //$NON-NLS-1$
1072 txtServerCDMVersion
.setText(""); //$NON-NLS-1$
1073 txtServerVersion
.setText(""); //$NON-NLS-1$
1074 txtServerVersion
.setToolTipText(""); //$NON-NLS-1$
1075 txtServerCDMVersion
.setText(""); //$NON-NLS-1$
1076 comboCdmInstance
.removeAll();
1077 txtCdmInstanceStatus
.setText(""); //$NON-NLS-1$
1078 txtPort
.setEditable(false);
1079 txtPort
.setEnabled(false);
1082 private void clearOnInstanceChange() {
1083 setMessage(""); //$NON-NLS-1$
1084 txtServerCDMVersion
.setText(""); //$NON-NLS-1$
1091 public void handleError(final Throwable t
) {
1093 Display
.getDefault().syncExec(new Runnable() {
1098 String title
= Messages
.RemotingLoginDialog_SERVER_LAUNCH_ERROR
;
1099 String message
= t
.getMessage();
1102 MessagingUtils
.errorDialog(title
,
1105 TaxeditorStorePlugin
.PLUGIN_ID
,