}
progressMonitor.worked(1);
- progressMonitor.subTask("Starting context ...");
+ progressMonitor.subTask("Starting application context ...");
applicationContext.refresh();
applicationContext.start();
setApplicationContext(applicationContext);
*/
@Override
public String getConnectionMessage() {
- return "Conncting to Remote CDM Server " + getName();
+ return "Connecting to Remote CDM Instance " + getName() + ":" + getPort() + "/" + getContextPath();
}
if(cdmEntitySession != null) {
cdmEntitySession.dispose();
}
- CdmApplicationState.getCurrentDataChangeService().unregister(this);
+ if(CdmApplicationState.getCurrentDataChangeService() != null) {
+ CdmApplicationState.getCurrentDataChangeService().unregister(this);
+ }
}
/*
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2015 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.store;
+
+/**
+ * @author cmathew
+ * @date 24 Jul 2015
+ *
+ */
+public class CdmAuthenticationException extends RuntimeException {
+
+ public CdmAuthenticationException(String message, Throwable t) {
+ super(message,t);
+ }
+
+}
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
import eu.etaxonomy.taxeditor.session.mock.MockCdmEntitySessionManager;
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
+import eu.etaxonomy.taxeditor.ui.dialog.RemotingLoginDialog;
import eu.etaxonomy.taxeditor.view.datasource.CdmDataSourceViewPart;
/**
*/
public class CdmStore {
- private static final Resource DEFAULT_APPLICATION_CONTEXT = new ClassPathResource(
- "/eu/etaxonomy/cdm/editorApplicationContext.xml",
- TaxeditorStorePlugin.class);
- private static final DbSchemaValidation DEFAULT_DB_SCHEMA_VALIDATION = DbSchemaValidation.VALIDATE;
+ private static final Resource DEFAULT_APPLICATION_CONTEXT = new ClassPathResource(
+ "/eu/etaxonomy/cdm/editorApplicationContext.xml",
+ TaxeditorStorePlugin.class);
+ private static final DbSchemaValidation DEFAULT_DB_SCHEMA_VALIDATION = DbSchemaValidation.VALIDATE;
- private static CdmStore instance;
+ private static CdmStore instance;
- //private final ICdmApplicationConfiguration applicationConfiguration;
+ //private final ICdmApplicationConfiguration applicationConfiguration;
- private static ContextManager contextManager = new ContextManager();
+ private static ContextManager contextManager = new ContextManager();
- private static LoginManager loginManager = new LoginManager();
+ private static LoginManager loginManager = new LoginManager();
- private static TermManager termManager = new TermManager();
+ private static TermManager termManager = new TermManager();
- private static SearchManager searchManager = new SearchManager();
+ private static SearchManager searchManager = new SearchManager();
- private static EditorManager editorManager = new EditorManager();
-
- private static UseObjectStore useObjectInitializer = new UseObjectStore();
-
- private static CdmStoreConnector job;
-
- private Language language;
-
- private ICdmSource cdmSource;
-
- private boolean isConnected;
-
-
-
- /**
- * <p>
- * getDefault
- * </p>
- *
- * @return a {@link eu.etaxonomy.taxeditor.store.CdmStore} object.
- */
- protected static CdmStore getDefault() {
- if (instance != null && instance.isConnected) {
- return instance;
- } else{// if (instance == null || !instance.isConnected) {
-
- MessagingUtils.noDataSourceWarningDialog(instance);
-
- AbstractUtility.showView(CdmDataSourceViewPart.ID);
- return null;
- }
- }
-
- /**
- * Initialize the with the last edited datasource
- */
- public static void connect() {
-
- ICdmSource cdmSource;
- try {
-
- cdmSource = CdmDataSourceRepository.getCurrentCdmSource();
- connect(cdmSource);
- } catch (Exception e) {
- MessagingUtils.messageDialog("Connection to CDM Source Failed", CdmStore.class, "Could not connect to target CDM Source", e);
- }
-
-
- }
-
- /**
- * Initialize with a specific datasource
- *
- * @param datasource
- * a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
- */
- public static void connect(ICdmSource cdmSource) {
- connect(cdmSource, DEFAULT_DB_SCHEMA_VALIDATION,
- DEFAULT_APPLICATION_CONTEXT);
- }
-
- /**
- * Initialize and provide
- *
- * @param datasource
- * @param dbSchemaValidation
- * @param applicationContextBean
- */
- private static void connect(final ICdmSource cdmSource,
- final DbSchemaValidation dbSchemaValidation,
- final Resource applicationContextBean) {
- if(isActive()) {
- // before we connect we clear the entity caches and the sessions
- CdmRemoteCacheManager.removeEntityCaches();
- if(getCurrentSessionManager() != null) {
- getCurrentSessionManager().disposeAll();
- }
- }
- MessagingUtils.info("Connecting to datasource: " + cdmSource);
-
- job = new CdmStoreConnector(Display.getDefault(), cdmSource,
- dbSchemaValidation, applicationContextBean);
- job.setUser(true);
- job.setPriority(Job.BUILD);
- job.schedule();
-
- }
-
- public static boolean isConnecting() {
- return job != null && job.getState() == Job.RUNNING;
- }
-
- /**
- * Closes the current application context
- *
- * @param monitor
- * a {@link org.eclipse.core.runtime.IProgressMonitor} object.
- */
- public static void close(final IProgressMonitor monitor) {
- Display.getDefault().asyncExec(new Runnable() {
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Runnable#run()
- */
- @Override
- public void run() {
- getContextManager().notifyContextAboutToStop(monitor);
- if ((monitor == null || (!monitor.isCanceled()) && isActive())) {
- getContextManager().notifyContextStop(monitor);
- instance.close();
- }
- }
- });
- }
-
- private void close() {
- isConnected = false;
- cdmSource = null;
- CdmApplicationState.dispose();
- }
-
- static void setInstance(ICdmApplicationConfiguration applicationController,
- ICdmSource cdmSource) {
- instance = new CdmStore(applicationController, cdmSource);
- }
-
- private CdmStore(ICdmApplicationConfiguration applicationController,
- ICdmSource cdmSource) {
- CdmApplicationState.setCurrentAppConfig(applicationController);
- CdmApplicationState.setCurrentDataChangeService(new CdmUIDataChangeService());
- this.cdmSource = cdmSource;
- isConnected = true;
- }
-
- /**
- * All calls to the datastore require
- *
- * @return
- */
- private ICdmApplicationConfiguration getApplicationConfiguration() {
- try {
- return CdmApplicationState.getCurrentAppConfig();
- } catch (Exception e) {
- MessagingUtils.error(CdmStore.class, e);
- }
- return null;
- }
-
- /**
- * <p>
- * getCurrentApplicationController
- * </p>
- *
- * @return a
- * {@link eu.etaxonomy.cdm.remote.api.application.CdmApplicationController}
- * object.
- */
- public static ICdmApplicationConfiguration getCurrentApplicationConfiguration() {
- if (getDefault() != null) {
- return getDefault().getApplicationConfiguration();
- }
- return null;
- }
-
- /*
- * CONVERSATIONS
- */
-
- /**
- * Creates a new conversation, binds resources to the conversation and start
- * a transaction for this conversation.
- *
- * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
- * object.
- */
- public static ConversationHolder createConversation() {
- ConversationHolder conversation = getCurrentApplicationConfiguration()
- .NewConversation();
- try {
- conversation.startTransaction();
- }catch(Exception e){
- MessagingUtils.messageDialog("No database connection", CdmStore.class, "No database connection available", e);
- }
- return conversation;
- }
-
- //FIXME:Remoting should be removed after moving completely to remoting
- private MockCdmEntitySessionManager mockCdmEntitySessionManager;
-
- private ICdmEntitySessionManager getSessionManager() {
- //FIXME:Remoting we should only have CdmApplicationRemoteConfiguration after move to remoting
- // bad hack which should be finally removed
- if(getCurrentApplicationConfiguration() instanceof CdmApplicationRemoteController) {
- return ((CdmApplicationRemoteController)getCurrentApplicationConfiguration()).getCdmEntitySessionManager();
- } else {
- if(mockCdmEntitySessionManager == null) {
- mockCdmEntitySessionManager = new MockCdmEntitySessionManager();
- }
- return mockCdmEntitySessionManager;
- }
- }
-
- public static ICdmEntitySessionManager getCurrentSessionManager() {
- if (getDefault() != null) {
- return getDefault().getSessionManager();
- }
- return null;
-
- }
-
- /**
- * Generic method that will scan the getters of {@link ICdmApplicationConfiguration} for the given service
- * interface. If a matching getter is found the according service implementation is returned by
- * invoking the getter otherwise the method returns <code>null</code>.
- *
- * @param <T>
- * @param serviceClass
- * @return the configured implementation of <code>serviceClass</code> or <code>null</code>
- */
- public static <T extends IService> T getService(Class<T> serviceClass) {
- T service = null;
- try {
- service = CdmApplicationState.getService(serviceClass);
- } catch (CdmApplicationException cae) {
- MessagingUtils.error(CdmStore.class, cae);
- }
-
- return service;
- }
-
- /**
- * @see #getService(Class)
- * As ICommonService is not extending IService we need a specific request here
- */
- public static ICommonService getCommonService() {
- return CdmApplicationState.getCommonService();
-
- }
-
- /**
- * <p>
- * getAuthenticationManager
- * </p>
- *
- * @return a
- * {@link org.springframework.security.authentication.ProviderManager}
- * object.
- */
- public static AuthenticationManager getAuthenticationManager() {
- return getCurrentApplicationConfiguration().getAuthenticationManager();
- }
-
- /**
- * <p>
- * getAuthenticationManager
- * </p>
- *
- * @return a
- * {@link ICdmPermissionEvaluator} object.
- */
- public static ICdmPermissionEvaluator getPermissionEvaluator() {
- return getCurrentApplicationConfiguration().getPermissionEvaluator();
- }
-
- /**
- * <p>
- * getGeoService
- * </p>
- *
- * @return a {@link eu.etaxonomy.cdm.ext.geo.IEditGeoService} object.
- */
- public static IEditGeoService getGeoService() {
- return (IEditGeoService) getCurrentApplicationConfiguration().getBean(
- "editGeoService");
- }
-
- /*
- * SECURITY RELATED CONVENIENCE METHODS
- */
-
- /**
- * @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, java.lang.Object, java.lang.Object)
+ private static EditorManager editorManager = new EditorManager();
+
+ private static UseObjectStore useObjectInitializer = new UseObjectStore();
+
+ private static CdmStoreConnector job;
+
+ private Language language;
+
+ private ICdmSource cdmSource;
+
+ private boolean isConnected;
+
+
+
+ /**
+ * <p>
+ * getDefault
+ * </p>
+ *
+ * @return a {@link eu.etaxonomy.taxeditor.store.CdmStore} object.
+ */
+ protected static CdmStore getDefault() {
+ if (instance != null && instance.isConnected) {
+ return instance;
+ } else{// if (instance == null || !instance.isConnected) {
+
+ MessagingUtils.noDataSourceWarningDialog(instance);
+
+ AbstractUtility.showView(CdmDataSourceViewPart.ID);
+ return null;
+ }
+ }
+
+ /**
+ * Initialize the with the last edited datasource
+ */
+ public static void connect() {
+
+ ICdmSource cdmSource;
+ try {
+
+ cdmSource = CdmDataSourceRepository.getCurrentCdmSource();
+ connect(cdmSource);
+ } catch (Exception e) {
+ MessagingUtils.messageDialog("Connection to CDM Source Failed", CdmStore.class, "Could not connect to target CDM Source", e);
+ }
+
+
+ }
+
+ /**
+ * Initialize with a specific datasource
+ *
+ * @param datasource
+ * a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
+ */
+ public static void connect(ICdmSource cdmSource) {
+ connect(cdmSource, DEFAULT_DB_SCHEMA_VALIDATION,
+ DEFAULT_APPLICATION_CONTEXT);
+ }
+
+ public static void connect(ICdmSource cdmSource, RemotingLoginDialog loginDialog) {
+ connect(cdmSource,
+ DEFAULT_DB_SCHEMA_VALIDATION,
+ DEFAULT_APPLICATION_CONTEXT,
+ loginDialog);
+ }
+
+ /**
+ * Initialize and provide
+ *
+ * @param datasource
+ * @param dbSchemaValidation
+ * @param applicationContextBean
+ */
+ private static void connect(final ICdmSource cdmSource,
+ final DbSchemaValidation dbSchemaValidation,
+ final Resource applicationContextBean) {
+
+ MessagingUtils.info("Connecting to datasource: " + cdmSource);
+
+ job = new CdmStoreConnector(Display.getDefault(), cdmSource,
+ dbSchemaValidation, applicationContextBean);
+ job.setUser(true);
+ job.setPriority(Job.BUILD);
+ job.schedule();
+
+ }
+
+ private static void connect(final ICdmSource cdmSource,
+ final DbSchemaValidation dbSchemaValidation,
+ final Resource applicationContextBean,
+ RemotingLoginDialog loginDialog) {
+ if(isActive()) {
+ // before we connect we clear the entity caches and the sessions
+ CdmRemoteCacheManager.removeEntityCaches();
+ if(getCurrentSessionManager() != null) {
+ getCurrentSessionManager().disposeAll();
+ }
+ }
+ MessagingUtils.info("Connecting to datasource: " + cdmSource);
+ job = new CdmStoreConnector(Display.getDefault(),
+ cdmSource,
+ dbSchemaValidation,
+ applicationContextBean);
+ job.start(loginDialog);
+ }
+
+ public static boolean isConnecting() {
+ return job != null && job.getState() == Job.RUNNING;
+ }
+
+ /**
+ * Closes the current application context
+ *
+ * @param monitor
+ * a {@link org.eclipse.core.runtime.IProgressMonitor} object.
+ */
+ public static void close(final IProgressMonitor monitor) {
+ Display.getDefault().asyncExec(new Runnable() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ @Override
+ public void run() {
+ getContextManager().notifyContextAboutToStop(monitor);
+ if ((monitor == null || (!monitor.isCanceled()) && isActive())) {
+ getContextManager().notifyContextStop(monitor);
+ instance.close();
+ }
+ }
+ });
+ }
+
+ public static void close(IProgressMonitor monitor, boolean async) {
+ if(async) {
+ close(monitor);
+ } else {
+ getContextManager().notifyContextAboutToStop(monitor);
+ if ((monitor == null || (!monitor.isCanceled()) && isActive())) {
+ getContextManager().notifyContextStop(monitor);
+ instance.close();
+ }
+ }
+
+ }
+ private void close() {
+ isConnected = false;
+ cdmSource = null;
+ CdmApplicationState.dispose();
+ }
+
+ static void setInstance(ICdmApplicationConfiguration applicationController,
+ ICdmSource cdmSource) {
+ instance = new CdmStore(applicationController, cdmSource);
+ }
+
+ private CdmStore(ICdmApplicationConfiguration applicationController,
+ ICdmSource cdmSource) {
+ CdmApplicationState.setCurrentAppConfig(applicationController);
+ CdmApplicationState.setCurrentDataChangeService(new CdmUIDataChangeService());
+ this.cdmSource = cdmSource;
+ isConnected = true;
+ }
+
+ /**
+ * All calls to the datastore require
+ *
+ * @return
+ */
+ private ICdmApplicationConfiguration getApplicationConfiguration() {
+ try {
+ return CdmApplicationState.getCurrentAppConfig();
+ } catch (Exception e) {
+ MessagingUtils.error(CdmStore.class, e);
+ }
+ return null;
+ }
+
+ /**
+ * <p>
+ * getCurrentApplicationController
+ * </p>
+ *
+ * @return a
+ * {@link eu.etaxonomy.cdm.remote.api.application.CdmApplicationController}
+ * object.
+ */
+ public static ICdmApplicationConfiguration getCurrentApplicationConfiguration() {
+ if (getDefault() != null) {
+ return getDefault().getApplicationConfiguration();
+ }
+ return null;
+ }
+
+ /*
+ * CONVERSATIONS
+ */
+
+ /**
+ * Creates a new conversation, binds resources to the conversation and start
+ * a transaction for this conversation.
*
- * @param targetDomainObject
- * @param permission
- * @return
- */
- public static boolean currentAuthentiationHasPermission(CdmBase targetDomainObject, EnumSet<CRUD> permission){
- //TODO use getCurrentApplicationConfiguration().currentAuthentiationHasPermission(CdmBase targetDomainObject, Operation permission) instead
- SecurityContext context = SecurityContextHolder.getContext();
- PermissionEvaluator pe = getPermissionEvaluator();
- boolean hasPermission = false;
- try {
+ * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
+ * object.
+ */
+ public static ConversationHolder createConversation() {
+ ConversationHolder conversation = getCurrentApplicationConfiguration()
+ .NewConversation();
+ try {
+ conversation.startTransaction();
+ }catch(Exception e){
+ MessagingUtils.messageDialog("No database connection", CdmStore.class, "No database connection available", e);
+ }
+ return conversation;
+ }
+
+ //FIXME:Remoting should be removed after moving completely to remoting
+ private MockCdmEntitySessionManager mockCdmEntitySessionManager;
+
+ private ICdmEntitySessionManager getSessionManager() {
+ //FIXME:Remoting we should only have CdmApplicationRemoteConfiguration after move to remoting
+ // bad hack which should be finally removed
+ if(getCurrentApplicationConfiguration() instanceof CdmApplicationRemoteController) {
+ return ((CdmApplicationRemoteController)getCurrentApplicationConfiguration()).getCdmEntitySessionManager();
+ } else {
+ if(mockCdmEntitySessionManager == null) {
+ mockCdmEntitySessionManager = new MockCdmEntitySessionManager();
+ }
+ return mockCdmEntitySessionManager;
+ }
+ }
+
+ public static ICdmEntitySessionManager getCurrentSessionManager() {
+ if (getDefault() != null) {
+ return getDefault().getSessionManager();
+ }
+ return null;
+
+ }
+
+ /**
+ * Generic method that will scan the getters of {@link ICdmApplicationConfiguration} for the given service
+ * interface. If a matching getter is found the according service implementation is returned by
+ * invoking the getter otherwise the method returns <code>null</code>.
+ *
+ * @param <T>
+ * @param serviceClass
+ * @return the configured implementation of <code>serviceClass</code> or <code>null</code>
+ */
+ public static <T extends IService> T getService(Class<T> serviceClass) {
+ T service = null;
+ try {
+ service = CdmApplicationState.getService(serviceClass);
+ } catch (CdmApplicationException cae) {
+ MessagingUtils.error(CdmStore.class, cae);
+ }
+
+ return service;
+ }
+
+ /**
+ * @see #getService(Class)
+ * As ICommonService is not extending IService we need a specific request here
+ */
+ public static ICommonService getCommonService() {
+ return CdmApplicationState.getCommonService();
+
+ }
+
+ /**
+ * <p>
+ * getAuthenticationManager
+ * </p>
+ *
+ * @return a
+ * {@link org.springframework.security.authentication.ProviderManager}
+ * object.
+ */
+ public static AuthenticationManager getAuthenticationManager() {
+ return getCurrentApplicationConfiguration().getAuthenticationManager();
+ }
+
+ /**
+ * <p>
+ * getAuthenticationManager
+ * </p>
+ *
+ * @return a
+ * {@link ICdmPermissionEvaluator} object.
+ */
+ public static ICdmPermissionEvaluator getPermissionEvaluator() {
+ return getCurrentApplicationConfiguration().getPermissionEvaluator();
+ }
+
+ /**
+ * <p>
+ * getGeoService
+ * </p>
+ *
+ * @return a {@link eu.etaxonomy.cdm.ext.geo.IEditGeoService} object.
+ */
+ public static IEditGeoService getGeoService() {
+ return (IEditGeoService) getCurrentApplicationConfiguration().getBean(
+ "editGeoService");
+ }
+
+ /*
+ * SECURITY RELATED CONVENIENCE METHODS
+ */
+
+ /**
+ * @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, java.lang.Object, java.lang.Object)
+ *
+ * @param targetDomainObject
+ * @param permission
+ * @return
+ */
+ public static boolean currentAuthentiationHasPermission(CdmBase targetDomainObject, EnumSet<CRUD> permission){
+ //TODO use getCurrentApplicationConfiguration().currentAuthentiationHasPermission(CdmBase targetDomainObject, Operation permission) instead
+ SecurityContext context = SecurityContextHolder.getContext();
+ PermissionEvaluator pe = getPermissionEvaluator();
+ boolean hasPermission = false;
+ try {
hasPermission = getPermissionEvaluator().hasPermission(context.getAuthentication(), targetDomainObject,
permission);
} catch (org.springframework.security.access.AccessDeniedException e) {
/* IGNORE */
}
return hasPermission;
- }
+ }
- /**
- * @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, java.lang.Object, java.lang.Object)
+ /**
+ * @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, java.lang.Object, java.lang.Object)
*
- * @param targetDomainObject
- * @param permission
- * @return
- */
- public static boolean currentAuthentiationHasPermission(Class<? extends CdmBase> targetType, EnumSet<CRUD> permission){
- boolean hasPermission = false;
+ * @param targetDomainObject
+ * @param permission
+ * @return
+ */
+ public static boolean currentAuthentiationHasPermission(Class<? extends CdmBase> targetType, EnumSet<CRUD> permission){
+ boolean hasPermission = false;
try {
hasPermission = getPermissionEvaluator().hasPermission(getCurrentAuthentiation(), null, targetType.getName(), permission);
} catch (org.springframework.security.access.AccessDeniedException e) {
/* IGNORE */
}
return hasPermission;
- }
+ }
- public static boolean currentAuthentiationHasOneOfRoles(Role ... roles){
- boolean hasPermission = false;
+ public static boolean currentAuthentiationHasOneOfRoles(Role ... roles){
+ boolean hasPermission = false;
try {
hasPermission = getPermissionEvaluator().hasOneOfRoles(getCurrentAuthentiation(), roles);
} catch (org.springframework.security.access.AccessDeniedException e) {
/* IGNORE */
}
return hasPermission;
- }
-
- public static Authentication getCurrentAuthentiation() {
- SecurityContext context = SecurityContextHolder.getContext();
- return context.getAuthentication();
- }
-
- /*
- * LANGUAGE
- */
-
- /**
- * Provides access to the global default language set in the application preferences.
- *
- * @return a {@link eu.etaxonomy.cdm.model.common.Language} object.
- */
- public static Language getDefaultLanguage() {
- if (getDefault().getLanguage() == null) {
- getDefault().setLanguage(PreferencesUtil.getGlobalLanguage());
- }
- return getDefault().getLanguage();
- }
-
- /**
- * <p>
- * setDefaultLanguage
- * </p>
- *
- * @param language
- * a {@link eu.etaxonomy.cdm.model.common.Language} object.
- */
- public static void setDefaultLanguage(Language language) {
- getDefault().setLanguage(language);
- }
-
- /**
- * @return the language
- */
- private Language getLanguage() {
- return language;
- }
-
- /**
- * @param language
- * the language to set
- */
- private void setLanguage(Language language) {
- this.language = language;
- }
-
- /*
- * LOGIN
- */
-
- /**
- * <p>
- * Getter for the field <code>loginManager</code>.
- * </p>
- *
- * @return a {@link eu.etaxonomy.taxeditor.store.LoginManager} object.
- */
- public static LoginManager getLoginManager() {
- return loginManager;
- }
-
- /**
- * <p>
- * Getter for the field <code>contextManager</code>.
- * </p>
- *
- * @return a {@link eu.etaxonomy.taxeditor.store.ContextManager} object.
- */
- public static ContextManager getContextManager() {
- return contextManager;
- }
-
- public static TermManager getTermManager() {
- return termManager;
- }
-
- public static SearchManager getSearchManager() {
- return searchManager;
- }
-
- public static EditorManager getEditorManager() {
- return editorManager;
- }
-
- /*
- * IMPORT/EXPORT FACTORIES
- */
-
- /**
- * <p>
- * Getter for the field <code>importHandler</code>.
- * </p>
- *
- * @return a {@link eu.etaxonomy.taxeditor.io.ImportManager} object.
- */
- public static ImportManager getImportManager() {
- return ImportManager.NewInstance(getCurrentApplicationConfiguration());
- }
-
- /**
- * <p>
- * Getter for the field <code>exportHandler</code>.
- * </p>
- *
- * @return a {@link eu.etaxonomy.taxeditor.io.ExportManager} object.
- */
- public static ExportManager getExportManager() {
- return ExportManager.NewInstance(getCurrentApplicationConfiguration());
- }
-
- /**
- * Whether this CdmStore is currently connected to a datasource
- *
- * @return a boolean.
- */
- public static boolean isActive() {
- return instance != null && instance.isConnected;
- }
-
- public static ICdmSource getActiveCdmSource() {
- if (isActive()) {
- return instance.getCdmSource();
- }
- return null;
- }
-
- /**
- * <p>
- * getDataSource
- * </p>
- *
- * @return a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
- * @deprecated currently retained for backward compatibility - use {@link getActiveCdmSource()} instead
- */
-// public static ICdmDataSource getDataSource() {
-// if (isActive()) {
-// return (ICdmDataSource)instance.getCdmSource();
-// }
-// return null;
-// }
-
- /**
- * @return
- */
- private ICdmSource getCdmSource() {
- return cdmSource;
- }
+ }
+
+ public static Authentication getCurrentAuthentiation() {
+ SecurityContext context = SecurityContextHolder.getContext();
+ return context.getAuthentication();
+ }
+
+ /*
+ * LANGUAGE
+ */
+
+ /**
+ * Provides access to the global default language set in the application preferences.
+ *
+ * @return a {@link eu.etaxonomy.cdm.model.common.Language} object.
+ */
+ public static Language getDefaultLanguage() {
+ if (getDefault().getLanguage() == null) {
+ getDefault().setLanguage(PreferencesUtil.getGlobalLanguage());
+ }
+ return getDefault().getLanguage();
+ }
+
+ /**
+ * <p>
+ * setDefaultLanguage
+ * </p>
+ *
+ * @param language
+ * a {@link eu.etaxonomy.cdm.model.common.Language} object.
+ */
+ public static void setDefaultLanguage(Language language) {
+ getDefault().setLanguage(language);
+ }
+
+ /**
+ * @return the language
+ */
+ private Language getLanguage() {
+ return language;
+ }
+
+ /**
+ * @param language
+ * the language to set
+ */
+ private void setLanguage(Language language) {
+ this.language = language;
+ }
+
+ /*
+ * LOGIN
+ */
+
+ /**
+ * <p>
+ * Getter for the field <code>loginManager</code>.
+ * </p>
+ *
+ * @return a {@link eu.etaxonomy.taxeditor.store.LoginManager} object.
+ */
+ public static LoginManager getLoginManager() {
+ return loginManager;
+ }
+
+ /**
+ * <p>
+ * Getter for the field <code>contextManager</code>.
+ * </p>
+ *
+ * @return a {@link eu.etaxonomy.taxeditor.store.ContextManager} object.
+ */
+ public static ContextManager getContextManager() {
+ return contextManager;
+ }
+
+ public static TermManager getTermManager() {
+ return termManager;
+ }
+
+ public static SearchManager getSearchManager() {
+ return searchManager;
+ }
+
+ public static EditorManager getEditorManager() {
+ return editorManager;
+ }
+
+ /*
+ * IMPORT/EXPORT FACTORIES
+ */
+
+ /**
+ * <p>
+ * Getter for the field <code>importHandler</code>.
+ * </p>
+ *
+ * @return a {@link eu.etaxonomy.taxeditor.io.ImportManager} object.
+ */
+ public static ImportManager getImportManager() {
+ return ImportManager.NewInstance(getCurrentApplicationConfiguration());
+ }
+
+ /**
+ * <p>
+ * Getter for the field <code>exportHandler</code>.
+ * </p>
+ *
+ * @return a {@link eu.etaxonomy.taxeditor.io.ExportManager} object.
+ */
+ public static ExportManager getExportManager() {
+ return ExportManager.NewInstance(getCurrentApplicationConfiguration());
+ }
+
+ /**
+ * Whether this CdmStore is currently connected to a datasource
+ *
+ * @return a boolean.
+ */
+ public static boolean isActive() {
+ return instance != null && instance.isConnected;
+ }
+
+ public static ICdmSource getActiveCdmSource() {
+ if (isActive()) {
+ return instance.getCdmSource();
+ }
+ return null;
+ }
+
+ /**
+ * <p>
+ * getDataSource
+ * </p>
+ *
+ * @return a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
+ * @deprecated currently retained for backward compatibility - use {@link getActiveCdmSource()} instead
+ */
+ // public static ICdmDataSource getDataSource() {
+ // if (isActive()) {
+ // return (ICdmDataSource)instance.getCdmSource();
+ // }
+ // return null;
+ // }
+
+ /**
+ * @return
+ */
+ private ICdmSource getCdmSource() {
+ return cdmSource;
+ }
}
package eu.etaxonomy.taxeditor.store;
+import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.util.concurrent.CancellationException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.widgets.Display;
import org.springframework.core.io.Resource;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
import eu.etaxonomy.taxeditor.ui.dialog.LoginDialog;
+import eu.etaxonomy.taxeditor.ui.dialog.RemotingLoginDialog;
import eu.etaxonomy.taxeditor.view.datasource.CdmDataSourceViewPart;
+
/**
* @author n.hoffmann
* @created Dec 8, 2010
* @version 1.0
*/
class CdmStoreConnector extends Job {
- private final Display display;
- private final ICdmSource cdmSource;
- private DbSchemaValidation dbSchemaValidation;
- private final Resource applicationContextBean;
-
- /**
- * @param datasource
- * @param dbSchemaValidation
- * @param applicationContextBean
- */
- public CdmStoreConnector(Display display, ICdmSource cdmSource,
- DbSchemaValidation dbSchemaValidation,
- Resource applicationContextBean) {
- super("Connecting to datasource: " + cdmSource);
- this.display = display;
- this.cdmSource = cdmSource;
- this.dbSchemaValidation = dbSchemaValidation;
- this.applicationContextBean = applicationContextBean;
- }
-
- @Override
- public IStatus run(final IProgressMonitor monitor) {
-
- monitor.beginTask(getConnectionMessage(), 10);
-
- // check if database is up and running
- checkDatabaseReachable(monitor);
-
- if (!monitor.isCanceled()) {
- // check if the datasource actually holds data
- checkIsNonEmptyCdmDatabase(monitor);
- }
-
- if (dbSchemaValidation != DbSchemaValidation.CREATE
- && !monitor.isCanceled()) {
- // if we do not create the datasource, we want to check if the
- // datasource is compatible with this editor
- checkDbSchemaVersionCompatibility(monitor);
- }
-
- // we are done with our low level checking and will free resources now
- cdmSource.closeOpenConnections();
-
- if (!monitor.isCanceled()) {
- CdmStore.close(monitor);
- }
-
- ICdmApplicationConfiguration applicationController = null;
-
- if (!monitor.isCanceled()) {
- CdmProgressMonitorAdapter subprogressMonitor = CdmProgressMonitorAdapter
- .CreateSubMonitor(monitor, 7);
- // This is where we instantiate the application controller
- int oldPriority = Thread.currentThread().getPriority();
- try {
- Thread.currentThread().setPriority(10);
- applicationController = getApplicationController(cdmSource,subprogressMonitor);
- } catch (Exception e) {
- if(! causeIsCancelationExceptionRecursive(e)){
- return new Status(IStatus.ERROR, "Could not connect to CDM Store", "An error occurred while trying to connect to datasource: " + cdmSource.getName(), e);
- }
- } finally {
- monitor.done();
- Thread.currentThread().setPriority(oldPriority);
- }
- }
-
-
-
- if (!monitor.isCanceled()) {
- CdmStore.setInstance(applicationController, cdmSource);
-
- display.asyncExec(new Runnable() {
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Runnable#run()
- */
- @Override
- public void run() {
- authenticate();
-
- startContext();
- }
- });
-
- MessagingUtils.info("Application context initialized.");
- return Status.OK_STATUS;
- } else {
- // Show datasource view if not shown yet
- display.asyncExec(new Runnable() {
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Runnable#run()
- */
- @Override
- public void run() {
- StoreUtil.showView(CdmDataSourceViewPart.ID);
- }
- });
- return Status.CANCEL_STATUS;
- }
-
- }
-
- private ICdmApplicationConfiguration getApplicationController(ICdmSource cdmSource, CdmProgressMonitorAdapter subprogressMonitor) {
- if(cdmSource instanceof ICdmDataSource) {
- return CdmApplicationController.NewInstance(applicationContextBean,
- (ICdmDataSource)cdmSource,
- dbSchemaValidation,
- false,
- subprogressMonitor);
- } else if(cdmSource instanceof ICdmRemoteSource) {
- return CdmApplicationRemoteController.NewInstance((ICdmRemoteSource)cdmSource,
- subprogressMonitor,
- null);
- } else {
- throw new UnsupportedOperationException("Cannot create application controller for " + cdmSource.getName());
- }
- }
- private void authenticate() {
- LoginDialog loginDialog = new LoginDialog(StoreUtil.getShell());
- loginDialog.open();
- }
-
- private void startContext() {
- CdmStore.getContextManager().notifyContextStart();
- }
-
- /**
- * @return
- */
- private String getConnectionMessage() {
- return cdmSource.getConnectionMessage();
- }
-
- /**
- * @return
- * @throws SQLException
- */
- private void checkDbSchemaVersionCompatibility(IProgressMonitor monitor) {
- monitor.subTask("Checking if datasource is compatible with this editor.");
- String dbSchemaVersion;
-
- String message = null;
- try {
- dbSchemaVersion = cdmSource.getDbSchemaVersion();
- // we assume that empty dbSchemaVersion means an empty database and
- // skip version checking
-
- if(dbSchemaVersion != null) {
- int compareVersion = CdmMetaData.compareVersion(dbSchemaVersion, CdmMetaData.getDbSchemaVersion(), 3, null);
- // if the datasource version is greater than the taxeditor compatible version then the taxeditor needs to
- // be updated else the datasource needs to be updated
- if(compareVersion > 0) {
- message = "Please update the Taxonomic Editor (Help->Check for Updates) or choose a compatible datasource";
- } else if (compareVersion < 0) {
- message = "Please update the chosen datasource or choose a new data source to connect to in the Datasource View.";
- }
- }
- monitor.worked(1);
- } catch (CdmSourceException e) {
- //
- }
-
- if (message != null) {
- // Show an error message
- MessagingUtils
- .messageDialog(
- "Datasource Compatibility Check failed",
- this,
- "The database schema for the chosen "
- + "datasource '"
- + cdmSource
- + "' \n is not compatible for this version of the taxonomic editor. \n\n"
- + message,
- null);
-
- monitor.setCanceled(true);
- }
-
- }
-
- private void checkIsNonEmptyCdmDatabase(IProgressMonitor monitor) {
- monitor.subTask("Checking if datasource is a non empty CDM database.");
- boolean isDbEmpty = false;
- try {
- isDbEmpty = cdmSource.isDbEmpty();
- } catch (CdmSourceException e) {
- isDbEmpty = true;
- }
- if(isDbEmpty) {
- dbSchemaValidation = DbSchemaValidation.CREATE;
- }
- }
-
- private boolean causeIsCancelationExceptionRecursive(Throwable throwable){
- if(throwable == null){
- return false;
- }else if(throwable instanceof CancellationException){
- return true;
- }else{
- return causeIsCancelationExceptionRecursive(throwable.getCause());
- }
- }
-
- private void checkDatabaseReachable(IProgressMonitor monitor) {
- try {
- monitor.subTask("Checking if datasource is reachable.");
- cdmSource.checkConnection();
- monitor.worked(1);
- } catch (CdmSourceException e) {
- MessagingUtils.messageDialog("Could not connect to chosen datasource",
- this, "Reason: " + e.getMessage(), e);
- monitor.setCanceled(true);
- }
- }
+ private final Display display;
+ private final ICdmSource cdmSource;
+ private DbSchemaValidation dbSchemaValidation;
+ private final Resource applicationContextBean;
+
+
+ /**
+ * @param datasource
+ * @param dbSchemaValidation
+ * @param applicationContextBean
+ */
+ public CdmStoreConnector(Display display,
+ ICdmSource cdmSource,
+ DbSchemaValidation dbSchemaValidation,
+ Resource applicationContextBean) {
+ super("Connecting to datasource: " + cdmSource);
+ this.display = display;
+ this.cdmSource = cdmSource;
+ this.dbSchemaValidation = dbSchemaValidation;
+ this.applicationContextBean = applicationContextBean;
+ }
+
+
+
+ @Override
+ public IStatus run(final IProgressMonitor monitor) {
+
+ monitor.beginTask(getConnectionMessage(), 10);
+
+ // check if database is up and running
+ checkDatabaseReachable(monitor);
+
+ if (!monitor.isCanceled()) {
+ // check if the datasource actually holds data
+ checkIsNonEmptyCdmDatabase(monitor);
+ }
+
+ if (dbSchemaValidation != DbSchemaValidation.CREATE
+ && !monitor.isCanceled()) {
+ // if we do not create the datasource, we want to check if the
+ // datasource is compatible with this editor
+ checkDbSchemaVersionCompatibility(monitor);
+ }
+
+ // we are done with our low level checking and will free resources now
+ cdmSource.closeOpenConnections();
+
+ if (!monitor.isCanceled()) {
+ CdmStore.close(monitor);
+ }
+
+ ICdmApplicationConfiguration applicationController = null;
+
+ if (!monitor.isCanceled()) {
+ CdmProgressMonitorAdapter subprogressMonitor = CdmProgressMonitorAdapter
+ .CreateSubMonitor(monitor, 7);
+ // This is where we instantiate the application controller
+ int oldPriority = Thread.currentThread().getPriority();
+ try {
+ Thread.currentThread().setPriority(10);
+ applicationController = getApplicationController(cdmSource,subprogressMonitor);
+ } catch (Exception e) {
+ if(! causeIsCancelationExceptionRecursive(e)){
+ return new Status(IStatus.ERROR, "Could not connect to CDM Store", "An error occurred while trying to connect to datasource: " + cdmSource.getName(), e);
+ }
+ } finally {
+ monitor.done();
+ Thread.currentThread().setPriority(oldPriority);
+ }
+ }
+
+
+
+ if (!monitor.isCanceled()) {
+ CdmStore.setInstance(applicationController, cdmSource);
+
+ display.asyncExec(new Runnable() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ @Override
+ public void run() {
+ authenticate();
+
+ startContext();
+ }
+ });
+
+ MessagingUtils.info("Application context initialized.");
+ return Status.OK_STATUS;
+ } else {
+ // Show datasource view if not shown yet
+ display.asyncExec(new Runnable() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ @Override
+ public void run() {
+ StoreUtil.showView(CdmDataSourceViewPart.ID);
+ }
+ });
+ return Status.CANCEL_STATUS;
+ }
+
+ }
+
+ public void start(final RemotingLoginDialog loginDialog) {
+ // hide login dialog and start connection dialog
+ loginDialog.setMessage(null);
+ loginDialog.hide(true);
+
+
+ ProgressMonitorDialog dialog = new ProgressMonitorDialog(StoreUtil.getShell());
+
+ try {
+ dialog.run(true, true, new IRunnableWithProgress() {
+ @Override
+ public void run(final IProgressMonitor monitor) {
+ try {
+ monitor.beginTask(getConnectionMessage(), 7);
+
+ // check if database is up and running
+ checkDatabaseReachable(monitor);
+
+ // check if the datasource actually holds data
+ checkIsNonEmptyCdmDatabase(monitor);
+
+ if (dbSchemaValidation != DbSchemaValidation.CREATE) {
+ // if we do not create the datasource, we want to check if the
+ // datasource is compatible with this editor
+ checkDbSchemaVersionCompatibility(monitor);
+ }
+
+ // we are done with our low level checking and will free resources now
+ cdmSource.closeOpenConnections();
+
+ display.syncExec(new Runnable() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ @Override
+ public void run() {
+ // close the current context
+ CdmStore.close(monitor, false);
+ }
+ });
+
+ ICdmApplicationConfiguration applicationController = null;
+
+ if (!monitor.isCanceled()) {
+ CdmProgressMonitorAdapter subprogressMonitor = CdmProgressMonitorAdapter
+ .CreateSubMonitor(monitor, 3);
+ // genrerate new application controller
+ applicationController = getApplicationController(cdmSource,subprogressMonitor);
+ }
+
+
+ if (!monitor.isCanceled()) {
+ CdmStore.setInstance(applicationController, cdmSource);
+ monitor.subTask("Authenticating user and starting editor context...");
+ display.syncExec(new Runnable() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ @Override
+ public void run() {
+
+ try {
+ // create new security context
+ CdmStore.getLoginManager().doAuthenticate(loginDialog.getUsername(), loginDialog.getPassword());
+ loginDialog.dispose();
+ // start editor context
+ CdmStore.getContextManager().notifyContextStartWithoutDialog(monitor);
+
+ } catch(CdmAuthenticationException cae) {
+ loginDialog.hide(false);
+ loginDialog.setMessage(cae.getMessage());
+ }
+
+ }
+ });
+ } else {
+ throw new RuntimeException("Login cancelled");
+ }
+ } finally {
+ monitor.done();
+ }
+ }
+ });
+ } catch (InvocationTargetException e) {
+ loginDialog.hide(false);
+ loginDialog.setMessage(e.getMessage());
+ } catch (InterruptedException e) {
+ loginDialog.hide(false);
+ loginDialog.setMessage(e.getMessage());
+ }
+ }
+
+
+ private ICdmApplicationConfiguration getApplicationController(ICdmSource cdmSource, CdmProgressMonitorAdapter subprogressMonitor) {
+ if(cdmSource instanceof ICdmDataSource) {
+ return CdmApplicationController.NewInstance(applicationContextBean,
+ (ICdmDataSource)cdmSource,
+ dbSchemaValidation,
+ false,
+ subprogressMonitor);
+ } else if(cdmSource instanceof ICdmRemoteSource) {
+ return CdmApplicationRemoteController.NewInstance((ICdmRemoteSource)cdmSource,
+ subprogressMonitor,
+ null);
+ } else {
+ throw new UnsupportedOperationException("Cannot create application controller for " + cdmSource.getName());
+ }
+ }
+
+ private void authenticate() {
+ LoginDialog saloginDialog = new LoginDialog(StoreUtil.getShell());
+ saloginDialog.open();
+ }
+
+ private void startContext() {
+ CdmStore.getContextManager().notifyContextStart();
+ }
+
+ /**
+ * @return
+ */
+ private String getConnectionMessage() {
+ return cdmSource.getConnectionMessage();
+ }
+
+ /**
+ * @return
+ * @throws SQLException
+ */
+ private void checkDbSchemaVersionCompatibility(IProgressMonitor monitor) {
+ monitor.subTask("Checking if datasource is compatible with this editor.");
+ String dbSchemaVersion;
+
+ String message = null;
+ try {
+ dbSchemaVersion = cdmSource.getDbSchemaVersion();
+ // we assume that empty dbSchemaVersion means an empty database and
+ // skip version checking
+
+ if(dbSchemaVersion != null) {
+ int compareVersion = CdmMetaData.compareVersion(dbSchemaVersion, CdmMetaData.getDbSchemaVersion(), 3, null);
+ // if the datasource version is greater than the taxeditor compatible version then the taxeditor needs to
+ // be updated else the datasource needs to be updated
+ if(compareVersion > 0) {
+ message = "Please update the Taxonomic Editor (Help->Check for Updates) or choose a compatible datasource";
+ } else if (compareVersion < 0) {
+ message = "Please update the chosen datasource or choose a new data source to connect to in the Datasource View.";
+ }
+ }
+ monitor.worked(1);
+ } catch (CdmSourceException e) {
+ //
+ }
+
+ if (message != null) {
+ // Show an error message
+ MessagingUtils
+ .messageDialog(
+ "Datasource Compatibility Check failed",
+ this,
+ "The database schema for the chosen "
+ + "datasource '"
+ + cdmSource
+ + "' \n is not compatible for this version of the taxonomic editor. \n\n"
+ + message,
+ null);
+
+ monitor.setCanceled(true);
+ }
+
+ }
+
+ private void checkIsNonEmptyCdmDatabase(IProgressMonitor monitor) {
+ monitor.subTask("Checking if datasource is a non empty CDM database.");
+ boolean isDbEmpty = false;
+ try {
+ isDbEmpty = cdmSource.isDbEmpty();
+ } catch (CdmSourceException e) {
+ isDbEmpty = true;
+ }
+ if(isDbEmpty) {
+ dbSchemaValidation = DbSchemaValidation.CREATE;
+ }
+ }
+
+ private boolean causeIsCancelationExceptionRecursive(Throwable throwable){
+ if(throwable == null){
+ return false;
+ }else if(throwable instanceof CancellationException){
+ return true;
+ }else{
+ return causeIsCancelationExceptionRecursive(throwable.getCause());
+ }
+ }
+
+ private void checkDatabaseReachable(IProgressMonitor monitor) {
+ try {
+ monitor.subTask("Checking if datasource is reachable.");
+ cdmSource.checkConnection();
+ monitor.worked(1);
+ } catch (CdmSourceException e) {
+ MessagingUtils.messageDialog("Could not connect to chosen datasource",
+ this, "Reason: " + e.getMessage(), e);
+ monitor.setCanceled(true);
+ }
+ }
+
+
}
// $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.
-*/
+ * 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.store;
*/
public class ContextManager implements IWorkbenchListener{
- private final ListenerList contextListeners = new ListenerList();
-
- private IMemento memento;
-
- /**
- * <p>Constructor for ContextManager.</p>
- */
- protected ContextManager() {
- if(Workbench.getInstance() != null) {
- PlatformUI.getWorkbench().addWorkbenchListener(this);
- }
- }
-
- /**
- * <p>addContextListener</p>
- *
- * @param listener a {@link eu.etaxonomy.taxeditor.model.IContextListener} object.
- */
- public void addContextListener(IContextListener listener){
- contextListeners.add(listener);
- }
-
- /**
- * <p>removeContextListener</p>
- *
- * @param listener a {@link eu.etaxonomy.taxeditor.model.IContextListener} object.
- */
- public void removeContextListener(IContextListener listener) {
- contextListeners.remove(listener);
- }
-
- /**
- * <p>notifyContextStart</p>
- */
- public void notifyContextStart() {
- MessagingUtils.info("Notifying context listeners, that the context has started.");
- ProgressMonitorDialog dialog = new ProgressMonitorDialog(StoreUtil.getShell());
-
- try {
- dialog.run(false, false, new IRunnableWithProgress() {
- /* (non-Javadoc)
- * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
- */
- @Override
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException, InterruptedException {
- monitor.beginTask("Starting context", contextListeners.size());
-
-
- readMemento();
-
- for(final Object listener : contextListeners.getListeners()){
- ((IContextListener) listener).contextStart(memento, monitor);
- monitor.worked(1);
- }
- monitor.done();
- }
- });
- } catch (InvocationTargetException e) {
- MessagingUtils.error(getClass(), e);
- } catch (InterruptedException e) {
- MessagingUtils.error(getClass(), e);
- }
- }
-
-
- /**
- *
- */
- public void notifyContextRefresh() {
- MessagingUtils.info("Notifying context listeners, that the context needs to be refreshed.");
- ProgressMonitorDialog dialog = new ProgressMonitorDialog(StoreUtil.getShell());
-
- try {
- dialog.run(false, false, new IRunnableWithProgress() {
- /* (non-Javadoc)
- * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
- */
- @Override
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException, InterruptedException {
- monitor.beginTask("Refreshing context", contextListeners.size());
-
- for(final Object listener : contextListeners.getListeners()){
- ((IContextListener) listener).contextRefresh(monitor);
- monitor.worked(1);
- }
- monitor.done();
- }
- });
- } catch (InvocationTargetException e) {
- MessagingUtils.error(getClass(), e);
- } catch (InterruptedException e) {
- MessagingUtils.error(getClass(), e);
- }
- }
-
- /**
- * <p>notifyContextAboutToStop</p>
- *
- * @param monitor a {@link org.eclipse.core.runtime.IProgressMonitor} object.
- */
- public void notifyContextAboutToStop(final IProgressMonitor monitor){
-
- IProgressMonitor subMonitor = StoreUtil.getSubProgressMonitor(monitor, 1);
-
- subMonitor.beginTask("Stoping context", contextListeners.size());
- // we are creating the memento here; even if the context is not stopped
- createMemento();
-
- for(final Object listener : contextListeners.getListeners()){
- ((IContextListener) listener).contextAboutToStop(memento, subMonitor);
- subMonitor.worked(1);
- }
-
- subMonitor.done();
- }
-
- /**
- * <p>notifyContextStop</p>
- *
- * @param monitor a {@link org.eclipse.core.runtime.IProgressMonitor} object.
- */
- public void notifyContextStop(IProgressMonitor monitor) {
-
- IProgressMonitor subMonitor = StoreUtil.getSubProgressMonitor(monitor, 1);
-
- subMonitor.beginTask("Stoping context", contextListeners.size());
- MessagingUtils.info("Notifying context listeners, that the context has stopped.");
-
- for(Object listener : contextListeners.getListeners()){
- ((IContextListener) listener).contextStop(memento, subMonitor);
- subMonitor.worked(1);
- }
-
- saveMemento();
- subMonitor.done();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.IWorkbenchListener#preShutdown(org.eclipse.ui.IWorkbench, boolean)
- */
- /** {@inheritDoc} */
- @Override
- public boolean preShutdown(IWorkbench workbench, boolean forced) {
-
- createMemento();
-
- IProgressMonitor monitor = null;
-
- for(Object listener : contextListeners.getListeners()){
- ((IContextListener) listener).workbenchShutdown(memento, monitor);
- }
-
- saveMemento();
-
- // return true in any case, otherwise the application will not stop
- return true;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.IWorkbenchListener#postShutdown(org.eclipse.ui.IWorkbench)
- */
- /** {@inheritDoc} */
- @Override
- public void postShutdown(IWorkbench workbench) {
-
-
- }
-
-
- private void readMemento(){
- try {
- memento = MementoHelper.readMementoFromFile(getStateFileForCurrentDatabase());
- } catch (FileNotFoundException e) {
- // no memento -> no previous state
- MessagingUtils.info("No state file for datasource");
- }
- }
-
- private void createMemento(){
-
- if (CdmStore.getActiveCdmSource() != null) {
-
- try {
- String name = CdmStore.getActiveCdmSource().getName();
- name = name.trim();
- name = name.replace(" ", "_");
- memento = XMLMemento.createWriteRoot(name);
-
- MessagingUtils.info("DataSource found. Memento created.");
- } catch (Exception e) {
- // The memento could not be created, but a not closable editor is avoided for this case.
- MessagingUtils.error(this.getClass(), "The memento could not be created", e);
- }
- } else {
- MessagingUtils.info("Not storing state data, because no DataSource present.");
- }
-
- }
-
- private boolean saveMemento(){
- return MementoHelper.saveMementoToFile(memento, getStateFileForCurrentDatabase()) != null;
- }
-
- /**
- * <p>getStateFileForCurrentDatabase</p>
- *
- * @return a {@link java.io.File} object.
- */
- protected File getStateFileForCurrentDatabase() {
- if(CdmStore.getActiveCdmSource() == null){
- return null;
- }
-
- IPath path = TaxeditorStorePlugin.getDefault().getStateLocation();
- if (path == null) {
- return null;
- }
- path = path.append("editor_state_" + CdmStore.getActiveCdmSource().getName() + ".xml");
- return path.toFile();
- }
+ private final ListenerList contextListeners = new ListenerList();
+
+ private IMemento memento;
+
+ /**
+ * <p>Constructor for ContextManager.</p>
+ */
+ protected ContextManager() {
+ if(Workbench.getInstance() != null) {
+ PlatformUI.getWorkbench().addWorkbenchListener(this);
+ }
+ }
+
+ /**
+ * <p>addContextListener</p>
+ *
+ * @param listener a {@link eu.etaxonomy.taxeditor.model.IContextListener} object.
+ */
+ public void addContextListener(IContextListener listener){
+ contextListeners.add(listener);
+ }
+
+ /**
+ * <p>removeContextListener</p>
+ *
+ * @param listener a {@link eu.etaxonomy.taxeditor.model.IContextListener} object.
+ */
+ public void removeContextListener(IContextListener listener) {
+ contextListeners.remove(listener);
+ }
+
+ public void notifyContextStartWithoutDialog(IProgressMonitor monitor) {
+ MessagingUtils.info("Notifying context listeners, that the context has started.");
+
+ readMemento();
+
+ for(final Object listener : contextListeners.getListeners()){
+ ((IContextListener) listener).contextStart(memento, monitor);
+ }
+ }
+ /**
+ * <p>notifyContextStart</p>
+ */
+ public void notifyContextStart() {
+ MessagingUtils.info("Notifying context listeners, that the context has started.");
+ ProgressMonitorDialog dialog = new ProgressMonitorDialog(StoreUtil.getShell());
+
+ try {
+ dialog.run(false, false, new IRunnableWithProgress() {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException, InterruptedException {
+ monitor.beginTask("Starting context", contextListeners.size());
+
+
+ readMemento();
+
+ for(final Object listener : contextListeners.getListeners()){
+ ((IContextListener) listener).contextStart(memento, monitor);
+ monitor.worked(1);
+ }
+ monitor.done();
+ }
+ });
+ } catch (InvocationTargetException e) {
+ MessagingUtils.error(getClass(), e);
+ } catch (InterruptedException e) {
+ MessagingUtils.error(getClass(), e);
+ }
+ }
+
+
+ /**
+ *
+ */
+ public void notifyContextRefresh() {
+ MessagingUtils.info("Notifying context listeners, that the context needs to be refreshed.");
+ ProgressMonitorDialog dialog = new ProgressMonitorDialog(StoreUtil.getShell());
+
+ try {
+ dialog.run(false, false, new IRunnableWithProgress() {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException, InterruptedException {
+ monitor.beginTask("Refreshing context", contextListeners.size());
+
+ for(final Object listener : contextListeners.getListeners()){
+ ((IContextListener) listener).contextRefresh(monitor);
+ monitor.worked(1);
+ }
+ monitor.done();
+ }
+ });
+ } catch (InvocationTargetException e) {
+ MessagingUtils.error(getClass(), e);
+ } catch (InterruptedException e) {
+ MessagingUtils.error(getClass(), e);
+ }
+ }
+
+ /**
+ * <p>notifyContextAboutToStop</p>
+ *
+ * @param monitor a {@link org.eclipse.core.runtime.IProgressMonitor} object.
+ */
+ public void notifyContextAboutToStop(final IProgressMonitor monitor){
+
+ IProgressMonitor subMonitor = StoreUtil.getSubProgressMonitor(monitor, 1);
+
+ subMonitor.beginTask("Stoping context", contextListeners.size());
+ // we are creating the memento here; even if the context is not stopped
+ createMemento();
+
+ for(final Object listener : contextListeners.getListeners()){
+ ((IContextListener) listener).contextAboutToStop(memento, subMonitor);
+ subMonitor.worked(1);
+ }
+
+ subMonitor.done();
+ }
+
+ /**
+ * <p>notifyContextStop</p>
+ *
+ * @param monitor a {@link org.eclipse.core.runtime.IProgressMonitor} object.
+ */
+ public void notifyContextStop(IProgressMonitor monitor) {
+
+ IProgressMonitor subMonitor = StoreUtil.getSubProgressMonitor(monitor, 1);
+
+ subMonitor.beginTask("Stoping context", contextListeners.size());
+ MessagingUtils.info("Notifying context listeners, that the context has stopped.");
+
+ for(Object listener : contextListeners.getListeners()){
+ ((IContextListener) listener).contextStop(memento, subMonitor);
+ subMonitor.worked(1);
+ }
+
+ saveMemento();
+ subMonitor.done();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchListener#preShutdown(org.eclipse.ui.IWorkbench, boolean)
+ */
+ /** {@inheritDoc} */
+ @Override
+ public boolean preShutdown(IWorkbench workbench, boolean forced) {
+
+ createMemento();
+
+ IProgressMonitor monitor = null;
+
+ for(Object listener : contextListeners.getListeners()){
+ ((IContextListener) listener).workbenchShutdown(memento, monitor);
+ }
+
+ saveMemento();
+
+ // return true in any case, otherwise the application will not stop
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchListener#postShutdown(org.eclipse.ui.IWorkbench)
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void postShutdown(IWorkbench workbench) {
+
+
+ }
+
+
+ private void readMemento(){
+ try {
+ memento = MementoHelper.readMementoFromFile(getStateFileForCurrentDatabase());
+ } catch (FileNotFoundException e) {
+ // no memento -> no previous state
+ MessagingUtils.info("No state file for datasource");
+ }
+ }
+
+ private void createMemento(){
+
+ if (CdmStore.getActiveCdmSource() != null) {
+
+ try {
+ String name = CdmStore.getActiveCdmSource().getName();
+ name = name.trim();
+ name = name.replace(" ", "_");
+ memento = XMLMemento.createWriteRoot(name);
+
+ MessagingUtils.info("DataSource found. Memento created.");
+ } catch (Exception e) {
+ // The memento could not be created, but a not closable editor is avoided for this case.
+ MessagingUtils.error(this.getClass(), "The memento could not be created", e);
+ }
+ } else {
+ MessagingUtils.info("Not storing state data, because no DataSource present.");
+ }
+
+ }
+
+ private boolean saveMemento(){
+ return MementoHelper.saveMementoToFile(memento, getStateFileForCurrentDatabase()) != null;
+ }
+
+ /**
+ * <p>getStateFileForCurrentDatabase</p>
+ *
+ * @return a {@link java.io.File} object.
+ */
+ protected File getStateFileForCurrentDatabase() {
+ if(CdmStore.getActiveCdmSource() == null){
+ return null;
+ }
+
+ IPath path = TaxeditorStorePlugin.getDefault().getStateLocation();
+ if (path == null) {
+ return null;
+ }
+ path = path.append("editor_state_" + CdmStore.getActiveCdmSource().getName() + ".xml");
+ return path.toFile();
+ }
}
*/
public boolean authenticate(String username, String password){
- // close all open editors
- if(!AbstractUtility.closeAll()){
- return false;
- }
+ // close all open editors
+ if(!AbstractUtility.closeAll()){
+ return false;
+ }
+
+
+ try{
+ doAuthenticate(username, password);
+ } catch (CdmAuthenticationException e) {
+ MessagingUtils.warningDialog("Could not authenticate", this, e.getMessage());
+ }
+ return false;
+ }
+ public void doAuthenticate(String username, String password) throws CdmAuthenticationException {
+ try {
+ SecurityContextHolder.clearContext();
+ Authentication lastAuthentication = CdmStore.getCurrentAuthentiation();
+
+ UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
+ Authentication authentication = CdmStore.getAuthenticationManager().authenticate(token);
+
+ User user = (User) authentication.getPrincipal();
+ /* circumventing problem with hibernate not refreshing the transient collection authorities in this case,
+ * see http://dev.e-taxonomy.eu/trac/ticket/4053 */
+ user.initAuthorities();
+
+ if(logger.isDebugEnabled()){
+ StringBuilder gaText = new StringBuilder();
+ String indent = " ";
+ Set<GrantedAuthority> gaSet = user.getGrantedAuthorities();
+ _logGrantedAuthotities(gaText, indent, gaSet);
+ for(Group gr : user.getGroups()){
+ gaText.append(indent).append("gr[").append(gr.hashCode()).append("] \"").append(gr.getName()).append("\" ").append(gr.toString()).append("\n");
+ _logGrantedAuthotities(gaText, indent + indent, gr.getGrantedAuthorities());
+ }
+ logger.debug("User authenticated: " + user.getUsername() + "\n" + gaText.toString());
+ }
+
+ authentication = new UsernamePasswordAuthenticationToken(user,password, authentication.getAuthorities());
+ SecurityContextHolder.getContext().setAuthentication(authentication);
+ CdmApplicationState.setCurrentSecurityContext(SecurityContextHolder.getContext());
+
+ if(!authentication.equals(lastAuthentication)){
+ this.setChanged();
+ this.notifyObservers();
+ }
+ } catch(BadCredentialsException e){
+ throw new CdmAuthenticationException("Login and/or Password incorrect", e);
+ } catch(LockedException e){
+ throw new CdmAuthenticationException("Account is locked", e);
+ } catch(IllegalArgumentException e){
+ throw new CdmAuthenticationException("Login and/or Password empty", e);
+ }
- try{
- SecurityContextHolder.clearContext();
- Authentication lastAuthentication = CdmStore.getCurrentAuthentiation();
-
- UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
- Authentication authentication = CdmStore.getAuthenticationManager().authenticate(token);
-
- User user = (User) authentication.getPrincipal();
- /* circumventing problem with hibernate not refreshing the transient collection authorities in this case,
- * see http://dev.e-taxonomy.eu/trac/ticket/4053 */
- user.initAuthorities();
-
- if(logger.isDebugEnabled()){
- StringBuilder gaText = new StringBuilder();
- String indent = " ";
- Set<GrantedAuthority> gaSet = user.getGrantedAuthorities();
- _logGrantedAuthotities(gaText, indent, gaSet);
- for(Group gr : user.getGroups()){
- gaText.append(indent).append("gr[").append(gr.hashCode()).append("] \"").append(gr.getName()).append("\" ").append(gr.toString()).append("\n");
- _logGrantedAuthotities(gaText, indent + indent, gr.getGrantedAuthorities());
- }
- logger.debug("User authenticated: " + user.getUsername() + "\n" + gaText.toString());
- }
-
- authentication = new UsernamePasswordAuthenticationToken(user,password, authentication.getAuthorities());
- SecurityContextHolder.getContext().setAuthentication(authentication);
- CdmApplicationState.setCurrentSecurityContext(SecurityContextHolder.getContext());
-
- if(!authentication.equals(lastAuthentication)){
- this.setChanged();
- this.notifyObservers();
- }
- return true;
- }
- catch(BadCredentialsException e){
- MessagingUtils.warningDialog("Could not authenticate", this, "Could not authenticate. Reason: Bad Credentials.");
- }
- catch(LockedException e){
- MessagingUtils.warningDialog("Could not authenticate", this, "Could not authenticate. Reason: Account is locked.");
- }
- catch(IllegalArgumentException e){
- MessagingUtils.warningDialog("Could not authenticate", this, "Could not authenticate. Reason: Username and/or Password empty.");
- }
- return false;
}
private void _logGrantedAuthotities(StringBuilder gaText, String indent,
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.events.ExpansionEvent;
+import org.eclipse.ui.forms.events.IExpansionListener;
+import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.wb.swt.SWTResourceManager;
-import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo;
protected Object result;
protected Shell shlConnect;
- private Text txtPort;
private Text txtCdmServerStatus;
private Text txtCdmInstanceStatus;
private Combo comboCdmServer;
private final String STATUS_ERROR = "Error";
private final String STATUS_REMOTING_NOT_ACTIVATED = "Remoting not activated";
+ private Composite remotingComposite;
private CdmServerInfo selectedCsii;
private CdmInstanceInfo selectedCdmInstance;
private Button btnCdmServerRefresh;
+ private Composite loginComposite;
+ private Label lblLogin;
+ private Text txtLogin;
+ private Label lblPassword;
+ private Text txtPassword;
+ private Button btnRememberMe;
+ private Composite composite;
+ private Label lblPort;
+ private Text txtPort;
+ private Label lblServerVersion;
+ private Text txtServerVersion;
+ private ExpandableComposite xpndblcmpstAdvanced;
+ private StyledText styledTxtMessage;
+
+ private final int MIN_WIDTH = 530;
+ private final int MIN_HEIGHT = 220;
+ private final int MIN_EXP_HEIGHT = 300;
+ private final int MESSAGE_HEIGHT = 25;
/**
* Create the dialog.
* @return the result
*/
public Object open() {
- ICdmRemoteSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
- if(devRemoteSource != null) {
- connect(devRemoteSource);
- } else {
- createContents();
- populateCdmServerCombo();
- shlConnect.open();
- shlConnect.layout();
-
- Display display = getParent().getDisplay();
-
- while (!shlConnect.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
+ // ICdmRemoteSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
+ // if(devRemoteSource != null) {
+ // connect(devRemoteSource);
+ // } else {
+ createContents();
+ populateCdmServerCombo();
+ shlConnect.open();
+ shlConnect.layout();
+
+ xpndblcmpstAdvanced.setExpanded(false);
+ //setMessage(null);
+
+ Display display = getParent().getDisplay();
+
+ while (!shlConnect.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
}
}
+ //}
return result;
}
* Create contents of the dialog.
*/
private void createContents() {
- shlConnect = new Shell(getParent(), getStyle());
- shlConnect.setSize(490, 157);
+ shlConnect = new Shell(getParent(), SWT.DIALOG_TRIM);
+ shlConnect.setMinimumSize(new Point(MIN_WIDTH, MIN_HEIGHT));
+ shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
shlConnect.setText("Connect");
shlConnect.setLayout(new FillLayout(SWT.HORIZONTAL));
- Composite composite = new Composite(shlConnect, SWT.NONE);
- FillLayout fl_composite = new FillLayout(SWT.VERTICAL);
- fl_composite.spacing = 5;
- composite.setLayout(fl_composite);
-
- Composite remotingComposite = new Composite(composite, SWT.NONE);
- FillLayout fl_remotingComposite = new FillLayout(SWT.VERTICAL);
- fl_remotingComposite.spacing = 5;
- remotingComposite.setLayout(fl_remotingComposite);
+ remotingComposite = new Composite(shlConnect, SWT.NONE);
+ remotingComposite.setLayout(new GridLayout(1, false));
Composite cdmServerComposite = new Composite(remotingComposite, SWT.NONE);
- cdmServerComposite.setLayout(new GridLayout(6, false));
+ GridData gd_cdmServerComposite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+ gd_cdmServerComposite.heightHint = 68;
+ cdmServerComposite.setLayoutData(gd_cdmServerComposite);
+ cdmServerComposite.setLayout(new GridLayout(4, false));
Label lblCdmServer = new Label(cdmServerComposite, SWT.NONE);
lblCdmServer.setText("CDM Server : ");
comboCdmServer.setLayoutData(gd_comboCdmServer);
comboCdmServer.select(0);
- Label lblPortSeparator = new Label(cdmServerComposite, SWT.NONE);
- lblPortSeparator.setText(" : ");
-
- txtPort = new Text(cdmServerComposite, SWT.BORDER);
- GridData gd_txtPort = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
- gd_txtPort.widthHint = 50;
- txtPort.setLayoutData(gd_txtPort);
-
txtCdmServerStatus = new Text(cdmServerComposite, SWT.BORDER);
txtCdmServerStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
txtCdmServerStatus.setEditable(false);
txtCdmInstanceStatus = new Text(cdmServerComposite, SWT.BORDER);
txtCdmInstanceStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
txtCdmInstanceStatus.setEditable(false);
- GridData gd_txtCdmInstanceStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
+ GridData gd_txtCdmInstanceStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_txtCdmInstanceStatus.widthHint = 100;
txtCdmInstanceStatus.setLayoutData(gd_txtCdmInstanceStatus);
gd_btnCdmInstanceRefresh.heightHint = 30;
btnCdmInstanceRefresh.setLayoutData(gd_btnCdmInstanceRefresh);
btnCdmInstanceRefresh.setText("Refresh");
- new Label(cdmServerComposite, SWT.NONE);
- btnConnect = new Button(cdmServerComposite, SWT.FLAT);
+ loginComposite = new Composite(remotingComposite, SWT.NONE);
+ GridData gd_loginComposite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+ gd_loginComposite.widthHint = 487;
+ gd_loginComposite.heightHint = 70;
+ loginComposite.setLayoutData(gd_loginComposite);
+ GridLayout gl_loginComposite = new GridLayout(6, false);
+ gl_loginComposite.marginTop = 5;
+ loginComposite.setLayout(gl_loginComposite);
+
+ lblLogin = new Label(loginComposite, SWT.CENTER);
+ GridData gd_lblLogin = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
+ gd_lblLogin.widthHint = 50;
+ lblLogin.setLayoutData(gd_lblLogin);
+ lblLogin.setText("Login : ");
+ lblLogin.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
+
+ txtLogin = new Text(loginComposite, SWT.BORDER);
+ GridData gd_txtLogin = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
+ gd_txtLogin.minimumWidth = 80;
+ gd_txtLogin.widthHint = 80;
+ gd_txtLogin.heightHint = 15;
+ txtLogin.setLayoutData(gd_txtLogin);
+
+ lblPassword = new Label(loginComposite, SWT.CENTER);
+ lblPassword.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblPassword.setText("Password : ");
+ lblPassword.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
+
+ txtPassword = new Text(loginComposite, SWT.BORDER | SWT.PASSWORD);
+ GridData gd_txtPassword = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
+ gd_txtPassword.minimumWidth = 80;
+ gd_txtPassword.widthHint = 80;
+ gd_txtPassword.heightHint = 15;
+ txtPassword.setLayoutData(gd_txtPassword);
+ new Label(loginComposite, SWT.NONE);
+
+ btnConnect = new Button(loginComposite, SWT.FLAT);
+ btnConnect.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
btnConnect.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
connect(selectedCsii.getCdmRemoteSource(selectedCdmInstance));
}
});
- GridData gd_btnConnect = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
- gd_btnConnect.heightHint = 30;
- btnConnect.setLayoutData(gd_btnConnect);
btnConnect.setText("Connect");
- new Label(cdmServerComposite, SWT.NONE);
- new Label(cdmServerComposite, SWT.NONE);
- new Label(cdmServerComposite, SWT.NONE);
- new Label(cdmServerComposite, SWT.NONE);
+
+ btnRememberMe = new Button(loginComposite, SWT.CHECK);
+ 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");
+
+ styledTxtMessage = new StyledText(remotingComposite, SWT.NONE);
+ styledTxtMessage.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
+ styledTxtMessage.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));
+ styledTxtMessage.setFont(SWTResourceManager.getFont("Ubuntu", 12, SWT.BOLD));
+ styledTxtMessage.setSelectionBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_SELECTION_TEXT));
+ styledTxtMessage.setSelectionForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));
+ styledTxtMessage.setDoubleClickEnabled(false);
+ styledTxtMessage.setEditable(false);
+ GridData gd_styledTxtMessage = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
+ gd_styledTxtMessage.exclude = true;
+ gd_styledTxtMessage.minimumHeight = MESSAGE_HEIGHT;
+ gd_styledTxtMessage.heightHint = MESSAGE_HEIGHT;
+ styledTxtMessage.setLayoutData(gd_styledTxtMessage);
+
+ xpndblcmpstAdvanced = new ExpandableComposite(remotingComposite, SWT.NONE, ExpandableComposite.TWISTIE);
+ GridData gd_xpndblcmpstAdvanced = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
+ gd_xpndblcmpstAdvanced.heightHint = 19;
+ xpndblcmpstAdvanced.setLayoutData(gd_xpndblcmpstAdvanced);
+ xpndblcmpstAdvanced.addExpansionListener(new IExpansionListener() {
+ @Override
+ public void expansionStateChanged(ExpansionEvent e) {
+ GridData gridData = (GridData) xpndblcmpstAdvanced.getLayoutData();
+ if(e.getState()) {
+ shlConnect.setSize(MIN_WIDTH, MIN_EXP_HEIGHT);
+ } else {
+ shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
+ }
+
+ }
+ @Override
+ public void expansionStateChanging(ExpansionEvent e) {
+ }
+ });
+ xpndblcmpstAdvanced.setText("advanced");
+ xpndblcmpstAdvanced.setExpanded(false);
+
+ composite = new Composite(xpndblcmpstAdvanced, SWT.NONE);
+ xpndblcmpstAdvanced.setClient(composite);
+ composite.setLayout(new GridLayout(2, false));
+
+ lblPort = new Label(composite, SWT.CENTER);
+ lblPort.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblPort.setSize(0, 0);
+ lblPort.setText("Port : ");
+ lblPort.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
+
+ txtPort = new Text(composite, SWT.BORDER);
+ txtPort.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
+
+ lblServerVersion = new Label(composite, SWT.CENTER);
+ lblServerVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblServerVersion.setText("Server Version :");
+ lblServerVersion.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
+
+ txtServerVersion = new Text(composite, SWT.BORDER);
+ txtServerVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
}
}
private void connect(ICdmRemoteSource source) {
+
+
+ if(!validateLogin()) {
+ return;
+ }
+
if(CdmStore.isConnecting()){
MessagingUtils.warningDialog("Already connecting", this, "You are currently connecting to a different CDM Instance already.");
return;
}
try {
- CdmDataSourceRepository.changeDataSource(source);
+ CdmStore.connect(source, this);
} catch (Exception e) {
// Do not expect anything to go wrong at this point, so we throw a runtime exception
// if any problems
throw new RuntimeException(e);
}
- if(shlConnect != null) {
- shlConnect.dispose();
+ }
+
+ private boolean validateLogin() {
+ if(getUsername() == null || getUsername().isEmpty()) {
+ setMessage("User login cannot be empty");
+ return false;
}
+ if(getPassword() == null || getPassword().isEmpty()) {
+ setMessage("Password cannot be empty");
+ return false;
+ }
+ return true;
+ }
+ public String getUsername() {
+ return txtLogin.getText();
}
+ public String getPassword() {
+ return txtPassword.getText();
+ }
+ public void setMessage(String message) {
+ if(message != null && !message.isEmpty()) {
+ styledTxtMessage.setText(message);
+ styledTxtMessage.setVisible(true);
+ ((GridData)styledTxtMessage.getLayoutData()).exclude = false;
+ shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT+MESSAGE_HEIGHT);
+ shlConnect.setMinimumSize(MIN_WIDTH, MIN_HEIGHT+MESSAGE_HEIGHT);
+ } else {
+ styledTxtMessage.setText("");
+ styledTxtMessage.setVisible(false);
+ ((GridData)styledTxtMessage.getLayoutData()).exclude = true;
+ shlConnect.setSize(MIN_WIDTH, MIN_HEIGHT);
+ shlConnect.setMinimumSize(MIN_WIDTH, MIN_HEIGHT);
+ }
+ remotingComposite.layout();
+ }
+
+ public void hide(boolean isHidden) {
+ if(shlConnect != null) {
+ shlConnect.setVisible(!isHidden);
+ }
+ }
+ public void dispose() {
+ if(shlConnect != null) {
+ shlConnect.dispose();
+ }
+ }
}