From: Cherian Mathew Date: Thu, 30 Jul 2015 08:58:19 +0000 (+0200) Subject: #5029 Add functionality for login to remember credentials, reconnect and switch user X-Git-Tag: remoting-3.9.0~70 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/1b626d515413ac766584373c24f54be238fb5e4c #5029 Add functionality for login to remember credentials, reconnect and switch user --- diff --git a/eu.etaxonomy.taxeditor.application/plugin.xml b/eu.etaxonomy.taxeditor.application/plugin.xml index 97897e120..b74e209ce 100644 --- a/eu.etaxonomy.taxeditor.application/plugin.xml +++ b/eu.etaxonomy.taxeditor.application/plugin.xml @@ -162,12 +162,6 @@ name="eu.etaxonomy.taxeditor.application.filemenu.io" visible="true"> - - - - diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmServerInfo.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmServerInfo.java index cf41d602d..ecca6c7f5 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmServerInfo.java +++ b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmServerInfo.java @@ -38,6 +38,7 @@ import eu.etaxonomy.taxeditor.remoting.server.CDMServerException; 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"; @@ -83,7 +84,7 @@ public class CdmServerInfo { } 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); @@ -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; diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySession.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySession.java index 97de82fcc..a8cc4ecd9 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySession.java +++ b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySession.java @@ -12,10 +12,8 @@ package eu.etaxonomy.taxeditor.session; 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.Set; 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 CdmTransientEntityCacher cdmTransientEntityCacher; - - private final List changeObservers; - - private final Set newCdmEntities; + private CdmTransientEntityCacher cdmTransientEntityCacher; + private List changeObservers; public CdmEntitySession(ICdmEntitySessionEnabled sessionOwner, CdmEntitySessionManager cdmEntitySessionManager) { this.sessionOwner = sessionOwner; - this.cdmTransientEntityCacher = new CdmTransientEntityCacher(sessionOwner, cdmEntitySessionManager); this.cdmEntitySessionManager = cdmEntitySessionManager; + init(sessionOwner, cdmEntitySessionManager); + } + + private void init(ICdmEntitySessionEnabled sessionOwner, CdmEntitySessionManager cdmEntitySessionManager) { + this.cdmTransientEntityCacher = new CdmTransientEntityCacher(sessionOwner, cdmEntitySessionManager); this.changeObservers = new ArrayList(); - this.newCdmEntities = new HashSet(); 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()); + if(!cdmEntitySessionManager.contains(sessionOwner)) { + init(sessionOwner, cdmEntitySessionManager); + } cdmEntitySessionManager.bind(sessionOwner); } diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionManager.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionManager.java index 9bddb82d5..a54117110 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionManager.java +++ b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionManager.java @@ -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) diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/ICdmEntitySessionManager.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/ICdmEntitySessionManager.java index cd15d27a2..1f8ba4e19 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/ICdmEntitySessionManager.java +++ b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/ICdmEntitySessionManager.java @@ -54,5 +54,11 @@ public interface ICdmEntitySessionManager { */ public void update(); + /** + * @param sessionOwner + * @return + */ + public boolean contains(ICdmEntitySessionEnabled sessionOwner); + } \ No newline at end of file diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/mock/MockCdmEntitySessionManager.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/mock/MockCdmEntitySessionManager.java index f32d7c2e5..443ed97c6 100644 --- a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/mock/MockCdmEntitySessionManager.java +++ b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/mock/MockCdmEntitySessionManager.java @@ -110,5 +110,13 @@ public class MockCdmEntitySessionManager implements ICdmEntitySessionManager { return updateResult; } + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#contains(eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled) + */ + @Override + public boolean contains(ICdmEntitySessionEnabled sessionOwner) { + return false; + } + } diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java index 7e48f97fc..a266c8d92 100644 --- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java @@ -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.store.internal.TaxeditorStorePlugin; /** *

NavigationUtil class.

@@ -98,7 +99,12 @@ public class NavigationUtil extends AbstractUtility{ } 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); + } } diff --git a/eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF b/eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF index db9b51a83..4b6f8c153 100644 --- a/eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF +++ b/eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF @@ -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.osgi.framework + org.osgi.framework, + org.osgi.service.prefs;version="1.1.1" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ClassPath: ., diff --git a/eu.etaxonomy.taxeditor.store/plugin.xml b/eu.etaxonomy.taxeditor.store/plugin.xml index 967bc4364..1ccc50cf2 100644 --- a/eu.etaxonomy.taxeditor.store/plugin.xml +++ b/eu.etaxonomy.taxeditor.store/plugin.xml @@ -392,10 +392,32 @@ + + + + + + + + + + + + - - - + class="eu.etaxonomy.taxeditor.handler.ShowRemotingLoginWindowHandler" + commandId="eu.etaxonomy.taxeditor.store.operations.showRemotingLoginWindow"> + + + + + + + + + + ShowLoginWindowHandler class.

* - * @author n.hoffmann - * @created Aug 7, 2009 - * @version 1.0 + * + * @author c.mathew */ 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 { - 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; } - - - } 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 index 000000000..93e12bd93 --- /dev/null +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/SwitchUserHandler.java @@ -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; + + } +} + diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java index d54c22daf..8e7e5ef20 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java @@ -173,7 +173,16 @@ public class CdmStore { 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(); @@ -181,12 +190,6 @@ public class CdmStore { getCurrentSessionManager().disposeAll(); } } - MessagingUtils.info("Connecting to datasource: " + cdmSource); - job = new CdmStoreConnector(Display.getDefault(), - cdmSource, - dbSchemaValidation, - applicationContextBean); - job.start(loginDialog); } public static boolean isConnecting() { diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStoreConnector.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStoreConnector.java index 9fbe2c6e8..3c7ac77b1 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStoreConnector.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStoreConnector.java @@ -223,7 +223,7 @@ class CdmStoreConnector extends Job { try { // create new security context CdmStore.getLoginManager().doAuthenticate(loginDialog.getUsername(), loginDialog.getPassword()); - loginDialog.dispose(); + loginDialog.onComplete(); // start editor context CdmStore.getContextManager().notifyContextStartWithoutDialog(monitor); diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java index 09d3af81e..5d2429189 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java @@ -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.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; @@ -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.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.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; @@ -64,13 +69,23 @@ public class RemotingLoginDialog extends Dialog { private final Map csiiMap = new HashMap(); - 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; @@ -102,6 +117,10 @@ public class RemotingLoginDialog extends Dialog { private Label lblEditorCDMVersion; private Text txtEditorCDMVersion; + private String serverName, instanceName; + private boolean autoConnect = false; + private boolean loadLoginPrefs = true; + /** * Create the dialog. * @param parent @@ -112,6 +131,23 @@ public class RemotingLoginDialog extends Dialog { setText("Login"); } + public Object open(CdmRemoteSource source, boolean loadLoginPrefs, boolean autoConnect) { + this.loadLoginPrefs = loadLoginPrefs; + this.serverName = source.getName(); + String contextPath = source.getContextPath(); + this.instanceName = contextPath.substring(contextPath.lastIndexOf("/") + 1); + return open(serverName, instanceName, loadLoginPrefs, autoConnect); + } + + + public Object open(String serverName, String instanceName, boolean loadLoginPrefs, boolean autoConnect) { + this.serverName = serverName; + this.instanceName = instanceName; + this.loadLoginPrefs = loadLoginPrefs; + this.autoConnect = autoConnect; + return open(); + } + /** * Open the dialog. * @return the result @@ -208,7 +244,7 @@ public class RemotingLoginDialog extends Dialog { @Override public void widgetSelected(SelectionEvent e) { updateSelectedCdmInstance(); - checkSelectedCdmServerInstance(); + checkSelectedCdmInstance(); } }); GridData gd_comboCdmInstance = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1); @@ -277,19 +313,16 @@ public class RemotingLoginDialog extends Dialog { 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); + 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.setEnabled(false); 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) { - Display.getDefault().asyncExec(new Runnable() { + Display.getDefault().syncExec(new Runnable() { @Override public void run() { for(CdmServerInfo csii : CdmServerInfo.getCdmServers()) { csiiMap.put(csii.getName(), csii); comboCdmServer.add(csii.getName()); } - comboCdmServer.select(0); + int serverIndex = -1; + if(serverName != null) { + serverIndex = comboCdmServer.indexOf(serverName); + } + if(serverIndex == -1) { + comboCdmServer.select(0); + autoConnect = false; + } else { + comboCdmServer.select(serverIndex); + } refreshCdmServer(); updatePort(); } @@ -450,17 +494,16 @@ public class RemotingLoginDialog extends Dialog { } private void checkSelectedCdmServer() { - int selIndex = comboCdmServer.getSelectionIndex(); + txtCdmInstanceStatus.setText(""); txtPort.setEditable(false); txtPort.setEnabled(false); + emptyCredentials(); + 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); @@ -479,6 +522,7 @@ public class RemotingLoginDialog extends Dialog { comboCdmInstance.setEnabled(false); btnConnect.setEnabled(false); txtCdmInstanceStatus.setText(STATUS_RETRIEVING); + 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()); } - comboCdmInstance.select(0); + int instanceIndex = -1; + if(instanceName != null) { + instanceIndex = comboCdmInstance.indexOf(instanceName); + } + if(instanceIndex == -1) { + comboCdmInstance.select(0); + autoConnect = false; + } else { + comboCdmInstance.select(instanceIndex); + } updateSelectedCdmInstance(); - checkSelectedCdmServerInstance(); + checkSelectedCdmInstance(); comboCdmInstance.setEnabled(true); + if(autoConnect) { + connect(); + } } else { txtCdmInstanceStatus.setText(STATUS_NO_INSTANCES); @@ -532,17 +588,20 @@ public class RemotingLoginDialog extends Dialog { 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)); + if(loadLoginPrefs) { + readPrefCredentials(); + } } } - private void checkSelectedCdmServerInstance() { + private void checkSelectedCdmInstance() { 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); - //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; } - 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; } +// +// if(CdmStore.isConnecting()){ +// MessagingUtils.warningDialog("Already connecting", this, "You are currently connecting to a different CDM Instance already."); +// return; +// } 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"); @@ -603,6 +723,10 @@ 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) + "..."; + } styledTxtMessage.setText(message); styledTxtMessage.setVisible(true); ((GridData)styledTxtMessage.getLayoutData()).exclude = false; @@ -618,6 +742,8 @@ public class RemotingLoginDialog extends Dialog { remotingComposite.layout(); } + + public void hide(boolean isHidden) { if(shlConnect != null) { shlConnect.setVisible(!isHidden); @@ -628,4 +754,17 @@ public class RemotingLoginDialog extends Dialog { shlConnect.dispose(); } } + + public void onComplete() { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + if(isRememberMe()) { + persistPrefCredentials(); + } + persistPrefLastServerInstance(); + dispose(); + } + }); + } }