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
.net
.SocketTimeoutException
;
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
.apache
.log4j
.Logger
;
22 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
23 import org
.eclipse
.core
.runtime
.IStatus
;
24 import org
.eclipse
.core
.runtime
.Status
;
25 import org
.eclipse
.core
.runtime
.jobs
.Job
;
26 import org
.eclipse
.core
.runtime
.preferences
.ConfigurationScope
;
27 import org
.eclipse
.core
.runtime
.preferences
.IEclipsePreferences
;
28 import org
.eclipse
.jface
.layout
.GridDataFactory
;
29 import org
.eclipse
.swt
.SWT
;
30 import org
.eclipse
.swt
.SWTException
;
31 import org
.eclipse
.swt
.custom
.StyledText
;
32 import org
.eclipse
.swt
.events
.KeyAdapter
;
33 import org
.eclipse
.swt
.events
.KeyEvent
;
34 import org
.eclipse
.swt
.events
.MouseAdapter
;
35 import org
.eclipse
.swt
.events
.MouseEvent
;
36 import org
.eclipse
.swt
.events
.SelectionAdapter
;
37 import org
.eclipse
.swt
.events
.SelectionEvent
;
38 import org
.eclipse
.swt
.layout
.FillLayout
;
39 import org
.eclipse
.swt
.layout
.GridData
;
40 import org
.eclipse
.swt
.layout
.GridLayout
;
41 import org
.eclipse
.swt
.widgets
.Button
;
42 import org
.eclipse
.swt
.widgets
.Combo
;
43 import org
.eclipse
.swt
.widgets
.Composite
;
44 import org
.eclipse
.swt
.widgets
.Dialog
;
45 import org
.eclipse
.swt
.widgets
.Display
;
46 import org
.eclipse
.swt
.widgets
.Label
;
47 import org
.eclipse
.swt
.widgets
.Shell
;
48 import org
.eclipse
.swt
.widgets
.Text
;
49 import org
.eclipse
.ui
.forms
.events
.ExpansionEvent
;
50 import org
.eclipse
.ui
.forms
.events
.IExpansionListener
;
51 import org
.eclipse
.ui
.forms
.widgets
.ExpandableComposite
;
52 import org
.eclipse
.ui
.progress
.IProgressConstants
;
53 import org
.eclipse
.wb
.swt
.SWTResourceManager
;
54 import org
.osgi
.service
.prefs
.BackingStoreException
;
55 import org
.osgi
.service
.prefs
.Preferences
;
56 import org
.springframework
.security
.authentication
.BadCredentialsException
;
57 import org
.springframework
.security
.authentication
.LockedException
;
58 import org
.springframework
.security
.authentication
.UsernamePasswordAuthenticationToken
;
60 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationRemoteConfiguration
;
61 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
62 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
63 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
64 import eu
.etaxonomy
.cdm
.config
.CdmSourceException
;
65 import eu
.etaxonomy
.cdm
.config
.ICdmSource
;
66 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
;
67 import eu
.etaxonomy
.cdm
.persistence
.permission
.Role
;
68 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
69 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
70 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
71 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
72 import eu
.etaxonomy
.taxeditor
.remoting
.server
.CdmServerException
;
73 import eu
.etaxonomy
.taxeditor
.remoting
.server
.CdmServerUtils
;
74 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmRemoteLocalhostSource
;
75 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
;
76 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
.CdmInstanceInfo
;
77 import eu
.etaxonomy
.taxeditor
.remoting
.source
.ICdmRemoteSource
;
78 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
79 import eu
.etaxonomy
.taxeditor
.store
.LoginManager
;
80 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
81 import eu
.etaxonomy
.taxeditor
.webapp
.CdmEmbeddedServerException
;
82 import eu
.etaxonomy
.taxeditor
.webapp
.CdmServer
;
83 import eu
.etaxonomy
.taxeditor
.webapp
.ICDMServerError
;
89 public class RemotingLoginDialog
extends Dialog
implements ICDMServerError
{
91 private Logger logger
= Logger
.getLogger(getClass());
93 private static final String DEFAULT_PASS
= "00000"; //$NON-NLS-1$
94 private static final String DEFAULT_USER
= "admin"; //$NON-NLS-1$
95 private static final String UBUNTU
= "Ubuntu"; //$NON-NLS-1$
96 protected Object result
;
97 protected Shell shlConnect
;
98 private Text txtCdmServerStatus
;
99 private Text txtCdmInstanceStatus
;
100 private Combo comboCdmServer
;
101 private Combo comboCdmInstance
;
102 private Button btnConnect
;
104 private final Map
<String
, CdmServerInfo
> csiiMap
= new HashMap
<>();
106 private final static String STATUS_AVAILABLE
= Messages
.RemotingLoginDialog_STATUS_AVAILABLE
;
107 private final static String STATUS_NOT_AVAILABLE
= Messages
.RemotingLoginDialog_STATUS_NOT_AVAILABLE
;
108 private final static String STATUS_STARTED
= Messages
.RemotingLoginDialog_STATUS_STARTED
;
109 private final static String STATUS_NOT_STARTED
= Messages
.RemotingLoginDialog_STATUS_NOT_STARTED
;
110 private final static String STATUS_RETRIEVING
= Messages
.RemotingLoginDialog_STATUS_RETRIEVING
;
111 private final static String STATUS_CHECKING_AVAILABILITY
= Messages
.RemotingLoginDialog_STATUS_CHECKING
;
112 private final static String STATUS_NO_INSTANCES
= Messages
.RemotingLoginDialog_STATUS_NO_INSTANCES_FOUND
;
113 private final static String STATUS_NOT_COMPATIBLE
= Messages
.RemotingLoginDialog_STATUS_NOT_COMPATIBLE
;
115 private final static String MESG_COMPATIBLE_EDITOR_OLD
= Messages
.RemotingLoginDialog_UPDATE_EDITOR
;
116 private final static String MESG_COMPATIBLE_SERVER_OLD
= Messages
.RemotingLoginDialog_CHOOSE_COMPATIBLE_CDM_SERVER
;
117 private final static String MESG_SCHEMA_MISSING
= Messages
.RemotingLoginDialog_SCHEMA_MISSING
;
118 private final static String MESG_NO_SCHEMA
= Messages
.RemotingLoginDialog_NO_SCHEMA
;
120 private final static String LABEL_CONNECT
= Messages
.RemotingLoginDialog_LABEL_CONNECT
;
121 private final static String LABEL_CREATE_SCHEMA
= Messages
.RemotingLoginDialog_LABEL_CREATE_SCHEMA
;
122 private final static String LABEL_UPDATE_SCHEMA_VERSION
= Messages
.RemotingLoginDialog_LABEL_UPDATE_SCHEMA_VERSION
;
123 private final static String MESG_UPDATE_SCHEMA_VERSION
= Messages
.RemotingLoginDialog_MSG_UPDATE_SCHEMA_VERSION
;
125 private final static String STORE_PREFERENCES_NODE
= "eu.etaxonomy.taxeditor.store"; //$NON-NLS-1$
127 private final static String LOGIN_NODE
= "login"; //$NON-NLS-1$
128 private final static String USERNAME_SUFFIX
= "_username"; //$NON-NLS-1$
129 private final static String PASSWORD_SUFFIX
= "_password"; //$NON-NLS-1$
131 private final static String LAST_SERVER_INSTANCE_NODE
= "lastServerInstance"; //$NON-NLS-1$
132 private final static String LAST_SERVER_KEY
= "lastServerKey"; //$NON-NLS-1$
133 private final static String LAST_INSTANCE_KEY
= "lastInstanceKey"; //$NON-NLS-1$
135 private Composite remotingComposite
;
136 private CdmServerInfo selectedServerInfo
;
137 private CdmInstanceInfo selectedCdmInstance
;
138 private Button btnCdmServerRefresh
;
139 private Button btnCdmInstanceRefresh
;
140 private Button btnStopServer
;
141 private Composite loginComposite
;
142 private Label lblLogin
;
143 private Text txtLogin
;
144 private Label lblPassword
;
145 private Text txtPassword
;
146 private Button btnRememberMe
;
147 private Label lblDefaultLogin
;
148 private Composite compAdvanced
;
149 private Label lblPort
;
150 private Text txtPort
;
151 private Label lblServerCdmlibVersion
;
152 private Text txtServerCdmlibVersion
;
153 private ExpandableComposite expandableCompositeAdvanced
;
154 private StyledText styledTxtMessage
;
156 // private final int MIN_WIDTH = 530;
157 // private final int MIN_HEIGHT = 220;
158 // private final int MIN_EXP_HEIGHT = 380;
160 private final int MESSAGE_HEIGHT
= 50;
161 private Label lblEditorCdmlibVersion
;
162 private Text txtEditorCdmlibVersion
;
163 private Label lblServerSchemaVersion
;
164 private Text txtServerSchemaVersion
;
165 private Label lblEditorCdmVersion
;
166 private Text txtEditorCdmVersion
;
168 private String serverName
, instanceName
;
169 private boolean autoConnect
= false;
170 private boolean loadLoginPrefs
= true;
171 private boolean isDevRemoteSource
= false;
172 private Job serverJob
;
179 public RemotingLoginDialog(Shell parent
, int style
) {
180 super(parent
, style
);
181 setText(Messages
.RemotingLoginDialog_LABEL_LOGIN
);
184 public Object
open(ICdmRemoteSource source
, boolean loadLoginPrefs
, boolean autoConnect
) {
185 this.loadLoginPrefs
= loadLoginPrefs
;
186 this.serverName
= source
.getName();
187 if (source
instanceof CdmRemoteLocalhostSource
){
188 this.instanceName
= ((CdmRemoteLocalhostSource
)source
).getDatasourceName();
190 String contextPath
= source
.getContext();
191 this.instanceName
= contextPath
== null?
"" : contextPath
.substring(contextPath
.lastIndexOf("/") + 1); //$NON-NLS-1$
193 return open(serverName
, instanceName
, loadLoginPrefs
, autoConnect
);
196 public Object
open(String serverName
, String instanceName
, boolean loadLoginPrefs
, boolean autoConnect
) {
197 this.serverName
= serverName
;
198 this.instanceName
= instanceName
;
199 this.loadLoginPrefs
= loadLoginPrefs
;
200 this.autoConnect
= autoConnect
;
206 * @return the dialog result
208 public Object
open() {
211 if(serverName
== null && instanceName
== null) {
212 readPrefLastServerInstance();
216 populateCdmServerCombo();
217 shlConnect
.pack(true);
220 expandableCompositeAdvanced
.setExpanded(false);
222 Display display
= getParent().getDisplay();
224 while (!shlConnect
.isDisposed()) {
225 if (!display
.isDisposed()){
226 if (!display
.readAndDispatch()) {
236 * Create contents of the dialog.
238 private void createContents() {
239 shlConnect
= new Shell(getParent(), SWT
.DIALOG_TRIM
| SWT
.APPLICATION_MODAL
| SWT
.RESIZE
);
240 shlConnect
.setText(LABEL_CONNECT
);
241 shlConnect
.setLayout(new FillLayout(SWT
.HORIZONTAL
));
243 remotingComposite
= new Composite(shlConnect
, SWT
.NONE
);
244 remotingComposite
.setLayout(new GridLayout(1, false));
247 Composite cdmServerComposite
= new Composite(remotingComposite
, SWT
.NONE
);
248 GridData gd_cdmServerComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
249 cdmServerComposite
.setLayoutData(gd_cdmServerComposite
);
250 cdmServerComposite
.setLayout(new GridLayout(4, false));
252 Label lblCdmServer
= new Label(cdmServerComposite
, SWT
.NONE
);
253 lblCdmServer
.setText(Messages
.RemotingLoginDialog_LABEL_CDM_SERVER
);
254 lblCdmServer
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
255 lblCdmServer
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
257 comboCdmServer
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
258 comboCdmServer
.addSelectionListener(new SelectionAdapter() {
260 public void widgetSelected(SelectionEvent e
) {
264 GridData gd_comboCdmServer
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
265 comboCdmServer
.setLayoutData(gd_comboCdmServer
);
266 comboCdmServer
.select(0);
268 txtCdmServerStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
269 txtCdmServerStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
270 txtCdmServerStatus
.setEditable(false);
271 GridData gd_txtCdmServerStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
273 txtCdmServerStatus
.setLayoutData(gd_txtCdmServerStatus
);
275 btnCdmServerRefresh
= new Button(cdmServerComposite
, SWT
.NONE
);
276 btnCdmServerRefresh
.addSelectionListener(new SelectionAdapter() {
278 public void widgetSelected(SelectionEvent e
) {
282 btnCdmServerRefresh
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
283 btnCdmServerRefresh
.setText(Messages
.RemotingLoginDialog_LABEL_REFRESH
);
286 Label lblCdmInstance
= new Label(cdmServerComposite
, SWT
.NONE
);
287 GridData gd_lblCdmInstance
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
288 //gd_lblCdmInstance.heightHint = 30;
289 lblCdmInstance
.setLayoutData(gd_lblCdmInstance
);
290 lblCdmInstance
.setText(Messages
.RemotingLoginDialog_LABEL_CDM_INSTANCE
);
291 lblCdmInstance
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
293 comboCdmInstance
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
294 comboCdmInstance
.addSelectionListener(new SelectionAdapter() {
296 public void widgetSelected(SelectionEvent e
) {
297 refreshCdmInstance();
300 GridData gd_comboCdmInstance
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
301 comboCdmInstance
.setLayoutData(gd_comboCdmInstance
);
302 comboCdmInstance
.select(0);
304 txtCdmInstanceStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
305 txtCdmInstanceStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
306 txtCdmInstanceStatus
.setEditable(false);
307 GridData gd_txtCdmInstanceStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
308 txtCdmInstanceStatus
.setLayoutData(gd_txtCdmInstanceStatus
);
310 btnCdmInstanceRefresh
= new Button(cdmServerComposite
, SWT
.FLAT
);
311 btnCdmInstanceRefresh
.addSelectionListener(new SelectionAdapter() {
313 public void widgetSelected(SelectionEvent e
) {
314 refreshCdmInstance();
317 GridData gd_btnCdmInstanceRefresh
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
318 btnCdmInstanceRefresh
.setLayoutData(gd_btnCdmInstanceRefresh
);
319 btnCdmInstanceRefresh
.setText(Messages
.RemotingLoginDialog_LABEL_REFRESH
);
322 loginComposite
= new Composite(remotingComposite
, SWT
.NONE
);
323 GridData gd_loginComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
324 loginComposite
.setLayoutData(gd_loginComposite
);
325 GridLayout gl_loginComposite
= new GridLayout(6, false);
326 gl_loginComposite
.marginTop
= 5;
327 loginComposite
.setLayout(gl_loginComposite
);
329 lblLogin
= new Label(loginComposite
, SWT
.CENTER
);
330 GridData gd_lblLogin
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
331 lblLogin
.setLayoutData(gd_lblLogin
);
332 lblLogin
.setText(Messages
.RemotingLoginDialog_LABEL_LOGIN_COLON
);
333 lblLogin
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
335 txtLogin
= new Text(loginComposite
, SWT
.BORDER
);
336 GridData gd_txtLogin
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
337 gd_txtLogin
.minimumWidth
= 80;
338 txtLogin
.setLayoutData(gd_txtLogin
);
340 lblPassword
= new Label(loginComposite
, SWT
.CENTER
);
341 lblPassword
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
342 lblPassword
.setText(Messages
.RemotingLoginDialog_LABEL_PASSWORD
);
343 lblPassword
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
345 txtPassword
= new Text(loginComposite
, SWT
.BORDER
| SWT
.PASSWORD
);
346 GridData gd_txtPassword
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
347 gd_txtPassword
.minimumWidth
= 80;
348 txtPassword
.setLayoutData(gd_txtPassword
);
349 @SuppressWarnings("unused")
350 Label nope
= new Label(loginComposite
, SWT
.NONE
);
351 txtPassword
.addKeyListener(new KeyAdapter() {
353 public void keyPressed(KeyEvent e
) {
354 if(e
.character
==SWT
.CR
){
355 connectButtonPressed();
360 btnConnect
= new Button(loginComposite
, SWT
.FLAT
);
361 btnConnect
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1));
362 btnConnect
.addSelectionListener(new SelectionAdapter() {
364 public void widgetSelected(SelectionEvent e
) {
365 connectButtonPressed();
368 btnConnect
.setText(LABEL_CONNECT
);
370 btnRememberMe
= new Button(loginComposite
, SWT
.CHECK
);
371 btnRememberMe
.setSelection(true);
372 GridData gd_btnRememberMe
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 2, 1);
373 btnRememberMe
.setLayoutData(gd_btnRememberMe
);
374 btnRememberMe
.setText(Messages
.RemotingLoginDialog_LABEL_REMEMBER_ME
);
376 lblDefaultLogin
= new Label(loginComposite
, SWT
.NONE
);
377 GridDataFactory
.fillDefaults().span(4, 1).align(SWT
.TRAIL
, SWT
.CENTER
).applyTo(lblDefaultLogin
);
378 lblDefaultLogin
.setText(String
.format(Messages
.RemotingLoginDialog_DEFAULT_LOGIN
, DEFAULT_USER
, DEFAULT_PASS
));
379 lblDefaultLogin
.setVisible(false);
381 styledTxtMessage
= new StyledText(remotingComposite
, SWT
.NONE
);
382 styledTxtMessage
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
383 styledTxtMessage
.setForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
384 styledTxtMessage
.setFont(SWTResourceManager
.getFont(UBUNTU
, 12, SWT
.BOLD
));
385 styledTxtMessage
.setSelectionBackground(SWTResourceManager
.getColor(SWT
.COLOR_LIST_SELECTION_TEXT
));
386 styledTxtMessage
.setSelectionForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
387 styledTxtMessage
.setDoubleClickEnabled(false);
388 styledTxtMessage
.setEditable(false);
389 styledTxtMessage
.setWordWrap(true);
391 GridData gd_styledTxtMessage
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
392 gd_styledTxtMessage
.exclude
= true;
393 gd_styledTxtMessage
.minimumHeight
= MESSAGE_HEIGHT
;
395 styledTxtMessage
.setLayoutData(gd_styledTxtMessage
);
398 expandableCompositeAdvanced
= new ExpandableComposite(remotingComposite
, SWT
.NONE
, ExpandableComposite
.TWISTIE
);
399 GridData gd_xpndblcmpstAdvanced
= new GridData(SWT
.FILL
, SWT
.FILL
, false, true, 1, 1);
400 expandableCompositeAdvanced
.setLayoutData(gd_xpndblcmpstAdvanced
);
401 expandableCompositeAdvanced
.addExpansionListener(new IExpansionListener() {
403 public void expansionStateChanged(ExpansionEvent e
) {
404 shlConnect
.pack(true);
407 public void expansionStateChanging(ExpansionEvent e
) {
410 expandableCompositeAdvanced
.setText(Messages
.RemotingLoginDialog_LABEL_ADVANCED
);
411 expandableCompositeAdvanced
.setExpanded(true);
413 compAdvanced
= new Composite(expandableCompositeAdvanced
, SWT
.NONE
);
414 expandableCompositeAdvanced
.setClient(compAdvanced
);
415 compAdvanced
.setLayout(new GridLayout(4, false));
417 lblPort
= new Label(compAdvanced
, SWT
.CENTER
);
418 lblPort
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
419 lblPort
.setText(Messages
.RemotingLoginDialog_LABEL_PORT
);
420 lblPort
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
422 txtPort
= new Text(compAdvanced
, SWT
.BORDER
);
423 GridData gd_txtPort
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1);
424 gd_txtPort
.minimumWidth
= 50;
425 txtPort
.setLayoutData(gd_txtPort
);
427 lblServerCdmlibVersion
= new Label(compAdvanced
, SWT
.CENTER
);
428 lblServerCdmlibVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
429 lblServerCdmlibVersion
.setText(Messages
.RemotingLoginDialog_LABEL_SERVER_CDMLIB_VERSION
);
430 lblServerCdmlibVersion
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
432 txtServerCdmlibVersion
= new Text(compAdvanced
, SWT
.BORDER
);
433 txtServerCdmlibVersion
.setEditable(false);
434 txtServerCdmlibVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
436 btnStopServer
= new Button(compAdvanced
, SWT
.FLAT
);
437 btnStopServer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 2, 1));
438 btnStopServer
.addMouseListener(new MouseAdapter() {
440 public void mouseUp(MouseEvent e
) {
444 btnStopServer
.setText(Messages
.RemotingLoginDialog_LABEL_STOP_MANAGED_SERVER
);
446 lblEditorCdmlibVersion
= new Label(compAdvanced
, SWT
.CENTER
);
447 lblEditorCdmlibVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
448 lblEditorCdmlibVersion
.setText(Messages
.RemotingLoginDialog_LABEL_EDITOR_CDMLIB_VERSION
);
449 lblEditorCdmlibVersion
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
451 txtEditorCdmlibVersion
= new Text(compAdvanced
, SWT
.BORDER
);
452 txtEditorCdmlibVersion
.setEditable(false);
453 txtEditorCdmlibVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
456 lblServerSchemaVersion
= new Label(compAdvanced
, SWT
.CENTER
);
457 lblServerSchemaVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
458 lblServerSchemaVersion
.setText(Messages
.RemotingLoginDialog_LABEL_SERVER_CDM_VERSION
);
459 lblServerSchemaVersion
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
461 txtServerSchemaVersion
= new Text(compAdvanced
, SWT
.BORDER
);
462 txtServerSchemaVersion
.setEditable(false);
463 txtServerSchemaVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
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));
476 @SuppressWarnings("unused")
477 private void addEmptyCells(int cnt
) {
478 for (int i
= 0; i
< cnt
; i
++) {
479 new Label(compAdvanced
, SWT
.NONE
);
483 private void connectButtonPressed() {
484 if(selectedServerInfo
.isLocalhostMgd() && !isSelectedCdmInstanceRunningInManagedServer()) {
485 startManagedServer();
488 if (CdmStore
.isActive() && CdmStore
.currentAuthentiationHasOneOfRoles(Role
.ROLE_REMOTING
)){
489 PreferencesUtil
.setNomenclaturalCodePreferences();
494 private void populateCdmServerCombo() {
495 Job job
= new Job(Messages
.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES
) {
497 protected IStatus
run(IProgressMonitor monitor
) {
498 Display
.getDefault().syncExec(new Runnable() {
501 for(CdmServerInfo csii
: CdmServerInfo
.getCdmServers()) {
502 csiiMap
.put(csii
.getName(), csii
);
503 comboCdmServer
.add(csii
.getName());
505 int serverIndex
= -1;
506 if(serverName
!= null) {
507 serverIndex
= comboCdmServer
.indexOf(serverName
);
509 if(serverIndex
== -1) {
510 comboCdmServer
.select(0);
513 comboCdmServer
.select(serverIndex
);
515 ICdmSource devRemoteSource
= CdmServerInfo
.getDevServerRemoteSource();
516 if(devRemoteSource
!= null) {
517 isDevRemoteSource
= true;
518 String username
= System
.getProperty("cdm.server.dev.username"); //$NON-NLS-1$
519 String password
= System
.getProperty("cdm.server.dev.password"); //$NON-NLS-1$
520 if(username
!= null && !username
.isEmpty() && password
!= null && !password
.isEmpty()) {
521 txtLogin
.setText(username
);
522 txtPassword
.setText(password
);
523 CdmStore
.connect(devRemoteSource
, RemotingLoginDialog
.this);
530 return Status
.OK_STATUS
;
536 private void refreshCdmServer() {
538 txtCdmServerStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
539 clearOnServerChange();
541 updateSelectedCdmServer();
542 Display
.getDefault().asyncExec(new Runnable() {
545 checkSelectedCdmServer();
549 catch(SWTException e
){
550 //catch widget is disposed exception which may occurr if
551 //dialog is closed but the runnable tries to update
555 private void updateSelectedCdmServer() {
556 int selIndex
= comboCdmServer
.getSelectionIndex();
558 selectedServerInfo
= csiiMap
.get(comboCdmServer
.getItem(selIndex
));
562 private void updatePort() {
563 txtPort
.setText(""); //$NON-NLS-1$
564 if(selectedServerInfo
!= null) {
565 int port
= selectedServerInfo
.getPort();
566 if(port
== CdmServerInfo
.NULL_PORT
) {
567 txtPort
.setText(CdmServerInfo
.NULL_PORT_STRING
);
569 txtPort
.setText(String
.valueOf(port
));
574 private int getPort() {
575 int port
= CdmServerInfo
.NULL_PORT
;
577 port
= Integer
.valueOf(txtPort
.getText());
578 } catch (NumberFormatException nfe
) {
579 if(!CdmServerInfo
.NULL_PORT_STRING
.equals(txtPort
.getText())) {
580 setMessage(Messages
.RemotingLoginDialog_MESSAGE_PORT_SHOULD_BE_INTEGER
);
586 private void checkSelectedCdmServer() {
588 if(selectedServerInfo
!= null) {
589 if(selectedServerInfo
.isLocalhost()) {
590 txtPort
.setEditable(true);
591 txtPort
.setEnabled(true);
592 setCdmlibVersion(txtServerCdmlibVersion
);
595 if(selectedServerInfo
.pingServer()) {
596 txtCdmServerStatus
.setText(STATUS_AVAILABLE
);
597 populateCdmInstanceCombo(true);
598 String serverVersionTimestamp
= generateLastModifiedTooltip(selectedServerInfo
.getCdmlibLastModified());
599 txtServerCdmlibVersion
.setText(selectedServerInfo
.getCdmlibServicesVersion() + ":" + serverVersionTimestamp
); //$NON-NLS-1$
601 txtCdmServerStatus
.setText(STATUS_NOT_AVAILABLE
);
602 comboCdmInstance
.removeAll();
603 disableCdmInstanceControls("", ""); //$NON-NLS-1$ //$NON-NLS-2$
605 } catch (CdmServerException
| IOException e
) {
606 txtCdmServerStatus
.setText(STATUS_NOT_AVAILABLE
);
607 // TODO distinguish java.net.ConnectException: Connection refused, java.net.SocketTimeoutException: Read timed out
609 if(e
instanceof CdmServerException
&& e
.getCause() != null){
610 cause
= e
.getCause();
612 String message
= Messages
.RemotingLoginDialog_CONNECTION_FAILED_MESSAGE
;
613 if(cause
instanceof SocketTimeoutException
){
614 message
= Messages
.RemotingLoginDialog_CONNECTION_TIMEOUT_MESSAGE
;
616 MessagingUtils
.warningDialog(Messages
.RemotingLoginDialog_CONNECTION_FAILED_TITLE
, this,
618 logger
.warn(Messages
.RemotingLoginDialog_CONNECTION_FAILED_TITLE
, e
);
623 catch(SWTException e
){
624 //catch widget is disposed exception which may occurr if
625 //dialog is closed but the runnable tries to update
629 private void populateCdmInstanceCombo(final boolean forceRefresh
) {
630 comboCdmInstance
.removeAll();
631 comboCdmInstance
.setEnabled(false);
632 btnConnect
.setEnabled(false);
633 txtCdmInstanceStatus
.setText(STATUS_RETRIEVING
);
634 txtCdmInstanceStatus
.setToolTipText(""); //$NON-NLS-1$
636 serverJob
= new Job(Messages
.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES
) {
638 protected IStatus
run(IProgressMonitor monitor
) {
640 if(selectedServerInfo
!= null) {
642 selectedServerInfo
.refreshInstances();
644 final List
<CdmInstanceInfo
> instances
= selectedServerInfo
.getInstances();
645 Display
.getDefault().asyncExec(new Runnable() {
648 if(!instances
.isEmpty()) {
649 for(CdmInstanceInfo cdmInstance
: instances
) {
650 comboCdmInstance
.add(cdmInstance
.getName());
652 int instanceIndex
= -1;
653 if(instanceName
!= null) {
654 instanceIndex
= comboCdmInstance
.indexOf(instanceName
);
656 if(instanceIndex
== -1) {
657 comboCdmInstance
.select(0);
660 comboCdmInstance
.select(instanceIndex
);
662 refreshCdmInstance();
663 comboCdmInstance
.setEnabled(true);
669 txtCdmInstanceStatus
.setText(STATUS_NO_INSTANCES
);
670 btnConnect
.setEnabled(false);
675 } catch (final CdmServerException e
) {
676 MessagingUtils
.warn(getClass(), e
);
677 Display
.getDefault().asyncExec(new Runnable() {
680 disableCdmInstanceControls(STATUS_NOT_AVAILABLE
, e
.getMessage());
684 return Status
.OK_STATUS
;
688 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
) && !isDevRemoteSource
) {
690 serverJob
.schedule();
694 private void disableCdmInstanceControls(String cdmInstanceStatus
, String tooltip
) {
695 txtCdmInstanceStatus
.setText(cdmInstanceStatus
);
696 txtCdmInstanceStatus
.setToolTipText(tooltip
);
697 comboCdmInstance
.setEnabled(false);
698 btnConnect
.setEnabled(false);
702 private void refreshCdmInstance() {
703 txtCdmInstanceStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
704 clearOnInstanceChange();
705 updateSelectedCdmInstance();
706 checkSelectedCdmInstance();
707 updateManagedServerControls();
710 private void updateSelectedCdmInstance() {
711 int selIndex
= comboCdmInstance
.getSelectionIndex();
713 selectedCdmInstance
= selectedServerInfo
.getInstanceFromName(comboCdmInstance
.getItem(selIndex
));
715 readPrefCredentials();
720 private void updateManagedServerControls() {
721 if(selectedServerInfo
.isLocalhostMgd()) {
722 if(isSelectedCdmInstanceRunningInManagedServer()) {
723 txtCdmInstanceStatus
.setText(STATUS_STARTED
);
725 txtCdmInstanceStatus
.setText(STATUS_NOT_STARTED
);
727 btnConnect
.setEnabled(true);
728 selectedServerInfo
.setPort(getManagedServerPort());
732 if(isManagedServerRunning()) {
733 btnStopServer
.setEnabled(true);
735 btnStopServer
.setEnabled(false);
739 private boolean isManagedServerRunning() {
740 return CdmStore
.getManagedServer() != null && CdmStore
.getManagedServer().isAlive();
743 private boolean isSelectedCdmInstanceRunningInManagedServer() {
744 return CdmStore
.getManagedServer() != null &&
745 CdmStore
.getManagedServer().isAlive() &&
746 selectedServerInfo
.isLocalhostMgd() &&
747 CdmStore
.getManagedServer().getDataSourceName().equals(selectedCdmInstance
.getName());
750 private void startManagedServer() {
751 if(isManagedServerRunning()) {
752 if(CdmStore
.getManagedServer().getDataSourceName().equals(selectedCdmInstance
.getName())) {
755 Display
.getDefault().syncExec(new Runnable() {
764 boolean forceSchemaCreate
= !schemaExists(selectedCdmInstance
);
765 boolean forceSchemaUpdate
= LABEL_UPDATE_SCHEMA_VERSION
.equals(btnConnect
.getText());
767 Job job
= new Job(Messages
.RemotingLoginDialog_JOB_SERVER_LAUNCH
) {
770 public IStatus
run(IProgressMonitor monitor
) {
771 String mgdServerConfigFileName
= "mgd.datasources.xml"; //$NON-NLS-1$
772 String config
= CdmServerUtils
.convertEditorToServerConfig();
774 monitor
.beginTask(Messages
.RemotingLoginDialog_TASK_LAUNCHING_SERVER
, maxUnits
);
776 monitor
.subTask(String
.format(Messages
.RemotingLoginDialog_GENERATING_CONFIG_FILE
, selectedCdmInstance
.getName()));
777 File managedServerConfigFile
= CdmServerUtils
.writeManagedServerConfig(config
, mgdServerConfigFileName
);
779 CdmServer cdmServer
= new CdmServer(selectedCdmInstance
.getName(), managedServerConfigFile
);
780 // boolean forceSchemaCreate = CdmStore.getManagedServer() != null
781 // && CdmStore.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName())
782 // && CdmStore.getManagedServer().isForceSchemaCreate();
783 cdmServer
.setForceSchemaCreate(forceSchemaCreate
);
784 cdmServer
.setForceSchemaUpdate(forceSchemaUpdate
);
785 CdmStore
.setManagedServer(cdmServer
);
786 monitor
.subTask(Messages
.RemotingLoginDialog_STARTING_MGD_SERVER
);
787 cdmServer
.start(false, RemotingLoginDialog
.this);
790 // the following loop is a 'fake' progress monitoring where the progress
791 // bar is advanced by one unit every second until maxUnits -2
792 while(!CdmStore
.getManagedServer().isStarted() && !CdmStore
.getManagedServer().isFailed()) {
793 if(serverUnits
< maxUnits
- 2) {
796 } catch (InterruptedException e
) {
802 Display
.getDefault().syncExec(()->{
804 updateManagedServerControls();
807 } catch (IOException ioe
) {
808 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_GENERATING_CONFIG_FILE
,
811 TaxeditorStorePlugin
.PLUGIN_ID
,
814 } catch (CdmEmbeddedServerException cese
) {
815 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_STARTING_SERVER
,
818 TaxeditorStorePlugin
.PLUGIN_ID
,
824 // NOTE: Errors thrown during server startup are passed to the handleError() implementation
825 // TODO: is the above catch clause for CDMEmbeddedServerException still valuable?
827 return Status
.OK_STATUS
;
832 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);
839 private boolean schemaExists(CdmInstanceInfo instanceInfo
) {
840 if (instanceInfo
.getDataSource() != null){
842 //TODO we need a new method in cdmlib to check for existing schema
843 String schemaVersion
= instanceInfo
.getDataSource().getDbSchemaVersion();
844 return schemaVersion
!= null;
845 } catch (CdmSourceException e
) {
853 private String
managedSchemaVersion(CdmInstanceInfo instanceInfo
) throws CdmSourceException
{
854 if (instanceInfo
.getDataSource() != null){
855 return instanceInfo
.getDataSource().getDbSchemaVersion();
857 throw new RuntimeException("ManagedSchemaVersion only available for managed server instances.");
860 private int compareSchemaVersion(CdmInstanceInfo instanceInfo
) throws CdmSourceException
{
861 return CdmMetaData
.compareVersion(managedSchemaVersion(instanceInfo
), CdmMetaData
.getDbSchemaVersion(), 3, null);
865 public void handleError(final Throwable t
) {
867 if(CdmStore
.getManagedServer().isFailed() && CdmStore
.getManagedServer().isPotentiallyMissingSchema()) {
868 CdmStore
.getManagedServer().setForceSchemaCreate(true);
869 // we are in a separate thread here, thus update the screen via
870 checkManagedSelectedInstance();
872 Display
.getDefault().syncExec(new Runnable() {
877 String title
= Messages
.RemotingLoginDialog_SERVER_LAUNCH_ERROR
;
878 String message
= t
.getMessage();
880 MessagingUtils
.errorDialog(title
,
883 TaxeditorStorePlugin
.PLUGIN_ID
,
891 private void stopManagedServer() {
893 CdmStore
.getManagedServer().stop();
894 } catch (Exception e
) {
895 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_STOPPING_SERVER
,
897 String
.format(Messages
.RemotingLoginDialog_COULD_NOT_STOP_SERVER
, CdmStore
.getManagedServer().getPort()),
898 TaxeditorStorePlugin
.PLUGIN_ID
,
902 CdmStore
.setManagedServer(null);
903 updateManagedServerControls();
906 private int getManagedServerPort() {
907 return CdmStore
.getManagedServer() == null ? CdmServerInfo
.NULL_PORT
: CdmStore
.getManagedServer().getPort();
910 private void checkSelectedCdmInstance() {
912 if (selectedServerInfo
.isLocalhostMgd()){
913 checkManagedSelectedInstance();
914 }else if (txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
)) {
915 boolean available
= false;
916 String instanceStatus
= STATUS_NOT_AVAILABLE
;
917 String message
= null;
919 if(selectedServerInfo
.pingInstance(selectedCdmInstance
, getPort())) {
920 instanceStatus
= STATUS_AVAILABLE
;
923 instanceStatus
= STATUS_NOT_AVAILABLE
;
928 txtServerSchemaVersion
.setText(selectedServerInfo
.getCdmRemoteSource(selectedCdmInstance
, getPort()).getDbSchemaVersion());
930 int compareDbSchemaVersion
= selectedServerInfo
.compareDbSchemaVersion(selectedCdmInstance
, getPort());
932 int compareCdmlibServicesVersion
= 0;
933 boolean disableServicesApiTimestampCheck
=
934 PreferencesUtil
.getBooleanValue((IPreferenceKeys
.DISABLE_SERVICES_API_TIMESTAMP_CHECK
));
935 if(!disableServicesApiTimestampCheck
) {
936 compareCdmlibServicesVersion
= selectedServerInfo
.compareCdmlibServicesVersion();
939 if(compareDbSchemaVersion
> 0 || compareCdmlibServicesVersion
> 0) {
940 instanceStatus
= STATUS_NOT_COMPATIBLE
;
942 message
= MESG_COMPATIBLE_EDITOR_OLD
;
943 } else if(compareDbSchemaVersion
< 0 || compareCdmlibServicesVersion
< 0) {
944 instanceStatus
= STATUS_NOT_COMPATIBLE
;
946 message
= MESG_COMPATIBLE_SERVER_OLD
;
948 instanceStatus
= STATUS_AVAILABLE
;
950 message
= ""; //$NON-NLS-1$
953 } catch (Exception e
) {
954 txtCdmInstanceStatus
.setToolTipText(e
.getMessage());
956 lblDefaultLogin
.setVisible(false);
957 btnConnect
.setEnabled(available
);
958 txtCdmInstanceStatus
.setText(instanceStatus
);
959 if(!StringUtils
.isBlank(message
)) {
966 private void checkManagedSelectedInstance() {
967 boolean available
= false;
968 String instanceStatus
= STATUS_NOT_AVAILABLE
;
969 String message
= null;
970 String connect
= LABEL_CONNECT
;
971 int color
= SWT
.COLOR_BLACK
;
972 String schemaVersion
= CdmMetaData
.getDbSchemaVersion();
974 if (!schemaExists(selectedCdmInstance
)){
975 message
= MESG_SCHEMA_MISSING
;
976 connect
= LABEL_CREATE_SCHEMA
;
977 color
= SWT
.COLOR_RED
;
978 schemaVersion
= MESG_NO_SCHEMA
;
982 schemaVersion
= managedSchemaVersion(selectedCdmInstance
);
983 compare
= compareSchemaVersion(selectedCdmInstance
);
985 instanceStatus
= STATUS_NOT_COMPATIBLE
;
986 message
= MESG_COMPATIBLE_EDITOR_OLD
;
988 }else if (compare
< 0){
989 instanceStatus
= STATUS_NOT_COMPATIBLE
;
990 message
= MESG_UPDATE_SCHEMA_VERSION
;
992 connect
= LABEL_UPDATE_SCHEMA_VERSION
;
993 color
= SWT
.COLOR_RED
;
996 instanceStatus
= STATUS_AVAILABLE
;
998 } catch (CdmSourceException e
) {
1003 setManagedValues(available
, instanceStatus
, connect
, color
, schemaVersion
);
1004 setMessage(message
);
1007 private void setManagedValues(boolean available
, String instanceStatus
, String connect
, int color
,
1008 String schemaVersion
) {
1009 Display
.getDefault().syncExec(()->{
1010 btnConnect
.setEnabled(available
);
1011 btnConnect
.setText(connect
);
1012 btnConnect
.setBackground(Display
.getCurrent().getSystemColor(color
));
1013 btnConnect
.requestLayout();
1014 txtCdmInstanceStatus
.setText(instanceStatus
);
1015 txtServerSchemaVersion
.setText(schemaVersion
);
1016 lblDefaultLogin
.setVisible(true);
1020 private void connect() {
1021 checkSelectedCdmInstance();
1023 if(!txtCdmInstanceStatus
.getText().equals(STATUS_AVAILABLE
)) {
1027 ICdmRemoteSource source
= selectedServerInfo
.getCdmRemoteSource(selectedCdmInstance
, getPort());
1029 if(!validateLogin(source
)) {
1034 CdmStore
.connect(source
, this);
1035 } catch (Exception e
) {
1036 // Do not expect anything to go wrong at this point, so we throw a runtime exception
1038 throw new RuntimeException(e
);
1042 public boolean isRememberMe() {
1043 return btnRememberMe
.getSelection();
1046 private void persistPrefLastServerInstance() {
1047 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
1048 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
1050 lastServerInstancePrefs
.put(LAST_SERVER_KEY
, selectedServerInfo
.getName());
1051 lastServerInstancePrefs
.put(LAST_INSTANCE_KEY
, selectedCdmInstance
.getName());
1053 flushPreferences(lastServerInstancePrefs
);
1056 private void persistPrefCredentials() {
1057 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
1058 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
1059 credentialsPrefs
.put(getUsernamePrefKey(), txtLogin
.getText());
1060 credentialsPrefs
.put(getPasswordPrefKey(), txtPassword
.getText());
1061 flushPreferences(credentialsPrefs
);
1064 private void removePrefCredentials() {
1065 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
1066 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
1067 credentialsPrefs
.put(getUsernamePrefKey(), txtLogin
.getText());
1068 credentialsPrefs
.put(getPasswordPrefKey(), txtPassword
.getText());
1069 removePreferences(credentialsPrefs
);
1072 private void removePreferences(Preferences prefs
) {
1075 } catch (BackingStoreException bse
) {
1076 setMessage(bse
.getMessage());
1080 private void flushPreferences(Preferences prefs
) {
1083 } catch (BackingStoreException bse
) {
1084 setMessage(bse
.getMessage());
1088 private void readPrefCredentials() {
1089 String username
, password
;
1090 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
1091 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
1092 username
= credentialsPrefs
.get(getUsernamePrefKey(), ""); //$NON-NLS-1$
1093 txtLogin
.setText(username
);
1094 password
= credentialsPrefs
.get(getPasswordPrefKey(),""); //$NON-NLS-1$
1095 txtPassword
.setText(password
);
1096 if(username
.isEmpty() || password
.isEmpty()) {
1097 autoConnect
= false;
1101 private void readPrefLastServerInstance() {
1102 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
1103 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
1105 serverName
= lastServerInstancePrefs
.get(LAST_SERVER_KEY
, null);
1106 instanceName
= lastServerInstancePrefs
.get(LAST_INSTANCE_KEY
, null);
1109 private void emptyCredentials() {
1110 txtLogin
.setText(""); //$NON-NLS-1$
1111 txtPassword
.setText(""); //$NON-NLS-1$
1114 private String
getUsernamePrefKey() {
1115 return selectedServerInfo
.toString(selectedCdmInstance
.getName(), isDevRemoteSource?
getPort():-1) + USERNAME_SUFFIX
;
1118 private String
getPasswordPrefKey() {
1119 return selectedServerInfo
.toString(selectedCdmInstance
.getName(), isDevRemoteSource?
getPort():-1) + PASSWORD_SUFFIX
;
1122 private boolean validateLogin(ICdmRemoteSource remoteSource
) {
1123 if(getUsername() == null || getUsername().isEmpty()) {
1124 setMessage(Messages
.RemotingLoginDialog_LOGIN_CANNOT_BE_EMPTY
);
1127 if(getPassword() == null || getPassword().isEmpty()) {
1128 setMessage(Messages
.RemotingLoginDialog_PASSWORD_CANNOT_BE_EMPTY
);
1133 IUserService userService
= CdmApplicationRemoteConfiguration
.getUserService(remoteSource
);
1134 UsernamePasswordAuthenticationToken token
= new UsernamePasswordAuthenticationToken(getUsername(), getPassword());
1135 CdmApplicationRemoteConfiguration
.getAuthenticationManager(userService
).authenticate(token
);
1136 } catch(BadCredentialsException e
){
1137 setMessage(LoginManager
.INCORRECT_CREDENTIALS_MESSAGE
);
1139 } catch(LockedException e
){
1140 setMessage(LoginManager
.ACCOUNT_LOCKED_MESSAGE
);
1142 } catch(IllegalArgumentException e
){
1143 setMessage(LoginManager
.INCORRECT_CREDENTIALS_MESSAGE
);
1149 public String
getUsername() {
1150 return txtLogin
.getText();
1153 public String
getPassword() {
1154 return txtPassword
.getText();
1157 public void setMessage(String message
) {
1158 if(CdmUtils
.isNotBlank(message
)) {
1159 // if(message.length() > 50) {
1160 // styledTxtMessage.setToolTipText(message);
1161 // message = message.substring(0,50) + "..."; //$NON-NLS-1$
1163 styledTxtMessage
.setText(message
);
1164 styledTxtMessage
.setVisible(true);
1165 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= false;
1166 // shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
1167 shlConnect
.pack(true);
1169 if (!styledTxtMessage
.isDisposed()){
1170 styledTxtMessage
.setText(""); //$NON-NLS-1$
1171 styledTxtMessage
.setVisible(false);
1172 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= true;
1174 if(!shlConnect
.isDisposed()){
1175 shlConnect
.pack(true);
1178 if (!remotingComposite
.isDisposed()){
1179 remotingComposite
.layout();
1183 // private int getHeightWithoutMessage() {
1184 // if(xpndblcmpstAdvanced.isExpanded()) {
1185 // return MIN_EXP_HEIGHT;
1187 // return MIN_HEIGHT;
1191 public void hide(boolean isHidden
) {
1192 if (!shlConnect
.isDisposed()){
1193 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
1194 shlConnect
.setVisible(!isHidden
);
1199 public void dispose() {
1200 if (!shlConnect
.isDisposed()){
1201 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
1202 shlConnect
.dispose();
1207 public void onComplete() {
1208 Display
.getDefault().asyncExec(new Runnable() {
1211 if(selectedCdmInstance
!=null){
1212 if(isRememberMe()) {
1213 persistPrefCredentials();
1215 removePrefCredentials();
1217 persistPrefLastServerInstance();
1224 private String
generateLastModifiedTooltip(String cdmlibLastModified
) {
1225 if(StringUtils
.isBlank(cdmlibLastModified
)) {
1226 return ""; //$NON-NLS-1$
1228 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy.MM.dd.HH.mm.z"); //$NON-NLS-1$
1229 Date cdmlibLastModifiedDate
;
1230 String cdmlibLastModifiedTimestamp
= ""; //$NON-NLS-1$
1232 cdmlibLastModifiedDate
= new Date(Long
.valueOf(cdmlibLastModified
));
1233 cdmlibLastModifiedTimestamp
= sdf
.format(cdmlibLastModifiedDate
);
1235 return cdmlibLastModifiedTimestamp
;
1238 private void setEditorInfo() {
1239 txtEditorCdmVersion
.setText(CdmMetaData
.getDbSchemaVersion());
1240 setCdmlibVersion(txtEditorCdmlibVersion
);
1241 String editorVersionTimestamp
= generateLastModifiedTooltip(CdmApplicationState
.getCdmlibLastModified());
1242 txtEditorCdmlibVersion
.setText(CdmApplicationState
.getCdmlibVersion() + ":" + editorVersionTimestamp
); //$NON-NLS-1$
1245 private void setCdmlibVersion(Text txt
) {
1246 String editorVersionTimestamp
= generateLastModifiedTooltip(CdmApplicationState
.getCdmlibLastModified());
1247 txt
.setText(CdmApplicationState
.getCdmlibVersion() + ":" + editorVersionTimestamp
); //$NON-NLS-1$
1250 private void clearOnServerChange() {
1251 setMessage(""); //$NON-NLS-1$
1252 txtServerSchemaVersion
.setText(""); //$NON-NLS-1$
1253 txtServerCdmlibVersion
.setText(""); //$NON-NLS-1$
1254 txtServerCdmlibVersion
.setToolTipText(""); //$NON-NLS-1$
1255 txtServerSchemaVersion
.setText(""); //$NON-NLS-1$
1256 comboCdmInstance
.removeAll();
1257 txtCdmInstanceStatus
.setText(""); //$NON-NLS-1$
1258 txtPort
.setEditable(false);
1259 txtPort
.setEnabled(false);
1262 private void clearOnInstanceChange() {
1263 setMessage(""); //$NON-NLS-1$
1264 txtServerSchemaVersion
.setText(""); //$NON-NLS-1$