Project

General

Profile

Download (45.7 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
 * Copyright (C) 2015 EDIT
4
 * European Distributed Institute of Taxonomy
5
 * http://www.e-taxonomy.eu
6
 *
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.
9
 */
10
package eu.etaxonomy.taxeditor.ui.dialog;
11

    
12
import java.io.File;
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;
18
import java.util.Map;
19

    
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;
55

    
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;
76

    
77

    
78
/**
79
 * @author cmathew
80
 * @date 20 Jan 2015
81
 *
82
 */
83
public class RemotingLoginDialog extends Dialog implements ICDMServerError {
84

    
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;
93

    
94
    private final Map<String, CdmServerInfo> csiiMap = new HashMap<String, CdmServerInfo>();
95

    
96
    private final static String STATUS_AVAILABLE = Messages.RemotingLoginDialog_STATUS_AVAILABLE;
97
    private final static String STATUS_NOT_AVAILABLE = Messages.RemotingLoginDialog_STATUS_NOT_AVAILABLE;
98
    private final static String STATUS_STARTED = Messages.RemotingLoginDialog_STATUS_STARTED;
99
    private final static String STATUS_NOT_STARTED = Messages.RemotingLoginDialog_STATUS_NOT_STARTED;
100
    private final static String STATUS_RETRIEVING = Messages.RemotingLoginDialog_STATUS_RETRIEVING;
101
    private final static String STATUS_CHECKING_AVAILABILITY = Messages.RemotingLoginDialog_STATUS_CHECKING;
102
    private final static String STATUS_NO_INSTANCES = Messages.RemotingLoginDialog_STATUS_NO_INSTANCES_FOUND;
103
    private final static String STATUS_ERROR = Messages.RemotingLoginDialog_STATUS_ERROR;
104
    private final static String STATUS_REMOTING_NOT_ACTIVATED = Messages.RemotingLoginDialog_STATUS_REMOTING_NOT_ACTIVATED;
105
    private final static String STATUS_NOT_COMPATIBLE = Messages.RemotingLoginDialog_STATUS_NOT_COMPATIBLE;
106

    
107
    private final static String MESG_COMPATIBLE_EDITOR_OLD = Messages.RemotingLoginDialog_UPDATE_EDITOR;
108
    private final static String MESG_COMPATIBLE_SERVER_OLD = Messages.RemotingLoginDialog_CHOOSE_COMPATIBLE_CDM_SERVER;
109

    
110
    private final static String STORE_PREFERENCES_NODE = "eu.etaxonomy.taxeditor.store"; //$NON-NLS-1$
111

    
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$
115

    
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$
119

    
120
    private final static String REFRESH_LABEL = Messages.RemotingLoginDialog_LABEL_REFRESH;
121

    
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;
141

    
142

    
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;
153

    
154
    private String serverName, instanceName;
155
    private boolean autoConnect = false;
156
    private boolean loadLoginPrefs = true;
157
    private boolean isDevRemoteSource = false;
158
    private Job serverJob;
159
    /**
160
     * Create the dialog.
161
     * @param parent
162
     * @param style
163
     */
164
    public RemotingLoginDialog(Shell parent, int style) {
165
        super(parent, style);
166
        setText(Messages.RemotingLoginDialog_LABEL_LOGIN);
167
    }
168

    
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);
175
    }
176

    
177

    
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;
183
        return open();
184
    }
185

    
186
    /**
187
     * Open the dialog.
188
     * @return the result
189
     */
190
    public Object open() {
191

    
192
        createContents();
193
        if(serverName == null && instanceName == null) {
194
            readPrefLastServerInstance();
195
        }
196

    
197
        setEditorInfo();
198
        populateCdmServerCombo();
199
        shlConnect.open();
200
        shlConnect.layout();
201

    
202
        xpndblcmpstAdvanced.setExpanded(false);
203

    
204
        Display display = getParent().getDisplay();
205

    
206
        while (!shlConnect.isDisposed()) {
207
            if (!display.readAndDispatch()) {
208
                display.sleep();
209
            }
210
        }
211

    
212
        return result;
213
    }
214

    
215
    /**
216
     * Create contents of the dialog.
217
     */
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(Messages.RemotingLoginDialog_LABEL_CONNECT);
223
        shlConnect.setLayout(new FillLayout(SWT.HORIZONTAL));
224

    
225
        remotingComposite = new Composite(shlConnect, SWT.NONE);
226
        remotingComposite.setLayout(new GridLayout(1, false));
227

    
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));
233

    
234
        Label lblCdmServer = new Label(cdmServerComposite, SWT.NONE);
235
        lblCdmServer.setText(Messages.RemotingLoginDialog_LABEL_CDM_SERVER);
236
        lblCdmServer.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
237
        lblCdmServer.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
238

    
239
        comboCdmServer = new Combo(cdmServerComposite, SWT.READ_ONLY);
240
        comboCdmServer.addSelectionListener(new SelectionAdapter() {
241
            @Override
242
            public void widgetSelected(SelectionEvent e) {
243
                refreshCdmServer();
244

    
245
            }
246
        });
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);
251

    
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);
258

    
259
        btnCdmServerRefresh = new Button(cdmServerComposite, SWT.NONE);
260
        btnCdmServerRefresh.addSelectionListener(new SelectionAdapter() {
261
            @Override
262
            public void widgetSelected(SelectionEvent e) {
263
                refreshCdmServer();
264
            }
265
        });
266
        btnCdmServerRefresh.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
267
        btnCdmServerRefresh.setText(Messages.RemotingLoginDialog_LABEL_REFRESH);
268

    
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(Messages.RemotingLoginDialog_LABEL_CDM_INSTANCE);
274
        lblCdmInstance.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
275

    
276
        comboCdmInstance = new Combo(cdmServerComposite, SWT.READ_ONLY);
277
        comboCdmInstance.addSelectionListener(new SelectionAdapter() {
278
            @Override
279
            public void widgetSelected(SelectionEvent e) {
280
                refreshCdmInstance();
281
            }
282
        });
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);
287

    
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);
294

    
295
        btnCdmInstanceRefresh = new Button(cdmServerComposite, SWT.FLAT);
296
        btnCdmInstanceRefresh.addSelectionListener(new SelectionAdapter() {
297
            @Override
298
            public void widgetSelected(SelectionEvent e) {
299
                refreshCdmInstance();
300
            }
301
        });
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(Messages.RemotingLoginDialog_LABEL_REFRESH);
307

    
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);
316

    
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(Messages.RemotingLoginDialog_LABEL_LOGIN_COLON);
322
        lblLogin.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
323

    
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);
330

    
331
        lblPassword = new Label(loginComposite, SWT.CENTER);
332
        lblPassword.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
333
        lblPassword.setText(Messages.RemotingLoginDialog_LABEL_PASSWORD);
334
        lblPassword.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
335

    
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);
343

    
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() {
347
            @Override
348
            public void mouseUp(MouseEvent e) {
349
                if(selectedCsii.isLocalhostMgd() && !isSelectedCdmInstanceRunningInManagedServer()) {
350
                    startManagedServer();
351
                } else {
352
                    connect();
353
                }
354
            }
355
        });
356
        btnConnect.setText(Messages.RemotingLoginDialog_LABEL_CONNECT);
357

    
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(Messages.RemotingLoginDialog_LABEL_REMEMBER_ME);
364
        new Label(loginComposite, SWT.NONE);
365
        new Label(loginComposite, SWT.NONE);
366
        new Label(loginComposite, SWT.NONE);
367
        new Label(loginComposite, SWT.NONE);
368

    
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);
382

    
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() {
388
            @Override
389
            public void expansionStateChanged(ExpansionEvent e) {
390
                GridData gridData = (GridData) xpndblcmpstAdvanced.getLayoutData();
391
                if(e.getState()) {
392
                    shlConnect.setSize(MIN_WIDTH, MIN_EXP_HEIGHT);
393
                } else {
394
                    shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
395
                }
396

    
397
            }
398
            @Override
399
            public void expansionStateChanging(ExpansionEvent e) {
400
            }
401
        });
402
        xpndblcmpstAdvanced.setText(Messages.RemotingLoginDialog_LABEL_ADVANCED);
403
        xpndblcmpstAdvanced.setExpanded(true);
404

    
405
        compAdvanced = new Composite(xpndblcmpstAdvanced, SWT.NONE);
406
        xpndblcmpstAdvanced.setClient(compAdvanced);
407
        compAdvanced.setLayout(new GridLayout(4, false));
408

    
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(Messages.RemotingLoginDialog_LABEL_PORT);
413
        lblPort.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
414

    
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);
420

    
421
        lblServerVersion = new Label(compAdvanced, SWT.CENTER);
422
        lblServerVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
423
        lblServerVersion.setText(Messages.RemotingLoginDialog_LABEL_SERVER_CDMLIB_VERSION);
424
        lblServerVersion.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
425

    
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() {
432
            @Override
433
            public void mouseUp(MouseEvent e) {
434
                stopManagedServer();
435
            }
436
        });
437
        btnStopServer.setText(Messages.RemotingLoginDialog_LABEL_STOP_MANAGED_SERVER);
438

    
439
        lblEditorVersion = new Label(compAdvanced, SWT.CENTER);
440
        lblEditorVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
441
        lblEditorVersion.setText(Messages.RemotingLoginDialog_LABEL_EDITOR_CDMLIB_VERSION);
442
        lblEditorVersion.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
443

    
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);
449

    
450
        lblServerCDMVersion = new Label(compAdvanced, SWT.CENTER);
451
        lblServerCDMVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
452
        lblServerCDMVersion.setText(Messages.RemotingLoginDialog_LABEL_SERVER_CDM_VERSION);
453
        lblServerCDMVersion.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
454

    
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);
460

    
461
        lblEditorCDMVersion = new Label(compAdvanced, SWT.CENTER);
462
        lblEditorCDMVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
463
        lblEditorCDMVersion.setText(Messages.RemotingLoginDialog_LABEL_EDITOR_CDM_VERSION);
464
        lblEditorCDMVersion.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
465

    
466
        txtEditorCDMVersion = new Text(compAdvanced, SWT.BORDER);
467
        txtEditorCDMVersion.setEditable(false);
468
        txtEditorCDMVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
469

    
470
    }
471

    
472

    
473

    
474
    private void populateCdmServerCombo() {
475
        Job job = new Job(Messages.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES) {
476
            @Override
477
            protected IStatus run(IProgressMonitor monitor) {
478
                Display.getDefault().syncExec(new Runnable() {
479
                    @Override
480
                    public void run() {
481
                        for(CdmServerInfo csii : CdmServerInfo.getCdmServers()) {
482
                            csiiMap.put(csii.getName(), csii);
483
                            comboCdmServer.add(csii.getName());
484
                        }
485
                        int serverIndex = -1;
486
                        if(serverName != null) {
487
                            serverIndex = comboCdmServer.indexOf(serverName);
488
                        }
489
                        if(serverIndex == -1) {
490
                            comboCdmServer.select(0);
491
                            autoConnect = false;
492
                        } else {
493
                            comboCdmServer.select(serverIndex);
494
                        }
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);
504
                            }
505
                        } else {
506
                            refreshCdmServer();
507
                        }
508
                    }
509
                });
510
                return Status.OK_STATUS;
511
            }
512
        };
513
        job.schedule();
514
    }
515

    
516

    
517
    private void refreshCdmServer() {
518
        txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
519
        clearOnServerChange();
520
        emptyCredentials();
521
        updateSelectedCdmServer();
522
        Display.getDefault().asyncExec(new Runnable() {
523
            @Override
524
            public void run() {
525
                checkSelectedCdmServer();
526
            }
527
        });
528

    
529
    }
530

    
531
    private void updateSelectedCdmServer() {
532
        int selIndex = comboCdmServer.getSelectionIndex();
533
        if(selIndex != -1) {
534
            selectedCsii = csiiMap.get(comboCdmServer.getItem(selIndex));
535
        }
536
    }
537

    
538
    private void updatePort() {
539
        txtPort.setText("");
540
        if(selectedCsii != null) {
541
            int port = selectedCsii.getPort();
542
            if(port == CdmServerInfo.NULL_PORT) {
543
                txtPort.setText(CdmServerInfo.NULL_PORT_STRING);
544
            } else {
545
                txtPort.setText(String.valueOf(port));
546
            }
547
        }
548
    }
549

    
550
    private int getPort() {
551
        int port = CdmServerInfo.NULL_PORT;
552
        try {
553
            port = Integer.valueOf(txtPort.getText());
554
        } catch (NumberFormatException nfe) {
555
            if(!CdmServerInfo.NULL_PORT_STRING.equals(txtPort.getText())) {
556
                setMessage(Messages.RemotingLoginDialog_MESSAGE_PORT_SHOULD_BE_INTEGER);
557
            }
558
        }
559
        return port;
560
    }
561

    
562
    private void checkSelectedCdmServer() {
563
        if(selectedCsii != null) {
564
            if(selectedCsii.isLocalhost()) {
565
                txtPort.setEditable(true);
566
                txtPort.setEnabled(true);
567
            }
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$
573
            } else {
574
                txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
575
                comboCdmInstance.removeAll();
576
                disableCdmInstanceControls("", "");
577
            }
578
        }
579
        updatePort();
580
    }
581

    
582

    
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("");
589

    
590
        serverJob = new Job(Messages.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES) {
591
            @Override
592
            protected IStatus run(IProgressMonitor monitor) {
593
                try {
594
                    if(selectedCsii != null) {
595
                        if(forceRefresh) {
596
                            selectedCsii.refreshInstances();
597
                        }
598
                        final List<CdmInstanceInfo> instances = selectedCsii.getInstances();
599
                        Display.getDefault().asyncExec(new Runnable() {
600
                            @Override
601
                            public void run() {
602
                                if(!instances.isEmpty()) {
603
                                    for(CdmInstanceInfo cdmInstance : instances) {
604
                                        comboCdmInstance.add(cdmInstance.getName());
605
                                    }
606
                                    int instanceIndex = -1;
607
                                    if(instanceName != null) {
608
                                        instanceIndex = comboCdmInstance.indexOf(instanceName);
609
                                    }
610
                                    if(instanceIndex == -1) {
611
                                        comboCdmInstance.select(0);
612
                                        autoConnect = false;
613
                                    } else {
614
                                        comboCdmInstance.select(instanceIndex);
615
                                    }
616
                                    refreshCdmInstance();
617
                                    comboCdmInstance.setEnabled(true);
618
                                    if(autoConnect) {
619
                                        connect();
620
                                    }
621

    
622
                                } else {
623
                                    txtCdmInstanceStatus.setText(STATUS_NO_INSTANCES);
624
                                    btnConnect.setEnabled(false);
625
                                }
626
                            }
627
                        });
628
                    }
629
                } catch (final CDMServerException e) {
630
                    MessagingUtils.warn(getClass(), e);
631
                    Display.getDefault().asyncExec(new Runnable() {
632
                        @Override
633
                        public void run() {
634
                            disableCdmInstanceControls(STATUS_NOT_AVAILABLE, e.getMessage());
635
                        }
636
                    });
637
                }
638
                return Status.OK_STATUS;
639
            }
640
        };
641

    
642
        if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE) && !isDevRemoteSource) {
643
            // Start the Job
644
            serverJob.schedule();
645
        }
646
    }
647

    
648
    private void disableCdmInstanceControls(String cdmInstanceStatus, String tooltip) {
649
        txtCdmInstanceStatus.setText(cdmInstanceStatus);
650
        txtCdmInstanceStatus.setToolTipText(tooltip);
651
        comboCdmInstance.setEnabled(false);
652
        btnConnect.setEnabled(false);
653

    
654
    }
655
    private void refreshCdmInstance() {
656
        txtCdmInstanceStatus.setText(STATUS_CHECKING_AVAILABILITY);
657
        clearOnInstanceChange();
658
        updateSelectedCdmInstance();
659
        checkSelectedCdmInstance();
660
        updateManagedServerControls();
661
    }
662

    
663
    private void updateSelectedCdmInstance() {
664
        int selIndex = comboCdmInstance.getSelectionIndex();
665
        if(selIndex != -1) {
666
            selectedCdmInstance = selectedCsii.getInstanceFromName(comboCdmInstance.getItem(selIndex));
667

    
668
            if(loadLoginPrefs && !isDevRemoteSource) {
669
                readPrefCredentials();
670
            }
671
        }
672
    }
673

    
674
    private void updateManagedServerControls() {
675
        if(selectedCsii.isLocalhostMgd()) {
676
            if(isSelectedCdmInstanceRunningInManagedServer()) {
677
                txtCdmInstanceStatus.setText(STATUS_STARTED);
678
            } else {
679
                txtCdmInstanceStatus.setText(STATUS_NOT_STARTED);
680
            }
681
            btnConnect.setEnabled(true);
682
            selectedCsii.setPort(getManagedServerPort());
683
            updatePort();
684
        }
685

    
686

    
687
        if(isManagedServerRunning()) {
688
            btnStopServer.setEnabled(true);
689
        } else {
690
            btnStopServer.setEnabled(false);
691
        }
692
    }
693

    
694
    private boolean isManagedServerRunning() {
695
        return CdmStore.getManagedServer() != null && CdmStore.getManagedServer().isAlive();
696
    }
697

    
698
    private boolean isSelectedCdmInstanceRunningInManagedServer() {
699
        return CdmStore.getManagedServer() != null &&
700
                CdmStore.getManagedServer().isAlive() &&
701
                selectedCsii.isLocalhostMgd() &&
702
                CdmStore.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName());
703
    }
704

    
705
    private void startManagedServer() {
706
        if(isManagedServerRunning()) {
707
            if(CdmStore.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName())) {
708
                return;
709
            } else {
710
                Display.getDefault().syncExec(new Runnable() {
711
                    @Override
712
                    public void run() {
713
                        stopManagedServer();
714
                    }
715
                });
716
            }
717
        }
718

    
719

    
720
        Job job = new Job(Messages.RemotingLoginDialog_JOB_SERVER_LAUNCH) {
721

    
722
            @Override
723
            public IStatus run(IProgressMonitor monitor) {
724
                String mgdServerConfigFileName = "mgd.datasources.xml"; //$NON-NLS-1$
725
                String config = CDMServerUtils.convertEditorToServerConfig();
726
                File managedServerConfigFile;
727
                int maxUnits = 50;
728
                monitor.beginTask(Messages.RemotingLoginDialog_TASK_LAUNCHING_SERVER, maxUnits);
729
                try {
730
                    monitor.subTask(String.format(Messages.RemotingLoginDialog_GENERATING_CONFIG_FILE, selectedCdmInstance.getName()));
731
                    managedServerConfigFile = CDMServerUtils.writeManagedServerConfig(config, mgdServerConfigFileName);
732
                    monitor.worked(1);
733
                    CdmStore.setManagedServer(new CDMServer(selectedCdmInstance.getName(), managedServerConfigFile));
734
                    monitor.subTask(Messages.RemotingLoginDialog_STARTING_MGD_SERVER);
735
                    CdmStore.getManagedServer().start(false, RemotingLoginDialog.this);
736
                    int serverUnits = 0;
737

    
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) {
742
                            try {
743
                                Thread.sleep(1000);
744
                            } catch (InterruptedException e) {
745
                            }
746
                            monitor.worked(1);
747
                            serverUnits++;
748
                        }
749
                    }
750
                    Display.getDefault().asyncExec(new Runnable() {
751
                        @Override
752
                        public void run() {
753
                                hide(false);
754
                                updateManagedServerControls();
755
                                connect();
756
                            }
757
                    });
758
                } catch (IOException ioe) {
759
                    MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_GENERATING_CONFIG_FILE,
760
                            this,
761
                            ioe.getMessage(),
762
                            TaxeditorStorePlugin.PLUGIN_ID,
763
                            ioe,
764
                            true);
765
                } catch (CDMEmbeddedServerException cse) {
766
                    MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_STARTING_SERVER,
767
                            this,
768
                            cse.getMessage(),
769
                            TaxeditorStorePlugin.PLUGIN_ID,
770
                            cse,
771
                            true);
772
                } finally {
773
                    monitor.done();
774
                }
775
                return Status.OK_STATUS;
776
            }
777
        };
778

    
779
        // configure the job
780
        job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
781
        job.setUser(true);
782
        // schedule job
783
        hide(true);
784
        job.schedule();
785
    }
786

    
787
    private void stopManagedServer() {
788
        try {
789
            CdmStore.getManagedServer().stop();
790
        } catch (Exception e) {
791
            MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_STOPPING_SERVER,
792
                    this,
793
                    String.format(Messages.RemotingLoginDialog_COULD_NOT_STOP_SERVER, CdmStore.getManagedServer().getPort()),
794
                    TaxeditorStorePlugin.PLUGIN_ID,
795
                    e,
796
                    true);
797
        }
798
        CdmStore.setManagedServer(null);
799
        updateManagedServerControls();
800
    }
801

    
802
    private int getManagedServerPort() {
803
        return CdmStore.getManagedServer() == null ? CdmServerInfo.NULL_PORT : CdmStore.getManagedServer().getPort();
804
    }
805

    
806
    private void checkSelectedCdmInstance() {
807
        boolean available = false;
808
        String status = STATUS_NOT_AVAILABLE;
809
        String message = null;
810

    
811
        if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
812
            try {
813
                if(selectedCsii.pingInstance(selectedCdmInstance, getPort())) {
814
                    status = STATUS_AVAILABLE;
815
                    available = true;
816
                } else {
817
                    status = STATUS_NOT_AVAILABLE;
818
                    available = false;
819
                }
820

    
821
                if(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();
829
                    }
830
                    if(compareDbSchemaVersion > 0 || compareCdmlibServicesVersion > 0) {
831
                        status =  STATUS_NOT_COMPATIBLE;
832
                        available = false;
833
                        message = MESG_COMPATIBLE_EDITOR_OLD;
834
                    } else if(compareDbSchemaVersion < 0 || compareCdmlibServicesVersion < 0) {
835
                        status = STATUS_NOT_COMPATIBLE;
836
                        available = false;
837
                        message = MESG_COMPATIBLE_SERVER_OLD;
838
                    } else {
839
                        status =  STATUS_AVAILABLE;
840
                        available = true;
841
                        message = ""; //$NON-NLS-1$
842
                    }
843
                }
844
            } catch (Exception e) {
845
                txtCdmInstanceStatus.setToolTipText(e.getMessage());
846
            } finally {
847
                btnConnect.setEnabled(available);
848
                txtCdmInstanceStatus.setText(status);
849
                if(!StringUtils.isBlank(message)) {
850
                    setMessage(message);
851
                }
852
            }
853
        }
854
    }
855

    
856
    private void connect() {
857
        checkSelectedCdmInstance();
858

    
859
        if(!txtCdmInstanceStatus.getText().equals(STATUS_AVAILABLE)) {
860
            return;
861
        }
862

    
863
        ICdmRemoteSource source = selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort());
864

    
865
        if(!validateLogin(source)) {
866
            return;
867
        }
868

    
869
        try {
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
873
            // if any problems
874
            throw new RuntimeException(e);
875
        }
876

    
877
    }
878

    
879

    
880
    public boolean isRememberMe() {
881
        return btnRememberMe.getSelection();
882
    }
883

    
884
    private void persistPrefLastServerInstance() {
885
        IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
886
        Preferences lastServerInstancePrefs = preferences.node(LAST_SERVER_INSTANCE_NODE);
887

    
888
        lastServerInstancePrefs.put(LAST_SERVER_KEY, selectedCsii.getName());
889
        lastServerInstancePrefs.put(LAST_INSTANCE_KEY, selectedCdmInstance.getName());
890

    
891
        flushPreferences(lastServerInstancePrefs);
892
    }
893

    
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);
900
    }
901

    
902
    private void flushPreferences(Preferences prefs) {
903
        try {
904
            prefs.flush();
905
        } catch (BackingStoreException bse) {
906
            setMessage(bse.getMessage());
907
        }
908
    }
909

    
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()) {
919
            autoConnect = false;
920
        }
921
    }
922

    
923
    private void readPrefLastServerInstance() {
924
        IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
925
        Preferences lastServerInstancePrefs = preferences.node(LAST_SERVER_INSTANCE_NODE);
926

    
927
        serverName = lastServerInstancePrefs.get(LAST_SERVER_KEY, null);
928
        instanceName = lastServerInstancePrefs.get(LAST_INSTANCE_KEY, null);
929
    }
930

    
931
    private void emptyCredentials() {
932
        txtLogin.setText("");
933
        txtPassword.setText("");
934
    }
935

    
936
    private String getUsernamePrefKey() {
937
        return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + USERNAME_SUFFIX;
938
    }
939

    
940
    private String getPasswordPrefKey() {
941
        return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + PASSWORD_SUFFIX;
942
    }
943

    
944
    private boolean validateLogin(ICdmRemoteSource remoteSource) {
945
        if(getUsername() == null || getUsername().isEmpty()) {
946
            setMessage(Messages.RemotingLoginDialog_LOGIN_CANNOT_BE_EMPTY);
947
            return false;
948
        }
949
        if(getPassword() == null || getPassword().isEmpty()) {
950
            setMessage(Messages.RemotingLoginDialog_PASSWORD_CANNOT_BE_EMPTY);
951
            return false;
952
        }
953

    
954

    
955
        try {
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);
961
            return false;
962
        } catch(LockedException e){
963
            setMessage(LoginManager.ACCOUNT_LOCKED_MESSAGE);
964
            return false;
965
        } catch(IllegalArgumentException e){
966
            setMessage(LoginManager.INCORRECT_CREDENTIALS_MESSAGE);
967
            return false;
968
        }
969
        return true;
970
    }
971

    
972
    public String getUsername() {
973
        return txtLogin.getText();
974
    }
975

    
976
    public String getPassword() {
977
        return txtPassword.getText();
978
    }
979

    
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$
985
            }
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);
991
        } else {
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());
997
        }
998
        remotingComposite.layout();
999
    }
1000

    
1001
    private int getHeightWithoutMessage() {
1002
        if(xpndblcmpstAdvanced.isExpanded()) {
1003
            return MIN_EXP_HEIGHT;
1004
        } else {
1005
            return MIN_HEIGHT;
1006
        }
1007
    }
1008

    
1009

    
1010
    public void hide(boolean isHidden) {
1011
        if(shlConnect != null && shlConnect.getDisplay() != null) {
1012
            shlConnect.setVisible(!isHidden);
1013
        }
1014
    }
1015
    public void dispose() {
1016
        if(shlConnect != null && shlConnect.getDisplay() != null) {
1017
            shlConnect.dispose();
1018
        }
1019
    }
1020

    
1021
    public void onComplete() {
1022
        Display.getDefault().asyncExec(new Runnable() {
1023
            @Override
1024
            public void run() {
1025
                if(!isDevRemoteSource) {
1026
                    if(isRememberMe()) {
1027
                        persistPrefCredentials();
1028
                    }
1029
                    persistPrefLastServerInstance();
1030
                }
1031
                dispose();
1032
            }
1033
        });
1034
    }
1035

    
1036
    private String generateLastModifiedTooltip(String cdmlibLastModified) {
1037
        if(StringUtils.isBlank(cdmlibLastModified)) {
1038
            return ""; //$NON-NLS-1$
1039
        }
1040
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm.z"); //$NON-NLS-1$
1041
        Date cdmlibLastModifiedDate;
1042
        String cdmlibLastModifiedTimestamp = ""; //$NON-NLS-1$
1043

    
1044
        cdmlibLastModifiedDate = new Date(Long.valueOf(cdmlibLastModified));
1045
        cdmlibLastModifiedTimestamp = sdf.format(cdmlibLastModifiedDate);
1046

    
1047
        return cdmlibLastModifiedTimestamp;
1048
    }
1049

    
1050
    private void setEditorInfo() {
1051
        txtEditorCDMVersion.setText(CdmMetaData.getDbSchemaVersion());
1052
        String editorVersionTimestamp = generateLastModifiedTooltip(CdmApplicationState.getCdmlibLastModified());
1053
        txtEditorVersion.setText(CdmApplicationState.getCdmlibVersion() + ":" + editorVersionTimestamp); //$NON-NLS-1$
1054
    }
1055

    
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);
1066
    }
1067

    
1068
    private void clearOnInstanceChange() {
1069
        setMessage(""); //$NON-NLS-1$
1070
        txtServerCDMVersion.setText(""); //$NON-NLS-1$
1071
    }
1072

    
1073
    /**
1074
     * {@inheritDoc}
1075
     */
1076
    @Override
1077
    public void handleError(final Throwable t) {
1078

    
1079
        Display.getDefault().syncExec(new Runnable() {
1080
            @Override
1081
            public void run() {
1082
                serverJob.cancel();
1083

    
1084
                String title = Messages.RemotingLoginDialog_SERVER_LAUNCH_ERROR;
1085
                String  message = t.getMessage();
1086

    
1087

    
1088
                MessagingUtils.errorDialog(title,
1089
                        this,
1090
                        message,
1091
                        TaxeditorStorePlugin.PLUGIN_ID,
1092
                        t,
1093
                        true);
1094
            }
1095
        });
1096
    }
1097

    
1098

    
1099
}
(4-4/6)