matching is now configurable in the editor
authorn.hoffmann <n.hoffmann@localhost>
Thu, 28 Jan 2010 14:20:05 +0000 (14:20 +0000)
committern.hoffmann <n.hoffmann@localhost>
Thu, 28 Jan 2010 14:20:05 +0000 (14:20 +0000)
.gitattributes
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/MatchingPreferences.java [new file with mode: 0644]
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java

index 82ce50aa13bfbda44a01ac9ff61729229d419e72..37bffd995a5a482b7c12a33aa36e7f3e7ce58023 100644 (file)
@@ -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 (file)
index 0000000..25cb350
--- /dev/null
@@ -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) {
+               
+       }
+       
+       
+}
index f8a0ebb517be0eb631025bf8ef2c6718215daae1..30a0e4b9ed02c026a277eac55fac8f90871d6c51 100644 (file)
@@ -36,7 +36,10 @@ import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
 import eu.etaxonomy.cdm.model.name.Rank;\r
 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;\r
 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;\r
-import eu.etaxonomy.cdm.persistence.query.MatchMode;\r
+import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy;\r
+import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;\r
+import eu.etaxonomy.cdm.strategy.match.MatchException;\r
+import eu.etaxonomy.cdm.strategy.match.MatchMode;\r
 import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;\r
 import eu.etaxonomy.taxeditor.store.VocabularyStore;\r
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;\r
@@ -66,6 +69,8 @@ public class PreferencesUtil {
        public static final String HIDE_BULKEDITOR_INFO = "bulkeditorInfo.hide";\r
 \r
        public static final String EDIT_MARKER_TYPE_PREFIX = "editMarkerType";\r
+       \r
+       public static final String MATCH_STRATEGY_PREFIX = "matchStrategy.";\r
                \r
        /**\r
         * \r
@@ -117,6 +122,72 @@ public class PreferencesUtil {
                return EDIT_MARKER_TYPE_PREFIX + "." + input.getClass().getName() + "." + markerType.getUuid().toString();\r
        }\r
        \r
+       /**\r
+        * Get the match strategy for the given class that was stored in preferences\r
+        * or the default strategy if it was not stored in preferences\r
+        * \r
+        * @param clazz\r
+        * @return\r
+        */\r
+       public static IMatchStrategy getMatchStrategy(Class clazz){\r
+               String className = clazz.getName();\r
+               if(getPreferenceStore().getBoolean(MATCH_STRATEGY_PREFIX + className)){\r
+                       IMatchStrategy matchStrategy = getDefaultMatchStrategy(clazz);\r
+                       \r
+                       for(String fieldName : matchStrategy.getMatchFieldPropertyNames()){\r
+                               String matchModeName = getPreferenceStore().getString(getMatchStrategyFieldName(className, fieldName));\r
+                               MatchMode matchMode = MatchMode.valueOf(matchModeName);\r
+                               try {\r
+                                       matchStrategy.setMatchMode(fieldName, matchMode);\r
+                               } catch (MatchException e) {\r
+                                       logger.error(e);\r
+                                       throw new RuntimeException(e);\r
+                               }\r
+                       }\r
+                       \r
+                       return matchStrategy;\r
+               }\r
+               return getDefaultMatchStrategy(clazz);\r
+       }\r
+       \r
+       /**\r
+        * Stores a matchStrategy into the preference store.\r
+        * \r
+        * @param clazz\r
+        */\r
+       public static void setMatchStrategy(IMatchStrategy matchStrategy){\r
+               String className = matchStrategy.getMatchClass().getName();\r
+               getPreferenceStore().setValue(MATCH_STRATEGY_PREFIX + className, true);\r
+               \r
+               Set<String> matchFields = matchStrategy.getMatchFieldPropertyNames();\r
+               \r
+               for(String fieldName : matchFields){\r
+                       getPreferenceStore().setValue(getMatchStrategyFieldName(className, fieldName),\r
+                                       matchStrategy.getMatchMode(fieldName).name());\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Helper method to create the preference property for a match field.\r
+        * \r
+        * @param className\r
+        * @param fieldName\r
+        * @return\r
+        */\r
+       private static String getMatchStrategyFieldName(String className, String fieldName){\r
+               return MATCH_STRATEGY_PREFIX + className  + "." +  fieldName;\r
+       }\r
+       \r
+       /**\r
+        * Returns the default match strategy for a given class.\r
+        * \r
+        * @param clazz\r
+        * @return\r
+        */\r
+       public static IMatchStrategy getDefaultMatchStrategy(Class clazz){\r
+               return DefaultMatchStrategy.NewInstance(clazz);\r
+       }\r
+       \r
        /**\r
         * Generic method to get term preferences for a term vocabulary\r
         * \r
@@ -271,7 +342,7 @@ public class PreferencesUtil {
                \r
                // DEFAULT VALUES               \r
                // match mode default only\r
-               configurator.setMatchMode(MatchMode.BEGINNING);\r
+               configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.BEGINNING);\r
                // i don't know what happens to sec at the moment\r
                configurator.setSec(null);\r
                // we set page number and size here as this should always be unlimited\r