From 9f02fc9aa570bb6bb5ccc50a96d5352e77cc3415 Mon Sep 17 00:00:00 2001 From: "n.hoffmann" Date: Thu, 25 Jun 2009 17:47:31 +0000 Subject: [PATCH] Implemented some of the import/export functionality. Major refactoring of datasource wizards and wizard pages. Again, refactoring of preferred terms handling. General code cleansing. --- .gitattributes | 13 +- taxeditor-store/META-INF/MANIFEST.MF | 5 +- taxeditor-store/plugin.xml | 37 +++- .../CdmDataSourceTypeSelectionWizardPage.java | 2 +- .../taxeditor/io/AbstractExportWizard.java | 22 +- .../taxeditor/io/AbstractImportWizard.java | 163 ++++++++++++++ .../taxeditor/io/BerlinModelExportWizard.java | 39 ++-- .../taxeditor/io/BerlinModelImportWizard.java | 82 +++++++ .../io/GenericConfiguratorWizardPage.java | 175 +++++++++++++++ ...a => JaxbExportDestinationWizardPage.java} | 6 +- .../taxeditor/io/JaxbExportWizard.java | 40 ++-- ...e.java => JaxbImportSourceWizardPage.java} | 20 +- .../taxeditor/model/LanguageUtil.java | 28 --- .../taxeditor/model/ReferenceUtil.java | 38 ---- .../etaxonomy/taxeditor/model/Resources.java | 8 +- .../preference/AbstractMenuPreferences.java | 40 +++- .../DistributionStatusMenuPreferences.java | 37 ++++ .../preference/FeatureMenuPreferences.java | 28 +-- .../preference/InitializeDbPreferences.java | 4 +- .../NameRelationshipTypeMenuPreferences.java | 31 +++ ...omenclaturalStatusTypeMenuPreferences.java | 30 +++ .../taxeditor/preference/PreferencesUtil.java | 195 ++++++----------- .../preference/RankMenuPreferences.java | 34 +-- .../preference/wizards/FeatureWizard.java | 6 +- .../etaxonomy/taxeditor/store/CdmStore.java | 143 ++---------- .../taxeditor/store/VocabularyStore.java | 205 ++++++++++++++++++ .../taxeditor/store/CdmStoreTest.java | 8 +- 27 files changed, 988 insertions(+), 451 deletions(-) create mode 100644 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractImportWizard.java create mode 100644 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/BerlinModelImportWizard.java create mode 100644 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/GenericConfiguratorWizardPage.java rename taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/{JaxbExportWizardPage.java => JaxbExportDestinationWizardPage.java} (95%) rename taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/{BerlinModelExportWizardPage.java => JaxbImportSourceWizardPage.java} (69%) delete mode 100644 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/LanguageUtil.java delete mode 100644 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/ReferenceUtil.java create mode 100644 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/DistributionStatusMenuPreferences.java create mode 100644 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/NameRelationshipTypeMenuPreferences.java create mode 100644 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/NomenclaturalStatusTypeMenuPreferences.java create mode 100644 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/store/VocabularyStore.java diff --git a/.gitattributes b/.gitattributes index bdefcfc2e..2070ec57e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1007,10 +1007,13 @@ taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/handler/ShowDataSourceViewH taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractExcelExportWizard.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractExcelImportWizard.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractExportWizard.java -text +taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractImportWizard.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/BerlinModelExportWizard.java -text -taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/BerlinModelExportWizardPage.java -text +taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/BerlinModelImportWizard.java -text +taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/GenericConfiguratorWizardPage.java -text +taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbExportDestinationWizardPage.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbExportWizard.java -text -taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbExportWizardPage.java -text +taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbImportSourceWizardPage.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbImportWizard.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/TcsExportWizard.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/TcsImportWizard.java -text @@ -1022,9 +1025,7 @@ taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/IDataChangeBehavior.j taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/ImageResources.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/ImagesUtil.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/IterableSynonymyList.java -text -taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/LanguageUtil.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/NameUtil.java -text -taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/ReferenceUtil.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/Resources.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/SynonymUtil.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/TaxonTransfer.java -text @@ -1062,10 +1063,13 @@ taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/parser/CdmParserUtil.java - taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/AbstractMenuPreferences.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/CdmPreferences.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/DescriptionPreferences.java -text +taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/DistributionStatusMenuPreferences.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/FeatureMenuPreferences.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/InitNomenclaturalCodePrefDialog.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/InitializeDbPreferences.java -text +taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/NameRelationshipTypeMenuPreferences.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/NomenclaturalCodePreferences.java -text +taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/NomenclaturalStatusTypeMenuPreferences.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/RankMenuPreferences.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/TaxonomicPreferences.java -text @@ -1074,6 +1078,7 @@ taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureW taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureWizardPage.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/store/StoreUtil.java -text +taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/store/VocabularyStore.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/store/internal/TaxeditorStorePlugin.java -text taxeditor-store/src/main/resources/eu/etaxonomy/cdm/defaultApplicationContext.xml -text taxeditor-store/src/main/resources/log4j.properties -text diff --git a/taxeditor-store/META-INF/MANIFEST.MF b/taxeditor-store/META-INF/MANIFEST.MF index 492018446..8d784f594 100644 --- a/taxeditor-store/META-INF/MANIFEST.MF +++ b/taxeditor-store/META-INF/MANIFEST.MF @@ -24,7 +24,10 @@ Require-Bundle: org.eclipse.ui;bundle-version="[3.2.0,4.0.0)", eu.etaxonomy.cdmLibrary;bundle-version="2.1.0", org.eclipse.ui.editors;bundle-version="3.4.0", org.eclipse.jface.text;bundle-version="3.4.1", - org.eclipse.ui.ide;bundle-version="3.4.2" + org.eclipse.ui.ide;bundle-version="3.4.2", + org.eclipse.debug.core;bundle-version="3.4.1", + org.eclipse.jdt.launching;bundle-version="3.4.1", + org.eclipse.jdt.core;bundle-version="3.4.4" Bundle-RequiredExecutionEnvironment: J2SE-1.5 Import-Package: junit.framework,org.junit Bundle-ActivationPolicy: lazy diff --git a/taxeditor-store/plugin.xml b/taxeditor-store/plugin.xml index 333c70bf8..8d2044070 100644 --- a/taxeditor-store/plugin.xml +++ b/taxeditor-store/plugin.xml @@ -24,13 +24,31 @@ category="eu.etaxonomy.taxeditor.preferences.description" class="eu.etaxonomy.taxeditor.preference.FeatureMenuPreferences" id="eu.etaxonomy.taxeditor.preferences.feature" - name="Preferred Features"> + name="Features"> + name="Ranks"> + + + + + + + + @@ -236,6 +260,13 @@ class="org.eclipse.ui.ExtensionFactory:progressView" id="org.eclipse.ui.views.ProgressView"> - + + + + + diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceTypeSelectionWizardPage.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceTypeSelectionWizardPage.java index 7fc00189c..af5f67366 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceTypeSelectionWizardPage.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceTypeSelectionWizardPage.java @@ -54,7 +54,7 @@ public class CdmDataSourceTypeSelectionWizardPage extends WizardPage implements private CdmDataSourceCredentialsWizardPage credentialsWizardPage; - protected CdmDataSourceTypeSelectionWizardPage(ICdmDataSource dataSource) { + public CdmDataSourceTypeSelectionWizardPage(ICdmDataSource dataSource) { super("DataSourceWizardPage"); this.dataSource = dataSource; diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractExportWizard.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractExportWizard.java index 2da7f1ae5..0756f79a1 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractExportWizard.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractExportWizard.java @@ -20,19 +20,24 @@ import org.eclipse.ui.IExportWizard; import eu.etaxonomy.cdm.io.common.CdmDefaultExport; import eu.etaxonomy.cdm.io.common.IExportConfigurator; +import eu.etaxonomy.cdm.io.common.IIoConfigurator; /** * @author n.hoffmann * @created 24.06.2009 * @version 1.0 */ -public abstract class AbstractExportWizard extends Wizard implements IExportWizard{ +public abstract class AbstractExportWizard extends Wizard implements IExportWizard{ private static final Logger logger = Logger .getLogger(AbstractExportWizard.class); + protected final String CONFIGURATION_PAGE = "CONFIGURATION_PAGE"; + + private GenericConfiguratorWizardPage pageConfiguration; + private CdmDefaultExport export; - public boolean export(final IExportConfigurator configurator){ + public boolean doExport(final IExportConfigurator configurator){ export = new CdmDefaultExport(); Job exportJob = new Job("Export"){ @@ -46,4 +51,17 @@ public abstract class AbstractExportWizard extends Wizard implements IExportWiza return true; } + + /* (non-Javadoc) + * @see org.eclipse.jface.wizard.Wizard#addPages() + */ + @Override + public void addPages() { + super.addPages(); + + pageConfiguration = new GenericConfiguratorWizardPage(CONFIGURATION_PAGE, getConfigurator()); + this.addPage(pageConfiguration); + } + + public abstract CONFIG getConfigurator(); } diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractImportWizard.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractImportWizard.java new file mode 100644 index 000000000..faade6401 --- /dev/null +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractImportWizard.java @@ -0,0 +1,163 @@ +// $Id$ +/** +* Copyright (C) 2007 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ + +package eu.etaxonomy.taxeditor.io; + +import org.apache.log4j.Logger; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; +import org.eclipse.jdt.launching.IVMInstall; +import org.eclipse.jdt.launching.IVMInstallType; +import org.eclipse.jdt.launching.JavaRuntime; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.IImportWizard; + +import eu.etaxonomy.cdm.io.common.CdmDefaultImport; +import eu.etaxonomy.cdm.io.common.IImportConfigurator; +import eu.etaxonomy.cdm.io.common.IIoConfigurator; +import eu.etaxonomy.taxeditor.store.StoreUtil; + +/** + * @author n.hoffmann + * @created 24.06.2009 + * @version 1.0 + */ +public abstract class AbstractImportWizard extends Wizard implements IImportWizard, IJavaLaunchConfigurationConstants{ + private static final Logger logger = Logger + .getLogger(AbstractImportWizard.class); + + protected final String CONFIGURATION_PAGE = "CONFIGURATION_PAGE"; + + private GenericConfiguratorWizardPage pageConfiguration; + + private CdmDefaultImport importer; + + /** + * Performs an import into a new database. The application context has to be changed + * @param configurator + * @return + */ + public boolean doImportExternal(IImportConfigurator configurator){ + + +// try { +// ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); +// ILaunchConfigurationType type = manager.getLaunchConfigurationType(ID_JAVA_APPLICATION); +// ILaunchConfiguration[] configurations = manager.getLaunchConfigurations(type); +// +// // delete possible prior launch configurations +// for (ILaunchConfiguration configuration : configurations) { +// if (configuration.getName().equals("NewInstance")) { +// configuration.delete(); +// break; +// } +// } +// +// ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, "NewInstance"); +// +// workingCopy.setAttribute(ATTR_MAIN_TYPE_NAME, "eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin"); +// +// +// workingCopy.setAttribute(ATTR_VM_INSTALL_NAME, JavaRuntime.getDefaultVMInstall().getName()); +// workingCopy.setAttribute(ATTR_VM_INSTALL_TYPE, JavaRuntime.getDefaultVMInstall().getVMInstallType().getId()); +// +// +// workingCopy.launch(ILaunchManager.RUN_MODE, null); + + +// IVMInstall vm = JavaRuntime.getDefaultVMInstall();//VMInstall(proj); +// if (vm == null) vm = JavaRuntime.getDefaultVMInstall(); +// IVMRunner vmr = vm.getVMRunner(ILaunchManager.RUN_MODE); +// String[] cp = JavaRuntime.computeDefaultRuntimeClassPath(proj); +// VMRunnerConfiguration config = new VMRunnerConfiguration(main, cp); +// ILaunch launch = new Launch(null, +// ILaunchManager.RUN_MODE, null); +// vmr.run(config, launch, null); + +// IVMInstallType[] types = JavaRuntime.getVMInstallTypes(); +// +// IVMInstall install = null; +// for(IVMInstallType type : types){ +// install = type.createVMInstall(type.getId()); +// break; +// } +// +// +// IPath path = JavaRuntime.newJREContainerPath(install); +// String jrePath = path.toPortableString(); + + +// +// ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); +// ILaunchConfigurationType type = manager.getLaunchConfigurationType(ID_JAVA_APPLICATION); +// ILaunchConfigurationWorkingCopy wc = type.newInstance(null, "NewInstance"); +// wc.setAttribute(ATTR_JRE_CONTAINER_PATH, jrePath); +// wc.setAttribute(ATTR_MAIN_TYPE_NAME, "eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin"); +// ILaunchConfiguration config = wc.doSave(); +// config.launch(ILaunchManager.RUN_MODE, null); +// +// +// Process p = Runtime.getRuntime().exec(cmdarray); +// +// +// } catch (CoreException e) { +// logger.error("Error launching import", e); +// } + + StoreUtil.notImplementedMessage(); + + return true; + } + + /** + * Use when importing data into the current application context + * + * @param configurator + * @return + */ + public boolean doImportInternal(final IImportConfigurator configurator){ + importer = new CdmDefaultImport(); + + Job importJob = new Job("Import"){ + @Override + protected IStatus run(IProgressMonitor monitor) { + return importer.invoke(configurator) ? Status.OK_STATUS : Status.CANCEL_STATUS; + } + }; + + importJob.schedule(); + + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.wizard.Wizard#addPages() + */ + @Override + public void addPages() { + super.addPages(); + + pageConfiguration = new GenericConfiguratorWizardPage(CONFIGURATION_PAGE, getConfigurator()); + this.addPage(pageConfiguration); + } + + public abstract CONFIG getConfigurator(); +} diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/BerlinModelExportWizard.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/BerlinModelExportWizard.java index d968318e4..ed3204bc7 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/BerlinModelExportWizard.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/BerlinModelExportWizard.java @@ -17,7 +17,6 @@ import org.eclipse.ui.IWorkbench; import eu.etaxonomy.cdm.database.ICdmDataSource; import eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportConfigurator; import eu.etaxonomy.cdm.io.common.Source; -import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository; import eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceSQLServerWizardPage; import eu.etaxonomy.taxeditor.store.CdmStore; @@ -26,13 +25,23 @@ import eu.etaxonomy.taxeditor.store.CdmStore; * @created 23.06.2009 * @version 1.0 */ -public class BerlinModelExportWizard extends AbstractExportWizard { +public class BerlinModelExportWizard extends AbstractExportWizard { private static final Logger logger = Logger .getLogger(BerlinModelExportWizard.class); - private CdmDataSourceSQLServerWizardPage page; + private CdmDataSourceSQLServerWizardPage pageDataSource; + private BerlinModelExportConfigurator configurator; + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) + */ + public void init(IWorkbench workbench, IStructuredSelection selection) { + this.setWindowTitle("Berlin Model Export"); + configurator = BerlinModelExportConfigurator.NewInstance(null, null); + } + /* (non-Javadoc) * @see org.eclipse.jface.wizard.Wizard#addPages() */ @@ -40,8 +49,10 @@ public class BerlinModelExportWizard extends AbstractExportWizard { public void addPages() { super.addPages(); - page = new CdmDataSourceSQLServerWizardPage(null); - this.addPage(page); + pageDataSource = new CdmDataSourceSQLServerWizardPage(null); + this.addPage(pageDataSource); + + } @@ -51,26 +62,28 @@ public class BerlinModelExportWizard extends AbstractExportWizard { @Override public boolean performFinish() { - ICdmDataSource dataSource = page.getDataSource(); + ICdmDataSource dataSource = pageDataSource.getDataSource(); // FIXME use new constructor Source(ICdmDataSource) - Source source = new Source(Source.SQL_SERVER_2005, + Source destination = new Source(Source.SQL_SERVER_2005, dataSource.getServer(), dataSource.getDatabase(), dataSource.getPort()); - source.setUserAndPwd(dataSource.getUsername(), dataSource.getPassword()); + destination.setUserAndPwd(dataSource.getUsername(), dataSource.getPassword()); - BerlinModelExportConfigurator configurator = BerlinModelExportConfigurator.NewInstance(source, CdmDataSourceRepository.getDefault().getCurrentDataSource()); + configurator.setDestination(destination); configurator.setCdmAppController(CdmStore.getApplicationController()); - return export(configurator); + + return doExport(configurator); } /* (non-Javadoc) - * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) + * @see eu.etaxonomy.taxeditor.io.AbstractExportWizard#getConfigurator() */ - public void init(IWorkbench workbench, IStructuredSelection selection) { - this.setWindowTitle("Berlin Model Export"); + @Override + public BerlinModelExportConfigurator getConfigurator() { + return configurator; } } diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/BerlinModelImportWizard.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/BerlinModelImportWizard.java new file mode 100644 index 000000000..7f5b3d025 --- /dev/null +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/BerlinModelImportWizard.java @@ -0,0 +1,82 @@ +// $Id$ +/** +* Copyright (C) 2007 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ + +package eu.etaxonomy.taxeditor.io; + +import org.apache.log4j.Logger; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IWorkbench; + +import eu.etaxonomy.cdm.database.ICdmDataSource; +import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator; +import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository; +import eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceTypeSelectionWizardPage; + +/** + * @author n.hoffmann + * @created 24.06.2009 + * @version 1.0 + */ +public class BerlinModelImportWizard extends AbstractImportWizard { + private static final Logger logger = Logger + .getLogger(BerlinModelImportWizard.class); + + CdmDataSourceTypeSelectionWizardPage dataSourceSelectionPage; + + BerlinModelImportConfigurator configurator; + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) + */ + public void init(IWorkbench workbench, IStructuredSelection selection) { + configurator = BerlinModelImportConfigurator.NewInstance(null, null); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.wizard.Wizard#performFinish() + */ + @Override + public boolean performFinish() { + + ICdmDataSource dataSource; + String dataSourceName = dataSourceSelectionPage.getDataSourceName(); + if(dataSourceSelectionPage.getCredentialsWizardPage() != null){ + dataSource = dataSourceSelectionPage.getCredentialsWizardPage().getDataSource(); + }else{ + throw new IllegalStateException("Expected a datasource credentials page to exist"); + } + + // save the new dataSource to repository + CdmDataSourceRepository.getDefault().save(dataSourceName, dataSource); + + configurator.setDestination(dataSource); + + return doImportExternal(configurator); + } + + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.io.AbstractImportWizard#getConfigurator() + */ + @Override + public BerlinModelImportConfigurator getConfigurator() { + return configurator; + } + + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.io.AbstractImportWizard#addPages() + */ + @Override + public void addPages() { + super.addPages(); + + dataSourceSelectionPage = new CdmDataSourceTypeSelectionWizardPage(null); + addPage(dataSourceSelectionPage); + } +} diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/GenericConfiguratorWizardPage.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/GenericConfiguratorWizardPage.java new file mode 100644 index 000000000..ac19b0fe2 --- /dev/null +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/GenericConfiguratorWizardPage.java @@ -0,0 +1,175 @@ +// $Id$ +/** +* Copyright (C) 2007 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ + +package eu.etaxonomy.taxeditor.io; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; + +import eu.etaxonomy.cdm.io.common.IIoConfigurator; + +/** + * @author n.hoffmann + * @created 23.06.2009 + * @version 1.0 + */ +public class GenericConfiguratorWizardPage extends WizardPage { + + + private static final Logger logger = Logger + .getLogger(GenericConfiguratorWizardPage.class); + + private IIoConfigurator configurator; + + /** + * @param pageName + * @param configurator + */ + protected GenericConfiguratorWizardPage(String pageName, IIoConfigurator configurator) { + super(pageName); + this.setTitle("Export Configuration"); + + this.setDescription("Configure the export mechanism."); + + this.configurator = configurator; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + */ + public void createControl(Composite parent) { + + Composite composite = new Composite(parent, SWT.NULL); + GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 2; + composite.setLayout(gridLayout); + + List methods = getConfiguratorsBooleanSetMethods(configurator); + + for(Method method : methods){ + createCheckbox(composite, method, configurator); + } + + setControl(composite); + } + + private void createCheckbox(Composite parent, Method method, final IIoConfigurator configurator){ + + String methodName = method.getName(); + + final String methodNameValue = methodName.substring(3); + + CLabel label = new CLabel(parent, SWT.NULL); + label.setText(methodNameValue); + + final Button checkBox = new Button(parent, SWT.CHECK); + checkBox.setSelection(executeBooleanGetMethod(configurator,"is" + methodNameValue)); + checkBox.addSelectionListener(new SelectionAdapter(){ + + /* (non-Javadoc) + * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) + */ + @Override + public void widgetSelected(SelectionEvent e) { + executeBooleanSetMethod(configurator, "set" + methodNameValue, checkBox.getSelection()); + } + + }); + + } + + + private boolean executeBooleanGetMethod(IIoConfigurator configurator, String methodName){ + + Class configuratorClass = configurator.getClass(); + + boolean result = false; + + Method[] methods = configuratorClass.getMethods(); + + for(Method method : methods){ + if(!method.getName().equals(methodName)){ + continue; + } + + try { + Object returnType = method.invoke(configurator, null); + if(returnType.getClass().equals(Boolean.class)){ + result = ((Boolean) returnType).booleanValue(); + } + + break; + } catch (Exception e) { + logger.warn("Could not invoke method"); + } + } + + + return result; + } + + private void executeBooleanSetMethod(IIoConfigurator configurator, String methodName, boolean selected){ + + Class configuratorClass = configurator.getClass(); + + + Method[] methods = configuratorClass.getMethods(); + + for(Method method : methods){ + if(!method.getName().equals(methodName)){ + continue; + } + + try { + method.invoke(configurator, selected); + + break; + } catch (Exception e) { + logger.warn("Could not invoke method"); + } + } + } + + private List getConfiguratorsBooleanSetMethods(IIoConfigurator configurator){ + List booleanMethods = new ArrayList(); + + Class configuratorClass = configurator.getClass(); + + Method[] allMethods = configuratorClass.getMethods(); + + for(Method method : allMethods){ + if(method.getName().startsWith("set")){ + + Class[] typeList = method.getParameterTypes(); + + if(typeList.length > 1){ + new IllegalStateException("Found a setter with parameter count > 1"); + } + + if(typeList[0].getName().equals("boolean")){ + booleanMethods.add(method); + } + } + } + + return booleanMethods; + } +} diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbExportWizardPage.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbExportDestinationWizardPage.java similarity index 95% rename from taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbExportWizardPage.java rename to taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbExportDestinationWizardPage.java index c968e3231..88895ebeb 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbExportWizardPage.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbExportDestinationWizardPage.java @@ -33,12 +33,12 @@ import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository; * @created 15.06.2009 * @version 1.0 */ -public class JaxbExportWizardPage extends WizardPage{ +public class JaxbExportDestinationWizardPage extends WizardPage{ public static final String DATE_FORMAT_NOW = "yyyyMMdd-HHmm"; private static final Logger logger = Logger - .getLogger(JaxbExportWizardPage.class); + .getLogger(JaxbExportDestinationWizardPage.class); private DirectoryDialog folderDialog; private Text text_exportFileName; @@ -49,7 +49,7 @@ public class JaxbExportWizardPage extends WizardPage{ * @param pageName * @param selection */ - protected JaxbExportWizardPage(String pageName) { + protected JaxbExportDestinationWizardPage(String pageName) { super(pageName); this.setTitle("JAXB Export"); diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbExportWizard.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbExportWizard.java index fe387c35f..a15d8b721 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbExportWizard.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbExportWizard.java @@ -17,7 +17,6 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IWorkbench; import eu.etaxonomy.cdm.io.jaxb.JaxbExportConfigurator; -import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository; import eu.etaxonomy.taxeditor.store.CdmStore; /** @@ -25,33 +24,36 @@ import eu.etaxonomy.taxeditor.store.CdmStore; * @created 15.06.2009 * @version 1.0 */ -public class JaxbExportWizard extends AbstractExportWizard { +public class JaxbExportWizard extends AbstractExportWizard { private static final Logger logger = Logger .getLogger(JaxbExportWizard.class); public final String JAXB_EXPORT = "JAXB_EXPORT"; - private JaxbExportWizardPage page; + private JaxbExportDestinationWizardPage page; + + private JaxbExportConfigurator configurator; + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) + */ + public void init(IWorkbench workbench, IStructuredSelection selection) { + this.setWindowTitle("JAXB Export"); + this.configurator = JaxbExportConfigurator.NewInstance(null, null); + } + /* (non-Javadoc) * @see org.eclipse.jface.wizard.Wizard#performFinish() */ @Override public boolean performFinish() { - String url = page.getFolderText() + File.pathSeparator + page.getExportFileName(); + String urlString = page.getFolderText() + File.pathSeparator + page.getExportFileName(); - JaxbExportConfigurator configurator = JaxbExportConfigurator.NewInstance(CdmDataSourceRepository.getDefault().getCurrentDataSource(), url); + configurator.setDestination(urlString); configurator.setCdmAppController(CdmStore.getApplicationController()); - return export(configurator); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) - */ - public void init(IWorkbench workbench, IStructuredSelection selection) { - this.setWindowTitle("JAXB Export"); + return doExport(configurator); } /* (non-Javadoc) @@ -60,12 +62,18 @@ public class JaxbExportWizard extends AbstractExportWizard { @Override public void addPages() { super.addPages(); - - page = new JaxbExportWizardPage(JAXB_EXPORT); - + + page = new JaxbExportDestinationWizardPage(JAXB_EXPORT); addPage(page); } + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.io.AbstractExportWizard#getConfigurator() + */ + @Override + public JaxbExportConfigurator getConfigurator() { + return configurator; + } } diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/BerlinModelExportWizardPage.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbImportSourceWizardPage.java similarity index 69% rename from taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/BerlinModelExportWizardPage.java rename to taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbImportSourceWizardPage.java index dfa3d5d82..6cd9448f1 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/BerlinModelExportWizardPage.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/io/JaxbImportSourceWizardPage.java @@ -16,25 +16,21 @@ import org.eclipse.swt.widgets.Composite; /** * @author n.hoffmann - * @created 23.06.2009 + * @created 24.06.2009 * @version 1.0 */ -public class BerlinModelExportWizardPage extends WizardPage { - - - private static final Logger logger = Logger - .getLogger(BerlinModelExportWizardPage.class); - +public class JaxbImportSourceWizardPage extends WizardPage { /** * @param pageName */ - protected BerlinModelExportWizardPage(String pageName) { + protected JaxbImportSourceWizardPage(String pageName) { super(pageName); - this.setTitle("Berlin Model Export"); - - this.setDescription("Exports the contents of the currently selected database into a Berlin Model database"); + // TODO Auto-generated constructor stub } - + + private static final Logger logger = Logger + .getLogger(JaxbImportSourceWizardPage.class); + /* (non-Javadoc) * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) */ diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/LanguageUtil.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/LanguageUtil.java deleted file mode 100644 index b2e925030..000000000 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/LanguageUtil.java +++ /dev/null @@ -1,28 +0,0 @@ -// $Id$ -/** -* Copyright (C) 2007 EDIT -* European Distributed Institute of Taxonomy -* http://www.e-taxonomy.eu -* -* The contents of this file are subject to the Mozilla Public License Version 1.1 -* See LICENSE.TXT at the top of this package for the full license terms. -*/ - -package eu.etaxonomy.taxeditor.model; - -import eu.etaxonomy.cdm.model.common.Language; - -/** - * @author p.ciardelli - * @created 03.04.2009 - * @version 1.0 - */ -public class LanguageUtil { - /** - * @param language - * @return - */ - public static String getDescription(Language language) { - return language.getDescription(); - } -} diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/ReferenceUtil.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/ReferenceUtil.java deleted file mode 100644 index cdb32f61c..000000000 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/ReferenceUtil.java +++ /dev/null @@ -1,38 +0,0 @@ -// $Id$ -/** -* Copyright (C) 2007 EDIT -* European Distributed Institute of Taxonomy -* http://www.e-taxonomy.eu -* -* The contents of this file are subject to the Mozilla Public License Version 1.1 -* See LICENSE.TXT at the top of this package for the full license terms. -*/ - -package eu.etaxonomy.taxeditor.model; - -import eu.etaxonomy.cdm.model.common.ReferencedEntityBase; -import eu.etaxonomy.cdm.model.reference.Generic; -import eu.etaxonomy.cdm.model.reference.ReferenceBase; - -/** - * @author p.ciardelli - * @created 02.04.2009 - * @version 1.0 - */ -public class ReferenceUtil { - /** - * Returns the entity's citation. If none exists, gives the - * entity a Generic citation. - * - * @param entity - * @return - */ - public static ReferenceBase getOrCreateCitation(ReferencedEntityBase entity) { - ReferenceBase citation = entity.getCitation(); - if (citation == null) { - citation = Generic.NewInstance(); - entity.setCitation(citation); - } - return citation; - } -} diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/Resources.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/Resources.java index 674eacd24..e9c1f0727 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/Resources.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/Resources.java @@ -27,6 +27,8 @@ import org.eclipse.ui.editors.text.EditorsUI; * @author n.hoffmann * @created 18.03.2009 * @version 1.0 + * + * @deprecated migrate to org.eclipse.ui.themes or at least handle this a little bit more eclipse like */ public class Resources { @@ -90,12 +92,6 @@ public class Resources { public static final String COLOR_COMPOSITE_SELECTED = "color_list_selection"; public static final String COLOR_LIST_BACKGROUND = "color_list_background"; - /* *************************************************************************************** - PREFERENCES - ************************************************************************************** */ - public static final String FEATURE_PREFERENCE = "feature_preference"; - public static final String RANK_PREFERENCE = "rank_preference"; - /*************************************************************************** * FONT REGISTRY diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/AbstractMenuPreferences.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/AbstractMenuPreferences.java index 1fc4a53e1..5979372c3 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/AbstractMenuPreferences.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/AbstractMenuPreferences.java @@ -10,6 +10,7 @@ package eu.etaxonomy.taxeditor.preference; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Set; @@ -30,6 +31,7 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; import eu.etaxonomy.cdm.model.common.DefinedTermBase; @@ -38,14 +40,15 @@ import eu.etaxonomy.cdm.model.common.DefinedTermBase; * @created 12.06.2009 * @version 1.0 */ -public abstract class AbstractMenuPreferences extends PreferencePage{ +public abstract class AbstractMenuPreferences extends PreferencePage implements + IWorkbenchPreferencePage{ private Button toggleButton; - protected HashMap menuButtons; + protected HashMap, Button> menuButtons; - protected Set vocabulary; + protected Set vocabulary; - private List preferedTerms; + private List preferedTerms; protected CheckboxTableViewer tableViewer; @@ -59,10 +62,10 @@ public abstract class AbstractMenuPreferences extends PreferencePage{ * @param title the title of the page * @param description describing text for the preference page */ - public AbstractMenuPreferences(Set initialVocabulary, List preferedTerms, String title, String description) { + public AbstractMenuPreferences(Set initialVocabulary, String title, String description) { super(title); vocabulary = initialVocabulary; - this.preferedTerms = preferedTerms; + preferedTerms = PreferencesUtil.getPreferredTerms(initialVocabulary); setDescription(description); } @@ -117,12 +120,16 @@ public abstract class AbstractMenuPreferences extends PreferencePage{ /** + * Default implementation + * * @param buttonContainer */ - protected abstract void createButtons(Composite buttonContainer); + protected void createButtons(Composite buttonContainer){ + // implement in client + } public void init(IWorkbench workbench) { - setPreferenceStore(PreferencesUtil.getPrefStore()); + setPreferenceStore(PreferencesUtil.getPreferenceStore()); } /* @@ -152,6 +159,8 @@ public abstract class AbstractMenuPreferences extends PreferencePage{ }; + + /** * * @author n.hoffmann @@ -181,6 +190,21 @@ public abstract class AbstractMenuPreferences extends PreferencePage{ */ public CheckboxTableViewer getTableViewer() { return tableViewer; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.preference.PreferencePage#performOk() + */ + @Override + public boolean performOk() { + List preferredTerms = new ArrayList(); + for (Object element : getTableViewer().getCheckedElements()){ + preferredTerms.add((T) element); + } + + PreferencesUtil.setPreferredTerms(preferredTerms, this.vocabulary); + + return true; } } \ No newline at end of file diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/DistributionStatusMenuPreferences.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/DistributionStatusMenuPreferences.java new file mode 100644 index 000000000..0037b88fa --- /dev/null +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/DistributionStatusMenuPreferences.java @@ -0,0 +1,37 @@ +// $Id$ +/** +* Copyright (C) 2007 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ + +package eu.etaxonomy.taxeditor.preference; + +import org.eclipse.ui.IWorkbenchPreferencePage; + +import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase; +import eu.etaxonomy.taxeditor.store.VocabularyStore; + +/** + * @author n.hoffmann + * @created 25.06.2009 + * @version 1.0 + */ +public class DistributionStatusMenuPreferences extends AbstractMenuPreferences>> implements + IWorkbenchPreferencePage { + + + /** + * @param initialVocabulary + * @param preferedTerms + * @param title + * @param description + */ + public DistributionStatusMenuPreferences() { + super(VocabularyStore.getPresenceAbsenceTerms(), "Distribution Status Preferences", "Choose which distribution states should be shown."); + } + +} diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/FeatureMenuPreferences.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/FeatureMenuPreferences.java index 899a1128b..5945341be 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/FeatureMenuPreferences.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/FeatureMenuPreferences.java @@ -8,9 +8,6 @@ */ package eu.etaxonomy.taxeditor.preference; -import java.util.ArrayList; -import java.util.List; - import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseAdapter; @@ -18,12 +15,11 @@ import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.IWorkbenchPreferencePage; import eu.etaxonomy.cdm.model.description.Feature; import eu.etaxonomy.taxeditor.preference.wizards.FeatureWizard; -import eu.etaxonomy.taxeditor.store.CdmStore; import eu.etaxonomy.taxeditor.store.StoreUtil; +import eu.etaxonomy.taxeditor.store.VocabularyStore; /** * @author p.ciardelli @@ -31,8 +27,7 @@ import eu.etaxonomy.taxeditor.store.StoreUtil; * @version 1.0 * @author n.hoffmann */ -public class FeatureMenuPreferences extends AbstractMenuPreferences implements - IWorkbenchPreferencePage { +public class FeatureMenuPreferences extends AbstractMenuPreferences { public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.preferences.feature"; private Button newButton; @@ -40,22 +35,7 @@ public class FeatureMenuPreferences extends AbstractMenuPreferences implements private Button removeButton; public FeatureMenuPreferences() { - super(CdmStore.getFeatures(), PreferencesUtil.getPreferredFeatures(), "Feature Preferences", "Choose which features you would like to use for descriptive elements."); - } - - - /* (non-Javadoc) - * @see org.eclipse.jface.preference.PreferencePage#performOk() - */ - public boolean performOk() { - List preferredFeatures = new ArrayList(); - for (Object element : getTableViewer().getCheckedElements()){ - preferredFeatures.add((Feature) element); - } - - PreferencesUtil.setPreferredFeatures(preferredFeatures); - - return true; + super(VocabularyStore.getFeatures(), "Feature Preferences", "Choose which features you would like to use for descriptive elements."); } /* (non-Javadoc) @@ -79,7 +59,7 @@ public class FeatureMenuPreferences extends AbstractMenuPreferences implements WizardDialog dialog = new WizardDialog(StoreUtil.getShell(), wizard); dialog.open(); - tableViewer.setInput(CdmStore.getFeatures()); + tableViewer.setInput(VocabularyStore.getFeatures()); } }); diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/InitializeDbPreferences.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/InitializeDbPreferences.java index ead719f50..83cb5d565 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/InitializeDbPreferences.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/InitializeDbPreferences.java @@ -85,7 +85,7 @@ public class InitializeDbPreferences extends PreferencePage implements * Initialize the preference page */ public void init(IWorkbench workbench) { - setPreferenceStore(PreferencesUtil.getPrefStore()); + setPreferenceStore(PreferencesUtil.getPreferenceStore()); } @Override @@ -100,7 +100,7 @@ public class InitializeDbPreferences extends PreferencePage implements boolean doReinitialize = !(btnInit.getSelection()); // boolean doInitTestdata = btnTestData.getSelection(); - PreferencesUtil.getPrefStore().setValue(Resources.INITIALIZED, doReinitialize); + PreferencesUtil.getPreferenceStore().setValue(Resources.INITIALIZED, doReinitialize); // UiUtil.getPrefStore().setValue(ITaxEditorConstants.INITIALIZE_W_TESTDATA, doInitTestdata); return true; } diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/NameRelationshipTypeMenuPreferences.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/NameRelationshipTypeMenuPreferences.java new file mode 100644 index 000000000..82467628b --- /dev/null +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/NameRelationshipTypeMenuPreferences.java @@ -0,0 +1,31 @@ +// $Id$ +/** +* Copyright (C) 2007 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ + +package eu.etaxonomy.taxeditor.preference; + +import eu.etaxonomy.cdm.model.name.NameRelationshipType; +import eu.etaxonomy.taxeditor.store.VocabularyStore; + +/** + * @author n.hoffmann + * @created 25.06.2009 + * @version 1.0 + */ +public class NameRelationshipTypeMenuPreferences extends + AbstractMenuPreferences { + + + public NameRelationshipTypeMenuPreferences() { + super(VocabularyStore.getNameRelationshipTypes(), + "Name relationship types", + "Configure name relationship types"); + + } +} diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/NomenclaturalStatusTypeMenuPreferences.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/NomenclaturalStatusTypeMenuPreferences.java new file mode 100644 index 000000000..84e3e2e40 --- /dev/null +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/NomenclaturalStatusTypeMenuPreferences.java @@ -0,0 +1,30 @@ +// $Id$ +/** +* Copyright (C) 2007 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ + +package eu.etaxonomy.taxeditor.preference; + +import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType; +import eu.etaxonomy.taxeditor.store.VocabularyStore; + +/** + * @author n.hoffmann + * @created 25.06.2009 + * @version 1.0 + */ +public class NomenclaturalStatusTypeMenuPreferences extends + AbstractMenuPreferences { + + public NomenclaturalStatusTypeMenuPreferences() { + super(VocabularyStore.getNomenclaturalStatusTypes(), + "Nomenlcatural Status Type Preferences", + "Configure nomenclatural status types"); + } + +} diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java index 36f7d8e6c..3a0ee0487 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java @@ -11,51 +11,63 @@ package eu.etaxonomy.taxeditor.preference; import java.util.ArrayList; import java.util.List; +import java.util.Set; import org.apache.log4j.Logger; import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.ui.editors.text.EditorsUI; -import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; +import eu.etaxonomy.cdm.model.common.DefinedTermBase; +import eu.etaxonomy.cdm.model.common.TermBase; import eu.etaxonomy.cdm.model.description.Feature; +import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase; import eu.etaxonomy.cdm.model.name.BotanicalName; +import eu.etaxonomy.cdm.model.name.NameRelationshipType; import eu.etaxonomy.cdm.model.name.NomenclaturalCode; +import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType; import eu.etaxonomy.cdm.model.name.NonViralName; import eu.etaxonomy.cdm.model.name.Rank; import eu.etaxonomy.cdm.model.name.ZoologicalName; import eu.etaxonomy.taxeditor.model.Resources; -import eu.etaxonomy.taxeditor.store.CdmStore; +import eu.etaxonomy.taxeditor.store.VocabularyStore; import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; /** * @author p.ciardelli * @created 05.12.2008 * @version 1.0 + * @author n.hoffmann */ public class PreferencesUtil { private static final Logger logger = Logger .getLogger(PreferencesUtil.class); - - private static final String FEATURE_PREFERENCE = "FEATURE_PREFERENCE"; - - - private static SourceViewerDecorationSupport decorationSupport; - /** * * @return */ - public static IPreferenceStore getPrefStore() { + public static IPreferenceStore getPreferenceStore() { return TaxeditorStorePlugin.getDefault().getPreferenceStore(); } + /** + * + * @return + */ + private static String getNameCodePreference() { + try{ + return getPreferenceStore().getString(Resources.CODE_PREFERENCE); + }catch(NullPointerException e){ + logger.warn("PreferenceStore was not available. That is OK if you are running a unit test. Setting ICBN as default code."); + return Resources.CODE_PREFERENCE_ICBN; + } + } + /** * * @param preferredCode */ public static void setNomenclaturalCode(String preferredCode) { - getPrefStore().setValue(Resources.CODE_PREFERENCE, preferredCode); + getPreferenceStore().setValue(Resources.CODE_PREFERENCE, preferredCode); } /** @@ -95,110 +107,7 @@ public class PreferencesUtil { return null; } - /** - * - * @return - */ - private static String getNameCodePreference() { - try{ - return getPrefStore().getString(Resources.CODE_PREFERENCE); - }catch(NullPointerException e){ - logger.warn("PreferenceStore was not available. That is OK if you are running a unit test. Setting ICBN as default code."); - return Resources.CODE_PREFERENCE_ICBN; - } - } - - /** - * Returns a Set of the Features that the user has chosen - * to have shown in preferences. - *

- *

- * Features are shown unless otherwise specified. - *

- * @return - */ - public static List getPreferredFeatures() { - - ArrayList preferedFeatures = new ArrayList(); - - for (Feature feature : CdmStore.getFeatures()) { - if(getPrefStore().getBoolean(getPreferenceKey(feature))){ - preferedFeatures.add(feature); - } - } - - return preferedFeatures; - } - - /** - * - * @param preferredFeatureList - */ - public static void setPreferredFeatures(List preferredFeatureList) { - - for (Feature feature : CdmStore.getFeatures()) { - getPrefStore().setValue(getPreferenceKey(feature), preferredFeatureList.contains(feature)); - } - } - - /** - * Construct a unique key using Feature's Uuid - * - * @param feature - * @return - */ - private static String getPreferenceKey(Feature feature) { - return FEATURE_PREFERENCE - . concat(".") - . concat(feature.getUuid().toString()); - } - - /** - * Returns a Set of the Ranks that the user has chosen - * to have shown in preferences. - *

- *

- * Ranks are shown unless otherwise specified. - *

- * @return - */ - public static List getPreferredRanks() { - - ArrayList preferedRanks = new ArrayList(); - - for (Rank rank : CdmStore.getRanks()) { - if(getPrefStore().getBoolean(getPreferenceKey(rank))){ - preferedRanks.add(rank); - } - } - - return preferedRanks; - } - /** - * - * @param preferedRankList - */ - public static void setPreferredRanks(List preferedRankList) { - for (Rank rank : CdmStore.getRanks()) { - getPrefStore().setValue(getPreferenceKey(rank), preferedRankList.contains(rank)); - } - } - - - - /** - * Construct a unique key using Rank's Uuid - * - * @param feature - * @return - */ - private static String getPreferenceKey(Rank rank) { - return Resources.RANK_PREFERENCE - . concat(".") - . concat(rank.getUuid().toString()); - } - /** * Returns a new name object that conforms to the nomenclatural * code specified in user preferences. @@ -222,25 +131,61 @@ public class PreferencesUtil { } /** - * Appends the code (i.e. ICBN or ICZN) specified in the user preferences - * to a string. The result is separated by a period: "key.ICBN". + * Generic method to get term preferences for a term vocabulary * - * @param key + * @param + * @param initialFeatures * @return */ - public static String concatCodeMessageSuffix(String key) { - String code = getNameCodePreference(); - return key + "." + code; + public static List getPreferredTerms(Set initialFeatures){ + List preferredTerms = new ArrayList(); + + for (T term : initialFeatures){ + if(getPreferenceStore().getBoolean(getPreferenceKey(term))){ + preferredTerms.add(term); + } + } + + return preferredTerms; } + + /** @return a List containing user preferred Feature terms */ + public static List getPreferredFeatures() { return getPreferredTerms(VocabularyStore.getFeatures());} + /** @return a List containing user preferred Rank terms */ + public static List getPreferredRanks() { return getPreferredTerms(VocabularyStore.getRanks());} + + /** @return a List containing user preferred PresenceAbsenceTermBase terms */ + public static List>> getPreferredPresenceAbsenceTerms(){ return getPreferredTerms(VocabularyStore.getPresenceAbsenceTerms());} + + /** @return a List containing user preferred NomenclaturalStatusType terms */ + public static List getPreferredNomenclaturalStatusTypes(){ return getPreferredTerms(VocabularyStore.getNomenclaturalStatusTypes());} + + /** @return a List containing user preferred NameRelationshipType terms */ + public static List getPreferredNameRelationshipTypes(){ return getPreferredTerms(VocabularyStore.getNameRelationshipTypes());} + + /** + * Generic method to set term preferences * - * @return + * @param preferredTerms + * @param initalTerms */ - public static SourceViewerDecorationSupport getDecorationSupport() { - if (decorationSupport == null) { - decorationSupport = new SourceViewerDecorationSupport(null, null, null, EditorsUI.getSharedTextColors()); + public static void setPreferredTerms(List preferredTerms, Set initalTerms){ + for(TermBase term : initalTerms){ + getPreferenceStore().setValue(getPreferenceKey(term), preferredTerms.contains(term)); } - return decorationSupport; + } + + /** + * Construct a unique key using the terms uuid + * + * @param term + * @return + */ + private static String getPreferenceKey(TermBase term) { + return term.getClass().getName() + . concat(".") + . concat(term.getUuid().toString()); } } diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/RankMenuPreferences.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/RankMenuPreferences.java index 58b12d421..475078656 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/RankMenuPreferences.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/RankMenuPreferences.java @@ -8,14 +8,10 @@ */ package eu.etaxonomy.taxeditor.preference; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IWorkbenchPreferencePage; import eu.etaxonomy.cdm.model.name.Rank; -import eu.etaxonomy.taxeditor.store.CdmStore; +import eu.etaxonomy.taxeditor.store.VocabularyStore; /** * Allows the user to choose which Ranks to display in the @@ -26,35 +22,15 @@ import eu.etaxonomy.taxeditor.store.CdmStore; * @version 1.0 * @author n.hoffmann */ -public class RankMenuPreferences extends AbstractMenuPreferences implements +public class RankMenuPreferences extends AbstractMenuPreferences implements IWorkbenchPreferencePage { public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.preferences.ranks"; public RankMenuPreferences() { - super(CdmStore.getRanks(), PreferencesUtil.getPreferredRanks(), "Rank Preferences", "Choose which ranks to display in the property sheet drop-down menu."); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.preference.PreferencePage#performOk() - */ - public boolean performOk() { - - List preferredRanks = new ArrayList(); - for (Object element : getTableViewer().getCheckedElements()){ - preferredRanks.add((Rank) element); - } - - PreferencesUtil.setPreferredRanks(preferredRanks); - - return true; + super(VocabularyStore.getRanks(), + "Rank Preferences", + "Choose which ranks to display in the property sheet drop-down menu."); } - /* (non-Javadoc) - * @see eu.etaxonomy.taxeditor.preference.AbstractMenuPreferences#createButtons(org.eclipse.swt.widgets.Composite) - */ - @Override - protected void createButtons(Composite buttonContainer) { - // not used - } } diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureWizard.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureWizard.java index 2f38892db..11c22774d 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureWizard.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureWizard.java @@ -14,8 +14,10 @@ import org.apache.log4j.Logger; import org.eclipse.jface.wizard.Wizard; import eu.etaxonomy.cdm.api.conversation.ConversationHolder; +import eu.etaxonomy.cdm.model.common.VocabularyEnum; import eu.etaxonomy.cdm.model.description.Feature; import eu.etaxonomy.taxeditor.store.CdmStore; +import eu.etaxonomy.taxeditor.store.VocabularyStore; /** * @author n.hoffmann @@ -62,9 +64,9 @@ public class FeatureWizard extends Wizard { ConversationHolder conversation = CdmStore.NewTransactionalConversation(); if(editMode){ - CdmStore.updateFeature(feature); + VocabularyStore.updateVocabulary(VocabularyEnum.Feature); }else{ - CdmStore.saveFeature(feature); + VocabularyStore.saveTerm(feature, VocabularyEnum.Feature); } conversation.commit(true); diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java index 083de428a..708e65c65 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java @@ -12,8 +12,6 @@ package eu.etaxonomy.taxeditor.store; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; -import java.util.Set; -import java.util.SortedSet; import java.util.UUID; import org.apache.log4j.Logger; @@ -25,22 +23,12 @@ import eu.etaxonomy.cdm.api.service.ILocationService; import eu.etaxonomy.cdm.api.service.INameService; import eu.etaxonomy.cdm.api.service.IReferenceService; import eu.etaxonomy.cdm.api.service.ITaxonService; -import eu.etaxonomy.cdm.api.service.ITermService; import eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator; import eu.etaxonomy.cdm.api.service.config.impl.TaxonServiceConfiguratorImpl; import eu.etaxonomy.cdm.database.DbSchemaValidation; import eu.etaxonomy.cdm.database.ICdmDataSource; -import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; import eu.etaxonomy.cdm.model.common.IdentifiableEntity; import eu.etaxonomy.cdm.model.common.Language; -import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary; -import eu.etaxonomy.cdm.model.common.TermVocabulary; -import eu.etaxonomy.cdm.model.common.VocabularyEnum; -import eu.etaxonomy.cdm.model.description.Feature; -import eu.etaxonomy.cdm.model.name.NameRelationshipType; -import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType; -import eu.etaxonomy.cdm.model.name.Rank; -import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus; import eu.etaxonomy.cdm.model.name.TaxonNameBase; import eu.etaxonomy.cdm.model.reference.Article; import eu.etaxonomy.cdm.model.reference.Book; @@ -48,7 +36,6 @@ import eu.etaxonomy.cdm.model.reference.BookSection; import eu.etaxonomy.cdm.model.reference.Generic; import eu.etaxonomy.cdm.model.reference.ReferenceBase; import eu.etaxonomy.cdm.model.taxon.Taxon; -import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; import eu.etaxonomy.cdm.model.taxon.TaxonomicTree; import eu.etaxonomy.cdm.persistence.query.MatchMode; import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository; @@ -132,51 +119,16 @@ public class CdmStore{ } } - public Set getConceptRelationshipTypes() { - Set conceptRelationshipTypes = getTaxonRelationshipTypes().getTerms(); - // remove these two relations as they are considered standard taxon relations - conceptRelationshipTypes.remove(TaxonRelationshipType.MISAPPLIED_NAME_FOR()); - conceptRelationshipTypes.remove(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()); - - return conceptRelationshipTypes; - } public ReferenceBase getDefaultSec() { // TODO why is this returning null? and of course, replace w the real deal return applicationController.getReferenceService().getReferenceByUuid( UUID.fromString("f3593c18-a8d2-4e51-bdad-0befbf8fb2d1")); } - - private TermVocabulary getFeaturesInternal() { - return applicationController.getTermService().getVocabulary(VocabularyEnum.Feature); - } - public static SortedSet getFeatures() { - return getDefault().getFeaturesInternal().getTermsOrderedByLabels(getDefaultLanguage()); - } - - public SortedSet getNameRelationshipTypes() { - return applicationController.getTermService().getVocabulary(VocabularyEnum.NameRelationshipType).getTermsOrderedByLabels(Language.DEFAULT()); - } - - public TermVocabulary getNomenclaturalStatusTypesInternal() { - return applicationController.getTermService().getVocabulary(VocabularyEnum.NomenclaturalStatusType); - } - - public static Set getNomenclaturalStatusTypes(){ - // TODO sort types - return getDefault().getNomenclaturalStatusTypesInternal().getTerms(); - } - - private OrderedTermVocabulary getRanksInternal(){ - TermVocabulary vocabulary = applicationController.getTermService().getVocabulary(VocabularyEnum.Rank); - return HibernateProxyHelper.deproxy(vocabulary, OrderedTermVocabulary.class); - } - - public static SortedSet getRanks(){ - return getDefault().getRanksInternal().getOrderedTerms(null); - } - + /** + * @deprecated use taxonomic tree instead + */ public List getRootTaxa() { boolean onlyWithChildren = false; boolean withMisapplications = true; @@ -191,26 +143,7 @@ public class CdmStore{ public List getTaxonomicTrees() { return applicationController.getTaxonService().getAllTaxonomicTrees(10000, 0); } - - public OrderedTermVocabulary getTaxonRelationshipTypes() { - TermVocabulary vocabulary = HibernateProxyHelper.deproxy - (applicationController.getTermService().getVocabulary(VocabularyEnum.TaxonRelationshipType), TermVocabulary.class); - return (OrderedTermVocabulary) vocabulary; - } - - public TermVocabulary getSpecimenTypeDesignationStatus() { - return applicationController.getTermService().getVocabulary(VocabularyEnum.SpecimenTypeDesignationStatus); - } - - - public UUID saveTaxon(Taxon taxon) { - return applicationController.getTaxonService().save(taxon); - } - - public void setApplicationController( - CdmApplicationController applicationController) { - this.applicationController = applicationController; - } + private CdmApplicationController getApplicationControllerInternal(){ return applicationController; @@ -262,25 +195,20 @@ public class CdmStore{ return getDefault().getGlobalReadOnlyConversation(); } - public static ITaxonService getTaxonService(){ - return getDefault().getApplicationController().getTaxonService(); - } + + /* + * EXPOSING SERVICES + */ - public static INameService getNameService(){ - return getDefault().getApplicationController().getNameService(); - } + public static ITaxonService getTaxonService(){ return getDefault().getApplicationControllerInternal().getTaxonService();} - public static IReferenceService getReferenceService(){ - return getDefault().getApplicationController().getReferenceService(); - } + public static INameService getNameService(){ return getDefault().getApplicationControllerInternal().getNameService();} - public static ILocationService getLocationService(){ - return getDefault().getApplicationController().getLocationService(); - } + public static IReferenceService getReferenceService(){ return getDefault().getApplicationControllerInternal().getReferenceService();} + + public static ILocationService getLocationService(){ return getDefault().getApplicationControllerInternal().getLocationService();} - public static ProviderManager getAuthenticationManager() { - return getDefault().getApplicationController().getAuthenticationManager(); - } + public static ProviderManager getAuthenticationManager() { return getDefault().getApplicationControllerInternal().getAuthenticationManager();} /** @@ -347,21 +275,6 @@ public class CdmStore{ } return resultsList; } - - - public static List getLanguages() { - ITermService termService = getDefault().getApplicationController().getTermService(); - ArrayList languages = new ArrayList(); - for (Language language : termService.getLanguageVocabulary()) { - languages.add(language); - } - - // TODO sort languages - -// languages.add(Language.ENGLISH()); -// languages.add(Language.GERMAN()); - return languages; - } /** * FIXME mock @@ -372,13 +285,6 @@ public class CdmStore{ return Language.ENGLISH(); } - /** - * @return - */ - private static String getApplicationContextBean() { - return DEFAULT_APPLICATION_CONTEXT; - } - /** * @return */ @@ -394,25 +300,4 @@ public class CdmStore{ return nomReferenceTypeMap; } - /** - * @param feature - */ - public static void saveFeature(Feature feature) { - TermVocabulary vocabulary = getDefault().getFeaturesInternal(); - - vocabulary.addTerm(feature); - - getDefault().getApplicationController().getTermService().saveTermVocabulary(vocabulary); - } - - /** - * TODO make this more generic - * - * @param feature - */ - public static void updateFeature(Feature feature) { - TermVocabulary vocabulary = getDefault().getFeaturesInternal(); - - getDefault().getApplicationController().getTermService().saveTermVocabulary(vocabulary); - } } diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/store/VocabularyStore.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/store/VocabularyStore.java new file mode 100644 index 000000000..fd81cac29 --- /dev/null +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/store/VocabularyStore.java @@ -0,0 +1,205 @@ +// $Id$ +/** +* Copyright (C) 2007 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ + +package eu.etaxonomy.taxeditor.store; + +import java.util.Set; +import java.util.SortedSet; + +import org.apache.log4j.Logger; + +import eu.etaxonomy.cdm.api.application.CdmApplicationController; +import eu.etaxonomy.cdm.api.service.ITermService; +import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; +import eu.etaxonomy.cdm.model.common.DefinedTermBase; +import eu.etaxonomy.cdm.model.common.Language; +import eu.etaxonomy.cdm.model.common.OrderedTermBase; +import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary; +import eu.etaxonomy.cdm.model.common.TermVocabulary; +import eu.etaxonomy.cdm.model.common.VocabularyEnum; +import eu.etaxonomy.cdm.model.description.Feature; +import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase; +import eu.etaxonomy.cdm.model.name.NameRelationshipType; +import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType; +import eu.etaxonomy.cdm.model.name.Rank; +import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus; +import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; + +/** + * All vocabularies may be accessed through this store. + * Note: This is for internal use. When using vocabularies in the UI, try to use the preferred terms from + * PreferenceUtil + * + * @author n.hoffmann + * @created 25.06.2009 + * @version 1.0 + */ +public class VocabularyStore { + private static final Logger logger = Logger.getLogger(VocabularyStore.class); + + /** + * The singleton instance + */ + private static VocabularyStore instance; + + /** + * Retrieve the singleton instance + * + * @return + */ + private static synchronized VocabularyStore getDefault(){ + if(instance == null){ + instance = new VocabularyStore(); + } + return instance; + } + + /** + * + * @return + */ + public static SortedSet getSpecimenTypeDesignationStatus() { + SortedSet specimenTypeDesignationStatus = getDefault().getTermVocabulary(VocabularyEnum.SpecimenTypeDesignationStatus).getTermsOrderedByLabels(getDefaultLanguage()); + return specimenTypeDesignationStatus; + } + + /** + * + * @return + */ + public static SortedSet getTaxonRelationshipTypes(){ + SortedSet taxonRelationshipTypes = getDefault().getOrderedTermVocabulary(VocabularyEnum.TaxonRelationshipType).getOrderedTerms(); + return taxonRelationshipTypes; + } + + /** + * + * @return + */ + public static SortedSet getConceptRelationshipTypes() { + SortedSet conceptRelationshipTypes = getTaxonRelationshipTypes(); + // remove these two relations as they are considered standard taxon relations + conceptRelationshipTypes.remove(TaxonRelationshipType.MISAPPLIED_NAME_FOR()); + conceptRelationshipTypes.remove(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN()); + + return conceptRelationshipTypes; + } + + /** + * + * @return + */ + public static SortedSet getLanguages(){ + SortedSet languages = getDefault().getTermVocabulary(VocabularyEnum.Language).getTermsOrderedByLabels(getDefaultLanguage()); + return languages; + } + + /** + * + * @return + */ + public static SortedSet getFeatures() { + SortedSet features = getDefault().getTermVocabulary(VocabularyEnum.Feature).getTermsOrderedByLabels(getDefaultLanguage()); + return features; + + } + + /** + * + * @return + */ + public static SortedSet getNameRelationshipTypes() { + SortedSet nameRelationshipTypes = getDefault().getTermVocabulary(VocabularyEnum.NameRelationshipType).getTermsOrderedByLabels(getDefaultLanguage()); + return nameRelationshipTypes; + } + + /** + * + * @return + */ + public static Set getNomenclaturalStatusTypes(){ + // TODO sort types + Set nomenclaturalStatusTypes = getDefault().getTermVocabulary(VocabularyEnum.NomenclaturalStatusType).getTermsOrderedByLabels(getDefaultLanguage()); + return nomenclaturalStatusTypes; + } + + /** + * Retrieve all ranks from data store. + * + * @return + */ + public static SortedSet getRanks(){ + SortedSet ranks = getDefault().getOrderedTermVocabulary(VocabularyEnum.Rank).getOrderedTerms(); + return ranks; + } + + + /** + * Retrieve all presence and absence terms from data store. + * + * @return + */ + public static SortedSet>> getPresenceAbsenceTerms() { + SortedSet presenceAbsenceTerms = getDefault().getTermVocabulary(VocabularyEnum.PresenceTerm).getTermsOrderedByLabels(getDefaultLanguage()); + presenceAbsenceTerms.addAll(getDefault().getTermVocabulary(VocabularyEnum.AbsenceTerm).getTermsOrderedByLabels(getDefaultLanguage())); + + return presenceAbsenceTerms; + } + + /*************** save methods ******************************/ + /** + * Adds a term to a vocabulary + * + * @param feature + */ + public static void saveTerm(DefinedTermBase term, VocabularyEnum vocabularyType) { + TermVocabulary vocabulary = getDefault().getTermVocabulary(vocabularyType); + + vocabulary.addTerm(term); + + getDefault().getTermService().saveTermVocabulary(vocabulary); + } + + /** + * Save a vacabulary to data store + * + * @param feature + */ + public static void updateVocabulary(VocabularyEnum vocabularyType) { + TermVocabulary vocabulary = getDefault().getTermVocabulary(vocabularyType); + + getDefault().getTermService().saveTermVocabulary(vocabulary); + } + + + + /*************** internal methods **************************/ + + private static Language getDefaultLanguage(){ + return CdmStore.getDefaultLanguage(); + } + + private OrderedTermVocabulary getOrderedTermVocabulary(VocabularyEnum vocabularyType){ + TermVocabulary vocabulary = getTermVocabulary(vocabularyType); + return HibernateProxyHelper.deproxy(vocabulary, OrderedTermVocabulary.class); + } + + private TermVocabulary getTermVocabulary(VocabularyEnum vocabularyType){ + return getTermService().getVocabulary(vocabularyType); + } + + private ITermService getTermService(){ + return getApplicationController().getTermService(); + } + + private CdmApplicationController getApplicationController(){ + return CdmStore.getApplicationController(); + } +} diff --git a/taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/CdmStoreTest.java b/taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/CdmStoreTest.java index 4479208eb..101de028d 100644 --- a/taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/CdmStoreTest.java +++ b/taxeditor-store/src/test/java/eu/etaxonomy/taxeditor/store/CdmStoreTest.java @@ -57,10 +57,8 @@ public class CdmStoreTest /*extends CdmIntegrationTest */{ @Test //@DataSet("CdmStoreTest.xml") @Ignore - public void testGetRootTaxa(){ - List rootTaxa = cdmStore.getRootTaxa(); - - Assert.assertNotNull(rootTaxa); + public void testGetTaxonomicTrees(){ + } /** @@ -71,7 +69,7 @@ public class CdmStoreTest /*extends CdmIntegrationTest */{ @Ignore public void testGetConceptRelationshipTypes(){ conversation.bind(); - Set conceptRelationshipTypes = cdmStore.getConceptRelationshipTypes(); + Set conceptRelationshipTypes = VocabularyStore.getConceptRelationshipTypes(); Assert.assertNotNull(conceptRelationshipTypes); } } -- 2.34.1