Revision 1b626d51
Added by Cherian Mathew over 8 years ago
eu.etaxonomy.taxeditor.application/plugin.xml | ||
---|---|---|
162 | 162 |
name="eu.etaxonomy.taxeditor.application.filemenu.io" |
163 | 163 |
visible="true"> |
164 | 164 |
</separator> |
165 |
<command |
|
166 |
commandId="eu.etaxonomy.taxeditor.store.operations.showRemotingLoginWindow" |
|
167 |
id="eu.etaxonomy.taxeditor.application.menu.login" |
|
168 |
label="Connect" |
|
169 |
style="push"> |
|
170 |
</command> |
|
171 | 165 |
<command |
172 | 166 |
commandId="org.eclipse.ui.file.exit" |
173 | 167 |
id="eu.etaxonomy.taxeditor.application.menu.exit" |
... | ... | |
361 | 355 |
id="eu.etaxonomy.taxeditor.install" |
362 | 356 |
name="%command.label.18"> |
363 | 357 |
</command> |
364 |
<command |
|
365 |
defaultHandler="eu.etaxonomy.taxeditor.handler.ShowRemotingLoginWindowHandler" |
|
366 |
id="eu.etaxonomy.taxeditor.store.operations.showRemotingLoginWindow" |
|
367 |
name="Connect"> |
|
368 |
</command> |
|
369 | 358 |
</extension> |
370 | 359 |
|
371 | 360 |
|
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmServerInfo.java | ||
---|---|---|
38 | 38 |
public class CdmServerInfo { |
39 | 39 |
public static final Logger logger = Logger.getLogger(CdmServerInfo.class); |
40 | 40 |
|
41 |
private final static String CDMSERVER_PREFIX = "cdmserver"; |
|
41 | 42 |
private final static String NAME_PRODUCTION = "edit-production"; |
42 | 43 |
private final static String SERVER_PRODUCTION = "dev.e-taxonomy.eu"; |
43 | 44 |
|
... | ... | |
83 | 84 |
} |
84 | 85 |
public void refreshInstances() throws CDMServerException { |
85 | 86 |
instances.clear(); |
86 |
String url = "http://" + server + ":" + String.valueOf(port) + "/cdmserver/instances.jsp";
|
|
87 |
String url = "http://" + server + ":" + String.valueOf(port) + "/" + CDMSERVER_PREFIX + "/instances.jsp";
|
|
87 | 88 |
|
88 | 89 |
HttpClient client = new DefaultHttpClient(); |
89 | 90 |
HttpGet httpGet = new HttpGet(url); |
... | ... | |
140 | 141 |
|
141 | 142 |
} |
142 | 143 |
|
144 |
public String toString(String instanceName, int port) { |
|
145 |
return server + ":" + String.valueOf(port) + "/" + instanceName; |
|
146 |
} |
|
147 |
|
|
143 | 148 |
public CdmInstanceInfo getInstanceFromName(String instanceName) { |
144 | 149 |
if(instanceName == null) { |
145 | 150 |
return null; |
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySession.java | ||
---|---|---|
12 | 12 |
import java.util.ArrayList; |
13 | 13 |
import java.util.Arrays; |
14 | 14 |
import java.util.Collection; |
15 |
import java.util.HashSet; |
|
16 | 15 |
import java.util.List; |
17 | 16 |
import java.util.Map; |
18 |
import java.util.Set; |
|
19 | 17 |
import java.util.UUID; |
20 | 18 |
|
21 | 19 |
import net.sf.ehcache.statistics.LiveCacheStatistics; |
... | ... | |
47 | 45 |
|
48 | 46 |
private final ICdmEntitySessionEnabled sessionOwner; |
49 | 47 |
|
50 |
private final CdmTransientEntityCacher cdmTransientEntityCacher; |
|
51 |
|
|
52 |
private final List<ICdmEntitySessionEnabled> changeObservers; |
|
53 |
|
|
54 |
private final Set<CdmBase> newCdmEntities; |
|
48 |
private CdmTransientEntityCacher cdmTransientEntityCacher; |
|
55 | 49 |
|
50 |
private List<ICdmEntitySessionEnabled> changeObservers; |
|
56 | 51 |
|
57 | 52 |
|
58 | 53 |
public CdmEntitySession(ICdmEntitySessionEnabled sessionOwner, CdmEntitySessionManager cdmEntitySessionManager) { |
59 | 54 |
this.sessionOwner = sessionOwner; |
60 |
this.cdmTransientEntityCacher = new CdmTransientEntityCacher(sessionOwner, cdmEntitySessionManager); |
|
61 | 55 |
this.cdmEntitySessionManager = cdmEntitySessionManager; |
56 |
init(sessionOwner, cdmEntitySessionManager); |
|
57 |
} |
|
58 |
|
|
59 |
private void init(ICdmEntitySessionEnabled sessionOwner, CdmEntitySessionManager cdmEntitySessionManager) { |
|
60 |
this.cdmTransientEntityCacher = new CdmTransientEntityCacher(sessionOwner, cdmEntitySessionManager); |
|
62 | 61 |
this.changeObservers = new ArrayList<ICdmEntitySessionEnabled>(); |
63 |
this.newCdmEntities = new HashSet<CdmBase>(); |
|
64 | 62 |
cdmEntitySessionManager.addToOwnerSessionMap(sessionOwner, this); |
65 | 63 |
} |
66 | 64 |
|
... | ... | |
181 | 179 |
@Override |
182 | 180 |
public void bind() { |
183 | 181 |
logger.info("Binding session with owner " + sessionOwner.toString()); |
182 |
if(!cdmEntitySessionManager.contains(sessionOwner)) { |
|
183 |
init(sessionOwner, cdmEntitySessionManager); |
|
184 |
} |
|
184 | 185 |
cdmEntitySessionManager.bind(sessionOwner); |
185 | 186 |
|
186 | 187 |
} |
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionManager.java | ||
---|---|---|
96 | 96 |
|
97 | 97 |
} |
98 | 98 |
|
99 |
@Override |
|
100 |
public boolean contains(ICdmEntitySessionEnabled sessionOwner) { |
|
101 |
return ownerSessionMap.containsKey(sessionOwner); |
|
102 |
} |
|
103 |
|
|
99 | 104 |
|
100 | 105 |
/* (non-Javadoc) |
101 | 106 |
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#load(T) |
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/ICdmEntitySessionManager.java | ||
---|---|---|
54 | 54 |
*/ |
55 | 55 |
public <T extends CdmBase> void update(); |
56 | 56 |
|
57 |
/** |
|
58 |
* @param sessionOwner |
|
59 |
* @return |
|
60 |
*/ |
|
61 |
public boolean contains(ICdmEntitySessionEnabled sessionOwner); |
|
62 |
|
|
57 | 63 |
|
58 | 64 |
} |
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/mock/MockCdmEntitySessionManager.java | ||
---|---|---|
110 | 110 |
return updateResult; |
111 | 111 |
} |
112 | 112 |
|
113 |
/* (non-Javadoc) |
|
114 |
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#contains(eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled) |
|
115 |
*/ |
|
116 |
@Override |
|
117 |
public boolean contains(ICdmEntitySessionEnabled sessionOwner) { |
|
118 |
return false; |
|
119 |
} |
|
120 |
|
|
113 | 121 |
|
114 | 122 |
} |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java | ||
---|---|---|
43 | 43 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
44 | 44 |
import eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin; |
45 | 45 |
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator; |
46 |
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; |
|
46 | 47 |
|
47 | 48 |
/** |
48 | 49 |
* <p>NavigationUtil class.</p> |
... | ... | |
98 | 99 |
} catch (PartInitException e) { |
99 | 100 |
MessagingUtils.error(NavigationUtil.class, "Error opening the editor", e); |
100 | 101 |
} catch (Exception e) { |
101 |
MessagingUtils.warningDialog("Could not create Taxon", NavigationUtil.class, e.getMessage()); |
|
102 |
MessagingUtils.errorDialog("Could not create Taxon", |
|
103 |
NavigationUtil.class, |
|
104 |
e.getMessage(), TaxeditorStorePlugin.PLUGIN_ID, |
|
105 |
e, |
|
106 |
true); |
|
107 |
|
|
102 | 108 |
} |
103 | 109 |
} |
104 | 110 |
|
eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF | ||
---|---|---|
85 | 85 |
org.eclipse.ui.editors.text, |
86 | 86 |
org.eclipse.ui.forms.widgets, |
87 | 87 |
org.eclipse.ui.ide.undo, |
88 |
org.osgi.framework |
|
88 |
org.osgi.framework, |
|
89 |
org.osgi.service.prefs;version="1.1.1" |
|
89 | 90 |
Bundle-ActivationPolicy: lazy |
90 | 91 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 |
91 | 92 |
Bundle-ClassPath: ., |
eu.etaxonomy.taxeditor.store/plugin.xml | ||
---|---|---|
392 | 392 |
</menuContribution> |
393 | 393 |
<menuContribution |
394 | 394 |
locationURI="menu:org.eclipse.ui.main.menu.file?after=eu.etaxonomy.taxeditor.application.filemenu.io"> |
395 |
<command |
|
396 |
commandId="eu.etaxonomy.taxeditor.store.operations.showRemotingLoginWindow" |
|
397 |
label="Connect" |
|
398 |
style="push"> |
|
399 |
</command> |
|
395 | 400 |
<command |
396 | 401 |
commandId="eu.etaxonomy.taxeditor.store.operations.showLoginWindow" |
397 | 402 |
label="%command.label.5" |
398 | 403 |
style="push"> |
404 |
<visibleWhen |
|
405 |
checkEnabled="true"> |
|
406 |
<reference |
|
407 |
definitionId="isUserLoggedIn"> |
|
408 |
</reference> |
|
409 |
</visibleWhen> |
|
410 |
</command> |
|
411 |
<command |
|
412 |
commandId="eu.etaxonomy.taxeditor.store.operations.reconnect" |
|
413 |
label="Re-Connect" |
|
414 |
style="push"> |
|
415 |
<visibleWhen |
|
416 |
checkEnabled="true"> |
|
417 |
<reference |
|
418 |
definitionId="isUserLoggedIn"> |
|
419 |
</reference> |
|
420 |
</visibleWhen> |
|
399 | 421 |
</command> |
400 | 422 |
<separator |
401 | 423 |
name="eu.etaxonomy.taxeditor.application.filemenu.login" |
... | ... | |
604 | 626 |
</activeWhen> |
605 | 627 |
</handler> |
606 | 628 |
<handler |
607 |
class="eu.etaxonomy.taxeditor.handler.ShowLoginWindowHandler" |
|
608 |
commandId="eu.etaxonomy.taxeditor.store.operations.showLoginWindow"> |
|
609 |
<enabledWhen> |
|
610 |
<reference |
|
611 |
definitionId="isUserLoggedIn"> |
|
612 |
</reference></enabledWhen> |
|
629 |
class="eu.etaxonomy.taxeditor.handler.ShowRemotingLoginWindowHandler" |
|
630 |
commandId="eu.etaxonomy.taxeditor.store.operations.showRemotingLoginWindow"> |
|
613 | 631 |
</handler> |
614 | 632 |
<handler |
615 | 633 |
class="eu.etaxonomy.taxeditor.handler.OpenPasswordWizzardHandler" |
... | ... | |
628 | 646 |
</reference> |
629 | 647 |
</activeWhen> |
630 | 648 |
</handler> |
649 |
<handler |
|
650 |
class="eu.etaxonomy.taxeditor.handler.SwitchUserHandler" |
|
651 |
commandId="eu.etaxonomy.taxeditor.store.operations.showLoginWindow"> |
|
652 |
<activeWhen> |
|
653 |
<reference |
|
654 |
definitionId="isRemoting"> |
|
655 |
</reference> |
|
656 |
</activeWhen> |
|
657 |
</handler> |
|
631 | 658 |
</extension> |
632 | 659 |
<extension |
633 | 660 |
name="%extension.name.0" |
... | ... | |
668 | 695 |
name="%command.name.3"> |
669 | 696 |
</command> |
670 | 697 |
<command |
698 |
defaultHandler="eu.etaxonomy.taxeditor.handler.ShowLoginWindowHandler" |
|
671 | 699 |
id="eu.etaxonomy.taxeditor.store.operations.showLoginWindow" |
672 | 700 |
name="%command.name.4"> |
673 | 701 |
</command> |
702 |
<command |
|
703 |
id="eu.etaxonomy.taxeditor.store.operations.showRemotingLoginWindow" |
|
704 |
name="Connect"> |
|
705 |
</command> |
|
706 |
<command |
|
707 |
defaultHandler="eu.etaxonomy.taxeditor.handler.ReconnectHandler" |
|
708 |
id="eu.etaxonomy.taxeditor.store.operations.reconnect" |
|
709 |
name="Re-Connect"> |
|
710 |
</command> |
|
674 | 711 |
<command |
675 | 712 |
defaultHandler="eu.etaxonomy.taxeditor.editor.definedterm.handler.OpenDefinedTermEditorHandler" |
676 | 713 |
id="eu.etaxonomy.taxeditor.store.openDefinedTermEditor" |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/ReconnectHandler.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.taxeditor.handler; |
|
12 |
|
|
13 |
import org.eclipse.core.commands.AbstractHandler; |
|
14 |
import org.eclipse.core.commands.ExecutionEvent; |
|
15 |
import org.eclipse.core.commands.ExecutionException; |
|
16 |
import org.eclipse.core.commands.IHandler; |
|
17 |
import org.eclipse.swt.SWT; |
|
18 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
19 |
|
|
20 |
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource; |
|
21 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
22 |
import eu.etaxonomy.taxeditor.ui.dialog.RemotingLoginDialog; |
|
23 |
|
|
24 |
/** |
|
25 |
* |
|
26 |
* |
|
27 |
* @author c.mathew |
|
28 |
*/ |
|
29 |
public class ReconnectHandler extends AbstractHandler implements IHandler { |
|
30 |
|
|
31 |
/* (non-Javadoc) |
|
32 |
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
33 |
*/ |
|
34 |
/** {@inheritDoc} */ |
|
35 |
@Override |
|
36 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
37 |
|
|
38 |
RemotingLoginDialog loginDialog = new RemotingLoginDialog(HandlerUtil.getActiveShell(event), |
|
39 |
SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); |
|
40 |
|
|
41 |
loginDialog.open((CdmRemoteSource) CdmStore.getActiveCdmSource(), true, true); |
|
42 |
|
|
43 |
return null; |
|
44 |
|
|
45 |
} |
|
46 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/ShowRemotingLoginWindowHandler.java | ||
---|---|---|
20 | 20 |
import eu.etaxonomy.taxeditor.ui.dialog.RemotingLoginDialog; |
21 | 21 |
|
22 | 22 |
/** |
23 |
* <p>ShowLoginWindowHandler class.</p> |
|
24 | 23 |
* |
25 |
* @author n.hoffmann |
|
26 |
* @created Aug 7, 2009 |
|
27 |
* @version 1.0 |
|
24 |
* |
|
25 |
* @author c.mathew |
|
28 | 26 |
*/ |
29 | 27 |
public class ShowRemotingLoginWindowHandler extends AbstractHandler implements IHandler{ |
30 | 28 |
|
... | ... | |
35 | 33 |
@Override |
36 | 34 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
37 | 35 |
|
38 |
RemotingLoginDialog loginDialog = new RemotingLoginDialog(HandlerUtil.getActiveShell(event),SWT.DIALOG_TRIM
|
|
39 |
| SWT.APPLICATION_MODAL); |
|
36 |
RemotingLoginDialog loginDialog = new RemotingLoginDialog(HandlerUtil.getActiveShell(event), |
|
37 |
SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
|
|
40 | 38 |
loginDialog.open(); |
41 | 39 |
|
42 | 40 |
return null; |
43 | 41 |
|
44 | 42 |
} |
45 |
|
|
46 |
|
|
47 |
|
|
48 | 43 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/SwitchUserHandler.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.taxeditor.handler; |
|
12 |
|
|
13 |
import org.eclipse.core.commands.AbstractHandler; |
|
14 |
import org.eclipse.core.commands.ExecutionEvent; |
|
15 |
import org.eclipse.core.commands.ExecutionException; |
|
16 |
import org.eclipse.core.commands.IHandler; |
|
17 |
import org.eclipse.swt.SWT; |
|
18 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
19 |
|
|
20 |
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource; |
|
21 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
22 |
import eu.etaxonomy.taxeditor.ui.dialog.RemotingLoginDialog; |
|
23 |
|
|
24 |
/** |
|
25 |
* |
|
26 |
* |
|
27 |
* @author c.mathew |
|
28 |
*/ |
|
29 |
public class SwitchUserHandler extends AbstractHandler implements IHandler { |
|
30 |
|
|
31 |
/* (non-Javadoc) |
|
32 |
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
33 |
*/ |
|
34 |
/** {@inheritDoc} */ |
|
35 |
@Override |
|
36 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
37 |
|
|
38 |
RemotingLoginDialog loginDialog = new RemotingLoginDialog(HandlerUtil.getActiveShell(event), |
|
39 |
SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); |
|
40 |
|
|
41 |
loginDialog.open((CdmRemoteSource) CdmStore.getActiveCdmSource(), false, false); |
|
42 |
|
|
43 |
return null; |
|
44 |
|
|
45 |
} |
|
46 |
} |
|
47 |
|
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java | ||
---|---|---|
173 | 173 |
private static void connect(final ICdmSource cdmSource, |
174 | 174 |
final DbSchemaValidation dbSchemaValidation, |
175 | 175 |
final Resource applicationContextBean, |
176 |
RemotingLoginDialog loginDialog) { |
|
176 |
RemotingLoginDialog remotingLoginDialog) { |
|
177 |
RemotingLoginDialog loginDialog = remotingLoginDialog; |
|
178 |
|
|
179 |
MessagingUtils.info("Connecting to datasource: " + cdmSource); |
|
180 |
|
|
181 |
job = new CdmStoreConnector(Display.getDefault(), |
|
182 |
cdmSource, |
|
183 |
dbSchemaValidation, |
|
184 |
applicationContextBean); |
|
185 |
job.start(loginDialog); |
|
177 | 186 |
if(isActive()) { |
178 | 187 |
// before we connect we clear the entity caches and the sessions |
179 | 188 |
CdmRemoteCacheManager.removeEntityCaches(); |
... | ... | |
181 | 190 |
getCurrentSessionManager().disposeAll(); |
182 | 191 |
} |
183 | 192 |
} |
184 |
MessagingUtils.info("Connecting to datasource: " + cdmSource); |
|
185 |
job = new CdmStoreConnector(Display.getDefault(), |
|
186 |
cdmSource, |
|
187 |
dbSchemaValidation, |
|
188 |
applicationContextBean); |
|
189 |
job.start(loginDialog); |
|
190 | 193 |
} |
191 | 194 |
|
192 | 195 |
public static boolean isConnecting() { |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStoreConnector.java | ||
---|---|---|
223 | 223 |
try { |
224 | 224 |
// create new security context |
225 | 225 |
CdmStore.getLoginManager().doAuthenticate(loginDialog.getUsername(), loginDialog.getPassword()); |
226 |
loginDialog.dispose();
|
|
226 |
loginDialog.onComplete();
|
|
227 | 227 |
// start editor context |
228 | 228 |
CdmStore.getContextManager().notifyContextStartWithoutDialog(monitor); |
229 | 229 |
|
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java | ||
---|---|---|
17 | 17 |
import org.eclipse.core.runtime.IStatus; |
18 | 18 |
import org.eclipse.core.runtime.Status; |
19 | 19 |
import org.eclipse.core.runtime.jobs.Job; |
20 |
import org.eclipse.core.runtime.preferences.ConfigurationScope; |
|
21 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
|
20 | 22 |
import org.eclipse.swt.SWT; |
21 | 23 |
import org.eclipse.swt.custom.StyledText; |
22 | 24 |
import org.eclipse.swt.events.MouseAdapter; |
... | ... | |
39 | 41 |
import org.eclipse.ui.forms.events.IExpansionListener; |
40 | 42 |
import org.eclipse.ui.forms.widgets.ExpandableComposite; |
41 | 43 |
import org.eclipse.wb.swt.SWTResourceManager; |
44 |
import org.osgi.service.prefs.BackingStoreException; |
|
45 |
import org.osgi.service.prefs.Preferences; |
|
42 | 46 |
|
43 | 47 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
44 | 48 |
import eu.etaxonomy.taxeditor.remoting.server.CDMServerException; |
49 |
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource; |
|
45 | 50 |
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo; |
46 | 51 |
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo.CdmInstanceInfo; |
47 | 52 |
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource; |
... | ... | |
64 | 69 |
|
65 | 70 |
private final Map<String, CdmServerInfo> csiiMap = new HashMap<String, CdmServerInfo>(); |
66 | 71 |
|
67 |
private final String STATUS_AVAILABLE = "Available"; |
|
68 |
private final String STATUS_NOT_AVAILABLE = "Not Available"; |
|
69 |
private final String STATUS_RETRIEVING = "Retrieving ..."; |
|
70 |
private final String STATUS_CHECKING_AVAILABILITY = "Checking ..."; |
|
71 |
private final String STATUS_NO_INSTANCES = "No Instances Found"; |
|
72 |
private final String STATUS_ERROR = "Error"; |
|
73 |
private final String STATUS_REMOTING_NOT_ACTIVATED = "Remoting not activated"; |
|
72 |
private final static String STATUS_AVAILABLE = "Available"; |
|
73 |
private final static String STATUS_NOT_AVAILABLE = "Not Available"; |
|
74 |
private final static String STATUS_RETRIEVING = "Retrieving ..."; |
|
75 |
private final static String STATUS_CHECKING_AVAILABILITY = "Checking ..."; |
|
76 |
private final static String STATUS_NO_INSTANCES = "No Instances Found"; |
|
77 |
private final static String STATUS_ERROR = "Error"; |
|
78 |
private final static String STATUS_REMOTING_NOT_ACTIVATED = "Remoting not activated"; |
|
79 |
private final static String STORE_PREFERENCES_NODE = "eu.etaxonomy.taxeditor.store"; |
|
80 |
|
|
81 |
private final static String LOGIN_NODE = "login"; |
|
82 |
private final static String USERNAME_SUFFIX = "_username"; |
|
83 |
private final static String PASSWORD_SUFFIX = "_password"; |
|
84 |
|
|
85 |
private final static String LAST_SERVER_INSTANCE_NODE = "lastServerInstance"; |
|
86 |
private final static String LAST_SERVER_KEY = "lastServerKey"; |
|
87 |
private final static String LAST_INSTANCE_KEY = "lastInstanceKey"; |
|
88 |
|
|
74 | 89 |
|
75 | 90 |
private Composite remotingComposite; |
76 | 91 |
private CdmServerInfo selectedCsii; |
... | ... | |
102 | 117 |
private Label lblEditorCDMVersion; |
103 | 118 |
private Text txtEditorCDMVersion; |
104 | 119 |
|
120 |
private String serverName, instanceName; |
|
121 |
private boolean autoConnect = false; |
|
122 |
private boolean loadLoginPrefs = true; |
|
123 |
|
|
105 | 124 |
/** |
106 | 125 |
* Create the dialog. |
107 | 126 |
* @param parent |
... | ... | |
112 | 131 |
setText("Login"); |
113 | 132 |
} |
114 | 133 |
|
134 |
public Object open(CdmRemoteSource source, boolean loadLoginPrefs, boolean autoConnect) { |
|
135 |
this.loadLoginPrefs = loadLoginPrefs; |
|
136 |
this.serverName = source.getName(); |
|
137 |
String contextPath = source.getContextPath(); |
|
138 |
this.instanceName = contextPath.substring(contextPath.lastIndexOf("/") + 1); |
|
139 |
return open(serverName, instanceName, loadLoginPrefs, autoConnect); |
|
140 |
} |
|
141 |
|
|
142 |
|
|
143 |
public Object open(String serverName, String instanceName, boolean loadLoginPrefs, boolean autoConnect) { |
|
144 |
this.serverName = serverName; |
|
145 |
this.instanceName = instanceName; |
|
146 |
this.loadLoginPrefs = loadLoginPrefs; |
|
147 |
this.autoConnect = autoConnect; |
|
148 |
return open(); |
|
149 |
} |
|
150 |
|
|
115 | 151 |
/** |
116 | 152 |
* Open the dialog. |
117 | 153 |
* @return the result |
... | ... | |
208 | 244 |
@Override |
209 | 245 |
public void widgetSelected(SelectionEvent e) { |
210 | 246 |
updateSelectedCdmInstance(); |
211 |
checkSelectedCdmServerInstance();
|
|
247 |
checkSelectedCdmInstance(); |
|
212 | 248 |
} |
213 | 249 |
}); |
214 | 250 |
GridData gd_comboCdmInstance = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1); |
... | ... | |
277 | 313 |
btnConnect.addMouseListener(new MouseAdapter() { |
278 | 314 |
@Override |
279 | 315 |
public void mouseUp(MouseEvent e) { |
280 |
int selInstanceIndex = comboCdmInstance.getSelectionIndex(); |
|
281 |
String instance = comboCdmInstance.getItem(selInstanceIndex); |
|
282 |
checkSelectedCdmServerInstance(); |
|
283 |
connect(selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort())); |
|
316 |
connect(); |
|
284 | 317 |
} |
285 | 318 |
}); |
286 | 319 |
btnConnect.setText("Connect"); |
287 | 320 |
|
288 | 321 |
btnRememberMe = new Button(loginComposite, SWT.CHECK); |
322 |
btnRememberMe.setSelection(true); |
|
289 | 323 |
GridData gd_btnRememberMe = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1); |
290 | 324 |
gd_btnRememberMe.widthHint = 107; |
291 | 325 |
btnRememberMe.setLayoutData(gd_btnRememberMe); |
292 |
btnRememberMe.setEnabled(false); |
|
293 | 326 |
btnRememberMe.setText("Remember Me"); |
294 | 327 |
new Label(loginComposite, SWT.NONE); |
295 | 328 |
new Label(loginComposite, SWT.NONE); |
... | ... | |
396 | 429 |
|
397 | 430 |
} |
398 | 431 |
|
432 |
|
|
433 |
|
|
399 | 434 |
private void populateCdmServerCombo() { |
400 | 435 |
Job job = new Job("Retrieve Server Instances") { |
401 | 436 |
@Override |
402 | 437 |
protected IStatus run(IProgressMonitor monitor) { |
403 |
Display.getDefault().asyncExec(new Runnable() {
|
|
438 |
Display.getDefault().syncExec(new Runnable() { |
|
404 | 439 |
@Override |
405 | 440 |
public void run() { |
406 | 441 |
for(CdmServerInfo csii : CdmServerInfo.getCdmServers()) { |
407 | 442 |
csiiMap.put(csii.getName(), csii); |
408 | 443 |
comboCdmServer.add(csii.getName()); |
409 | 444 |
} |
410 |
comboCdmServer.select(0); |
|
445 |
int serverIndex = -1; |
|
446 |
if(serverName != null) { |
|
447 |
serverIndex = comboCdmServer.indexOf(serverName); |
|
448 |
} |
|
449 |
if(serverIndex == -1) { |
|
450 |
comboCdmServer.select(0); |
|
451 |
autoConnect = false; |
|
452 |
} else { |
|
453 |
comboCdmServer.select(serverIndex); |
|
454 |
} |
|
411 | 455 |
refreshCdmServer(); |
412 | 456 |
updatePort(); |
413 | 457 |
} |
... | ... | |
450 | 494 |
} |
451 | 495 |
|
452 | 496 |
private void checkSelectedCdmServer() { |
453 |
int selIndex = comboCdmServer.getSelectionIndex(); |
|
497 |
|
|
454 | 498 |
txtCdmInstanceStatus.setText(""); |
455 | 499 |
txtPort.setEditable(false); |
456 | 500 |
txtPort.setEnabled(false); |
501 |
emptyCredentials(); |
|
502 |
|
|
457 | 503 |
if(selectedCsii != null) { |
458 | 504 |
if(selectedCsii.isLocalhost()) { |
459 | 505 |
txtPort.setEditable(true); |
460 | 506 |
txtPort.setEnabled(true); |
461 |
} else { |
|
462 |
txtPort.setEditable(false); |
|
463 |
txtPort.setEnabled(false); |
|
464 | 507 |
} |
465 | 508 |
if(selectedCsii.pingServer()) { |
466 | 509 |
txtCdmServerStatus.setText(STATUS_AVAILABLE); |
... | ... | |
479 | 522 |
comboCdmInstance.setEnabled(false); |
480 | 523 |
btnConnect.setEnabled(false); |
481 | 524 |
txtCdmInstanceStatus.setText(STATUS_RETRIEVING); |
525 |
|
|
482 | 526 |
Job job = new Job("Retrieve Server Instances") { |
483 | 527 |
@Override |
484 | 528 |
protected IStatus run(IProgressMonitor monitor) { |
... | ... | |
495 | 539 |
for(CdmInstanceInfo cdmInstance : instances) { |
496 | 540 |
comboCdmInstance.add(cdmInstance.getName()); |
497 | 541 |
} |
498 |
comboCdmInstance.select(0); |
|
542 |
int instanceIndex = -1; |
|
543 |
if(instanceName != null) { |
|
544 |
instanceIndex = comboCdmInstance.indexOf(instanceName); |
|
545 |
} |
|
546 |
if(instanceIndex == -1) { |
|
547 |
comboCdmInstance.select(0); |
|
548 |
autoConnect = false; |
|
549 |
} else { |
|
550 |
comboCdmInstance.select(instanceIndex); |
|
551 |
} |
|
499 | 552 |
updateSelectedCdmInstance(); |
500 |
checkSelectedCdmServerInstance();
|
|
553 |
checkSelectedCdmInstance(); |
|
501 | 554 |
comboCdmInstance.setEnabled(true); |
555 |
if(autoConnect) { |
|
556 |
connect(); |
|
557 |
} |
|
502 | 558 |
|
503 | 559 |
} else { |
504 | 560 |
txtCdmInstanceStatus.setText(STATUS_NO_INSTANCES); |
... | ... | |
532 | 588 |
private void refreshCdmInstance() { |
533 | 589 |
txtCdmInstanceStatus.setText(STATUS_CHECKING_AVAILABILITY); |
534 | 590 |
updateSelectedCdmInstance(); |
535 |
checkSelectedCdmServerInstance();
|
|
591 |
checkSelectedCdmInstance(); |
|
536 | 592 |
} |
537 | 593 |
|
538 | 594 |
private void updateSelectedCdmInstance() { |
539 | 595 |
int selIndex = comboCdmInstance.getSelectionIndex(); |
540 | 596 |
if(selIndex != -1) { |
541 | 597 |
selectedCdmInstance = selectedCsii.getInstanceFromName(comboCdmInstance.getItem(selIndex)); |
598 |
if(loadLoginPrefs) { |
|
599 |
readPrefCredentials(); |
|
600 |
} |
|
542 | 601 |
} |
543 | 602 |
} |
544 | 603 |
|
545 |
private void checkSelectedCdmServerInstance() {
|
|
604 |
private void checkSelectedCdmInstance() { |
|
546 | 605 |
if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) { |
547 | 606 |
try { |
548 | 607 |
if(selectedCsii.pingInstance(selectedCdmInstance, getPort())) { |
... | ... | |
554 | 613 |
} |
555 | 614 |
} catch (Exception e) { |
556 | 615 |
txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE); |
557 |
//MessagingUtils.warn(this.getClass(), e);
|
|
616 |
txtCdmInstanceStatus.setToolTipText(e.getMessage());
|
|
558 | 617 |
} |
559 | 618 |
} |
560 | 619 |
|
561 | 620 |
} |
562 | 621 |
|
563 |
private void connect(ICdmRemoteSource source) {
|
|
564 |
|
|
622 |
private void connect() { |
|
623 |
checkSelectedCdmInstance(); |
|
565 | 624 |
|
566 |
if(!validateLogin()) {
|
|
625 |
if(!txtCdmInstanceStatus.getText().equals(STATUS_AVAILABLE)) {
|
|
567 | 626 |
return; |
568 | 627 |
} |
569 | 628 |
|
570 |
if(CdmStore.isConnecting()){ |
|
571 |
MessagingUtils.warningDialog("Already connecting", this, "You are currently connecting to a different CDM Instance already."); |
|
629 |
ICdmRemoteSource source = selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort()); |
|
630 |
|
|
631 |
if(!validateLogin()) { |
|
572 | 632 |
return; |
573 | 633 |
} |
634 |
// |
|
635 |
// if(CdmStore.isConnecting()){ |
|
636 |
// MessagingUtils.warningDialog("Already connecting", this, "You are currently connecting to a different CDM Instance already."); |
|
637 |
// return; |
|
638 |
// } |
|
574 | 639 |
|
575 | 640 |
try { |
576 | 641 |
CdmStore.connect(source, this); |
... | ... | |
582 | 647 |
|
583 | 648 |
} |
584 | 649 |
|
650 |
public boolean isRememberMe() { |
|
651 |
return btnRememberMe.getSelection(); |
|
652 |
} |
|
653 |
|
|
654 |
private void persistPrefLastServerInstance() { |
|
655 |
IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE); |
|
656 |
Preferences lastServerInstancePrefs = preferences.node(LAST_SERVER_INSTANCE_NODE); |
|
657 |
|
|
658 |
lastServerInstancePrefs.put(LAST_SERVER_KEY, selectedCsii.getName()); |
|
659 |
lastServerInstancePrefs.put(LAST_INSTANCE_KEY, selectedCdmInstance.getName()); |
|
660 |
|
|
661 |
flushPreferences(lastServerInstancePrefs); |
|
662 |
} |
|
663 |
|
|
664 |
private void persistPrefCredentials() { |
|
665 |
IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE); |
|
666 |
Preferences credentialsPrefs = preferences.node(LOGIN_NODE); |
|
667 |
credentialsPrefs.put(getUsernamePrefKey(), txtLogin.getText()); |
|
668 |
credentialsPrefs.put(getPasswordPrefKey(), txtPassword.getText()); |
|
669 |
flushPreferences(credentialsPrefs); |
|
670 |
} |
|
671 |
|
|
672 |
private void flushPreferences(Preferences prefs) { |
|
673 |
try { |
|
674 |
prefs.flush(); |
|
675 |
} catch (BackingStoreException bse) { |
|
676 |
setMessage(bse.getMessage()); |
|
677 |
} |
|
678 |
} |
|
679 |
|
|
680 |
private void readPrefCredentials() { |
|
681 |
IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE); |
|
682 |
Preferences credentialsPrefs = preferences.node(LOGIN_NODE); |
|
683 |
String username = credentialsPrefs.get(getUsernamePrefKey(), ""); |
|
684 |
txtLogin.setText(username); |
|
685 |
String password = credentialsPrefs.get(getPasswordPrefKey(), ""); |
|
686 |
txtPassword.setText(password); |
|
687 |
if(username.isEmpty() || password.isEmpty()) { |
|
688 |
autoConnect = false; |
|
689 |
} |
|
690 |
} |
|
691 |
|
|
692 |
private void emptyCredentials() { |
|
693 |
txtLogin.setText(""); |
|
694 |
txtLogin.setText(""); |
|
695 |
} |
|
696 |
|
|
697 |
private String getUsernamePrefKey() { |
|
698 |
return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + USERNAME_SUFFIX; |
|
699 |
} |
|
700 |
|
|
701 |
private String getPasswordPrefKey() { |
|
702 |
return selectedCsii.toString(selectedCdmInstance.getName(), getPort()) + PASSWORD_SUFFIX; |
|
703 |
} |
|
704 |
|
|
585 | 705 |
private boolean validateLogin() { |
586 | 706 |
if(getUsername() == null || getUsername().isEmpty()) { |
587 | 707 |
setMessage("User login cannot be empty"); |
... | ... | |
603 | 723 |
|
604 | 724 |
public void setMessage(String message) { |
605 | 725 |
if(message != null && !message.isEmpty()) { |
726 |
if(message.length() > 60) { |
|
727 |
styledTxtMessage.setToolTipText(message); |
|
728 |
message = message.substring(0, 60) + "..."; |
|
729 |
} |
|
606 | 730 |
styledTxtMessage.setText(message); |
607 | 731 |
styledTxtMessage.setVisible(true); |
608 | 732 |
((GridData)styledTxtMessage.getLayoutData()).exclude = false; |
... | ... | |
618 | 742 |
remotingComposite.layout(); |
619 | 743 |
} |
620 | 744 |
|
745 |
|
|
746 |
|
|
621 | 747 |
public void hide(boolean isHidden) { |
622 | 748 |
if(shlConnect != null) { |
623 | 749 |
shlConnect.setVisible(!isHidden); |
... | ... | |
628 | 754 |
shlConnect.dispose(); |
629 | 755 |
} |
630 | 756 |
} |
757 |
|
|
758 |
public void onComplete() { |
|
759 |
Display.getDefault().asyncExec(new Runnable() { |
|
760 |
@Override |
|
761 |
public void run() { |
|
762 |
if(isRememberMe()) { |
|
763 |
persistPrefCredentials(); |
|
764 |
} |
|
765 |
persistPrefLastServerInstance(); |
|
766 |
dispose(); |
|
767 |
} |
|
768 |
}); |
|
769 |
} |
|
631 | 770 |
} |
Also available in: Unified diff
#5029 Add functionality for login to remember credentials, reconnect and switch user