Fixed persistency of Matching preferences #5337
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 28 Oct 2015 16:08:43 +0000 (17:08 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 28 Oct 2015 16:08:43 +0000 (17:08 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/matching/AbstractMatchingPreferences.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/matching/NonViralNameMatchingPreference.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/matching/ReferenceMatchingPreference.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/matching/TeamOrPersonMatchingPreference.java

index 6d2ddb9bc92792faa37e28d4b6bfc938a0a071ed..be84b00cfff03c850b7222227c69cf3bd5c2fad4 100644 (file)
@@ -17,15 +17,10 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-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.jface.preference.ComboFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
 import org.eclipse.swt.widgets.Combo;
-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.IdentifiableEntity;
@@ -37,13 +32,11 @@ import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
- * <p>Abstract AbstractMatchingPreferences class.</p>
- *
  * @author n.hoffmann
  * @created Jan 22, 2010
  * @version 1.0
  */
-public abstract class AbstractMatchingPreferences<T extends IdentifiableEntity> extends PreferencePage implements
+public abstract class AbstractMatchingPreferences<T extends IdentifiableEntity> extends FieldEditorPreferencePage implements
                IWorkbenchPreferencePage {
 
        /**
@@ -60,96 +53,30 @@ public abstract class AbstractMatchingPreferences<T extends IdentifiableEntity>
 
        protected Map<String, Combo> matchModeCombos = new HashMap<String, Combo>();
 
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+    @Override
+    public void init(IWorkbench workbench) {
+        setPreferenceStore(PreferencesUtil.getPreferenceStore());
+    }
+
+       /**
+        * {@inheritDoc}
         */
-       /** {@inheritDoc} */
        @Override
-       protected Control createContents(Composite parent) {
-               final Composite composite = new Composite(parent, SWT.NULL);
-               GridLayout gridLayout = new GridLayout();
-               gridLayout.numColumns = 2;
-               composite.setLayout(gridLayout);
-
-               if(!CdmStore.isActive()) {
+       protected void createFieldEditors() {
+           if(!CdmStore.isActive()) {
             MessagingUtils.noDataSourceWarningDialog(null);
         }else{
             for(String fieldName : getFieldNames()){
-                createFieldWidget(composite, fieldName);
+                String[][] comboValues = new String[getMatchModeList().size()][2];
+                for (int i=0;i<getMatchModeList().size();i++) {
+                    comboValues[i][0] = getMatchModeList().get(i).name();
+                    comboValues[i][1] = getMatchModeList().get(i).name();
+                }
+                addField(new ComboFieldEditor(this.getClass().getCanonicalName()+fieldName,
+                        fieldName, comboValues,
+                        getFieldEditorParent()));
             }
         }
-
-               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 final Combo matchModeCombo;
-               private final 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 event) {
-                       super.widgetSelected(event);
-                       MatchMode matchMode = getMatchModeList().get(matchModeCombo.getSelectionIndex());
-                       try {
-                               matchStrategy.setMatchMode(fieldName, matchMode);
-                       } catch (MatchException e) {
-                               MessagingUtils.error(this.getClass(), e);
-                               throw new RuntimeException(e);
-                       }
-               }
        }
 
        /**
@@ -202,40 +129,6 @@ public abstract class AbstractMatchingPreferences<T extends IdentifiableEntity>
            return fields;
        }
 
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.preference.PreferencePage#performApply()
-        */
-       /** {@inheritDoc} */
-       @Override
-       protected void performApply() {
-           PreferencesUtil.setMatchStrategy(matchStrategy);
-               super.performApply();
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
-        */
-       /** {@inheritDoc} */
-       @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 = matchStrategy.getMatchMode(fieldName);
-                               combo.select(matchModeList.indexOf(matchMode));
-                       }
-
-               } catch (MatchException e) {
-                       MessagingUtils.error(this.getClass(), e);
-                       throw new RuntimeException(e);
-               }
-               super.performDefaults();
-       }
-
        /**
         * Returns the default match strategy for the respective class
         *
index 339232c7aacf8f14bab108f5f394c505bf0b472f..b048e2d13a6906fce33e878c225ac691a4392c37 100644 (file)
@@ -27,12 +27,10 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
  */
 public class NonViralNameMatchingPreference extends AbstractMatchingPreferences<NonViralName>{
 
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
-        */
        /** {@inheritDoc} */
        @Override
     public void init(IWorkbench workbench) {
+           super.init(workbench);
                clazz = NonViralName.class;
 
                try {
@@ -43,9 +41,6 @@ public class NonViralNameMatchingPreference extends AbstractMatchingPreferences<
                }
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.preference.matching.AbstractMatchingPreferences#getDefaultMatchStrategy()
-        */
        /** {@inheritDoc} */
        @Override
        protected IMatchStrategy getDefaultMatchStrategy() throws MatchException {
index 9a578c0c4a929a2dee67474f21f5689e1afd795d..f28e61fc68cf2a315a0ff11e31345335f294ddc0 100644 (file)
@@ -19,20 +19,16 @@ import eu.etaxonomy.cdm.strategy.match.MatchStrategyConfigurator;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 
 /**
- * <p>ReferenceMatchingPreference class.</p>
- *
  * @author n.hoffmann
  * @created Jan 22, 2010
  * @version 1.0
  */
 public class ReferenceMatchingPreference extends AbstractMatchingPreferences<Reference> {
 
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
-        */
        /** {@inheritDoc} */
        @Override
     public void init(IWorkbench workbench) {
+           super.init(workbench);
                clazz = Reference.class;
 
                try {
@@ -43,9 +39,6 @@ public class ReferenceMatchingPreference extends AbstractMatchingPreferences<Ref
                }
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.preference.matching.AbstractMatchingPreferences#getDefaultMatchStrategy()
-        */
        /** {@inheritDoc} */
        @Override
        protected IMatchStrategy getDefaultMatchStrategy() throws MatchException {
index fac1a2b109ec0a634cccc5d2ae4a76c0218fc0f4..a9774b346f7b2d12af6c69388e19118fbc301c03 100644 (file)
@@ -19,8 +19,6 @@ import eu.etaxonomy.cdm.strategy.match.MatchStrategyConfigurator;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 
 /**
- * <p>TeamOrPersonMatchingPreference class.</p>
- *
  * @author n.hoffmann
  * @created Jan 22, 2010
  * @version 1.0
@@ -28,13 +26,10 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
 public class TeamOrPersonMatchingPreference extends
                AbstractMatchingPreferences<TeamOrPersonBase> {
 
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
-        */
        /** {@inheritDoc} */
        @Override
     public void init(IWorkbench workbench) {
-
+           super.init(workbench);
                clazz = TeamOrPersonBase.class;
 
                try {
@@ -45,9 +40,6 @@ public class TeamOrPersonMatchingPreference extends
                }
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.preference.matching.AbstractMatchingPreferences#getDefaultMatchStrategy()
-        */
        /** {@inheritDoc} */
        @Override
        protected IMatchStrategy getDefaultMatchStrategy() throws MatchException {