--- /dev/null
+// $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) {
+
+ }
+
+
+}
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
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
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
\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