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
;
11 import java
.io
.IOException
;
12 import java
.net
.SocketTimeoutException
;
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
.lang3
.StringUtils
;
20 import org
.apache
.logging
.log4j
.LogManager
;
21 import org
.apache
.logging
.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
.SelectionAdapter
;
35 import org
.eclipse
.swt
.events
.SelectionEvent
;
36 import org
.eclipse
.swt
.graphics
.Point
;
37 import org
.eclipse
.swt
.graphics
.Rectangle
;
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
.wb
.swt
.SWTResourceManager
;
53 import org
.osgi
.service
.prefs
.BackingStoreException
;
54 import org
.osgi
.service
.prefs
.Preferences
;
55 import org
.springframework
.security
.authentication
.BadCredentialsException
;
56 import org
.springframework
.security
.authentication
.LockedException
;
57 import org
.springframework
.security
.authentication
.UsernamePasswordAuthenticationToken
;
59 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationRemoteConfiguration
;
60 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
61 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
62 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
63 import eu
.etaxonomy
.cdm
.config
.CdmSourceException
;
64 import eu
.etaxonomy
.cdm
.config
.ICdmSource
;
65 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
;
66 import eu
.etaxonomy
.cdm
.persistence
.permission
.Role
;
67 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
68 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
69 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
70 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
71 import eu
.etaxonomy
.taxeditor
.remoting
.server
.CdmServerException
;
72 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmRemoteLocalhostSource
;
73 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
;
74 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
.CdmInstanceInfo
;
75 import eu
.etaxonomy
.taxeditor
.remoting
.source
.ICdmRemoteSource
;
76 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
77 import eu
.etaxonomy
.taxeditor
.store
.LoginManager
;
78 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
79 import eu
.etaxonomy
.taxeditor
.workbench
.datasource
.ICdmServerError
;
85 public class RemotingLoginDialog
extends Dialog
implements ICdmServerError
{
87 private Logger logger
= LogManager
.getLogger(getClass());
89 public static final String DEFAULT_PASS
= "00000"; //$NON-NLS-1$
90 public static final String DEFAULT_USER
= "admin"; //$NON-NLS-1$
92 public final static String STATUS_AVAILABLE
= Messages
.RemotingLoginDialog_STATUS_AVAILABLE
;
93 public final static String STATUS_NOT_AVAILABLE
= Messages
.RemotingLoginDialog_STATUS_NOT_AVAILABLE
;
94 public final static String STATUS_STARTED
= Messages
.RemotingLoginDialog_STATUS_STARTED
;
95 public final static String STATUS_NOT_STARTED
= Messages
.RemotingLoginDialog_STATUS_NOT_STARTED
;
96 public final static String STATUS_RETRIEVING
= Messages
.RemotingLoginDialog_STATUS_RETRIEVING
;
97 public final static String STATUS_CHECKING_AVAILABILITY
= Messages
.RemotingLoginDialog_STATUS_CHECKING
;
98 public final static String STATUS_NO_INSTANCES
= Messages
.RemotingLoginDialog_STATUS_NO_INSTANCES_FOUND
;
99 public final static String STATUS_NOT_COMPATIBLE
= Messages
.RemotingLoginDialog_STATUS_NOT_COMPATIBLE
;
101 public final static String MESG_COMPATIBLE_EDITOR_OLD
= Messages
.RemotingLoginDialog_UPDATE_EDITOR
;
102 public final static String MESG_COMPATIBLE_SERVER_OLD
= Messages
.RemotingLoginDialog_CHOOSE_COMPATIBLE_CDM_SERVER
;
103 public final static String MESG_SCHEMA_MISSING
= Messages
.RemotingLoginDialog_SCHEMA_MISSING
;
104 public final static String MESG_NO_SCHEMA
= Messages
.RemotingLoginDialog_NO_SCHEMA
;
106 public final static String LABEL_CONNECT
= Messages
.RemotingLoginDialog_LABEL_CONNECT
;
107 public final static String LABEL_CREATE_SCHEMA
= Messages
.RemotingLoginDialog_LABEL_CREATE_SCHEMA
;
108 public final static String LABEL_UPDATE_SCHEMA_VERSION
= Messages
.RemotingLoginDialog_LABEL_UPDATE_SCHEMA_VERSION
;
109 public final static String MESG_UPDATE_SCHEMA_VERSION
= Messages
.RemotingLoginDialog_MSG_UPDATE_SCHEMA_VERSION
;
110 public final static String LABEL_LOGIN
= Messages
.RemotingLoginDialog_LABEL_LOGIN
;
111 public final static String LABEL_CDM_SERVER
= Messages
.RemotingLoginDialog_LABEL_CDM_SERVER
;
112 public final static String LABEL_REFRESH
= Messages
.RemotingLoginDialog_LABEL_REFRESH
;
113 public final static String LABEL_CDM_INSTANCE
= Messages
.RemotingLoginDialog_LABEL_CDM_INSTANCE
;
114 public final static String LABEL_LOGIN_COLON
= Messages
.RemotingLoginDialog_LABEL_LOGIN_COLON
;
115 public final static String LABEL_PASSWORD
= Messages
.RemotingLoginDialog_LABEL_PASSWORD
;
116 public final static String LABEL_EDITOR_CDM_VERSION
= Messages
.RemotingLoginDialog_LABEL_EDITOR_CDM_VERSION
;
117 public final static String LABEL_SERVER_CDM_VERSION
= Messages
.RemotingLoginDialog_LABEL_SERVER_CDM_VERSION
;
118 public final static String LABEL_EDITOR_CDMLIB_VERSION
= Messages
.RemotingLoginDialog_LABEL_EDITOR_CDMLIB_VERSION
;
119 public final static String LABEL_SERVER_CDMLIB_VERSION
= Messages
.RemotingLoginDialog_LABEL_SERVER_CDMLIB_VERSION
;
120 public final static String LABEL_STOP_MANAGED_SERVER
= Messages
.RemotingLoginDialog_LABEL_STOP_MANAGED_SERVER
;
121 public final static String LABEL_PORT
= Messages
.RemotingLoginDialog_LABEL_PORT
;
122 public final static String LABEL_ADVANCED
= Messages
.RemotingLoginDialog_LABEL_ADVANCED
;
123 public final static String LABEL_DEFAULT_LOGIN
= Messages
.RemotingLoginDialog_DEFAULT_LOGIN
;
124 public final static String LABEL_REMEMBER_ME
= Messages
.RemotingLoginDialog_LABEL_REMEMBER_ME
;
126 public final static String MESG_LOGIN_CANNOT_BE_EMPTY
= Messages
.RemotingLoginDialog_LOGIN_CANNOT_BE_EMPTY
;
127 public final static String STATUS_GENERATING_CONFIG_FILE
= Messages
.RemotingLoginDialog_GENERATING_CONFIG_FILE
;
128 public final static String STATUS_STARTING_MGD_SERVER
= Messages
.RemotingLoginDialog_STARTING_MGD_SERVER
;
130 public final static String ERR_GENERATING_CONFIG_FILE
= Messages
.RemotingLoginDialog_ERROR_GENERATING_CONFIG_FILE
;
131 public final static String ERR_STARTING_SERVER
= Messages
.RemotingLoginDialog_ERROR_STARTING_SERVER
;
132 public final static String ERR_SERVER_LAUNCH
= Messages
.RemotingLoginDialog_SERVER_LAUNCH_ERROR
;
133 public final static String ERR_STOPPING_SERVER
= Messages
.RemotingLoginDialog_ERROR_STOPPING_SERVER
;
134 public final static String ERR_COULD_NOT_STOP_SERVER
= Messages
.RemotingLoginDialog_COULD_NOT_STOP_SERVER
;
135 public final static String RETRIEVE_SERVER_INSTANCES
= Messages
.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES
;
136 public final static String TASK_LAUNCHING_SERVER
= Messages
.RemotingLoginDialog_TASK_LAUNCHING_SERVER
;
138 public static final int BTN_COLOR_ATTENTION
= SWT
.COLOR_RED
;
140 public final static String STORE_PREFERENCES_NODE
= "eu.etaxonomy.taxeditor.store"; //$NON-NLS-1$
142 public final static String LOGIN_NODE
= "login"; //$NON-NLS-1$
143 public final static String USERNAME_SUFFIX
= "_username"; //$NON-NLS-1$
144 public final static String PASSWORD_SUFFIX
= "_password"; //$NON-NLS-1$
146 public final static String LAST_SERVER_INSTANCE_NODE
= "lastServerInstance"; //$NON-NLS-1$
147 public final static String LAST_SERVER_KEY
= "lastServerKey"; //$NON-NLS-1$
148 public final static String LAST_INSTANCE_KEY
= "lastInstanceKey"; //$NON-NLS-1$
150 protected Shell shlConnect
;
151 protected Text txtCdmServerStatus
;
152 protected Text txtCdmInstanceStatus
;
154 protected Combo comboCdmServer
;
155 protected boolean allowServerChange
= true;
156 protected Combo comboCdmInstance
;
157 protected boolean allowInstanceChange
= true;
158 public Button btnConnect
;
160 protected Composite remotingComposite
;
161 protected Button btnCdmServerRefresh
;
162 protected Button btnCdmInstanceRefresh
;
163 protected Button btnStopServer
;
164 protected Composite loginComposite
;
165 protected Label lblLogin
;
166 protected Text txtLogin
;
167 protected Label lblPassword
;
168 protected Text txtPassword
;
169 protected Button btnRememberMe
;
170 protected Label lblDefaultLogin
;
171 protected Composite compAdvanced
;
172 protected Label lblPort
;
173 protected Text txtPort
;
174 protected Label lblServerCdmlibVersion
;
175 protected Text txtServerCdmlibVersion
;
176 protected ExpandableComposite expandableCompositeAdvanced
;
177 protected StyledText styledTxtMessage
;
179 protected Label lblEditorCdmlibVersion
;
180 protected Text txtEditorCdmlibVersion
;
181 protected Label lblServerSchemaVersion
;
182 protected Text txtServerSchemaVersion
;
183 protected Label lblEditorCdmVersion
;
184 protected Text txtEditorCdmVersion
;
186 protected final int MESSAGE_HEIGHT
= 50;
187 protected final int COMBO_MIN_WIDTH
=200;
188 protected final int CONTROLS_MIN_HEIGHT
= 23; //does not seem to work yet
189 // private final int MIN_EXP_HEIGHT = 380;
191 protected boolean autoConnect
= false;
192 protected boolean loadLoginPrefs
= true;
193 protected boolean isDevRemoteSource
= false;
194 protected boolean isLocal
= false;
196 protected Job serverJob
;
197 protected Object result
;
199 protected final Map
<String
, CdmServerInfo
> serverInfoMap
= new HashMap
<>();
201 protected String serverName
;
202 protected String instanceName
;
203 protected CdmServerInfo selectedServerInfo
;
204 protected CdmInstanceInfo selectedCdmInstance
;
205 protected String login
;
206 protected String password
;
211 public RemotingLoginDialog(Shell parent
, int style
) {
212 super(parent
, style
);
213 setText(LABEL_LOGIN
);
216 public Object
open(ICdmRemoteSource source
, boolean loadLoginPrefs
, boolean autoConnect
) {
217 this.loadLoginPrefs
= loadLoginPrefs
;
218 this.setServerName(source
.getName());
219 if (source
instanceof CdmRemoteLocalhostSource
){
220 this.setInstanceName(((CdmRemoteLocalhostSource
)source
).getDatasourceName());
222 String contextPath
= source
.getContext();
223 this.setInstanceName(contextPath
== null?
"" : contextPath
.substring(contextPath
.lastIndexOf("/") + 1)); //$NON-NLS-1$
225 //disable datasource selection if datasource is given, see #10463
227 allowServerChange
= false;
228 allowInstanceChange
= false;
230 return open(getServerName(), getInstanceName(), loadLoginPrefs
, autoConnect
);
233 public Object
open(String serverName
, String instanceName
, boolean loadLoginPrefs
, boolean autoConnect
) {
234 this.setServerName(serverName
);
235 this.setInstanceName(instanceName
);
236 this.loadLoginPrefs
= loadLoginPrefs
;
237 this.setAutoConnect(autoConnect
);
243 * @return the dialog result
245 public Object
open() {
248 if(getServerName() == null && getInstanceName() == null) {
249 readPrefLastServerInstance();
251 expandableCompositeAdvanced
.setExpanded(false);
254 populateCdmServerCombo();
255 shlConnect
.pack(true);
260 Display display
= getParent().getDisplay();
261 while (!shlConnect
.isDisposed()) {
262 if (!display
.isDisposed()){
263 if (!display
.readAndDispatch()) {
272 * Create contents of the dialog.
274 protected void createContents() {
275 shlConnect
= new Shell(getParent(), SWT
.DIALOG_TRIM
| SWT
.APPLICATION_MODAL
| SWT
.RESIZE
| SWT
.CENTER
);
276 shlConnect
.setText(LABEL_CONNECT
);
277 shlConnect
.setLayout(new FillLayout(SWT
.HORIZONTAL
));
279 remotingComposite
= new Composite(shlConnect
, SWT
.NONE
);
280 remotingComposite
.setLayout(new GridLayout(1, false));
283 Composite cdmServerComposite
= new Composite(remotingComposite
, SWT
.NONE
);
284 GridData gd_cdmServerComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
285 cdmServerComposite
.setLayoutData(gd_cdmServerComposite
);
286 cdmServerComposite
.setLayout(new GridLayout(4, false));
288 Label lblCdmServer
= new Label(cdmServerComposite
, SWT
.NONE
);
289 lblCdmServer
.setText(LABEL_CDM_SERVER
);
290 lblCdmServer
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
292 comboCdmServer
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
293 comboCdmServer
.addSelectionListener(new SelectionAdapter() {
295 public void widgetSelected(SelectionEvent e
) {
296 onRefreshCdmServer();
300 GridData gd_comboCdmServer
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, true, 1, 1);
302 comboCdmServer
.setLayoutData(gd_comboCdmServer
);
303 comboCdmServer
.select(0);
305 txtCdmServerStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
306 txtCdmServerStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
307 txtCdmServerStatus
.setEditable(false);
308 GridData gd_txtCdmServerStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, true, 1, 1);
309 gd_txtCdmServerStatus
.minimumHeight
= CONTROLS_MIN_HEIGHT
;
310 txtCdmServerStatus
.setLayoutData(gd_txtCdmServerStatus
);
312 btnCdmServerRefresh
= new Button(cdmServerComposite
, SWT
.NONE
);
313 btnCdmServerRefresh
.addSelectionListener(new SelectionAdapter() {
315 public void widgetSelected(SelectionEvent e
) {
316 onRefreshCdmServer();
319 GridData gd_btnCdmServerRefresh
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, true, 1, 1);
320 gd_btnCdmServerRefresh
.minimumHeight
= CONTROLS_MIN_HEIGHT
;
321 btnCdmServerRefresh
.setLayoutData(gd_btnCdmServerRefresh
);
322 btnCdmServerRefresh
.setText(LABEL_REFRESH
);
325 Label lblCdmInstance
= new Label(cdmServerComposite
, SWT
.NONE
);
326 GridData gd_lblCdmInstance
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, true, 1, 1);
327 //gd_lblCdmInstance.heightHint = 30;
328 lblCdmInstance
.setLayoutData(gd_lblCdmInstance
);
329 lblCdmInstance
.setText(LABEL_CDM_INSTANCE
);
331 comboCdmInstance
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
332 comboCdmInstance
.addSelectionListener(new SelectionAdapter() {
334 public void widgetSelected(SelectionEvent e
) {
335 onRefreshCdmInstance();
339 GridData gd_comboCdmInstance
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 1);
340 gd_comboCdmInstance
.minimumWidth
= COMBO_MIN_WIDTH
;
342 comboCdmInstance
.setLayoutData(gd_comboCdmInstance
);
343 comboCdmInstance
.select(0);
345 txtCdmInstanceStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
346 txtCdmInstanceStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
347 txtCdmInstanceStatus
.setEditable(false);
348 GridData gd_txtCdmInstanceStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, true, 1, 1);
349 gd_txtCdmInstanceStatus
.minimumHeight
= CONTROLS_MIN_HEIGHT
;
350 txtCdmInstanceStatus
.setLayoutData(gd_txtCdmInstanceStatus
);
352 btnCdmInstanceRefresh
= new Button(cdmServerComposite
, SWT
.FLAT
);
353 btnCdmInstanceRefresh
.addSelectionListener(new SelectionAdapter() {
355 public void widgetSelected(SelectionEvent e
) {
356 onRefreshCdmInstance();
359 GridData gd_btnCdmInstanceRefresh
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 1);
360 gd_btnCdmInstanceRefresh
.minimumHeight
= CONTROLS_MIN_HEIGHT
;
361 btnCdmInstanceRefresh
.setLayoutData(gd_btnCdmInstanceRefresh
);
362 btnCdmInstanceRefresh
.setText(Messages
.RemotingLoginDialog_LABEL_REFRESH
);
365 loginComposite
= new Composite(remotingComposite
, SWT
.NONE
);
366 GridData gd_loginComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
367 loginComposite
.setLayoutData(gd_loginComposite
);
368 GridLayout gl_loginComposite
= new GridLayout(6, false);
369 gl_loginComposite
.marginTop
= 5;
370 loginComposite
.setLayout(gl_loginComposite
);
372 lblLogin
= new Label(loginComposite
, SWT
.CENTER
);
373 GridData gd_lblLogin
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
374 lblLogin
.setLayoutData(gd_lblLogin
);
375 lblLogin
.setText(Messages
.RemotingLoginDialog_LABEL_LOGIN_COLON
);
377 txtLogin
= new Text(loginComposite
, SWT
.BORDER
);
378 GridData gd_txtLogin
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
379 gd_txtLogin
.minimumWidth
= 80;
380 txtLogin
.setLayoutData(gd_txtLogin
);
382 lblPassword
= new Label(loginComposite
, SWT
.CENTER
);
383 lblPassword
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
384 lblPassword
.setText(Messages
.RemotingLoginDialog_LABEL_PASSWORD
);
386 txtPassword
= new Text(loginComposite
, SWT
.BORDER
| SWT
.PASSWORD
);
387 GridData gd_txtPassword
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
388 gd_txtPassword
.minimumWidth
= 80;
389 txtPassword
.setLayoutData(gd_txtPassword
);
390 @SuppressWarnings("unused")
391 Label nope
= new Label(loginComposite
, SWT
.NONE
);
392 txtPassword
.addKeyListener(new KeyAdapter() {
394 public void keyPressed(KeyEvent e
) {
395 if(e
.character
==SWT
.CR
){
396 if(btnConnect
.getText().equals(LABEL_CONNECT
)){
397 onConnectButtonPressed();
403 btnConnect
= new Button(loginComposite
, SWT
.FLAT
);
404 btnConnect
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1));
405 btnConnect
.addSelectionListener(new SelectionAdapter() {
407 public void widgetSelected(SelectionEvent e
) {
408 onConnectButtonPressed();
411 btnConnect
.setText(LABEL_CONNECT
);
413 //rememberMe + default values
414 btnRememberMe
= new Button(loginComposite
, SWT
.CHECK
);
415 btnRememberMe
.setSelection(true);
416 GridData gd_btnRememberMe
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 2, 1);
417 btnRememberMe
.setLayoutData(gd_btnRememberMe
);
418 btnRememberMe
.setText(Messages
.RemotingLoginDialog_LABEL_REMEMBER_ME
);
420 lblDefaultLogin
= new Label(loginComposite
, SWT
.NONE
);
421 GridDataFactory
.fillDefaults().span(4, 1).align(SWT
.TRAIL
, SWT
.CENTER
).applyTo(lblDefaultLogin
);
422 lblDefaultLogin
.setText(String
.format(Messages
.RemotingLoginDialog_DEFAULT_LOGIN
, DEFAULT_USER
, DEFAULT_PASS
));
423 lblDefaultLogin
.setVisible(false);
425 styledTxtMessage
= new StyledText(remotingComposite
, SWT
.NONE
);
426 styledTxtMessage
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
427 styledTxtMessage
.setForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
428 styledTxtMessage
.setSelectionBackground(SWTResourceManager
.getColor(SWT
.COLOR_LIST_SELECTION_TEXT
));
429 styledTxtMessage
.setSelectionForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
430 styledTxtMessage
.setDoubleClickEnabled(false);
431 styledTxtMessage
.setEditable(false);
432 styledTxtMessage
.setWordWrap(true);
434 GridData gd_styledTxtMessage
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
435 gd_styledTxtMessage
.exclude
= true;
436 gd_styledTxtMessage
.minimumHeight
= MESSAGE_HEIGHT
;
438 styledTxtMessage
.setLayoutData(gd_styledTxtMessage
);
441 expandableCompositeAdvanced
= new ExpandableComposite(remotingComposite
, SWT
.NONE
, ExpandableComposite
.TWISTIE
);
442 GridData gd_xpndblcmpstAdvanced
= new GridData(SWT
.FILL
, SWT
.FILL
, false, true, 1, 1);
443 expandableCompositeAdvanced
.setLayoutData(gd_xpndblcmpstAdvanced
);
444 expandableCompositeAdvanced
.addExpansionListener(new IExpansionListener() {
446 public void expansionStateChanged(ExpansionEvent e
) {
447 shlConnect
.pack(true);
450 public void expansionStateChanging(ExpansionEvent e
) {
453 expandableCompositeAdvanced
.setText(Messages
.RemotingLoginDialog_LABEL_ADVANCED
);
454 expandableCompositeAdvanced
.setExpanded(true);
456 compAdvanced
= new Composite(expandableCompositeAdvanced
, SWT
.NONE
);
457 expandableCompositeAdvanced
.setClient(compAdvanced
);
458 compAdvanced
.setLayout(new GridLayout(4, false));
460 lblPort
= new Label(compAdvanced
, SWT
.CENTER
);
461 lblPort
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
462 lblPort
.setText(Messages
.RemotingLoginDialog_LABEL_PORT
);
464 txtPort
= new Text(compAdvanced
, SWT
.BORDER
);
465 GridData gd_txtPort
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1);
466 gd_txtPort
.minimumWidth
= 50;
467 txtPort
.setLayoutData(gd_txtPort
);
469 lblServerCdmlibVersion
= new Label(compAdvanced
, SWT
.CENTER
);
470 lblServerCdmlibVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
471 lblServerCdmlibVersion
.setText(Messages
.RemotingLoginDialog_LABEL_SERVER_CDMLIB_VERSION
);
473 txtServerCdmlibVersion
= new Text(compAdvanced
, SWT
.BORDER
);
474 txtServerCdmlibVersion
.setEditable(false);
475 txtServerCdmlibVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
477 lblEditorCdmlibVersion
= new Label(compAdvanced
, SWT
.CENTER
);
478 lblEditorCdmlibVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
479 lblEditorCdmlibVersion
.setText(Messages
.RemotingLoginDialog_LABEL_EDITOR_CDMLIB_VERSION
);
481 txtEditorCdmlibVersion
= new Text(compAdvanced
, SWT
.BORDER
);
482 txtEditorCdmlibVersion
.setEditable(false);
483 txtEditorCdmlibVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
486 lblServerSchemaVersion
= new Label(compAdvanced
, SWT
.CENTER
);
487 lblServerSchemaVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
488 lblServerSchemaVersion
.setText(Messages
.RemotingLoginDialog_LABEL_SERVER_CDM_VERSION
);
490 txtServerSchemaVersion
= new Text(compAdvanced
, SWT
.BORDER
);
491 txtServerSchemaVersion
.setEditable(false);
492 txtServerSchemaVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
495 lblEditorCdmVersion
= new Label(compAdvanced
, SWT
.CENTER
);
496 lblEditorCdmVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
497 lblEditorCdmVersion
.setText(Messages
.RemotingLoginDialog_LABEL_EDITOR_CDM_VERSION
);
499 txtEditorCdmVersion
= new Text(compAdvanced
, SWT
.BORDER
);
500 txtEditorCdmVersion
.setEditable(false);
501 txtEditorCdmVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
504 public void setCenterPoint() {
505 Rectangle parentSize
= getParent().getBounds();
506 Rectangle shellSize
= shlConnect
.getBounds();
507 int locationX
= (parentSize
.width
- shellSize
.width
)/2+parentSize
.x
;
508 int locationY
= (parentSize
.height
- shellSize
.height
)/2+parentSize
.y
;
509 shlConnect
.setLocation(new Point(locationX
, locationY
));
513 protected void addEmptyCells(int cnt
) {
514 for (int i
= 0; i
< cnt
; i
++) {
515 new Label(compAdvanced
, SWT
.NONE
);
519 protected void onConnectButtonPressed() {
521 if (CdmStore
.isActive() && CdmStore
.currentAuthentiationHasOneOfRoles(Role
.ROLE_REMOTING
)){
522 PreferencesUtil
.setNomenclaturalCodePreferences();
527 protected void populateCdmServerCombo() {
528 Job job
= new Job(RETRIEVE_SERVER_INSTANCES
) {
530 protected IStatus
run(IProgressMonitor monitor
) {
531 Display
.getDefault().syncExec(new Runnable() {
536 int serverIndex
= -1;
537 if(getServerName() != null) {
538 serverIndex
= comboCdmServer
.indexOf(getServerName());
540 if(serverIndex
== -1) {
541 comboCdmServer
.select(0);
542 setAutoConnect(false);
544 comboCdmServer
.select(serverIndex
);
546 ICdmSource devRemoteSource
= CdmServerInfo
.getDevServerRemoteSource();
547 if(devRemoteSource
!= null) {
548 setDevRemoteSource(true);
549 String username
= System
.getProperty("cdm.server.dev.username"); //$NON-NLS-1$
550 String password
= System
.getProperty("cdm.server.dev.password"); //$NON-NLS-1$
551 if(username
!= null && !username
.isEmpty() && password
!= null && !password
.isEmpty()) {
552 txtLogin
.setText(username
);
553 txtPassword
.setText(password
);
554 CdmStore
.connect(devRemoteSource
, RemotingLoginDialog
.this);
557 onRefreshCdmServer();
563 return Status
.OK_STATUS
;
568 public void putAllServers() {
569 for(CdmServerInfo csii
: CdmServerInfo
.getCdmServers(isLocal
)) {
571 comboCdmServer
.add(csii
.getName());
575 public void putServerInfo(CdmServerInfo csii
) {
576 getServerInfoMap().put(csii
.getName(), csii
);
578 public void onRefreshCdmServer() {
580 txtCdmServerStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
581 clearOnServerChange();
583 updateSelectedCdmServer();
584 Display
.getDefault().asyncExec(new Runnable() {
587 checkSelectedCdmServer();
591 catch(SWTException e
){
592 //catch widget is disposed exception which may occur if
593 //dialog is closed but the runnable tries to update
597 protected void updateSelectedCdmServer() {
598 int selIndex
= comboCdmServer
.getSelectionIndex();
600 selectedServerInfo
= getServerInfoMap().get(comboCdmServer
.getItem(selIndex
));
604 protected void updatePort() {
605 txtPort
.setText(""); //$NON-NLS-1$
606 if(selectedServerInfo
!= null) {
607 int port
= selectedServerInfo
.getPort();
608 if(port
== CdmServerInfo
.NULL_PORT
) {
609 txtPort
.setText(CdmServerInfo
.NULL_PORT_STRING
);
611 txtPort
.setText(String
.valueOf(port
));
616 protected int getPort() {
617 int port
= CdmServerInfo
.NULL_PORT
;
619 port
= Integer
.valueOf(txtPort
.getText());
620 } catch (NumberFormatException nfe
) {
621 if(!CdmServerInfo
.NULL_PORT_STRING
.equals(txtPort
.getText())) {
622 setMessage(Messages
.RemotingLoginDialog_MESSAGE_PORT_SHOULD_BE_INTEGER
);
628 private void checkSelectedCdmServer() {
630 if(selectedServerInfo
!= null) {
631 if(selectedServerInfo
.isLocalhost()) {
632 txtPort
.setEditable(true);
633 txtPort
.setEnabled(true);
636 if(selectedServerInfo
.pingServer()) {
637 txtCdmServerStatus
.setText(STATUS_AVAILABLE
);
638 populateCdmInstanceCombo(true);
639 if(selectedServerInfo
.isLocalhost()){
640 setCdmlibVersion(txtServerCdmlibVersion
);
642 String serverVersionTimestamp
= generateLastModifiedTooltip(selectedServerInfo
.getCdmlibLastModified());
643 txtServerCdmlibVersion
.setText(selectedServerInfo
.getCdmlibServicesVersion() + ":" + serverVersionTimestamp
); //$NON-NLS-1$
646 txtCdmServerStatus
.setText(STATUS_NOT_AVAILABLE
);
647 comboCdmInstance
.removeAll();
648 disableCdmInstanceControls("", ""); //$NON-NLS-1$ //$NON-NLS-2$
650 } catch (CdmServerException
| IOException e
) {
651 txtCdmServerStatus
.setText(STATUS_NOT_AVAILABLE
);
652 // TODO distinguish java.net.ConnectException: Connection refused, java.net.SocketTimeoutException: Read timed out
654 if(e
instanceof CdmServerException
&& e
.getCause() != null){
655 cause
= e
.getCause();
657 String message
= Messages
.RemotingLoginDialog_CONNECTION_FAILED_MESSAGE
;
658 if(cause
instanceof SocketTimeoutException
){
659 message
= Messages
.RemotingLoginDialog_CONNECTION_TIMEOUT_MESSAGE
;
661 MessagingUtils
.warningDialog(Messages
.RemotingLoginDialog_CONNECTION_FAILED_TITLE
, this,
663 logger
.warn(Messages
.RemotingLoginDialog_CONNECTION_FAILED_TITLE
, e
);
668 catch(SWTException e
){
669 //catch widget is disposed exception which may occur if
670 //dialog is closed but the runnable tries to update
674 protected void populateCdmInstanceCombo(final boolean forceRefresh
) {
675 comboCdmInstance
.removeAll();
676 comboCdmInstance
.setEnabled(false);
677 btnConnect
.setEnabled(false);
678 txtCdmInstanceStatus
.setText(STATUS_RETRIEVING
);
679 txtCdmInstanceStatus
.setToolTipText(""); //$NON-NLS-1$
682 serverJob
= new Job(Messages
.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES
) {
684 protected IStatus
run(IProgressMonitor monitor
) {
686 if(selectedServerInfo
!= null) {
688 selectedServerInfo
.refreshInstances();
690 final List
<CdmInstanceInfo
> instances
= selectedServerInfo
.getInstances();
691 Display
.getDefault().asyncExec(()->{
692 if(!instances
.isEmpty()) {
693 for(CdmInstanceInfo cdmInstance
: instances
) {
694 comboCdmInstance
.add(cdmInstance
.getName());
696 int instanceIndex
= -1;
697 if(getInstanceName() != null) {
698 instanceIndex
= comboCdmInstance
.indexOf(getInstanceName());
700 if(instanceIndex
== -1) {
701 comboCdmInstance
.select(0);
702 setAutoConnect(false);
704 comboCdmInstance
.select(instanceIndex
);
706 onRefreshCdmInstance();
707 comboCdmInstance
.setEnabled(allowInstanceChange
);
708 if(isAutoConnect()) {
712 txtCdmInstanceStatus
.setText(STATUS_NO_INSTANCES
);
713 btnConnect
.setEnabled(false);
717 } catch (final CdmServerException e
) {
718 MessagingUtils
.warn(getClass(), e
);
719 Display
.getDefault().asyncExec(new Runnable() {
722 disableCdmInstanceControls(STATUS_NOT_AVAILABLE
, e
.getMessage());
726 return Status
.OK_STATUS
;
730 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
) && !isDevRemoteSource()) {
732 serverJob
.schedule();
736 public void disableCdmInstanceControls(String cdmInstanceStatus
, String tooltip
) {
737 txtCdmInstanceStatus
.setText(cdmInstanceStatus
);
738 txtCdmInstanceStatus
.setToolTipText(tooltip
);
739 comboCdmInstance
.setEnabled(false);
740 btnConnect
.setEnabled(false);
743 public void onRefreshCdmInstance() {
744 txtCdmInstanceStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
745 clearOnInstanceChange();
746 updateSelectedCdmInstance();
747 checkSelectedCdmInstance();
748 // updateManagedServerControls();
751 protected void updateSelectedCdmInstance() {
752 int selIndex
= comboCdmInstance
.getSelectionIndex();
754 selectedCdmInstance
= selectedServerInfo
.getInstanceFromName(comboCdmInstance
.getItem(selIndex
));
756 readPrefCredentials();
761 private boolean schemaExists(CdmInstanceInfo instanceInfo
) {
762 if (instanceInfo
.getDataSource() != null){
764 //TODO we need a new method in cdmlib to check for existing schema
765 String schemaVersion
= instanceInfo
.getDataSource().getDbSchemaVersion();
766 return schemaVersion
!= null;
767 } catch (CdmSourceException e
) {
775 private String
managedSchemaVersion(CdmInstanceInfo instanceInfo
) throws CdmSourceException
{
776 if (instanceInfo
.getDataSource() != null){
777 return instanceInfo
.getDataSource().getDbSchemaVersion();
779 throw new RuntimeException("ManagedSchemaVersion only available for managed server instances.");
782 private int compareSchemaVersion(CdmInstanceInfo instanceInfo
) throws CdmSourceException
{
783 return CdmMetaData
.compareVersion(managedSchemaVersion(instanceInfo
), CdmMetaData
.getDbSchemaVersion(), 3, null);
786 protected void checkSelectedCdmInstance() {
788 if (selectedCdmInstance
!= null && selectedCdmInstance
.getDataSource() != null){
789 String schemaVersion
= selectedCdmInstance
.getDataSource().getDbSchemaVersion();
791 } catch (CdmSourceException e1
) {
792 // TODO Auto-generated catch block
793 e1
.printStackTrace();
795 if (txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
)) {
797 boolean available
= false;
798 String instanceStatus
= STATUS_NOT_AVAILABLE
;
799 String message
= null;
801 if(selectedServerInfo
.pingInstance(selectedCdmInstance
, getPort())) {
802 instanceStatus
= STATUS_AVAILABLE
;
805 instanceStatus
= STATUS_NOT_AVAILABLE
;
810 txtServerSchemaVersion
.setText(selectedServerInfo
.getCdmRemoteSource(selectedCdmInstance
, getPort()).getDbSchemaVersion());
812 int compareDbSchemaVersion
= selectedServerInfo
.compareDbSchemaVersion(selectedCdmInstance
, getPort());
814 int compareCdmlibServicesVersion
= 0;
815 boolean disableServicesApiTimestampCheck
=
816 PreferencesUtil
.getBooleanValue((IPreferenceKeys
.DISABLE_SERVICES_API_TIMESTAMP_CHECK
));
817 if(!disableServicesApiTimestampCheck
) {
818 compareCdmlibServicesVersion
= selectedServerInfo
.compareCdmlibServicesVersion();
821 if(compareDbSchemaVersion
> 0 || compareCdmlibServicesVersion
> 0) {
822 instanceStatus
= STATUS_NOT_COMPATIBLE
;
824 message
= MESG_COMPATIBLE_EDITOR_OLD
;
825 } else if(compareDbSchemaVersion
< 0 || compareCdmlibServicesVersion
< 0) {
826 instanceStatus
= STATUS_NOT_COMPATIBLE
;
828 message
= MESG_COMPATIBLE_SERVER_OLD
;
830 instanceStatus
= STATUS_AVAILABLE
;
832 message
= ""; //$NON-NLS-1$
835 } catch (Exception e
) {
836 txtCdmInstanceStatus
.setToolTipText(e
.getMessage());
838 lblDefaultLogin
.setVisible(false);
839 btnConnect
.setEnabled(available
);
840 txtCdmInstanceStatus
.setText(instanceStatus
);
841 if(!StringUtils
.isBlank(message
)) {
849 public void connect() {
850 checkSelectedCdmInstance();
852 if(!txtCdmInstanceStatus
.getText().equals(STATUS_AVAILABLE
)) {
856 ICdmRemoteSource source
= selectedServerInfo
.getCdmRemoteSource(selectedCdmInstance
, getPort());
858 if(!validateLogin(source
)) {
863 CdmStore
.connect(source
, this);
864 } catch (Exception e
) {
865 // Do not expect anything to go wrong at this point, so we throw a runtime exception
867 throw new RuntimeException(e
);
871 public boolean isRememberMe() {
872 return btnRememberMe
.getSelection();
875 private void persistPrefLastServerInstance() {
876 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
877 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
879 lastServerInstancePrefs
.put(LAST_SERVER_KEY
, selectedServerInfo
.getName());
880 lastServerInstancePrefs
.put(LAST_INSTANCE_KEY
, selectedCdmInstance
.getName());
882 flushPreferences(lastServerInstancePrefs
);
885 private void persistPrefCredentials() {
886 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
887 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
888 credentialsPrefs
.put(getUsernamePrefKey(), txtLogin
.getText());
889 credentialsPrefs
.put(getPasswordPrefKey(), txtPassword
.getText());
890 flushPreferences(credentialsPrefs
);
893 private void removePrefCredentials() {
894 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
895 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
896 credentialsPrefs
.put(getUsernamePrefKey(), txtLogin
.getText());
897 credentialsPrefs
.put(getPasswordPrefKey(), txtPassword
.getText());
898 removePreferences(credentialsPrefs
);
901 private void removePreferences(Preferences prefs
) {
904 } catch (BackingStoreException bse
) {
905 setMessage(bse
.getMessage());
909 private void flushPreferences(Preferences prefs
) {
912 } catch (BackingStoreException bse
) {
913 setMessage(bse
.getMessage());
917 protected void readPrefCredentials() {
918 String username
, password
;
919 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
920 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
921 username
= credentialsPrefs
.get(getUsernamePrefKey(), ""); //$NON-NLS-1$
922 txtLogin
.setText(username
);
923 password
= credentialsPrefs
.get(getPasswordPrefKey(),""); //$NON-NLS-1$
924 txtPassword
.setText(password
);
925 if(username
.isEmpty() || password
.isEmpty()) {
926 setAutoConnect(false);
930 private void readPrefLastServerInstance() {
931 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
932 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
934 setServerName(lastServerInstancePrefs
.get(LAST_SERVER_KEY
, null));
935 setInstanceName(lastServerInstancePrefs
.get(LAST_INSTANCE_KEY
, null));
938 private void emptyCredentials() {
939 txtLogin
.setText(""); //$NON-NLS-1$
940 txtPassword
.setText(""); //$NON-NLS-1$
943 private String
getUsernamePrefKey() {
944 return selectedServerInfo
.toString(selectedCdmInstance
.getName(), isDevRemoteSource()?
getPort():-1) + USERNAME_SUFFIX
;
947 private String
getPasswordPrefKey() {
948 return selectedServerInfo
.toString(selectedCdmInstance
.getName(), isDevRemoteSource()?
getPort():-1) + PASSWORD_SUFFIX
;
951 private boolean validateLogin(ICdmRemoteSource remoteSource
) {
952 if(getUsername() == null || getUsername().isEmpty()) {
953 setMessage(Messages
.RemotingLoginDialog_LOGIN_CANNOT_BE_EMPTY
);
956 if(getPassword() == null || getPassword().isEmpty()) {
957 setMessage(Messages
.RemotingLoginDialog_PASSWORD_CANNOT_BE_EMPTY
);
962 IUserService userService
= CdmApplicationRemoteConfiguration
.getUserService(remoteSource
);
963 UsernamePasswordAuthenticationToken token
= new UsernamePasswordAuthenticationToken(getUsername(), getPassword());
964 CdmApplicationRemoteConfiguration
.getAuthenticationManager(userService
).authenticate(token
);
965 } catch(BadCredentialsException e
){
966 setMessage(LoginManager
.INCORRECT_CREDENTIALS_MESSAGE
);
968 } catch(LockedException e
){
969 setMessage(LoginManager
.ACCOUNT_LOCKED_MESSAGE
);
971 } catch(IllegalArgumentException e
){
972 setMessage(LoginManager
.INCORRECT_CREDENTIALS_MESSAGE
);
978 public String
getUsername() {
979 return txtLogin
.getText();
982 public String
getPassword() {
983 return txtPassword
.getText();
986 public void setMessage(String message
) {
987 if(CdmUtils
.isNotBlank(message
)) {
988 // if(message.length() > 50) {
989 // styledTxtMessage.setToolTipText(message);
990 // message = message.substring(0,50) + "..."; //$NON-NLS-1$
992 styledTxtMessage
.setText(message
);
993 styledTxtMessage
.setVisible(true);
994 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= false;
995 // shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
996 shlConnect
.pack(true);
998 if (!styledTxtMessage
.isDisposed()){
999 styledTxtMessage
.setText(""); //$NON-NLS-1$
1000 styledTxtMessage
.setVisible(false);
1001 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= true;
1003 if(!shlConnect
.isDisposed()){
1004 shlConnect
.pack(true);
1007 if (!remotingComposite
.isDisposed()){
1008 remotingComposite
.layout();
1013 public void hide(boolean isHidden
) {
1014 if (!shlConnect
.isDisposed()){
1015 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
1016 shlConnect
.setVisible(!isHidden
);
1021 public void dispose() {
1022 if (!shlConnect
.isDisposed()){
1023 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
1024 shlConnect
.dispose();
1029 public void onComplete() {
1030 Display
.getDefault().asyncExec(new Runnable() {
1033 if(selectedCdmInstance
!=null){
1034 if(isRememberMe()) {
1035 persistPrefCredentials();
1037 removePrefCredentials();
1039 persistPrefLastServerInstance();
1046 private String
generateLastModifiedTooltip(String cdmlibLastModified
) {
1047 if(StringUtils
.isBlank(cdmlibLastModified
)) {
1048 return ""; //$NON-NLS-1$
1050 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy.MM.dd.HH.mm.z"); //$NON-NLS-1$
1051 Date cdmlibLastModifiedDate
;
1052 String cdmlibLastModifiedTimestamp
= ""; //$NON-NLS-1$
1054 cdmlibLastModifiedDate
= new Date(Long
.valueOf(cdmlibLastModified
));
1055 cdmlibLastModifiedTimestamp
= sdf
.format(cdmlibLastModifiedDate
);
1057 return cdmlibLastModifiedTimestamp
;
1060 private void setEditorInfo() {
1061 txtEditorCdmVersion
.setText(CdmMetaData
.getDbSchemaVersion());
1062 setCdmlibVersion(txtEditorCdmlibVersion
);
1065 private void setCdmlibVersion(Text txt
) {
1066 String editorVersionTimestamp
= generateLastModifiedTooltip(CdmApplicationState
.getCdmlibLastModified());
1067 txt
.setText(CdmApplicationState
.getCdmlibVersion() + ":" + editorVersionTimestamp
); //$NON-NLS-1$
1070 private void clearOnServerChange() {
1071 setMessage(""); //$NON-NLS-1$
1072 txtServerSchemaVersion
.setText(""); //$NON-NLS-1$
1073 txtServerCdmlibVersion
.setText(""); //$NON-NLS-1$
1074 txtServerCdmlibVersion
.setToolTipText(""); //$NON-NLS-1$
1075 txtServerSchemaVersion
.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 txtServerSchemaVersion
.setText(""); //$NON-NLS-1$
1085 btnConnect
.setText(LABEL_CONNECT
);
1086 btnConnect
.setBackground(null);
1087 btnConnect
.requestLayout();
1090 @SuppressWarnings("unused") //in work, for future centralized handling of control's status
1091 private void updateControls(){
1094 String strServerStatus
= this.selectedServerInfo
!= null? STATUS_NOT_AVAILABLE
: STATUS_AVAILABLE
;
1095 txtCdmServerStatus
.setText(strServerStatus
);
1100 String strInstanceStatus
= this.selectedCdmInstance
!= null? STATUS_NOT_AVAILABLE
: STATUS_AVAILABLE
;
1101 txtCdmInstanceStatus
.setText(strInstanceStatus
);
1105 txtLogin
.setText(Nz(login
));
1106 txtPassword
.setText(Nz(password
));
1107 btnConnect
.setText(LABEL_CONNECT
); //TODO
1108 btnConnect
.setEnabled(true);
1112 private String
Nz(String value
) {
1113 return CdmUtils
.Nz(value
);
1116 public Map
<String
, CdmServerInfo
> getServerInfoMap() {
1117 return serverInfoMap
;
1120 public String
getServerName() {
1124 public void setServerName(String serverName
) {
1125 this.serverName
= serverName
;
1128 public boolean isAutoConnect() {
1132 public void setAutoConnect(boolean autoConnect
) {
1133 this.autoConnect
= autoConnect
;
1136 public boolean isDevRemoteSource() {
1137 return isDevRemoteSource
;
1140 public void setDevRemoteSource(boolean isDevRemoteSource
) {
1141 this.isDevRemoteSource
= isDevRemoteSource
;
1144 public String
getInstanceName() {
1145 return instanceName
;
1148 public void setInstanceName(String instanceName
) {
1149 this.instanceName
= instanceName
;
1153 public void handleError(Throwable t
) {
1154 Display
.getDefault().syncExec(()-> {
1157 String title
= Messages
.RemotingLoginDialog_SERVER_LAUNCH_ERROR
;
1158 String message
= t
.getMessage();
1160 MessagingUtils
.errorDialog(title
,
1163 TaxeditorStorePlugin
.PLUGIN_ID
,