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
.logging
.log4j
.LogManager
;import org
.apache
.logging
.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
;
88 public class RemotingLoginDialogLocal
extends RemotingLoginDialog
{
90 private Logger logger
= LogManager
.getLogger(getClass());
92 // protected Shell shlConnect;
93 // private Text txtCdmServerStatus;
94 // private Text txtCdmInstanceStatus;
96 // private Button btnConnect;
98 // private Composite remotingComposite;
99 // private Button btnCdmServerRefresh;
100 // private Button btnCdmInstanceRefresh;
101 // private Button btnStopServer;
102 // private Composite loginComposite;
103 // private Label lblLogin;
104 // private Text txtLogin;
105 // private Label lblPassword;
106 // private Text txtPassword;
107 // private Button btnRememberMe;
108 // private Label lblDefaultLogin;
109 // private Composite compAdvanced;
110 // private Label lblPort;
111 // private Text txtPort;
112 // private Label lblServerCdmlibVersion;
113 // private Text txtServerCdmlibVersion;
114 // private ExpandableComposite expandableCompositeAdvanced;
115 // private StyledText styledTxtMessage;
117 // private Label lblEditorCdmlibVersion;
118 // private Text txtEditorCdmlibVersion;
119 // private Label lblServerSchemaVersion;
120 // private Text txtServerSchemaVersion;
121 // private Label lblEditorCdmVersion;
122 // private Text txtEditorCdmVersion;
124 // private final int MESSAGE_HEIGHT = 50;
125 // private final int COMBO_MIN_WIDTH =200;
126 // private final int CONTROLS_MIN_HEIGHT = 23; //does not seem to work yet
127 //// private final int MIN_EXP_HEIGHT = 380;
129 // private boolean autoConnect = false;
130 // private boolean loadLoginPrefs = true;
131 // private boolean isDevRemoteSource = false;
133 // private Job serverJob;
134 // protected Object result;
136 // private final Map<String, CdmServerInfo> serverInfoMap = new HashMap<>();
138 // private String serverName;
139 // private String instanceName;
140 // private CdmServerInfo selectedServerInfo;
141 // private CdmInstanceInfo selectedCdmInstance;
142 // private String login;
143 // private String password;
150 public RemotingLoginDialogLocal(Shell parent
, int style
) {
151 super(parent
, style
);
152 setText(Messages
.RemotingLoginDialog_LABEL_LOGIN
);
158 public Object
open(ICdmRemoteSource source
, boolean loadLoginPrefs
, boolean autoConnect
) {
159 this.loadLoginPrefs
= loadLoginPrefs
;
160 this.serverName
= source
.getName();
161 if (source
instanceof CdmRemoteLocalhostSource
){
162 this.instanceName
= ((CdmRemoteLocalhostSource
)source
).getDatasourceName();
164 String contextPath
= source
.getContext();
165 this.instanceName
= contextPath
== null?
"" : contextPath
.substring(contextPath
.lastIndexOf("/") + 1); //$NON-NLS-1$
167 return open(serverName
, instanceName
, loadLoginPrefs
, autoConnect
);
172 public Object
open(String serverName
, String instanceName
, boolean loadLoginPrefs
, boolean autoConnect
) {
173 this.serverName
= serverName
;
174 this.instanceName
= instanceName
;
175 this.loadLoginPrefs
= loadLoginPrefs
;
176 this.autoConnect
= autoConnect
;
182 * @return the dialog result
186 public Object
open() {
189 if(serverName
== null && instanceName
== null) {
190 readPrefLastServerInstance();
192 expandableCompositeAdvanced
.setExpanded(false);
195 populateCdmServerCombo();
196 shlConnect
.pack(true);
201 Display display
= getParent().getDisplay();
202 while (!shlConnect
.isDisposed()) {
203 if (!display
.isDisposed()){
204 if (!display
.readAndDispatch()) {
213 * Create contents of the dialog.
216 protected void createContents() {
217 shlConnect
= new Shell(getParent(), SWT
.DIALOG_TRIM
| SWT
.APPLICATION_MODAL
| SWT
.RESIZE
| SWT
.CENTER
);
218 shlConnect
.setText(LABEL_CONNECT
);
219 shlConnect
.setLayout(new FillLayout(SWT
.HORIZONTAL
));
221 remotingComposite
= new Composite(shlConnect
, SWT
.NONE
);
222 remotingComposite
.setLayout(new GridLayout(1, false));
225 Composite cdmServerComposite
= new Composite(remotingComposite
, SWT
.NONE
);
226 GridData gd_cdmServerComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
227 cdmServerComposite
.setLayoutData(gd_cdmServerComposite
);
228 cdmServerComposite
.setLayout(new GridLayout(4, false));
230 Label lblCdmServer
= new Label(cdmServerComposite
, SWT
.NONE
);
231 lblCdmServer
.setText(Messages
.RemotingLoginDialog_LABEL_CDM_SERVER
);
232 lblCdmServer
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
234 comboCdmServer
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
235 comboCdmServer
.addSelectionListener(new SelectionAdapter() {
237 public void widgetSelected(SelectionEvent e
) {
238 onRefreshCdmServer();
242 GridData gd_comboCdmServer
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, true, 1, 1);
244 comboCdmServer
.setLayoutData(gd_comboCdmServer
);
245 comboCdmServer
.select(0);
247 txtCdmServerStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
248 txtCdmServerStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
249 txtCdmServerStatus
.setEditable(false);
250 GridData gd_txtCdmServerStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, true, 1, 1);
251 gd_txtCdmServerStatus
.minimumHeight
= CONTROLS_MIN_HEIGHT
;
252 txtCdmServerStatus
.setLayoutData(gd_txtCdmServerStatus
);
254 btnCdmServerRefresh
= new Button(cdmServerComposite
, SWT
.NONE
);
255 btnCdmServerRefresh
.addSelectionListener(new SelectionAdapter() {
257 public void widgetSelected(SelectionEvent e
) {
258 onRefreshCdmServer();
261 GridData gd_btnCdmServerRefresh
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, true, 1, 1);
262 gd_btnCdmServerRefresh
.minimumHeight
= CONTROLS_MIN_HEIGHT
;
263 btnCdmServerRefresh
.setLayoutData(gd_btnCdmServerRefresh
);
264 btnCdmServerRefresh
.setText(Messages
.RemotingLoginDialog_LABEL_REFRESH
);
267 Label lblCdmInstance
= new Label(cdmServerComposite
, SWT
.NONE
);
268 GridData gd_lblCdmInstance
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, true, 1, 1);
269 //gd_lblCdmInstance.heightHint = 30;
270 lblCdmInstance
.setLayoutData(gd_lblCdmInstance
);
271 lblCdmInstance
.setText(Messages
.RemotingLoginDialog_LABEL_CDM_INSTANCE
);
273 comboCdmInstance
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
274 comboCdmInstance
.addSelectionListener(new SelectionAdapter() {
276 public void widgetSelected(SelectionEvent e
) {
277 onRefreshCdmInstance();
281 GridData gd_comboCdmInstance
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 1);
282 gd_comboCdmInstance
.minimumWidth
= COMBO_MIN_WIDTH
;
284 comboCdmInstance
.setLayoutData(gd_comboCdmInstance
);
285 comboCdmInstance
.select(0);
287 txtCdmInstanceStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
288 txtCdmInstanceStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
289 txtCdmInstanceStatus
.setEditable(false);
290 GridData gd_txtCdmInstanceStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, true, 1, 1);
291 gd_txtCdmInstanceStatus
.minimumHeight
= CONTROLS_MIN_HEIGHT
;
292 txtCdmInstanceStatus
.setLayoutData(gd_txtCdmInstanceStatus
);
294 btnCdmInstanceRefresh
= new Button(cdmServerComposite
, SWT
.FLAT
);
295 btnCdmInstanceRefresh
.addSelectionListener(new SelectionAdapter() {
297 public void widgetSelected(SelectionEvent e
) {
298 onRefreshCdmInstance();
301 GridData gd_btnCdmInstanceRefresh
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 1);
302 gd_btnCdmInstanceRefresh
.minimumHeight
= CONTROLS_MIN_HEIGHT
;
303 btnCdmInstanceRefresh
.setLayoutData(gd_btnCdmInstanceRefresh
);
304 btnCdmInstanceRefresh
.setText(Messages
.RemotingLoginDialog_LABEL_REFRESH
);
307 loginComposite
= new Composite(remotingComposite
, SWT
.NONE
);
308 GridData gd_loginComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
309 loginComposite
.setLayoutData(gd_loginComposite
);
310 GridLayout gl_loginComposite
= new GridLayout(6, false);
311 gl_loginComposite
.marginTop
= 5;
312 loginComposite
.setLayout(gl_loginComposite
);
314 lblLogin
= new Label(loginComposite
, SWT
.CENTER
);
315 GridData gd_lblLogin
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
316 lblLogin
.setLayoutData(gd_lblLogin
);
317 lblLogin
.setText(Messages
.RemotingLoginDialog_LABEL_LOGIN_COLON
);
319 txtLogin
= new Text(loginComposite
, SWT
.BORDER
);
320 GridData gd_txtLogin
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
321 gd_txtLogin
.minimumWidth
= 80;
322 txtLogin
.setLayoutData(gd_txtLogin
);
324 lblPassword
= new Label(loginComposite
, SWT
.CENTER
);
325 lblPassword
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
326 lblPassword
.setText(Messages
.RemotingLoginDialog_LABEL_PASSWORD
);
328 txtPassword
= new Text(loginComposite
, SWT
.BORDER
| SWT
.PASSWORD
);
329 GridData gd_txtPassword
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
330 gd_txtPassword
.minimumWidth
= 80;
331 txtPassword
.setLayoutData(gd_txtPassword
);
332 @SuppressWarnings("unused")
333 Label nope
= new Label(loginComposite
, SWT
.NONE
);
334 txtPassword
.addKeyListener(new KeyAdapter() {
336 public void keyPressed(KeyEvent e
) {
337 if(e
.character
==SWT
.CR
){
338 if(btnConnect
.getText().equals(LABEL_CONNECT
)){
339 onConnectButtonPressed();
345 btnConnect
= new Button(loginComposite
, SWT
.FLAT
);
346 btnConnect
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1));
347 btnConnect
.addSelectionListener(new SelectionAdapter() {
349 public void widgetSelected(SelectionEvent e
) {
350 onConnectButtonPressed();
353 btnConnect
.setText(LABEL_CONNECT
);
355 //rememberMe + default values
356 btnRememberMe
= new Button(loginComposite
, SWT
.CHECK
);
357 btnRememberMe
.setSelection(true);
358 GridData gd_btnRememberMe
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 2, 1);
359 btnRememberMe
.setLayoutData(gd_btnRememberMe
);
360 btnRememberMe
.setText(Messages
.RemotingLoginDialog_LABEL_REMEMBER_ME
);
362 lblDefaultLogin
= new Label(loginComposite
, SWT
.NONE
);
363 GridDataFactory
.fillDefaults().span(4, 1).align(SWT
.TRAIL
, SWT
.CENTER
).applyTo(lblDefaultLogin
);
364 lblDefaultLogin
.setText(String
.format(Messages
.RemotingLoginDialog_DEFAULT_LOGIN
, DEFAULT_USER
, DEFAULT_PASS
));
365 lblDefaultLogin
.setVisible(false);
367 styledTxtMessage
= new StyledText(remotingComposite
, SWT
.NONE
);
368 styledTxtMessage
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
369 styledTxtMessage
.setForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
370 styledTxtMessage
.setSelectionBackground(SWTResourceManager
.getColor(SWT
.COLOR_LIST_SELECTION_TEXT
));
371 styledTxtMessage
.setSelectionForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
372 styledTxtMessage
.setDoubleClickEnabled(false);
373 styledTxtMessage
.setEditable(false);
374 styledTxtMessage
.setWordWrap(true);
376 GridData gd_styledTxtMessage
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
377 gd_styledTxtMessage
.exclude
= true;
378 gd_styledTxtMessage
.minimumHeight
= MESSAGE_HEIGHT
;
380 styledTxtMessage
.setLayoutData(gd_styledTxtMessage
);
383 expandableCompositeAdvanced
= new ExpandableComposite(remotingComposite
, SWT
.NONE
, ExpandableComposite
.TWISTIE
);
384 GridData gd_xpndblcmpstAdvanced
= new GridData(SWT
.FILL
, SWT
.FILL
, false, true, 1, 1);
385 expandableCompositeAdvanced
.setLayoutData(gd_xpndblcmpstAdvanced
);
386 expandableCompositeAdvanced
.addExpansionListener(new IExpansionListener() {
388 public void expansionStateChanged(ExpansionEvent e
) {
389 shlConnect
.pack(true);
392 public void expansionStateChanging(ExpansionEvent e
) {
395 expandableCompositeAdvanced
.setText(Messages
.RemotingLoginDialog_LABEL_ADVANCED
);
396 expandableCompositeAdvanced
.setExpanded(true);
398 compAdvanced
= new Composite(expandableCompositeAdvanced
, SWT
.NONE
);
399 expandableCompositeAdvanced
.setClient(compAdvanced
);
400 compAdvanced
.setLayout(new GridLayout(4, false));
402 lblPort
= new Label(compAdvanced
, SWT
.CENTER
);
403 lblPort
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
404 lblPort
.setText(Messages
.RemotingLoginDialog_LABEL_PORT
);
406 txtPort
= new Text(compAdvanced
, SWT
.BORDER
);
407 GridData gd_txtPort
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1);
408 gd_txtPort
.minimumWidth
= 50;
409 txtPort
.setLayoutData(gd_txtPort
);
411 lblServerCdmlibVersion
= new Label(compAdvanced
, SWT
.CENTER
);
412 lblServerCdmlibVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
413 lblServerCdmlibVersion
.setText(Messages
.RemotingLoginDialog_LABEL_SERVER_CDMLIB_VERSION
);
415 txtServerCdmlibVersion
= new Text(compAdvanced
, SWT
.BORDER
);
416 txtServerCdmlibVersion
.setEditable(false);
417 txtServerCdmlibVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
419 btnStopServer
= new Button(compAdvanced
, SWT
.FLAT
);
420 btnStopServer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 2, 1));
421 btnStopServer
.addMouseListener(new MouseAdapter() {
423 public void mouseUp(MouseEvent e
) {
424 onStopManagedServer();
427 btnStopServer
.setText(Messages
.RemotingLoginDialog_LABEL_STOP_MANAGED_SERVER
);
429 lblEditorCdmlibVersion
= new Label(compAdvanced
, SWT
.CENTER
);
430 lblEditorCdmlibVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
431 lblEditorCdmlibVersion
.setText(Messages
.RemotingLoginDialog_LABEL_EDITOR_CDMLIB_VERSION
);
433 txtEditorCdmlibVersion
= new Text(compAdvanced
, SWT
.BORDER
);
434 txtEditorCdmlibVersion
.setEditable(false);
435 txtEditorCdmlibVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
438 lblServerSchemaVersion
= new Label(compAdvanced
, SWT
.CENTER
);
439 lblServerSchemaVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
440 lblServerSchemaVersion
.setText(Messages
.RemotingLoginDialog_LABEL_SERVER_CDM_VERSION
);
442 txtServerSchemaVersion
= new Text(compAdvanced
, SWT
.BORDER
);
443 txtServerSchemaVersion
.setEditable(false);
444 txtServerSchemaVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
447 lblEditorCdmVersion
= new Label(compAdvanced
, SWT
.CENTER
);
448 lblEditorCdmVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
449 lblEditorCdmVersion
.setText(Messages
.RemotingLoginDialog_LABEL_EDITOR_CDM_VERSION
);
451 txtEditorCdmVersion
= new Text(compAdvanced
, SWT
.BORDER
);
452 txtEditorCdmVersion
.setEditable(false);
453 txtEditorCdmVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
458 public void setCenterPoint() {
459 Rectangle parentSize
= getParent().getBounds();
460 Rectangle shellSize
= shlConnect
.getBounds();
461 int locationX
= (parentSize
.width
- shellSize
.width
)/2+parentSize
.x
;
462 int locationY
= (parentSize
.height
- shellSize
.height
)/2+parentSize
.y
;
463 shlConnect
.setLocation(new Point(locationX
, locationY
));
472 @SuppressWarnings("unused")
473 private void addEmptyCells(int cnt
) {
474 for (int i
= 0; i
< cnt
; i
++) {
475 new Label(compAdvanced
, SWT
.NONE
);
480 protected void onConnectButtonPressed() {
481 if(selectedServerInfo
.isLocalhostMgd() && !isSelectedCdmInstanceRunningInManagedServer()) {
482 startManagedServer();
485 if (CdmStore
.isActive() && CdmStore
.currentAuthentiationHasOneOfRoles(Role
.ROLE_REMOTING
)){
486 PreferencesUtil
.setNomenclaturalCodePreferences();
491 // private void populateCdmServerCombo() {
492 // Job job = new Job(Messages.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES) {
494 // protected IStatus run(IProgressMonitor monitor) {
495 // Display.getDefault().syncExec(new Runnable() {
497 // public void run() {
498 // //TODO performance
499 // for(CdmServerInfo csii : CdmServerInfo.getCdmServers(true)) {
500 // serverInfoMap.put(csii.getName(), csii);
501 // comboCdmServer.add(csii.getName());
503 // int serverIndex = -1;
504 // if(serverName != null) {
505 // serverIndex = comboCdmServer.indexOf(serverName);
507 // if(serverIndex == -1) {
508 // comboCdmServer.select(0);
509 // autoConnect = false;
511 // comboCdmServer.select(serverIndex);
513 // ICdmSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
514 // if(devRemoteSource != null) {
515 // isDevRemoteSource = true;
516 // String username = System.getProperty("cdm.server.dev.username"); //$NON-NLS-1$
517 // String password = System.getProperty("cdm.server.dev.password"); //$NON-NLS-1$
518 // if(username != null && !username.isEmpty() && password != null && !password.isEmpty()) {
519 // txtLogin.setText(username);
520 // txtPassword.setText(password);
521 // CdmStoreLocal.connect(devRemoteSource, RemotingLoginDialogLocal.this);
524 // onRefreshCdmServer();
528 // return Status.OK_STATUS;
535 public void onRefreshCdmServer() {
537 txtCdmServerStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
538 clearOnServerChange();
540 updateSelectedCdmServer();
541 Display
.getDefault().asyncExec(new Runnable() {
544 checkSelectedCdmServer();
548 catch(SWTException e
){
549 //catch widget is disposed exception which may occur if
550 //dialog is closed but the runnable tries to update
555 protected void updateSelectedCdmServer() {
556 int selIndex
= comboCdmServer
.getSelectionIndex();
558 selectedServerInfo
= serverInfoMap
.get(comboCdmServer
.getItem(selIndex
));
563 protected void updatePort() {
564 txtPort
.setText(""); //$NON-NLS-1$
565 if(selectedServerInfo
!= null) {
566 int port
= selectedServerInfo
.getPort();
567 if(port
== CdmServerInfo
.NULL_PORT
) {
568 txtPort
.setText(CdmServerInfo
.NULL_PORT_STRING
);
570 txtPort
.setText(String
.valueOf(port
));
576 protected int getPort() {
577 int port
= CdmServerInfo
.NULL_PORT
;
579 port
= Integer
.valueOf(txtPort
.getText());
580 } catch (NumberFormatException nfe
) {
581 if(!CdmServerInfo
.NULL_PORT_STRING
.equals(txtPort
.getText())) {
582 setMessage(Messages
.RemotingLoginDialog_MESSAGE_PORT_SHOULD_BE_INTEGER
);
588 private void checkSelectedCdmServer() {
590 if(selectedServerInfo
!= null) {
591 if(selectedServerInfo
.isLocalhost()) {
592 txtPort
.setEditable(true);
593 txtPort
.setEnabled(true);
596 if(selectedServerInfo
.pingServer()) {
597 txtCdmServerStatus
.setText(STATUS_AVAILABLE
);
598 populateCdmInstanceCombo(true);
599 if(selectedServerInfo
.isLocalhost()){
600 setCdmlibVersion(txtServerCdmlibVersion
);
602 String serverVersionTimestamp
= generateLastModifiedTooltip(selectedServerInfo
.getCdmlibLastModified());
603 txtServerCdmlibVersion
.setText(selectedServerInfo
.getCdmlibServicesVersion() + ":" + serverVersionTimestamp
); //$NON-NLS-1$
606 txtCdmServerStatus
.setText(STATUS_NOT_AVAILABLE
);
607 comboCdmInstance
.removeAll();
608 disableCdmInstanceControls("", ""); //$NON-NLS-1$ //$NON-NLS-2$
610 } catch (CdmServerException
| IOException e
) {
611 txtCdmServerStatus
.setText(STATUS_NOT_AVAILABLE
);
612 // TODO distinguish java.net.ConnectException: Connection refused, java.net.SocketTimeoutException: Read timed out
614 if(e
instanceof CdmServerException
&& e
.getCause() != null){
615 cause
= e
.getCause();
617 String message
= Messages
.RemotingLoginDialog_CONNECTION_FAILED_MESSAGE
;
618 if(cause
instanceof SocketTimeoutException
){
619 message
= Messages
.RemotingLoginDialog_CONNECTION_TIMEOUT_MESSAGE
;
621 MessagingUtils
.warningDialog(Messages
.RemotingLoginDialog_CONNECTION_FAILED_TITLE
, this,
623 logger
.warn(Messages
.RemotingLoginDialog_CONNECTION_FAILED_TITLE
, e
);
628 catch(SWTException e
){
629 //catch widget is disposed exception which may occur if
630 //dialog is closed but the runnable tries to update
635 protected void populateCdmInstanceCombo(final boolean forceRefresh
) {
636 comboCdmInstance
.removeAll();
637 comboCdmInstance
.setEnabled(false);
638 btnConnect
.setEnabled(false);
639 txtCdmInstanceStatus
.setText(STATUS_RETRIEVING
);
640 txtCdmInstanceStatus
.setToolTipText(""); //$NON-NLS-1$
642 serverJob
= new Job(Messages
.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES
) {
644 protected IStatus
run(IProgressMonitor monitor
) {
646 if(selectedServerInfo
!= null) {
648 selectedServerInfo
.refreshInstances();
650 final List
<CdmInstanceInfo
> instances
= selectedServerInfo
.getInstances();
651 Display
.getDefault().asyncExec(()->{
652 if(!instances
.isEmpty()) {
653 for(CdmInstanceInfo cdmInstance
: instances
) {
654 comboCdmInstance
.add(cdmInstance
.getName());
656 int instanceIndex
= -1;
657 if(instanceName
!= null) {
658 instanceIndex
= comboCdmInstance
.indexOf(instanceName
);
660 if(instanceIndex
== -1) {
661 comboCdmInstance
.select(0);
664 comboCdmInstance
.select(instanceIndex
);
666 onRefreshCdmInstance();
667 comboCdmInstance
.setEnabled(true);
672 txtCdmInstanceStatus
.setText(STATUS_NO_INSTANCES
);
673 btnConnect
.setEnabled(false);
677 } catch (final CdmServerException e
) {
678 MessagingUtils
.warn(getClass(), e
);
679 Display
.getDefault().asyncExec(new Runnable() {
682 disableCdmInstanceControls(STATUS_NOT_AVAILABLE
, e
.getMessage());
686 return Status
.OK_STATUS
;
690 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
) && !isDevRemoteSource
) {
692 serverJob
.schedule();
697 public void disableCdmInstanceControls(String cdmInstanceStatus
, String tooltip
) {
698 txtCdmInstanceStatus
.setText(cdmInstanceStatus
);
699 txtCdmInstanceStatus
.setToolTipText(tooltip
);
700 comboCdmInstance
.setEnabled(false);
701 btnConnect
.setEnabled(false);
705 public void onRefreshCdmInstance() {
706 txtCdmInstanceStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
707 clearOnInstanceChange();
708 updateSelectedCdmInstance();
709 checkSelectedCdmInstance();
710 updateManagedServerControls();
714 protected void updateSelectedCdmInstance() {
715 int selIndex
= comboCdmInstance
.getSelectionIndex();
717 selectedCdmInstance
= selectedServerInfo
.getInstanceFromName(comboCdmInstance
.getItem(selIndex
));
719 readPrefCredentials();
724 private void updateManagedServerControls() {
725 if(selectedServerInfo
.isLocalhostMgd()) {
726 if(isSelectedCdmInstanceRunningInManagedServer()) {
727 txtCdmInstanceStatus
.setText(STATUS_STARTED
);
729 txtCdmInstanceStatus
.setText(STATUS_NOT_STARTED
);
731 btnConnect
.setEnabled(true);
732 selectedServerInfo
.setPort(getManagedServerPort());
736 if(isManagedServerRunning()) {
737 btnStopServer
.setEnabled(true);
739 btnStopServer
.setEnabled(false);
743 private boolean isManagedServerRunning() {
744 return CdmStoreLocal
.getManagedServer() != null && CdmStoreLocal
.getManagedServer().isAlive();
747 private boolean isSelectedCdmInstanceRunningInManagedServer() {
748 return CdmStoreLocal
.getManagedServer() != null &&
749 CdmStoreLocal
.getManagedServer().isAlive() &&
750 selectedServerInfo
.isLocalhostMgd() &&
751 CdmStoreLocal
.getManagedServer().getDataSourceName().equals(selectedCdmInstance
.getName());
754 private void startManagedServer() {
755 if(isManagedServerRunning()) {
756 if(CdmStoreLocal
.getManagedServer().getDataSourceName().equals(selectedCdmInstance
.getName())) {
759 Display
.getDefault().syncExec(new Runnable() {
762 onStopManagedServer();
768 boolean forceSchemaCreate
= !schemaExists(selectedCdmInstance
);
769 boolean forceSchemaUpdate
= LABEL_UPDATE_SCHEMA_VERSION
.equals(btnConnect
.getText());
771 Job job
= new Job(Messages
.RemotingLoginDialog_JOB_SERVER_LAUNCH
) {
774 public IStatus
run(IProgressMonitor monitor
) {
775 String mgdServerConfigFileName
= "mgd.datasources.xml"; //$NON-NLS-1$
776 String config
= CdmServerUtils
.convertEditorToServerConfig();
778 monitor
.beginTask(Messages
.RemotingLoginDialog_TASK_LAUNCHING_SERVER
, maxUnits
);
780 monitor
.subTask(String
.format(Messages
.RemotingLoginDialog_GENERATING_CONFIG_FILE
, selectedCdmInstance
.getName()));
781 File managedServerConfigFile
= CdmServerUtils
.writeManagedServerConfig(config
, mgdServerConfigFileName
);
785 CdmServer cdmServer
= new CdmServer(selectedCdmInstance
.getName(), managedServerConfigFile
);
787 // ICdmServer cdmServer = new CdmServer(selectedCdmInstance.getName(), managedServerConfigFile);
788 cdmServer
.setForceSchemaCreate(forceSchemaCreate
);
789 cdmServer
.setForceSchemaUpdate(forceSchemaUpdate
);
790 CdmStoreLocal
.setManagedServer(cdmServer
);
791 monitor
.subTask(Messages
.RemotingLoginDialog_STARTING_MGD_SERVER
);
792 cdmServer
.start(false, RemotingLoginDialogLocal
.this);
795 // the following loop is a 'fake' progress monitoring where the progress
796 // bar is advanced by one unit every second until maxUnits -2
797 while(!CdmStoreLocal
.getManagedServer().isStarted() && !CdmStoreLocal
.getManagedServer().isFailed()) {
798 if(serverUnits
< maxUnits
- 2) {
801 } catch (InterruptedException e
) {
807 Display
.getDefault().syncExec(()->{
809 updateManagedServerControls();
812 } catch (IOException ioe
) {
813 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_GENERATING_CONFIG_FILE
,
816 TaxeditorStorePlugin
.PLUGIN_ID
,
819 } catch (CdmEmbeddedServerException cese
) {
820 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_STARTING_SERVER
,
823 TaxeditorStorePlugin
.PLUGIN_ID
,
829 // NOTE: Errors thrown during server startup are passed to the handleError() implementation
830 // TODO: is the above catch clause for CdmEmbeddedServerException still valuable?
832 return Status
.OK_STATUS
;
837 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);
844 private boolean schemaExists(CdmInstanceInfo instanceInfo
) {
845 if (instanceInfo
.getDataSource() != null){
847 //TODO we need a new method in cdmlib to check for existing schema
848 String schemaVersion
= instanceInfo
.getDataSource().getDbSchemaVersion();
849 return schemaVersion
!= null;
850 } catch (CdmSourceException e
) {
858 private String
managedSchemaVersion(CdmInstanceInfo instanceInfo
) throws CdmSourceException
{
859 if (instanceInfo
.getDataSource() != null){
860 return instanceInfo
.getDataSource().getDbSchemaVersion();
862 throw new RuntimeException("ManagedSchemaVersion only available for managed server instances.");
865 private int compareSchemaVersion(CdmInstanceInfo instanceInfo
) throws CdmSourceException
{
866 return CdmMetaData
.compareVersion(managedSchemaVersion(instanceInfo
), CdmMetaData
.getDbSchemaVersion(), 3, null);
871 public void handleError(final Throwable t
) {
873 Display
.getDefault().syncExec(()-> {
876 String title
= Messages
.RemotingLoginDialog_SERVER_LAUNCH_ERROR
;
877 String message
= t
.getMessage();
879 MessagingUtils
.errorDialog(title
,
882 TaxeditorStorePlugin
.PLUGIN_ID
,
888 private void onStopManagedServer() {
890 CdmStoreLocal
.getManagedServer().stop();
891 } catch (Exception e
) {
892 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_STOPPING_SERVER
,
894 String
.format(Messages
.RemotingLoginDialog_COULD_NOT_STOP_SERVER
, CdmStoreLocal
.getManagedServer().getPort()),
895 TaxeditorStorePlugin
.PLUGIN_ID
,
899 CdmStoreLocal
.setManagedServer(null);
900 updateManagedServerControls();
903 private int getManagedServerPort() {
904 return CdmStoreLocal
.getManagedServer() == null ? CdmServerInfo
.NULL_PORT
: CdmStoreLocal
.getManagedServer().getPort();
908 protected void checkSelectedCdmInstance() {
910 if (selectedServerInfo
.isLocalhostMgd()){
911 checkManagedSelectedInstance();
912 }else if (txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
)) {
914 boolean available
= false;
915 String instanceStatus
= STATUS_NOT_AVAILABLE
;
916 String message
= null;
918 if(selectedServerInfo
.pingInstance(selectedCdmInstance
, getPort())) {
919 instanceStatus
= STATUS_AVAILABLE
;
922 instanceStatus
= STATUS_NOT_AVAILABLE
;
927 txtServerSchemaVersion
.setText(selectedServerInfo
.getCdmRemoteSource(selectedCdmInstance
, getPort()).getDbSchemaVersion());
929 int compareDbSchemaVersion
= selectedServerInfo
.compareDbSchemaVersion(selectedCdmInstance
, getPort());
931 int compareCdmlibServicesVersion
= 0;
932 boolean disableServicesApiTimestampCheck
=
933 PreferencesUtil
.getBooleanValue((IPreferenceKeys
.DISABLE_SERVICES_API_TIMESTAMP_CHECK
));
934 if(!disableServicesApiTimestampCheck
) {
935 compareCdmlibServicesVersion
= selectedServerInfo
.compareCdmlibServicesVersion();
938 if(compareDbSchemaVersion
> 0 || compareCdmlibServicesVersion
> 0) {
939 instanceStatus
= STATUS_NOT_COMPATIBLE
;
941 message
= MESG_COMPATIBLE_EDITOR_OLD
;
942 } else if(compareDbSchemaVersion
< 0 || compareCdmlibServicesVersion
< 0) {
943 instanceStatus
= STATUS_NOT_COMPATIBLE
;
945 message
= MESG_COMPATIBLE_SERVER_OLD
;
947 instanceStatus
= STATUS_AVAILABLE
;
949 message
= ""; //$NON-NLS-1$
952 } catch (Exception e
) {
953 txtCdmInstanceStatus
.setToolTipText(e
.getMessage());
955 lblDefaultLogin
.setVisible(false);
956 btnConnect
.setEnabled(available
);
957 txtCdmInstanceStatus
.setText(instanceStatus
);
958 if(!StringUtils
.isBlank(message
)) {
965 private void checkManagedSelectedInstance() {
966 boolean available
= false;
967 String instanceStatus
= STATUS_NOT_AVAILABLE
;
968 String message
= null;
969 String connect
= LABEL_CONNECT
;
970 Integer color
= null;
971 String schemaVersion
= CdmMetaData
.getDbSchemaVersion();
973 if (!schemaExists(selectedCdmInstance
)){
974 message
= MESG_SCHEMA_MISSING
;
975 connect
= LABEL_CREATE_SCHEMA
;
976 color
= BTN_COLOR_ATTENTION
;
977 schemaVersion
= MESG_NO_SCHEMA
;
981 schemaVersion
= managedSchemaVersion(selectedCdmInstance
);
982 compare
= compareSchemaVersion(selectedCdmInstance
);
984 instanceStatus
= STATUS_NOT_COMPATIBLE
;
985 message
= MESG_COMPATIBLE_EDITOR_OLD
;
987 }else if (compare
< 0){
988 instanceStatus
= STATUS_NOT_COMPATIBLE
;
989 message
= MESG_UPDATE_SCHEMA_VERSION
;
991 connect
= LABEL_UPDATE_SCHEMA_VERSION
;
992 color
= BTN_COLOR_ATTENTION
;
995 instanceStatus
= STATUS_AVAILABLE
;
997 } catch (CdmSourceException e
) {
1002 setManagedValues(available
, instanceStatus
, connect
, color
, schemaVersion
);
1003 setMessage(message
);
1006 private void setManagedValues(boolean available
, String instanceStatus
, String connect
, Integer color
,
1007 String schemaVersion
) {
1008 Display
.getDefault().syncExec(()->{
1009 btnConnect
.setEnabled(available
);
1010 btnConnect
.setText(connect
);
1011 Color systemColor
= null;
1013 systemColor
= Display
.getCurrent().getSystemColor(color
);
1015 btnConnect
.setBackground(systemColor
);
1016 btnConnect
.requestLayout();
1017 txtCdmInstanceStatus
.setText(instanceStatus
);
1018 txtServerSchemaVersion
.setText(schemaVersion
);
1019 lblDefaultLogin
.setVisible(true);
1024 public void connect() {
1025 checkSelectedCdmInstance();
1027 if(!txtCdmInstanceStatus
.getText().equals(STATUS_AVAILABLE
)) {
1031 ICdmRemoteSource source
= selectedServerInfo
.getCdmRemoteSource(selectedCdmInstance
, getPort());
1033 if(!validateLogin(source
)) {
1038 CdmStoreLocal
.connect(source
, RemotingLoginDialogLocal
.this);
1039 } catch (Exception e
) {
1040 // Do not expect anything to go wrong at this point, so we throw a runtime exception
1042 throw new RuntimeException(e
);
1048 public boolean isRememberMe() {
1049 return btnRememberMe
.getSelection();
1052 private void persistPrefLastServerInstance() {
1053 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
1054 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
1056 lastServerInstancePrefs
.put(LAST_SERVER_KEY
, selectedServerInfo
.getName());
1057 lastServerInstancePrefs
.put(LAST_INSTANCE_KEY
, selectedCdmInstance
.getName());
1059 flushPreferences(lastServerInstancePrefs
);
1062 private void persistPrefCredentials() {
1063 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
1064 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
1065 credentialsPrefs
.put(getUsernamePrefKey(), txtLogin
.getText());
1066 credentialsPrefs
.put(getPasswordPrefKey(), txtPassword
.getText());
1067 flushPreferences(credentialsPrefs
);
1070 private void removePrefCredentials() {
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 removePreferences(credentialsPrefs
);
1078 private void removePreferences(Preferences prefs
) {
1081 } catch (BackingStoreException bse
) {
1082 setMessage(bse
.getMessage());
1086 private void flushPreferences(Preferences prefs
) {
1089 } catch (BackingStoreException bse
) {
1090 setMessage(bse
.getMessage());
1095 protected void readPrefCredentials() {
1096 String username
, password
;
1097 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
1098 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
1099 username
= credentialsPrefs
.get(getUsernamePrefKey(), ""); //$NON-NLS-1$
1100 txtLogin
.setText(username
);
1101 password
= credentialsPrefs
.get(getPasswordPrefKey(),""); //$NON-NLS-1$
1102 txtPassword
.setText(password
);
1103 if(username
.isEmpty() || password
.isEmpty()) {
1104 autoConnect
= false;
1108 private void readPrefLastServerInstance() {
1109 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
1110 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
1112 serverName
= lastServerInstancePrefs
.get(LAST_SERVER_KEY
, null);
1113 instanceName
= lastServerInstancePrefs
.get(LAST_INSTANCE_KEY
, null);
1116 private void emptyCredentials() {
1117 txtLogin
.setText(""); //$NON-NLS-1$
1118 txtPassword
.setText(""); //$NON-NLS-1$
1121 private String
getUsernamePrefKey() {
1122 return selectedServerInfo
.toString(selectedCdmInstance
.getName(), isDevRemoteSource?
getPort():-1) + USERNAME_SUFFIX
;
1125 private String
getPasswordPrefKey() {
1126 return selectedServerInfo
.toString(selectedCdmInstance
.getName(), isDevRemoteSource?
getPort():-1) + PASSWORD_SUFFIX
;
1129 private boolean validateLogin(ICdmRemoteSource remoteSource
) {
1130 if(getUsername() == null || getUsername().isEmpty()) {
1131 setMessage(Messages
.RemotingLoginDialog_LOGIN_CANNOT_BE_EMPTY
);
1134 if(getPassword() == null || getPassword().isEmpty()) {
1135 setMessage(Messages
.RemotingLoginDialog_PASSWORD_CANNOT_BE_EMPTY
);
1140 IUserService userService
= CdmApplicationRemoteConfiguration
.getUserService(remoteSource
);
1141 UsernamePasswordAuthenticationToken token
= new UsernamePasswordAuthenticationToken(getUsername(), getPassword());
1142 CdmApplicationRemoteConfiguration
.getAuthenticationManager(userService
).authenticate(token
);
1143 } catch(BadCredentialsException e
){
1144 setMessage(LoginManager
.INCORRECT_CREDENTIALS_MESSAGE
);
1146 } catch(LockedException e
){
1147 setMessage(LoginManager
.ACCOUNT_LOCKED_MESSAGE
);
1149 } catch(IllegalArgumentException e
){
1150 setMessage(LoginManager
.INCORRECT_CREDENTIALS_MESSAGE
);
1158 public String
getUsername() {
1159 return txtLogin
.getText();
1164 public String
getPassword() {
1165 return txtPassword
.getText();
1170 public void setMessage(String message
) {
1171 if(CdmUtils
.isNotBlank(message
)) {
1172 // if(message.length() > 50) {
1173 // styledTxtMessage.setToolTipText(message);
1174 // message = message.substring(0,50) + "..."; //$NON-NLS-1$
1176 styledTxtMessage
.setText(message
);
1177 styledTxtMessage
.setVisible(true);
1178 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= false;
1179 // shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
1180 shlConnect
.pack(true);
1182 if (!styledTxtMessage
.isDisposed()){
1183 styledTxtMessage
.setText(""); //$NON-NLS-1$
1184 styledTxtMessage
.setVisible(false);
1185 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= true;
1187 if(!shlConnect
.isDisposed()){
1188 shlConnect
.pack(true);
1191 if (!remotingComposite
.isDisposed()){
1192 remotingComposite
.layout();
1196 // private int getHeightWithoutMessage() {
1197 // if(xpndblcmpstAdvanced.isExpanded()) {
1198 // return MIN_EXP_HEIGHT;
1200 // return MIN_HEIGHT;
1205 public void hide(boolean isHidden
) {
1206 if (!shlConnect
.isDisposed()){
1207 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
1208 shlConnect
.setVisible(!isHidden
);
1215 public void dispose() {
1216 if (!shlConnect
.isDisposed()){
1217 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
1218 shlConnect
.dispose();
1225 public void onComplete() {
1226 Display
.getDefault().asyncExec(new Runnable() {
1229 if(selectedCdmInstance
!=null){
1230 if(isRememberMe()) {
1231 persistPrefCredentials();
1233 removePrefCredentials();
1235 persistPrefLastServerInstance();
1242 private String
generateLastModifiedTooltip(String cdmlibLastModified
) {
1243 if(StringUtils
.isBlank(cdmlibLastModified
)) {
1244 return ""; //$NON-NLS-1$
1246 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy.MM.dd.HH.mm.z"); //$NON-NLS-1$
1247 Date cdmlibLastModifiedDate
;
1248 String cdmlibLastModifiedTimestamp
= ""; //$NON-NLS-1$
1250 cdmlibLastModifiedDate
= new Date(Long
.valueOf(cdmlibLastModified
));
1251 cdmlibLastModifiedTimestamp
= sdf
.format(cdmlibLastModifiedDate
);
1253 return cdmlibLastModifiedTimestamp
;
1256 private void setEditorInfo() {
1257 txtEditorCdmVersion
.setText(CdmMetaData
.getDbSchemaVersion());
1258 setCdmlibVersion(txtEditorCdmlibVersion
);
1261 private void setCdmlibVersion(Text txt
) {
1262 String editorVersionTimestamp
= generateLastModifiedTooltip(CdmApplicationState
.getCdmlibLastModified());
1263 txt
.setText(CdmApplicationState
.getCdmlibVersion() + ":" + editorVersionTimestamp
); //$NON-NLS-1$
1266 private void clearOnServerChange() {
1267 setMessage(""); //$NON-NLS-1$
1268 txtServerSchemaVersion
.setText(""); //$NON-NLS-1$
1269 txtServerCdmlibVersion
.setText(""); //$NON-NLS-1$
1270 txtServerCdmlibVersion
.setToolTipText(""); //$NON-NLS-1$
1271 txtServerSchemaVersion
.setText(""); //$NON-NLS-1$
1272 comboCdmInstance
.removeAll();
1273 txtCdmInstanceStatus
.setText(""); //$NON-NLS-1$
1274 txtPort
.setEditable(false);
1275 txtPort
.setEnabled(false);
1278 private void clearOnInstanceChange() {
1279 setMessage(""); //$NON-NLS-1$
1280 txtServerSchemaVersion
.setText(""); //$NON-NLS-1$
1281 btnConnect
.setText(LABEL_CONNECT
);
1282 btnConnect
.setBackground(null);
1283 btnConnect
.requestLayout();
1286 @SuppressWarnings("unused") //in work, for future centralized handling of control's status
1287 private void updateControls(){
1290 // comboCdmServer; //nothing to change
1291 String strServerStatus
= this.selectedServerInfo
!= null? STATUS_NOT_AVAILABLE
: STATUS_AVAILABLE
;
1292 txtCdmServerStatus
.setText(strServerStatus
);
1293 // btnCdmServerRefresh; //nothing to change
1297 String strInstanceStatus
= this.selectedCdmInstance
!= null? STATUS_NOT_AVAILABLE
: STATUS_AVAILABLE
;
1298 txtCdmInstanceStatus
.setText(strInstanceStatus
);
1299 // btnCdmInstanceRefresh; //nothing to change
1302 txtLogin
.setText(Nz(login
));
1303 txtPassword
.setText(Nz(password
));
1304 btnConnect
.setText(LABEL_CONNECT
); //TODO
1305 btnConnect
.setEnabled(true);
1307 //rememberMe + defaultValues
1312 // styledTxtMessage;
1318 // txtServerCdmlibVersion;
1319 // txtEditorCdmlibVersion;
1320 // txtServerSchemaVersion;
1321 // txtEditorCdmVersion;
1324 private String
Nz(String value
) {
1325 return CdmUtils
.Nz(value
);