-// $Id$
/**
* Copyright (C) 2007 EDIT
* European Distributed Institute of Taxonomy
package eu.etaxonomy.taxeditor.store;
+import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.util.concurrent.CancellationException;
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteController;
-import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
+import eu.etaxonomy.cdm.api.application.ICdmRepository;
import eu.etaxonomy.cdm.config.CdmSourceException;
import eu.etaxonomy.cdm.config.ICdmSource;
import eu.etaxonomy.cdm.database.DbSchemaValidation;
import eu.etaxonomy.cdm.database.ICdmDataSource;
+import eu.etaxonomy.cdm.model.common.DefinedTermBase;
import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
+import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
+import eu.etaxonomy.cdm.model.name.Rank;
+import eu.etaxonomy.taxeditor.l10n.Messages;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.CdmProgressMonitorAdapter;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
+import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
import eu.etaxonomy.taxeditor.ui.dialog.LoginDialog;
import eu.etaxonomy.taxeditor.ui.dialog.RemotingLoginDialog;
import eu.etaxonomy.taxeditor.view.datasource.CdmDataSourceViewPart;
ICdmSource cdmSource,
DbSchemaValidation dbSchemaValidation,
Resource applicationContextBean) {
- super("Connecting to datasource: " + cdmSource);
+ super(String.format(Messages.CdmStoreConnector_CREATING_DATAMODEL, cdmSource));
this.display = display;
this.cdmSource = cdmSource;
this.dbSchemaValidation = dbSchemaValidation;
CdmStore.close(monitor);
}
- ICdmApplicationConfiguration applicationController = null;
+ ICdmRepository applicationController = null;
if (!monitor.isCanceled()) {
CdmProgressMonitorAdapter subprogressMonitor = CdmProgressMonitorAdapter
try {
Thread.currentThread().setPriority(10);
applicationController = getApplicationController(cdmSource,subprogressMonitor);
+ MessagingUtils.informationDialog(Messages.CdmStoreConnector_SUCCESS, Messages.CdmStoreConnector_DATA_MODEL_CREATION_SUCCESSFUL);
+ CdmDataSourceViewPart dataSourceView = (CdmDataSourceViewPart) AbstractUtility.getView("eu.etaxonomy.taxeditor.view.datasource", false);
+ if(dataSourceView!=null){
+ dataSourceView.refresh();
+ }
+ return Status.OK_STATUS;
} 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);
+ MessagingUtils.errorDialog(Messages.CdmStoreConnector_COULD_NOT_CREATE_DATAMODEL, CdmStoreConnector.class,
+ String.format(Messages.CdmStoreConnector_ERROR_DURING_DATAMODEL_CREATION, cdmSource.getName()), TaxeditorStorePlugin.PLUGIN_ID, e, true);
+ return Status.CANCEL_STATUS;
}
} 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;
- }
+ return Status.CANCEL_STATUS;
}
}
});
- ICdmApplicationConfiguration applicationController = null;
+ ICdmRepository applicationController = null;
if (!monitor.isCanceled()) {
CdmProgressMonitorAdapter subprogressMonitor = CdmProgressMonitorAdapter
if (!monitor.isCanceled()) {
CdmStore.setInstance(applicationController, cdmSource);
- monitor.subTask("Authenticating user");
+ monitor.subTask(Messages.CdmStoreConnector_AUTHENTICATING_USER);
display.syncExec(new Runnable() {
/*
* (non-Javadoc)
CdmStore.getLoginManager().doAuthenticate(loginDialog.getUsername(), loginDialog.getPassword());
loginDialog.onComplete();
CdmStore.getContextManager().notifyContextStart();
+ getInstance(Rank.class).resetTerms();
+ getInstance(NomenclaturalStatusType.class).resetTerms();
+ Rank.initDefaultTerms();
+ NomenclaturalStatusType.initDefaultTerms();
} catch(CdmAuthenticationException cae) {
loginDialog.hide(false);
loginDialog.setMessage(cae.getMessage());
}
}
+ /**
+ * Returns a new instance for the given class by using the default constructor.
+ * The constructor must be declared but can be unaccessible (e.g. private)
+ * @param termClass
+ * @return
+ */
+ private <T extends DefinedTermBase> T getInstance(Class<? extends DefinedTermBase> termClass) {
+ try {
+ Constructor<T> c = ((Class<T>)termClass).getDeclaredConstructor();
+ c.setAccessible(true);
+ T termInstance = c.newInstance();
+ return termInstance;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
- private ICdmApplicationConfiguration getApplicationController(ICdmSource cdmSource, CdmProgressMonitorAdapter subprogressMonitor) {
+ private ICdmRepository getApplicationController(ICdmSource cdmSource, CdmProgressMonitorAdapter subprogressMonitor) {
if(cdmSource instanceof ICdmDataSource) {
return CdmApplicationController.NewInstance(applicationContextBean,
(ICdmDataSource)cdmSource,
* @throws SQLException
*/
private void checkDbSchemaVersionCompatibility(IProgressMonitor monitor) {
- monitor.subTask("Checking if datasource is compatible with this editor.");
+ monitor.subTask(Messages.CdmStoreConnector_CHECK_IF_EDITOR_IS_COMPATIBLE);
String dbSchemaVersion;
String message = 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";
+ message = Messages.CdmStoreConnector_UPDATE_EDITOR_OR_CHOOSE_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.";
+ message = Messages.CdmStoreConnector_UPDATE_DATASOUREC_OR_CHOOSE_NEW_DATASOURCE;
}
}
monitor.worked(1);
// Show an error message
MessagingUtils
.messageDialog(
- "Datasource Compatibility Check failed",
+ Messages.CdmStoreConnector_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,
+ String.format(Messages.CdmStoreConnector_SCHEME_NOT_COMPATIBLE, cdmSource, message),
null);
monitor.setCanceled(true);
}
private void checkIsNonEmptyCdmDatabase(IProgressMonitor monitor) {
- monitor.subTask("Checking if datasource is a non empty CDM database.");
+ monitor.subTask(Messages.CdmStoreConnector_CHECK_IF_NON_EMPTY);
boolean isDbEmpty = false;
try {
isDbEmpty = cdmSource.isDbEmpty();
private void checkDatabaseReachable(IProgressMonitor monitor) {
try {
- monitor.subTask("Checking if datasource is reachable.");
+ monitor.subTask(Messages.CdmStoreConnector_CHECK_IF_REACHABLE);
cdmSource.checkConnection();
monitor.worked(1);
} catch (CdmSourceException e) {
- MessagingUtils.messageDialog("Could not connect to chosen datasource",
- this, "Reason: " + e.getMessage(), e);
+ MessagingUtils.messageDialog(Messages.CdmStoreConnector_COULD_NOT_CONNECT_TO_CHOSEN_DATASOURCE,
+ this, Messages.CdmStoreConnector_REASON + e.getMessage(), e);
monitor.setCanceled(true);
}
}