Project

General

Profile

Download (46 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2015 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9
package eu.etaxonomy.taxeditor.ui.dialog;
10

    
11
import java.io.File;
12
import java.io.IOException;
13
import java.text.SimpleDateFormat;
14
import java.util.Date;
15
import java.util.HashMap;
16
import java.util.List;
17
import java.util.Map;
18

    
19
import org.apache.commons.lang.StringUtils;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.Status;
23
import org.eclipse.core.runtime.jobs.Job;
24
import org.eclipse.core.runtime.preferences.ConfigurationScope;
25
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.custom.StyledText;
28
import org.eclipse.swt.events.KeyAdapter;
29
import org.eclipse.swt.events.KeyEvent;
30
import org.eclipse.swt.events.MouseAdapter;
31
import org.eclipse.swt.events.MouseEvent;
32
import org.eclipse.swt.events.SelectionAdapter;
33
import org.eclipse.swt.events.SelectionEvent;
34
import org.eclipse.swt.graphics.Point;
35
import org.eclipse.swt.layout.FillLayout;
36
import org.eclipse.swt.layout.GridData;
37
import org.eclipse.swt.layout.GridLayout;
38
import org.eclipse.swt.widgets.Button;
39
import org.eclipse.swt.widgets.Combo;
40
import org.eclipse.swt.widgets.Composite;
41
import org.eclipse.swt.widgets.Dialog;
42
import org.eclipse.swt.widgets.Display;
43
import org.eclipse.swt.widgets.Label;
44
import org.eclipse.swt.widgets.Shell;
45
import org.eclipse.swt.widgets.Text;
46
import org.eclipse.ui.forms.events.ExpansionEvent;
47
import org.eclipse.ui.forms.events.IExpansionListener;
48
import org.eclipse.ui.forms.widgets.ExpandableComposite;
49
import org.eclipse.ui.progress.IProgressConstants;
50
import org.eclipse.wb.swt.SWTResourceManager;
51
import org.osgi.service.prefs.BackingStoreException;
52
import org.osgi.service.prefs.Preferences;
53
import org.springframework.security.authentication.BadCredentialsException;
54
import org.springframework.security.authentication.LockedException;
55
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
56

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

    
78

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

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

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

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

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

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

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

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

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

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

    
143

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

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

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

    
178

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

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

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

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

    
203
        xpndblcmpstAdvanced.setExpanded(false);
204

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

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

    
213
        return result;
214
    }
215

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
474
    }
475

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

    
485
		}
486
	}
487

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

    
530

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

    
543
    }
544

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

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

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

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

    
596

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

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

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

    
656
        if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE) && !isDevRemoteSource) {
657
            // Start the Job
658
            serverJob.schedule();
659
        }
660
    }
661

    
662
    private void disableCdmInstanceControls(String cdmInstanceStatus, String tooltip) {
663
        txtCdmInstanceStatus.setText(cdmInstanceStatus);
664
        txtCdmInstanceStatus.setToolTipText(tooltip);
665
        comboCdmInstance.setEnabled(false);
666
        btnConnect.setEnabled(false);
667

    
668
    }
669
    private void refreshCdmInstance() {
670
        txtCdmInstanceStatus.setText(STATUS_CHECKING_AVAILABILITY);
671
        clearOnInstanceChange();
672
        updateSelectedCdmInstance();
673
        checkSelectedCdmInstance();
674
        updateManagedServerControls();
675
    }
676

    
677
    private void updateSelectedCdmInstance() {
678
        int selIndex = comboCdmInstance.getSelectionIndex();
679
        if(selIndex != -1) {
680
            selectedCdmInstance = selectedCsii.getInstanceFromName(comboCdmInstance.getItem(selIndex));
681

    
682
            if(loadLoginPrefs && !isDevRemoteSource) {
683
                readPrefCredentials();
684
            }
685
        }
686
    }
687

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

    
700

    
701
        if(isManagedServerRunning()) {
702
            btnStopServer.setEnabled(true);
703
        } else {
704
            btnStopServer.setEnabled(false);
705
        }
706
    }
707

    
708
    private boolean isManagedServerRunning() {
709
        return CdmStore.getManagedServer() != null && CdmStore.getManagedServer().isAlive();
710
    }
711

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

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

    
733

    
734
        Job job = new Job(Messages.RemotingLoginDialog_JOB_SERVER_LAUNCH) {
735

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

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

    
793
        // configure the job
794
        job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
795
        job.setUser(true);
796
        // schedule job
797
        hide(true);
798
        job.schedule();
799
    }
800

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

    
816
    private int getManagedServerPort() {
817
        return CdmStore.getManagedServer() == null ? CdmServerInfo.NULL_PORT : CdmStore.getManagedServer().getPort();
818
    }
819

    
820
    private void checkSelectedCdmInstance() {
821
        boolean available = false;
822
        String status = STATUS_NOT_AVAILABLE;
823
        String message = null;
824

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

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

    
870
    private void connect() {
871
        checkSelectedCdmInstance();
872

    
873
        if(!txtCdmInstanceStatus.getText().equals(STATUS_AVAILABLE)) {
874
            return;
875
        }
876

    
877
        ICdmRemoteSource source = selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort());
878

    
879
        if(!validateLogin(source)) {
880
            return;
881
        }
882

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

    
891
    }
892

    
893

    
894
    public boolean isRememberMe() {
895
        return btnRememberMe.getSelection();
896
    }
897

    
898
    private void persistPrefLastServerInstance() {
899
        IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
900
        Preferences lastServerInstancePrefs = preferences.node(LAST_SERVER_INSTANCE_NODE);
901

    
902
        lastServerInstancePrefs.put(LAST_SERVER_KEY, selectedCsii.getName());
903
        lastServerInstancePrefs.put(LAST_INSTANCE_KEY, selectedCdmInstance.getName());
904

    
905
        flushPreferences(lastServerInstancePrefs);
906
    }
907

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

    
916
    private void flushPreferences(Preferences prefs) {
917
        try {
918
            prefs.flush();
919
        } catch (BackingStoreException bse) {
920
            setMessage(bse.getMessage());
921
        }
922
    }
923

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

    
937
    private void readPrefLastServerInstance() {
938
        IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
939
        Preferences lastServerInstancePrefs = preferences.node(LAST_SERVER_INSTANCE_NODE);
940

    
941
        serverName = lastServerInstancePrefs.get(LAST_SERVER_KEY, null);
942
        instanceName = lastServerInstancePrefs.get(LAST_INSTANCE_KEY, null);
943
    }
944

    
945
    private void emptyCredentials() {
946
        txtLogin.setText("");
947
        txtPassword.setText("");
948
    }
949

    
950
    private String getUsernamePrefKey() {
951
        return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + USERNAME_SUFFIX;
952
    }
953

    
954
    private String getPasswordPrefKey() {
955
        return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + PASSWORD_SUFFIX;
956
    }
957

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

    
968

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

    
986
    public String getUsername() {
987
        return txtLogin.getText();
988
    }
989

    
990
    public String getPassword() {
991
        return txtPassword.getText();
992
    }
993

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

    
1015
    private int getHeightWithoutMessage() {
1016
        if(xpndblcmpstAdvanced.isExpanded()) {
1017
            return MIN_EXP_HEIGHT;
1018
        } else {
1019
            return MIN_HEIGHT;
1020
        }
1021
    }
1022

    
1023

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

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

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

    
1058
        cdmlibLastModifiedDate = new Date(Long.valueOf(cdmlibLastModified));
1059
        cdmlibLastModifiedTimestamp = sdf.format(cdmlibLastModifiedDate);
1060

    
1061
        return cdmlibLastModifiedTimestamp;
1062
    }
1063

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

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

    
1082
    private void clearOnInstanceChange() {
1083
        setMessage(""); //$NON-NLS-1$
1084
        txtServerCDMVersion.setText(""); //$NON-NLS-1$
1085
    }
1086

    
1087
    /**
1088
     * {@inheritDoc}
1089
     */
1090
    @Override
1091
    public void handleError(final Throwable t) {
1092

    
1093
        Display.getDefault().syncExec(new Runnable() {
1094
            @Override
1095
            public void run() {
1096
                serverJob.cancel();
1097

    
1098
                String title = Messages.RemotingLoginDialog_SERVER_LAUNCH_ERROR;
1099
                String  message = t.getMessage();
1100

    
1101

    
1102
                MessagingUtils.errorDialog(title,
1103
                        this,
1104
                        message,
1105
                        TaxeditorStorePlugin.PLUGIN_ID,
1106
                        t,
1107
                        true);
1108
            }
1109
        });
1110
    }
1111

    
1112

    
1113
}
(5-5/7)