ref #7981: implement aggregation configuration wizard
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / RemotingLoginDialog.java
index 0a6b84b3227e8a074ab213156fa04e37ea7e2579..004a26e2f656ec53caa5b831cf24105cddc3781c 100644 (file)
@@ -1,4 +1,3 @@
-// $Id$
 /**
  * Copyright (C) 2015 EDIT
  * European Distributed Institute of Taxonomy
@@ -9,6 +8,8 @@
  */
 package eu.etaxonomy.taxeditor.ui.dialog;
 
+import java.io.File;
+import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.HashMap;
@@ -16,14 +17,19 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
 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.jface.layout.GridDataFactory;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTException;
 import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
 import org.eclipse.swt.events.MouseAdapter;
 import org.eclipse.swt.events.MouseEvent;
 import org.eclipse.swt.events.SelectionAdapter;
@@ -43,28 +49,50 @@ 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.ui.progress.IProgressConstants;
 import org.eclipse.wb.swt.SWTResourceManager;
 import org.osgi.service.prefs.BackingStoreException;
 import org.osgi.service.prefs.Preferences;
+import org.springframework.security.authentication.BadCredentialsException;
+import org.springframework.security.authentication.LockedException;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 
+import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteConfiguration;
 import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+import eu.etaxonomy.cdm.api.service.IUserService;
 import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
+import eu.etaxonomy.taxeditor.l10n.Messages;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
+import eu.etaxonomy.taxeditor.remoting.server.CDMServerUtils;
 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;
 import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.LoginManager;
+import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
+import eu.etaxonomy.taxeditor.webapp.CDMEmbeddedServerException;
+import eu.etaxonomy.taxeditor.webapp.CDMServer;
+import eu.etaxonomy.taxeditor.webapp.ICDMServerError;
+
 
 /**
  * @author cmathew
  * @date 20 Jan 2015
  *
  */
-public class RemotingLoginDialog extends Dialog {
+public class RemotingLoginDialog extends Dialog implements ICDMServerError {
+
+    private Logger logger = Logger.getLogger(getClass());
 
-    protected Object result;
+    private static final String DEFAULT_PASS = "00000"; //$NON-NLS-1$
+    private static final String DEFAULT_USER = "admin"; //$NON-NLS-1$
+    private static final String UBUNTU = "Ubuntu"; //$NON-NLS-1$
+       protected Object result;
     protected Shell shlConnect;
     private Text txtCdmServerStatus;
     private Text txtCdmInstanceStatus;
@@ -74,33 +102,35 @@ public class RemotingLoginDialog extends Dialog {
 
     private final Map<String, CdmServerInfo> csiiMap = new HashMap<String, CdmServerInfo>();
 
-    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 STATUS_AVAILABLE = Messages.RemotingLoginDialog_STATUS_AVAILABLE;
+    private final static String STATUS_NOT_AVAILABLE = Messages.RemotingLoginDialog_STATUS_NOT_AVAILABLE;
+    private final static String STATUS_STARTED = Messages.RemotingLoginDialog_STATUS_STARTED;
+    private final static String STATUS_NOT_STARTED = Messages.RemotingLoginDialog_STATUS_NOT_STARTED;
+    private final static String STATUS_RETRIEVING = Messages.RemotingLoginDialog_STATUS_RETRIEVING;
+    private final static String STATUS_CHECKING_AVAILABILITY = Messages.RemotingLoginDialog_STATUS_CHECKING;
+    private final static String STATUS_NO_INSTANCES = Messages.RemotingLoginDialog_STATUS_NO_INSTANCES_FOUND;
+    private final static String STATUS_NOT_COMPATIBLE = Messages.RemotingLoginDialog_STATUS_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 MESG_COMPATIBLE_EDITOR_OLD = Messages.RemotingLoginDialog_UPDATE_EDITOR;
+    private final static String MESG_COMPATIBLE_SERVER_OLD = Messages.RemotingLoginDialog_CHOOSE_COMPATIBLE_CDM_SERVER;
 
-    private final static String STORE_PREFERENCES_NODE = "eu.etaxonomy.taxeditor.store";
+    private final static String STORE_PREFERENCES_NODE = "eu.etaxonomy.taxeditor.store"; //$NON-NLS-1$
 
-    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 LOGIN_NODE = "login"; //$NON-NLS-1$
+    private final static String USERNAME_SUFFIX = "_username"; //$NON-NLS-1$
+    private final static String PASSWORD_SUFFIX = "_password"; //$NON-NLS-1$
 
-    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 final static String LAST_SERVER_INSTANCE_NODE = "lastServerInstance"; //$NON-NLS-1$
+    private final static String LAST_SERVER_KEY = "lastServerKey"; //$NON-NLS-1$
+    private final static String LAST_INSTANCE_KEY = "lastInstanceKey"; //$NON-NLS-1$
 
 
     private Composite remotingComposite;
     private CdmServerInfo selectedCsii;
     private CdmInstanceInfo selectedCdmInstance;
     private Button btnCdmServerRefresh;
+    private Button btnCdmInstanceRefresh;
+    private Button btnStopServer;
     private Composite loginComposite;
     private Label lblLogin;
     private Text txtLogin;
@@ -119,7 +149,7 @@ public class RemotingLoginDialog extends Dialog {
     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 final int MESSAGE_HEIGHT = 50;
     private Label lblEditorVersion;
     private Text txtEditorVersion;
     private Label lblServerCDMVersion;
@@ -131,7 +161,7 @@ public class RemotingLoginDialog extends Dialog {
     private boolean autoConnect = false;
     private boolean loadLoginPrefs = true;
     private boolean isDevRemoteSource = false;
-
+    private Job serverJob;
     /**
      * Create the dialog.
      * @param parent
@@ -139,14 +169,14 @@ public class RemotingLoginDialog extends Dialog {
      */
     public RemotingLoginDialog(Shell parent, int style) {
         super(parent, style);
-        setText("Login");
+        setText(Messages.RemotingLoginDialog_LABEL_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);
+        this.instanceName = contextPath.substring(contextPath.lastIndexOf("/") + 1); //$NON-NLS-1$
         return open(serverName, instanceName, loadLoginPrefs, autoConnect);
     }
 
@@ -164,10 +194,7 @@ public class RemotingLoginDialog extends Dialog {
      * @return the result
      */
     public Object open() {
-        //        ICdmRemoteSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
-        //        if(devRemoteSource != null) {
-        //            connect(devRemoteSource);
-        //        } else {
+
         createContents();
         if(serverName == null && instanceName == null) {
             readPrefLastServerInstance();
@@ -183,11 +210,13 @@ public class RemotingLoginDialog extends Dialog {
         Display display = getParent().getDisplay();
 
         while (!shlConnect.isDisposed()) {
-            if (!display.readAndDispatch()) {
-                display.sleep();
+            if (!display.isDisposed()){
+                if (!display.readAndDispatch()) {
+                    display.sleep();
+                }
             }
         }
-        //}
+
         return result;
     }
 
@@ -195,10 +224,10 @@ public class RemotingLoginDialog extends Dialog {
      * Create contents of the dialog.
      */
     private void createContents() {
-        shlConnect = new Shell(getParent(), SWT.DIALOG_TRIM);
+        shlConnect = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
         shlConnect.setMinimumSize(new Point(MIN_WIDTH, MIN_HEIGHT));
         shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
-        shlConnect.setText("Connect");
+        shlConnect.setText(Messages.RemotingLoginDialog_LABEL_CONNECT);
         shlConnect.setLayout(new FillLayout(SWT.HORIZONTAL));
 
         remotingComposite = new Composite(shlConnect, SWT.NONE);
@@ -211,8 +240,8 @@ public class RemotingLoginDialog extends Dialog {
         cdmServerComposite.setLayout(new GridLayout(4, false));
 
         Label lblCdmServer = new Label(cdmServerComposite, SWT.NONE);
-        lblCdmServer.setText("CDM Server : ");
-        lblCdmServer.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
+        lblCdmServer.setText(Messages.RemotingLoginDialog_LABEL_CDM_SERVER);
+        lblCdmServer.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
         lblCdmServer.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
 
         comboCdmServer = new Combo(cdmServerComposite, SWT.READ_ONLY);
@@ -220,7 +249,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);
@@ -233,6 +262,7 @@ public class RemotingLoginDialog extends Dialog {
         txtCdmServerStatus.setEditable(false);
         GridData gd_txtCdmServerStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
         gd_txtCdmServerStatus.widthHint = 100;
+
         txtCdmServerStatus.setLayoutData(gd_txtCdmServerStatus);
 
         btnCdmServerRefresh = new Button(cdmServerComposite, SWT.NONE);
@@ -243,21 +273,20 @@ public class RemotingLoginDialog extends Dialog {
             }
         });
         btnCdmServerRefresh.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
-        btnCdmServerRefresh.setText("Refresh");
+        btnCdmServerRefresh.setText(Messages.RemotingLoginDialog_LABEL_REFRESH);
 
         Label lblCdmInstance = new Label(cdmServerComposite, SWT.NONE);
         GridData gd_lblCdmInstance = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
         gd_lblCdmInstance.heightHint = 30;
         lblCdmInstance.setLayoutData(gd_lblCdmInstance);
-        lblCdmInstance.setText("CDM Instance : ");
-        lblCdmInstance.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
+        lblCdmInstance.setText(Messages.RemotingLoginDialog_LABEL_CDM_INSTANCE);
+        lblCdmInstance.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
 
         comboCdmInstance = new Combo(cdmServerComposite, SWT.READ_ONLY);
         comboCdmInstance.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                updateSelectedCdmInstance();
-                checkSelectedCdmInstance();
+                refreshCdmInstance();
             }
         });
         GridData gd_comboCdmInstance = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
@@ -272,7 +301,7 @@ public class RemotingLoginDialog extends Dialog {
         gd_txtCdmInstanceStatus.widthHint = 100;
         txtCdmInstanceStatus.setLayoutData(gd_txtCdmInstanceStatus);
 
-        Button btnCdmInstanceRefresh = new Button(cdmServerComposite, SWT.FLAT);
+        btnCdmInstanceRefresh = new Button(cdmServerComposite, SWT.FLAT);
         btnCdmInstanceRefresh.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
@@ -283,7 +312,7 @@ public class RemotingLoginDialog extends Dialog {
         gd_btnCdmInstanceRefresh.widthHint = 110;
         gd_btnCdmInstanceRefresh.heightHint = 30;
         btnCdmInstanceRefresh.setLayoutData(gd_btnCdmInstanceRefresh);
-        btnCdmInstanceRefresh.setText("Refresh");
+        btnCdmInstanceRefresh.setText(Messages.RemotingLoginDialog_LABEL_REFRESH);
 
         loginComposite = new Composite(remotingComposite, SWT.NONE);
         GridData gd_loginComposite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
@@ -298,8 +327,8 @@ public class RemotingLoginDialog extends Dialog {
         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));
+        lblLogin.setText(Messages.RemotingLoginDialog_LABEL_LOGIN_COLON);
+        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);
@@ -310,8 +339,8 @@ public class RemotingLoginDialog extends Dialog {
 
         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));
+        lblPassword.setText(Messages.RemotingLoginDialog_LABEL_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);
@@ -320,50 +349,61 @@ public class RemotingLoginDialog extends Dialog {
         gd_txtPassword.heightHint = 15;
         txtPassword.setLayoutData(gd_txtPassword);
         new Label(loginComposite, SWT.NONE);
+        txtPassword.addKeyListener(new KeyAdapter() {
+               @Override
+               public void keyPressed(KeyEvent e) {
+                       if(e.character==SWT.CR){
+                               connectButtonPressed();
+                       }
+               }
+        });
 
         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) {
-                connect();
-            }
-        });
-        btnConnect.setText("Connect");
+        btnConnect.addSelectionListener(new SelectionAdapter() {
+                       @Override
+                       public void widgetSelected(SelectionEvent e) {
+                               connectButtonPressed();
+                       }
+               });
+        btnConnect.setText(Messages.RemotingLoginDialog_LABEL_CONNECT);
 
         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);
+        btnRememberMe.setText(Messages.RemotingLoginDialog_LABEL_REMEMBER_ME);
+
+        Label lblDefaultLogin = new Label(loginComposite, SWT.NONE);
+        GridDataFactory.fillDefaults().span(4, 1).align(SWT.TRAIL, SWT.CENTER).applyTo(lblDefaultLogin);
+        lblDefaultLogin.setText(String.format(Messages.RemotingLoginDialog_DEFAULT_LOGIN, DEFAULT_USER, DEFAULT_PASS));
 
         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.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);
+        styledTxtMessage.setWordWrap(true);
+
         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;
+        gd_styledTxtMessage.widthHint = MIN_WIDTH - 5;
+
         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;
+        gd_xpndblcmpstAdvanced.widthHint = MIN_WIDTH - 10;
         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 {
@@ -375,7 +415,7 @@ public class RemotingLoginDialog extends Dialog {
             public void expansionStateChanging(ExpansionEvent e) {
             }
         });
-        xpndblcmpstAdvanced.setText("advanced");
+        xpndblcmpstAdvanced.setText(Messages.RemotingLoginDialog_LABEL_ADVANCED);
         xpndblcmpstAdvanced.setExpanded(true);
 
         compAdvanced = new Composite(xpndblcmpstAdvanced, SWT.NONE);
@@ -385,8 +425,8 @@ public class RemotingLoginDialog extends Dialog {
         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));
+        lblPort.setText(Messages.RemotingLoginDialog_LABEL_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);
@@ -396,19 +436,26 @@ public class RemotingLoginDialog extends Dialog {
 
         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));
+        lblServerVersion.setText(Messages.RemotingLoginDialog_LABEL_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);
+        btnStopServer = new Button(compAdvanced, SWT.FLAT);
+        btnStopServer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
+        btnStopServer.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mouseUp(MouseEvent e) {
+                stopManagedServer();
+            }
+        });
+        btnStopServer.setText(Messages.RemotingLoginDialog_LABEL_STOP_MANAGED_SERVER);
 
         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));
+        lblEditorVersion.setText(Messages.RemotingLoginDialog_LABEL_EDITOR_CDMLIB_VERSION);
+        lblEditorVersion.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
 
         txtEditorVersion = new Text(compAdvanced, SWT.BORDER);
         txtEditorVersion.setEditable(false);
@@ -418,8 +465,8 @@ public class RemotingLoginDialog extends Dialog {
 
         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));
+        lblServerCDMVersion.setText(Messages.RemotingLoginDialog_LABEL_SERVER_CDM_VERSION);
+        lblServerCDMVersion.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
 
         txtServerCDMVersion = new Text(compAdvanced, SWT.BORDER);
         txtServerCDMVersion.setEditable(false);
@@ -429,8 +476,8 @@ public class RemotingLoginDialog extends Dialog {
 
         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));
+        lblEditorCDMVersion.setText(Messages.RemotingLoginDialog_LABEL_EDITOR_CDM_VERSION);
+        lblEditorCDMVersion.setFont(SWTResourceManager.getFont(UBUNTU, 9, SWT.NORMAL));
 
         txtEditorCDMVersion = new Text(compAdvanced, SWT.BORDER);
         txtEditorCDMVersion.setEditable(false);
@@ -438,10 +485,20 @@ public class RemotingLoginDialog extends Dialog {
 
     }
 
+       private void connectButtonPressed() {
+               if(selectedCsii.isLocalhostMgd() && !isSelectedCdmInstanceRunningInManagedServer()) {
+                       startManagedServer();
+               } else {
+                       connect();
+                       if (CdmStore.isActive() && CdmStore.currentAuthentiationHasOneOfRoles(Role.ROLE_REMOTING)){
+                           PreferencesUtil.setNomenclaturalCodePreferences();
+                       }
 
+               }
+       }
 
     private void populateCdmServerCombo() {
-        Job job = new Job("Retrieve Server Instances") {
+        Job job = new Job(Messages.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES) {
             @Override
             protected IStatus run(IProgressMonitor monitor) {
                 Display.getDefault().syncExec(new Runnable() {
@@ -464,18 +521,15 @@ public class RemotingLoginDialog extends Dialog {
                         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");
+                            String username = System.getProperty("cdm.server.dev.username"); //$NON-NLS-1$
+                            String password = System.getProperty("cdm.server.dev.password"); //$NON-NLS-1$
                             if(username != null && !username.isEmpty() && password != null && !password.isEmpty()) {
                                 txtLogin.setText(username);
                                 txtPassword.setText(password);
                                 CdmStore.connect(devRemoteSource, RemotingLoginDialog.this);
                             }
+                        } else {
+                            refreshCdmServer();
                         }
                     }
                 });
@@ -487,9 +541,22 @@ public class RemotingLoginDialog extends Dialog {
 
 
     private void refreshCdmServer() {
-        txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
-        updateSelectedCdmServer();
-        checkSelectedCdmServer();
+        try{
+            txtCdmServerStatus.setText(STATUS_CHECKING_AVAILABILITY);
+            clearOnServerChange();
+            emptyCredentials();
+            updateSelectedCdmServer();
+            Display.getDefault().asyncExec(new Runnable() {
+                @Override
+                public void run() {
+                    checkSelectedCdmServer();
+                }
+            });
+        }
+        catch(SWTException e){
+            //catch widget is disposed exception which may occurr if
+            //dialog is closed but the runnable tries to update
+        }
     }
 
     private void updateSelectedCdmServer() {
@@ -500,42 +567,59 @@ public class RemotingLoginDialog extends Dialog {
     }
 
     private void updatePort() {
-        txtPort.setText("");
+        txtPort.setText(""); //$NON-NLS-1$
         if(selectedCsii != null) {
-            txtPort.setText(String.valueOf(selectedCsii.getPort()));
+            int port = selectedCsii.getPort();
+            if(port == CdmServerInfo.NULL_PORT) {
+                txtPort.setText(CdmServerInfo.NULL_PORT_STRING);
+            } else {
+                txtPort.setText(String.valueOf(port));
+            }
         }
     }
 
     private int getPort() {
-        int port = 0;
+        int port = CdmServerInfo.NULL_PORT;
         try {
             port = Integer.valueOf(txtPort.getText());
         } catch (NumberFormatException nfe) {
-            setMessage("Port should be an integer");
+            if(!CdmServerInfo.NULL_PORT_STRING.equals(txtPort.getText())) {
+                setMessage(Messages.RemotingLoginDialog_MESSAGE_PORT_SHOULD_BE_INTEGER);
+            }
         }
         return port;
     }
 
     private void checkSelectedCdmServer() {
-
-        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();
+        try{
+            if(selectedCsii != null) {
+                if(selectedCsii.isLocalhost()) {
+                    txtPort.setEditable(true);
+                    txtPort.setEnabled(true);
+                }
+                try {
+                    if(selectedCsii.pingServer()) {
+                        txtCdmServerStatus.setText(STATUS_AVAILABLE);
+                        populateCdmInstanceCombo(true);
+                        String serverVersionTimestamp = generateLastModifiedTooltip(selectedCsii.getCdmlibLastModified());
+                        txtServerVersion.setText(selectedCsii.getCdmlibServicesVersion() + ":" + serverVersionTimestamp); //$NON-NLS-1$
+                    } else {
+                        txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
+                        comboCdmInstance.removeAll();
+                        disableCdmInstanceControls("", ""); //$NON-NLS-1$ //$NON-NLS-2$
+                    }
+                } catch (CDMServerException | IOException e) {
+                    txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
+                    MessagingUtils.warningDialog(Messages.RemotingLoginDialog_CONNECTION_FAILED_TITLE, this,
+                            Messages.RemotingLoginDialog_CONNECTION_FAILED_MESSAGE);
+                    logger.warn(Messages.RemotingLoginDialog_CONNECTION_FAILED_TITLE, e);
+                }
             }
+            updatePort();
+        }
+        catch(SWTException e){
+            //catch widget is disposed exception which may occurr if
+            //dialog is closed but the runnable tries to update
         }
     }
 
@@ -545,9 +629,9 @@ public class RemotingLoginDialog extends Dialog {
         comboCdmInstance.setEnabled(false);
         btnConnect.setEnabled(false);
         txtCdmInstanceStatus.setText(STATUS_RETRIEVING);
-        txtCdmInstanceStatus.setToolTipText("");
+        txtCdmInstanceStatus.setToolTipText(""); //$NON-NLS-1$
 
-        Job job = new Job("Retrieve Server Instances") {
+        serverJob = new Job(Messages.RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES) {
             @Override
             protected IStatus run(IProgressMonitor monitor) {
                 try {
@@ -573,8 +657,7 @@ public class RemotingLoginDialog extends Dialog {
                                     } else {
                                         comboCdmInstance.select(instanceIndex);
                                     }
-                                    updateSelectedCdmInstance();
-                                    checkSelectedCdmInstance();
+                                    refreshCdmInstance();
                                     comboCdmInstance.setEnabled(true);
                                     if(autoConnect) {
                                         connect();
@@ -592,10 +675,7 @@ public class RemotingLoginDialog extends Dialog {
                     Display.getDefault().asyncExec(new Runnable() {
                         @Override
                         public void run() {
-                            txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
-                            txtCdmInstanceStatus.setToolTipText(e.getMessage());
-                            comboCdmInstance.setEnabled(false);
-                            btnConnect.setEnabled(false);
+                            disableCdmInstanceControls(STATUS_NOT_AVAILABLE, e.getMessage());
                         }
                     });
                 }
@@ -605,28 +685,168 @@ public class RemotingLoginDialog extends Dialog {
 
         if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE) && !isDevRemoteSource) {
             // Start the Job
-            job.schedule();
+            serverJob.schedule();
         }
-
     }
 
+    private void disableCdmInstanceControls(String cdmInstanceStatus, String tooltip) {
+        txtCdmInstanceStatus.setText(cdmInstanceStatus);
+        txtCdmInstanceStatus.setToolTipText(tooltip);
+        comboCdmInstance.setEnabled(false);
+        btnConnect.setEnabled(false);
+
+    }
     private void refreshCdmInstance() {
         txtCdmInstanceStatus.setText(STATUS_CHECKING_AVAILABILITY);
         clearOnInstanceChange();
         updateSelectedCdmInstance();
         checkSelectedCdmInstance();
+        updateManagedServerControls();
     }
 
     private void updateSelectedCdmInstance() {
         int selIndex = comboCdmInstance.getSelectionIndex();
         if(selIndex != -1) {
             selectedCdmInstance = selectedCsii.getInstanceFromName(comboCdmInstance.getItem(selIndex));
-            if(loadLoginPrefs && !isDevRemoteSource) {
+
+            if(loadLoginPrefs) {
                 readPrefCredentials();
             }
         }
     }
 
+    private void updateManagedServerControls() {
+        if(selectedCsii.isLocalhostMgd()) {
+            if(isSelectedCdmInstanceRunningInManagedServer()) {
+                txtCdmInstanceStatus.setText(STATUS_STARTED);
+            } else {
+                txtCdmInstanceStatus.setText(STATUS_NOT_STARTED);
+            }
+            btnConnect.setEnabled(true);
+            selectedCsii.setPort(getManagedServerPort());
+            updatePort();
+        }
+
+
+        if(isManagedServerRunning()) {
+            btnStopServer.setEnabled(true);
+        } else {
+            btnStopServer.setEnabled(false);
+        }
+    }
+
+    private boolean isManagedServerRunning() {
+        return CdmStore.getManagedServer() != null && CdmStore.getManagedServer().isAlive();
+    }
+
+    private boolean isSelectedCdmInstanceRunningInManagedServer() {
+        return CdmStore.getManagedServer() != null &&
+                CdmStore.getManagedServer().isAlive() &&
+                selectedCsii.isLocalhostMgd() &&
+                CdmStore.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName());
+    }
+
+    private void startManagedServer() {
+        if(isManagedServerRunning()) {
+            if(CdmStore.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName())) {
+                return;
+            } else {
+                Display.getDefault().syncExec(new Runnable() {
+                    @Override
+                    public void run() {
+                        stopManagedServer();
+                    }
+                });
+            }
+        }
+
+
+        Job job = new Job(Messages.RemotingLoginDialog_JOB_SERVER_LAUNCH) {
+
+            @Override
+            public IStatus run(IProgressMonitor monitor) {
+                String mgdServerConfigFileName = "mgd.datasources.xml"; //$NON-NLS-1$
+                String config = CDMServerUtils.convertEditorToServerConfig();
+                File managedServerConfigFile;
+                int maxUnits = 50;
+                monitor.beginTask(Messages.RemotingLoginDialog_TASK_LAUNCHING_SERVER, maxUnits);
+                try {
+                    monitor.subTask(String.format(Messages.RemotingLoginDialog_GENERATING_CONFIG_FILE, selectedCdmInstance.getName()));
+                    managedServerConfigFile = CDMServerUtils.writeManagedServerConfig(config, mgdServerConfigFileName);
+                    monitor.worked(1);
+                    CdmStore.setManagedServer(new CDMServer(selectedCdmInstance.getName(), managedServerConfigFile));
+                    monitor.subTask(Messages.RemotingLoginDialog_STARTING_MGD_SERVER);
+                    CdmStore.getManagedServer().start(false, RemotingLoginDialog.this);
+                    int serverUnits = 0;
+
+                    // the following loop is a 'fake' progress monitoring where the progress
+                    // bar is advanced by one unit every second until maxUnits -2
+                    while(!CdmStore.getManagedServer().isStarted() && !CdmStore.getManagedServer().isFailed()) {
+                        if(serverUnits < maxUnits - 2) {
+                            try {
+                                Thread.sleep(1000);
+                            } catch (InterruptedException e) {
+                            }
+                            monitor.worked(1);
+                            serverUnits++;
+                        }
+                    }
+                    Display.getDefault().asyncExec(new Runnable() {
+                        @Override
+                        public void run() {
+                                hide(false);
+                                updateManagedServerControls();
+                                connect();
+                            }
+                    });
+                } catch (IOException ioe) {
+                    MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_GENERATING_CONFIG_FILE,
+                            this,
+                            ioe.getMessage(),
+                            TaxeditorStorePlugin.PLUGIN_ID,
+                            ioe,
+                            true);
+                } catch (CDMEmbeddedServerException cse) {
+                    MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_STARTING_SERVER,
+                            this,
+                            cse.getMessage(),
+                            TaxeditorStorePlugin.PLUGIN_ID,
+                            cse,
+                            true);
+                } finally {
+                    monitor.done();
+                }
+                return Status.OK_STATUS;
+            }
+        };
+
+        // configure the job
+        job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
+        job.setUser(true);
+        // schedule job
+        hide(true);
+        job.schedule();
+    }
+
+    private void stopManagedServer() {
+        try {
+            CdmStore.getManagedServer().stop();
+        } catch (Exception e) {
+            MessagingUtils.errorDialog(Messages.RemotingLoginDialog_ERROR_STOPPING_SERVER,
+                    this,
+                    String.format(Messages.RemotingLoginDialog_COULD_NOT_STOP_SERVER, CdmStore.getManagedServer().getPort()),
+                    TaxeditorStorePlugin.PLUGIN_ID,
+                    e,
+                    true);
+        }
+        CdmStore.setManagedServer(null);
+        updateManagedServerControls();
+    }
+
+    private int getManagedServerPort() {
+        return CdmStore.getManagedServer() == null ? CdmServerInfo.NULL_PORT : CdmStore.getManagedServer().getPort();
+    }
+
     private void checkSelectedCdmInstance() {
         boolean available = false;
         String status = STATUS_NOT_AVAILABLE;
@@ -645,8 +865,12 @@ public class RemotingLoginDialog extends Dialog {
                 if(available) {
                     txtServerCDMVersion.setText(selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort()).getDbSchemaVersion());
                     int compareDbSchemaVersion = selectedCsii.compareDbSchemaVersion(selectedCdmInstance, getPort());
-                    int compareCdmlibServicesVersion = selectedCsii.compareCdmlibServicesVersion();
-
+                    int compareCdmlibServicesVersion = 0;
+                    boolean disableServicesApiTimestampCheck =
+                            PreferencesUtil.getBooleanValue((IPreferenceKeys.DISABLE_SERVICES_API_TIMESTAMP_CHECK));
+                    if(!disableServicesApiTimestampCheck) {
+                        compareCdmlibServicesVersion = selectedCsii.compareCdmlibServicesVersion();
+                    }
                     if(compareDbSchemaVersion > 0 || compareCdmlibServicesVersion > 0) {
                         status =  STATUS_NOT_COMPATIBLE;
                         available = false;
@@ -658,12 +882,9 @@ public class RemotingLoginDialog extends Dialog {
                     } else {
                         status =  STATUS_AVAILABLE;
                         available = true;
-                        message = "";
+                        message = ""; //$NON-NLS-1$
                     }
-
-
                 }
-
             } catch (Exception e) {
                 txtCdmInstanceStatus.setToolTipText(e.getMessage());
             } finally {
@@ -673,9 +894,7 @@ public class RemotingLoginDialog extends Dialog {
                     setMessage(message);
                 }
             }
-
         }
-
     }
 
     private void connect() {
@@ -687,7 +906,7 @@ public class RemotingLoginDialog extends Dialog {
 
         ICdmRemoteSource source = selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort());
 
-        if(!validateLogin()) {
+        if(!validateLogin(source)) {
             return;
         }
 
@@ -724,6 +943,20 @@ public class RemotingLoginDialog extends Dialog {
          flushPreferences(credentialsPrefs);
     }
 
+    private void removePrefCredentials() {
+        IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
+        Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
+        credentialsPrefs.put(getUsernamePrefKey(), txtLogin.getText());
+        credentialsPrefs.put(getPasswordPrefKey(), txtPassword.getText());
+        removePreferences(credentialsPrefs);
+   }
+    private void removePreferences(Preferences prefs) {
+        try {
+            prefs.removeNode();
+        } catch (BackingStoreException bse) {
+            setMessage(bse.getMessage());
+        }
+    }
     private void flushPreferences(Preferences prefs) {
         try {
             prefs.flush();
@@ -732,13 +965,15 @@ public class RemotingLoginDialog extends Dialog {
         }
     }
 
+
+
     private void readPrefCredentials() {
         String username, password;
         IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
         Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
-        username = credentialsPrefs.get(getUsernamePrefKey(), "");
+        username = credentialsPrefs.get(getUsernamePrefKey(), ""); //$NON-NLS-1$
         txtLogin.setText(username);
-        password = credentialsPrefs.get(getPasswordPrefKey(),"");
+        password = credentialsPrefs.get(getPasswordPrefKey(),""); //$NON-NLS-1$
         txtPassword.setText(password);
         if(username.isEmpty() || password.isEmpty()) {
             autoConnect = false;
@@ -754,29 +989,46 @@ public class RemotingLoginDialog extends Dialog {
     }
 
     private void emptyCredentials() {
-        txtLogin.setText("");
-        txtPassword.setText("");
+        txtLogin.setText(""); //$NON-NLS-1$
+        txtPassword.setText(""); //$NON-NLS-1$
     }
 
     private String getUsernamePrefKey() {
-        return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + USERNAME_SUFFIX;
+        return selectedCsii.toString(selectedCdmInstance.getName(), isDevRemoteSource?getPort():-1) + USERNAME_SUFFIX;
     }
 
     private String getPasswordPrefKey() {
-        return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + PASSWORD_SUFFIX;
+        return selectedCsii.toString(selectedCdmInstance.getName(), isDevRemoteSource?getPort():-1) + PASSWORD_SUFFIX;
     }
 
-    private boolean validateLogin() {
+    private boolean validateLogin(ICdmRemoteSource remoteSource) {
         if(getUsername() == null || getUsername().isEmpty()) {
-            setMessage("User login cannot be empty");
+            setMessage(Messages.RemotingLoginDialog_LOGIN_CANNOT_BE_EMPTY);
             return false;
         }
         if(getPassword() == null || getPassword().isEmpty()) {
-            setMessage("Password cannot be empty");
+            setMessage(Messages.RemotingLoginDialog_PASSWORD_CANNOT_BE_EMPTY);
+            return false;
+        }
+
+
+        try {
+            IUserService userService = CdmApplicationRemoteConfiguration.getUserService(remoteSource);
+            UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(getUsername(), getPassword());
+            CdmApplicationRemoteConfiguration.getAuthenticationManager(userService).authenticate(token);
+        } catch(BadCredentialsException e){
+            setMessage(LoginManager.INCORRECT_CREDENTIALS_MESSAGE);
+            return false;
+        } catch(LockedException e){
+            setMessage(LoginManager.ACCOUNT_LOCKED_MESSAGE);
+            return false;
+        } catch(IllegalArgumentException e){
+            setMessage(LoginManager.INCORRECT_CREDENTIALS_MESSAGE);
             return false;
         }
         return true;
     }
+
     public String getUsername() {
         return txtLogin.getText();
     }
@@ -787,23 +1039,29 @@ public class RemotingLoginDialog extends Dialog {
 
     public void setMessage(String message) {
         if(message != null && !message.isEmpty()) {
-            if(message.length() > 60) {
-                styledTxtMessage.setToolTipText(message);
-                message = message.substring(0, 60) + "...";
-            }
+//            if(message.length() > 50) {
+//                styledTxtMessage.setToolTipText(message);
+//                message = message.substring(0,50) + "..."; //$NON-NLS-1$
+//            }
             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());
+            if (!styledTxtMessage.isDisposed()){
+                styledTxtMessage.setText(""); //$NON-NLS-1$
+                styledTxtMessage.setVisible(false);
+                ((GridData)styledTxtMessage.getLayoutData()).exclude = true;
+            }
+            if(!shlConnect.isDisposed()){
+                shlConnect.setSize(MIN_WIDTH, getHeightWithoutMessage());
+                shlConnect.setMinimumSize(MIN_WIDTH, getHeightWithoutMessage());
+            }
+        }
+        if (!remotingComposite.isDisposed()){
+            remotingComposite.layout();
         }
-        remotingComposite.layout();
     }
 
     private int getHeightWithoutMessage() {
@@ -816,13 +1074,17 @@ public class RemotingLoginDialog extends Dialog {
 
 
     public void hide(boolean isHidden) {
-        if(shlConnect != null && shlConnect.getDisplay() != null) {
-            shlConnect.setVisible(!isHidden);
+        if (!shlConnect.isDisposed()){
+            if(shlConnect != null && shlConnect.getDisplay() != null) {
+                shlConnect.setVisible(!isHidden);
+            }
         }
     }
     public void dispose() {
-        if(shlConnect != null && shlConnect.getDisplay() != null) {
-            shlConnect.dispose();
+        if (!shlConnect.isDisposed()){
+            if(shlConnect != null && shlConnect.getDisplay() != null) {
+                shlConnect.dispose();
+            }
         }
     }
 
@@ -830,9 +1092,11 @@ public class RemotingLoginDialog extends Dialog {
         Display.getDefault().asyncExec(new Runnable() {
             @Override
             public void run() {
-                if(!isDevRemoteSource) {
+                if(selectedCdmInstance!=null){
                     if(isRememberMe()) {
                         persistPrefCredentials();
+                    }else{
+                        removePrefCredentials();
                     }
                     persistPrefLastServerInstance();
                 }
@@ -842,39 +1106,66 @@ public class RemotingLoginDialog extends Dialog {
     }
 
     private String generateLastModifiedTooltip(String cdmlibLastModified) {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z");
+        if(StringUtils.isBlank(cdmlibLastModified)) {
+            return ""; //$NON-NLS-1$
+        }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm.z"); //$NON-NLS-1$
         Date cdmlibLastModifiedDate;
-        String cdmlibLastModifiedTimestamp = "";
+        String cdmlibLastModifiedTimestamp = ""; //$NON-NLS-1$
 
         cdmlibLastModifiedDate = new Date(Long.valueOf(cdmlibLastModified));
         cdmlibLastModifiedTimestamp = sdf.format(cdmlibLastModifiedDate);
 
-        return "last modified : " + cdmlibLastModifiedTimestamp;
+        return cdmlibLastModifiedTimestamp;
     }
 
     private void setEditorInfo() {
         txtEditorCDMVersion.setText(CdmMetaData.getDbSchemaVersion());
-        txtEditorVersion.setText(CdmApplicationState.getCdmlibVersion());
-        txtEditorVersion.setToolTipText(generateLastModifiedTooltip(CdmApplicationState.getCdmlibLastModified()));
+        String editorVersionTimestamp = generateLastModifiedTooltip(CdmApplicationState.getCdmlibLastModified());
+        txtEditorVersion.setText(CdmApplicationState.getCdmlibVersion() + ":" + editorVersionTimestamp); //$NON-NLS-1$
     }
 
     private void clearOnServerChange() {
-        setMessage("");
-        txtServerCDMVersion.setText("");
-        txtServerVersion.setText("");
-        txtServerVersion.setToolTipText("");
-        txtServerCDMVersion.setText("");
+        setMessage(""); //$NON-NLS-1$
+        txtServerCDMVersion.setText(""); //$NON-NLS-1$
+        txtServerVersion.setText(""); //$NON-NLS-1$
+        txtServerVersion.setToolTipText(""); //$NON-NLS-1$
+        txtServerCDMVersion.setText(""); //$NON-NLS-1$
+        comboCdmInstance.removeAll();
+        txtCdmInstanceStatus.setText(""); //$NON-NLS-1$
         txtPort.setEditable(false);
         txtPort.setEnabled(false);
     }
 
     private void clearOnInstanceChange() {
-        setMessage("");
-        txtServerCDMVersion.setText("");
+        setMessage(""); //$NON-NLS-1$
+        txtServerCDMVersion.setText(""); //$NON-NLS-1$
     }
 
-    private void updateOnServerChange(String serverVersion, String serverVersionTooltip) {
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void handleError(final Throwable t) {
+
+        Display.getDefault().syncExec(new Runnable() {
+            @Override
+            public void run() {
+                serverJob.cancel();
+
+                String title = Messages.RemotingLoginDialog_SERVER_LAUNCH_ERROR;
+                String  message = t.getMessage();
 
+
+                MessagingUtils.errorDialog(title,
+                        this,
+                        message,
+                        TaxeditorStorePlugin.PLUGIN_ID,
+                        t,
+                        true);
+            }
+        });
     }
 
+
 }