Project

General

Profile

« Previous | Next » 

Revision 821fe02d

Added by Katja Luther over 3 years ago

create new branch webapp

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java
8 8
 */
9 9
package eu.etaxonomy.taxeditor.ui.dialog;
10 10

  
11
import java.io.File;
12 11
import java.io.IOException;
13 12
import java.net.SocketTimeoutException;
14 13
import java.text.SimpleDateFormat;
......
31 30
import org.eclipse.swt.custom.StyledText;
32 31
import org.eclipse.swt.events.KeyAdapter;
33 32
import org.eclipse.swt.events.KeyEvent;
34
import org.eclipse.swt.events.MouseAdapter;
35
import org.eclipse.swt.events.MouseEvent;
36 33
import org.eclipse.swt.events.SelectionAdapter;
37 34
import org.eclipse.swt.events.SelectionEvent;
38
import org.eclipse.swt.graphics.Color;
39 35
import org.eclipse.swt.graphics.Point;
40 36
import org.eclipse.swt.graphics.Rectangle;
41 37
import org.eclipse.swt.layout.FillLayout;
......
52 48
import org.eclipse.ui.forms.events.ExpansionEvent;
53 49
import org.eclipse.ui.forms.events.IExpansionListener;
54 50
import org.eclipse.ui.forms.widgets.ExpandableComposite;
55
import org.eclipse.ui.progress.IProgressConstants;
56 51
import org.eclipse.wb.swt.SWTResourceManager;
57 52
import org.osgi.service.prefs.BackingStoreException;
58 53
import org.osgi.service.prefs.Preferences;
......
73 68
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
74 69
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
75 70
import eu.etaxonomy.taxeditor.remoting.server.CdmServerException;
76
import eu.etaxonomy.taxeditor.remoting.server.CdmServerUtils;
77 71
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteLocalhostSource;
78 72
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo;
79 73
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo.CdmInstanceInfo;
80 74
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
81 75
import eu.etaxonomy.taxeditor.store.CdmStore;
82 76
import eu.etaxonomy.taxeditor.store.LoginManager;
83
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
77
/*
84 78
import eu.etaxonomy.taxeditor.webapp.CdmEmbeddedServerException;
85 79
import eu.etaxonomy.taxeditor.webapp.CdmServer;
86 80
import eu.etaxonomy.taxeditor.webapp.ICDMServerError;
87

  
81
*/
88 82
/**
89 83
 * @author cmathew
90 84
 * @date 20 Jan 2015
91 85
 */
92
public class RemotingLoginDialog extends Dialog implements ICDMServerError {
86
public class RemotingLoginDialog extends Dialog{ //implements ICDMServerError {
93 87

  
94 88
    private Logger logger = Logger.getLogger(getClass());
95 89

  
96
    private static final String DEFAULT_PASS = "00000"; //$NON-NLS-1$
97
    private static final String DEFAULT_USER = "admin"; //$NON-NLS-1$
98

  
99
    private final static String STATUS_AVAILABLE = Messages.RemotingLoginDialog_STATUS_AVAILABLE;
100
    private final static String STATUS_NOT_AVAILABLE = Messages.RemotingLoginDialog_STATUS_NOT_AVAILABLE;
101
    private final static String STATUS_STARTED = Messages.RemotingLoginDialog_STATUS_STARTED;
102
    private final static String STATUS_NOT_STARTED = Messages.RemotingLoginDialog_STATUS_NOT_STARTED;
103
    private final static String STATUS_RETRIEVING = Messages.RemotingLoginDialog_STATUS_RETRIEVING;
104
    private final static String STATUS_CHECKING_AVAILABILITY = Messages.RemotingLoginDialog_STATUS_CHECKING;
105
    private final static String STATUS_NO_INSTANCES = Messages.RemotingLoginDialog_STATUS_NO_INSTANCES_FOUND;
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
    private final static String MESG_SCHEMA_MISSING = Messages.RemotingLoginDialog_SCHEMA_MISSING;
111
    private final static String MESG_NO_SCHEMA = Messages.RemotingLoginDialog_NO_SCHEMA;
112

  
113
    private final static String LABEL_CONNECT = Messages.RemotingLoginDialog_LABEL_CONNECT;
114
    private final static String LABEL_CREATE_SCHEMA = Messages.RemotingLoginDialog_LABEL_CREATE_SCHEMA;
115
    private final static String LABEL_UPDATE_SCHEMA_VERSION = Messages.RemotingLoginDialog_LABEL_UPDATE_SCHEMA_VERSION;
116
    private final static String MESG_UPDATE_SCHEMA_VERSION = Messages.RemotingLoginDialog_MSG_UPDATE_SCHEMA_VERSION;
117

  
118
    private static final int BTN_COLOR_ATTENTION = SWT.COLOR_RED;
119

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

  
122
    private final static String LOGIN_NODE = "login"; //$NON-NLS-1$
123
    private final static String USERNAME_SUFFIX = "_username"; //$NON-NLS-1$
124
    private final static String PASSWORD_SUFFIX = "_password"; //$NON-NLS-1$
125

  
126
    private final static String LAST_SERVER_INSTANCE_NODE = "lastServerInstance"; //$NON-NLS-1$
127
    private final static String LAST_SERVER_KEY = "lastServerKey"; //$NON-NLS-1$
128
    private final static String LAST_INSTANCE_KEY = "lastInstanceKey"; //$NON-NLS-1$
90
    public static final String DEFAULT_PASS = "00000"; //$NON-NLS-1$
91
    public static final String DEFAULT_USER = "admin"; //$NON-NLS-1$
92

  
93
    public final static String STATUS_AVAILABLE = Messages.RemotingLoginDialog_STATUS_AVAILABLE;
94
    public final static String STATUS_NOT_AVAILABLE = Messages.RemotingLoginDialog_STATUS_NOT_AVAILABLE;
95
    public final static String STATUS_STARTED = Messages.RemotingLoginDialog_STATUS_STARTED;
96
    public final static String STATUS_NOT_STARTED = Messages.RemotingLoginDialog_STATUS_NOT_STARTED;
97
    public final static String STATUS_RETRIEVING = Messages.RemotingLoginDialog_STATUS_RETRIEVING;
98
    public final static String STATUS_CHECKING_AVAILABILITY = Messages.RemotingLoginDialog_STATUS_CHECKING;
99
    public final static String STATUS_NO_INSTANCES = Messages.RemotingLoginDialog_STATUS_NO_INSTANCES_FOUND;
100
    public final static String STATUS_NOT_COMPATIBLE = Messages.RemotingLoginDialog_STATUS_NOT_COMPATIBLE;
101

  
102
    public final static String MESG_COMPATIBLE_EDITOR_OLD = Messages.RemotingLoginDialog_UPDATE_EDITOR;
103
    public final static String MESG_COMPATIBLE_SERVER_OLD = Messages.RemotingLoginDialog_CHOOSE_COMPATIBLE_CDM_SERVER;
104
    public final static String MESG_SCHEMA_MISSING = Messages.RemotingLoginDialog_SCHEMA_MISSING;
105
    public final static String MESG_NO_SCHEMA = Messages.RemotingLoginDialog_NO_SCHEMA;
106

  
107
    public final static String LABEL_CONNECT = Messages.RemotingLoginDialog_LABEL_CONNECT;
108
    public final static String LABEL_CREATE_SCHEMA = Messages.RemotingLoginDialog_LABEL_CREATE_SCHEMA;
109
    public final static String LABEL_UPDATE_SCHEMA_VERSION = Messages.RemotingLoginDialog_LABEL_UPDATE_SCHEMA_VERSION;
110
    public final static String MESG_UPDATE_SCHEMA_VERSION = Messages.RemotingLoginDialog_MSG_UPDATE_SCHEMA_VERSION;
111
    public final static String LABEL_LOGIN = Messages.RemotingLoginDialog_LABEL_LOGIN;
112
    public final static String LABEL_CDM_SERVER = Messages.RemotingLoginDialog_LABEL_CDM_SERVER;
113
    public final static String LABEL_REFRESH = Messages.RemotingLoginDialog_LABEL_REFRESH;
114
    public final static String LABEL_CDM_INSTANCE = Messages.RemotingLoginDialog_LABEL_CDM_INSTANCE;
115
    public final static String LABEL_LOGIN_COLON = Messages.RemotingLoginDialog_LABEL_LOGIN_COLON;
116
    public final static String LABEL_PASSWORD = Messages.RemotingLoginDialog_LABEL_PASSWORD;
117
    public final static String LABEL_EDITOR_CDM_VERSION = Messages.RemotingLoginDialog_LABEL_EDITOR_CDM_VERSION;
118
    public final static String LABEL_SERVER_CDM_VERSION = Messages.RemotingLoginDialog_LABEL_SERVER_CDM_VERSION;
119
    public final static String LABEL_EDITOR_CDMLIB_VERSION = Messages.RemotingLoginDialog_LABEL_EDITOR_CDMLIB_VERSION;
120
    public final static String LABEL_SERVER_CDMLIB_VERSION = Messages.RemotingLoginDialog_LABEL_SERVER_CDMLIB_VERSION;
121
    public final static String LABEL_STOP_MANAGED_SERVER = Messages.RemotingLoginDialog_LABEL_STOP_MANAGED_SERVER;
122
    public final static String LABEL_PORT = Messages.RemotingLoginDialog_LABEL_PORT;
123
    public final static String LABEL_ADVANCED = Messages.RemotingLoginDialog_LABEL_ADVANCED;
124
    public final static String LABEL_DEFAULT_LOGIN = Messages.RemotingLoginDialog_DEFAULT_LOGIN;
125
    public final static String LABEL_REMEMBER_ME = Messages.RemotingLoginDialog_LABEL_REMEMBER_ME;
126

  
127
    public final static String MESG_LOGIN_CANNOT_BE_EMPTY = Messages.RemotingLoginDialog_LOGIN_CANNOT_BE_EMPTY;
128
    public final static String STATUS_GENERATING_CONFIG_FILE = Messages.RemotingLoginDialog_GENERATING_CONFIG_FILE;
129
    public final static String STATUS_STARTING_MGD_SERVER = Messages.RemotingLoginDialog_STARTING_MGD_SERVER;
130

  
131
    public final static String ERR_GENERATING_CONFIG_FILE = Messages.RemotingLoginDialog_ERROR_GENERATING_CONFIG_FILE;
132
    public final static String ERR_STARTING_SERVER = Messages.RemotingLoginDialog_ERROR_STARTING_SERVER;
133
    public final static String ERR_SERVER_LAUNCH = Messages.RemotingLoginDialog_SERVER_LAUNCH_ERROR;
134
    public final static String ERR_STOPPING_SERVER = Messages.RemotingLoginDialog_ERROR_STOPPING_SERVER;
135
    public final static String ERR_COULD_NOT_STOP_SERVER = Messages.RemotingLoginDialog_COULD_NOT_STOP_SERVER;
136
    public final static String RETRIEVE_SERVER_INSTANCES = Messages.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES;
137
    public final static String TASK_LAUNCHING_SERVER = Messages.RemotingLoginDialog_TASK_LAUNCHING_SERVER;
138

  
139
    public static final int BTN_COLOR_ATTENTION = SWT.COLOR_RED;
140

  
141
    public final static String STORE_PREFERENCES_NODE = "eu.etaxonomy.taxeditor.store"; //$NON-NLS-1$
142

  
143
    public final static String LOGIN_NODE = "login"; //$NON-NLS-1$
144
    public final static String USERNAME_SUFFIX = "_username"; //$NON-NLS-1$
145
    public final static String PASSWORD_SUFFIX = "_password"; //$NON-NLS-1$
146

  
147
    public final static String LAST_SERVER_INSTANCE_NODE = "lastServerInstance"; //$NON-NLS-1$
148
    public final static String LAST_SERVER_KEY = "lastServerKey"; //$NON-NLS-1$
149
    public final static String LAST_INSTANCE_KEY = "lastInstanceKey"; //$NON-NLS-1$
129 150

  
130 151
    protected Shell shlConnect;
131
    private Text txtCdmServerStatus;
132
    private Text txtCdmInstanceStatus;
133
    private Combo comboCdmServer;
134
    private Combo comboCdmInstance;
135
    private Button btnConnect;
136

  
137
    private Composite remotingComposite;
138
    private Button btnCdmServerRefresh;
139
    private Button btnCdmInstanceRefresh;
140
    private Button btnStopServer;
141
    private Composite loginComposite;
142
    private Label lblLogin;
143
    private Text txtLogin;
144
    private Label lblPassword;
145
    private Text txtPassword;
146
    private Button btnRememberMe;
147
    private Label lblDefaultLogin;
148
    private Composite compAdvanced;
149
    private Label lblPort;
150
    private Text txtPort;
151
    private Label lblServerCdmlibVersion;
152
    private Text txtServerCdmlibVersion;
153
    private ExpandableComposite expandableCompositeAdvanced;
154
    private StyledText styledTxtMessage;
155

  
156
    private Label lblEditorCdmlibVersion;
157
    private Text txtEditorCdmlibVersion;
158
    private Label lblServerSchemaVersion;
159
    private Text txtServerSchemaVersion;
160
    private Label lblEditorCdmVersion;
161
    private Text txtEditorCdmVersion;
162

  
163
    private final int MESSAGE_HEIGHT = 50;
164
    private final int COMBO_MIN_WIDTH =200;
165
    private final int CONTROLS_MIN_HEIGHT = 23; //does not seem to work yet
152
    protected Text txtCdmServerStatus;
153
    protected Text txtCdmInstanceStatus;
154
    protected Combo comboCdmServer;
155
    protected Combo comboCdmInstance;
156
    protected Button btnConnect;
157

  
158
    protected Composite remotingComposite;
159
    protected Button btnCdmServerRefresh;
160
    protected Button btnCdmInstanceRefresh;
161
    protected Button btnStopServer;
162
    protected Composite loginComposite;
163
    protected Label lblLogin;
164
    protected Text txtLogin;
165
    protected Label lblPassword;
166
    protected Text txtPassword;
167
    protected Button btnRememberMe;
168
    protected Label lblDefaultLogin;
169
    protected Composite compAdvanced;
170
    protected Label lblPort;
171
    protected Text txtPort;
172
    protected Label lblServerCdmlibVersion;
173
    protected Text txtServerCdmlibVersion;
174
    protected ExpandableComposite expandableCompositeAdvanced;
175
    protected StyledText styledTxtMessage;
176

  
177
    protected Label lblEditorCdmlibVersion;
178
    protected Text txtEditorCdmlibVersion;
179
    protected Label lblServerSchemaVersion;
180
    protected Text txtServerSchemaVersion;
181
    protected Label lblEditorCdmVersion;
182
    protected Text txtEditorCdmVersion;
183

  
184
    protected final int MESSAGE_HEIGHT = 50;
185
    protected final int COMBO_MIN_WIDTH =200;
186
    protected final int CONTROLS_MIN_HEIGHT = 23; //does not seem to work yet
166 187
//  private final int MIN_EXP_HEIGHT = 380;
167 188

  
168 189
    private boolean autoConnect = false;
169
    private boolean loadLoginPrefs = true;
190
    protected boolean loadLoginPrefs = true;
170 191
    private boolean isDevRemoteSource = false;
171 192

  
172
    private Job serverJob;
193
    protected Job serverJob;
173 194
    protected Object result;
174 195

  
175 196
    private final Map<String, CdmServerInfo> serverInfoMap = new HashMap<>();
176 197

  
177 198
    private String serverName;
178 199
    private String instanceName;
179
    private CdmServerInfo selectedServerInfo;
180
    private CdmInstanceInfo selectedCdmInstance;
181
    private String login;
182
    private String password;
200
    protected CdmServerInfo selectedServerInfo;
201
    protected CdmInstanceInfo selectedCdmInstance;
202
    protected String login;
203
    protected String password;
183 204

  
184 205
    /**
185 206
     * Create the dialog.
......
188 209
     */
189 210
    public RemotingLoginDialog(Shell parent, int style) {
190 211
        super(parent, style);
191
        setText(Messages.RemotingLoginDialog_LABEL_LOGIN);
212
        setText(LABEL_LOGIN);
192 213
    }
193 214

  
194 215
    public Object open(ICdmRemoteSource source, boolean loadLoginPrefs, boolean autoConnect) {
195 216
        this.loadLoginPrefs = loadLoginPrefs;
196
        this.serverName = source.getName();
217
        this.setServerName(source.getName());
197 218
        if (source instanceof CdmRemoteLocalhostSource){
198
            this.instanceName = ((CdmRemoteLocalhostSource)source).getDatasourceName();
219
            this.setInstanceName(((CdmRemoteLocalhostSource)source).getDatasourceName());
199 220
        }else{
200 221
            String contextPath = source.getContext();
201
            this.instanceName = contextPath == null? "" : contextPath.substring(contextPath.lastIndexOf("/") + 1); //$NON-NLS-1$
222
            this.setInstanceName(contextPath == null? "" : contextPath.substring(contextPath.lastIndexOf("/") + 1)); //$NON-NLS-1$
202 223
        }
203
        return open(serverName, instanceName, loadLoginPrefs, autoConnect);
224
        return open(getServerName(), getInstanceName(), loadLoginPrefs, autoConnect);
204 225
    }
205 226

  
206 227
    public Object open(String serverName, String instanceName, boolean loadLoginPrefs, boolean autoConnect) {
207
        this.serverName = serverName;
208
        this.instanceName = instanceName;
228
        this.setServerName(serverName);
229
        this.setInstanceName(instanceName);
209 230
        this.loadLoginPrefs = loadLoginPrefs;
210
        this.autoConnect = autoConnect;
231
        this.setAutoConnect(autoConnect);
211 232
        return open();
212 233
    }
213 234

  
......
218 239
    public Object open() {
219 240

  
220 241
        createContents();
221
        if(serverName == null && instanceName == null) {
242
        if(getServerName() == null && getInstanceName() == null) {
222 243
            readPrefLastServerInstance();
223 244
        }
224 245
        expandableCompositeAdvanced.setExpanded(false);
......
244 265
    /**
245 266
     * Create contents of the dialog.
246 267
     */
247
    private void createContents() {
268
    protected void createContents() {
248 269
        shlConnect = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE | SWT.CENTER);
249 270
        shlConnect.setText(LABEL_CONNECT);
250 271
        shlConnect.setLayout(new FillLayout(SWT.HORIZONTAL));
......
259 280
        cdmServerComposite.setLayout(new GridLayout(4, false));
260 281

  
261 282
        Label lblCdmServer = new Label(cdmServerComposite, SWT.NONE);
262
        lblCdmServer.setText(Messages.RemotingLoginDialog_LABEL_CDM_SERVER);
283
        lblCdmServer.setText(LABEL_CDM_SERVER);
263 284
        lblCdmServer.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
264 285

  
265 286
        comboCdmServer = new Combo(cdmServerComposite, SWT.READ_ONLY);
......
292 313
        GridData gd_btnCdmServerRefresh = new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1);
293 314
        gd_btnCdmServerRefresh.minimumHeight = CONTROLS_MIN_HEIGHT;
294 315
        btnCdmServerRefresh.setLayoutData(gd_btnCdmServerRefresh);
295
        btnCdmServerRefresh.setText(Messages.RemotingLoginDialog_LABEL_REFRESH);
316
        btnCdmServerRefresh.setText(LABEL_REFRESH);
296 317

  
297 318
        //instance
298 319
        Label lblCdmInstance = new Label(cdmServerComposite, SWT.NONE);
299 320
        GridData gd_lblCdmInstance = new GridData(SWT.RIGHT, SWT.CENTER, false, true, 1, 1);
300 321
        //gd_lblCdmInstance.heightHint = 30;
301 322
        lblCdmInstance.setLayoutData(gd_lblCdmInstance);
302
        lblCdmInstance.setText(Messages.RemotingLoginDialog_LABEL_CDM_INSTANCE);
323
        lblCdmInstance.setText(LABEL_CDM_INSTANCE);
303 324

  
304 325
        comboCdmInstance = new Combo(cdmServerComposite, SWT.READ_ONLY);
305 326
        comboCdmInstance.addSelectionListener(new SelectionAdapter() {
......
446 467
        txtServerCdmlibVersion = new Text(compAdvanced, SWT.BORDER);
447 468
        txtServerCdmlibVersion.setEditable(false);
448 469
        txtServerCdmlibVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
449

  
470
/*
450 471
        btnStopServer = new Button(compAdvanced, SWT.FLAT);
451 472
        btnStopServer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
452 473
        btnStopServer.addMouseListener(new MouseAdapter() {
......
456 477
            }
457 478
        });
458 479
        btnStopServer.setText(Messages.RemotingLoginDialog_LABEL_STOP_MANAGED_SERVER);
459

  
480
*/
460 481
        lblEditorCdmlibVersion = new Label(compAdvanced, SWT.CENTER);
461 482
        lblEditorCdmlibVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
462 483
        lblEditorCdmlibVersion.setText(Messages.RemotingLoginDialog_LABEL_EDITOR_CDMLIB_VERSION);
......
505 526
        }
506 527
    }
507 528

  
508
	private void onConnectButtonPressed() {
509
		if(selectedServerInfo.isLocalhostMgd() && !isSelectedCdmInstanceRunningInManagedServer()) {
529
	protected void onConnectButtonPressed() {
530
		/*if(selectedServerInfo.isLocalhostMgd() && !isSelectedCdmInstanceRunningInManagedServer()) {
510 531
			startManagedServer();
511
		} else {
532
		} else {*/
512 533
			connect();
513 534
			if (CdmStore.isActive() && CdmStore.currentAuthentiationHasOneOfRoles(Role.ROLE_REMOTING)){
514 535
			    PreferencesUtil.setNomenclaturalCodePreferences();
515 536
			}
516
		}
537
//		}
517 538
	}
518 539

  
519 540
    private void populateCdmServerCombo() {
520
        Job job = new Job(Messages.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES) {
541
        Job job = new Job(RETRIEVE_SERVER_INSTANCES) {
521 542
            @Override
522 543
            protected IStatus run(IProgressMonitor monitor) {
523 544
                Display.getDefault().syncExec(new Runnable() {
524 545
                    @Override
525 546
                    public void run() {
526 547
                        //TODO performance
527
                        for(CdmServerInfo csii : CdmServerInfo.getCdmServers()) {
528
                            serverInfoMap.put(csii.getName(), csii);
529
                            comboCdmServer.add(csii.getName());
530
                        }
548
                        putAllServers();
531 549
                        int serverIndex = -1;
532
                        if(serverName != null) {
533
                            serverIndex = comboCdmServer.indexOf(serverName);
550
                        if(getServerName() != null) {
551
                            serverIndex = comboCdmServer.indexOf(getServerName());
534 552
                        }
535 553
                        if(serverIndex == -1) {
536 554
                            comboCdmServer.select(0);
537
                            autoConnect = false;
555
                            setAutoConnect(false);
538 556
                        } else {
539 557
                            comboCdmServer.select(serverIndex);
540 558
                        }
541 559
                        ICdmSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
542 560
                        if(devRemoteSource != null) {
543
                            isDevRemoteSource = true;
561
                            setDevRemoteSource(true);
544 562
                            String username = System.getProperty("cdm.server.dev.username"); //$NON-NLS-1$
545 563
                            String password = System.getProperty("cdm.server.dev.password"); //$NON-NLS-1$
546 564
                            if(username != null && !username.isEmpty() && password != null && !password.isEmpty()) {
......
552 570
                            onRefreshCdmServer();
553 571
                        }
554 572
                    }
573

  
574

  
555 575
                });
556 576
                return Status.OK_STATUS;
557 577
            }
558 578
        };
559 579
        job.schedule();
560 580
    }
581
    public void putAllServers() {
582
        for(CdmServerInfo csii : CdmServerInfo.getCdmServers()) {
583
            putServerInfo(csii);
584
            comboCdmServer.add(csii.getName());
585
        }
586
    }
561 587

  
562
    private void onRefreshCdmServer() {
588
    public void putServerInfo(CdmServerInfo csii) {
589
        getServerInfoMap().put(csii.getName(), csii);
590
    }
591
    public void onRefreshCdmServer() {
563 592
        try{
564 593
            txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
565 594
            clearOnServerChange();
......
578 607
        }
579 608
    }
580 609

  
581
    private void updateSelectedCdmServer() {
610
    protected void updateSelectedCdmServer() {
582 611
        int selIndex = comboCdmServer.getSelectionIndex();
583 612
        if(selIndex != -1) {
584
            selectedServerInfo = serverInfoMap.get(comboCdmServer.getItem(selIndex));
613
            selectedServerInfo = getServerInfoMap().get(comboCdmServer.getItem(selIndex));
585 614
        }
586 615
    }
587 616

  
588
    private void updatePort() {
617
    protected void updatePort() {
589 618
        txtPort.setText(""); //$NON-NLS-1$
590 619
        if(selectedServerInfo != null) {
591 620
            int port = selectedServerInfo.getPort();
......
597 626
        }
598 627
    }
599 628

  
600
    private int getPort() {
629
    protected int getPort() {
601 630
        int port = CdmServerInfo.NULL_PORT;
602 631
        try {
603 632
            port = Integer.valueOf(txtPort.getText());
......
655 684
        }
656 685
    }
657 686

  
658
    private void populateCdmInstanceCombo(final boolean forceRefresh) {
687
    protected void populateCdmInstanceCombo(final boolean forceRefresh) {
659 688
        comboCdmInstance.removeAll();
660 689
        comboCdmInstance.setEnabled(false);
661 690
        btnConnect.setEnabled(false);
......
679 708
                                        comboCdmInstance.add(cdmInstance.getName());
680 709
                                    }
681 710
                                    int instanceIndex = -1;
682
                                    if(instanceName != null) {
683
                                        instanceIndex = comboCdmInstance.indexOf(instanceName);
711
                                    if(getInstanceName() != null) {
712
                                        instanceIndex = comboCdmInstance.indexOf(getInstanceName());
684 713
                                    }
685 714
                                    if(instanceIndex == -1) {
686 715
                                        comboCdmInstance.select(0);
687
                                        autoConnect = false;
716
                                        setAutoConnect(false);
688 717
                                    } else {
689 718
                                        comboCdmInstance.select(instanceIndex);
690 719
                                    }
691 720
                                    onRefreshCdmInstance();
692 721
                                    comboCdmInstance.setEnabled(true);
693
                                    if(autoConnect) {
722
                                    if(isAutoConnect()) {
694 723
                                        connect();
695 724
                                    }
696 725
                                } else {
......
713 742
            }
714 743
        };
715 744

  
716
        if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE) && !isDevRemoteSource) {
745
        if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE) && !isDevRemoteSource()) {
717 746
            // Start the Job
718 747
            serverJob.schedule();
719 748
        }
720 749
    }
721 750

  
722
    private void disableCdmInstanceControls(String cdmInstanceStatus, String tooltip) {
751
    public void disableCdmInstanceControls(String cdmInstanceStatus, String tooltip) {
723 752
        txtCdmInstanceStatus.setText(cdmInstanceStatus);
724 753
        txtCdmInstanceStatus.setToolTipText(tooltip);
725 754
        comboCdmInstance.setEnabled(false);
726 755
        btnConnect.setEnabled(false);
727 756
    }
728 757

  
729
    private void onRefreshCdmInstance() {
758
    public void onRefreshCdmInstance() {
730 759
        txtCdmInstanceStatus.setText(STATUS_CHECKING_AVAILABILITY);
731 760
        clearOnInstanceChange();
732 761
        updateSelectedCdmInstance();
733 762
        checkSelectedCdmInstance();
734
        updateManagedServerControls();
763
//        updateManagedServerControls();
735 764
    }
736 765

  
737
    private void updateSelectedCdmInstance() {
766
    protected void updateSelectedCdmInstance() {
738 767
        int selIndex = comboCdmInstance.getSelectionIndex();
739 768
        if(selIndex != -1) {
740 769
            selectedCdmInstance = selectedServerInfo.getInstanceFromName(comboCdmInstance.getItem(selIndex));
......
743 772
            }
744 773
        }
745 774
    }
746

  
775
/*
747 776
    private void updateManagedServerControls() {
748 777
        if(selectedServerInfo.isLocalhostMgd()) {
749 778
            if(isSelectedCdmInstanceRunningInManagedServer()) {
......
775 804
    }
776 805

  
777 806
    private void startManagedServer() {
778
        if(isManagedServerRunning()) {
807
        /*if(isManagedServerRunning()) {
779 808
            if(CdmStore.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName())) {
780 809
                return;
781 810
            } else {
......
787 816
                });
788 817
            }
789 818
        }
790

  
791 819
        boolean forceSchemaCreate = !schemaExists(selectedCdmInstance);
792 820
        boolean forceSchemaUpdate = LABEL_UPDATE_SCHEMA_VERSION.equals(btnConnect.getText());
793 821

  
......
859 887
        hide(true);
860 888
        job.schedule();
861 889
    }
862

  
890
    */
863 891
    private boolean schemaExists(CdmInstanceInfo instanceInfo) {
864 892
        if (instanceInfo.getDataSource() != null){
865 893
            try {
......
884 912
    private int compareSchemaVersion(CdmInstanceInfo instanceInfo) throws CdmSourceException {
885 913
        return CdmMetaData.compareVersion(managedSchemaVersion(instanceInfo), CdmMetaData.getDbSchemaVersion(), 3, null);
886 914
    }
887

  
915
/*
888 916
    @Override
889 917
    public void handleError(final Throwable t) {
890 918

  
......
921 949
    private int getManagedServerPort() {
922 950
        return CdmStore.getManagedServer() == null ? CdmServerInfo.NULL_PORT : CdmStore.getManagedServer().getPort();
923 951
    }
924

  
925
    private void checkSelectedCdmInstance() {
926

  
927
        if (selectedServerInfo.isLocalhostMgd()){
928
            checkManagedSelectedInstance();
929
        }else if (txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
952
*/
953
    protected void checkSelectedCdmInstance() {
954
        try {
955
            if (selectedCdmInstance != null && selectedCdmInstance.getDataSource() != null){
956
                String schemaVersion = selectedCdmInstance.getDataSource().getDbSchemaVersion();
957
            }
958
        } catch (CdmSourceException e1) {
959
            // TODO Auto-generated catch block
960
            e1.printStackTrace();
961
        }
962
       if (txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
930 963

  
931 964
            boolean available = false;
932 965
            String instanceStatus = STATUS_NOT_AVAILABLE;
......
979 1012
        }
980 1013
    }
981 1014

  
982
    private void checkManagedSelectedInstance() {
983
        boolean available = false;
984
        String instanceStatus = STATUS_NOT_AVAILABLE;
985
        String message = null;
986
        String connect = LABEL_CONNECT;
987
        Integer color = null;
988
        String schemaVersion = CdmMetaData.getDbSchemaVersion();
989

  
990
        if (!schemaExists(selectedCdmInstance)){
991
            message = MESG_SCHEMA_MISSING;
992
            connect = LABEL_CREATE_SCHEMA;
993
            color = BTN_COLOR_ATTENTION;
994
            schemaVersion = MESG_NO_SCHEMA;
995
        } else {
996
            int compare;
997
            try {
998
                schemaVersion = managedSchemaVersion(selectedCdmInstance);
999
                compare = compareSchemaVersion(selectedCdmInstance);
1000
                if (compare > 0){
1001
                    instanceStatus = STATUS_NOT_COMPATIBLE;
1002
                    message = MESG_COMPATIBLE_EDITOR_OLD;
1003
                    available = false;
1004
                }else if (compare < 0){
1005
                    instanceStatus = STATUS_NOT_COMPATIBLE;
1006
                    message = MESG_UPDATE_SCHEMA_VERSION;
1007
                    available = true;
1008
                    connect = LABEL_UPDATE_SCHEMA_VERSION;
1009
                    color = BTN_COLOR_ATTENTION;
1010
                }else{
1011
                    available = true;
1012
                    instanceStatus = STATUS_AVAILABLE;
1013
                }
1014
            } catch (CdmSourceException e) {
1015
                available = false;
1016
            }
1017
        }
1018

  
1019
        setManagedValues(available, instanceStatus, connect, color, schemaVersion);
1020
        setMessage(message);
1021
    }
1022

  
1023
    private void setManagedValues(boolean available, String instanceStatus, String connect, Integer color,
1024
            String schemaVersion) {
1025
        Display.getDefault().syncExec(()->{
1026
            btnConnect.setEnabled(available);
1027
            btnConnect.setText(connect);
1028
            Color systemColor = null;
1029
            if(color != null) {
1030
                systemColor = Display.getCurrent().getSystemColor(color);
1031
            }
1032
            btnConnect.setBackground(systemColor);
1033
            btnConnect.requestLayout();
1034
            txtCdmInstanceStatus.setText(instanceStatus);
1035
            txtServerSchemaVersion.setText(schemaVersion);
1036
            lblDefaultLogin.setVisible(true);
1037
         });
1038
    }
1015
//    private void checkManagedSelectedInstance() {
1016
//        boolean available = false;
1017
//        String instanceStatus = STATUS_NOT_AVAILABLE;
1018
//        String message = null;
1019
//        String connect = LABEL_CONNECT;
1020
//        Integer color = null;
1021
//        String schemaVersion = CdmMetaData.getDbSchemaVersion();
1022
//
1023
//        if (!schemaExists(selectedCdmInstance)){
1024
//            message = MESG_SCHEMA_MISSING;
1025
//            connect = LABEL_CREATE_SCHEMA;
1026
//            color = BTN_COLOR_ATTENTION;
1027
//            schemaVersion = MESG_NO_SCHEMA;
1028
//        } else {
1029
//            int compare;
1030
//            try {
1031
//                schemaVersion = managedSchemaVersion(selectedCdmInstance);
1032
//                compare = compareSchemaVersion(selectedCdmInstance);
1033
//                if (compare > 0){
1034
//                    instanceStatus = STATUS_NOT_COMPATIBLE;
1035
//                    message = MESG_COMPATIBLE_EDITOR_OLD;
1036
//                    available = false;
1037
//                }else if (compare < 0){
1038
//                    instanceStatus = STATUS_NOT_COMPATIBLE;
1039
//                    message = MESG_UPDATE_SCHEMA_VERSION;
1040
//                    available = true;
1041
//                    connect = LABEL_UPDATE_SCHEMA_VERSION;
1042
//                    color = BTN_COLOR_ATTENTION;
1043
//                }else{
1044
//                    available = true;
1045
//                    instanceStatus = STATUS_AVAILABLE;
1046
//                }
1047
//            } catch (CdmSourceException e) {
1048
//                available = false;
1049
//            }
1050
//        }
1051
//
1052
//        setManagedValues(available, instanceStatus, connect, color, schemaVersion);
1053
//        setMessage(message);
1054
//    }
1055
//
1056
//    private void setManagedValues(boolean available, String instanceStatus, String connect, Integer color,
1057
//            String schemaVersion) {
1058
//        Display.getDefault().syncExec(()->{
1059
//            btnConnect.setEnabled(available);
1060
//            btnConnect.setText(connect);
1061
//            Color systemColor = null;
1062
//            if(color != null) {
1063
//                systemColor = Display.getCurrent().getSystemColor(color);
1064
//            }
1065
//            btnConnect.setBackground(systemColor);
1066
//            btnConnect.requestLayout();
1067
//            txtCdmInstanceStatus.setText(instanceStatus);
1068
//            txtServerSchemaVersion.setText(schemaVersion);
1069
//            lblDefaultLogin.setVisible(true);
1070
//         });
1071
//    }
1039 1072

  
1040
    private void connect() {
1073
    public void connect() {
1041 1074
        checkSelectedCdmInstance();
1042 1075

  
1043 1076
        if(!txtCdmInstanceStatus.getText().equals(STATUS_AVAILABLE)) {
......
1105 1138
        }
1106 1139
    }
1107 1140

  
1108
    private void readPrefCredentials() {
1141
    protected void readPrefCredentials() {
1109 1142
        String username, password;
1110 1143
        IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
1111 1144
        Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
......
1114 1147
        password = credentialsPrefs.get(getPasswordPrefKey(),""); //$NON-NLS-1$
1115 1148
        txtPassword.setText(password);
1116 1149
        if(username.isEmpty() || password.isEmpty()) {
1117
            autoConnect = false;
1150
            setAutoConnect(false);
1118 1151
        }
1119 1152
    }
1120 1153

  
......
1122 1155
        IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
1123 1156
        Preferences lastServerInstancePrefs = preferences.node(LAST_SERVER_INSTANCE_NODE);
1124 1157

  
1125
        serverName = lastServerInstancePrefs.get(LAST_SERVER_KEY, null);
1126
        instanceName = lastServerInstancePrefs.get(LAST_INSTANCE_KEY, null);
1158
        setServerName(lastServerInstancePrefs.get(LAST_SERVER_KEY, null));
1159
        setInstanceName(lastServerInstancePrefs.get(LAST_INSTANCE_KEY, null));
1127 1160
    }
1128 1161

  
1129 1162
    private void emptyCredentials() {
......
1132 1165
    }
1133 1166

  
1134 1167
    private String getUsernamePrefKey() {
1135
        return selectedServerInfo.toString(selectedCdmInstance.getName(), isDevRemoteSource?getPort():-1) + USERNAME_SUFFIX;
1168
        return selectedServerInfo.toString(selectedCdmInstance.getName(), isDevRemoteSource()?getPort():-1) + USERNAME_SUFFIX;
1136 1169
    }
1137 1170

  
1138 1171
    private String getPasswordPrefKey() {
1139
        return selectedServerInfo.toString(selectedCdmInstance.getName(), isDevRemoteSource?getPort():-1) + PASSWORD_SUFFIX;
1172
        return selectedServerInfo.toString(selectedCdmInstance.getName(), isDevRemoteSource()?getPort():-1) + PASSWORD_SUFFIX;
1140 1173
    }
1141 1174

  
1142 1175
    private boolean validateLogin(ICdmRemoteSource remoteSource) {
......
1326 1359
    private String Nz(String value) {
1327 1360
        return CdmUtils.Nz(value);
1328 1361
    }
1362

  
1363
    public Map<String, CdmServerInfo> getServerInfoMap() {
1364
        return serverInfoMap;
1365
    }
1366

  
1367
    public String getServerName() {
1368
        return serverName;
1369
    }
1370

  
1371
    public void setServerName(String serverName) {
1372
        this.serverName = serverName;
1373
    }
1374

  
1375
    public boolean isAutoConnect() {
1376
        return autoConnect;
1377
    }
1378

  
1379
    public void setAutoConnect(boolean autoConnect) {
1380
        this.autoConnect = autoConnect;
1381
    }
1382

  
1383
    public boolean isDevRemoteSource() {
1384
        return isDevRemoteSource;
1385
    }
1386

  
1387
    public void setDevRemoteSource(boolean isDevRemoteSource) {
1388
        this.isDevRemoteSource = isDevRemoteSource;
1389
    }
1390

  
1391
    public String getInstanceName() {
1392
        return instanceName;
1393
    }
1394

  
1395
    public void setInstanceName(String instanceName) {
1396
        this.instanceName = instanceName;
1397
    }
1329 1398
}

Also available in: Unified diff