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
.model
.MessagingUtils
;
61 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
62 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
63 import eu
.etaxonomy
.taxeditor
.remoting
.server
.CDMServerException
;
64 import eu
.etaxonomy
.taxeditor
.remoting
.server
.CDMServerUtils
;
65 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmRemoteSource
;
66 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
;
67 import eu
.etaxonomy
.taxeditor
.remoting
.source
.CdmServerInfo
.CdmInstanceInfo
;
68 import eu
.etaxonomy
.taxeditor
.remoting
.source
.ICdmRemoteSource
;
69 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
70 import eu
.etaxonomy
.taxeditor
.store
.LoginManager
;
71 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
72 import eu
.etaxonomy
.taxeditor
.webapp
.CDMEmbeddedServerException
;
73 import eu
.etaxonomy
.taxeditor
.webapp
.CDMServer
;
74 import eu
.etaxonomy
.taxeditor
.webapp
.ICDMServerError
;
82 public class RemotingLoginDialog
extends Dialog
implements ICDMServerError
{
84 protected Object result
;
85 protected Shell shlConnect
;
86 private Text txtCdmServerStatus
;
87 private Text txtCdmInstanceStatus
;
88 private Combo comboCdmServer
;
89 private Combo comboCdmInstance
;
90 private Button btnConnect
;
92 private final Map
<String
, CdmServerInfo
> csiiMap
= new HashMap
<String
, CdmServerInfo
>();
94 private final static String STATUS_AVAILABLE
= "Available";
95 private final static String STATUS_NOT_AVAILABLE
= "Not Available";
96 private final static String STATUS_STARTED
= "Started";
97 private final static String STATUS_NOT_STARTED
= "Not Started";
98 private final static String STATUS_RETRIEVING
= "Retrieving ...";
99 private final static String STATUS_CHECKING_AVAILABILITY
= "Checking ...";
100 private final static String STATUS_NO_INSTANCES
= "No Instances Found";
101 private final static String STATUS_ERROR
= "Error";
102 private final static String STATUS_REMOTING_NOT_ACTIVATED
= "Remoting not activated";
103 private final static String STATUS_NOT_COMPATIBLE
= "Not Compatible";
105 private final static String MESG_COMPATIBLE_EDITOR_OLD
= "Please update the Taxonomic Editor (Help->Check for Updates) or choose a compatible cdm-server";
106 private final static String MESG_COMPATIBLE_SERVER_OLD
= "Please choose a compatible cdm-server or update the chosen cdm-server";
108 private final static String STORE_PREFERENCES_NODE
= "eu.etaxonomy.taxeditor.store";
110 private final static String LOGIN_NODE
= "login";
111 private final static String USERNAME_SUFFIX
= "_username";
112 private final static String PASSWORD_SUFFIX
= "_password";
114 private final static String LAST_SERVER_INSTANCE_NODE
= "lastServerInstance";
115 private final static String LAST_SERVER_KEY
= "lastServerKey";
116 private final static String LAST_INSTANCE_KEY
= "lastInstanceKey";
118 private final static String REFRESH_LABEL
= "Refresh";
120 private Composite remotingComposite
;
121 private CdmServerInfo selectedCsii
;
122 private CdmInstanceInfo selectedCdmInstance
;
123 private Button btnCdmServerRefresh
;
124 private Button btnCdmInstanceRefresh
;
125 private Button btnStopServer
;
126 private Composite loginComposite
;
127 private Label lblLogin
;
128 private Text txtLogin
;
129 private Label lblPassword
;
130 private Text txtPassword
;
131 private Button btnRememberMe
;
132 private Composite compAdvanced
;
133 private Label lblPort
;
134 private Text txtPort
;
135 private Label lblServerVersion
;
136 private Text txtServerVersion
;
137 private ExpandableComposite xpndblcmpstAdvanced
;
138 private StyledText styledTxtMessage
;
141 private final int MIN_WIDTH
= 530;
142 private final int MIN_HEIGHT
= 220;
143 private final int MIN_EXP_HEIGHT
= 380;
144 private final int MESSAGE_HEIGHT
= 25;
145 private Label lblEditorVersion
;
146 private Text txtEditorVersion
;
147 private Label lblServerCDMVersion
;
148 private Text txtServerCDMVersion
;
149 private Label lblEditorCDMVersion
;
150 private Text txtEditorCDMVersion
;
152 private String serverName
, instanceName
;
153 private boolean autoConnect
= false;
154 private boolean loadLoginPrefs
= true;
155 private boolean isDevRemoteSource
= false;
156 private Job serverJob
;
162 public RemotingLoginDialog(Shell parent
, int style
) {
163 super(parent
, style
);
167 public Object
open(CdmRemoteSource source
, boolean loadLoginPrefs
, boolean autoConnect
) {
168 this.loadLoginPrefs
= loadLoginPrefs
;
169 this.serverName
= source
.getName();
170 String contextPath
= source
.getContextPath();
171 this.instanceName
= contextPath
.substring(contextPath
.lastIndexOf("/") + 1);
172 return open(serverName
, instanceName
, loadLoginPrefs
, autoConnect
);
176 public Object
open(String serverName
, String instanceName
, boolean loadLoginPrefs
, boolean autoConnect
) {
177 this.serverName
= serverName
;
178 this.instanceName
= instanceName
;
179 this.loadLoginPrefs
= loadLoginPrefs
;
180 this.autoConnect
= autoConnect
;
188 public Object
open() {
191 if(serverName
== null && instanceName
== null) {
192 readPrefLastServerInstance();
196 populateCdmServerCombo();
200 xpndblcmpstAdvanced
.setExpanded(false);
202 Display display
= getParent().getDisplay();
204 while (!shlConnect
.isDisposed()) {
205 if (!display
.readAndDispatch()) {
214 * Create contents of the dialog.
216 private void createContents() {
217 shlConnect
= new Shell(getParent(), SWT
.DIALOG_TRIM
);
218 shlConnect
.setMinimumSize(new Point(MIN_WIDTH
, MIN_HEIGHT
));
219 shlConnect
.setSize(MIN_WIDTH
, MIN_HEIGHT
);
220 shlConnect
.setText("Connect");
221 shlConnect
.setLayout(new FillLayout(SWT
.HORIZONTAL
));
223 remotingComposite
= new Composite(shlConnect
, SWT
.NONE
);
224 remotingComposite
.setLayout(new GridLayout(1, false));
226 Composite cdmServerComposite
= new Composite(remotingComposite
, SWT
.NONE
);
227 GridData gd_cdmServerComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
228 gd_cdmServerComposite
.heightHint
= 68;
229 cdmServerComposite
.setLayoutData(gd_cdmServerComposite
);
230 cdmServerComposite
.setLayout(new GridLayout(4, false));
232 Label lblCdmServer
= new Label(cdmServerComposite
, SWT
.NONE
);
233 lblCdmServer
.setText("CDM Server : ");
234 lblCdmServer
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
235 lblCdmServer
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
237 comboCdmServer
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
238 comboCdmServer
.addSelectionListener(new SelectionAdapter() {
240 public void widgetSelected(SelectionEvent e
) {
245 GridData gd_comboCdmServer
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
246 gd_comboCdmServer
.widthHint
= 150;
247 comboCdmServer
.setLayoutData(gd_comboCdmServer
);
248 comboCdmServer
.select(0);
250 txtCdmServerStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
251 txtCdmServerStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
252 txtCdmServerStatus
.setEditable(false);
253 GridData gd_txtCdmServerStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
254 gd_txtCdmServerStatus
.widthHint
= 100;
255 txtCdmServerStatus
.setLayoutData(gd_txtCdmServerStatus
);
257 btnCdmServerRefresh
= new Button(cdmServerComposite
, SWT
.NONE
);
258 btnCdmServerRefresh
.addSelectionListener(new SelectionAdapter() {
260 public void widgetSelected(SelectionEvent e
) {
264 btnCdmServerRefresh
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
265 btnCdmServerRefresh
.setText("Refresh");
267 Label lblCdmInstance
= new Label(cdmServerComposite
, SWT
.NONE
);
268 GridData gd_lblCdmInstance
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
269 gd_lblCdmInstance
.heightHint
= 30;
270 lblCdmInstance
.setLayoutData(gd_lblCdmInstance
);
271 lblCdmInstance
.setText("CDM Instance : ");
272 lblCdmInstance
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
274 comboCdmInstance
= new Combo(cdmServerComposite
, SWT
.READ_ONLY
);
275 comboCdmInstance
.addSelectionListener(new SelectionAdapter() {
277 public void widgetSelected(SelectionEvent e
) {
278 refreshCdmInstance();
281 GridData gd_comboCdmInstance
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
282 gd_comboCdmInstance
.widthHint
= 150;
283 comboCdmInstance
.setLayoutData(gd_comboCdmInstance
);
284 comboCdmInstance
.select(0);
286 txtCdmInstanceStatus
= new Text(cdmServerComposite
, SWT
.BORDER
);
287 txtCdmInstanceStatus
.setBackground(SWTResourceManager
.getColor(SWT
.COLOR_INFO_BACKGROUND
));
288 txtCdmInstanceStatus
.setEditable(false);
289 GridData gd_txtCdmInstanceStatus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
290 gd_txtCdmInstanceStatus
.widthHint
= 100;
291 txtCdmInstanceStatus
.setLayoutData(gd_txtCdmInstanceStatus
);
293 btnCdmInstanceRefresh
= new Button(cdmServerComposite
, SWT
.FLAT
);
294 btnCdmInstanceRefresh
.addSelectionListener(new SelectionAdapter() {
296 public void widgetSelected(SelectionEvent e
) {
297 refreshCdmInstance();
300 GridData gd_btnCdmInstanceRefresh
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1);
301 gd_btnCdmInstanceRefresh
.widthHint
= 110;
302 gd_btnCdmInstanceRefresh
.heightHint
= 30;
303 btnCdmInstanceRefresh
.setLayoutData(gd_btnCdmInstanceRefresh
);
304 btnCdmInstanceRefresh
.setText("Refresh");
306 loginComposite
= new Composite(remotingComposite
, SWT
.NONE
);
307 GridData gd_loginComposite
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
308 gd_loginComposite
.widthHint
= 487;
309 gd_loginComposite
.heightHint
= 70;
310 loginComposite
.setLayoutData(gd_loginComposite
);
311 GridLayout gl_loginComposite
= new GridLayout(6, false);
312 gl_loginComposite
.marginTop
= 5;
313 loginComposite
.setLayout(gl_loginComposite
);
315 lblLogin
= new Label(loginComposite
, SWT
.CENTER
);
316 GridData gd_lblLogin
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1);
317 gd_lblLogin
.widthHint
= 50;
318 lblLogin
.setLayoutData(gd_lblLogin
);
319 lblLogin
.setText("Login : ");
320 lblLogin
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
322 txtLogin
= new Text(loginComposite
, SWT
.BORDER
);
323 GridData gd_txtLogin
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
324 gd_txtLogin
.minimumWidth
= 80;
325 gd_txtLogin
.widthHint
= 80;
326 gd_txtLogin
.heightHint
= 15;
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("Password : ");
332 lblPassword
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
334 txtPassword
= new Text(loginComposite
, SWT
.BORDER
| SWT
.PASSWORD
);
335 GridData gd_txtPassword
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
336 gd_txtPassword
.minimumWidth
= 80;
337 gd_txtPassword
.widthHint
= 80;
338 gd_txtPassword
.heightHint
= 15;
339 txtPassword
.setLayoutData(gd_txtPassword
);
340 new Label(loginComposite
, SWT
.NONE
);
342 btnConnect
= new Button(loginComposite
, SWT
.FLAT
);
343 btnConnect
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1));
344 btnConnect
.addMouseListener(new MouseAdapter() {
346 public void mouseUp(MouseEvent e
) {
347 if(selectedCsii
.isLocalhostMgd() && !isSelectedCdmInstanceRunningInManagedServer()) {
348 startManagedServer();
354 btnConnect
.setText("Connect");
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 gd_btnRememberMe
.widthHint
= 107;
360 btnRememberMe
.setLayoutData(gd_btnRememberMe
);
361 btnRememberMe
.setText("Remember Me");
362 new Label(loginComposite
, SWT
.NONE
);
363 new Label(loginComposite
, SWT
.NONE
);
364 new Label(loginComposite
, SWT
.NONE
);
365 new Label(loginComposite
, SWT
.NONE
);
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
.setFont(SWTResourceManager
.getFont("Ubuntu", 12, SWT
.BOLD
));
371 styledTxtMessage
.setSelectionBackground(SWTResourceManager
.getColor(SWT
.COLOR_LIST_SELECTION_TEXT
));
372 styledTxtMessage
.setSelectionForeground(SWTResourceManager
.getColor(SWT
.COLOR_DARK_RED
));
373 styledTxtMessage
.setDoubleClickEnabled(false);
374 styledTxtMessage
.setEditable(false);
375 GridData gd_styledTxtMessage
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 1);
376 gd_styledTxtMessage
.exclude
= true;
377 gd_styledTxtMessage
.minimumHeight
= MESSAGE_HEIGHT
;
378 gd_styledTxtMessage
.heightHint
= MESSAGE_HEIGHT
;
379 styledTxtMessage
.setLayoutData(gd_styledTxtMessage
);
381 xpndblcmpstAdvanced
= new ExpandableComposite(remotingComposite
, SWT
.NONE
, ExpandableComposite
.TWISTIE
);
382 GridData gd_xpndblcmpstAdvanced
= new GridData(SWT
.FILL
, SWT
.FILL
, false, true, 1, 1);
383 gd_xpndblcmpstAdvanced
.heightHint
= 19;
384 xpndblcmpstAdvanced
.setLayoutData(gd_xpndblcmpstAdvanced
);
385 xpndblcmpstAdvanced
.addExpansionListener(new IExpansionListener() {
387 public void expansionStateChanged(ExpansionEvent e
) {
388 GridData gridData
= (GridData
) xpndblcmpstAdvanced
.getLayoutData();
390 shlConnect
.setSize(MIN_WIDTH
, MIN_EXP_HEIGHT
);
392 shlConnect
.setSize(MIN_WIDTH
, MIN_HEIGHT
);
397 public void expansionStateChanging(ExpansionEvent e
) {
400 xpndblcmpstAdvanced
.setText("advanced");
401 xpndblcmpstAdvanced
.setExpanded(true);
403 compAdvanced
= new Composite(xpndblcmpstAdvanced
, SWT
.NONE
);
404 xpndblcmpstAdvanced
.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
.setSize(0, 0);
410 lblPort
.setText("Port : ");
411 lblPort
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
413 txtPort
= new Text(compAdvanced
, SWT
.BORDER
);
414 GridData gd_txtPort
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1);
415 gd_txtPort
.minimumWidth
= 50;
416 gd_txtPort
.widthHint
= 50;
417 txtPort
.setLayoutData(gd_txtPort
);
419 lblServerVersion
= new Label(compAdvanced
, SWT
.CENTER
);
420 lblServerVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
421 lblServerVersion
.setText("Server Cdmlib Version :");
422 lblServerVersion
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
424 txtServerVersion
= new Text(compAdvanced
, SWT
.BORDER
);
425 txtServerVersion
.setEditable(false);
426 txtServerVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 1, 1));
427 btnStopServer
= new Button(compAdvanced
, SWT
.FLAT
);
428 btnStopServer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 2, 1));
429 btnStopServer
.addMouseListener(new MouseAdapter() {
431 public void mouseUp(MouseEvent e
) {
435 btnStopServer
.setText("Stop Managed Server");
437 lblEditorVersion
= new Label(compAdvanced
, SWT
.CENTER
);
438 lblEditorVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
439 lblEditorVersion
.setText("Editor Cdmlib Version :");
440 lblEditorVersion
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
442 txtEditorVersion
= new Text(compAdvanced
, SWT
.BORDER
);
443 txtEditorVersion
.setEditable(false);
444 txtEditorVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
445 new Label(compAdvanced
, SWT
.NONE
);
446 new Label(compAdvanced
, SWT
.NONE
);
448 lblServerCDMVersion
= new Label(compAdvanced
, SWT
.CENTER
);
449 lblServerCDMVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
450 lblServerCDMVersion
.setText("Server CDM Version :");
451 lblServerCDMVersion
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
453 txtServerCDMVersion
= new Text(compAdvanced
, SWT
.BORDER
);
454 txtServerCDMVersion
.setEditable(false);
455 txtServerCDMVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
456 new Label(compAdvanced
, SWT
.NONE
);
457 new Label(compAdvanced
, SWT
.NONE
);
459 lblEditorCDMVersion
= new Label(compAdvanced
, SWT
.CENTER
);
460 lblEditorCDMVersion
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
461 lblEditorCDMVersion
.setText("Editor CDM Version :");
462 lblEditorCDMVersion
.setFont(SWTResourceManager
.getFont("Ubuntu", 9, SWT
.NORMAL
));
464 txtEditorCDMVersion
= new Text(compAdvanced
, SWT
.BORDER
);
465 txtEditorCDMVersion
.setEditable(false);
466 txtEditorCDMVersion
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
472 private void populateCdmServerCombo() {
473 Job job
= new Job("Retrieve Server Instances") {
475 protected IStatus
run(IProgressMonitor monitor
) {
476 Display
.getDefault().syncExec(new Runnable() {
479 for(CdmServerInfo csii
: CdmServerInfo
.getCdmServers()) {
480 csiiMap
.put(csii
.getName(), csii
);
481 comboCdmServer
.add(csii
.getName());
483 int serverIndex
= -1;
484 if(serverName
!= null) {
485 serverIndex
= comboCdmServer
.indexOf(serverName
);
487 if(serverIndex
== -1) {
488 comboCdmServer
.select(0);
491 comboCdmServer
.select(serverIndex
);
493 CdmRemoteSource devRemoteSource
= CdmServerInfo
.getDevServerRemoteSource();
494 if(devRemoteSource
!= null) {
495 isDevRemoteSource
= true;
496 String username
= System
.getProperty("cdm.server.dev.username");
497 String password
= System
.getProperty("cdm.server.dev.password");
498 if(username
!= null && !username
.isEmpty() && password
!= null && !password
.isEmpty()) {
499 txtLogin
.setText(username
);
500 txtPassword
.setText(password
);
501 CdmStore
.connect(devRemoteSource
, RemotingLoginDialog
.this);
508 return Status
.OK_STATUS
;
515 private void refreshCdmServer() {
516 txtCdmServerStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
517 clearOnServerChange();
519 updateSelectedCdmServer();
520 Display
.getDefault().asyncExec(new Runnable() {
523 checkSelectedCdmServer();
529 private void updateSelectedCdmServer() {
530 int selIndex
= comboCdmServer
.getSelectionIndex();
532 selectedCsii
= csiiMap
.get(comboCdmServer
.getItem(selIndex
));
536 private void updatePort() {
538 if(selectedCsii
!= null) {
539 int port
= selectedCsii
.getPort();
540 if(port
== CdmServerInfo
.NULL_PORT
) {
541 txtPort
.setText(CdmServerInfo
.NULL_PORT_STRING
);
543 txtPort
.setText(String
.valueOf(port
));
548 private int getPort() {
549 int port
= CdmServerInfo
.NULL_PORT
;
551 port
= Integer
.valueOf(txtPort
.getText());
552 } catch (NumberFormatException nfe
) {
553 if(!CdmServerInfo
.NULL_PORT_STRING
.equals(txtPort
.getText())) {
554 setMessage("Port should be an integer");
560 private void checkSelectedCdmServer() {
561 if(selectedCsii
!= null) {
562 if(selectedCsii
.isLocalhost()) {
563 txtPort
.setEditable(true);
564 txtPort
.setEnabled(true);
566 if(selectedCsii
.pingServer()) {
567 txtCdmServerStatus
.setText(STATUS_AVAILABLE
);
568 populateCdmInstanceCombo(true);
569 String serverVersionTimestamp
= generateLastModifiedTooltip(selectedCsii
.getCdmlibLastModified());
570 txtServerVersion
.setText(selectedCsii
.getCdmlibServicesVersion() + ":" + serverVersionTimestamp
);
572 txtCdmServerStatus
.setText(STATUS_NOT_AVAILABLE
);
573 comboCdmInstance
.removeAll();
574 disableCdmInstanceControls("", "");
581 private void populateCdmInstanceCombo(final boolean forceRefresh
) {
582 comboCdmInstance
.removeAll();
583 comboCdmInstance
.setEnabled(false);
584 btnConnect
.setEnabled(false);
585 txtCdmInstanceStatus
.setText(STATUS_RETRIEVING
);
586 txtCdmInstanceStatus
.setToolTipText("");
588 serverJob
= new Job("Retrieve Server Instances") {
590 protected IStatus
run(IProgressMonitor monitor
) {
592 if(selectedCsii
!= null) {
594 selectedCsii
.refreshInstances();
596 final List
<CdmInstanceInfo
> instances
= selectedCsii
.getInstances();
597 Display
.getDefault().asyncExec(new Runnable() {
600 if(!instances
.isEmpty()) {
601 for(CdmInstanceInfo cdmInstance
: instances
) {
602 comboCdmInstance
.add(cdmInstance
.getName());
604 int instanceIndex
= -1;
605 if(instanceName
!= null) {
606 instanceIndex
= comboCdmInstance
.indexOf(instanceName
);
608 if(instanceIndex
== -1) {
609 comboCdmInstance
.select(0);
612 comboCdmInstance
.select(instanceIndex
);
614 refreshCdmInstance();
615 comboCdmInstance
.setEnabled(true);
621 txtCdmInstanceStatus
.setText(STATUS_NO_INSTANCES
);
622 btnConnect
.setEnabled(false);
627 } catch (final CDMServerException e
) {
628 MessagingUtils
.warn(getClass(), e
);
629 Display
.getDefault().asyncExec(new Runnable() {
632 disableCdmInstanceControls(STATUS_NOT_AVAILABLE
, e
.getMessage());
636 return Status
.OK_STATUS
;
640 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
) && !isDevRemoteSource
) {
642 serverJob
.schedule();
646 private void disableCdmInstanceControls(String cdmInstanceStatus
, String tooltip
) {
647 txtCdmInstanceStatus
.setText(cdmInstanceStatus
);
648 txtCdmInstanceStatus
.setToolTipText(tooltip
);
649 comboCdmInstance
.setEnabled(false);
650 btnConnect
.setEnabled(false);
653 private void refreshCdmInstance() {
654 txtCdmInstanceStatus
.setText(STATUS_CHECKING_AVAILABILITY
);
655 clearOnInstanceChange();
656 updateSelectedCdmInstance();
657 checkSelectedCdmInstance();
658 updateManagedServerControls();
661 private void updateSelectedCdmInstance() {
662 int selIndex
= comboCdmInstance
.getSelectionIndex();
664 selectedCdmInstance
= selectedCsii
.getInstanceFromName(comboCdmInstance
.getItem(selIndex
));
666 if(loadLoginPrefs
&& !isDevRemoteSource
) {
667 readPrefCredentials();
672 private void updateManagedServerControls() {
673 if(selectedCsii
.isLocalhostMgd()) {
674 if(isSelectedCdmInstanceRunningInManagedServer()) {
675 txtCdmInstanceStatus
.setText(STATUS_STARTED
);
677 txtCdmInstanceStatus
.setText(STATUS_NOT_STARTED
);
679 btnConnect
.setEnabled(true);
680 selectedCsii
.setPort(getManagedServerPort());
685 if(isManagedServerRunning()) {
686 btnStopServer
.setEnabled(true);
688 btnStopServer
.setEnabled(false);
692 private boolean isManagedServerRunning() {
693 return CdmStore
.getManagedServer() != null && CdmStore
.getManagedServer().isAlive();
696 private boolean isSelectedCdmInstanceRunningInManagedServer() {
697 return CdmStore
.getManagedServer() != null &&
698 CdmStore
.getManagedServer().isAlive() &&
699 selectedCsii
.isLocalhostMgd() &&
700 CdmStore
.getManagedServer().getDataSourceName().equals(selectedCdmInstance
.getName());
703 private void startManagedServer() {
704 if(isManagedServerRunning()) {
705 if(CdmStore
.getManagedServer().getDataSourceName().equals(selectedCdmInstance
.getName())) {
708 Display
.getDefault().syncExec(new Runnable() {
718 Job job
= new Job("Managed CDM Server Launch") {
721 public IStatus
run(IProgressMonitor monitor
) {
722 String mgdServerConfigFileName
= "mgd.datasources.xml";
723 String config
= CDMServerUtils
.convertEditorToServerConfig();
724 File managedServerConfigFile
;
726 monitor
.beginTask("Launching Managed CDM Server", maxUnits
);
728 monitor
.subTask("Generating datasources config file for " + selectedCdmInstance
.getName());
729 managedServerConfigFile
= CDMServerUtils
.writeManagedServerConfig(config
, mgdServerConfigFileName
);
731 CdmStore
.setManagedServer(new CDMServer(selectedCdmInstance
.getName(), managedServerConfigFile
));
732 monitor
.subTask("Starting Managed CDM Server. This may take a while.");
733 CdmStore
.getManagedServer().start(false, RemotingLoginDialog
.this);
736 // the following loop is a 'fake' progress monitoring where the progress
737 // bar is advanced by one unit every second until maxUnits -2
738 while(!CdmStore
.getManagedServer().isStarted()) {
739 if(serverUnits
< maxUnits
- 2) {
742 } catch (InterruptedException e
) {
748 Display
.getDefault().asyncExec(new Runnable() {
752 updateManagedServerControls();
756 } catch (IOException ioe
) {
757 MessagingUtils
.errorDialog("Error generating server config file",
760 TaxeditorStorePlugin
.PLUGIN_ID
,
763 } catch (CDMEmbeddedServerException cse
) {
764 MessagingUtils
.errorDialog("Error starting managed server",
767 TaxeditorStorePlugin
.PLUGIN_ID
,
773 return Status
.OK_STATUS
;
778 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);
785 private void stopManagedServer() {
787 CdmStore
.getManagedServer().stop();
788 } catch (Exception e
) {
789 MessagingUtils
.errorDialog("Error stopping managed server",
791 "Could not stop managed server running at port " + CdmStore
.getManagedServer().getPort() + ". Please stop it manually",
792 TaxeditorStorePlugin
.PLUGIN_ID
,
796 CdmStore
.setManagedServer(null);
797 updateManagedServerControls();
800 private int getManagedServerPort() {
801 return CdmStore
.getManagedServer() == null ? CdmServerInfo
.NULL_PORT
: CdmStore
.getManagedServer().getPort();
804 private void checkSelectedCdmInstance() {
805 boolean available
= false;
806 String status
= STATUS_NOT_AVAILABLE
;
807 String message
= null;
809 if(txtCdmServerStatus
.getText().equals(STATUS_AVAILABLE
)) {
811 if(selectedCsii
.pingInstance(selectedCdmInstance
, getPort())) {
812 status
= STATUS_AVAILABLE
;
815 status
= STATUS_NOT_AVAILABLE
;
820 txtServerCDMVersion
.setText(selectedCsii
.getCdmRemoteSource(selectedCdmInstance
, getPort()).getDbSchemaVersion());
821 int compareDbSchemaVersion
= selectedCsii
.compareDbSchemaVersion(selectedCdmInstance
, getPort());
822 int compareCdmlibServicesVersion
= 0;
823 boolean disableServicesApiTimestampCheck
=
824 PreferencesUtil
.getPreferenceStore().getBoolean((IPreferenceKeys
.DISABLE_SERVICES_API_TIMESTAMP_CHECK
));
825 if(!disableServicesApiTimestampCheck
) {
826 compareCdmlibServicesVersion
= selectedCsii
.compareCdmlibServicesVersion();
828 if(compareDbSchemaVersion
> 0 || compareCdmlibServicesVersion
> 0) {
829 status
= STATUS_NOT_COMPATIBLE
;
831 message
= MESG_COMPATIBLE_EDITOR_OLD
;
832 } else if(compareDbSchemaVersion
< 0 || compareCdmlibServicesVersion
< 0) {
833 status
= STATUS_NOT_COMPATIBLE
;
835 message
= MESG_COMPATIBLE_SERVER_OLD
;
837 status
= STATUS_AVAILABLE
;
842 } catch (Exception e
) {
843 txtCdmInstanceStatus
.setToolTipText(e
.getMessage());
845 btnConnect
.setEnabled(available
);
846 txtCdmInstanceStatus
.setText(status
);
847 if(!StringUtils
.isBlank(message
)) {
854 private void connect() {
855 checkSelectedCdmInstance();
857 if(!txtCdmInstanceStatus
.getText().equals(STATUS_AVAILABLE
)) {
861 ICdmRemoteSource source
= selectedCsii
.getCdmRemoteSource(selectedCdmInstance
, getPort());
863 if(!validateLogin(source
)) {
868 CdmStore
.connect(source
, this);
869 } catch (Exception e
) {
870 // Do not expect anything to go wrong at this point, so we throw a runtime exception
872 throw new RuntimeException(e
);
878 public boolean isRememberMe() {
879 return btnRememberMe
.getSelection();
882 private void persistPrefLastServerInstance() {
883 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
884 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
886 lastServerInstancePrefs
.put(LAST_SERVER_KEY
, selectedCsii
.getName());
887 lastServerInstancePrefs
.put(LAST_INSTANCE_KEY
, selectedCdmInstance
.getName());
889 flushPreferences(lastServerInstancePrefs
);
892 private void persistPrefCredentials() {
893 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
894 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
895 credentialsPrefs
.put(getUsernamePrefKey(), txtLogin
.getText());
896 credentialsPrefs
.put(getPasswordPrefKey(), txtPassword
.getText());
897 flushPreferences(credentialsPrefs
);
900 private void flushPreferences(Preferences prefs
) {
903 } catch (BackingStoreException bse
) {
904 setMessage(bse
.getMessage());
908 private void readPrefCredentials() {
909 String username
, password
;
910 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
911 Preferences credentialsPrefs
= preferences
.node(LOGIN_NODE
);
912 username
= credentialsPrefs
.get(getUsernamePrefKey(), "");
913 txtLogin
.setText(username
);
914 password
= credentialsPrefs
.get(getPasswordPrefKey(),"");
915 txtPassword
.setText(password
);
916 if(username
.isEmpty() || password
.isEmpty()) {
921 private void readPrefLastServerInstance() {
922 IEclipsePreferences preferences
= ConfigurationScope
.INSTANCE
.getNode(STORE_PREFERENCES_NODE
);
923 Preferences lastServerInstancePrefs
= preferences
.node(LAST_SERVER_INSTANCE_NODE
);
925 serverName
= lastServerInstancePrefs
.get(LAST_SERVER_KEY
, null);
926 instanceName
= lastServerInstancePrefs
.get(LAST_INSTANCE_KEY
, null);
929 private void emptyCredentials() {
930 txtLogin
.setText("");
931 txtPassword
.setText("");
934 private String
getUsernamePrefKey() {
935 return selectedCsii
.toString(selectedCdmInstance
.getName(), getPort()) + USERNAME_SUFFIX
;
938 private String
getPasswordPrefKey() {
939 return selectedCsii
.toString(selectedCdmInstance
.getName(), getPort()) + PASSWORD_SUFFIX
;
942 private boolean validateLogin(ICdmRemoteSource remoteSource
) {
943 if(getUsername() == null || getUsername().isEmpty()) {
944 setMessage("User login cannot be empty");
947 if(getPassword() == null || getPassword().isEmpty()) {
948 setMessage("Password cannot be empty");
954 IUserService userService
= CdmApplicationRemoteConfiguration
.getUserService(remoteSource
);
955 UsernamePasswordAuthenticationToken token
= new UsernamePasswordAuthenticationToken(getUsername(), getPassword());
956 CdmApplicationRemoteConfiguration
.getAuthenticationManager(userService
).authenticate(token
);
957 } catch(BadCredentialsException e
){
958 setMessage(LoginManager
.INCORRECT_CREDENTIALS_MESSAGE
);
960 } catch(LockedException e
){
961 setMessage(LoginManager
.ACCOUNT_LOCKED_MESSAGE
);
963 } catch(IllegalArgumentException e
){
964 setMessage(LoginManager
.INCORRECT_CREDENTIALS_MESSAGE
);
970 public String
getUsername() {
971 return txtLogin
.getText();
974 public String
getPassword() {
975 return txtPassword
.getText();
978 public void setMessage(String message
) {
979 if(message
!= null && !message
.isEmpty()) {
980 if(message
.length() > 60) {
981 styledTxtMessage
.setToolTipText(message
);
982 message
= message
.substring(0, 60) + "...";
984 styledTxtMessage
.setText(message
);
985 styledTxtMessage
.setVisible(true);
986 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= false;
987 shlConnect
.setSize(MIN_WIDTH
, getHeightWithoutMessage() + MESSAGE_HEIGHT
);
988 shlConnect
.setMinimumSize(MIN_WIDTH
, getHeightWithoutMessage() + MESSAGE_HEIGHT
);
990 styledTxtMessage
.setText("");
991 styledTxtMessage
.setVisible(false);
992 ((GridData
)styledTxtMessage
.getLayoutData()).exclude
= true;
993 shlConnect
.setSize(MIN_WIDTH
, getHeightWithoutMessage());
994 shlConnect
.setMinimumSize(MIN_WIDTH
, getHeightWithoutMessage());
996 remotingComposite
.layout();
999 private int getHeightWithoutMessage() {
1000 if(xpndblcmpstAdvanced
.isExpanded()) {
1001 return MIN_EXP_HEIGHT
;
1008 public void hide(boolean isHidden
) {
1009 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
1010 shlConnect
.setVisible(!isHidden
);
1013 public void dispose() {
1014 if(shlConnect
!= null && shlConnect
.getDisplay() != null) {
1015 shlConnect
.dispose();
1019 public void onComplete() {
1020 Display
.getDefault().asyncExec(new Runnable() {
1023 if(!isDevRemoteSource
) {
1024 if(isRememberMe()) {
1025 persistPrefCredentials();
1027 persistPrefLastServerInstance();
1034 private String
generateLastModifiedTooltip(String cdmlibLastModified
) {
1035 if(StringUtils
.isBlank(cdmlibLastModified
)) {
1038 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy.MM.dd.HH.mm.z");
1039 Date cdmlibLastModifiedDate
;
1040 String cdmlibLastModifiedTimestamp
= "";
1042 cdmlibLastModifiedDate
= new Date(Long
.valueOf(cdmlibLastModified
));
1043 cdmlibLastModifiedTimestamp
= sdf
.format(cdmlibLastModifiedDate
);
1045 return cdmlibLastModifiedTimestamp
;
1048 private void setEditorInfo() {
1049 txtEditorCDMVersion
.setText(CdmMetaData
.getDbSchemaVersion());
1050 String editorVersionTimestamp
= generateLastModifiedTooltip(CdmApplicationState
.getCdmlibLastModified());
1051 txtEditorVersion
.setText(CdmApplicationState
.getCdmlibVersion() + ":" + editorVersionTimestamp
);
1054 private void clearOnServerChange() {
1056 txtServerCDMVersion
.setText("");
1057 txtServerVersion
.setText("");
1058 txtServerVersion
.setToolTipText("");
1059 txtServerCDMVersion
.setText("");
1060 comboCdmInstance
.removeAll();
1061 txtCdmInstanceStatus
.setText("");
1062 txtPort
.setEditable(false);
1063 txtPort
.setEnabled(false);
1066 private void clearOnInstanceChange() {
1068 txtServerCDMVersion
.setText("");
1075 public void handleError(final Throwable t
) {
1077 Display
.getDefault().syncExec(new Runnable() {
1082 String title
= "CDM Server launch error";
1083 String message
= t
.getMessage();
1086 MessagingUtils
.errorDialog(title
,
1089 TaxeditorStorePlugin
.PLUGIN_ID
,