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
.KeyAdapter
;
30 import org
.eclipse
.swt
.events
.KeyEvent
;
31 import org
.eclipse
.swt
.events
.MouseAdapter
;
32 import org
.eclipse
.swt
.events
.MouseEvent
;
33 import org
.eclipse
.swt
.events
.SelectionAdapter
;
34 import org
.eclipse
.swt
.events
.SelectionEvent
;
35 import org
.eclipse
.swt
.graphics
.Point
;
36 import org
.eclipse
.swt
.layout
.FillLayout
;
37 import org
.eclipse
.swt
.layout
.GridData
;
38 import org
.eclipse
.swt
.layout
.GridLayout
;
39 import org
.eclipse
.swt
.widgets
.Button
;
40 import org
.eclipse
.swt
.widgets
.Combo
;
41 import org
.eclipse
.swt
.widgets
.Composite
;
42 import org
.eclipse
.swt
.widgets
.Dialog
;
43 import org
.eclipse
.swt
.widgets
.Display
;
44 import org
.eclipse
.swt
.widgets
.Label
;
45 import org
.eclipse
.swt
.widgets
.Shell
;
46 import org
.eclipse
.swt
.widgets
.Text
;
47 import org
.eclipse
.ui
.forms
.events
.ExpansionEvent
;
48 import org
.eclipse
.ui
.forms
.events
.IExpansionListener
;
49 import org
.eclipse
.ui
.forms
.widgets
.ExpandableComposite
;
50 import org
.eclipse
.ui
.progress
.IProgressConstants
;
51 import org
.eclipse
.wb
.swt
.SWTResourceManager
;
52 import org
.osgi
.service
.prefs
.BackingStoreException
;
53 import org
.osgi
.service
.prefs
.Preferences
;
54 import org
.springframework
.security
.authentication
.BadCredentialsException
;
55 import org
.springframework
.security
.authentication
.LockedException
;
56 import org
.springframework
.security
.authentication
.UsernamePasswordAuthenticationToken
;
58 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationRemoteConfiguration
;
59 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
60 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
61 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
;
62 import eu
.etaxonomy
.taxeditor
.Messages
;
63 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
64 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
65 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
66 import eu
.etaxonomy
.taxeditor
.remoting
.server
.CDMServerException
;
67 import eu
.etaxonomy
.taxeditor
.remoting
.server
.CDMServerUtils
;
68 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmRemoteSource
;
69 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
;
70 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
.CdmInstanceInfo
;
71 import eu
.etaxonomy
.taxeditor
.remoting
.source
.ICdmRemoteSource
;
72 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
73 import eu
.etaxonomy
.taxeditor
.store
.LoginManager
;
74 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
75 import eu
.etaxonomy
.taxeditor
.webapp
.CDMEmbeddedServerException
;
76 import eu
.etaxonomy
.taxeditor
.webapp
.CDMServer
;
77 import eu
.etaxonomy
.taxeditor
.webapp
.ICDMServerError
;
85 public class RemotingLoginDialog
extends Dialog
implements ICDMServerError
{
87 private static final String UBUNTU
= "Ubuntu"; //$NON-NLS-1$
88 protected Object result
;
89 protected Shell shlConnect
;
90 private Text txtCdmServerStatus
;
91 private Text txtCdmInstanceStatus
;
92 private Combo comboCdmServer
;
93 private Combo comboCdmInstance
;
94 private Button btnConnect
;
96 private final Map
<String
, CdmServerInfo
> csiiMap
= new HashMap
<String
, CdmServerInfo
>();
98 private final static String STATUS_AVAILABLE
= Messages
.RemotingLoginDialog_STATUS_AVAILABLE
;
99 private final static String STATUS_NOT_AVAILABLE
= Messages
.RemotingLoginDialog_STATUS_NOT_AVAILABLE
;
100 private final static String STATUS_STARTED
= Messages
.RemotingLoginDialog_STATUS_STARTED
;
101 private final static String STATUS_NOT_STARTED
= Messages
.RemotingLoginDialog_STATUS_NOT_STARTED
;
102 private final static String STATUS_RETRIEVING
= Messages
.RemotingLoginDialog_STATUS_RETRIEVING
;
103 private final static String STATUS_CHECKING_AVAILABILITY
= Messages
.RemotingLoginDialog_STATUS_CHECKING
;
104 private final static String STATUS_NO_INSTANCES
= Messages
.RemotingLoginDialog_STATUS_NO_INSTANCES_FOUND
;
105 private final static String STATUS_ERROR
= Messages
.RemotingLoginDialog_STATUS_ERROR
;
106 private final static String STATUS_REMOTING_NOT_ACTIVATED
= Messages
.RemotingLoginDialog_STATUS_REMOTING_NOT_ACTIVATED
;
107 private final static String STATUS_NOT_COMPATIBLE
= Messages
.RemotingLoginDialog_STATUS_NOT_COMPATIBLE
;
109 private final static String MESG_COMPATIBLE_EDITOR_OLD
= Messages
.RemotingLoginDialog_UPDATE_EDITOR
;
110 private final static String MESG_COMPATIBLE_SERVER_OLD
= Messages
.RemotingLoginDialog_CHOOSE_COMPATIBLE_CDM_SERVER
;
112 private final static String STORE_PREFERENCES_NODE
= "eu.etaxonomy.taxeditor.store"; //$NON-NLS-1$
114 private final static String LOGIN_NODE
= "login"; //$NON-NLS-1$
115 private final static String USERNAME_SUFFIX
= "_username"; //$NON-NLS-1$
116 private final static String PASSWORD_SUFFIX
= "_password"; //$NON-NLS-1$
118 private final static String LAST_SERVER_INSTANCE_NODE
= "lastServerInstance"; //$NON-NLS-1$
119 private final static String LAST_SERVER_KEY
= "lastServerKey"; //$NON-NLS-1$
120 private final static String LAST_INSTANCE_KEY
= "lastInstanceKey"; //$NON-NLS-1$
122 private final static String REFRESH_LABEL
= Messages
.RemotingLoginDialog_LABEL_REFRESH
;
124 private Composite remotingComposite
;
125 private CdmServerInfo selectedCsii
;
126 private CdmInstanceInfo selectedCdmInstance
;
127 private Button btnCdmServerRefresh
;
128 private Button btnCdmInstanceRefresh
;
129 private Button btnStopServer
;
130 private Composite loginComposite
;
131 private Label lblLogin
;
132 private Text txtLogin
;
133 private Label lblPassword
;
134 private Text txtPassword
;
135 private Button btnRememberMe
;
136 private Composite compAdvanced
;
137 private Label lblPort
;
138 private Text txtPort
;
139 private Label lblServerVersion
;
140 private Text txtServerVersion
;
141 private ExpandableComposite xpndblcmpstAdvanced
;
142 private StyledText styledTxtMessage
;
145 private final int MIN_WIDTH
= 530;
146 private final int MIN_HEIGHT
= 220;
147 private final int MIN_EXP_HEIGHT
= 380;
148 private final int MESSAGE_HEIGHT
= 25;
149 private Label lblEditorVersion
;
150 private Text txtEditorVersion
;
151 private Label lblServerCDMVersion
;
152 private Text txtServerCDMVersion
;
153 private Label lblEditorCDMVersion
;
154 private Text txtEditorCDMVersion
;
156 private String serverName
, instanceName
;
157 private boolean autoConnect
= false;
158 private boolean loadLoginPrefs
= true;
159 private boolean isDevRemoteSource
= false;
160 private Job serverJob
;
166 public RemotingLoginDialog(Shell parent
, int style
) {
167 super(parent
, style
);
168 setText(Messages
.RemotingLoginDialog_LABEL_LOGIN
);
171 public Object
open(CdmRemoteSource source
, boolean loadLoginPrefs
, boolean autoConnect
) {
172 this.loadLoginPrefs
= loadLoginPrefs
;
173 this.serverName
= source
.getName();
174 String contextPath
= source
.getContextPath();
175 this.instanceName
= contextPath
.substring(contextPath
.lastIndexOf("/") + 1); //$NON-NLS-1$
176 return open(serverName
, instanceName
, loadLoginPrefs
, autoConnect
);
180 public Object
open(String serverName
, String instanceName
, boolean loadLoginPrefs
, boolean autoConnect
) {
181 this.serverName
= serverName
;
182 this.instanceName
= instanceName
;
183 this.loadLoginPrefs
= loadLoginPrefs
;
184 this.autoConnect
= autoConnect
;
192 public Object
open() {
195 if(serverName
== null && instanceName
== null) {
196 readPrefLastServerInstance();
200 populateCdmServerCombo();
204 xpndblcmpstAdvanced
.setExpanded(false);
206 Display display
= getParent().getDisplay();
208 while (!shlConnect
.isDisposed()) {
209 if (!display
.readAndDispatch()) {
218 * Create contents of the dialog.
220 private void createContents() {
221 shlConnect
= new Shell(getParent(), SWT
.DIALOG_TRIM
);
222 shlConnect
.setMinimumSize(new Point(MIN_WIDTH
, MIN_HEIGHT
));
223 shlConnect
.setSize(MIN_WIDTH
, MIN_HEIGHT
);
224 shlConnect
.setText(Messages
.RemotingLoginDialog_LABEL_CONNECT
);
225 shlConnect
.setLayout(new FillLayout(SWT
.HORIZONTAL
));
227 remotingComposite
= new Composite(shlConnect
, SWT
.NONE
);
228 remotingComposite
.setLayout(new GridLayout(1, false));
230 Composite cdmServerComposite
= new Composite(remotingComposite
, SWT
.NONE
);
231 GridData gd_cdmServerComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
232 gd_cdmServerComposite
.heightHint
= 68;
233 cdmServerComposite
.setLayoutData(gd_cdmServerComposite
);
234 cdmServerComposite
.setLayout(new GridLayout(4, false));
236 Label lblCdmServer
= new Label(cdmServerComposite
, SWT
.NONE
);
237 lblCdmServer
.setText(Messages
.RemotingLoginDialog_LABEL_CDM_SERVER
);
238 lblCdmServer
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
239 lblCdmServer
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
241 comboCdmServer
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
242 comboCdmServer
.addSelectionListener(new SelectionAdapter() {
244 public void widgetSelected(SelectionEvent e
) {
249 GridData gd_comboCdmServer
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
250 gd_comboCdmServer
.widthHint
= 150;
251 comboCdmServer
.setLayoutData(gd_comboCdmServer
);
252 comboCdmServer
.select(0);
254 txtCdmServerStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
255 txtCdmServerStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
256 txtCdmServerStatus
.setEditable(false);
257 GridData gd_txtCdmServerStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
258 gd_txtCdmServerStatus
.widthHint
= 100;
259 txtCdmServerStatus
.setLayoutData(gd_txtCdmServerStatus
);
261 btnCdmServerRefresh
= new Button(cdmServerComposite
, SWT
.NONE
);
262 btnCdmServerRefresh
.addSelectionListener(new SelectionAdapter() {
264 public void widgetSelected(SelectionEvent e
) {
268 btnCdmServerRefresh
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
269 btnCdmServerRefresh
.setText(Messages
.RemotingLoginDialog_LABEL_REFRESH
);
271 Label lblCdmInstance
= new Label(cdmServerComposite
, SWT
.NONE
);
272 GridData gd_lblCdmInstance
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
273 gd_lblCdmInstance
.heightHint
= 30;
274 lblCdmInstance
.setLayoutData(gd_lblCdmInstance
);
275 lblCdmInstance
.setText(Messages
.RemotingLoginDialog_LABEL_CDM_INSTANCE
);
276 lblCdmInstance
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
278 comboCdmInstance
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
279 comboCdmInstance
.addSelectionListener(new SelectionAdapter() {
281 public void widgetSelected(SelectionEvent e
) {
282 refreshCdmInstance();
285 GridData gd_comboCdmInstance
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
286 gd_comboCdmInstance
.widthHint
= 150;
287 comboCdmInstance
.setLayoutData(gd_comboCdmInstance
);
288 comboCdmInstance
.select(0);
290 txtCdmInstanceStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
291 txtCdmInstanceStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
292 txtCdmInstanceStatus
.setEditable(false);
293 GridData gd_txtCdmInstanceStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
294 gd_txtCdmInstanceStatus
.widthHint
= 100;
295 txtCdmInstanceStatus
.setLayoutData(gd_txtCdmInstanceStatus
);
297 btnCdmInstanceRefresh
= new Button(cdmServerComposite
, SWT
.FLAT
);
298 btnCdmInstanceRefresh
.addSelectionListener(new SelectionAdapter() {
300 public void widgetSelected(SelectionEvent e
) {
301 refreshCdmInstance();
304 GridData gd_btnCdmInstanceRefresh
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
305 gd_btnCdmInstanceRefresh
.widthHint
= 110;
306 gd_btnCdmInstanceRefresh
.heightHint
= 30;
307 btnCdmInstanceRefresh
.setLayoutData(gd_btnCdmInstanceRefresh
);
308 btnCdmInstanceRefresh
.setText(Messages
.RemotingLoginDialog_LABEL_REFRESH
);
310 loginComposite
= new Composite(remotingComposite
, SWT
.NONE
);
311 GridData gd_loginComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
312 gd_loginComposite
.widthHint
= 487;
313 gd_loginComposite
.heightHint
= 70;
314 loginComposite
.setLayoutData(gd_loginComposite
);
315 GridLayout gl_loginComposite
= new GridLayout(6, false);
316 gl_loginComposite
.marginTop
= 5;
317 loginComposite
.setLayout(gl_loginComposite
);
319 lblLogin
= new Label(loginComposite
, SWT
.CENTER
);
320 GridData gd_lblLogin
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
321 gd_lblLogin
.widthHint
= 50;
322 lblLogin
.setLayoutData(gd_lblLogin
);
323 lblLogin
.setText(Messages
.RemotingLoginDialog_LABEL_LOGIN_COLON
);
324 lblLogin
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
326 txtLogin
= new Text(loginComposite
, SWT
.BORDER
);
327 GridData gd_txtLogin
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
328 gd_txtLogin
.minimumWidth
= 80;
329 gd_txtLogin
.widthHint
= 80;
330 gd_txtLogin
.heightHint
= 15;
331 txtLogin
.setLayoutData(gd_txtLogin
);
333 lblPassword
= new Label(loginComposite
, SWT
.CENTER
);
334 lblPassword
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
335 lblPassword
.setText(Messages
.RemotingLoginDialog_LABEL_PASSWORD
);
336 lblPassword
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
338 txtPassword
= new Text(loginComposite
, SWT
.BORDER
| SWT
.PASSWORD
);
339 GridData gd_txtPassword
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
340 gd_txtPassword
.minimumWidth
= 80;
341 gd_txtPassword
.widthHint
= 80;
342 gd_txtPassword
.heightHint
= 15;
343 txtPassword
.setLayoutData(gd_txtPassword
);
344 new Label(loginComposite
, SWT
.NONE
);
345 txtPassword
.addKeyListener(new KeyAdapter() {
347 public void keyPressed(KeyEvent e
) {
348 if(e
.character
==SWT
.CR
){
349 connectButtonPressed();
354 btnConnect
= new Button(loginComposite
, SWT
.FLAT
);
355 btnConnect
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1));
356 btnConnect
.addSelectionListener(new SelectionAdapter() {
358 public void widgetSelected(SelectionEvent e
) {
359 connectButtonPressed();
362 btnConnect
.setText(Messages
.RemotingLoginDialog_LABEL_CONNECT
);
364 btnRememberMe
= new Button(loginComposite
, SWT
.CHECK
);
365 btnRememberMe
.setSelection(true);
366 GridData gd_btnRememberMe
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 2, 1);
367 btnRememberMe
.setLayoutData(gd_btnRememberMe
);
368 btnRememberMe
.setText(Messages
.RemotingLoginDialog_LABEL_REMEMBER_ME
);
369 new Label(loginComposite
, SWT
.NONE
);
370 new Label(loginComposite
, SWT
.NONE
);
371 new Label(loginComposite
, SWT
.NONE
);
372 new Label(loginComposite
, SWT
.NONE
);
374 styledTxtMessage
= new StyledText(remotingComposite
, SWT
.NONE
);
375 styledTxtMessage
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
376 styledTxtMessage
.setForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
377 styledTxtMessage
.setFont(SWTResourceManager
.getFont(UBUNTU
, 12, SWT
.BOLD
));
378 styledTxtMessage
.setSelectionBackground(SWTResourceManager
.getColor(SWT
.COLOR_LIST_SELECTION_TEXT
));
379 styledTxtMessage
.setSelectionForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
380 styledTxtMessage
.setDoubleClickEnabled(false);
381 styledTxtMessage
.setEditable(false);
382 GridData gd_styledTxtMessage
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
383 gd_styledTxtMessage
.exclude
= true;
384 gd_styledTxtMessage
.minimumHeight
= MESSAGE_HEIGHT
;
385 gd_styledTxtMessage
.heightHint
= MESSAGE_HEIGHT
;
386 styledTxtMessage
.setLayoutData(gd_styledTxtMessage
);
388 xpndblcmpstAdvanced
= new ExpandableComposite(remotingComposite
, SWT
.NONE
, ExpandableComposite
.TWISTIE
);
389 GridData gd_xpndblcmpstAdvanced
= new GridData(SWT
.FILL
, SWT
.FILL
, false, true, 1, 1);
390 gd_xpndblcmpstAdvanced
.heightHint
= 19;
391 xpndblcmpstAdvanced
.setLayoutData(gd_xpndblcmpstAdvanced
);
392 xpndblcmpstAdvanced
.addExpansionListener(new IExpansionListener() {
394 public void expansionStateChanged(ExpansionEvent e
) {
395 GridData gridData
= (GridData
) xpndblcmpstAdvanced
.getLayoutData();
397 shlConnect
.setSize(MIN_WIDTH
, MIN_EXP_HEIGHT
);
399 shlConnect
.setSize(MIN_WIDTH
, MIN_HEIGHT
);
404 public void expansionStateChanging(ExpansionEvent e
) {
407 xpndblcmpstAdvanced
.setText(Messages
.RemotingLoginDialog_LABEL_ADVANCED
);
408 xpndblcmpstAdvanced
.setExpanded(true);
410 compAdvanced
= new Composite(xpndblcmpstAdvanced
, SWT
.NONE
);
411 xpndblcmpstAdvanced
.setClient(compAdvanced
);
412 compAdvanced
.setLayout(new GridLayout(4, false));
414 lblPort
= new Label(compAdvanced
, SWT
.CENTER
);
415 lblPort
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
416 lblPort
.setSize(0, 0);
417 lblPort
.setText(Messages
.RemotingLoginDialog_LABEL_PORT
);
418 lblPort
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
420 txtPort
= new Text(compAdvanced
, SWT
.BORDER
);
421 GridData gd_txtPort
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1);
422 gd_txtPort
.minimumWidth
= 50;
423 gd_txtPort
.widthHint
= 50;
424 txtPort
.setLayoutData(gd_txtPort
);
426 lblServerVersion
= new Label(compAdvanced
, SWT
.CENTER
);
427 lblServerVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
428 lblServerVersion
.setText(Messages
.RemotingLoginDialog_LABEL_SERVER_CDMLIB_VERSION
);
429 lblServerVersion
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
431 txtServerVersion
= new Text(compAdvanced
, SWT
.BORDER
);
432 txtServerVersion
.setEditable(false);
433 txtServerVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
434 btnStopServer
= new Button(compAdvanced
, SWT
.FLAT
);
435 btnStopServer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 2, 1));
436 btnStopServer
.addMouseListener(new MouseAdapter() {
438 public void mouseUp(MouseEvent e
) {
442 btnStopServer
.setText(Messages
.RemotingLoginDialog_LABEL_STOP_MANAGED_SERVER
);
444 lblEditorVersion
= new Label(compAdvanced
, SWT
.CENTER
);
445 lblEditorVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
446 lblEditorVersion
.setText(Messages
.RemotingLoginDialog_LABEL_EDITOR_CDMLIB_VERSION
);
447 lblEditorVersion
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
449 txtEditorVersion
= new Text(compAdvanced
, SWT
.BORDER
);
450 txtEditorVersion
.setEditable(false);
451 txtEditorVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
452 new Label(compAdvanced
, SWT
.NONE
);
453 new Label(compAdvanced
, SWT
.NONE
);
455 lblServerCDMVersion
= new Label(compAdvanced
, SWT
.CENTER
);
456 lblServerCDMVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
457 lblServerCDMVersion
.setText(Messages
.RemotingLoginDialog_LABEL_SERVER_CDM_VERSION
);
458 lblServerCDMVersion
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
460 txtServerCDMVersion
= new Text(compAdvanced
, SWT
.BORDER
);
461 txtServerCDMVersion
.setEditable(false);
462 txtServerCDMVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
463 new Label(compAdvanced
, SWT
.NONE
);
464 new Label(compAdvanced
, SWT
.NONE
);
466 lblEditorCDMVersion
= new Label(compAdvanced
, SWT
.CENTER
);
467 lblEditorCDMVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
468 lblEditorCDMVersion
.setText(Messages
.RemotingLoginDialog_LABEL_EDITOR_CDM_VERSION
);
469 lblEditorCDMVersion
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
471 txtEditorCDMVersion
= new Text(compAdvanced
, SWT
.BORDER
);
472 txtEditorCDMVersion
.setEditable(false);
473 txtEditorCDMVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
477 private void connectButtonPressed() {
478 if(selectedCsii
.isLocalhostMgd() && !isSelectedCdmInstanceRunningInManagedServer()) {
479 startManagedServer();
482 if (CdmStore
.isActive()){
483 PreferencesUtil
.setNomenclaturalCodePreferences();
489 private void populateCdmServerCombo() {
490 Job job
= new Job(Messages
.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES
) {
492 protected IStatus
run(IProgressMonitor monitor
) {
493 Display
.getDefault().syncExec(new Runnable() {
496 for(CdmServerInfo csii
: CdmServerInfo
.getCdmServers()) {
497 csiiMap
.put(csii
.getName(), csii
);
498 comboCdmServer
.add(csii
.getName());
500 int serverIndex
= -1;
501 if(serverName
!= null) {
502 serverIndex
= comboCdmServer
.indexOf(serverName
);
504 if(serverIndex
== -1) {
505 comboCdmServer
.select(0);
508 comboCdmServer
.select(serverIndex
);
510 CdmRemoteSource devRemoteSource
= CdmServerInfo
.getDevServerRemoteSource();
511 if(devRemoteSource
!= null) {
512 isDevRemoteSource
= true;
513 String username
= System
.getProperty("cdm.server.dev.username"); //$NON-NLS-1$
514 String password
= System
.getProperty("cdm.server.dev.password"); //$NON-NLS-1$
515 if(username
!= null && !username
.isEmpty() && password
!= null && !password
.isEmpty()) {
516 txtLogin
.setText(username
);
517 txtPassword
.setText(password
);
518 CdmStore
.connect(devRemoteSource
, RemotingLoginDialog
.this);
525 return Status
.OK_STATUS
;
532 private void refreshCdmServer() {
533 txtCdmServerStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
534 clearOnServerChange();
536 updateSelectedCdmServer();
537 Display
.getDefault().asyncExec(new Runnable() {
540 checkSelectedCdmServer();
546 private void updateSelectedCdmServer() {
547 int selIndex
= comboCdmServer
.getSelectionIndex();
549 selectedCsii
= csiiMap
.get(comboCdmServer
.getItem(selIndex
));
553 private void updatePort() {
555 if(selectedCsii
!= null) {
556 int port
= selectedCsii
.getPort();
557 if(port
== CdmServerInfo
.NULL_PORT
) {
558 txtPort
.setText(CdmServerInfo
.NULL_PORT_STRING
);
560 txtPort
.setText(String
.valueOf(port
));
565 private int getPort() {
566 int port
= CdmServerInfo
.NULL_PORT
;
568 port
= Integer
.valueOf(txtPort
.getText());
569 } catch (NumberFormatException nfe
) {
570 if(!CdmServerInfo
.NULL_PORT_STRING
.equals(txtPort
.getText())) {
571 setMessage(Messages
.RemotingLoginDialog_MESSAGE_PORT_SHOULD_BE_INTEGER
);
577 private void checkSelectedCdmServer() {
578 if(selectedCsii
!= null) {
579 if(selectedCsii
.isLocalhost()) {
580 txtPort
.setEditable(true);
581 txtPort
.setEnabled(true);
583 if(selectedCsii
.pingServer()) {
584 txtCdmServerStatus
.setText(STATUS_AVAILABLE
);
585 populateCdmInstanceCombo(true);
586 String serverVersionTimestamp
= generateLastModifiedTooltip(selectedCsii
.getCdmlibLastModified());
587 txtServerVersion
.setText(selectedCsii
.getCdmlibServicesVersion() + ":" + serverVersionTimestamp
); //$NON-NLS-1$
589 txtCdmServerStatus
.setText(STATUS_NOT_AVAILABLE
);
590 comboCdmInstance
.removeAll();
591 disableCdmInstanceControls("", "");
598 private void populateCdmInstanceCombo(final boolean forceRefresh
) {
599 comboCdmInstance
.removeAll();
600 comboCdmInstance
.setEnabled(false);
601 btnConnect
.setEnabled(false);
602 txtCdmInstanceStatus
.setText(STATUS_RETRIEVING
);
603 txtCdmInstanceStatus
.setToolTipText("");
605 serverJob
= new Job(Messages
.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES
) {
607 protected IStatus
run(IProgressMonitor monitor
) {
609 if(selectedCsii
!= null) {
611 selectedCsii
.refreshInstances();
613 final List
<CdmInstanceInfo
> instances
= selectedCsii
.getInstances();
614 Display
.getDefault().asyncExec(new Runnable() {
617 if(!instances
.isEmpty()) {
618 for(CdmInstanceInfo cdmInstance
: instances
) {
619 comboCdmInstance
.add(cdmInstance
.getName());
621 int instanceIndex
= -1;
622 if(instanceName
!= null) {
623 instanceIndex
= comboCdmInstance
.indexOf(instanceName
);
625 if(instanceIndex
== -1) {
626 comboCdmInstance
.select(0);
629 comboCdmInstance
.select(instanceIndex
);
631 refreshCdmInstance();
632 comboCdmInstance
.setEnabled(true);
638 txtCdmInstanceStatus
.setText(STATUS_NO_INSTANCES
);
639 btnConnect
.setEnabled(false);
644 } catch (final CDMServerException e
) {
645 MessagingUtils
.warn(getClass(), e
);
646 Display
.getDefault().asyncExec(new Runnable() {
649 disableCdmInstanceControls(STATUS_NOT_AVAILABLE
, e
.getMessage());
653 return Status
.OK_STATUS
;
657 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
) && !isDevRemoteSource
) {
659 serverJob
.schedule();
663 private void disableCdmInstanceControls(String cdmInstanceStatus
, String tooltip
) {
664 txtCdmInstanceStatus
.setText(cdmInstanceStatus
);
665 txtCdmInstanceStatus
.setToolTipText(tooltip
);
666 comboCdmInstance
.setEnabled(false);
667 btnConnect
.setEnabled(false);
670 private void refreshCdmInstance() {
671 txtCdmInstanceStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
672 clearOnInstanceChange();
673 updateSelectedCdmInstance();
674 checkSelectedCdmInstance();
675 updateManagedServerControls();
678 private void updateSelectedCdmInstance() {
679 int selIndex
= comboCdmInstance
.getSelectionIndex();
681 selectedCdmInstance
= selectedCsii
.getInstanceFromName(comboCdmInstance
.getItem(selIndex
));
683 if(loadLoginPrefs
&& !isDevRemoteSource
) {
684 readPrefCredentials();
689 private void updateManagedServerControls() {
690 if(selectedCsii
.isLocalhostMgd()) {
691 if(isSelectedCdmInstanceRunningInManagedServer()) {
692 txtCdmInstanceStatus
.setText(STATUS_STARTED
);
694 txtCdmInstanceStatus
.setText(STATUS_NOT_STARTED
);
696 btnConnect
.setEnabled(true);
697 selectedCsii
.setPort(getManagedServerPort());
702 if(isManagedServerRunning()) {
703 btnStopServer
.setEnabled(true);
705 btnStopServer
.setEnabled(false);
709 private boolean isManagedServerRunning() {
710 return CdmStore
.getManagedServer() != null && CdmStore
.getManagedServer().isAlive();
713 private boolean isSelectedCdmInstanceRunningInManagedServer() {
714 return CdmStore
.getManagedServer() != null &&
715 CdmStore
.getManagedServer().isAlive() &&
716 selectedCsii
.isLocalhostMgd() &&
717 CdmStore
.getManagedServer().getDataSourceName().equals(selectedCdmInstance
.getName());
720 private void startManagedServer() {
721 if(isManagedServerRunning()) {
722 if(CdmStore
.getManagedServer().getDataSourceName().equals(selectedCdmInstance
.getName())) {
725 Display
.getDefault().syncExec(new Runnable() {
735 Job job
= new Job(Messages
.RemotingLoginDialog_JOB_SERVER_LAUNCH
) {
738 public IStatus
run(IProgressMonitor monitor
) {
739 String mgdServerConfigFileName
= "mgd.datasources.xml"; //$NON-NLS-1$
740 String config
= CDMServerUtils
.convertEditorToServerConfig();
741 File managedServerConfigFile
;
743 monitor
.beginTask(Messages
.RemotingLoginDialog_TASK_LAUNCHING_SERVER
, maxUnits
);
745 monitor
.subTask(String
.format(Messages
.RemotingLoginDialog_GENERATING_CONFIG_FILE
, selectedCdmInstance
.getName()));
746 managedServerConfigFile
= CDMServerUtils
.writeManagedServerConfig(config
, mgdServerConfigFileName
);
748 CdmStore
.setManagedServer(new CDMServer(selectedCdmInstance
.getName(), managedServerConfigFile
));
749 monitor
.subTask(Messages
.RemotingLoginDialog_STARTING_MGD_SERVER
);
750 CdmStore
.getManagedServer().start(false, RemotingLoginDialog
.this);
753 // the following loop is a 'fake' progress monitoring where the progress
754 // bar is advanced by one unit every second until maxUnits -2
755 while(!CdmStore
.getManagedServer().isStarted() && !CdmStore
.getManagedServer().isFailed()) {
756 if(serverUnits
< maxUnits
- 2) {
759 } catch (InterruptedException e
) {
765 Display
.getDefault().asyncExec(new Runnable() {
769 updateManagedServerControls();
773 } catch (IOException ioe
) {
774 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_GENERATING_CONFIG_FILE
,
777 TaxeditorStorePlugin
.PLUGIN_ID
,
780 } catch (CDMEmbeddedServerException cse
) {
781 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_STARTING_SERVER
,
784 TaxeditorStorePlugin
.PLUGIN_ID
,
790 return Status
.OK_STATUS
;
795 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);
802 private void stopManagedServer() {
804 CdmStore
.getManagedServer().stop();
805 } catch (Exception e
) {
806 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_STOPPING_SERVER
,
808 String
.format(Messages
.RemotingLoginDialog_COULD_NOT_STOP_SERVER
, CdmStore
.getManagedServer().getPort()),
809 TaxeditorStorePlugin
.PLUGIN_ID
,
813 CdmStore
.setManagedServer(null);
814 updateManagedServerControls();
817 private int getManagedServerPort() {
818 return CdmStore
.getManagedServer() == null ? CdmServerInfo
.NULL_PORT
: CdmStore
.getManagedServer().getPort();
821 private void checkSelectedCdmInstance() {
822 boolean available
= false;
823 String status
= STATUS_NOT_AVAILABLE
;
824 String message
= null;
826 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
)) {
828 if(selectedCsii
.pingInstance(selectedCdmInstance
, getPort())) {
829 status
= STATUS_AVAILABLE
;
832 status
= STATUS_NOT_AVAILABLE
;
837 txtServerCDMVersion
.setText(selectedCsii
.getCdmRemoteSource(selectedCdmInstance
, getPort()).getDbSchemaVersion());
838 int compareDbSchemaVersion
= selectedCsii
.compareDbSchemaVersion(selectedCdmInstance
, getPort());
839 int compareCdmlibServicesVersion
= 0;
840 boolean disableServicesApiTimestampCheck
=
841 PreferencesUtil
.getPreferenceStore().getBoolean((IPreferenceKeys
.DISABLE_SERVICES_API_TIMESTAMP_CHECK
));
842 if(!disableServicesApiTimestampCheck
) {
843 compareCdmlibServicesVersion
= selectedCsii
.compareCdmlibServicesVersion();
845 if(compareDbSchemaVersion
> 0 || compareCdmlibServicesVersion
> 0) {
846 status
= STATUS_NOT_COMPATIBLE
;
848 message
= MESG_COMPATIBLE_EDITOR_OLD
;
849 } else if(compareDbSchemaVersion
< 0 || compareCdmlibServicesVersion
< 0) {
850 status
= STATUS_NOT_COMPATIBLE
;
852 message
= MESG_COMPATIBLE_SERVER_OLD
;
854 status
= STATUS_AVAILABLE
;
856 message
= ""; //$NON-NLS-1$
859 } catch (Exception e
) {
860 txtCdmInstanceStatus
.setToolTipText(e
.getMessage());
862 btnConnect
.setEnabled(available
);
863 txtCdmInstanceStatus
.setText(status
);
864 if(!StringUtils
.isBlank(message
)) {
871 private void connect() {
872 checkSelectedCdmInstance();
874 if(!txtCdmInstanceStatus
.getText().equals(STATUS_AVAILABLE
)) {
878 ICdmRemoteSource source
= selectedCsii
.getCdmRemoteSource(selectedCdmInstance
, getPort());
880 if(!validateLogin(source
)) {
885 CdmStore
.connect(source
, this);
886 } catch (Exception e
) {
887 // Do not expect anything to go wrong at this point, so we throw a runtime exception
889 throw new RuntimeException(e
);
895 public boolean isRememberMe() {
896 return btnRememberMe
.getSelection();
899 private void persistPrefLastServerInstance() {
900 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
901 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
903 lastServerInstancePrefs
.put(LAST_SERVER_KEY
, selectedCsii
.getName());
904 lastServerInstancePrefs
.put(LAST_INSTANCE_KEY
, selectedCdmInstance
.getName());
906 flushPreferences(lastServerInstancePrefs
);
909 private void persistPrefCredentials() {
910 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
911 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
912 credentialsPrefs
.put(getUsernamePrefKey(), txtLogin
.getText());
913 credentialsPrefs
.put(getPasswordPrefKey(), txtPassword
.getText());
914 flushPreferences(credentialsPrefs
);
917 private void flushPreferences(Preferences prefs
) {
920 } catch (BackingStoreException bse
) {
921 setMessage(bse
.getMessage());
925 private void readPrefCredentials() {
926 String username
, password
;
927 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
928 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
929 username
= credentialsPrefs
.get(getUsernamePrefKey(), ""); //$NON-NLS-1$
930 txtLogin
.setText(username
);
931 password
= credentialsPrefs
.get(getPasswordPrefKey(),""); //$NON-NLS-1$
932 txtPassword
.setText(password
);
933 if(username
.isEmpty() || password
.isEmpty()) {
938 private void readPrefLastServerInstance() {
939 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
940 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
942 serverName
= lastServerInstancePrefs
.get(LAST_SERVER_KEY
, null);
943 instanceName
= lastServerInstancePrefs
.get(LAST_INSTANCE_KEY
, null);
946 private void emptyCredentials() {
947 txtLogin
.setText("");
948 txtPassword
.setText("");
951 private String
getUsernamePrefKey() {
952 return selectedCsii
.toString(selectedCdmInstance
.getName(), getPort()) + USERNAME_SUFFIX
;
955 private String
getPasswordPrefKey() {
956 return selectedCsii
.toString(selectedCdmInstance
.getName(), getPort()) + PASSWORD_SUFFIX
;
959 private boolean validateLogin(ICdmRemoteSource remoteSource
) {
960 if(getUsername() == null || getUsername().isEmpty()) {
961 setMessage(Messages
.RemotingLoginDialog_LOGIN_CANNOT_BE_EMPTY
);
964 if(getPassword() == null || getPassword().isEmpty()) {
965 setMessage(Messages
.RemotingLoginDialog_PASSWORD_CANNOT_BE_EMPTY
);
971 IUserService userService
= CdmApplicationRemoteConfiguration
.getUserService(remoteSource
);
972 UsernamePasswordAuthenticationToken token
= new UsernamePasswordAuthenticationToken(getUsername(), getPassword());
973 CdmApplicationRemoteConfiguration
.getAuthenticationManager(userService
).authenticate(token
);
974 } catch(BadCredentialsException e
){
975 setMessage(LoginManager
.INCORRECT_CREDENTIALS_MESSAGE
);
977 } catch(LockedException e
){
978 setMessage(LoginManager
.ACCOUNT_LOCKED_MESSAGE
);
980 } catch(IllegalArgumentException e
){
981 setMessage(LoginManager
.INCORRECT_CREDENTIALS_MESSAGE
);
987 public String
getUsername() {
988 return txtLogin
.getText();
991 public String
getPassword() {
992 return txtPassword
.getText();
995 public void setMessage(String message
) {
996 if(message
!= null && !message
.isEmpty()) {
997 if(message
.length() > 60) {
998 styledTxtMessage
.setToolTipText(message
);
999 message
= message
.substring(0, 60) + "..."; //$NON-NLS-1$
1001 styledTxtMessage
.setText(message
);
1002 styledTxtMessage
.setVisible(true);
1003 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= false;
1004 shlConnect
.setSize(MIN_WIDTH
, getHeightWithoutMessage() + MESSAGE_HEIGHT
);
1005 shlConnect
.setMinimumSize(MIN_WIDTH
, getHeightWithoutMessage() + MESSAGE_HEIGHT
);
1007 styledTxtMessage
.setText(""); //$NON-NLS-1$
1008 styledTxtMessage
.setVisible(false);
1009 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= true;
1010 shlConnect
.setSize(MIN_WIDTH
, getHeightWithoutMessage());
1011 shlConnect
.setMinimumSize(MIN_WIDTH
, getHeightWithoutMessage());
1013 remotingComposite
.layout();
1016 private int getHeightWithoutMessage() {
1017 if(xpndblcmpstAdvanced
.isExpanded()) {
1018 return MIN_EXP_HEIGHT
;
1025 public void hide(boolean isHidden
) {
1026 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
1027 shlConnect
.setVisible(!isHidden
);
1030 public void dispose() {
1031 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
1032 shlConnect
.dispose();
1036 public void onComplete() {
1037 Display
.getDefault().asyncExec(new Runnable() {
1040 if(!isDevRemoteSource
) {
1041 if(isRememberMe()) {
1042 persistPrefCredentials();
1044 persistPrefLastServerInstance();
1051 private String
generateLastModifiedTooltip(String cdmlibLastModified
) {
1052 if(StringUtils
.isBlank(cdmlibLastModified
)) {
1053 return ""; //$NON-NLS-1$
1055 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy.MM.dd.HH.mm.z"); //$NON-NLS-1$
1056 Date cdmlibLastModifiedDate
;
1057 String cdmlibLastModifiedTimestamp
= ""; //$NON-NLS-1$
1059 cdmlibLastModifiedDate
= new Date(Long
.valueOf(cdmlibLastModified
));
1060 cdmlibLastModifiedTimestamp
= sdf
.format(cdmlibLastModifiedDate
);
1062 return cdmlibLastModifiedTimestamp
;
1065 private void setEditorInfo() {
1066 txtEditorCDMVersion
.setText(CdmMetaData
.getDbSchemaVersion());
1067 String editorVersionTimestamp
= generateLastModifiedTooltip(CdmApplicationState
.getCdmlibLastModified());
1068 txtEditorVersion
.setText(CdmApplicationState
.getCdmlibVersion() + ":" + editorVersionTimestamp
); //$NON-NLS-1$
1071 private void clearOnServerChange() {
1072 setMessage(""); //$NON-NLS-1$
1073 txtServerCDMVersion
.setText(""); //$NON-NLS-1$
1074 txtServerVersion
.setText(""); //$NON-NLS-1$
1075 txtServerVersion
.setToolTipText(""); //$NON-NLS-1$
1076 txtServerCDMVersion
.setText(""); //$NON-NLS-1$
1077 comboCdmInstance
.removeAll();
1078 txtCdmInstanceStatus
.setText(""); //$NON-NLS-1$
1079 txtPort
.setEditable(false);
1080 txtPort
.setEnabled(false);
1083 private void clearOnInstanceChange() {
1084 setMessage(""); //$NON-NLS-1$
1085 txtServerCDMVersion
.setText(""); //$NON-NLS-1$
1092 public void handleError(final Throwable t
) {
1094 Display
.getDefault().syncExec(new Runnable() {
1099 String title
= Messages
.RemotingLoginDialog_SERVER_LAUNCH_ERROR
;
1100 String message
= t
.getMessage();
1103 MessagingUtils
.errorDialog(title
,
1106 TaxeditorStorePlugin
.PLUGIN_ID
,