taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java -text
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/TaxonomicEditorGeneralPreferences.java -text
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/TaxonomicPreferences.java -text
+taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/matching/AbstractMatchingPreferences.java -text
+taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/matching/NonViralNameMatchingPreference.java -text
+taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/matching/ReferenceMatchingPreference.java -text
+taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/matching/TeamOrPersonMatchingPreference.java -text
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/AbstractMenuPreferences.java -text
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/DistributionStatusMenuPreferences.java -text
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/ExtensionTypeMenuPreferences.java -text
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
import eu.etaxonomy.cdm.model.name.NonViralName;
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
-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.preference.PreferencesUtil;
/**
* This class defines the MatchStrategies that will be used by the ParseHandler.
*/
public class MatchStrategyConfigurator {
- /**
- * Singleton instance
- */
- private static MatchStrategyConfigurator instance = new MatchStrategyConfigurator();
-
- private IMatchStrategy nonViralNameMatchStrategy;
- private IMatchStrategy teamOrPersonMatchStrategy;
- private IMatchStrategy referenceMatchStrategy;
-
/**
*
* @return
* @throws MatchException
*/
public static IMatchStrategy NonViralNameMatchStrategy() throws MatchException{
- return instance.getNonViralNameMatchStrategy();
+ return PreferencesUtil.getMatchStrategy(NonViralName.class);
}
/**
* @throws MatchException
*/
public static IMatchStrategy TeamOrPersonMatchStrategy() throws MatchException{
- return instance.getTeamOrPersonMatchStrategy();
+ return PreferencesUtil.getMatchStrategy(TeamOrPersonBase.class);
}
/**
* @throws MatchException
*/
public static IMatchStrategy ReferenceMatchStrategy() throws MatchException{
- return instance.getReferenceMatchStrategy();
- }
-
- /**
- * @param strategy the nonViralNameMatchStrategy to set
- */
- private void doSetNonViralNameMatchStrategy(IMatchStrategy strategy) {
- this.nonViralNameMatchStrategy = strategy;
- }
-
- /**
- * @param strategy the nonViralNameMatchStrategy to set
- */
- public static void setNonViralNameMatchStrategy(IMatchStrategy strategy) {
- instance.doSetNonViralNameMatchStrategy(strategy);
- }
-
- /**
- * @param strategy the teamOrPersonMatchStrategy to set
- */
- private void doSetTeamOrPersonMatchStrategy(IMatchStrategy strategy) {
- this.teamOrPersonMatchStrategy = strategy;
- }
-
- /**
- * @param strategy the teamOrPersonMatchStrategy to set
- */
- public static void setTeamOrPersonMatchStrategy(IMatchStrategy strategy) {
- instance.doSetTeamOrPersonMatchStrategy(strategy);
- }
-
- /**
- * @param strategy the referenceMatchStrategy to set
- */
- private void doSetReferenceMatchStrategy(IMatchStrategy strategy) {
- this.referenceMatchStrategy = strategy;
- }
-
- /**
- * @param strategy the referenceMatchStrategy to set
- */
- public static void setReferenceMatchStrategy(IMatchStrategy strategy) {
- instance.doSetReferenceMatchStrategy(strategy);
+ return PreferencesUtil.getMatchStrategy(ReferenceBase.class);
}
- /**
- * @return the nonViralNameMatchStrategy
- * @throws MatchException
- */
- private IMatchStrategy getNonViralNameMatchStrategy() throws MatchException {
- if(nonViralNameMatchStrategy == null){
- nonViralNameMatchStrategy = getDefaultNonViralNameMatchStrategy();
- }
- return nonViralNameMatchStrategy;
- }
-
/**
*
* @return
* @throws MatchException
*/
public static IMatchStrategy getDefaultNonViralNameMatchStrategy() throws MatchException{
- DefaultMatchStrategy strategy = DefaultMatchStrategy.NewInstance(NonViralName.class);
+ IMatchStrategy strategy = PreferencesUtil.getDefaultMatchStrategy(NonViralName.class);
strategy.setMatchMode("nomenclaturalReference", MatchMode.IGNORE);
strategy.setMatchMode("combinationAuthorTeam", MatchMode.IGNORE);
return strategy;
}
- /**
- * @return the teamOrPersonMatchStrategy
- */
- private IMatchStrategy getTeamOrPersonMatchStrategy() throws MatchException{
- if(teamOrPersonMatchStrategy == null){
- teamOrPersonMatchStrategy = getDefaultTeamOrPersonMatchStrategy();
- }
- return teamOrPersonMatchStrategy;
- }
-
/**
*
* @return
*/
public static IMatchStrategy getDefaultTeamOrPersonMatchStrategy() throws MatchException{
- IMatchStrategy strategy = DefaultMatchStrategy.NewInstance(TeamOrPersonBase.class);
+ IMatchStrategy strategy = PreferencesUtil.getDefaultMatchStrategy(TeamOrPersonBase.class);
return strategy;
}
- /**
- * @return the referenceMatchStrategy
- */
- private IMatchStrategy getReferenceMatchStrategy() throws MatchException{
- if(referenceMatchStrategy == null){
- referenceMatchStrategy = getDefaultReferenceMatchStrategy();
- }
- return referenceMatchStrategy;
- }
-
public static IMatchStrategy getDefaultReferenceMatchStrategy() throws MatchException{
- DefaultMatchStrategy strategy = DefaultMatchStrategy.NewInstance(ReferenceBase.class);
+ IMatchStrategy strategy = PreferencesUtil.getDefaultMatchStrategy(ReferenceBase.class);
return strategy;
}
+
+ /**
+ * @param matchStrategy
+ */
+ public static void setMatchStrategy(IMatchStrategy matchStrategy) {
+ PreferencesUtil.setMatchStrategy(matchStrategy);
+ }
}
--- /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.matching;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.eclipse.jface.preference.PreferencePage;
+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.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
+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.parser.MatchStrategyConfigurator;
+
+/**
+ * @author n.hoffmann
+ * @created Jan 22, 2010
+ * @version 1.0
+ */
+public abstract class AbstractMatchingPreferences<T extends IdentifiableEntity> extends PreferencePage implements
+ IWorkbenchPreferencePage {
+ private static final Logger logger = Logger
+ .getLogger(AbstractMatchingPreferences.class);
+
+ /**
+ * Fields that will be excluded from the display
+ */
+ private static final String ExcludePattern = "serialVersionUID|logger|allFields|ajc.*|id|updated|updatedBy|created|createdBy|uuid" +
+ "|parsingProblem|problemStarts|problemEnds|PROTECTED|NOT_PROTECTED|propertyChangeSupport";
+
+ protected IMatchStrategy matchStrategy;
+
+ protected Class<T> clazz;
+
+ private List<MatchMode> matchModeList;
+
+ protected Map<String, Combo> matchModeCombos = new HashMap<String, Combo>();
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected Control createContents(Composite parent) {
+ final Composite composite = new Composite(parent, SWT.NULL);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 2;
+ composite.setLayout(gridLayout);
+
+
+ for(String fieldName : getFieldNames()){
+ createFieldWidget(composite, fieldName);
+ }
+
+ return composite;
+ }
+
+ /**
+ * Creates a widget for a field consisting of the label and a combo
+ *
+ * @see {@link #createMatchModeCombo(Composite, String, MatchMode)}
+ * @param composite
+ * @param fieldName
+ */
+ private void createFieldWidget(Composite parent, String fieldName) {
+ CLabel label = new CLabel(parent, SWT.NONE);
+ label.setText(fieldName);
+
+ MatchMode matchMode = matchStrategy.getMatchMode(fieldName);
+
+ createMatchModeCombo(parent, fieldName, matchMode);
+ }
+
+ /**
+ * Creates a combo for a field with the currently selected match mode for that field preselected
+ *
+ * @param parent
+ * @param matchMode
+ */
+ private void createMatchModeCombo(Composite parent, String fieldName, MatchMode selectedMatchMode) {
+ Combo matchModeCombo = new Combo(parent, SWT.NULL);
+
+ for (MatchMode matchMode : getMatchModeList()) {
+ matchModeCombo.add(matchMode.name());
+ }
+
+ int index = getMatchModeList().indexOf(selectedMatchMode);
+
+ matchModeCombo.select(index);
+
+ matchModeCombo.addSelectionListener(new MatchModeComboSelectionListener(matchModeCombo, fieldName));
+
+ matchModeCombos.put(fieldName, matchModeCombo);
+ }
+
+ /**
+ * This listener updates the cache strategy when a value was changed in one of the combos
+ *
+ * @author n.hoffmann
+ * @created Jan 28, 2010
+ * @version 1.0
+ */
+ private class MatchModeComboSelectionListener extends SelectionAdapter{
+
+ private Combo matchModeCombo;
+ private String fieldName;
+
+ MatchModeComboSelectionListener(Combo matchModeCombo, String fieldName){
+ this.matchModeCombo = matchModeCombo;
+ this.fieldName = fieldName;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ super.widgetSelected(e);
+ MatchMode matchMode = getMatchModeList().get(matchModeCombo.getSelectionIndex());
+ try {
+ matchStrategy.setMatchMode(fieldName, matchMode);
+ } catch (MatchException exception) {
+ logger.error(e);
+ throw new RuntimeException(exception);
+ }
+ }
+ }
+
+ /**
+ * Transforms the MatchMode enum into a list.
+ *
+ * @return
+ */
+ private List<MatchMode> getMatchModeList(){
+ if(matchModeList == null){
+ matchModeList = Arrays.asList(MatchMode.values());
+ }
+ return matchModeList;
+ }
+
+ /**
+ * Get names of all declared fields
+ *
+ * @return
+ */
+ private List<String> getFieldNames(){
+ List<Field> fields = new ArrayList<Field>();
+
+ fields = getAllFields(fields, clazz);
+ List<String> fieldNames = new ArrayList<String>();
+
+ for(Field field : fields){
+ String fieldName = field.getName();
+ if(! fieldName.matches(ExcludePattern)){
+ fieldNames.add(fieldName);
+ }
+ }
+
+ return fieldNames;
+ }
+
+ /**
+ * Get all declared fields including fields of the superclasses.
+ *
+ * @param fields
+ * @param type
+ * @return
+ */
+ public static List<Field> getAllFields(List<Field> fields, Class<?> type) {
+ fields.addAll(Arrays.asList(type.getDeclaredFields()));
+
+ if (type.getSuperclass() != null) {
+ fields = getAllFields(fields, type.getSuperclass());
+ }
+
+ return fields;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#performApply()
+ */
+ @Override
+ protected void performApply() {
+ MatchStrategyConfigurator.setMatchStrategy(matchStrategy);
+ super.performApply();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
+ */
+ @Override
+ protected void performDefaults() {
+ try {
+ // set match strategy to default
+ matchStrategy = getDefaultMatchStrategy();
+
+ // set combos to their default values
+ for(String fieldName : matchModeCombos.keySet()){
+ Combo combo = matchModeCombos.get(fieldName);
+ MatchMode matchMode;
+ if(matchStrategy.getMatchMode(fieldName) == null){
+
+ matchMode = IMatchStrategy.defaultMatchMode;
+
+ // TODO set default match modes for collections and other objects
+ }else{
+ matchMode = matchStrategy.getMatchMode(fieldName);
+ }
+
+ combo.select(matchModeList.indexOf(matchMode));
+ }
+
+ } catch (MatchException e) {
+ logger.error(e);
+ throw new RuntimeException(e);
+ }
+ super.performDefaults();
+ }
+
+ /**
+ * Returns the default match strategy for the respective class
+ *
+ * @return
+ * @throws MatchException
+ */
+ protected abstract IMatchStrategy getDefaultMatchStrategy() throws MatchException;
+}
--- /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.matching;
+
+import org.apache.log4j.Logger;
+import org.eclipse.ui.IWorkbench;
+
+import eu.etaxonomy.cdm.model.name.NonViralName;
+import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
+import eu.etaxonomy.cdm.strategy.match.MatchException;
+import eu.etaxonomy.taxeditor.parser.MatchStrategyConfigurator;
+
+/**
+ * @author n.hoffmann
+ * @created Jan 22, 2010
+ * @version 1.0
+ */
+public class NonViralNameMatchingPreference extends AbstractMatchingPreferences<NonViralName>{
+ private static final Logger logger = Logger
+ .getLogger(NonViralNameMatchingPreference.class);
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+ */
+ public void init(IWorkbench workbench) {
+ clazz = NonViralName.class;
+
+ try {
+ matchStrategy = MatchStrategyConfigurator.NonViralNameMatchStrategy();
+ } catch (MatchException e) {
+ logger.error(e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.preference.matching.AbstractMatchingPreferences#getDefaultMatchStrategy()
+ */
+ @Override
+ protected IMatchStrategy getDefaultMatchStrategy() throws MatchException {
+ return MatchStrategyConfigurator.getDefaultNonViralNameMatchStrategy();
+ }
+}
--- /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.matching;
+
+import org.apache.log4j.Logger;
+import org.eclipse.ui.IWorkbench;
+
+import eu.etaxonomy.cdm.model.reference.ReferenceBase;
+import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
+import eu.etaxonomy.cdm.strategy.match.MatchException;
+import eu.etaxonomy.taxeditor.parser.MatchStrategyConfigurator;
+
+/**
+ * @author n.hoffmann
+ * @created Jan 22, 2010
+ * @version 1.0
+ */
+public class ReferenceMatchingPreference extends AbstractMatchingPreferences<ReferenceBase> {
+ private static final Logger logger = Logger
+ .getLogger(ReferenceMatchingPreference.class);
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+ */
+ public void init(IWorkbench workbench) {
+ clazz = ReferenceBase.class;
+
+ try {
+ matchStrategy = MatchStrategyConfigurator.ReferenceMatchStrategy();
+ } catch (MatchException e) {
+ logger.error(e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.preference.matching.AbstractMatchingPreferences#getDefaultMatchStrategy()
+ */
+ @Override
+ protected IMatchStrategy getDefaultMatchStrategy() throws MatchException {
+ return MatchStrategyConfigurator.getDefaultReferenceMatchStrategy();
+ }
+}
--- /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.matching;
+
+import org.apache.log4j.Logger;
+import org.eclipse.ui.IWorkbench;
+
+import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
+import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
+import eu.etaxonomy.cdm.strategy.match.MatchException;
+import eu.etaxonomy.taxeditor.parser.MatchStrategyConfigurator;
+
+/**
+ * @author n.hoffmann
+ * @created Jan 22, 2010
+ * @version 1.0
+ */
+public class TeamOrPersonMatchingPreference extends
+ AbstractMatchingPreferences<TeamOrPersonBase> {
+ private static final Logger logger = Logger
+ .getLogger(TeamOrPersonMatchingPreference.class);
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+ */
+ public void init(IWorkbench workbench) {
+
+ clazz = TeamOrPersonBase.class;
+
+ try {
+ matchStrategy = MatchStrategyConfigurator.TeamOrPersonMatchStrategy();
+ } catch (MatchException e) {
+ logger.error(e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.preference.matching.AbstractMatchingPreferences#getDefaultMatchStrategy()
+ */
+ @Override
+ protected IMatchStrategy getDefaultMatchStrategy() throws MatchException {
+ return MatchStrategyConfigurator.getDefaultTeamOrPersonMatchStrategy();
+ }
+}