Project

General

Profile

Download (45.9 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.KeyAdapter;
30
import org.eclipse.swt.events.KeyEvent;
31
import org.eclipse.swt.events.MouseAdapter;
32
import org.eclipse.swt.events.MouseEvent;
33
import org.eclipse.swt.events.SelectionAdapter;
34
import org.eclipse.swt.events.SelectionEvent;
35
import org.eclipse.swt.graphics.Point;
36
import org.eclipse.swt.layout.FillLayout;
37
import org.eclipse.swt.layout.GridData;
38
import org.eclipse.swt.layout.GridLayout;
39
import org.eclipse.swt.widgets.Button;
40
import org.eclipse.swt.widgets.Combo;
41
import org.eclipse.swt.widgets.Composite;
42
import org.eclipse.swt.widgets.Dialog;
43
import org.eclipse.swt.widgets.Display;
44
import org.eclipse.swt.widgets.Label;
45
import org.eclipse.swt.widgets.Shell;
46
import org.eclipse.swt.widgets.Text;
47
import org.eclipse.ui.forms.events.ExpansionEvent;
48
import org.eclipse.ui.forms.events.IExpansionListener;
49
import org.eclipse.ui.forms.widgets.ExpandableComposite;
50
import org.eclipse.ui.progress.IProgressConstants;
51
import org.eclipse.wb.swt.SWTResourceManager;
52
import org.osgi.service.prefs.BackingStoreException;
53
import org.osgi.service.prefs.Preferences;
54
import org.springframework.security.authentication.BadCredentialsException;
55
import org.springframework.security.authentication.LockedException;
56
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
57

    
58
import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteConfiguration;
59
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
60
import eu.etaxonomy.cdm.api.service.IUserService;
61
import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
62
import eu.etaxonomy.taxeditor.Messages;
63
import eu.etaxonomy.taxeditor.model.MessagingUtils;
64
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
65
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
66
import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
67
import eu.etaxonomy.taxeditor.remoting.server.CDMServerUtils;
68
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
69
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo;
70
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo.CdmInstanceInfo;
71
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
72
import eu.etaxonomy.taxeditor.store.CdmStore;
73
import eu.etaxonomy.taxeditor.store.LoginManager;
74
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
75
import eu.etaxonomy.taxeditor.webapp.CDMEmbeddedServerException;
76
import eu.etaxonomy.taxeditor.webapp.CDMServer;
77
import eu.etaxonomy.taxeditor.webapp.ICDMServerError;
78

    
79

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

    
87
    private static final String UBUNTU = "Ubuntu"; //$NON-NLS-1$
88
	protected Object result;
89
    protected Shell shlConnect;
90
    private Text txtCdmServerStatus;
91
    private Text txtCdmInstanceStatus;
92
    private Combo comboCdmServer;
93
    private Combo comboCdmInstance;
94
    private Button btnConnect;
95

    
96
    private final Map<String, CdmServerInfo> csiiMap = new HashMap<String, CdmServerInfo>();
97

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

    
109
    private final static String MESG_COMPATIBLE_EDITOR_OLD = Messages.RemotingLoginDialog_UPDATE_EDITOR;
110
    private final static String MESG_COMPATIBLE_SERVER_OLD = Messages.RemotingLoginDialog_CHOOSE_COMPATIBLE_CDM_SERVER;
111

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

    
114
    private final static String LOGIN_NODE = "login"; //$NON-NLS-1$
115
    private final static String USERNAME_SUFFIX = "_username"; //$NON-NLS-1$
116
    private final static String PASSWORD_SUFFIX = "_password"; //$NON-NLS-1$
117

    
118
    private final static String LAST_SERVER_INSTANCE_NODE = "lastServerInstance"; //$NON-NLS-1$
119
    private final static String LAST_SERVER_KEY = "lastServerKey"; //$NON-NLS-1$
120
    private final static String LAST_INSTANCE_KEY = "lastInstanceKey"; //$NON-NLS-1$
121

    
122
    private final static String REFRESH_LABEL = Messages.RemotingLoginDialog_LABEL_REFRESH;
123

    
124
    private Composite remotingComposite;
125
    private CdmServerInfo selectedCsii;
126
    private CdmInstanceInfo selectedCdmInstance;
127
    private Button btnCdmServerRefresh;
128
    private Button btnCdmInstanceRefresh;
129
    private Button btnStopServer;
130
    private Composite loginComposite;
131
    private Label lblLogin;
132
    private Text txtLogin;
133
    private Label lblPassword;
134
    private Text txtPassword;
135
    private Button btnRememberMe;
136
    private Composite compAdvanced;
137
    private Label lblPort;
138
    private Text txtPort;
139
    private Label lblServerVersion;
140
    private Text txtServerVersion;
141
    private ExpandableComposite xpndblcmpstAdvanced;
142
    private StyledText styledTxtMessage;
143

    
144

    
145
    private final int MIN_WIDTH = 530;
146
    private final int MIN_HEIGHT = 220;
147
    private final int MIN_EXP_HEIGHT = 380;
148
    private final int MESSAGE_HEIGHT = 25;
149
    private Label lblEditorVersion;
150
    private Text txtEditorVersion;
151
    private Label lblServerCDMVersion;
152
    private Text txtServerCDMVersion;
153
    private Label lblEditorCDMVersion;
154
    private Text txtEditorCDMVersion;
155

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

    
171
    public Object open(CdmRemoteSource source, boolean loadLoginPrefs, boolean autoConnect) {
172
        this.loadLoginPrefs = loadLoginPrefs;
173
        this.serverName = source.getName();
174
        String contextPath = source.getContextPath();
175
        this.instanceName = contextPath.substring(contextPath.lastIndexOf("/") + 1); //$NON-NLS-1$
176
        return open(serverName, instanceName, loadLoginPrefs, autoConnect);
177
    }
178

    
179

    
180
    public Object open(String serverName, String instanceName, boolean loadLoginPrefs, boolean autoConnect) {
181
        this.serverName = serverName;
182
        this.instanceName = instanceName;
183
        this.loadLoginPrefs = loadLoginPrefs;
184
        this.autoConnect = autoConnect;
185
        return open();
186
    }
187

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

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

    
199
        setEditorInfo();
200
        populateCdmServerCombo();
201
        shlConnect.open();
202
        shlConnect.layout();
203

    
204
        xpndblcmpstAdvanced.setExpanded(false);
205

    
206
        Display display = getParent().getDisplay();
207

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

    
214
        return result;
215
    }
216

    
217
    /**
218
     * Create contents of the dialog.
219
     */
220
    private void createContents() {
221
        shlConnect = new Shell(getParent(), SWT.DIALOG_TRIM);
222
        shlConnect.setMinimumSize(new Point(MIN_WIDTH, MIN_HEIGHT));
223
        shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
224
        shlConnect.setText(Messages.RemotingLoginDialog_LABEL_CONNECT);
225
        shlConnect.setLayout(new FillLayout(SWT.HORIZONTAL));
226

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

    
230
        Composite cdmServerComposite = new Composite(remotingComposite, SWT.NONE);
231
        GridData gd_cdmServerComposite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
232
        gd_cdmServerComposite.heightHint = 68;
233
        cdmServerComposite.setLayoutData(gd_cdmServerComposite);
234
        cdmServerComposite.setLayout(new GridLayout(4, false));
235

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

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

    
247
            }
248
        });
249
        GridData gd_comboCdmServer = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
250
        gd_comboCdmServer.widthHint = 150;
251
        comboCdmServer.setLayoutData(gd_comboCdmServer);
252
        comboCdmServer.select(0);
253

    
254
        txtCdmServerStatus = new Text(cdmServerComposite, SWT.BORDER);
255
        txtCdmServerStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
256
        txtCdmServerStatus.setEditable(false);
257
        GridData gd_txtCdmServerStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
258
        gd_txtCdmServerStatus.widthHint = 100;
259
        txtCdmServerStatus.setLayoutData(gd_txtCdmServerStatus);
260

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

    
271
        Label lblCdmInstance = new Label(cdmServerComposite, SWT.NONE);
272
        GridData gd_lblCdmInstance = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
273
        gd_lblCdmInstance.heightHint = 30;
274
        lblCdmInstance.setLayoutData(gd_lblCdmInstance);
275
        lblCdmInstance.setText(Messages.RemotingLoginDialog_LABEL_CDM_INSTANCE);
276
        lblCdmInstance.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
277

    
278
        comboCdmInstance = new Combo(cdmServerComposite, SWT.READ_ONLY);
279
        comboCdmInstance.addSelectionListener(new SelectionAdapter() {
280
            @Override
281
            public void widgetSelected(SelectionEvent e) {
282
                refreshCdmInstance();
283
            }
284
        });
285
        GridData gd_comboCdmInstance = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
286
        gd_comboCdmInstance.widthHint = 150;
287
        comboCdmInstance.setLayoutData(gd_comboCdmInstance);
288
        comboCdmInstance.select(0);
289

    
290
        txtCdmInstanceStatus = new Text(cdmServerComposite, SWT.BORDER);
291
        txtCdmInstanceStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
292
        txtCdmInstanceStatus.setEditable(false);
293
        GridData gd_txtCdmInstanceStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
294
        gd_txtCdmInstanceStatus.widthHint = 100;
295
        txtCdmInstanceStatus.setLayoutData(gd_txtCdmInstanceStatus);
296

    
297
        btnCdmInstanceRefresh = new Button(cdmServerComposite, SWT.FLAT);
298
        btnCdmInstanceRefresh.addSelectionListener(new SelectionAdapter() {
299
            @Override
300
            public void widgetSelected(SelectionEvent e) {
301
                refreshCdmInstance();
302
            }
303
        });
304
        GridData gd_btnCdmInstanceRefresh = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
305
        gd_btnCdmInstanceRefresh.widthHint = 110;
306
        gd_btnCdmInstanceRefresh.heightHint = 30;
307
        btnCdmInstanceRefresh.setLayoutData(gd_btnCdmInstanceRefresh);
308
        btnCdmInstanceRefresh.setText(Messages.RemotingLoginDialog_LABEL_REFRESH);
309

    
310
        loginComposite = new Composite(remotingComposite, SWT.NONE);
311
        GridData gd_loginComposite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
312
        gd_loginComposite.widthHint = 487;
313
        gd_loginComposite.heightHint = 70;
314
        loginComposite.setLayoutData(gd_loginComposite);
315
        GridLayout gl_loginComposite = new GridLayout(6, false);
316
        gl_loginComposite.marginTop = 5;
317
        loginComposite.setLayout(gl_loginComposite);
318

    
319
        lblLogin = new Label(loginComposite, SWT.CENTER);
320
        GridData gd_lblLogin = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
321
        gd_lblLogin.widthHint = 50;
322
        lblLogin.setLayoutData(gd_lblLogin);
323
        lblLogin.setText(Messages.RemotingLoginDialog_LABEL_LOGIN_COLON);
324
        lblLogin.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
325

    
326
        txtLogin = new Text(loginComposite, SWT.BORDER);
327
        GridData gd_txtLogin = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
328
        gd_txtLogin.minimumWidth = 80;
329
        gd_txtLogin.widthHint = 80;
330
        gd_txtLogin.heightHint = 15;
331
        txtLogin.setLayoutData(gd_txtLogin);
332

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

    
338
        txtPassword = new Text(loginComposite, SWT.BORDER | SWT.PASSWORD);
339
        GridData gd_txtPassword = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
340
        gd_txtPassword.minimumWidth = 80;
341
        gd_txtPassword.widthHint = 80;
342
        gd_txtPassword.heightHint = 15;
343
        txtPassword.setLayoutData(gd_txtPassword);
344
        new Label(loginComposite, SWT.NONE);
345
        txtPassword.addKeyListener(new KeyAdapter() {
346
        	@Override
347
        	public void keyPressed(KeyEvent e) {
348
        		if(e.character==SWT.CR){
349
        			connectButtonPressed();
350
        		}
351
        	}
352
        });
353

    
354
        btnConnect = new Button(loginComposite, SWT.FLAT);
355
        btnConnect.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
356
        btnConnect.addSelectionListener(new SelectionAdapter() {
357
			@Override
358
			public void widgetSelected(SelectionEvent e) {
359
				connectButtonPressed();
360
			}
361
		});
362
        btnConnect.setText(Messages.RemotingLoginDialog_LABEL_CONNECT);
363

    
364
        btnRememberMe = new Button(loginComposite, SWT.CHECK);
365
        btnRememberMe.setSelection(true);
366
        GridData gd_btnRememberMe = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);
367
        btnRememberMe.setLayoutData(gd_btnRememberMe);
368
        btnRememberMe.setText(Messages.RemotingLoginDialog_LABEL_REMEMBER_ME);
369
        new Label(loginComposite, SWT.NONE);
370
        new Label(loginComposite, SWT.NONE);
371
        new Label(loginComposite, SWT.NONE);
372
        new Label(loginComposite, SWT.NONE);
373

    
374
        styledTxtMessage = new StyledText(remotingComposite, SWT.NONE);
375
        styledTxtMessage.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
376
        styledTxtMessage.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));
377
        styledTxtMessage.setFont(SWTResourceManager.getFont(UBUNTU, 12, SWT.BOLD));
378
        styledTxtMessage.setSelectionBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_SELECTION_TEXT));
379
        styledTxtMessage.setSelectionForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));
380
        styledTxtMessage.setDoubleClickEnabled(false);
381
        styledTxtMessage.setEditable(false);
382
        GridData gd_styledTxtMessage = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
383
        gd_styledTxtMessage.exclude = true;
384
        gd_styledTxtMessage.minimumHeight = MESSAGE_HEIGHT;
385
        gd_styledTxtMessage.heightHint = MESSAGE_HEIGHT;
386
        styledTxtMessage.setLayoutData(gd_styledTxtMessage);
387

    
388
        xpndblcmpstAdvanced = new ExpandableComposite(remotingComposite, SWT.NONE, ExpandableComposite.TWISTIE);
389
        GridData gd_xpndblcmpstAdvanced = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
390
        gd_xpndblcmpstAdvanced.heightHint = 19;
391
        xpndblcmpstAdvanced.setLayoutData(gd_xpndblcmpstAdvanced);
392
        xpndblcmpstAdvanced.addExpansionListener(new IExpansionListener() {
393
            @Override
394
            public void expansionStateChanged(ExpansionEvent e) {
395
                GridData gridData = (GridData) xpndblcmpstAdvanced.getLayoutData();
396
                if(e.getState()) {
397
                    shlConnect.setSize(MIN_WIDTH, MIN_EXP_HEIGHT);
398
                } else {
399
                    shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
400
                }
401

    
402
            }
403
            @Override
404
            public void expansionStateChanging(ExpansionEvent e) {
405
            }
406
        });
407
        xpndblcmpstAdvanced.setText(Messages.RemotingLoginDialog_LABEL_ADVANCED);
408
        xpndblcmpstAdvanced.setExpanded(true);
409

    
410
        compAdvanced = new Composite(xpndblcmpstAdvanced, SWT.NONE);
411
        xpndblcmpstAdvanced.setClient(compAdvanced);
412
        compAdvanced.setLayout(new GridLayout(4, false));
413

    
414
        lblPort = new Label(compAdvanced, SWT.CENTER);
415
        lblPort.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
416
        lblPort.setSize(0, 0);
417
        lblPort.setText(Messages.RemotingLoginDialog_LABEL_PORT);
418
        lblPort.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
419

    
420
        txtPort = new Text(compAdvanced, SWT.BORDER);
421
        GridData gd_txtPort = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
422
        gd_txtPort.minimumWidth = 50;
423
        gd_txtPort.widthHint = 50;
424
        txtPort.setLayoutData(gd_txtPort);
425

    
426
        lblServerVersion = new Label(compAdvanced, SWT.CENTER);
427
        lblServerVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
428
        lblServerVersion.setText(Messages.RemotingLoginDialog_LABEL_SERVER_CDMLIB_VERSION);
429
        lblServerVersion.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
430

    
431
        txtServerVersion = new Text(compAdvanced, SWT.BORDER);
432
        txtServerVersion.setEditable(false);
433
        txtServerVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
434
        btnStopServer = new Button(compAdvanced, SWT.FLAT);
435
        btnStopServer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
436
        btnStopServer.addMouseListener(new MouseAdapter() {
437
            @Override
438
            public void mouseUp(MouseEvent e) {
439
                stopManagedServer();
440
            }
441
        });
442
        btnStopServer.setText(Messages.RemotingLoginDialog_LABEL_STOP_MANAGED_SERVER);
443

    
444
        lblEditorVersion = new Label(compAdvanced, SWT.CENTER);
445
        lblEditorVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
446
        lblEditorVersion.setText(Messages.RemotingLoginDialog_LABEL_EDITOR_CDMLIB_VERSION);
447
        lblEditorVersion.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
448

    
449
        txtEditorVersion = new Text(compAdvanced, SWT.BORDER);
450
        txtEditorVersion.setEditable(false);
451
        txtEditorVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
452
        new Label(compAdvanced, SWT.NONE);
453
        new Label(compAdvanced, SWT.NONE);
454

    
455
        lblServerCDMVersion = new Label(compAdvanced, SWT.CENTER);
456
        lblServerCDMVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
457
        lblServerCDMVersion.setText(Messages.RemotingLoginDialog_LABEL_SERVER_CDM_VERSION);
458
        lblServerCDMVersion.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
459

    
460
        txtServerCDMVersion = new Text(compAdvanced, SWT.BORDER);
461
        txtServerCDMVersion.setEditable(false);
462
        txtServerCDMVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
463
        new Label(compAdvanced, SWT.NONE);
464
        new Label(compAdvanced, SWT.NONE);
465

    
466
        lblEditorCDMVersion = new Label(compAdvanced, SWT.CENTER);
467
        lblEditorCDMVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
468
        lblEditorCDMVersion.setText(Messages.RemotingLoginDialog_LABEL_EDITOR_CDM_VERSION);
469
        lblEditorCDMVersion.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
470

    
471
        txtEditorCDMVersion = new Text(compAdvanced, SWT.BORDER);
472
        txtEditorCDMVersion.setEditable(false);
473
        txtEditorCDMVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
474

    
475
    }
476

    
477
	private void connectButtonPressed() {
478
		if(selectedCsii.isLocalhostMgd() && !isSelectedCdmInstanceRunningInManagedServer()) {
479
			startManagedServer();
480
		} else {
481
			connect();
482
		}
483
	}
484

    
485
    private void populateCdmServerCombo() {
486
        Job job = new Job(Messages.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES) {
487
            @Override
488
            protected IStatus run(IProgressMonitor monitor) {
489
                Display.getDefault().syncExec(new Runnable() {
490
                    @Override
491
                    public void run() {
492
                        for(CdmServerInfo csii : CdmServerInfo.getCdmServers()) {
493
                            csiiMap.put(csii.getName(), csii);
494
                            comboCdmServer.add(csii.getName());
495
                        }
496
                        int serverIndex = -1;
497
                        if(serverName != null) {
498
                            serverIndex = comboCdmServer.indexOf(serverName);
499
                        }
500
                        if(serverIndex == -1) {
501
                            comboCdmServer.select(0);
502
                            autoConnect = false;
503
                        } else {
504
                            comboCdmServer.select(serverIndex);
505
                        }
506
                        CdmRemoteSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
507
                        if(devRemoteSource != null) {
508
                            isDevRemoteSource = true;
509
                            String username = System.getProperty("cdm.server.dev.username"); //$NON-NLS-1$
510
                            String password = System.getProperty("cdm.server.dev.password"); //$NON-NLS-1$
511
                            if(username != null && !username.isEmpty() && password != null && !password.isEmpty()) {
512
                                txtLogin.setText(username);
513
                                txtPassword.setText(password);
514
                                CdmStore.connect(devRemoteSource, RemotingLoginDialog.this);
515
                            }
516
                        } else {
517
                            refreshCdmServer();
518
                        }
519
                    }
520
                });
521
                return Status.OK_STATUS;
522
            }
523
        };
524
        job.schedule();
525
    }
526

    
527

    
528
    private void refreshCdmServer() {
529
        txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
530
        clearOnServerChange();
531
        emptyCredentials();
532
        updateSelectedCdmServer();
533
        Display.getDefault().asyncExec(new Runnable() {
534
            @Override
535
            public void run() {
536
                checkSelectedCdmServer();
537
            }
538
        });
539

    
540
    }
541

    
542
    private void updateSelectedCdmServer() {
543
        int selIndex = comboCdmServer.getSelectionIndex();
544
        if(selIndex != -1) {
545
            selectedCsii = csiiMap.get(comboCdmServer.getItem(selIndex));
546
        }
547
    }
548

    
549
    private void updatePort() {
550
        txtPort.setText("");
551
        if(selectedCsii != null) {
552
            int port = selectedCsii.getPort();
553
            if(port == CdmServerInfo.NULL_PORT) {
554
                txtPort.setText(CdmServerInfo.NULL_PORT_STRING);
555
            } else {
556
                txtPort.setText(String.valueOf(port));
557
            }
558
        }
559
    }
560

    
561
    private int getPort() {
562
        int port = CdmServerInfo.NULL_PORT;
563
        try {
564
            port = Integer.valueOf(txtPort.getText());
565
        } catch (NumberFormatException nfe) {
566
            if(!CdmServerInfo.NULL_PORT_STRING.equals(txtPort.getText())) {
567
                setMessage(Messages.RemotingLoginDialog_MESSAGE_PORT_SHOULD_BE_INTEGER);
568
            }
569
        }
570
        return port;
571
    }
572

    
573
    private void checkSelectedCdmServer() {
574
        if(selectedCsii != null) {
575
            if(selectedCsii.isLocalhost()) {
576
                txtPort.setEditable(true);
577
                txtPort.setEnabled(true);
578
            }
579
            if(selectedCsii.pingServer()) {
580
                txtCdmServerStatus.setText(STATUS_AVAILABLE);
581
                populateCdmInstanceCombo(true);
582
                String serverVersionTimestamp = generateLastModifiedTooltip(selectedCsii.getCdmlibLastModified());
583
                txtServerVersion.setText(selectedCsii.getCdmlibServicesVersion() + ":" + serverVersionTimestamp); //$NON-NLS-1$
584
            } else {
585
                txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
586
                comboCdmInstance.removeAll();
587
                disableCdmInstanceControls("", "");
588
            }
589
        }
590
        updatePort();
591
    }
592

    
593

    
594
    private void populateCdmInstanceCombo(final boolean forceRefresh) {
595
        comboCdmInstance.removeAll();
596
        comboCdmInstance.setEnabled(false);
597
        btnConnect.setEnabled(false);
598
        txtCdmInstanceStatus.setText(STATUS_RETRIEVING);
599
        txtCdmInstanceStatus.setToolTipText("");
600

    
601
        serverJob = new Job(Messages.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES) {
602
            @Override
603
            protected IStatus run(IProgressMonitor monitor) {
604
                try {
605
                    if(selectedCsii != null) {
606
                        if(forceRefresh) {
607
                            selectedCsii.refreshInstances();
608
                        }
609
                        final List<CdmInstanceInfo> instances = selectedCsii.getInstances();
610
                        Display.getDefault().asyncExec(new Runnable() {
611
                            @Override
612
                            public void run() {
613
                                if(!instances.isEmpty()) {
614
                                    for(CdmInstanceInfo cdmInstance : instances) {
615
                                        comboCdmInstance.add(cdmInstance.getName());
616
                                    }
617
                                    int instanceIndex = -1;
618
                                    if(instanceName != null) {
619
                                        instanceIndex = comboCdmInstance.indexOf(instanceName);
620
                                    }
621
                                    if(instanceIndex == -1) {
622
                                        comboCdmInstance.select(0);
623
                                        autoConnect = false;
624
                                    } else {
625
                                        comboCdmInstance.select(instanceIndex);
626
                                    }
627
                                    refreshCdmInstance();
628
                                    comboCdmInstance.setEnabled(true);
629
                                    if(autoConnect) {
630
                                        connect();
631
                                    }
632

    
633
                                } else {
634
                                    txtCdmInstanceStatus.setText(STATUS_NO_INSTANCES);
635
                                    btnConnect.setEnabled(false);
636
                                }
637
                            }
638
                        });
639
                    }
640
                } catch (final CDMServerException e) {
641
                    MessagingUtils.warn(getClass(), e);
642
                    Display.getDefault().asyncExec(new Runnable() {
643
                        @Override
644
                        public void run() {
645
                            disableCdmInstanceControls(STATUS_NOT_AVAILABLE, e.getMessage());
646
                        }
647
                    });
648
                }
649
                return Status.OK_STATUS;
650
            }
651
        };
652

    
653
        if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE) && !isDevRemoteSource) {
654
            // Start the Job
655
            serverJob.schedule();
656
        }
657
    }
658

    
659
    private void disableCdmInstanceControls(String cdmInstanceStatus, String tooltip) {
660
        txtCdmInstanceStatus.setText(cdmInstanceStatus);
661
        txtCdmInstanceStatus.setToolTipText(tooltip);
662
        comboCdmInstance.setEnabled(false);
663
        btnConnect.setEnabled(false);
664

    
665
    }
666
    private void refreshCdmInstance() {
667
        txtCdmInstanceStatus.setText(STATUS_CHECKING_AVAILABILITY);
668
        clearOnInstanceChange();
669
        updateSelectedCdmInstance();
670
        checkSelectedCdmInstance();
671
        updateManagedServerControls();
672
    }
673

    
674
    private void updateSelectedCdmInstance() {
675
        int selIndex = comboCdmInstance.getSelectionIndex();
676
        if(selIndex != -1) {
677
            selectedCdmInstance = selectedCsii.getInstanceFromName(comboCdmInstance.getItem(selIndex));
678

    
679
            if(loadLoginPrefs && !isDevRemoteSource) {
680
                readPrefCredentials();
681
            }
682
        }
683
    }
684

    
685
    private void updateManagedServerControls() {
686
        if(selectedCsii.isLocalhostMgd()) {
687
            if(isSelectedCdmInstanceRunningInManagedServer()) {
688
                txtCdmInstanceStatus.setText(STATUS_STARTED);
689
            } else {
690
                txtCdmInstanceStatus.setText(STATUS_NOT_STARTED);
691
            }
692
            btnConnect.setEnabled(true);
693
            selectedCsii.setPort(getManagedServerPort());
694
            updatePort();
695
        }
696

    
697

    
698
        if(isManagedServerRunning()) {
699
            btnStopServer.setEnabled(true);
700
        } else {
701
            btnStopServer.setEnabled(false);
702
        }
703
    }
704

    
705
    private boolean isManagedServerRunning() {
706
        return CdmStore.getManagedServer() != null && CdmStore.getManagedServer().isAlive();
707
    }
708

    
709
    private boolean isSelectedCdmInstanceRunningInManagedServer() {
710
        return CdmStore.getManagedServer() != null &&
711
                CdmStore.getManagedServer().isAlive() &&
712
                selectedCsii.isLocalhostMgd() &&
713
                CdmStore.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName());
714
    }
715

    
716
    private void startManagedServer() {
717
        if(isManagedServerRunning()) {
718
            if(CdmStore.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName())) {
719
                return;
720
            } else {
721
                Display.getDefault().syncExec(new Runnable() {
722
                    @Override
723
                    public void run() {
724
                        stopManagedServer();
725
                    }
726
                });
727
            }
728
        }
729

    
730

    
731
        Job job = new Job(Messages.RemotingLoginDialog_JOB_SERVER_LAUNCH) {
732

    
733
            @Override
734
            public IStatus run(IProgressMonitor monitor) {
735
                String mgdServerConfigFileName = "mgd.datasources.xml"; //$NON-NLS-1$
736
                String config = CDMServerUtils.convertEditorToServerConfig();
737
                File managedServerConfigFile;
738
                int maxUnits = 50;
739
                monitor.beginTask(Messages.RemotingLoginDialog_TASK_LAUNCHING_SERVER, maxUnits);
740
                try {
741
                    monitor.subTask(String.format(Messages.RemotingLoginDialog_GENERATING_CONFIG_FILE, selectedCdmInstance.getName()));
742
                    managedServerConfigFile = CDMServerUtils.writeManagedServerConfig(config, mgdServerConfigFileName);
743
                    monitor.worked(1);
744
                    CdmStore.setManagedServer(new CDMServer(selectedCdmInstance.getName(), managedServerConfigFile));
745
                    monitor.subTask(Messages.RemotingLoginDialog_STARTING_MGD_SERVER);
746
                    CdmStore.getManagedServer().start(false, RemotingLoginDialog.this);
747
                    int serverUnits = 0;
748

    
749
                    // the following loop is a 'fake' progress monitoring where the progress
750
                    // bar is advanced by one unit every second until maxUnits -2
751
                    while(!CdmStore.getManagedServer().isStarted() && !CdmStore.getManagedServer().isFailed()) {
752
                        if(serverUnits < maxUnits - 2) {
753
                            try {
754
                                Thread.sleep(1000);
755
                            } catch (InterruptedException e) {
756
                            }
757
                            monitor.worked(1);
758
                            serverUnits++;
759
                        }
760
                    }
761
                    Display.getDefault().asyncExec(new Runnable() {
762
                        @Override
763
                        public void run() {
764
                                hide(false);
765
                                updateManagedServerControls();
766
                                connect();
767
                            }
768
                    });
769
                } catch (IOException ioe) {
770
                    MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_GENERATING_CONFIG_FILE,
771
                            this,
772
                            ioe.getMessage(),
773
                            TaxeditorStorePlugin.PLUGIN_ID,
774
                            ioe,
775
                            true);
776
                } catch (CDMEmbeddedServerException cse) {
777
                    MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_STARTING_SERVER,
778
                            this,
779
                            cse.getMessage(),
780
                            TaxeditorStorePlugin.PLUGIN_ID,
781
                            cse,
782
                            true);
783
                } finally {
784
                    monitor.done();
785
                }
786
                return Status.OK_STATUS;
787
            }
788
        };
789

    
790
        // configure the job
791
        job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
792
        job.setUser(true);
793
        // schedule job
794
        hide(true);
795
        job.schedule();
796
    }
797

    
798
    private void stopManagedServer() {
799
        try {
800
            CdmStore.getManagedServer().stop();
801
        } catch (Exception e) {
802
            MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_STOPPING_SERVER,
803
                    this,
804
                    String.format(Messages.RemotingLoginDialog_COULD_NOT_STOP_SERVER, CdmStore.getManagedServer().getPort()),
805
                    TaxeditorStorePlugin.PLUGIN_ID,
806
                    e,
807
                    true);
808
        }
809
        CdmStore.setManagedServer(null);
810
        updateManagedServerControls();
811
    }
812

    
813
    private int getManagedServerPort() {
814
        return CdmStore.getManagedServer() == null ? CdmServerInfo.NULL_PORT : CdmStore.getManagedServer().getPort();
815
    }
816

    
817
    private void checkSelectedCdmInstance() {
818
        boolean available = false;
819
        String status = STATUS_NOT_AVAILABLE;
820
        String message = null;
821

    
822
        if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
823
            try {
824
                if(selectedCsii.pingInstance(selectedCdmInstance, getPort())) {
825
                    status = STATUS_AVAILABLE;
826
                    available = true;
827
                } else {
828
                    status = STATUS_NOT_AVAILABLE;
829
                    available = false;
830
                }
831

    
832
                if(available) {
833
                    txtServerCDMVersion.setText(selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort()).getDbSchemaVersion());
834
                    int compareDbSchemaVersion = selectedCsii.compareDbSchemaVersion(selectedCdmInstance, getPort());
835
                    int compareCdmlibServicesVersion = 0;
836
                    boolean disableServicesApiTimestampCheck =
837
                            PreferencesUtil.getPreferenceStore().getBoolean((IPreferenceKeys.DISABLE_SERVICES_API_TIMESTAMP_CHECK));
838
                    if(!disableServicesApiTimestampCheck) {
839
                        compareCdmlibServicesVersion = selectedCsii.compareCdmlibServicesVersion();
840
                    }
841
                    if(compareDbSchemaVersion > 0 || compareCdmlibServicesVersion > 0) {
842
                        status =  STATUS_NOT_COMPATIBLE;
843
                        available = false;
844
                        message = MESG_COMPATIBLE_EDITOR_OLD;
845
                    } else if(compareDbSchemaVersion < 0 || compareCdmlibServicesVersion < 0) {
846
                        status = STATUS_NOT_COMPATIBLE;
847
                        available = false;
848
                        message = MESG_COMPATIBLE_SERVER_OLD;
849
                    } else {
850
                        status =  STATUS_AVAILABLE;
851
                        available = true;
852
                        message = ""; //$NON-NLS-1$
853
                    }
854
                }
855
            } catch (Exception e) {
856
                txtCdmInstanceStatus.setToolTipText(e.getMessage());
857
            } finally {
858
                btnConnect.setEnabled(available);
859
                txtCdmInstanceStatus.setText(status);
860
                if(!StringUtils.isBlank(message)) {
861
                    setMessage(message);
862
                }
863
            }
864
        }
865
    }
866

    
867
    private void connect() {
868
        checkSelectedCdmInstance();
869

    
870
        if(!txtCdmInstanceStatus.getText().equals(STATUS_AVAILABLE)) {
871
            return;
872
        }
873

    
874
        ICdmRemoteSource source = selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort());
875

    
876
        if(!validateLogin(source)) {
877
            return;
878
        }
879

    
880
        try {
881
            CdmStore.connect(source, this);
882
        } catch (Exception e) {
883
            // Do not expect anything to go wrong at this point, so we throw a runtime exception
884
            // if any problems
885
            throw new RuntimeException(e);
886
        }
887

    
888
    }
889

    
890

    
891
    public boolean isRememberMe() {
892
        return btnRememberMe.getSelection();
893
    }
894

    
895
    private void persistPrefLastServerInstance() {
896
        IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
897
        Preferences lastServerInstancePrefs = preferences.node(LAST_SERVER_INSTANCE_NODE);
898

    
899
        lastServerInstancePrefs.put(LAST_SERVER_KEY, selectedCsii.getName());
900
        lastServerInstancePrefs.put(LAST_INSTANCE_KEY, selectedCdmInstance.getName());
901

    
902
        flushPreferences(lastServerInstancePrefs);
903
    }
904

    
905
    private void persistPrefCredentials() {
906
         IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
907
         Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
908
         credentialsPrefs.put(getUsernamePrefKey(), txtLogin.getText());
909
         credentialsPrefs.put(getPasswordPrefKey(), txtPassword.getText());
910
         flushPreferences(credentialsPrefs);
911
    }
912

    
913
    private void flushPreferences(Preferences prefs) {
914
        try {
915
            prefs.flush();
916
        } catch (BackingStoreException bse) {
917
            setMessage(bse.getMessage());
918
        }
919
    }
920

    
921
    private void readPrefCredentials() {
922
        String username, password;
923
        IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
924
        Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
925
        username = credentialsPrefs.get(getUsernamePrefKey(), ""); //$NON-NLS-1$
926
        txtLogin.setText(username);
927
        password = credentialsPrefs.get(getPasswordPrefKey(),""); //$NON-NLS-1$
928
        txtPassword.setText(password);
929
        if(username.isEmpty() || password.isEmpty()) {
930
            autoConnect = false;
931
        }
932
    }
933

    
934
    private void readPrefLastServerInstance() {
935
        IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
936
        Preferences lastServerInstancePrefs = preferences.node(LAST_SERVER_INSTANCE_NODE);
937

    
938
        serverName = lastServerInstancePrefs.get(LAST_SERVER_KEY, null);
939
        instanceName = lastServerInstancePrefs.get(LAST_INSTANCE_KEY, null);
940
    }
941

    
942
    private void emptyCredentials() {
943
        txtLogin.setText("");
944
        txtPassword.setText("");
945
    }
946

    
947
    private String getUsernamePrefKey() {
948
        return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + USERNAME_SUFFIX;
949
    }
950

    
951
    private String getPasswordPrefKey() {
952
        return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + PASSWORD_SUFFIX;
953
    }
954

    
955
    private boolean validateLogin(ICdmRemoteSource remoteSource) {
956
        if(getUsername() == null || getUsername().isEmpty()) {
957
            setMessage(Messages.RemotingLoginDialog_LOGIN_CANNOT_BE_EMPTY);
958
            return false;
959
        }
960
        if(getPassword() == null || getPassword().isEmpty()) {
961
            setMessage(Messages.RemotingLoginDialog_PASSWORD_CANNOT_BE_EMPTY);
962
            return false;
963
        }
964

    
965

    
966
        try {
967
            IUserService userService = CdmApplicationRemoteConfiguration.getUserService(remoteSource);
968
            UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(getUsername(), getPassword());
969
            CdmApplicationRemoteConfiguration.getAuthenticationManager(userService).authenticate(token);
970
        } catch(BadCredentialsException e){
971
            setMessage(LoginManager.INCORRECT_CREDENTIALS_MESSAGE);
972
            return false;
973
        } catch(LockedException e){
974
            setMessage(LoginManager.ACCOUNT_LOCKED_MESSAGE);
975
            return false;
976
        } catch(IllegalArgumentException e){
977
            setMessage(LoginManager.INCORRECT_CREDENTIALS_MESSAGE);
978
            return false;
979
        }
980
        return true;
981
    }
982

    
983
    public String getUsername() {
984
        return txtLogin.getText();
985
    }
986

    
987
    public String getPassword() {
988
        return txtPassword.getText();
989
    }
990

    
991
    public void setMessage(String message) {
992
        if(message != null && !message.isEmpty()) {
993
            if(message.length() > 60) {
994
                styledTxtMessage.setToolTipText(message);
995
                message = message.substring(0, 60) + "..."; //$NON-NLS-1$
996
            }
997
            styledTxtMessage.setText(message);
998
            styledTxtMessage.setVisible(true);
999
            ((GridData)styledTxtMessage.getLayoutData()).exclude = false;
1000
            shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
1001
            shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
1002
        } else {
1003
            styledTxtMessage.setText(""); //$NON-NLS-1$
1004
            styledTxtMessage.setVisible(false);
1005
            ((GridData)styledTxtMessage.getLayoutData()).exclude = true;
1006
            shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage());
1007
            shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage());
1008
        }
1009
        remotingComposite.layout();
1010
    }
1011

    
1012
    private int getHeightWithoutMessage() {
1013
        if(xpndblcmpstAdvanced.isExpanded()) {
1014
            return MIN_EXP_HEIGHT;
1015
        } else {
1016
            return MIN_HEIGHT;
1017
        }
1018
    }
1019

    
1020

    
1021
    public void hide(boolean isHidden) {
1022
        if(shlConnect != null && shlConnect.getDisplay() != null) {
1023
            shlConnect.setVisible(!isHidden);
1024
        }
1025
    }
1026
    public void dispose() {
1027
        if(shlConnect != null && shlConnect.getDisplay() != null) {
1028
            shlConnect.dispose();
1029
        }
1030
    }
1031

    
1032
    public void onComplete() {
1033
        Display.getDefault().asyncExec(new Runnable() {
1034
            @Override
1035
            public void run() {
1036
                if(!isDevRemoteSource) {
1037
                    if(isRememberMe()) {
1038
                        persistPrefCredentials();
1039
                    }
1040
                    persistPrefLastServerInstance();
1041
                }
1042
                dispose();
1043
            }
1044
        });
1045
    }
1046

    
1047
    private String generateLastModifiedTooltip(String cdmlibLastModified) {
1048
        if(StringUtils.isBlank(cdmlibLastModified)) {
1049
            return ""; //$NON-NLS-1$
1050
        }
1051
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm.z"); //$NON-NLS-1$
1052
        Date cdmlibLastModifiedDate;
1053
        String cdmlibLastModifiedTimestamp = ""; //$NON-NLS-1$
1054

    
1055
        cdmlibLastModifiedDate = new Date(Long.valueOf(cdmlibLastModified));
1056
        cdmlibLastModifiedTimestamp = sdf.format(cdmlibLastModifiedDate);
1057

    
1058
        return cdmlibLastModifiedTimestamp;
1059
    }
1060

    
1061
    private void setEditorInfo() {
1062
        txtEditorCDMVersion.setText(CdmMetaData.getDbSchemaVersion());
1063
        String editorVersionTimestamp = generateLastModifiedTooltip(CdmApplicationState.getCdmlibLastModified());
1064
        txtEditorVersion.setText(CdmApplicationState.getCdmlibVersion() + ":" + editorVersionTimestamp); //$NON-NLS-1$
1065
    }
1066

    
1067
    private void clearOnServerChange() {
1068
        setMessage(""); //$NON-NLS-1$
1069
        txtServerCDMVersion.setText(""); //$NON-NLS-1$
1070
        txtServerVersion.setText(""); //$NON-NLS-1$
1071
        txtServerVersion.setToolTipText(""); //$NON-NLS-1$
1072
        txtServerCDMVersion.setText(""); //$NON-NLS-1$
1073
        comboCdmInstance.removeAll();
1074
        txtCdmInstanceStatus.setText(""); //$NON-NLS-1$
1075
        txtPort.setEditable(false);
1076
        txtPort.setEnabled(false);
1077
    }
1078

    
1079
    private void clearOnInstanceChange() {
1080
        setMessage(""); //$NON-NLS-1$
1081
        txtServerCDMVersion.setText(""); //$NON-NLS-1$
1082
    }
1083

    
1084
    /**
1085
     * {@inheritDoc}
1086
     */
1087
    @Override
1088
    public void handleError(final Throwable t) {
1089

    
1090
        Display.getDefault().syncExec(new Runnable() {
1091
            @Override
1092
            public void run() {
1093
                serverJob.cancel();
1094

    
1095
                String title = Messages.RemotingLoginDialog_SERVER_LAUNCH_ERROR;
1096
                String  message = t.getMessage();
1097

    
1098

    
1099
                MessagingUtils.errorDialog(title,
1100
                        this,
1101
                        message,
1102
                        TaxeditorStorePlugin.PLUGIN_ID,
1103
                        t,
1104
                        true);
1105
            }
1106
        });
1107
    }
1108

    
1109

    
1110
}
(5-5/7)