3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.ui
.dialog
;
13 import java
.io
.IOException
;
14 import java
.text
.SimpleDateFormat
;
15 import java
.util
.Date
;
16 import java
.util
.HashMap
;
17 import java
.util
.List
;
20 import org
.apache
.commons
.lang
.StringUtils
;
21 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
22 import org
.eclipse
.core
.runtime
.IStatus
;
23 import org
.eclipse
.core
.runtime
.Status
;
24 import org
.eclipse
.core
.runtime
.jobs
.Job
;
25 import org
.eclipse
.core
.runtime
.preferences
.ConfigurationScope
;
26 import org
.eclipse
.core
.runtime
.preferences
.IEclipsePreferences
;
27 import org
.eclipse
.swt
.SWT
;
28 import org
.eclipse
.swt
.custom
.StyledText
;
29 import org
.eclipse
.swt
.events
.MouseAdapter
;
30 import org
.eclipse
.swt
.events
.MouseEvent
;
31 import org
.eclipse
.swt
.events
.SelectionAdapter
;
32 import org
.eclipse
.swt
.events
.SelectionEvent
;
33 import org
.eclipse
.swt
.graphics
.Point
;
34 import org
.eclipse
.swt
.layout
.FillLayout
;
35 import org
.eclipse
.swt
.layout
.GridData
;
36 import org
.eclipse
.swt
.layout
.GridLayout
;
37 import org
.eclipse
.swt
.widgets
.Button
;
38 import org
.eclipse
.swt
.widgets
.Combo
;
39 import org
.eclipse
.swt
.widgets
.Composite
;
40 import org
.eclipse
.swt
.widgets
.Dialog
;
41 import org
.eclipse
.swt
.widgets
.Display
;
42 import org
.eclipse
.swt
.widgets
.Label
;
43 import org
.eclipse
.swt
.widgets
.Shell
;
44 import org
.eclipse
.swt
.widgets
.Text
;
45 import org
.eclipse
.ui
.forms
.events
.ExpansionEvent
;
46 import org
.eclipse
.ui
.forms
.events
.IExpansionListener
;
47 import org
.eclipse
.ui
.forms
.widgets
.ExpandableComposite
;
48 import org
.eclipse
.ui
.progress
.IProgressConstants
;
49 import org
.eclipse
.wb
.swt
.SWTResourceManager
;
50 import org
.osgi
.service
.prefs
.BackingStoreException
;
51 import org
.osgi
.service
.prefs
.Preferences
;
52 import org
.springframework
.security
.authentication
.BadCredentialsException
;
53 import org
.springframework
.security
.authentication
.LockedException
;
54 import org
.springframework
.security
.authentication
.UsernamePasswordAuthenticationToken
;
56 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationRemoteConfiguration
;
57 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
58 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
59 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
;
60 import eu
.etaxonomy
.taxeditor
.Messages
;
61 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
62 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
63 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
64 import eu
.etaxonomy
.taxeditor
.remoting
.server
.CDMServerException
;
65 import eu
.etaxonomy
.taxeditor
.remoting
.server
.CDMServerUtils
;
66 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmRemoteSource
;
67 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
;
68 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
.CdmInstanceInfo
;
69 import eu
.etaxonomy
.taxeditor
.remoting
.source
.ICdmRemoteSource
;
70 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
71 import eu
.etaxonomy
.taxeditor
.store
.LoginManager
;
72 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
73 import eu
.etaxonomy
.taxeditor
.webapp
.CDMEmbeddedServerException
;
74 import eu
.etaxonomy
.taxeditor
.webapp
.CDMServer
;
75 import eu
.etaxonomy
.taxeditor
.webapp
.ICDMServerError
;
83 public class RemotingLoginDialog
extends Dialog
implements ICDMServerError
{
85 private static final String UBUNTU
= "Ubuntu"; //$NON-NLS-1$
86 protected Object result
;
87 protected Shell shlConnect
;
88 private Text txtCdmServerStatus
;
89 private Text txtCdmInstanceStatus
;
90 private Combo comboCdmServer
;
91 private Combo comboCdmInstance
;
92 private Button btnConnect
;
94 private final Map
<String
, CdmServerInfo
> csiiMap
= new HashMap
<String
, CdmServerInfo
>();
96 private final static String STATUS_AVAILABLE
= ""; //$NON-NLS-1$
97 private final static String STATUS_NOT_AVAILABLE
= ""; //$NON-NLS-1$
98 private final static String STATUS_STARTED
= ""; //$NON-NLS-1$
99 private final static String STATUS_NOT_STARTED
= ""; //$NON-NLS-1$
100 private final static String STATUS_RETRIEVING
= ""; //$NON-NLS-1$
101 private final static String STATUS_CHECKING_AVAILABILITY
= ""; //$NON-NLS-1$
102 private final static String STATUS_NO_INSTANCES
= ""; //$NON-NLS-1$
103 private final static String STATUS_ERROR
= ""; //$NON-NLS-1$
104 private final static String STATUS_REMOTING_NOT_ACTIVATED
= ""; //$NON-NLS-1$
105 private final static String STATUS_NOT_COMPATIBLE
= ""; //$NON-NLS-1$
107 private final static String MESG_COMPATIBLE_EDITOR_OLD
= ""; //$NON-NLS-1$
108 private final static String MESG_COMPATIBLE_SERVER_OLD
= ""; //$NON-NLS-1$
110 private final static String STORE_PREFERENCES_NODE
= "eu.etaxonomy.taxeditor.store"; //$NON-NLS-1$
112 private final static String LOGIN_NODE
= "login"; //$NON-NLS-1$
113 private final static String USERNAME_SUFFIX
= "_username"; //$NON-NLS-1$
114 private final static String PASSWORD_SUFFIX
= "_password"; //$NON-NLS-1$
116 private final static String LAST_SERVER_INSTANCE_NODE
= "lastServerInstance"; //$NON-NLS-1$
117 private final static String LAST_SERVER_KEY
= "lastServerKey"; //$NON-NLS-1$
118 private final static String LAST_INSTANCE_KEY
= "lastInstanceKey"; //$NON-NLS-1$
120 private final static String REFRESH_LABEL
= ""; //$NON-NLS-1$
122 private Composite remotingComposite
;
123 private CdmServerInfo selectedCsii
;
124 private CdmInstanceInfo selectedCdmInstance
;
125 private Button btnCdmServerRefresh
;
126 private Button btnCdmInstanceRefresh
;
127 private Button btnStopServer
;
128 private Composite loginComposite
;
129 private Label lblLogin
;
130 private Text txtLogin
;
131 private Label lblPassword
;
132 private Text txtPassword
;
133 private Button btnRememberMe
;
134 private Composite compAdvanced
;
135 private Label lblPort
;
136 private Text txtPort
;
137 private Label lblServerVersion
;
138 private Text txtServerVersion
;
139 private ExpandableComposite xpndblcmpstAdvanced
;
140 private StyledText styledTxtMessage
;
143 private final int MIN_WIDTH
= 530;
144 private final int MIN_HEIGHT
= 220;
145 private final int MIN_EXP_HEIGHT
= 380;
146 private final int MESSAGE_HEIGHT
= 25;
147 private Label lblEditorVersion
;
148 private Text txtEditorVersion
;
149 private Label lblServerCDMVersion
;
150 private Text txtServerCDMVersion
;
151 private Label lblEditorCDMVersion
;
152 private Text txtEditorCDMVersion
;
154 private String serverName
, instanceName
;
155 private boolean autoConnect
= false;
156 private boolean loadLoginPrefs
= true;
157 private boolean isDevRemoteSource
= false;
158 private Job serverJob
;
164 public RemotingLoginDialog(Shell parent
, int style
) {
165 super(parent
, style
);
166 setText(""); //$NON-NLS-1$
169 public Object
open(CdmRemoteSource source
, boolean loadLoginPrefs
, boolean autoConnect
) {
170 this.loadLoginPrefs
= loadLoginPrefs
;
171 this.serverName
= source
.getName();
172 String contextPath
= source
.getContextPath();
173 this.instanceName
= contextPath
.substring(contextPath
.lastIndexOf("/") + 1); //$NON-NLS-1$
174 return open(serverName
, instanceName
, loadLoginPrefs
, autoConnect
);
178 public Object
open(String serverName
, String instanceName
, boolean loadLoginPrefs
, boolean autoConnect
) {
179 this.serverName
= serverName
;
180 this.instanceName
= instanceName
;
181 this.loadLoginPrefs
= loadLoginPrefs
;
182 this.autoConnect
= autoConnect
;
190 public Object
open() {
193 if(serverName
== null && instanceName
== null) {
194 readPrefLastServerInstance();
198 populateCdmServerCombo();
202 xpndblcmpstAdvanced
.setExpanded(false);
204 Display display
= getParent().getDisplay();
206 while (!shlConnect
.isDisposed()) {
207 if (!display
.readAndDispatch()) {
216 * Create contents of the dialog.
218 private void createContents() {
219 shlConnect
= new Shell(getParent(), SWT
.DIALOG_TRIM
);
220 shlConnect
.setMinimumSize(new Point(MIN_WIDTH
, MIN_HEIGHT
));
221 shlConnect
.setSize(MIN_WIDTH
, MIN_HEIGHT
);
222 shlConnect
.setText(""); //$NON-NLS-1$
223 shlConnect
.setLayout(new FillLayout(SWT
.HORIZONTAL
));
225 remotingComposite
= new Composite(shlConnect
, SWT
.NONE
);
226 remotingComposite
.setLayout(new GridLayout(1, false));
228 Composite cdmServerComposite
= new Composite(remotingComposite
, SWT
.NONE
);
229 GridData gd_cdmServerComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
230 gd_cdmServerComposite
.heightHint
= 68;
231 cdmServerComposite
.setLayoutData(gd_cdmServerComposite
);
232 cdmServerComposite
.setLayout(new GridLayout(4, false));
234 Label lblCdmServer
= new Label(cdmServerComposite
, SWT
.NONE
);
235 lblCdmServer
.setText(""); //$NON-NLS-1$
236 lblCdmServer
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
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
) {
247 GridData gd_comboCdmServer
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
248 gd_comboCdmServer
.widthHint
= 150;
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, false, 1, 1);
256 gd_txtCdmServerStatus
.widthHint
= 100;
257 txtCdmServerStatus
.setLayoutData(gd_txtCdmServerStatus
);
259 btnCdmServerRefresh
= new Button(cdmServerComposite
, SWT
.NONE
);
260 btnCdmServerRefresh
.addSelectionListener(new SelectionAdapter() {
262 public void widgetSelected(SelectionEvent e
) {
266 btnCdmServerRefresh
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
267 btnCdmServerRefresh
.setText(""); //$NON-NLS-1$
269 Label lblCdmInstance
= new Label(cdmServerComposite
, SWT
.NONE
);
270 GridData gd_lblCdmInstance
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
271 gd_lblCdmInstance
.heightHint
= 30;
272 lblCdmInstance
.setLayoutData(gd_lblCdmInstance
);
273 lblCdmInstance
.setText(""); //$NON-NLS-1$
274 lblCdmInstance
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
276 comboCdmInstance
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
277 comboCdmInstance
.addSelectionListener(new SelectionAdapter() {
279 public void widgetSelected(SelectionEvent e
) {
280 refreshCdmInstance();
283 GridData gd_comboCdmInstance
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
284 gd_comboCdmInstance
.widthHint
= 150;
285 comboCdmInstance
.setLayoutData(gd_comboCdmInstance
);
286 comboCdmInstance
.select(0);
288 txtCdmInstanceStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
289 txtCdmInstanceStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
290 txtCdmInstanceStatus
.setEditable(false);
291 GridData gd_txtCdmInstanceStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
292 gd_txtCdmInstanceStatus
.widthHint
= 100;
293 txtCdmInstanceStatus
.setLayoutData(gd_txtCdmInstanceStatus
);
295 btnCdmInstanceRefresh
= new Button(cdmServerComposite
, SWT
.FLAT
);
296 btnCdmInstanceRefresh
.addSelectionListener(new SelectionAdapter() {
298 public void widgetSelected(SelectionEvent e
) {
299 refreshCdmInstance();
302 GridData gd_btnCdmInstanceRefresh
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
303 gd_btnCdmInstanceRefresh
.widthHint
= 110;
304 gd_btnCdmInstanceRefresh
.heightHint
= 30;
305 btnCdmInstanceRefresh
.setLayoutData(gd_btnCdmInstanceRefresh
);
306 btnCdmInstanceRefresh
.setText(""); //$NON-NLS-1$
308 loginComposite
= new Composite(remotingComposite
, SWT
.NONE
);
309 GridData gd_loginComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
310 gd_loginComposite
.widthHint
= 487;
311 gd_loginComposite
.heightHint
= 70;
312 loginComposite
.setLayoutData(gd_loginComposite
);
313 GridLayout gl_loginComposite
= new GridLayout(6, false);
314 gl_loginComposite
.marginTop
= 5;
315 loginComposite
.setLayout(gl_loginComposite
);
317 lblLogin
= new Label(loginComposite
, SWT
.CENTER
);
318 GridData gd_lblLogin
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
319 gd_lblLogin
.widthHint
= 50;
320 lblLogin
.setLayoutData(gd_lblLogin
);
321 lblLogin
.setText(""); //$NON-NLS-1$
322 lblLogin
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
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 gd_txtLogin
.widthHint
= 80;
328 gd_txtLogin
.heightHint
= 15;
329 txtLogin
.setLayoutData(gd_txtLogin
);
331 lblPassword
= new Label(loginComposite
, SWT
.CENTER
);
332 lblPassword
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
333 lblPassword
.setText(""); //$NON-NLS-1$
334 lblPassword
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
336 txtPassword
= new Text(loginComposite
, SWT
.BORDER
| SWT
.PASSWORD
);
337 GridData gd_txtPassword
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
338 gd_txtPassword
.minimumWidth
= 80;
339 gd_txtPassword
.widthHint
= 80;
340 gd_txtPassword
.heightHint
= 15;
341 txtPassword
.setLayoutData(gd_txtPassword
);
342 new Label(loginComposite
, SWT
.NONE
);
344 btnConnect
= new Button(loginComposite
, SWT
.FLAT
);
345 btnConnect
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1));
346 btnConnect
.addMouseListener(new MouseAdapter() {
348 public void mouseUp(MouseEvent e
) {
349 if(selectedCsii
.isLocalhostMgd() && !isSelectedCdmInstanceRunningInManagedServer()) {
350 startManagedServer();
356 btnConnect
.setText(""); //$NON-NLS-1$
358 btnRememberMe
= new Button(loginComposite
, SWT
.CHECK
);
359 btnRememberMe
.setSelection(true);
360 GridData gd_btnRememberMe
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 2, 1);
361 gd_btnRememberMe
.widthHint
= 107;
362 btnRememberMe
.setLayoutData(gd_btnRememberMe
);
363 btnRememberMe
.setText(""); //$NON-NLS-1$
364 new Label(loginComposite
, SWT
.NONE
);
365 new Label(loginComposite
, SWT
.NONE
);
366 new Label(loginComposite
, SWT
.NONE
);
367 new Label(loginComposite
, SWT
.NONE
);
369 styledTxtMessage
= new StyledText(remotingComposite
, SWT
.NONE
);
370 styledTxtMessage
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
371 styledTxtMessage
.setForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
372 styledTxtMessage
.setFont(SWTResourceManager
.getFont(UBUNTU
, 12, SWT
.BOLD
));
373 styledTxtMessage
.setSelectionBackground(SWTResourceManager
.getColor(SWT
.COLOR_LIST_SELECTION_TEXT
));
374 styledTxtMessage
.setSelectionForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
375 styledTxtMessage
.setDoubleClickEnabled(false);
376 styledTxtMessage
.setEditable(false);
377 GridData gd_styledTxtMessage
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
378 gd_styledTxtMessage
.exclude
= true;
379 gd_styledTxtMessage
.minimumHeight
= MESSAGE_HEIGHT
;
380 gd_styledTxtMessage
.heightHint
= MESSAGE_HEIGHT
;
381 styledTxtMessage
.setLayoutData(gd_styledTxtMessage
);
383 xpndblcmpstAdvanced
= new ExpandableComposite(remotingComposite
, SWT
.NONE
, ExpandableComposite
.TWISTIE
);
384 GridData gd_xpndblcmpstAdvanced
= new GridData(SWT
.FILL
, SWT
.FILL
, false, true, 1, 1);
385 gd_xpndblcmpstAdvanced
.heightHint
= 19;
386 xpndblcmpstAdvanced
.setLayoutData(gd_xpndblcmpstAdvanced
);
387 xpndblcmpstAdvanced
.addExpansionListener(new IExpansionListener() {
389 public void expansionStateChanged(ExpansionEvent e
) {
390 GridData gridData
= (GridData
) xpndblcmpstAdvanced
.getLayoutData();
392 shlConnect
.setSize(MIN_WIDTH
, MIN_EXP_HEIGHT
);
394 shlConnect
.setSize(MIN_WIDTH
, MIN_HEIGHT
);
399 public void expansionStateChanging(ExpansionEvent e
) {
402 xpndblcmpstAdvanced
.setText(""); //$NON-NLS-1$
403 xpndblcmpstAdvanced
.setExpanded(true);
405 compAdvanced
= new Composite(xpndblcmpstAdvanced
, SWT
.NONE
);
406 xpndblcmpstAdvanced
.setClient(compAdvanced
);
407 compAdvanced
.setLayout(new GridLayout(4, false));
409 lblPort
= new Label(compAdvanced
, SWT
.CENTER
);
410 lblPort
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
411 lblPort
.setSize(0, 0);
412 lblPort
.setText(""); //$NON-NLS-1$
413 lblPort
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
415 txtPort
= new Text(compAdvanced
, SWT
.BORDER
);
416 GridData gd_txtPort
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1);
417 gd_txtPort
.minimumWidth
= 50;
418 gd_txtPort
.widthHint
= 50;
419 txtPort
.setLayoutData(gd_txtPort
);
421 lblServerVersion
= new Label(compAdvanced
, SWT
.CENTER
);
422 lblServerVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
423 lblServerVersion
.setText(""); //$NON-NLS-1$
424 lblServerVersion
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
426 txtServerVersion
= new Text(compAdvanced
, SWT
.BORDER
);
427 txtServerVersion
.setEditable(false);
428 txtServerVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
429 btnStopServer
= new Button(compAdvanced
, SWT
.FLAT
);
430 btnStopServer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 2, 1));
431 btnStopServer
.addMouseListener(new MouseAdapter() {
433 public void mouseUp(MouseEvent e
) {
437 btnStopServer
.setText(""); //$NON-NLS-1$
439 lblEditorVersion
= new Label(compAdvanced
, SWT
.CENTER
);
440 lblEditorVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
441 lblEditorVersion
.setText(""); //$NON-NLS-1$
442 lblEditorVersion
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
444 txtEditorVersion
= new Text(compAdvanced
, SWT
.BORDER
);
445 txtEditorVersion
.setEditable(false);
446 txtEditorVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
447 new Label(compAdvanced
, SWT
.NONE
);
448 new Label(compAdvanced
, SWT
.NONE
);
450 lblServerCDMVersion
= new Label(compAdvanced
, SWT
.CENTER
);
451 lblServerCDMVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
452 lblServerCDMVersion
.setText(""); //$NON-NLS-1$
453 lblServerCDMVersion
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
455 txtServerCDMVersion
= new Text(compAdvanced
, SWT
.BORDER
);
456 txtServerCDMVersion
.setEditable(false);
457 txtServerCDMVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
458 new Label(compAdvanced
, SWT
.NONE
);
459 new Label(compAdvanced
, SWT
.NONE
);
461 lblEditorCDMVersion
= new Label(compAdvanced
, SWT
.CENTER
);
462 lblEditorCDMVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
463 lblEditorCDMVersion
.setText(""); //$NON-NLS-1$
464 lblEditorCDMVersion
.setFont(SWTResourceManager
.getFont(UBUNTU
, 9, SWT
.NORMAL
));
466 txtEditorCDMVersion
= new Text(compAdvanced
, SWT
.BORDER
);
467 txtEditorCDMVersion
.setEditable(false);
468 txtEditorCDMVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
474 private void populateCdmServerCombo() {
475 Job job
= new Job("") { //$NON-NLS-1$
477 protected IStatus
run(IProgressMonitor monitor
) {
478 Display
.getDefault().syncExec(new Runnable() {
481 for(CdmServerInfo csii
: CdmServerInfo
.getCdmServers()) {
482 csiiMap
.put(csii
.getName(), csii
);
483 comboCdmServer
.add(csii
.getName());
485 int serverIndex
= -1;
486 if(serverName
!= null) {
487 serverIndex
= comboCdmServer
.indexOf(serverName
);
489 if(serverIndex
== -1) {
490 comboCdmServer
.select(0);
493 comboCdmServer
.select(serverIndex
);
495 CdmRemoteSource devRemoteSource
= CdmServerInfo
.getDevServerRemoteSource();
496 if(devRemoteSource
!= null) {
497 isDevRemoteSource
= true;
498 String username
= System
.getProperty("cdm.server.dev.username"); //$NON-NLS-1$
499 String password
= System
.getProperty("cdm.server.dev.password"); //$NON-NLS-1$
500 if(username
!= null && !username
.isEmpty() && password
!= null && !password
.isEmpty()) {
501 txtLogin
.setText(username
);
502 txtPassword
.setText(password
);
503 CdmStore
.connect(devRemoteSource
, RemotingLoginDialog
.this);
510 return Status
.OK_STATUS
;
517 private void refreshCdmServer() {
518 txtCdmServerStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
519 clearOnServerChange();
521 updateSelectedCdmServer();
522 Display
.getDefault().asyncExec(new Runnable() {
525 checkSelectedCdmServer();
531 private void updateSelectedCdmServer() {
532 int selIndex
= comboCdmServer
.getSelectionIndex();
534 selectedCsii
= csiiMap
.get(comboCdmServer
.getItem(selIndex
));
538 private void updatePort() {
539 txtPort
.setText(""); //$NON-NLS-1$
540 if(selectedCsii
!= null) {
541 int port
= selectedCsii
.getPort();
542 if(port
== CdmServerInfo
.NULL_PORT
) {
543 txtPort
.setText(CdmServerInfo
.NULL_PORT_STRING
);
545 txtPort
.setText(String
.valueOf(port
));
550 private int getPort() {
551 int port
= CdmServerInfo
.NULL_PORT
;
553 port
= Integer
.valueOf(txtPort
.getText());
554 } catch (NumberFormatException nfe
) {
555 if(!CdmServerInfo
.NULL_PORT_STRING
.equals(txtPort
.getText())) {
556 setMessage(""); //$NON-NLS-1$
562 private void checkSelectedCdmServer() {
563 if(selectedCsii
!= null) {
564 if(selectedCsii
.isLocalhost()) {
565 txtPort
.setEditable(true);
566 txtPort
.setEnabled(true);
568 if(selectedCsii
.pingServer()) {
569 txtCdmServerStatus
.setText(STATUS_AVAILABLE
);
570 populateCdmInstanceCombo(true);
571 String serverVersionTimestamp
= generateLastModifiedTooltip(selectedCsii
.getCdmlibLastModified());
572 txtServerVersion
.setText(selectedCsii
.getCdmlibServicesVersion() + ":" + serverVersionTimestamp
); //$NON-NLS-1$
574 txtCdmServerStatus
.setText(STATUS_NOT_AVAILABLE
);
575 comboCdmInstance
.removeAll();
576 disableCdmInstanceControls("", ""); //$NON-NLS-1$ //$NON-NLS-2$
583 private void populateCdmInstanceCombo(final boolean forceRefresh
) {
584 comboCdmInstance
.removeAll();
585 comboCdmInstance
.setEnabled(false);
586 btnConnect
.setEnabled(false);
587 txtCdmInstanceStatus
.setText(STATUS_RETRIEVING
);
588 txtCdmInstanceStatus
.setToolTipText(""); //$NON-NLS-1$
590 serverJob
= new Job("") { //$NON-NLS-1$
592 protected IStatus
run(IProgressMonitor monitor
) {
594 if(selectedCsii
!= null) {
596 selectedCsii
.refreshInstances();
598 final List
<CdmInstanceInfo
> instances
= selectedCsii
.getInstances();
599 Display
.getDefault().asyncExec(new Runnable() {
602 if(!instances
.isEmpty()) {
603 for(CdmInstanceInfo cdmInstance
: instances
) {
604 comboCdmInstance
.add(cdmInstance
.getName());
606 int instanceIndex
= -1;
607 if(instanceName
!= null) {
608 instanceIndex
= comboCdmInstance
.indexOf(instanceName
);
610 if(instanceIndex
== -1) {
611 comboCdmInstance
.select(0);
614 comboCdmInstance
.select(instanceIndex
);
616 refreshCdmInstance();
617 comboCdmInstance
.setEnabled(true);
623 txtCdmInstanceStatus
.setText(STATUS_NO_INSTANCES
);
624 btnConnect
.setEnabled(false);
629 } catch (final CDMServerException e
) {
630 MessagingUtils
.warn(getClass(), e
);
631 Display
.getDefault().asyncExec(new Runnable() {
634 disableCdmInstanceControls(STATUS_NOT_AVAILABLE
, e
.getMessage());
638 return Status
.OK_STATUS
;
642 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
) && !isDevRemoteSource
) {
644 serverJob
.schedule();
648 private void disableCdmInstanceControls(String cdmInstanceStatus
, String tooltip
) {
649 txtCdmInstanceStatus
.setText(cdmInstanceStatus
);
650 txtCdmInstanceStatus
.setToolTipText(tooltip
);
651 comboCdmInstance
.setEnabled(false);
652 btnConnect
.setEnabled(false);
655 private void refreshCdmInstance() {
656 txtCdmInstanceStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
657 clearOnInstanceChange();
658 updateSelectedCdmInstance();
659 checkSelectedCdmInstance();
660 updateManagedServerControls();
663 private void updateSelectedCdmInstance() {
664 int selIndex
= comboCdmInstance
.getSelectionIndex();
666 selectedCdmInstance
= selectedCsii
.getInstanceFromName(comboCdmInstance
.getItem(selIndex
));
668 if(loadLoginPrefs
&& !isDevRemoteSource
) {
669 readPrefCredentials();
674 private void updateManagedServerControls() {
675 if(selectedCsii
.isLocalhostMgd()) {
676 if(isSelectedCdmInstanceRunningInManagedServer()) {
677 txtCdmInstanceStatus
.setText(STATUS_STARTED
);
679 txtCdmInstanceStatus
.setText(STATUS_NOT_STARTED
);
681 btnConnect
.setEnabled(true);
682 selectedCsii
.setPort(getManagedServerPort());
687 if(isManagedServerRunning()) {
688 btnStopServer
.setEnabled(true);
690 btnStopServer
.setEnabled(false);
694 private boolean isManagedServerRunning() {
695 return CdmStore
.getManagedServer() != null && CdmStore
.getManagedServer().isAlive();
698 private boolean isSelectedCdmInstanceRunningInManagedServer() {
699 return CdmStore
.getManagedServer() != null &&
700 CdmStore
.getManagedServer().isAlive() &&
701 selectedCsii
.isLocalhostMgd() &&
702 CdmStore
.getManagedServer().getDataSourceName().equals(selectedCdmInstance
.getName());
705 private void startManagedServer() {
706 if(isManagedServerRunning()) {
707 if(CdmStore
.getManagedServer().getDataSourceName().equals(selectedCdmInstance
.getName())) {
710 Display
.getDefault().syncExec(new Runnable() {
720 Job job
= new Job(Messages
.RemotingLoginDialog_JOB_SERVER_LAUNCH
) {
723 public IStatus
run(IProgressMonitor monitor
) {
724 String mgdServerConfigFileName
= "mgd.datasources.xml"; //$NON-NLS-1$
725 String config
= CDMServerUtils
.convertEditorToServerConfig();
726 File managedServerConfigFile
;
728 monitor
.beginTask(Messages
.RemotingLoginDialog_TASK_LAUNCHING_SERVER
, maxUnits
);
730 monitor
.subTask(String
.format(Messages
.RemotingLoginDialog_GENERATING_CONFIG_FILE
, selectedCdmInstance
.getName()));
731 managedServerConfigFile
= CDMServerUtils
.writeManagedServerConfig(config
, mgdServerConfigFileName
);
733 CdmStore
.setManagedServer(new CDMServer(selectedCdmInstance
.getName(), managedServerConfigFile
));
734 monitor
.subTask(Messages
.RemotingLoginDialog_STARTING_MGD_SERVER
);
735 CdmStore
.getManagedServer().start(false, RemotingLoginDialog
.this);
738 // the following loop is a 'fake' progress monitoring where the progress
739 // bar is advanced by one unit every second until maxUnits -2
740 while(!CdmStore
.getManagedServer().isStarted() && !CdmStore
.getManagedServer().isFailed()) {
741 if(serverUnits
< maxUnits
- 2) {
744 } catch (InterruptedException e
) {
750 Display
.getDefault().asyncExec(new Runnable() {
754 updateManagedServerControls();
758 } catch (IOException ioe
) {
759 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_GENERATING_CONFIG_FILE
,
762 TaxeditorStorePlugin
.PLUGIN_ID
,
765 } catch (CDMEmbeddedServerException cse
) {
766 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_STARTING_SERVER
,
769 TaxeditorStorePlugin
.PLUGIN_ID
,
775 return Status
.OK_STATUS
;
780 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);
787 private void stopManagedServer() {
789 CdmStore
.getManagedServer().stop();
790 } catch (Exception e
) {
791 MessagingUtils
.errorDialog(Messages
.RemotingLoginDialog_ERROR_STOPPING_SERVER
,
793 String
.format(Messages
.RemotingLoginDialog_COULD_NOT_STOP_SERVER
, CdmStore
.getManagedServer().getPort()),
794 TaxeditorStorePlugin
.PLUGIN_ID
,
798 CdmStore
.setManagedServer(null);
799 updateManagedServerControls();
802 private int getManagedServerPort() {
803 return CdmStore
.getManagedServer() == null ? CdmServerInfo
.NULL_PORT
: CdmStore
.getManagedServer().getPort();
806 private void checkSelectedCdmInstance() {
807 boolean available
= false;
808 String status
= STATUS_NOT_AVAILABLE
;
809 String message
= null;
811 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
)) {
813 if(selectedCsii
.pingInstance(selectedCdmInstance
, getPort())) {
814 status
= STATUS_AVAILABLE
;
817 status
= STATUS_NOT_AVAILABLE
;
822 txtServerCDMVersion
.setText(selectedCsii
.getCdmRemoteSource(selectedCdmInstance
, getPort()).getDbSchemaVersion());
823 int compareDbSchemaVersion
= selectedCsii
.compareDbSchemaVersion(selectedCdmInstance
, getPort());
824 int compareCdmlibServicesVersion
= 0;
825 boolean disableServicesApiTimestampCheck
=
826 PreferencesUtil
.getPreferenceStore().getBoolean((IPreferenceKeys
.DISABLE_SERVICES_API_TIMESTAMP_CHECK
));
827 if(!disableServicesApiTimestampCheck
) {
828 compareCdmlibServicesVersion
= selectedCsii
.compareCdmlibServicesVersion();
830 if(compareDbSchemaVersion
> 0 || compareCdmlibServicesVersion
> 0) {
831 status
= STATUS_NOT_COMPATIBLE
;
833 message
= MESG_COMPATIBLE_EDITOR_OLD
;
834 } else if(compareDbSchemaVersion
< 0 || compareCdmlibServicesVersion
< 0) {
835 status
= STATUS_NOT_COMPATIBLE
;
837 message
= MESG_COMPATIBLE_SERVER_OLD
;
839 status
= STATUS_AVAILABLE
;
841 message
= ""; //$NON-NLS-1$
844 } catch (Exception e
) {
845 txtCdmInstanceStatus
.setToolTipText(e
.getMessage());
847 btnConnect
.setEnabled(available
);
848 txtCdmInstanceStatus
.setText(status
);
849 if(!StringUtils
.isBlank(message
)) {
856 private void connect() {
857 checkSelectedCdmInstance();
859 if(!txtCdmInstanceStatus
.getText().equals(STATUS_AVAILABLE
)) {
863 ICdmRemoteSource source
= selectedCsii
.getCdmRemoteSource(selectedCdmInstance
, getPort());
865 if(!validateLogin(source
)) {
870 CdmStore
.connect(source
, this);
871 } catch (Exception e
) {
872 // Do not expect anything to go wrong at this point, so we throw a runtime exception
874 throw new RuntimeException(e
);
880 public boolean isRememberMe() {
881 return btnRememberMe
.getSelection();
884 private void persistPrefLastServerInstance() {
885 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
886 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
888 lastServerInstancePrefs
.put(LAST_SERVER_KEY
, selectedCsii
.getName());
889 lastServerInstancePrefs
.put(LAST_INSTANCE_KEY
, selectedCdmInstance
.getName());
891 flushPreferences(lastServerInstancePrefs
);
894 private void persistPrefCredentials() {
895 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
896 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
897 credentialsPrefs
.put(getUsernamePrefKey(), txtLogin
.getText());
898 credentialsPrefs
.put(getPasswordPrefKey(), txtPassword
.getText());
899 flushPreferences(credentialsPrefs
);
902 private void flushPreferences(Preferences prefs
) {
905 } catch (BackingStoreException bse
) {
906 setMessage(bse
.getMessage());
910 private void readPrefCredentials() {
911 String username
, password
;
912 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
913 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
914 username
= credentialsPrefs
.get(getUsernamePrefKey(), ""); //$NON-NLS-1$
915 txtLogin
.setText(username
);
916 password
= credentialsPrefs
.get(getPasswordPrefKey(),""); //$NON-NLS-1$
917 txtPassword
.setText(password
);
918 if(username
.isEmpty() || password
.isEmpty()) {
923 private void readPrefLastServerInstance() {
924 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
925 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
927 serverName
= lastServerInstancePrefs
.get(LAST_SERVER_KEY
, null);
928 instanceName
= lastServerInstancePrefs
.get(LAST_INSTANCE_KEY
, null);
931 private void emptyCredentials() {
932 txtLogin
.setText(""); //$NON-NLS-1$
933 txtPassword
.setText(""); //$NON-NLS-1$
936 private String
getUsernamePrefKey() {
937 return selectedCsii
.toString(selectedCdmInstance
.getName(), getPort()) + USERNAME_SUFFIX
;
940 private String
getPasswordPrefKey() {
941 return selectedCsii
.toString(selectedCdmInstance
.getName(), getPort()) + PASSWORD_SUFFIX
;
944 private boolean validateLogin(ICdmRemoteSource remoteSource
) {
945 if(getUsername() == null || getUsername().isEmpty()) {
946 setMessage(""); //$NON-NLS-1$
949 if(getPassword() == null || getPassword().isEmpty()) {
950 setMessage(""); //$NON-NLS-1$
956 IUserService userService
= CdmApplicationRemoteConfiguration
.getUserService(remoteSource
);
957 UsernamePasswordAuthenticationToken token
= new UsernamePasswordAuthenticationToken(getUsername(), getPassword());
958 CdmApplicationRemoteConfiguration
.getAuthenticationManager(userService
).authenticate(token
);
959 } catch(BadCredentialsException e
){
960 setMessage(LoginManager
.INCORRECT_CREDENTIALS_MESSAGE
);
962 } catch(LockedException e
){
963 setMessage(LoginManager
.ACCOUNT_LOCKED_MESSAGE
);
965 } catch(IllegalArgumentException e
){
966 setMessage(LoginManager
.INCORRECT_CREDENTIALS_MESSAGE
);
972 public String
getUsername() {
973 return txtLogin
.getText();
976 public String
getPassword() {
977 return txtPassword
.getText();
980 public void setMessage(String message
) {
981 if(message
!= null && !message
.isEmpty()) {
982 if(message
.length() > 60) {
983 styledTxtMessage
.setToolTipText(message
);
984 message
= message
.substring(0, 60) + "..."; //$NON-NLS-1$
986 styledTxtMessage
.setText(message
);
987 styledTxtMessage
.setVisible(true);
988 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= false;
989 shlConnect
.setSize(MIN_WIDTH
, getHeightWithoutMessage() + MESSAGE_HEIGHT
);
990 shlConnect
.setMinimumSize(MIN_WIDTH
, getHeightWithoutMessage() + MESSAGE_HEIGHT
);
992 styledTxtMessage
.setText(""); //$NON-NLS-1$
993 styledTxtMessage
.setVisible(false);
994 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= true;
995 shlConnect
.setSize(MIN_WIDTH
, getHeightWithoutMessage());
996 shlConnect
.setMinimumSize(MIN_WIDTH
, getHeightWithoutMessage());
998 remotingComposite
.layout();
1001 private int getHeightWithoutMessage() {
1002 if(xpndblcmpstAdvanced
.isExpanded()) {
1003 return MIN_EXP_HEIGHT
;
1010 public void hide(boolean isHidden
) {
1011 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
1012 shlConnect
.setVisible(!isHidden
);
1015 public void dispose() {
1016 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
1017 shlConnect
.dispose();
1021 public void onComplete() {
1022 Display
.getDefault().asyncExec(new Runnable() {
1025 if(!isDevRemoteSource
) {
1026 if(isRememberMe()) {
1027 persistPrefCredentials();
1029 persistPrefLastServerInstance();
1036 private String
generateLastModifiedTooltip(String cdmlibLastModified
) {
1037 if(StringUtils
.isBlank(cdmlibLastModified
)) {
1038 return ""; //$NON-NLS-1$
1040 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy.MM.dd.HH.mm.z"); //$NON-NLS-1$
1041 Date cdmlibLastModifiedDate
;
1042 String cdmlibLastModifiedTimestamp
= ""; //$NON-NLS-1$
1044 cdmlibLastModifiedDate
= new Date(Long
.valueOf(cdmlibLastModified
));
1045 cdmlibLastModifiedTimestamp
= sdf
.format(cdmlibLastModifiedDate
);
1047 return cdmlibLastModifiedTimestamp
;
1050 private void setEditorInfo() {
1051 txtEditorCDMVersion
.setText(CdmMetaData
.getDbSchemaVersion());
1052 String editorVersionTimestamp
= generateLastModifiedTooltip(CdmApplicationState
.getCdmlibLastModified());
1053 txtEditorVersion
.setText(CdmApplicationState
.getCdmlibVersion() + ":" + editorVersionTimestamp
); //$NON-NLS-1$
1056 private void clearOnServerChange() {
1057 setMessage(""); //$NON-NLS-1$
1058 txtServerCDMVersion
.setText(""); //$NON-NLS-1$
1059 txtServerVersion
.setText(""); //$NON-NLS-1$
1060 txtServerVersion
.setToolTipText(""); //$NON-NLS-1$
1061 txtServerCDMVersion
.setText(""); //$NON-NLS-1$
1062 comboCdmInstance
.removeAll();
1063 txtCdmInstanceStatus
.setText(""); //$NON-NLS-1$
1064 txtPort
.setEditable(false);
1065 txtPort
.setEnabled(false);
1068 private void clearOnInstanceChange() {
1069 setMessage(""); //$NON-NLS-1$
1070 txtServerCDMVersion
.setText(""); //$NON-NLS-1$
1077 public void handleError(final Throwable t
) {
1079 Display
.getDefault().syncExec(new Runnable() {
1084 String title
= ""; //$NON-NLS-1$
1085 String message
= t
.getMessage();
1088 MessagingUtils
.errorDialog(title
,
1091 TaxeditorStorePlugin
.PLUGIN_ID
,