#5029 Add functionality for login to remember credentials, reconnect and switch user
authorCherian Mathew <c.mathew@bgbm.org>
Thu, 30 Jul 2015 08:58:19 +0000 (10:58 +0200)
committerCherian Mathew <c.mathew@bgbm.org>
Thu, 30 Jul 2015 08:58:19 +0000 (10:58 +0200)
15 files changed:
eu.etaxonomy.taxeditor.application/plugin.xml
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmServerInfo.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySession.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionManager.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/ICdmEntitySessionManager.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/mock/MockCdmEntitySessionManager.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java
eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.store/plugin.xml
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/ReconnectHandler.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/ShowRemotingLoginWindowHandler.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/SwitchUserHandler.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStoreConnector.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java

index 97897e12022fe17a56d4be80ccaeb223b3de2536..b74e209ce9d93b65fa3e04ed7461db32d7388015 100644 (file)
                name="eu.etaxonomy.taxeditor.application.filemenu.io"\r
                visible="true">\r
          </separator>\r
                name="eu.etaxonomy.taxeditor.application.filemenu.io"\r
                visible="true">\r
          </separator>\r
-         <command\r
-               commandId="eu.etaxonomy.taxeditor.store.operations.showRemotingLoginWindow"\r
-               id="eu.etaxonomy.taxeditor.application.menu.login"\r
-               label="Connect"\r
-               style="push">\r
-         </command>\r
          <command\r
                commandId="org.eclipse.ui.file.exit"\r
                id="eu.etaxonomy.taxeditor.application.menu.exit"\r
          <command\r
                commandId="org.eclipse.ui.file.exit"\r
                id="eu.etaxonomy.taxeditor.application.menu.exit"\r
             id="eu.etaxonomy.taxeditor.install"\r
             name="%command.label.18">\r
       </command>\r
             id="eu.etaxonomy.taxeditor.install"\r
             name="%command.label.18">\r
       </command>\r
-      <command\r
-            defaultHandler="eu.etaxonomy.taxeditor.handler.ShowRemotingLoginWindowHandler"\r
-            id="eu.etaxonomy.taxeditor.store.operations.showRemotingLoginWindow"\r
-            name="Connect">\r
-      </command>\r
    </extension>\r
    \r
    \r
    </extension>\r
    \r
    \r
index cf41d602d82610d595ec526cb521133e4730b011..ecca6c7f58a241587e0064634ece4df14a818dd8 100644 (file)
@@ -38,6 +38,7 @@ import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
 public class CdmServerInfo {
     public static final Logger logger = Logger.getLogger(CdmServerInfo.class);
 
 public class CdmServerInfo {
     public static final Logger logger = Logger.getLogger(CdmServerInfo.class);
 
+    private final static String CDMSERVER_PREFIX = "cdmserver";
     private final static String NAME_PRODUCTION = "edit-production";
     private final static String SERVER_PRODUCTION = "dev.e-taxonomy.eu";
 
     private final static String NAME_PRODUCTION = "edit-production";
     private final static String SERVER_PRODUCTION = "dev.e-taxonomy.eu";
 
@@ -83,7 +84,7 @@ public class CdmServerInfo {
     }
     public void refreshInstances() throws CDMServerException {
         instances.clear();
     }
     public void refreshInstances() throws CDMServerException {
         instances.clear();
-        String url = "http://" + server + ":" + String.valueOf(port) + "/cdmserver/instances.jsp";
+        String url = "http://" + server + ":" + String.valueOf(port) + "/" + CDMSERVER_PREFIX + "/instances.jsp";
 
         HttpClient client = new DefaultHttpClient();
         HttpGet httpGet = new HttpGet(url);
 
         HttpClient client = new DefaultHttpClient();
         HttpGet httpGet = new HttpGet(url);
@@ -140,6 +141,10 @@ public class CdmServerInfo {
 
     }
 
 
     }
 
+    public String toString(String instanceName, int port) {
+        return server + ":" + String.valueOf(port) + "/" + instanceName;
+    }
+
     public CdmInstanceInfo getInstanceFromName(String instanceName) {
         if(instanceName == null) {
             return null;
     public CdmInstanceInfo getInstanceFromName(String instanceName) {
         if(instanceName == null) {
             return null;
index 97de82fcca7b4eead83b7f715edc051e3ce7e9a9..a8cc4ecd9c6ea218040a1a87bf80ec8e7e9a8375 100644 (file)
@@ -12,10 +12,8 @@ package eu.etaxonomy.taxeditor.session;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.UUID;
 
 import net.sf.ehcache.statistics.LiveCacheStatistics;
 import java.util.UUID;
 
 import net.sf.ehcache.statistics.LiveCacheStatistics;
@@ -47,20 +45,20 @@ public class CdmEntitySession implements ICdmEntitySession  {
 
     private final ICdmEntitySessionEnabled sessionOwner;
 
 
     private final ICdmEntitySessionEnabled sessionOwner;
 
-    private final CdmTransientEntityCacher cdmTransientEntityCacher;
-
-    private final List<ICdmEntitySessionEnabled> changeObservers;
-
-    private final Set<CdmBase> newCdmEntities;
+    private CdmTransientEntityCacher cdmTransientEntityCacher;
 
 
+    private List<ICdmEntitySessionEnabled> changeObservers;
 
 
     public CdmEntitySession(ICdmEntitySessionEnabled sessionOwner, CdmEntitySessionManager cdmEntitySessionManager) {
         this.sessionOwner = sessionOwner;
 
 
     public CdmEntitySession(ICdmEntitySessionEnabled sessionOwner, CdmEntitySessionManager cdmEntitySessionManager) {
         this.sessionOwner = sessionOwner;
-        this.cdmTransientEntityCacher = new CdmTransientEntityCacher(sessionOwner, cdmEntitySessionManager);
         this.cdmEntitySessionManager = cdmEntitySessionManager;
         this.cdmEntitySessionManager = cdmEntitySessionManager;
+        init(sessionOwner, cdmEntitySessionManager);
+    }
+
+    private void init(ICdmEntitySessionEnabled sessionOwner, CdmEntitySessionManager cdmEntitySessionManager) {
+        this.cdmTransientEntityCacher = new CdmTransientEntityCacher(sessionOwner, cdmEntitySessionManager);
         this.changeObservers = new ArrayList<ICdmEntitySessionEnabled>();
         this.changeObservers = new ArrayList<ICdmEntitySessionEnabled>();
-        this.newCdmEntities = new HashSet<CdmBase>();
         cdmEntitySessionManager.addToOwnerSessionMap(sessionOwner, this);
     }
 
         cdmEntitySessionManager.addToOwnerSessionMap(sessionOwner, this);
     }
 
@@ -181,6 +179,9 @@ public class CdmEntitySession implements ICdmEntitySession  {
     @Override
     public void bind() {
         logger.info("Binding session with owner " + sessionOwner.toString());
     @Override
     public void bind() {
         logger.info("Binding session with owner " + sessionOwner.toString());
+        if(!cdmEntitySessionManager.contains(sessionOwner)) {
+            init(sessionOwner, cdmEntitySessionManager);
+        }
         cdmEntitySessionManager.bind(sessionOwner);
 
     }
         cdmEntitySessionManager.bind(sessionOwner);
 
     }
index 9bddb82d5035e181b477ed2ccde78b49c6d6ee41..a5411711003a3ee8b18b23296d0ad7501491364a 100644 (file)
@@ -96,6 +96,11 @@ public class CdmEntitySessionManager implements ICdmEntitySessionManager {
 
     }
 
 
     }
 
+    @Override
+    public boolean contains(ICdmEntitySessionEnabled sessionOwner) {
+        return ownerSessionMap.containsKey(sessionOwner);
+    }
+
 
     /* (non-Javadoc)
      * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#load(T)
 
     /* (non-Javadoc)
      * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#load(T)
index cd15d27a2b15d879517eac59ec563be247bd7335..1f8ba4e19ef10399f4beead43cd1d258d71404db 100644 (file)
@@ -54,5 +54,11 @@ public interface ICdmEntitySessionManager {
      */
     public <T extends CdmBase> void update();
 
      */
     public <T extends CdmBase> void update();
 
+    /**
+     * @param sessionOwner
+     * @return
+     */
+    public boolean contains(ICdmEntitySessionEnabled sessionOwner);
+
 
 }
\ No newline at end of file
 
 }
\ No newline at end of file
index f32d7c2e57afe3527f7ae85b5b2d3cd7e0074ba8..443ed97c6a682581d09a07ac73ed378cccfe3bb3 100644 (file)
@@ -110,5 +110,13 @@ public class MockCdmEntitySessionManager implements ICdmEntitySessionManager {
         return updateResult;
     }
 
         return updateResult;
     }
 
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#contains(eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled)
+     */
+    @Override
+    public boolean contains(ICdmEntitySessionEnabled sessionOwner) {
+        return false;
+    }
+
 
 }
 
 }
index 7e48f97fcf6066329bdb081c0b236c6e0c17236f..a266c8d9249de70341c8ddebb3d14107d3c44dd8 100644 (file)
@@ -43,6 +43,7 @@ import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin;
 import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin;
 import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
+import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
 
 /**
  * <p>NavigationUtil class.</p>
 
 /**
  * <p>NavigationUtil class.</p>
@@ -98,7 +99,12 @@ public class NavigationUtil extends AbstractUtility{
                } catch (PartInitException e) {
                        MessagingUtils.error(NavigationUtil.class, "Error opening the editor", e);
                } catch (Exception e) {
                } catch (PartInitException e) {
                        MessagingUtils.error(NavigationUtil.class, "Error opening the editor", e);
                } catch (Exception e) {
-                       MessagingUtils.warningDialog("Could not create Taxon", NavigationUtil.class, e.getMessage());
+                   MessagingUtils.errorDialog("Could not create Taxon",
+                           NavigationUtil.class,
+                           e.getMessage(), TaxeditorStorePlugin.PLUGIN_ID,
+                           e,
+                           true);
+
                }
        }
 
                }
        }
 
index db9b51a83a3df87f9ae69c21b78af9e9c9a69d6a..4b6f8c1536d870a19f3632cd74044f752977c6f4 100644 (file)
@@ -85,7 +85,8 @@ Import-Package: org.eclipse.core.commands,
  org.eclipse.ui.editors.text,
  org.eclipse.ui.forms.widgets,
  org.eclipse.ui.ide.undo,
  org.eclipse.ui.editors.text,
  org.eclipse.ui.forms.widgets,
  org.eclipse.ui.ide.undo,
- org.osgi.framework
+ org.osgi.framework,
+ org.osgi.service.prefs;version="1.1.1"
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ClassPath: .,
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ClassPath: .,
index 967bc43642a18aa9559201c6234f27911df608dc..1ccc50cf20abd3363f8b238f03ace3f42312ca06 100644 (file)
       </menuContribution>
       <menuContribution
             locationURI="menu:org.eclipse.ui.main.menu.file?after=eu.etaxonomy.taxeditor.application.filemenu.io">
       </menuContribution>
       <menuContribution
             locationURI="menu:org.eclipse.ui.main.menu.file?after=eu.etaxonomy.taxeditor.application.filemenu.io">
+         <command
+               commandId="eu.etaxonomy.taxeditor.store.operations.showRemotingLoginWindow"
+               label="Connect"
+               style="push">
+         </command>
          <command
                commandId="eu.etaxonomy.taxeditor.store.operations.showLoginWindow"
                label="%command.label.5"
                style="push">
          <command
                commandId="eu.etaxonomy.taxeditor.store.operations.showLoginWindow"
                label="%command.label.5"
                style="push">
+            <visibleWhen
+                  checkEnabled="true">
+               <reference
+                     definitionId="isUserLoggedIn">
+               </reference>
+            </visibleWhen>
+         </command>
+         <command
+               commandId="eu.etaxonomy.taxeditor.store.operations.reconnect"
+               label="Re-Connect"
+               style="push">
+            <visibleWhen
+                  checkEnabled="true">
+               <reference
+                     definitionId="isUserLoggedIn">
+               </reference>
+            </visibleWhen>
          </command>
          <separator
                name="eu.etaxonomy.taxeditor.application.filemenu.login"
          </command>
          <separator
                name="eu.etaxonomy.taxeditor.application.filemenu.login"
          </activeWhen>
       </handler>
       <handler
          </activeWhen>
       </handler>
       <handler
-            class="eu.etaxonomy.taxeditor.handler.ShowLoginWindowHandler"
-            commandId="eu.etaxonomy.taxeditor.store.operations.showLoginWindow">
-         <enabledWhen>
-            <reference
-                  definitionId="isUserLoggedIn">
-            </reference></enabledWhen>
+            class="eu.etaxonomy.taxeditor.handler.ShowRemotingLoginWindowHandler"
+            commandId="eu.etaxonomy.taxeditor.store.operations.showRemotingLoginWindow">
       </handler>
       <handler
             class="eu.etaxonomy.taxeditor.handler.OpenPasswordWizzardHandler"
       </handler>
       <handler
             class="eu.etaxonomy.taxeditor.handler.OpenPasswordWizzardHandler"
             </reference>
          </activeWhen>
       </handler>
             </reference>
          </activeWhen>
       </handler>
+      <handler
+            class="eu.etaxonomy.taxeditor.handler.SwitchUserHandler"
+            commandId="eu.etaxonomy.taxeditor.store.operations.showLoginWindow">
+         <activeWhen>
+            <reference
+                  definitionId="isRemoting">
+            </reference>
+         </activeWhen>
+      </handler>
    </extension>
    <extension
          name="%extension.name.0"
    </extension>
    <extension
          name="%extension.name.0"
             name="%command.name.3">
       </command>
       <command
             name="%command.name.3">
       </command>
       <command
+            defaultHandler="eu.etaxonomy.taxeditor.handler.ShowLoginWindowHandler"
             id="eu.etaxonomy.taxeditor.store.operations.showLoginWindow"
             name="%command.name.4">
       </command>
             id="eu.etaxonomy.taxeditor.store.operations.showLoginWindow"
             name="%command.name.4">
       </command>
+      <command
+            id="eu.etaxonomy.taxeditor.store.operations.showRemotingLoginWindow"
+            name="Connect">
+      </command>
+      <command
+            defaultHandler="eu.etaxonomy.taxeditor.handler.ReconnectHandler"
+            id="eu.etaxonomy.taxeditor.store.operations.reconnect"
+            name="Re-Connect">
+      </command>
       <command
             defaultHandler="eu.etaxonomy.taxeditor.editor.definedterm.handler.OpenDefinedTermEditorHandler"
             id="eu.etaxonomy.taxeditor.store.openDefinedTermEditor"
       <command
             defaultHandler="eu.etaxonomy.taxeditor.editor.definedterm.handler.OpenDefinedTermEditorHandler"
             id="eu.etaxonomy.taxeditor.store.openDefinedTermEditor"
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/ReconnectHandler.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/ReconnectHandler.java
new file mode 100644 (file)
index 0000000..28ffa45
--- /dev/null
@@ -0,0 +1,46 @@
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.swt.SWT;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.ui.dialog.RemotingLoginDialog;
+
+/**
+ *
+ *
+ * @author c.mathew
+ */
+public class ReconnectHandler extends AbstractHandler implements IHandler {
+
+       /* (non-Javadoc)
+        * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+        */
+       /** {@inheritDoc} */
+       @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+
+               RemotingLoginDialog loginDialog = new RemotingLoginDialog(HandlerUtil.getActiveShell(event),
+                       SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
+
+               loginDialog.open((CdmRemoteSource) CdmStore.getActiveCdmSource(), true, true);
+
+               return null;
+
+       }
+}
index 025c493e4cc938cbbb254398680e314ac18de1d7..dcb01c6fd91f35cdae2d626497c3d805a21ec427 100644 (file)
@@ -20,11 +20,9 @@ import org.eclipse.ui.handlers.HandlerUtil;
 import eu.etaxonomy.taxeditor.ui.dialog.RemotingLoginDialog;
 
 /**
 import eu.etaxonomy.taxeditor.ui.dialog.RemotingLoginDialog;
 
 /**
- * <p>ShowLoginWindowHandler class.</p>
  *
  *
- * @author n.hoffmann
- * @created Aug 7, 2009
- * @version 1.0
+ *
+ * @author c.mathew
  */
 public class ShowRemotingLoginWindowHandler extends AbstractHandler implements IHandler{
 
  */
 public class ShowRemotingLoginWindowHandler extends AbstractHandler implements IHandler{
 
@@ -35,14 +33,11 @@ public class ShowRemotingLoginWindowHandler extends AbstractHandler implements I
        @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
 
        @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
 
-               RemotingLoginDialog loginDialog = new RemotingLoginDialog(HandlerUtil.getActiveShell(event),SWT.DIALOG_TRIM
-                       | SWT.APPLICATION_MODAL);
+               RemotingLoginDialog loginDialog = new RemotingLoginDialog(HandlerUtil.getActiveShell(event),
+                       SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
                loginDialog.open();
 
                return null;
 
        }
                loginDialog.open();
 
                return null;
 
        }
-
-
-
 }
 }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/SwitchUserHandler.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/SwitchUserHandler.java
new file mode 100644 (file)
index 0000000..93e12bd
--- /dev/null
@@ -0,0 +1,47 @@
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.swt.SWT;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.ui.dialog.RemotingLoginDialog;
+
+/**
+ *
+ *
+ * @author c.mathew
+ */
+public class SwitchUserHandler extends AbstractHandler implements IHandler {
+
+       /* (non-Javadoc)
+        * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+        */
+       /** {@inheritDoc} */
+       @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+
+               RemotingLoginDialog loginDialog = new RemotingLoginDialog(HandlerUtil.getActiveShell(event),
+                       SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
+
+               loginDialog.open((CdmRemoteSource) CdmStore.getActiveCdmSource(), false, false);
+
+               return null;
+
+       }
+}
+
index d54c22daf1872f7c5268b0b520cf6e9c0e52df90..8e7e5ef206e351cc0f1d5ecc86985991adcd33dd 100644 (file)
@@ -173,7 +173,16 @@ public class CdmStore {
     private static void connect(final ICdmSource cdmSource,
             final DbSchemaValidation dbSchemaValidation,
             final Resource applicationContextBean,
     private static void connect(final ICdmSource cdmSource,
             final DbSchemaValidation dbSchemaValidation,
             final Resource applicationContextBean,
-            RemotingLoginDialog loginDialog) {
+            RemotingLoginDialog remotingLoginDialog) {
+        RemotingLoginDialog loginDialog = remotingLoginDialog;
+
+        MessagingUtils.info("Connecting to datasource: " + cdmSource);
+
+        job = new CdmStoreConnector(Display.getDefault(),
+                cdmSource,
+                dbSchemaValidation,
+                applicationContextBean);
+        job.start(loginDialog);
         if(isActive()) {
             // before we connect we clear the entity caches and the sessions
             CdmRemoteCacheManager.removeEntityCaches();
         if(isActive()) {
             // before we connect we clear the entity caches and the sessions
             CdmRemoteCacheManager.removeEntityCaches();
@@ -181,12 +190,6 @@ public class CdmStore {
                 getCurrentSessionManager().disposeAll();
             }
         }
                 getCurrentSessionManager().disposeAll();
             }
         }
-        MessagingUtils.info("Connecting to datasource: " + cdmSource);
-        job = new CdmStoreConnector(Display.getDefault(),
-                cdmSource,
-                dbSchemaValidation,
-                applicationContextBean);
-        job.start(loginDialog);
     }
 
     public static boolean isConnecting() {
     }
 
     public static boolean isConnecting() {
index 9fbe2c6e81fac0a6d6afa01eff07891bb58a6756..3c7ac77b13c7258f0942c8ce0dc368954d7dc1f3 100644 (file)
@@ -223,7 +223,7 @@ class CdmStoreConnector extends Job {
                                     try {
                                         // create new security context
                                         CdmStore.getLoginManager().doAuthenticate(loginDialog.getUsername(), loginDialog.getPassword());
                                     try {
                                         // create new security context
                                         CdmStore.getLoginManager().doAuthenticate(loginDialog.getUsername(), loginDialog.getPassword());
-                                        loginDialog.dispose();
+                                        loginDialog.onComplete();
                                         // start editor context
                                         CdmStore.getContextManager().notifyContextStartWithoutDialog(monitor);
 
                                         // start editor context
                                         CdmStore.getContextManager().notifyContextStartWithoutDialog(monitor);
 
index 09d3af81e5d5b9cb2fada17151ffd661dc39617e..5d2429189576e22a5b9e52cdea043d2203d0088e 100644 (file)
@@ -17,6 +17,8 @@ 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.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.SWT;
 import org.eclipse.swt.custom.StyledText;
 import org.eclipse.swt.events.MouseAdapter;
@@ -39,9 +41,12 @@ 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.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.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
 
 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;
 import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo;
 import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo.CdmInstanceInfo;
 import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
@@ -64,13 +69,23 @@ public class RemotingLoginDialog extends Dialog {
 
     private final Map<String, CdmServerInfo> csiiMap = new HashMap<String, CdmServerInfo>();
 
 
     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 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 Composite remotingComposite;
     private CdmServerInfo selectedCsii;
@@ -102,6 +117,10 @@ public class RemotingLoginDialog extends Dialog {
     private Label lblEditorCDMVersion;
     private Text txtEditorCDMVersion;
 
     private Label lblEditorCDMVersion;
     private Text txtEditorCDMVersion;
 
+    private String serverName, instanceName;
+    private boolean autoConnect = false;
+    private boolean loadLoginPrefs = true;
+
     /**
      * Create the dialog.
      * @param parent
     /**
      * Create the dialog.
      * @param parent
@@ -112,6 +131,23 @@ public class RemotingLoginDialog extends Dialog {
         setText("Login");
     }
 
         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
     /**
      * Open the dialog.
      * @return the result
@@ -208,7 +244,7 @@ public class RemotingLoginDialog extends Dialog {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 updateSelectedCdmInstance();
             @Override
             public void widgetSelected(SelectionEvent e) {
                 updateSelectedCdmInstance();
-                checkSelectedCdmServerInstance();
+                checkSelectedCdmInstance();
             }
         });
         GridData gd_comboCdmInstance = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
             }
         });
         GridData gd_comboCdmInstance = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
@@ -277,19 +313,16 @@ public class RemotingLoginDialog extends Dialog {
         btnConnect.addMouseListener(new MouseAdapter() {
             @Override
             public void mouseUp(MouseEvent e) {
         btnConnect.addMouseListener(new MouseAdapter() {
             @Override
             public void mouseUp(MouseEvent e) {
-                int selInstanceIndex = comboCdmInstance.getSelectionIndex();
-                String instance = comboCdmInstance.getItem(selInstanceIndex);
-                checkSelectedCdmServerInstance();
-                connect(selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort()));
+                connect();
             }
         });
         btnConnect.setText("Connect");
 
         btnRememberMe = new Button(loginComposite, SWT.CHECK);
             }
         });
         btnConnect.setText("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);
         GridData gd_btnRememberMe = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);
         gd_btnRememberMe.widthHint = 107;
         btnRememberMe.setLayoutData(gd_btnRememberMe);
-        btnRememberMe.setEnabled(false);
         btnRememberMe.setText("Remember Me");
         new Label(loginComposite, SWT.NONE);
         new Label(loginComposite, SWT.NONE);
         btnRememberMe.setText("Remember Me");
         new Label(loginComposite, SWT.NONE);
         new Label(loginComposite, SWT.NONE);
@@ -396,18 +429,29 @@ public class RemotingLoginDialog extends Dialog {
 
     }
 
 
     }
 
+
+
     private void populateCdmServerCombo() {
         Job job = new Job("Retrieve Server Instances") {
             @Override
             protected IStatus run(IProgressMonitor monitor) {
     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());
                         }
                     @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);
+                        }
                         refreshCdmServer();
                         updatePort();
                     }
                         refreshCdmServer();
                         updatePort();
                     }
@@ -450,17 +494,16 @@ public class RemotingLoginDialog extends Dialog {
     }
 
     private void checkSelectedCdmServer() {
     }
 
     private void checkSelectedCdmServer() {
-        int selIndex = comboCdmServer.getSelectionIndex();
+
         txtCdmInstanceStatus.setText("");
         txtPort.setEditable(false);
         txtPort.setEnabled(false);
         txtCdmInstanceStatus.setText("");
         txtPort.setEditable(false);
         txtPort.setEnabled(false);
+        emptyCredentials();
+
         if(selectedCsii != null) {
             if(selectedCsii.isLocalhost()) {
                 txtPort.setEditable(true);
                 txtPort.setEnabled(true);
         if(selectedCsii != null) {
             if(selectedCsii.isLocalhost()) {
                 txtPort.setEditable(true);
                 txtPort.setEnabled(true);
-            } else {
-                txtPort.setEditable(false);
-                txtPort.setEnabled(false);
             }
             if(selectedCsii.pingServer()) {
                 txtCdmServerStatus.setText(STATUS_AVAILABLE);
             }
             if(selectedCsii.pingServer()) {
                 txtCdmServerStatus.setText(STATUS_AVAILABLE);
@@ -479,6 +522,7 @@ public class RemotingLoginDialog extends Dialog {
         comboCdmInstance.setEnabled(false);
         btnConnect.setEnabled(false);
         txtCdmInstanceStatus.setText(STATUS_RETRIEVING);
         comboCdmInstance.setEnabled(false);
         btnConnect.setEnabled(false);
         txtCdmInstanceStatus.setText(STATUS_RETRIEVING);
+
         Job job = new Job("Retrieve Server Instances") {
             @Override
             protected IStatus run(IProgressMonitor monitor) {
         Job job = new Job("Retrieve Server Instances") {
             @Override
             protected IStatus run(IProgressMonitor monitor) {
@@ -495,10 +539,22 @@ public class RemotingLoginDialog extends Dialog {
                                     for(CdmInstanceInfo cdmInstance : instances) {
                                         comboCdmInstance.add(cdmInstance.getName());
                                     }
                                     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();
                                     updateSelectedCdmInstance();
-                                    checkSelectedCdmServerInstance();
+                                    checkSelectedCdmInstance();
                                     comboCdmInstance.setEnabled(true);
                                     comboCdmInstance.setEnabled(true);
+                                    if(autoConnect) {
+                                        connect();
+                                    }
 
                                 } else {
                                     txtCdmInstanceStatus.setText(STATUS_NO_INSTANCES);
 
                                 } else {
                                     txtCdmInstanceStatus.setText(STATUS_NO_INSTANCES);
@@ -532,17 +588,20 @@ public class RemotingLoginDialog extends Dialog {
     private void refreshCdmInstance() {
         txtCdmInstanceStatus.setText(STATUS_CHECKING_AVAILABILITY);
         updateSelectedCdmInstance();
     private void refreshCdmInstance() {
         txtCdmInstanceStatus.setText(STATUS_CHECKING_AVAILABILITY);
         updateSelectedCdmInstance();
-        checkSelectedCdmServerInstance();
+        checkSelectedCdmInstance();
     }
 
     private void updateSelectedCdmInstance() {
         int selIndex = comboCdmInstance.getSelectionIndex();
         if(selIndex != -1) {
             selectedCdmInstance = selectedCsii.getInstanceFromName(comboCdmInstance.getItem(selIndex));
     }
 
     private void updateSelectedCdmInstance() {
         int selIndex = comboCdmInstance.getSelectionIndex();
         if(selIndex != -1) {
             selectedCdmInstance = selectedCsii.getInstanceFromName(comboCdmInstance.getItem(selIndex));
+            if(loadLoginPrefs) {
+                readPrefCredentials();
+            }
         }
     }
 
         }
     }
 
-    private void checkSelectedCdmServerInstance() {
+    private void checkSelectedCdmInstance() {
         if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
             try {
                 if(selectedCsii.pingInstance(selectedCdmInstance, getPort())) {
         if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
             try {
                 if(selectedCsii.pingInstance(selectedCdmInstance, getPort())) {
@@ -554,23 +613,29 @@ public class RemotingLoginDialog extends Dialog {
                 }
             } catch (Exception e) {
                 txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
                 }
             } catch (Exception e) {
                 txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
-                //MessagingUtils.warn(this.getClass(), e);
+                txtCdmInstanceStatus.setToolTipText(e.getMessage());
             }
         }
 
     }
 
             }
         }
 
     }
 
-    private void connect(ICdmRemoteSource source) {
-
+    private void connect() {
+        checkSelectedCdmInstance();
 
 
-        if(!validateLogin()) {
+        if(!txtCdmInstanceStatus.getText().equals(STATUS_AVAILABLE)) {
             return;
         }
 
             return;
         }
 
-        if(CdmStore.isConnecting()){
-            MessagingUtils.warningDialog("Already connecting", this, "You are currently connecting to a different CDM Instance already.");
+        ICdmRemoteSource source = selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort());
+
+        if(!validateLogin()) {
             return;
         }
             return;
         }
+//
+//        if(CdmStore.isConnecting()){
+//            MessagingUtils.warningDialog("Already connecting", this, "You are currently connecting to a different CDM Instance already.");
+//            return;
+//        }
 
         try {
             CdmStore.connect(source, this);
 
         try {
             CdmStore.connect(source, this);
@@ -582,6 +647,61 @@ public class RemotingLoginDialog extends Dialog {
 
     }
 
 
     }
 
+    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() {
+        IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
+        Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
+        String username = credentialsPrefs.get(getUsernamePrefKey(), "");
+        txtLogin.setText(username);
+        String password = credentialsPrefs.get(getPasswordPrefKey(), "");
+        txtPassword.setText(password);
+        if(username.isEmpty() || password.isEmpty()) {
+            autoConnect = false;
+        }
+    }
+
+    private void emptyCredentials() {
+        txtLogin.setText("");
+        txtLogin.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");
     private boolean validateLogin() {
         if(getUsername() == null || getUsername().isEmpty()) {
             setMessage("User login cannot be empty");
@@ -603,6 +723,10 @@ public class RemotingLoginDialog extends Dialog {
 
     public void setMessage(String message) {
         if(message != null && !message.isEmpty()) {
 
     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;
             styledTxtMessage.setText(message);
             styledTxtMessage.setVisible(true);
             ((GridData)styledTxtMessage.getLayoutData()).exclude = false;
@@ -618,6 +742,8 @@ public class RemotingLoginDialog extends Dialog {
         remotingComposite.layout();
     }
 
         remotingComposite.layout();
     }
 
+
+
     public void hide(boolean isHidden) {
         if(shlConnect != null) {
             shlConnect.setVisible(!isHidden);
     public void hide(boolean isHidden) {
         if(shlConnect != null) {
             shlConnect.setVisible(!isHidden);
@@ -628,4 +754,17 @@ public class RemotingLoginDialog extends Dialog {
             shlConnect.dispose();
         }
     }
             shlConnect.dispose();
         }
     }
+
+    public void onComplete() {
+        Display.getDefault().asyncExec(new Runnable() {
+            @Override
+            public void run() {
+                if(isRememberMe()) {
+                    persistPrefCredentials();
+                }
+                persistPrefLastServerInstance();
+                dispose();
+            }
+        });
+    }
 }
 }