From bccd16ea203e8cb954b41a837e0b72c761486f53 Mon Sep 17 00:00:00 2001 From: "n.hoffmann" Date: Thu, 28 Jan 2010 14:20:05 +0000 Subject: [PATCH] matching is now configurable in the editor --- .gitattributes | 1 + .../preference/MatchingPreferences.java | 52 +++++++++++++ .../taxeditor/preference/PreferencesUtil.java | 75 ++++++++++++++++++- 3 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/MatchingPreferences.java diff --git a/.gitattributes b/.gitattributes index 82ce50aa1..37bffd995 100644 --- a/.gitattributes +++ b/.gitattributes @@ -616,6 +616,7 @@ taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/CdmPreferences.j taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/DescriptionPreferences.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/MatchingPreferences.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/NomenclaturalCodePreferences.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/TaxonomicEditorGeneralPreferences.java -text diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/MatchingPreferences.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/MatchingPreferences.java new file mode 100644 index 000000000..25cb35094 --- /dev/null +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/MatchingPreferences.java @@ -0,0 +1,52 @@ +// $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.apache.log4j.Logger; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +/** + * @author n.hoffmann + * @created Jan 22, 2010 + * @version 1.0 + */ +public class MatchingPreferences extends PreferencePage implements + IWorkbenchPreferencePage { + private static final Logger logger = Logger + .getLogger(MatchingPreferences.class); + + /* (non-Javadoc) + * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Control createContents(Composite parent) { + Composite container = new Composite(parent, SWT.NULL); + container.setLayout(new GridLayout()); + + // + return container; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) + */ + public void init(IWorkbench workbench) { + + } + + +} 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 f8a0ebb51..30a0e4b9e 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 @@ -36,7 +36,10 @@ 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; -import eu.etaxonomy.cdm.persistence.query.MatchMode; +import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy; +import eu.etaxonomy.cdm.strategy.match.IMatchStrategy; +import eu.etaxonomy.cdm.strategy.match.MatchException; +import eu.etaxonomy.cdm.strategy.match.MatchMode; import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper; import eu.etaxonomy.taxeditor.store.VocabularyStore; import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; @@ -66,6 +69,8 @@ public class PreferencesUtil { public static final String HIDE_BULKEDITOR_INFO = "bulkeditorInfo.hide"; public static final String EDIT_MARKER_TYPE_PREFIX = "editMarkerType"; + + public static final String MATCH_STRATEGY_PREFIX = "matchStrategy."; /** * @@ -117,6 +122,72 @@ public class PreferencesUtil { return EDIT_MARKER_TYPE_PREFIX + "." + input.getClass().getName() + "." + markerType.getUuid().toString(); } + /** + * Get the match strategy for the given class that was stored in preferences + * or the default strategy if it was not stored in preferences + * + * @param clazz + * @return + */ + public static IMatchStrategy getMatchStrategy(Class clazz){ + String className = clazz.getName(); + if(getPreferenceStore().getBoolean(MATCH_STRATEGY_PREFIX + className)){ + IMatchStrategy matchStrategy = getDefaultMatchStrategy(clazz); + + for(String fieldName : matchStrategy.getMatchFieldPropertyNames()){ + String matchModeName = getPreferenceStore().getString(getMatchStrategyFieldName(className, fieldName)); + MatchMode matchMode = MatchMode.valueOf(matchModeName); + try { + matchStrategy.setMatchMode(fieldName, matchMode); + } catch (MatchException e) { + logger.error(e); + throw new RuntimeException(e); + } + } + + return matchStrategy; + } + return getDefaultMatchStrategy(clazz); + } + + /** + * Stores a matchStrategy into the preference store. + * + * @param clazz + */ + public static void setMatchStrategy(IMatchStrategy matchStrategy){ + String className = matchStrategy.getMatchClass().getName(); + getPreferenceStore().setValue(MATCH_STRATEGY_PREFIX + className, true); + + Set matchFields = matchStrategy.getMatchFieldPropertyNames(); + + for(String fieldName : matchFields){ + getPreferenceStore().setValue(getMatchStrategyFieldName(className, fieldName), + matchStrategy.getMatchMode(fieldName).name()); + } + } + + /** + * Helper method to create the preference property for a match field. + * + * @param className + * @param fieldName + * @return + */ + private static String getMatchStrategyFieldName(String className, String fieldName){ + return MATCH_STRATEGY_PREFIX + className + "." + fieldName; + } + + /** + * Returns the default match strategy for a given class. + * + * @param clazz + * @return + */ + public static IMatchStrategy getDefaultMatchStrategy(Class clazz){ + return DefaultMatchStrategy.NewInstance(clazz); + } + /** * Generic method to get term preferences for a term vocabulary * @@ -271,7 +342,7 @@ public class PreferencesUtil { // DEFAULT VALUES // match mode default only - configurator.setMatchMode(MatchMode.BEGINNING); + configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.BEGINNING); // i don't know what happens to sec at the moment configurator.setSec(null); // we set page number and size here as this should always be unlimited -- 2.34.1