#5302 Add cdm version and services version check
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / RemotingLoginDialog.java
index 37ba28d86ba7edae1b14a592515c83f391f6062a..0a6b84b3227e8a074ab213156fa04e37ea7e2579 100644 (file)
@@ -9,19 +9,26 @@
  */
 package eu.etaxonomy.taxeditor.ui.dialog;
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.preferences.ConfigurationScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
 import org.eclipse.swt.events.MouseAdapter;
 import org.eclipse.swt.events.MouseEvent;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
@@ -33,11 +40,18 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.events.ExpansionEvent;
+import org.eclipse.ui.forms.events.IExpansionListener;
+import org.eclipse.ui.forms.widgets.ExpandableComposite;
 import org.eclipse.wb.swt.SWTResourceManager;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
 
-import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
+import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
 import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo;
 import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo.CdmInstanceInfo;
 import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
@@ -52,7 +66,6 @@ public class RemotingLoginDialog extends Dialog {
 
     protected Object result;
     protected Shell shlConnect;
-    private Text txtPort;
     private Text txtCdmServerStatus;
     private Text txtCdmInstanceStatus;
     private Combo comboCdmServer;
@@ -61,18 +74,63 @@ public class RemotingLoginDialog extends Dialog {
 
     private final Map<String, CdmServerInfo> csiiMap = new HashMap<String, CdmServerInfo>();
 
-    private final String STATUS_AVAILABLE = "Available";
-    private final String STATUS_NOT_AVAILABLE = "Not Available";
-    private final String STATUS_RETRIEVING = "Retrieving ...";
-    private final String STATUS_CHECKING_AVAILABILITY = "Checking ...";
-    private final String STATUS_NO_INSTANCES = "No Instances Found";
-    private final String STATUS_ERROR = "Error";
-    private final String STATUS_REMOTING_NOT_ACTIVATED = "Remoting not activated";
+    private final static String STATUS_AVAILABLE = "Available";
+    private final static String STATUS_NOT_AVAILABLE = "Not Available";
+    private final static String STATUS_RETRIEVING = "Retrieving ...";
+    private final static String STATUS_CHECKING_AVAILABILITY = "Checking ...";
+    private final static String STATUS_NO_INSTANCES = "No Instances Found";
+    private final static String STATUS_ERROR = "Error";
+    private final static String STATUS_REMOTING_NOT_ACTIVATED = "Remoting not activated";
+    private final static String STATUS_NOT_COMPATIBLE = "Not Compatible";
+
+    private final static String MESG_COMPATIBLE_EDITOR_OLD = "Please update the Taxonomic Editor (Help->Check for Updates) or choose a compatible cdm-server";
+    private final static String MESG_COMPATIBLE_SERVER_OLD = "Please update the chosen cdm-server or choose a compatible cdm-server";
+
+    private final static String STORE_PREFERENCES_NODE = "eu.etaxonomy.taxeditor.store";
+
+    private final static String LOGIN_NODE = "login";
+    private final static String USERNAME_SUFFIX = "_username";
+    private final static String PASSWORD_SUFFIX = "_password";
+
+    private final static String LAST_SERVER_INSTANCE_NODE = "lastServerInstance";
+    private final static String LAST_SERVER_KEY = "lastServerKey";
+    private final static String LAST_INSTANCE_KEY = "lastInstanceKey";
 
+
+    private Composite remotingComposite;
     private CdmServerInfo selectedCsii;
     private CdmInstanceInfo selectedCdmInstance;
     private Button btnCdmServerRefresh;
-
+    private Composite loginComposite;
+    private Label lblLogin;
+    private Text txtLogin;
+    private Label lblPassword;
+    private Text txtPassword;
+    private Button btnRememberMe;
+    private Composite compAdvanced;
+    private Label lblPort;
+    private Text txtPort;
+    private Label lblServerVersion;
+    private Text txtServerVersion;
+    private ExpandableComposite xpndblcmpstAdvanced;
+    private StyledText styledTxtMessage;
+
+
+    private final int MIN_WIDTH = 530;
+    private final int MIN_HEIGHT = 220;
+    private final int MIN_EXP_HEIGHT = 380;
+    private final int MESSAGE_HEIGHT = 25;
+    private Label lblEditorVersion;
+    private Text txtEditorVersion;
+    private Label lblServerCDMVersion;
+    private Text txtServerCDMVersion;
+    private Label lblEditorCDMVersion;
+    private Text txtEditorCDMVersion;
+
+    private String serverName, instanceName;
+    private boolean autoConnect = false;
+    private boolean loadLoginPrefs = true;
+    private boolean isDevRemoteSource = false;
 
     /**
      * Create the dialog.
@@ -84,28 +142,52 @@ public class RemotingLoginDialog extends Dialog {
         setText("Login");
     }
 
+    public Object open(CdmRemoteSource source, boolean loadLoginPrefs, boolean autoConnect) {
+        this.loadLoginPrefs = loadLoginPrefs;
+        this.serverName = source.getName();
+        String contextPath = source.getContextPath();
+        this.instanceName = contextPath.substring(contextPath.lastIndexOf("/") + 1);
+        return open(serverName, instanceName, loadLoginPrefs, autoConnect);
+    }
+
+
+    public Object open(String serverName, String instanceName, boolean loadLoginPrefs, boolean autoConnect) {
+        this.serverName = serverName;
+        this.instanceName = instanceName;
+        this.loadLoginPrefs = loadLoginPrefs;
+        this.autoConnect = autoConnect;
+        return open();
+    }
+
     /**
      * Open the dialog.
      * @return the result
      */
     public Object open() {
-        ICdmRemoteSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
-        if(devRemoteSource != null) {
-            connect(devRemoteSource);
-        } else {
-            createContents();
-            populateCdmServerCombo();
-            shlConnect.open();
-            shlConnect.layout();
+        //        ICdmRemoteSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
+        //        if(devRemoteSource != null) {
+        //            connect(devRemoteSource);
+        //        } else {
+        createContents();
+        if(serverName == null && instanceName == null) {
+            readPrefLastServerInstance();
+        }
 
-            Display display = getParent().getDisplay();
+        setEditorInfo();
+        populateCdmServerCombo();
+        shlConnect.open();
+        shlConnect.layout();
 
-            while (!shlConnect.isDisposed()) {
-                if (!display.readAndDispatch()) {
-                    display.sleep();
-                }
+        xpndblcmpstAdvanced.setExpanded(false);
+
+        Display display = getParent().getDisplay();
+
+        while (!shlConnect.isDisposed()) {
+            if (!display.readAndDispatch()) {
+                display.sleep();
             }
         }
+        //}
         return result;
     }
 
@@ -113,23 +195,20 @@ public class RemotingLoginDialog extends Dialog {
      * Create contents of the dialog.
      */
     private void createContents() {
-        shlConnect = new Shell(getParent(), getStyle());
-        shlConnect.setSize(490, 157);
+        shlConnect = new Shell(getParent(), SWT.DIALOG_TRIM);
+        shlConnect.setMinimumSize(new Point(MIN_WIDTH, MIN_HEIGHT));
+        shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
         shlConnect.setText("Connect");
         shlConnect.setLayout(new FillLayout(SWT.HORIZONTAL));
 
-        Composite composite = new Composite(shlConnect, SWT.NONE);
-        FillLayout fl_composite = new FillLayout(SWT.VERTICAL);
-        fl_composite.spacing = 5;
-        composite.setLayout(fl_composite);
-
-        Composite remotingComposite = new Composite(composite, SWT.NONE);
-        FillLayout fl_remotingComposite = new FillLayout(SWT.VERTICAL);
-        fl_remotingComposite.spacing = 5;
-        remotingComposite.setLayout(fl_remotingComposite);
+        remotingComposite = new Composite(shlConnect, SWT.NONE);
+        remotingComposite.setLayout(new GridLayout(1, false));
 
         Composite cdmServerComposite = new Composite(remotingComposite, SWT.NONE);
-        cdmServerComposite.setLayout(new GridLayout(6, false));
+        GridData gd_cdmServerComposite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+        gd_cdmServerComposite.heightHint = 68;
+        cdmServerComposite.setLayoutData(gd_cdmServerComposite);
+        cdmServerComposite.setLayout(new GridLayout(4, false));
 
         Label lblCdmServer = new Label(cdmServerComposite, SWT.NONE);
         lblCdmServer.setText("CDM Server : ");
@@ -141,6 +220,7 @@ public class RemotingLoginDialog extends Dialog {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 refreshCdmServer();
+                updatePort();
             }
         });
         GridData gd_comboCdmServer = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
@@ -148,14 +228,6 @@ public class RemotingLoginDialog extends Dialog {
         comboCdmServer.setLayoutData(gd_comboCdmServer);
         comboCdmServer.select(0);
 
-        Label lblPortSeparator = new Label(cdmServerComposite, SWT.NONE);
-        lblPortSeparator.setText(" :  ");
-
-        txtPort = new Text(cdmServerComposite, SWT.BORDER);
-        GridData gd_txtPort = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
-        gd_txtPort.widthHint = 50;
-        txtPort.setLayoutData(gd_txtPort);
-
         txtCdmServerStatus = new Text(cdmServerComposite, SWT.BORDER);
         txtCdmServerStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
         txtCdmServerStatus.setEditable(false);
@@ -185,7 +257,7 @@ public class RemotingLoginDialog extends Dialog {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 updateSelectedCdmInstance();
-                checkSelectedCdmServerInstance();
+                checkSelectedCdmInstance();
             }
         });
         GridData gd_comboCdmInstance = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
@@ -196,7 +268,7 @@ public class RemotingLoginDialog extends Dialog {
         txtCdmInstanceStatus = new Text(cdmServerComposite, SWT.BORDER);
         txtCdmInstanceStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
         txtCdmInstanceStatus.setEditable(false);
-        GridData gd_txtCdmInstanceStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
+        GridData gd_txtCdmInstanceStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
         gd_txtCdmInstanceStatus.widthHint = 100;
         txtCdmInstanceStatus.setLayoutData(gd_txtCdmInstanceStatus);
 
@@ -212,42 +284,199 @@ public class RemotingLoginDialog extends Dialog {
         gd_btnCdmInstanceRefresh.heightHint = 30;
         btnCdmInstanceRefresh.setLayoutData(gd_btnCdmInstanceRefresh);
         btnCdmInstanceRefresh.setText("Refresh");
-        new Label(cdmServerComposite, SWT.NONE);
 
-        btnConnect = new Button(cdmServerComposite, SWT.FLAT);
+        loginComposite = new Composite(remotingComposite, SWT.NONE);
+        GridData gd_loginComposite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+        gd_loginComposite.widthHint = 487;
+        gd_loginComposite.heightHint = 70;
+        loginComposite.setLayoutData(gd_loginComposite);
+        GridLayout gl_loginComposite = new GridLayout(6, false);
+        gl_loginComposite.marginTop = 5;
+        loginComposite.setLayout(gl_loginComposite);
+
+        lblLogin = new Label(loginComposite, SWT.CENTER);
+        GridData gd_lblLogin = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
+        gd_lblLogin.widthHint = 50;
+        lblLogin.setLayoutData(gd_lblLogin);
+        lblLogin.setText("Login : ");
+        lblLogin.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
+
+        txtLogin = new Text(loginComposite, SWT.BORDER);
+        GridData gd_txtLogin = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
+        gd_txtLogin.minimumWidth = 80;
+        gd_txtLogin.widthHint = 80;
+        gd_txtLogin.heightHint = 15;
+        txtLogin.setLayoutData(gd_txtLogin);
+
+        lblPassword = new Label(loginComposite, SWT.CENTER);
+        lblPassword.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+        lblPassword.setText("Password : ");
+        lblPassword.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
+
+        txtPassword = new Text(loginComposite, SWT.BORDER | SWT.PASSWORD);
+        GridData gd_txtPassword = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
+        gd_txtPassword.minimumWidth = 80;
+        gd_txtPassword.widthHint = 80;
+        gd_txtPassword.heightHint = 15;
+        txtPassword.setLayoutData(gd_txtPassword);
+        new Label(loginComposite, SWT.NONE);
+
+        btnConnect = new Button(loginComposite, SWT.FLAT);
+        btnConnect.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
         btnConnect.addMouseListener(new MouseAdapter() {
             @Override
             public void mouseUp(MouseEvent e) {
-                int selInstanceIndex = comboCdmInstance.getSelectionIndex();
-                String instance = comboCdmInstance.getItem(selInstanceIndex);
-                checkSelectedCdmServerInstance();
-                connect(selectedCsii.getCdmRemoteSource(selectedCdmInstance));
+                connect();
             }
         });
-        GridData gd_btnConnect = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
-        gd_btnConnect.heightHint = 30;
-        btnConnect.setLayoutData(gd_btnConnect);
         btnConnect.setText("Connect");
-        new Label(cdmServerComposite, SWT.NONE);
-        new Label(cdmServerComposite, SWT.NONE);
-        new Label(cdmServerComposite, SWT.NONE);
-        new Label(cdmServerComposite, SWT.NONE);
+
+        btnRememberMe = new Button(loginComposite, SWT.CHECK);
+        btnRememberMe.setSelection(true);
+        GridData gd_btnRememberMe = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);
+        gd_btnRememberMe.widthHint = 107;
+        btnRememberMe.setLayoutData(gd_btnRememberMe);
+        btnRememberMe.setText("Remember Me");
+        new Label(loginComposite, SWT.NONE);
+        new Label(loginComposite, SWT.NONE);
+        new Label(loginComposite, SWT.NONE);
+        new Label(loginComposite, SWT.NONE);
+
+        styledTxtMessage = new StyledText(remotingComposite, SWT.NONE);
+        styledTxtMessage.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
+        styledTxtMessage.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));
+        styledTxtMessage.setFont(SWTResourceManager.getFont("Ubuntu", 12, SWT.BOLD));
+        styledTxtMessage.setSelectionBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_SELECTION_TEXT));
+        styledTxtMessage.setSelectionForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));
+        styledTxtMessage.setDoubleClickEnabled(false);
+        styledTxtMessage.setEditable(false);
+        GridData gd_styledTxtMessage = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
+        gd_styledTxtMessage.exclude = true;
+        gd_styledTxtMessage.minimumHeight = MESSAGE_HEIGHT;
+        gd_styledTxtMessage.heightHint = MESSAGE_HEIGHT;
+        styledTxtMessage.setLayoutData(gd_styledTxtMessage);
+
+        xpndblcmpstAdvanced = new ExpandableComposite(remotingComposite, SWT.NONE, ExpandableComposite.TWISTIE);
+        GridData gd_xpndblcmpstAdvanced = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
+        gd_xpndblcmpstAdvanced.heightHint = 19;
+        xpndblcmpstAdvanced.setLayoutData(gd_xpndblcmpstAdvanced);
+        xpndblcmpstAdvanced.addExpansionListener(new IExpansionListener() {
+            @Override
+            public void expansionStateChanged(ExpansionEvent e) {
+                GridData gridData = (GridData) xpndblcmpstAdvanced.getLayoutData();
+                if(e.getState()) {
+                    shlConnect.setSize(MIN_WIDTH, MIN_EXP_HEIGHT);
+                } else {
+                    shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
+                }
+
+            }
+            @Override
+            public void expansionStateChanging(ExpansionEvent e) {
+            }
+        });
+        xpndblcmpstAdvanced.setText("advanced");
+        xpndblcmpstAdvanced.setExpanded(true);
+
+        compAdvanced = new Composite(xpndblcmpstAdvanced, SWT.NONE);
+        xpndblcmpstAdvanced.setClient(compAdvanced);
+        compAdvanced.setLayout(new GridLayout(4, false));
+
+        lblPort = new Label(compAdvanced, SWT.CENTER);
+        lblPort.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+        lblPort.setSize(0, 0);
+        lblPort.setText("Port : ");
+        lblPort.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
+
+        txtPort = new Text(compAdvanced, SWT.BORDER);
+        GridData gd_txtPort = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
+        gd_txtPort.minimumWidth = 50;
+        gd_txtPort.widthHint = 50;
+        txtPort.setLayoutData(gd_txtPort);
+
+        lblServerVersion = new Label(compAdvanced, SWT.CENTER);
+        lblServerVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+        lblServerVersion.setText("Server Cdmlib Version :");
+        lblServerVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
+
+        txtServerVersion = new Text(compAdvanced, SWT.BORDER);
+        txtServerVersion.setEditable(false);
+        txtServerVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
+        new Label(compAdvanced, SWT.NONE);
+        new Label(compAdvanced, SWT.NONE);
+
+        lblEditorVersion = new Label(compAdvanced, SWT.CENTER);
+        lblEditorVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+        lblEditorVersion.setText("Editor Cdmlib Version :");
+        lblEditorVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
+
+        txtEditorVersion = new Text(compAdvanced, SWT.BORDER);
+        txtEditorVersion.setEditable(false);
+        txtEditorVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+        new Label(compAdvanced, SWT.NONE);
+        new Label(compAdvanced, SWT.NONE);
+
+        lblServerCDMVersion = new Label(compAdvanced, SWT.CENTER);
+        lblServerCDMVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+        lblServerCDMVersion.setText("Server CDM Version :");
+        lblServerCDMVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
+
+        txtServerCDMVersion = new Text(compAdvanced, SWT.BORDER);
+        txtServerCDMVersion.setEditable(false);
+        txtServerCDMVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+        new Label(compAdvanced, SWT.NONE);
+        new Label(compAdvanced, SWT.NONE);
+
+        lblEditorCDMVersion = new Label(compAdvanced, SWT.CENTER);
+        lblEditorCDMVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+        lblEditorCDMVersion.setText("Editor CDM Version :");
+        lblEditorCDMVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
+
+        txtEditorCDMVersion = new Text(compAdvanced, SWT.BORDER);
+        txtEditorCDMVersion.setEditable(false);
+        txtEditorCDMVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
 
     }
 
+
+
     private void populateCdmServerCombo() {
         Job job = new Job("Retrieve Server Instances") {
             @Override
             protected IStatus run(IProgressMonitor monitor) {
-                Display.getDefault().asyncExec(new Runnable() {
+                Display.getDefault().syncExec(new Runnable() {
                     @Override
                     public void run() {
                         for(CdmServerInfo csii : CdmServerInfo.getCdmServers()) {
                             csiiMap.put(csii.getName(), csii);
                             comboCdmServer.add(csii.getName());
                         }
-                        comboCdmServer.select(0);
+                        int serverIndex = -1;
+                        if(serverName != null) {
+                            serverIndex = comboCdmServer.indexOf(serverName);
+                        }
+                        if(serverIndex == -1) {
+                            comboCdmServer.select(0);
+                            autoConnect = false;
+                        } else {
+                            comboCdmServer.select(serverIndex);
+                        }
+                        CdmRemoteSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
+                        if(devRemoteSource != null) {
+                            isDevRemoteSource = true;
+                        }
                         refreshCdmServer();
+                        updatePort();
+
+                        if(devRemoteSource != null) {
+                            String username = System.getProperty("cdm.server.dev.username");
+                            String password = System.getProperty("cdm.server.dev.password");
+                            if(username != null && !username.isEmpty() && password != null && !password.isEmpty()) {
+                                txtLogin.setText(username);
+                                txtPassword.setText(password);
+                                CdmStore.connect(devRemoteSource, RemotingLoginDialog.this);
+                            }
+                        }
                     }
                 });
                 return Status.OK_STATUS;
@@ -260,7 +489,6 @@ public class RemotingLoginDialog extends Dialog {
     private void refreshCdmServer() {
         txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
         updateSelectedCdmServer();
-        updatePort();
         checkSelectedCdmServer();
     }
 
@@ -278,13 +506,32 @@ public class RemotingLoginDialog extends Dialog {
         }
     }
 
+    private int getPort() {
+        int port = 0;
+        try {
+            port = Integer.valueOf(txtPort.getText());
+        } catch (NumberFormatException nfe) {
+            setMessage("Port should be an integer");
+        }
+        return port;
+    }
+
     private void checkSelectedCdmServer() {
-        int selIndex = comboCdmServer.getSelectionIndex();
-        txtCdmInstanceStatus.setText("");
+
+        clearOnServerChange();
+        emptyCredentials();
+
         if(selectedCsii != null) {
+            if(selectedCsii.isLocalhost()) {
+                txtPort.setEditable(true);
+                txtPort.setEnabled(true);
+            }
             if(selectedCsii.pingServer()) {
                 txtCdmServerStatus.setText(STATUS_AVAILABLE);
                 populateCdmInstanceCombo(true);
+                txtServerVersion.setText(selectedCsii.getCdmlibServicesVersion());
+                txtServerVersion.setToolTipText(generateLastModifiedTooltip(selectedCsii.getCdmlibLastModified()));
+
             } else {
                 txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
                 comboCdmInstance.removeAll();
@@ -298,6 +545,8 @@ public class RemotingLoginDialog extends Dialog {
         comboCdmInstance.setEnabled(false);
         btnConnect.setEnabled(false);
         txtCdmInstanceStatus.setText(STATUS_RETRIEVING);
+        txtCdmInstanceStatus.setToolTipText("");
+
         Job job = new Job("Retrieve Server Instances") {
             @Override
             protected IStatus run(IProgressMonitor monitor) {
@@ -314,10 +563,23 @@ public class RemotingLoginDialog extends Dialog {
                                     for(CdmInstanceInfo cdmInstance : instances) {
                                         comboCdmInstance.add(cdmInstance.getName());
                                     }
-                                    comboCdmInstance.select(0);
+                                    int instanceIndex = -1;
+                                    if(instanceName != null) {
+                                        instanceIndex = comboCdmInstance.indexOf(instanceName);
+                                    }
+                                    if(instanceIndex == -1) {
+                                        comboCdmInstance.select(0);
+                                        autoConnect = false;
+                                    } else {
+                                        comboCdmInstance.select(instanceIndex);
+                                    }
                                     updateSelectedCdmInstance();
-                                    checkSelectedCdmServerInstance();
+                                    checkSelectedCdmInstance();
                                     comboCdmInstance.setEnabled(true);
+                                    if(autoConnect) {
+                                        connect();
+                                    }
+
                                 } else {
                                     txtCdmInstanceStatus.setText(STATUS_NO_INSTANCES);
                                     btnConnect.setEnabled(false);
@@ -325,12 +587,13 @@ public class RemotingLoginDialog extends Dialog {
                             }
                         });
                     }
-                } catch (CDMServerException e) {
+                } catch (final CDMServerException e) {
                     MessagingUtils.warn(getClass(), e);
                     Display.getDefault().asyncExec(new Runnable() {
                         @Override
                         public void run() {
-                            txtCdmInstanceStatus.setText(STATUS_REMOTING_NOT_ACTIVATED);
+                            txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
+                            txtCdmInstanceStatus.setToolTipText(e.getMessage());
                             comboCdmInstance.setEnabled(false);
                             btnConnect.setEnabled(false);
                         }
@@ -340,7 +603,7 @@ public class RemotingLoginDialog extends Dialog {
             }
         };
 
-        if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
+        if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE) && !isDevRemoteSource) {
             // Start the Job
             job.schedule();
         }
@@ -349,53 +612,269 @@ public class RemotingLoginDialog extends Dialog {
 
     private void refreshCdmInstance() {
         txtCdmInstanceStatus.setText(STATUS_CHECKING_AVAILABILITY);
+        clearOnInstanceChange();
         updateSelectedCdmInstance();
-        checkSelectedCdmServerInstance();
+        checkSelectedCdmInstance();
     }
 
     private void updateSelectedCdmInstance() {
         int selIndex = comboCdmInstance.getSelectionIndex();
         if(selIndex != -1) {
             selectedCdmInstance = selectedCsii.getInstanceFromName(comboCdmInstance.getItem(selIndex));
+            if(loadLoginPrefs && !isDevRemoteSource) {
+                readPrefCredentials();
+            }
         }
     }
 
-    private void checkSelectedCdmServerInstance() {
+    private void checkSelectedCdmInstance() {
+        boolean available = false;
+        String status = STATUS_NOT_AVAILABLE;
+        String message = null;
+
         if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
             try {
-                if(selectedCsii.pingInstance(selectedCdmInstance)) {
-                    txtCdmInstanceStatus.setText(STATUS_AVAILABLE);
-                    btnConnect.setEnabled(true);
+                if(selectedCsii.pingInstance(selectedCdmInstance, getPort())) {
+                    status = STATUS_AVAILABLE;
+                    available = true;
                 } else {
-                    txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
-                    btnConnect.setEnabled(false);
+                    status = STATUS_NOT_AVAILABLE;
+                    available = false;
+                }
+
+                if(available) {
+                    txtServerCDMVersion.setText(selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort()).getDbSchemaVersion());
+                    int compareDbSchemaVersion = selectedCsii.compareDbSchemaVersion(selectedCdmInstance, getPort());
+                    int compareCdmlibServicesVersion = selectedCsii.compareCdmlibServicesVersion();
+
+                    if(compareDbSchemaVersion > 0 || compareCdmlibServicesVersion > 0) {
+                        status =  STATUS_NOT_COMPATIBLE;
+                        available = false;
+                        message = MESG_COMPATIBLE_EDITOR_OLD;
+                    } else if(compareDbSchemaVersion < 0 || compareCdmlibServicesVersion < 0) {
+                        status = STATUS_NOT_COMPATIBLE;
+                        available = false;
+                        message = MESG_COMPATIBLE_SERVER_OLD;
+                    } else {
+                        status =  STATUS_AVAILABLE;
+                        available = true;
+                        message = "";
+                    }
+
+
                 }
+
             } catch (Exception e) {
-                txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
-                MessagingUtils.warn(this.getClass(), e);
+                txtCdmInstanceStatus.setToolTipText(e.getMessage());
+            } finally {
+                btnConnect.setEnabled(available);
+                txtCdmInstanceStatus.setText(status);
+                if(!StringUtils.isBlank(message)) {
+                    setMessage(message);
+                }
             }
+
         }
 
     }
 
-    private void connect(ICdmRemoteSource source) {
-        if(CdmStore.isConnecting()){
-            MessagingUtils.warningDialog("Already connecting", this, "You are currently connecting to a different CDM Instance already.");
+    private void connect() {
+        checkSelectedCdmInstance();
+
+        if(!txtCdmInstanceStatus.getText().equals(STATUS_AVAILABLE)) {
+            return;
+        }
+
+        ICdmRemoteSource source = selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort());
+
+        if(!validateLogin()) {
             return;
         }
 
         try {
-            CdmDataSourceRepository.changeDataSource(source);
+            CdmStore.connect(source, this);
         } catch (Exception e) {
             // Do not expect anything to go wrong at this point, so we throw a runtime exception
             // if any problems
             throw new RuntimeException(e);
         }
 
-        if(shlConnect != null) {
+    }
+
+
+    public boolean isRememberMe() {
+        return btnRememberMe.getSelection();
+    }
+
+    private void persistPrefLastServerInstance() {
+        IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
+        Preferences lastServerInstancePrefs = preferences.node(LAST_SERVER_INSTANCE_NODE);
+
+        lastServerInstancePrefs.put(LAST_SERVER_KEY, selectedCsii.getName());
+        lastServerInstancePrefs.put(LAST_INSTANCE_KEY, selectedCdmInstance.getName());
+
+        flushPreferences(lastServerInstancePrefs);
+    }
+
+    private void persistPrefCredentials() {
+         IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
+         Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
+         credentialsPrefs.put(getUsernamePrefKey(), txtLogin.getText());
+         credentialsPrefs.put(getPasswordPrefKey(), txtPassword.getText());
+         flushPreferences(credentialsPrefs);
+    }
+
+    private void flushPreferences(Preferences prefs) {
+        try {
+            prefs.flush();
+        } catch (BackingStoreException bse) {
+            setMessage(bse.getMessage());
+        }
+    }
+
+    private void readPrefCredentials() {
+        String username, password;
+        IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
+        Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
+        username = credentialsPrefs.get(getUsernamePrefKey(), "");
+        txtLogin.setText(username);
+        password = credentialsPrefs.get(getPasswordPrefKey(),"");
+        txtPassword.setText(password);
+        if(username.isEmpty() || password.isEmpty()) {
+            autoConnect = false;
+        }
+    }
+
+    private void readPrefLastServerInstance() {
+        IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
+        Preferences lastServerInstancePrefs = preferences.node(LAST_SERVER_INSTANCE_NODE);
+
+        serverName = lastServerInstancePrefs.get(LAST_SERVER_KEY, null);
+        instanceName = lastServerInstancePrefs.get(LAST_INSTANCE_KEY, null);
+    }
+
+    private void emptyCredentials() {
+        txtLogin.setText("");
+        txtPassword.setText("");
+    }
+
+    private String getUsernamePrefKey() {
+        return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + USERNAME_SUFFIX;
+    }
+
+    private String getPasswordPrefKey() {
+        return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + PASSWORD_SUFFIX;
+    }
+
+    private boolean validateLogin() {
+        if(getUsername() == null || getUsername().isEmpty()) {
+            setMessage("User login cannot be empty");
+            return false;
+        }
+        if(getPassword() == null || getPassword().isEmpty()) {
+            setMessage("Password cannot be empty");
+            return false;
+        }
+        return true;
+    }
+    public String getUsername() {
+        return txtLogin.getText();
+    }
+
+    public String getPassword() {
+        return txtPassword.getText();
+    }
+
+    public void setMessage(String message) {
+        if(message != null && !message.isEmpty()) {
+            if(message.length() > 60) {
+                styledTxtMessage.setToolTipText(message);
+                message = message.substring(0, 60) + "...";
+            }
+            styledTxtMessage.setText(message);
+            styledTxtMessage.setVisible(true);
+            ((GridData)styledTxtMessage.getLayoutData()).exclude = false;
+            shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
+            shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage() + MESSAGE_HEIGHT);
+        } else {
+            styledTxtMessage.setText("");
+            styledTxtMessage.setVisible(false);
+            ((GridData)styledTxtMessage.getLayoutData()).exclude = true;
+            shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage());
+            shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage());
+        }
+        remotingComposite.layout();
+    }
+
+    private int getHeightWithoutMessage() {
+        if(xpndblcmpstAdvanced.isExpanded()) {
+            return MIN_EXP_HEIGHT;
+        } else {
+            return MIN_HEIGHT;
+        }
+    }
+
+
+    public void hide(boolean isHidden) {
+        if(shlConnect != null && shlConnect.getDisplay() != null) {
+            shlConnect.setVisible(!isHidden);
+        }
+    }
+    public void dispose() {
+        if(shlConnect != null && shlConnect.getDisplay() != null) {
             shlConnect.dispose();
         }
     }
 
+    public void onComplete() {
+        Display.getDefault().asyncExec(new Runnable() {
+            @Override
+            public void run() {
+                if(!isDevRemoteSource) {
+                    if(isRememberMe()) {
+                        persistPrefCredentials();
+                    }
+                    persistPrefLastServerInstance();
+                }
+                dispose();
+            }
+        });
+    }
+
+    private String generateLastModifiedTooltip(String cdmlibLastModified) {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z");
+        Date cdmlibLastModifiedDate;
+        String cdmlibLastModifiedTimestamp = "";
+
+        cdmlibLastModifiedDate = new Date(Long.valueOf(cdmlibLastModified));
+        cdmlibLastModifiedTimestamp = sdf.format(cdmlibLastModifiedDate);
+
+        return "last modified : " + cdmlibLastModifiedTimestamp;
+    }
+
+    private void setEditorInfo() {
+        txtEditorCDMVersion.setText(CdmMetaData.getDbSchemaVersion());
+        txtEditorVersion.setText(CdmApplicationState.getCdmlibVersion());
+        txtEditorVersion.setToolTipText(generateLastModifiedTooltip(CdmApplicationState.getCdmlibLastModified()));
+    }
+
+    private void clearOnServerChange() {
+        setMessage("");
+        txtServerCDMVersion.setText("");
+        txtServerVersion.setText("");
+        txtServerVersion.setToolTipText("");
+        txtServerCDMVersion.setText("");
+        txtPort.setEditable(false);
+        txtPort.setEnabled(false);
+    }
+
+    private void clearOnInstanceChange() {
+        setMessage("");
+        txtServerCDMVersion.setText("");
+    }
+
+    private void updateOnServerChange(String serverVersion, String serverVersionTooltip) {
+
+    }
 
 }