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
.local
.server
;
12 import java
.io
.IOException
;
13 import java
.net
.SocketTimeoutException
;
14 import java
.text
.SimpleDateFormat
;
15 import java
.util
.Date
;
16 import java
.util
.List
;
18 import org
.apache
.commons
.lang3
.StringUtils
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.core
.runtime
.IStatus
;
22 import org
.eclipse
.core
.runtime
.Status
;
23 import org
.eclipse
.core
.runtime
.jobs
.Job
;
24 import org
.eclipse
.core
.runtime
.preferences
.ConfigurationScope
;
25 import org
.eclipse
.core
.runtime
.preferences
.IEclipsePreferences
;
26 import org
.eclipse
.jface
.layout
.GridDataFactory
;
27 import org
.eclipse
.swt
.SWT
;
28 import org
.eclipse
.swt
.SWTException
;
29 import org
.eclipse
.swt
.custom
.StyledText
;
30 import org
.eclipse
.swt
.events
.KeyAdapter
;
31 import org
.eclipse
.swt
.events
.KeyEvent
;
32 import org
.eclipse
.swt
.events
.MouseAdapter
;
33 import org
.eclipse
.swt
.events
.MouseEvent
;
34 import org
.eclipse
.swt
.events
.SelectionAdapter
;
35 import org
.eclipse
.swt
.events
.SelectionEvent
;
36 import org
.eclipse
.swt
.graphics
.Color
;
37 import org
.eclipse
.swt
.graphics
.Point
;
38 import org
.eclipse
.swt
.graphics
.Rectangle
;
39 import org
.eclipse
.swt
.layout
.FillLayout
;
40 import org
.eclipse
.swt
.layout
.GridData
;
41 import org
.eclipse
.swt
.layout
.GridLayout
;
42 import org
.eclipse
.swt
.widgets
.Button
;
43 import org
.eclipse
.swt
.widgets
.Combo
;
44 import org
.eclipse
.swt
.widgets
.Composite
;
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
.model
.metadata
.CdmMetaData
;
66 import eu
.etaxonomy
.cdm
.persistence
.permission
.Role
;
67 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
68 import eu
.etaxonomy
.taxeditor
.local
.CdmEmbeddedServerException
;
69 import eu
.etaxonomy
.taxeditor
.local
.CdmServer
;
70 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
71 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
72 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
73 import eu
.etaxonomy
.taxeditor
.remoting
.server
.CdmServerException
;
74 import eu
.etaxonomy
.taxeditor
.remoting
.server
.CdmServerUtils
;
75 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmRemoteLocalhostSource
;
76 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
;
77 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
.CdmInstanceInfo
;
78 import eu
.etaxonomy
.taxeditor
.remoting
.source
.ICdmRemoteSource
;
79 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
80 import eu
.etaxonomy
.taxeditor
.store
.LoginManager
;
81 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
82 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.RemotingLoginDialog
;
83 import eu
.etaxonomy
.taxeditor
.workbench
.datasource
.ICdmServerError
;
91 public class RemotingLoginDialogLocal
extends RemotingLoginDialog
implements ICdmServerError
{
93 private Logger logger
= Logger
.getLogger(getClass());
97 // protected Shell shlConnect;
98 // private Text txtCdmServerStatus;
99 // private Text txtCdmInstanceStatus;
101 // private Button btnConnect;
103 // private Composite remotingComposite;
104 // private Button btnCdmServerRefresh;
105 // private Button btnCdmInstanceRefresh;
106 // private Button btnStopServer;
107 // private Composite loginComposite;
108 // private Label lblLogin;
109 // private Text txtLogin;
110 // private Label lblPassword;
111 // private Text txtPassword;
112 // private Button btnRememberMe;
113 // private Label lblDefaultLogin;
114 // private Composite compAdvanced;
115 // private Label lblPort;
116 // private Text txtPort;
117 // private Label lblServerCdmlibVersion;
118 // private Text txtServerCdmlibVersion;
119 // private ExpandableComposite expandableCompositeAdvanced;
120 // private StyledText styledTxtMessage;
122 // private Label lblEditorCdmlibVersion;
123 // private Text txtEditorCdmlibVersion;
124 // private Label lblServerSchemaVersion;
125 // private Text txtServerSchemaVersion;
126 // private Label lblEditorCdmVersion;
127 // private Text txtEditorCdmVersion;
129 // private final int MESSAGE_HEIGHT = 50;
130 // private final int COMBO_MIN_WIDTH =200;
131 // private final int CONTROLS_MIN_HEIGHT = 23; //does not seem to work yet
132 //// private final int MIN_EXP_HEIGHT = 380;
134 // private boolean autoConnect = false;
135 // private boolean loadLoginPrefs = true;
136 // private boolean isDevRemoteSource = false;
138 // private Job serverJob;
139 // protected Object result;
141 // private final Map<String, CdmServerInfo> serverInfoMap = new HashMap<>();
143 // private String serverName;
144 // private String instanceName;
145 // private CdmServerInfo selectedServerInfo;
146 // private CdmInstanceInfo selectedCdmInstance;
147 // private String login;
148 // private String password;
155 public RemotingLoginDialogLocal(Shell parent
, int style
) {
156 super(parent
, style
);
157 setText(Messages
.RemotingLoginDialog_LABEL_LOGIN
);
163 public Object
open(ICdmRemoteSource source
, boolean loadLoginPrefs
, boolean autoConnect
) {
164 this.loadLoginPrefs
= loadLoginPrefs
;
165 this.serverName
= source
.getName();
166 if (source
instanceof CdmRemoteLocalhostSource
){
167 this.instanceName
= ((CdmRemoteLocalhostSource
)source
).getDatasourceName();
169 String contextPath
= source
.getContext();
170 this.instanceName
= contextPath
== null?
"" : contextPath
.substring(contextPath
.lastIndexOf("/") + 1); //$NON-NLS-1$
172 return open(serverName
, instanceName
, loadLoginPrefs
, autoConnect
);
177 public Object
open(String serverName
, String instanceName
, boolean loadLoginPrefs
, boolean autoConnect
) {
178 this.serverName
= serverName
;
179 this.instanceName
= instanceName
;
180 this.loadLoginPrefs
= loadLoginPrefs
;
181 this.autoConnect
= autoConnect
;
187 * @return the dialog result
191 public Object
open() {
194 if(serverName
== null && instanceName
== null) {
195 readPrefLastServerInstance();
197 expandableCompositeAdvanced
.setExpanded(false);
200 populateCdmServerCombo();
201 shlConnect
.pack(true);
206 Display display
= getParent().getDisplay();
207 while (!shlConnect
.isDisposed()) {
208 if (!display
.isDisposed()){
209 if (!display
.readAndDispatch()) {
218 * Create contents of the dialog.
221 protected void createContents() {
222 shlConnect
= new Shell(getParent(), SWT
.DIALOG_TRIM
| SWT
.APPLICATION_MODAL
| SWT
.RESIZE
| SWT
.CENTER
);
223 shlConnect
.setText(LABEL_CONNECT
);
224 shlConnect
.setLayout(new FillLayout(SWT
.HORIZONTAL
));
226 remotingComposite
= new Composite(shlConnect
, SWT
.NONE
);
227 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 cdmServerComposite
.setLayoutData(gd_cdmServerComposite
);
233 cdmServerComposite
.setLayout(new GridLayout(4, false));
235 Label lblCdmServer
= new Label(cdmServerComposite
, SWT
.NONE
);
236 lblCdmServer
.setText(Messages
.RemotingLoginDialog_LABEL_CDM_SERVER
);
237 lblCdmServer
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
239 comboCdmServer
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
240 comboCdmServer
.addSelectionListener(new SelectionAdapter() {
242 public void widgetSelected(SelectionEvent e
) {
243 onRefreshCdmServer();
247 GridData gd_comboCdmServer
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, true, 1, 1);
249 comboCdmServer
.setLayoutData(gd_comboCdmServer
);
250 comboCdmServer
.select(0);
252 txtCdmServerStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
253 txtCdmServerStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
254 txtCdmServerStatus
.setEditable(false);
255 GridData gd_txtCdmServerStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, true, 1, 1);
256 gd_txtCdmServerStatus
.minimumHeight
= CONTROLS_MIN_HEIGHT
;
257 txtCdmServerStatus
.setLayoutData(gd_txtCdmServerStatus
);
259 btnCdmServerRefresh
= new Button(cdmServerComposite
, SWT
.NONE
);
260 btnCdmServerRefresh
.addSelectionListener(new SelectionAdapter() {
262 public void widgetSelected(SelectionEvent e
) {
263 onRefreshCdmServer();
266 GridData gd_btnCdmServerRefresh
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, true, 1, 1);
267 gd_btnCdmServerRefresh
.minimumHeight
= CONTROLS_MIN_HEIGHT
;
268 btnCdmServerRefresh
.setLayoutData(gd_btnCdmServerRefresh
);
269 btnCdmServerRefresh
.setText(Messages
.RemotingLoginDialog_LABEL_REFRESH
);
272 Label lblCdmInstance
= new Label(cdmServerComposite
, SWT
.NONE
);
273 GridData gd_lblCdmInstance
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, true, 1, 1);
274 //gd_lblCdmInstance.heightHint = 30;
275 lblCdmInstance
.setLayoutData(gd_lblCdmInstance
);
276 lblCdmInstance
.setText(Messages
.RemotingLoginDialog_LABEL_CDM_INSTANCE
);
278 comboCdmInstance
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
279 comboCdmInstance
.addSelectionListener(new SelectionAdapter() {
281 public void widgetSelected(SelectionEvent e
) {
282 onRefreshCdmInstance();
286 GridData gd_comboCdmInstance
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 1);
287 gd_comboCdmInstance
.minimumWidth
= COMBO_MIN_WIDTH
;
289 comboCdmInstance
.setLayoutData(gd_comboCdmInstance
);
290 comboCdmInstance
.select(0);
292 txtCdmInstanceStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
293 txtCdmInstanceStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
294 txtCdmInstanceStatus
.setEditable(false);
295 GridData gd_txtCdmInstanceStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, true, 1, 1);
296 gd_txtCdmInstanceStatus
.minimumHeight
= CONTROLS_MIN_HEIGHT
;
297 txtCdmInstanceStatus
.setLayoutData(gd_txtCdmInstanceStatus
);
299 btnCdmInstanceRefresh
= new Button(cdmServerComposite
, SWT
.FLAT
);
300 btnCdmInstanceRefresh
.addSelectionListener(new SelectionAdapter() {
302 public void widgetSelected(SelectionEvent e
) {
303 onRefreshCdmInstance();
306 GridData gd_btnCdmInstanceRefresh
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 1);
307 gd_btnCdmInstanceRefresh
.minimumHeight
= CONTROLS_MIN_HEIGHT
;
308 btnCdmInstanceRefresh
.setLayoutData(gd_btnCdmInstanceRefresh
);
309 btnCdmInstanceRefresh
.setText(Messages
.RemotingLoginDialog_LABEL_REFRESH
);
312 loginComposite
= new Composite(remotingComposite
, SWT
.NONE
);
313 GridData gd_loginComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
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 lblLogin
.setLayoutData(gd_lblLogin
);
322 lblLogin
.setText(Messages
.RemotingLoginDialog_LABEL_LOGIN_COLON
);
324 txtLogin
= new Text(loginComposite
, SWT
.BORDER
);
325 GridData gd_txtLogin
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
326 gd_txtLogin
.minimumWidth
= 80;
327 txtLogin
.setLayoutData(gd_txtLogin
);
329 lblPassword
= new Label(loginComposite
, SWT
.CENTER
);
330 lblPassword
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
331 lblPassword
.setText(Messages
.RemotingLoginDialog_LABEL_PASSWORD
);
333 txtPassword
= new Text(loginComposite
, SWT
.BORDER
| SWT
.PASSWORD
);
334 GridData gd_txtPassword
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
335 gd_txtPassword
.minimumWidth
= 80;
336 txtPassword
.setLayoutData(gd_txtPassword
);
337 @SuppressWarnings("unused")
338 Label nope
= new Label(loginComposite
, SWT
.NONE
);
339 txtPassword
.addKeyListener(new KeyAdapter() {
341 public void keyPressed(KeyEvent e
) {
342 if(e
.character
==SWT
.CR
){
343 if(btnConnect
.getText().equals(LABEL_CONNECT
)){
344 onConnectButtonPressed();
350 btnConnect
= new Button(loginComposite
, SWT
.FLAT
);
351 btnConnect
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1));
352 btnConnect
.addSelectionListener(new SelectionAdapter() {
354 public void widgetSelected(SelectionEvent e
) {
355 onConnectButtonPressed();
358 btnConnect
.setText(LABEL_CONNECT
);
360 //rememberMe + default values
361 btnRememberMe
= new Button(loginComposite
, SWT
.CHECK
);
362 btnRememberMe
.setSelection(true);
363 GridData gd_btnRememberMe
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 2, 1);
364 btnRememberMe
.setLayoutData(gd_btnRememberMe
);
365 btnRememberMe
.setText(Messages
.RemotingLoginDialog_LABEL_REMEMBER_ME
);
367 lblDefaultLogin
= new Label(loginComposite
, SWT
.NONE
);
368 GridDataFactory
.fillDefaults().span(4, 1).align(SWT
.TRAIL
, SWT
.CENTER
).applyTo(lblDefaultLogin
);
369 lblDefaultLogin
.setText(String
.format(Messages
.RemotingLoginDialog_DEFAULT_LOGIN
, DEFAULT_USER
, DEFAULT_PASS
));
370 lblDefaultLogin
.setVisible(false);
372 styledTxtMessage
= new StyledText(remotingComposite
, SWT
.NONE
);
373 styledTxtMessage
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
374 styledTxtMessage
.setForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
375 styledTxtMessage
.setSelectionBackground(SWTResourceManager
.getColor(SWT
.COLOR_LIST_SELECTION_TEXT
));
376 styledTxtMessage
.setSelectionForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
377 styledTxtMessage
.setDoubleClickEnabled(false);
378 styledTxtMessage
.setEditable(false);
379 styledTxtMessage
.setWordWrap(true);
381 GridData gd_styledTxtMessage
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
382 gd_styledTxtMessage
.exclude
= true;
383 gd_styledTxtMessage
.minimumHeight
= MESSAGE_HEIGHT
;
385 styledTxtMessage
.setLayoutData(gd_styledTxtMessage
);
388 expandableCompositeAdvanced
= new ExpandableComposite(remotingComposite
, SWT
.NONE
, ExpandableComposite
.TWISTIE
);
389 GridData gd_xpndblcmpstAdvanced
= new GridData(SWT
.FILL
, SWT
.FILL
, false, true, 1, 1);
390 expandableCompositeAdvanced
.setLayoutData(gd_xpndblcmpstAdvanced
);
391 expandableCompositeAdvanced
.addExpansionListener(new IExpansionListener() {
393 public void expansionStateChanged(ExpansionEvent e
) {
394 shlConnect
.pack(true);
397 public void expansionStateChanging(ExpansionEvent e
) {
400 expandableCompositeAdvanced
.setText(Messages
.RemotingLoginDialog_LABEL_ADVANCED
);
401 expandableCompositeAdvanced
.setExpanded(true);
403 compAdvanced
= new Composite(expandableCompositeAdvanced
, SWT
.NONE
);
404 expandableCompositeAdvanced
.setClient(compAdvanced
);
405 compAdvanced
.setLayout(new GridLayout(4, false));
407 lblPort
= new Label(compAdvanced
, SWT
.CENTER
);
408 lblPort
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
409 lblPort
.setText(Messages
.RemotingLoginDialog_LABEL_PORT
);
411 txtPort
= new Text(compAdvanced
, SWT
.BORDER
);
412 GridData gd_txtPort
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1);
413 gd_txtPort
.minimumWidth
= 50;
414 txtPort
.setLayoutData(gd_txtPort
);
416 lblServerCdmlibVersion
= new Label(compAdvanced
, SWT
.CENTER
);
417 lblServerCdmlibVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
418 lblServerCdmlibVersion
.setText(Messages
.RemotingLoginDialog_LABEL_SERVER_CDMLIB_VERSION
);
420 txtServerCdmlibVersion
= new Text(compAdvanced
, SWT
.BORDER
);
421 txtServerCdmlibVersion
.setEditable(false);
422 txtServerCdmlibVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
424 btnStopServer
= new Button(compAdvanced
, SWT
.FLAT
);
425 btnStopServer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 2, 1));
426 btnStopServer
.addMouseListener(new MouseAdapter() {
428 public void mouseUp(MouseEvent e
) {
429 onStopManagedServer();
432 btnStopServer
.setText(Messages
.RemotingLoginDialog_LABEL_STOP_MANAGED_SERVER
);
434 lblEditorCdmlibVersion
= new Label(compAdvanced
, SWT
.CENTER
);
435 lblEditorCdmlibVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
436 lblEditorCdmlibVersion
.setText(Messages
.RemotingLoginDialog_LABEL_EDITOR_CDMLIB_VERSION
);
438 txtEditorCdmlibVersion
= new Text(compAdvanced
, SWT
.BORDER
);
439 txtEditorCdmlibVersion
.setEditable(false);
440 txtEditorCdmlibVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
443 lblServerSchemaVersion
= new Label(compAdvanced
, SWT
.CENTER
);
444 lblServerSchemaVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
445 lblServerSchemaVersion
.setText(Messages
.RemotingLoginDialog_LABEL_SERVER_CDM_VERSION
);
447 txtServerSchemaVersion
= new Text(compAdvanced
, SWT
.BORDER
);
448 txtServerSchemaVersion
.setEditable(false);
449 txtServerSchemaVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
452 lblEditorCdmVersion
= new Label(compAdvanced
, SWT
.CENTER
);
453 lblEditorCdmVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
454 lblEditorCdmVersion
.setText(Messages
.RemotingLoginDialog_LABEL_EDITOR_CDM_VERSION
);
456 txtEditorCdmVersion
= new Text(compAdvanced
, SWT
.BORDER
);
457 txtEditorCdmVersion
.setEditable(false);
458 txtEditorCdmVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
463 public void setCenterPoint() {
464 Rectangle parentSize
= getParent().getBounds();
465 Rectangle shellSize
= shlConnect
.getBounds();
466 int locationX
= (parentSize
.width
- shellSize
.width
)/2+parentSize
.x
;
467 int locationY
= (parentSize
.height
- shellSize
.height
)/2+parentSize
.y
;
468 shlConnect
.setLocation(new Point(locationX
, locationY
));
477 @SuppressWarnings("unused")
478 private void addEmptyCells(int cnt
) {
479 for (int i
= 0; i
< cnt
; i
++) {
480 new Label(compAdvanced
, SWT
.NONE
);
485 protected void onConnectButtonPressed() {
486 if(selectedServerInfo
.isLocalhostMgd() && !isSelectedCdmInstanceRunningInManagedServer()) {
487 startManagedServer();
490 if (CdmStore
.isActive() && CdmStore
.currentAuthentiationHasOneOfRoles(Role
.ROLE_REMOTING
)){
491 PreferencesUtil
.setNomenclaturalCodePreferences();
496 // private void populateCdmServerCombo() {
497 // Job job = new Job(Messages.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES) {
499 // protected IStatus run(IProgressMonitor monitor) {
500 // Display.getDefault().syncExec(new Runnable() {
502 // public void run() {
503 // //TODO performance
504 // for(CdmServerInfo csii : CdmServerInfo.getCdmServers(true)) {
505 // serverInfoMap.put(csii.getName(), csii);
506 // comboCdmServer.add(csii.getName());
508 // int serverIndex = -1;
509 // if(serverName != null) {
510 // serverIndex = comboCdmServer.indexOf(serverName);
512 // if(serverIndex == -1) {
513 // comboCdmServer.select(0);
514 // autoConnect = false;
516 // comboCdmServer.select(serverIndex);
518 // ICdmSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
519 // if(devRemoteSource != null) {
520 // isDevRemoteSource = true;
521 // String username = System.getProperty("cdm.server.dev.username"); //$NON-NLS-1$
522 // String password = System.getProperty("cdm.server.dev.password"); //$NON-NLS-1$
523 // if(username != null && !username.isEmpty() && password != null && !password.isEmpty()) {
524 // txtLogin.setText(username);
525 // txtPassword.setText(password);
526 // CdmStoreLocal.connect(devRemoteSource, RemotingLoginDialogLocal.this);
529 // onRefreshCdmServer();
533 // return Status.OK_STATUS;
540 public void onRefreshCdmServer() {
542 txtCdmServerStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
543 clearOnServerChange();
545 updateSelectedCdmServer();
546 Display
.getDefault().asyncExec(new Runnable() {
549 checkSelectedCdmServer();
553 catch(SWTException e
){
554 //catch widget is disposed exception which may occur if
555 //dialog is closed but the runnable tries to update
560 protected void updateSelectedCdmServer() {
561 int selIndex
= comboCdmServer
.getSelectionIndex();
563 selectedServerInfo
= serverInfoMap
.get(comboCdmServer
.getItem(selIndex
));
568 protected void updatePort() {
569 txtPort
.setText(""); //$NON-NLS-1$
570 if(selectedServerInfo
!= null) {
571 int port
= selectedServerInfo
.getPort();
572 if(port
== CdmServerInfo
.NULL_PORT
) {
573 txtPort
.setText(CdmServerInfo
.NULL_PORT_STRING
);
575 txtPort
.setText(String
.valueOf(port
));
581 protected int getPort() {
582 int port
= CdmServerInfo
.NULL_PORT
;
584 port
= Integer
.valueOf(txtPort
.getText());
585 } catch (NumberFormatException nfe
) {
586 if(!CdmServerInfo
.NULL_PORT_STRING
.equals(txtPort
.getText())) {
587 setMessage(Messages
.RemotingLoginDialog_MESSAGE_PORT_SHOULD_BE_INTEGER
);
593 private void checkSelectedCdmServer() {
595 if(selectedServerInfo
!= null) {
596 if(selectedServerInfo
.isLocalhost()) {
597 txtPort
.setEditable(true);
598 txtPort
.setEnabled(true);
601 if(selectedServerInfo
.pingServer()) {
602 txtCdmServerStatus
.setText(STATUS_AVAILABLE
);
603 populateCdmInstanceCombo(true);
604 if(selectedServerInfo
.isLocalhost()){
605 setCdmlibVersion(txtServerCdmlibVersion
);
607 String serverVersionTimestamp
= generateLastModifiedTooltip(selectedServerInfo
.getCdmlibLastModified());
608 txtServerCdmlibVersion
.setText(selectedServerInfo
.getCdmlibServicesVersion() + ":" + serverVersionTimestamp
); //$NON-NLS-1$
611 txtCdmServerStatus
.setText(STATUS_NOT_AVAILABLE
);
612 comboCdmInstance
.removeAll();
613 disableCdmInstanceControls("", ""); //$NON-NLS-1$ //$NON-NLS-2$
615 } catch (CdmServerException
| IOException e
) {
616 txtCdmServerStatus
.setText(STATUS_NOT_AVAILABLE
);
617 // TODO distinguish java.net.ConnectException: Connection refused, java.net.SocketTimeoutException: Read timed out
619 if(e
instanceof CdmServerException
&& e
.getCause() != null){
620 cause
= e
.getCause();
622 String message
= Messages
.RemotingLoginDialog_CONNECTION_FAILED_MESSAGE
;
623 if(cause
instanceof SocketTimeoutException
){
624 message
= Messages
.RemotingLoginDialog_CONNECTION_TIMEOUT_MESSAGE
;
626 MessagingUtils
.warningDialog(Messages
.RemotingLoginDialog_CONNECTION_FAILED_TITLE
, this,
628 logger
.warn(Messages
.RemotingLoginDialog_CONNECTION_FAILED_TITLE
, e
);
633 catch(SWTException e
){
634 //catch widget is disposed exception which may occur if
635 //dialog is closed but the runnable tries to update
640 protected void populateCdmInstanceCombo(final boolean forceRefresh
) {
641 comboCdmInstance
.removeAll();
642 comboCdmInstance
.setEnabled(false);
643 btnConnect
.setEnabled(false);
644 txtCdmInstanceStatus
.setText(STATUS_RETRIEVING
);
645 txtCdmInstanceStatus
.setToolTipText(""); //$NON-NLS-1$
647 serverJob
= new Job(Messages
.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES
) {
649 protected IStatus
run(IProgressMonitor monitor
) {
651 if(selectedServerInfo
!= null) {
653 selectedServerInfo
.refreshInstances();
655 final List
<CdmInstanceInfo
> instances
= selectedServerInfo
.getInstances();
656 Display
.getDefault().asyncExec(new Runnable() {
659 if(!instances
.isEmpty()) {
660 for(CdmInstanceInfo cdmInstance
: instances
) {
661 comboCdmInstance
.add(cdmInstance
.getName());
663 int instanceIndex
= -1;
664 if(instanceName
!= null) {
665 instanceIndex
= comboCdmInstance
.indexOf(instanceName
);
667 if(instanceIndex
== -1) {
668 comboCdmInstance
.select(0);
671 comboCdmInstance
.select(instanceIndex
);
673 onRefreshCdmInstance();
674 comboCdmInstance
.setEnabled(true);
679 txtCdmInstanceStatus
.setText(STATUS_NO_INSTANCES
);
680 btnConnect
.setEnabled(false);
685 } catch (final CdmServerException e
) {
686 MessagingUtils
.warn(getClass(), e
);
687 Display
.getDefault().asyncExec(new Runnable() {
690 disableCdmInstanceControls(STATUS_NOT_AVAILABLE
, e
.getMessage());
694 return Status
.OK_STATUS
;
698 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
) && !isDevRemoteSource
) {
700 serverJob
.schedule();
705 public void disableCdmInstanceControls(String cdmInstanceStatus
, String tooltip
) {
706 txtCdmInstanceStatus
.setText(cdmInstanceStatus
);
707 txtCdmInstanceStatus
.setToolTipText(tooltip
);
708 comboCdmInstance
.setEnabled(false);
709 btnConnect
.setEnabled(false);
713 public void onRefreshCdmInstance() {
714 txtCdmInstanceStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
715 clearOnInstanceChange();
716 updateSelectedCdmInstance();
717 checkSelectedCdmInstance();
718 updateManagedServerControls();
722 protected void updateSelectedCdmInstance() {
723 int selIndex
= comboCdmInstance
.getSelectionIndex();
725 selectedCdmInstance
= selectedServerInfo
.getInstanceFromName(comboCdmInstance
.getItem(selIndex
));
727 readPrefCredentials();
732 private void updateManagedServerControls() {
733 if(selectedServerInfo
.isLocalhostMgd()) {
734 if(isSelectedCdmInstanceRunningInManagedServer()) {
735 txtCdmInstanceStatus
.setText(STATUS_STARTED
);
737 txtCdmInstanceStatus
.setText(STATUS_NOT_STARTED
);
739 btnConnect
.setEnabled(true);
740 selectedServerInfo
.setPort(getManagedServerPort());
744 if(isManagedServerRunning()) {
745 btnStopServer
.setEnabled(true);
747 btnStopServer
.setEnabled(false);
751 private boolean isManagedServerRunning() {
752 return CdmStoreLocal
.getManagedServer() != null && CdmStoreLocal
.getManagedServer().isAlive();
755 private boolean isSelectedCdmInstanceRunningInManagedServer() {
756 return CdmStoreLocal
.getManagedServer() != null &&
757 CdmStoreLocal
.getManagedServer().isAlive() &&
758 selectedServerInfo
.isLocalhostMgd() &&
759 CdmStoreLocal
.getManagedServer().getDataSourceName().equals(selectedCdmInstance
.getName());
762 private void startManagedServer() {
763 if(isManagedServerRunning()) {
764 if(CdmStoreLocal
.getManagedServer().getDataSourceName().equals(selectedCdmInstance
.getName())) {
767 Display
.getDefault().syncExec(new Runnable() {
770 onStopManagedServer();
776 boolean forceSchemaCreate
= !schemaExists(selectedCdmInstance
);
777 boolean forceSchemaUpdate
= LABEL_UPDATE_SCHEMA_VERSION
.equals(btnConnect
.getText());
779 Job job
= new Job(Messages
.RemotingLoginDialog_JOB_SERVER_LAUNCH
) {
782 public IStatus
run(IProgressMonitor monitor
) {
783 String mgdServerConfigFileName
= "mgd.datasources.xml"; //$NON-NLS-1$
784 String config
= CdmServerUtils
.convertEditorToServerConfig();
786 monitor
.beginTask(Messages
.RemotingLoginDialog_TASK_LAUNCHING_SERVER
, maxUnits
);
788 monitor
.subTask(String
.format(Messages
.RemotingLoginDialog_GENERATING_CONFIG_FILE
, selectedCdmInstance
.getName()));
789 File managedServerConfigFile
= CdmServerUtils
.writeManagedServerConfig(config
, mgdServerConfigFileName
);
793 CdmServer cdmServer
= new CdmServer(selectedCdmInstance
.getName(), managedServerConfigFile
);
795 // ICdmServer cdmServer = new CdmServer(selectedCdmInstance.getName(), managedServerConfigFile);
796 cdmServer
.setForceSchemaCreate(forceSchemaCreate
);
797 cdmServer
.setForceSchemaUpdate(forceSchemaUpdate
);
798 CdmStoreLocal
.setManagedServer(cdmServer
);
799 monitor
.subTask(Messages
.RemotingLoginDialog_STARTING_MGD_SERVER
);
800 cdmServer
.start(false, RemotingLoginDialogLocal
.this);
803 // the following loop is a 'fake' progress monitoring where the progress
804 // bar is advanced by one unit every second until maxUnits -2
805 while(!CdmStoreLocal
.getManagedServer().isStarted() && !CdmStoreLocal
.getManagedServer().isFailed()) {
806 if(serverUnits
< maxUnits
- 2) {
809 } catch (InterruptedException e
) {
815 Display
.getDefault().syncExec(()->{
817 updateManagedServerControls();
820 } catch (IOException ioe
) {
821 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_GENERATING_CONFIG_FILE
,
824 TaxeditorStorePlugin
.PLUGIN_ID
,
827 } catch (CdmEmbeddedServerException cese
) {
828 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_STARTING_SERVER
,
831 TaxeditorStorePlugin
.PLUGIN_ID
,
837 // NOTE: Errors thrown during server startup are passed to the handleError() implementation
838 // TODO: is the above catch clause for CdmEmbeddedServerException still valuable?
840 return Status
.OK_STATUS
;
845 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);
852 private boolean schemaExists(CdmInstanceInfo instanceInfo
) {
853 if (instanceInfo
.getDataSource() != null){
855 //TODO we need a new method in cdmlib to check for existing schema
856 String schemaVersion
= instanceInfo
.getDataSource().getDbSchemaVersion();
857 return schemaVersion
!= null;
858 } catch (CdmSourceException e
) {
866 private String
managedSchemaVersion(CdmInstanceInfo instanceInfo
) throws CdmSourceException
{
867 if (instanceInfo
.getDataSource() != null){
868 return instanceInfo
.getDataSource().getDbSchemaVersion();
870 throw new RuntimeException("ManagedSchemaVersion only available for managed server instances.");
873 private int compareSchemaVersion(CdmInstanceInfo instanceInfo
) throws CdmSourceException
{
874 return CdmMetaData
.compareVersion(managedSchemaVersion(instanceInfo
), CdmMetaData
.getDbSchemaVersion(), 3, null);
879 public void handleError(final Throwable t
) {
881 Display
.getDefault().syncExec(()-> {
884 String title
= Messages
.RemotingLoginDialog_SERVER_LAUNCH_ERROR
;
885 String message
= t
.getMessage();
887 MessagingUtils
.errorDialog(title
,
890 TaxeditorStorePlugin
.PLUGIN_ID
,
896 private void onStopManagedServer() {
898 CdmStoreLocal
.getManagedServer().stop();
899 } catch (Exception e
) {
900 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_STOPPING_SERVER
,
902 String
.format(Messages
.RemotingLoginDialog_COULD_NOT_STOP_SERVER
, CdmStoreLocal
.getManagedServer().getPort()),
903 TaxeditorStorePlugin
.PLUGIN_ID
,
907 CdmStoreLocal
.setManagedServer(null);
908 updateManagedServerControls();
911 private int getManagedServerPort() {
912 return CdmStoreLocal
.getManagedServer() == null ? CdmServerInfo
.NULL_PORT
: CdmStoreLocal
.getManagedServer().getPort();
916 protected void checkSelectedCdmInstance() {
918 if (selectedServerInfo
.isLocalhostMgd()){
919 checkManagedSelectedInstance();
920 }else if (txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
)) {
922 boolean available
= false;
923 String instanceStatus
= STATUS_NOT_AVAILABLE
;
924 String message
= null;
926 if(selectedServerInfo
.pingInstance(selectedCdmInstance
, getPort())) {
927 instanceStatus
= STATUS_AVAILABLE
;
930 instanceStatus
= STATUS_NOT_AVAILABLE
;
935 txtServerSchemaVersion
.setText(selectedServerInfo
.getCdmRemoteSource(selectedCdmInstance
, getPort()).getDbSchemaVersion());
937 int compareDbSchemaVersion
= selectedServerInfo
.compareDbSchemaVersion(selectedCdmInstance
, getPort());
939 int compareCdmlibServicesVersion
= 0;
940 boolean disableServicesApiTimestampCheck
=
941 PreferencesUtil
.getBooleanValue((IPreferenceKeys
.DISABLE_SERVICES_API_TIMESTAMP_CHECK
));
942 if(!disableServicesApiTimestampCheck
) {
943 compareCdmlibServicesVersion
= selectedServerInfo
.compareCdmlibServicesVersion();
946 if(compareDbSchemaVersion
> 0 || compareCdmlibServicesVersion
> 0) {
947 instanceStatus
= STATUS_NOT_COMPATIBLE
;
949 message
= MESG_COMPATIBLE_EDITOR_OLD
;
950 } else if(compareDbSchemaVersion
< 0 || compareCdmlibServicesVersion
< 0) {
951 instanceStatus
= STATUS_NOT_COMPATIBLE
;
953 message
= MESG_COMPATIBLE_SERVER_OLD
;
955 instanceStatus
= STATUS_AVAILABLE
;
957 message
= ""; //$NON-NLS-1$
960 } catch (Exception e
) {
961 txtCdmInstanceStatus
.setToolTipText(e
.getMessage());
963 lblDefaultLogin
.setVisible(false);
964 btnConnect
.setEnabled(available
);
965 txtCdmInstanceStatus
.setText(instanceStatus
);
966 if(!StringUtils
.isBlank(message
)) {
973 private void checkManagedSelectedInstance() {
974 boolean available
= false;
975 String instanceStatus
= STATUS_NOT_AVAILABLE
;
976 String message
= null;
977 String connect
= LABEL_CONNECT
;
978 Integer color
= null;
979 String schemaVersion
= CdmMetaData
.getDbSchemaVersion();
981 if (!schemaExists(selectedCdmInstance
)){
982 message
= MESG_SCHEMA_MISSING
;
983 connect
= LABEL_CREATE_SCHEMA
;
984 color
= BTN_COLOR_ATTENTION
;
985 schemaVersion
= MESG_NO_SCHEMA
;
989 schemaVersion
= managedSchemaVersion(selectedCdmInstance
);
990 compare
= compareSchemaVersion(selectedCdmInstance
);
992 instanceStatus
= STATUS_NOT_COMPATIBLE
;
993 message
= MESG_COMPATIBLE_EDITOR_OLD
;
995 }else if (compare
< 0){
996 instanceStatus
= STATUS_NOT_COMPATIBLE
;
997 message
= MESG_UPDATE_SCHEMA_VERSION
;
999 connect
= LABEL_UPDATE_SCHEMA_VERSION
;
1000 color
= BTN_COLOR_ATTENTION
;
1003 instanceStatus
= STATUS_AVAILABLE
;
1005 } catch (CdmSourceException e
) {
1010 setManagedValues(available
, instanceStatus
, connect
, color
, schemaVersion
);
1011 setMessage(message
);
1014 private void setManagedValues(boolean available
, String instanceStatus
, String connect
, Integer color
,
1015 String schemaVersion
) {
1016 Display
.getDefault().syncExec(()->{
1017 btnConnect
.setEnabled(available
);
1018 btnConnect
.setText(connect
);
1019 Color systemColor
= null;
1021 systemColor
= Display
.getCurrent().getSystemColor(color
);
1023 btnConnect
.setBackground(systemColor
);
1024 btnConnect
.requestLayout();
1025 txtCdmInstanceStatus
.setText(instanceStatus
);
1026 txtServerSchemaVersion
.setText(schemaVersion
);
1027 lblDefaultLogin
.setVisible(true);
1032 public void connect() {
1033 checkSelectedCdmInstance();
1035 if(!txtCdmInstanceStatus
.getText().equals(STATUS_AVAILABLE
)) {
1039 ICdmRemoteSource source
= selectedServerInfo
.getCdmRemoteSource(selectedCdmInstance
, getPort());
1041 if(!validateLogin(source
)) {
1046 CdmStoreLocal
.connect(source
, RemotingLoginDialogLocal
.this);
1047 } catch (Exception e
) {
1048 // Do not expect anything to go wrong at this point, so we throw a runtime exception
1050 throw new RuntimeException(e
);
1056 public boolean isRememberMe() {
1057 return btnRememberMe
.getSelection();
1060 private void persistPrefLastServerInstance() {
1061 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
1062 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
1064 lastServerInstancePrefs
.put(LAST_SERVER_KEY
, selectedServerInfo
.getName());
1065 lastServerInstancePrefs
.put(LAST_INSTANCE_KEY
, selectedCdmInstance
.getName());
1067 flushPreferences(lastServerInstancePrefs
);
1070 private void persistPrefCredentials() {
1071 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
1072 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
1073 credentialsPrefs
.put(getUsernamePrefKey(), txtLogin
.getText());
1074 credentialsPrefs
.put(getPasswordPrefKey(), txtPassword
.getText());
1075 flushPreferences(credentialsPrefs
);
1078 private void removePrefCredentials() {
1079 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
1080 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
1081 credentialsPrefs
.put(getUsernamePrefKey(), txtLogin
.getText());
1082 credentialsPrefs
.put(getPasswordPrefKey(), txtPassword
.getText());
1083 removePreferences(credentialsPrefs
);
1086 private void removePreferences(Preferences prefs
) {
1089 } catch (BackingStoreException bse
) {
1090 setMessage(bse
.getMessage());
1094 private void flushPreferences(Preferences prefs
) {
1097 } catch (BackingStoreException bse
) {
1098 setMessage(bse
.getMessage());
1103 protected void readPrefCredentials() {
1104 String username
, password
;
1105 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
1106 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
1107 username
= credentialsPrefs
.get(getUsernamePrefKey(), ""); //$NON-NLS-1$
1108 txtLogin
.setText(username
);
1109 password
= credentialsPrefs
.get(getPasswordPrefKey(),""); //$NON-NLS-1$
1110 txtPassword
.setText(password
);
1111 if(username
.isEmpty() || password
.isEmpty()) {
1112 autoConnect
= false;
1116 private void readPrefLastServerInstance() {
1117 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
1118 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
1120 serverName
= lastServerInstancePrefs
.get(LAST_SERVER_KEY
, null);
1121 instanceName
= lastServerInstancePrefs
.get(LAST_INSTANCE_KEY
, null);
1124 private void emptyCredentials() {
1125 txtLogin
.setText(""); //$NON-NLS-1$
1126 txtPassword
.setText(""); //$NON-NLS-1$
1129 private String
getUsernamePrefKey() {
1130 return selectedServerInfo
.toString(selectedCdmInstance
.getName(), isDevRemoteSource?
getPort():-1) + USERNAME_SUFFIX
;
1133 private String
getPasswordPrefKey() {
1134 return selectedServerInfo
.toString(selectedCdmInstance
.getName(), isDevRemoteSource?
getPort():-1) + PASSWORD_SUFFIX
;
1137 private boolean validateLogin(ICdmRemoteSource remoteSource
) {
1138 if(getUsername() == null || getUsername().isEmpty()) {
1139 setMessage(Messages
.RemotingLoginDialog_LOGIN_CANNOT_BE_EMPTY
);
1142 if(getPassword() == null || getPassword().isEmpty()) {
1143 setMessage(Messages
.RemotingLoginDialog_PASSWORD_CANNOT_BE_EMPTY
);
1148 IUserService userService
= CdmApplicationRemoteConfiguration
.getUserService(remoteSource
);
1149 UsernamePasswordAuthenticationToken token
= new UsernamePasswordAuthenticationToken(getUsername(), getPassword());
1150 CdmApplicationRemoteConfiguration
.getAuthenticationManager(userService
).authenticate(token
);
1151 } catch(BadCredentialsException e
){
1152 setMessage(LoginManager
.INCORRECT_CREDENTIALS_MESSAGE
);
1154 } catch(LockedException e
){
1155 setMessage(LoginManager
.ACCOUNT_LOCKED_MESSAGE
);
1157 } catch(IllegalArgumentException e
){
1158 setMessage(LoginManager
.INCORRECT_CREDENTIALS_MESSAGE
);
1166 public String
getUsername() {
1167 return txtLogin
.getText();
1172 public String
getPassword() {
1173 return txtPassword
.getText();
1178 public void setMessage(String message
) {
1179 if(CdmUtils
.isNotBlank(message
)) {
1180 // if(message.length() > 50) {
1181 // styledTxtMessage.setToolTipText(message);
1182 // message = message.substring(0,50) + "..."; //$NON-NLS-1$
1184 styledTxtMessage
.setText(message
);
1185 styledTxtMessage
.setVisible(true);
1186 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= false;
1187 // shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
1188 shlConnect
.pack(true);
1190 if (!styledTxtMessage
.isDisposed()){
1191 styledTxtMessage
.setText(""); //$NON-NLS-1$
1192 styledTxtMessage
.setVisible(false);
1193 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= true;
1195 if(!shlConnect
.isDisposed()){
1196 shlConnect
.pack(true);
1199 if (!remotingComposite
.isDisposed()){
1200 remotingComposite
.layout();
1204 // private int getHeightWithoutMessage() {
1205 // if(xpndblcmpstAdvanced.isExpanded()) {
1206 // return MIN_EXP_HEIGHT;
1208 // return MIN_HEIGHT;
1213 public void hide(boolean isHidden
) {
1214 if (!shlConnect
.isDisposed()){
1215 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
1216 shlConnect
.setVisible(!isHidden
);
1223 public void dispose() {
1224 if (!shlConnect
.isDisposed()){
1225 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
1226 shlConnect
.dispose();
1233 public void onComplete() {
1234 Display
.getDefault().asyncExec(new Runnable() {
1237 if(selectedCdmInstance
!=null){
1238 if(isRememberMe()) {
1239 persistPrefCredentials();
1241 removePrefCredentials();
1243 persistPrefLastServerInstance();
1250 private String
generateLastModifiedTooltip(String cdmlibLastModified
) {
1251 if(StringUtils
.isBlank(cdmlibLastModified
)) {
1252 return ""; //$NON-NLS-1$
1254 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy.MM.dd.HH.mm.z"); //$NON-NLS-1$
1255 Date cdmlibLastModifiedDate
;
1256 String cdmlibLastModifiedTimestamp
= ""; //$NON-NLS-1$
1258 cdmlibLastModifiedDate
= new Date(Long
.valueOf(cdmlibLastModified
));
1259 cdmlibLastModifiedTimestamp
= sdf
.format(cdmlibLastModifiedDate
);
1261 return cdmlibLastModifiedTimestamp
;
1264 private void setEditorInfo() {
1265 txtEditorCdmVersion
.setText(CdmMetaData
.getDbSchemaVersion());
1266 setCdmlibVersion(txtEditorCdmlibVersion
);
1269 private void setCdmlibVersion(Text txt
) {
1270 String editorVersionTimestamp
= generateLastModifiedTooltip(CdmApplicationState
.getCdmlibLastModified());
1271 txt
.setText(CdmApplicationState
.getCdmlibVersion() + ":" + editorVersionTimestamp
); //$NON-NLS-1$
1274 private void clearOnServerChange() {
1275 setMessage(""); //$NON-NLS-1$
1276 txtServerSchemaVersion
.setText(""); //$NON-NLS-1$
1277 txtServerCdmlibVersion
.setText(""); //$NON-NLS-1$
1278 txtServerCdmlibVersion
.setToolTipText(""); //$NON-NLS-1$
1279 txtServerSchemaVersion
.setText(""); //$NON-NLS-1$
1280 comboCdmInstance
.removeAll();
1281 txtCdmInstanceStatus
.setText(""); //$NON-NLS-1$
1282 txtPort
.setEditable(false);
1283 txtPort
.setEnabled(false);
1286 private void clearOnInstanceChange() {
1287 setMessage(""); //$NON-NLS-1$
1288 txtServerSchemaVersion
.setText(""); //$NON-NLS-1$
1289 btnConnect
.setText(LABEL_CONNECT
);
1290 btnConnect
.setBackground(null);
1291 btnConnect
.requestLayout();
1294 @SuppressWarnings("unused") //in work, for future centralized handling of control's status
1295 private void updateControls(){
1298 // comboCdmServer; //nothing to change
1299 String strServerStatus
= this.selectedServerInfo
!= null? STATUS_NOT_AVAILABLE
: STATUS_AVAILABLE
;
1300 txtCdmServerStatus
.setText(strServerStatus
);
1301 // btnCdmServerRefresh; //nothing to change
1305 String strInstanceStatus
= this.selectedCdmInstance
!= null? STATUS_NOT_AVAILABLE
: STATUS_AVAILABLE
;
1306 txtCdmInstanceStatus
.setText(strInstanceStatus
);
1307 // btnCdmInstanceRefresh; //nothing to change
1310 txtLogin
.setText(Nz(login
));
1311 txtPassword
.setText(Nz(password
));
1312 btnConnect
.setText(LABEL_CONNECT
); //TODO
1313 btnConnect
.setEnabled(true);
1315 //rememberMe + defaultValues
1320 // styledTxtMessage;
1326 // txtServerCdmlibVersion;
1327 // txtEditorCdmlibVersion;
1328 // txtServerSchemaVersion;
1329 // txtEditorCdmVersion;
1332 private String
Nz(String value
) {
1333 return CdmUtils
.Nz(value
);