Refactored menu preference selection
authorn.hoffmann <n.hoffmann@localhost>
Fri, 12 Jun 2009 17:33:23 +0000 (17:33 +0000)
committern.hoffmann <n.hoffmann@localhost>
Fri, 12 Jun 2009 17:33:23 +0000 (17:33 +0000)
.gitattributes
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/AbstractMenuPreferences.java [new file with mode: 0644]
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/FeaturePreferences.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/RankMenuPreferences.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureWizard.java [new file with mode: 0644]
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureWizardEditPage.java [new file with mode: 0644]
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureWizardNewPage.java [new file with mode: 0644]
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java

index 5398fe771e45a16ffbf394b6cda401d43619a712..54eea05365562e2b137d368974e0139814e93891 100644 (file)
@@ -1008,6 +1008,7 @@ taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/MoveTaxonOperati
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/RemoveHomotypicalGroupBasionymOperation.java -text
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/SwapSynonymAndAcceptedOperation.java -text
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/parser/CdmParserUtil.java -text
+taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/AbstractMenuPreferences.java -text
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/CdmPreferences.java -text
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/DescriptionPreferences.java -text
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/FeaturePreferences.java -text
@@ -1017,6 +1018,9 @@ taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/NomenclaturalCod
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java -text
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/RankMenuPreferences.java -text
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/TaxonomicPreferences.java -text
+taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureWizard.java -text
+taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureWizardEditPage.java -text
+taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureWizardNewPage.java -text
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java -text
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/store/StoreUtil.java -text
 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/store/internal/TaxeditorStorePlugin.java -text
diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/AbstractMenuPreferences.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/AbstractMenuPreferences.java
new file mode 100644 (file)
index 0000000..60d30a1
--- /dev/null
@@ -0,0 +1,185 @@
+// $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 java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkbench;
+
+import eu.etaxonomy.cdm.model.common.DefinedTermBase;
+
+/**
+ * @author n.hoffmann
+ * @created 12.06.2009
+ * @version 1.0
+ */
+public abstract class AbstractMenuPreferences extends PreferencePage {
+
+       private Button toggleButton;
+       protected HashMap<DefinedTermBase, Button> menuButtons;
+       
+       protected Set<?> vocabulary;
+       
+       private List preferedTerms;
+       
+       private CheckboxTableViewer tableViewer;
+       
+       private boolean state = true;
+
+       /**
+        * Constructs a new menu preference page.
+        * 
+        * @param initialVocabulary the initial vocabulary contating all possible entries for the menu
+        * @param preferedTerms a List containtg already prefered terms 
+        * @param title the title of the page
+        * @param description describing text for the preference page
+        */
+       public AbstractMenuPreferences(Set<?> initialVocabulary, List preferedTerms, String title, String description) {
+               super(title);
+               vocabulary = initialVocabulary;
+               this.preferedTerms = preferedTerms;
+               setDescription(description);
+       }
+
+       /**
+        * Create contents of the preference page
+        * @param parent
+        */
+       @Override
+       public Control createContents(Composite parent) {
+               
+               Composite container = new Composite(parent, SWT.NULL);
+               final GridLayout gridLayout = new GridLayout();
+               gridLayout.numColumns = 2;
+               container.setLayout(gridLayout);
+       
+               tableViewer = CheckboxTableViewer.newCheckList(container, SWT.NULL);
+               GridData tableLayoutData = new GridData(SWT.FILL, SWT.FILL, true, false);
+               tableLayoutData.heightHint = 300;
+               tableViewer.getTable().setLayoutData(tableLayoutData);
+               
+               tableViewer.setContentProvider(new MenuPreferenceContentProvider());
+               tableViewer.setLabelProvider(new MenuPreferenceLabelProvider());
+                       
+               tableViewer.setInput(vocabulary);
+               
+               tableViewer.setCheckedElements(preferedTerms.toArray());
+               
+               Composite buttonContainer = new Composite(container, SWT.NULL);
+               GridData buttonContainerLayoutData = new GridData();
+               buttonContainerLayoutData.verticalAlignment = SWT.TOP;
+               buttonContainer.setLayoutData(buttonContainerLayoutData);
+               buttonContainer.setLayout(new GridLayout());
+               
+               createButtons(buttonContainer);
+               
+               toggleButton = new Button(buttonContainer, SWT.PUSH);
+               toggleButton.setText("Toggle");
+               toggleButton.addMouseListener(new MouseAdapter(){
+       
+                       /* (non-Javadoc)
+                        * @see org.eclipse.swt.events.MouseAdapter#mouseDown(org.eclipse.swt.events.MouseEvent)
+                        */
+                       @Override
+                       public void mouseDown(MouseEvent e) {
+                               tableViewer.setAllChecked(state);
+                               state = state ? false : true;
+                       }                       
+               });
+               
+               return container;
+       }
+
+
+       /**
+        * @param buttonContainer
+        */
+       protected abstract void createButtons(Composite buttonContainer);
+
+       public void init(IWorkbench workbench) {
+               setPreferenceStore(PreferencesUtil.getPrefStore());
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
+        */
+       protected void performDefaults() {
+               tableViewer.setAllChecked(true);
+       }
+       
+       /**
+        * 
+        * @author n.hoffmann
+        * @created 12.06.2009
+        * @version 1.0
+        */
+       private class MenuPreferenceContentProvider implements IStructuredContentProvider{
+
+               public Object[] getElements(Object inputElement) {                      
+                       return ((Set<?>) inputElement).toArray(new DefinedTermBase[0]);
+               }
+
+               public void dispose() {}
+
+               public void inputChanged(Viewer viewer, Object oldInput,
+                               Object newInput) {}
+               
+       };
+       
+       /**
+        * 
+        * @author n.hoffmann
+        * @created 12.06.2009
+        * @version 1.0
+        */
+       private class MenuPreferenceLabelProvider extends LabelProvider implements ITableLabelProvider{
+
+               /* (non-Javadoc)
+                * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
+                */
+               public Image getColumnImage(Object element, int columnIndex) {
+                       return null;
+               }
+
+               /* (non-Javadoc)
+                * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
+                */
+               public String getColumnText(Object element, int columnIndex) {
+                       return ((DefinedTermBase)element).getLabel();
+               }
+               
+       }
+
+       /**
+        * @return the tableViewer
+        */
+       public CheckboxTableViewer getTableViewer() {
+               return tableViewer;
+       };
+}
\ No newline at end of file
index 42b994816a4ca797c1616397e40701810d3a7e55..ac1b08b4c6299884fa36745684e888ce44057227 100644 (file)
@@ -8,19 +8,16 @@
 */\r
 package eu.etaxonomy.taxeditor.preference;\r
 \r
-import java.util.HashMap;\r
-import java.util.Map;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
 \r
-import org.eclipse.jface.preference.PreferencePage;\r
 import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.layout.GridLayout;\r
+import org.eclipse.swt.events.MouseAdapter;\r
+import org.eclipse.swt.events.MouseEvent;\r
 import org.eclipse.swt.widgets.Button;\r
 import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.ui.IWorkbench;\r
 import org.eclipse.ui.IWorkbenchPreferencePage;\r
 \r
-import eu.etaxonomy.cdm.model.common.TermVocabulary;\r
 import eu.etaxonomy.cdm.model.description.Feature;\r
 import eu.etaxonomy.taxeditor.store.CdmStore;\r
 \r
@@ -28,80 +25,82 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @author p.ciardelli\r
  * @created 17.09.2008\r
  * @version 1.0\r
+ * @author n.hoffmann\r
  */\r
-public class FeaturePreferences extends PreferencePage implements\r
+public class FeaturePreferences extends AbstractMenuPreferences implements\r
                IWorkbenchPreferencePage {\r
 \r
        public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.preferences.feature";\r
+       private Button newButton;\r
+       private Button editButton;\r
+       private Button removeButton;\r
        \r
-       private Map<Feature, Button> featureButtons;\r
-\r
        public FeaturePreferences() {\r
-               super();\r
-               setDescription("Choose which features you would like to use for descriptive elements.");\r
+               super(CdmStore.getFeatures(), PreferencesUtil.getPreferredFeatures(), "Feature Preferences", "Choose which features you would like to use for descriptive elements.");\r
        }\r
 \r
+       \r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.jface.preference.PreferencePage#performOk()\r
+        */\r
+       public boolean performOk() {\r
+               List<Feature> preferredFeatures = new ArrayList<Feature>();\r
+               for (Object element : getTableViewer().getCheckedElements()){\r
+                       preferredFeatures.add((Feature) element);\r
+               }\r
+               \r
+               PreferencesUtil.setPreferredFeatures(preferredFeatures);\r
+               \r
+               return true;\r
+       }\r
 \r
-       /**\r
-        * Create contents of the preference page\r
-        * @param parent\r
+       /* (non-Javadoc)\r
+        * @see eu.etaxonomy.taxeditor.preference.AbstractMenuPreferences#createButtons(org.eclipse.swt.widgets.Composite)\r
         */\r
        @Override\r
-       public Control createContents(Composite parent) {\r
+       protected void createButtons(Composite buttonContainer) {\r
+               newButton = new Button(buttonContainer, SWT.PUSH);\r
+               newButton.setText("New");\r
+               newButton.addMouseListener(new MouseAdapter(){\r
 \r
-               featureButtons = new HashMap<Feature, Button>();\r
+                       /* (non-Javadoc)\r
+                        * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)\r
+                        */\r
+                       @Override\r
+                       public void mouseUp(MouseEvent e) {\r
+                               super.mouseUp(e);\r
+                       }\r
+                       \r
+               });\r
                \r
-               Composite container = new Composite(parent, SWT.NULL);\r
-               final GridLayout gridLayout = new GridLayout();\r
-               gridLayout.numColumns = 3;\r
-               container.setLayout(gridLayout);\r
+               editButton = new Button(buttonContainer, SWT.PUSH);\r
+               editButton.setText("Edit");\r
+               editButton.addMouseListener(new MouseAdapter(){\r
 \r
-               CdmStore.getDefault();\r
-               TermVocabulary<Feature> features = CdmStore.getFeatures();\r
-               \r
-               for (Feature feature : features) {\r
-                                               \r
-                       Button button = new Button(container, SWT.CHECK);\r
-                       button.setText(feature.getLabel());\r
-                       featureButtons.put(feature, button);\r
-                       \r
-                       if (PreferencesUtil.getFeaturePreference(feature)) {\r
-                               button.setSelection(true);\r
+                       /* (non-Javadoc)\r
+                        * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)\r
+                        */\r
+                       @Override\r
+                       public void mouseUp(MouseEvent e) {\r
+                               super.mouseUp(e);\r
                        }\r
-               }\r
+                       \r
+               });\r
                \r
-               return container;\r
+               removeButton = new Button(buttonContainer, SWT.PUSH);\r
+               removeButton.setText("Remove");\r
+               removeButton.addMouseListener(new MouseAdapter(){\r
+\r
+                       /* (non-Javadoc)\r
+                        * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)\r
+                        */\r
+                       @Override\r
+                       public void mouseUp(MouseEvent e) {\r
+                               super.mouseUp(e);\r
+                       }\r
+                       \r
+               });\r
        }\r
 \r
 \r
-       /* (non-Javadoc)\r
-        * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)\r
-        */\r
-       public void init(IWorkbench workbench) {\r
-               setPreferenceStore(PreferencesUtil.getPrefStore());\r
-       }\r
-       \r
-       /* (non-Javadoc)\r
-        * @see org.eclipse.jface.preference.PreferencePage#performDefaults()\r
-        */\r
-       protected void performDefaults() {\r
-               \r
-               // Set all buttons to show feature\r
-               for (Button button : featureButtons.values()) {\r
-                       button.setSelection(true);\r
-               }\r
-       }\r
-       \r
-       /* (non-Javadoc)\r
-        * @see org.eclipse.jface.preference.PreferencePage#performOk()\r
-        */\r
-       public boolean performOk() {\r
-               \r
-               for (Feature feature : featureButtons.keySet()) {\r
-                       Button button = featureButtons.get(feature);\r
-                       PreferencesUtil.setFeaturePreference(feature, button.getSelection());\r
-               }\r
-               \r
-               return true;\r
-       }\r
 }\r
index 5935306790f178ea23cae1d5b65d2e388c7cb1b2..36f7d8e6cfb2d82e2e2b811f8bcd3b258ad2b4cb 100644 (file)
 package eu.etaxonomy.taxeditor.preference;\r
 \r
 import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.Comparator;\r
 import java.util.List;\r
-import java.util.SortedSet;\r
 \r
 import org.apache.log4j.Logger;\r
 import org.eclipse.jface.preference.IPreferenceStore;\r
@@ -39,19 +36,39 @@ public class PreferencesUtil {
        private static final Logger logger = Logger\r
                        .getLogger(PreferencesUtil.class);\r
 \r
-       private static List<Feature> preferredFeatureList;\r
-       private static List<Rank> preferredRankList;\r
+\r
+       private static final String FEATURE_PREFERENCE = "FEATURE_PREFERENCE";\r
+\r
 \r
        private static SourceViewerDecorationSupport decorationSupport;\r
 \r
+       /**\r
+        * \r
+        * @return\r
+        */\r
+       public static IPreferenceStore getPrefStore() {\r
+               return TaxeditorStorePlugin.getDefault().getPreferenceStore();\r
+       }\r
+       \r
+       /**\r
+        * \r
+        * @param preferredCode\r
+        */\r
        public static void setNomenclaturalCode(String preferredCode) {\r
                getPrefStore().setValue(Resources.CODE_PREFERENCE, preferredCode);\r
        }\r
        \r
+       /**\r
+        * \r
+        */\r
        public static void setDefaultNomenclaturalCode() {\r
                setNomenclaturalCode(Resources.DEFAULT_CODE_PREFERENCE);\r
        }\r
 \r
+       /**\r
+        * \r
+        * @return\r
+        */\r
        public static String getPreferredNomenclaturalCodeAsString() {\r
                String nameCodePreference = getNameCodePreference();\r
                \r
@@ -78,6 +95,10 @@ public class PreferencesUtil {
                return null;\r
        }\r
        \r
+       /**\r
+        * \r
+        * @return\r
+        */\r
        private static String getNameCodePreference() {\r
                try{\r
                        return getPrefStore().getString(Resources.CODE_PREFERENCE);\r
@@ -98,70 +119,28 @@ public class PreferencesUtil {
         */\r
        public static List<Feature> getPreferredFeatures() {\r
                \r
-               // Initialize preferredFeatureSet as necessary\r
-               if (preferredFeatureList == null) {\r
-                       \r
-                       setPreferredFeatures(new ArrayList<Feature>()); \r
-                                               \r
-                       for (Feature feature : CdmStore.getFeatures()) {\r
-                               \r
-                               // If the feature is set to show, add it to preferredFeatureSet\r
-                               if (PreferencesUtil.getFeaturePreference(feature)) {\r
-                                       addPreferredFeature(feature);\r
-                               }\r
+               ArrayList<Feature> preferedFeatures = new ArrayList<Feature>();\r
+               \r
+               for (Feature feature : CdmStore.getFeatures()) {\r
+                       if(getPrefStore().getBoolean(getPreferenceKey(feature))){\r
+                               preferedFeatures.add(feature);\r
                        }\r
-                       \r
-                       Collections.sort(preferredFeatureList, new Comparator<Feature>(){\r
-\r
-                               public int compare(Feature feature1, Feature feature2) {\r
-                                       String feature1Label = feature1.getLabel(CdmStore.getDefaultLanguage());\r
-                                       String feature2Label = feature2.getLabel(CdmStore.getDefaultLanguage());                        \r
-                                       return feature1Label.compareToIgnoreCase(feature2Label);\r
-                               }\r
-                               \r
-                       });\r
                }\r
                \r
-               return preferredFeatureList;\r
+               return preferedFeatures;\r
        }\r
 \r
        /**\r
-        * True if <code>Feature</code> is set to "show" in preferences.\r
         * \r
-        * @param feature\r
-        * @return\r
+        * @param preferredFeatureList\r
         */\r
-       public static boolean getFeaturePreference(Feature feature) {\r
-               \r
-               String preferenceKey = getPreferenceKey(feature);\r
+       public static void setPreferredFeatures(List<Feature> preferredFeatureList) {\r
                \r
-               // If feature does not yet have a pref, set it to true\r
-               if (!PreferencesUtil.getPrefStore().contains(preferenceKey)) {\r
-                       PreferencesUtil.getPrefStore().setDefault(preferenceKey, true);\r
+               for (Feature feature : CdmStore.getFeatures()) {\r
+                       getPrefStore().setValue(getPreferenceKey(feature), preferredFeatureList.contains(feature));\r
                }\r
-               \r
-               return PreferencesUtil.getPrefStore().getBoolean(preferenceKey);\r
-       }\r
-\r
-       /**\r
-        * Set the show state of a <code>Feature</code> in the \r
-        * <code>PreferenceStore</code>.\r
-        * <p>\r
-        * Also sets <code>preferredFeatureSet</code> to null to force it be\r
-        * re-populated the next time {@link getPreferredFeatures} is called.\r
-        * \r
-        * @param feature\r
-        * @param show\r
-        */\r
-       public static void setFeaturePreference(Feature feature, boolean show) {\r
-               setPreferredFeatures(null);\r
-               PreferencesUtil.getPrefStore().setValue(PreferencesUtil.getPreferenceKey(feature), show);\r
-       }\r
-\r
-       public static IPreferenceStore getPrefStore() {\r
-               return TaxeditorStorePlugin.getDefault().getPreferenceStore();\r
        }\r
-\r
+       \r
        /**\r
         * Construct a unique key using <code>Feature</code>'s <code>Uuid</code>\r
         * \r
@@ -169,7 +148,7 @@ public class PreferencesUtil {
         * @return\r
         */\r
        private static String getPreferenceKey(Feature feature) {\r
-               return Resources.FEATURE_PREFERENCE \r
+               return FEATURE_PREFERENCE \r
                                . concat(".")\r
                                . concat(feature.getUuid().toString());\r
        }\r
@@ -185,64 +164,28 @@ public class PreferencesUtil {
         */\r
        public static List<Rank> getPreferredRanks() {\r
                \r
-               // Initialize preferredRankSet as necessary\r
-               if (preferredRankList == null) {\r
-                       \r
-                       setPreferredRanks(new ArrayList<Rank>());       \r
-                       \r
-                       for (Rank rank : CdmStore.getDefault().getRanksInternal()) {\r
-                               \r
-                               // If the feature is set to show, add it to preferredFeatureSet\r
-                               if (PreferencesUtil.getRankPreference(rank)) {\r
-                                       addPreferredRank(rank);\r
-                               }\r
+               ArrayList<Rank> preferedRanks = new ArrayList<Rank>();\r
+               \r
+               for (Rank rank : CdmStore.getRanks()) {\r
+                       if(getPrefStore().getBoolean(getPreferenceKey(rank))){\r
+                               preferedRanks.add(rank);\r
                        }\r
-                       \r
-                       Collections.sort(preferredRankList, new Comparator<Rank>(){\r
-\r
-                               public int compare(Rank rank1, Rank rank2) {\r
-                                       return rank1.isHigher(rank2) ? 1 : 0;\r
-                               }       \r
-                       });\r
-                       \r
                }\r
                \r
-               return preferredRankList;\r
+               return preferedRanks;\r
        }\r
-\r
+       \r
        /**\r
-        * True if <code>Rank</code> is set to "show" in preferences.\r
         * \r
-        * @param rank\r
-        * @return\r
+        * @param preferedRankList\r
         */\r
-       public static boolean getRankPreference(Rank rank) {\r
-               \r
-               String preferenceKey = PreferencesUtil.getPreferenceKey(rank);\r
-               \r
-               // If rank does not yet have a pref, set it to true\r
-               if (!getPrefStore().contains(preferenceKey)) {\r
-                       getPrefStore().setDefault(preferenceKey, true);\r
+       public static void setPreferredRanks(List<Rank> preferedRankList) {\r
+               for (Rank rank : CdmStore.getRanks()) {\r
+                       getPrefStore().setValue(getPreferenceKey(rank), preferedRankList.contains(rank));\r
                }\r
-               \r
-               return getPrefStore().getBoolean(preferenceKey);\r
        }\r
 \r
-       /**\r
-        * Set the show state of a <code>Rank</code> in the \r
-        * <code>PreferenceStore</code>.\r
-        * <p>\r
-        * Also sets <code>preferredRankSet</code> to null to force it be\r
-        * re-populated the next time {@link getPreferredRanks} is called.\r
-        * \r
-        * @param rank\r
-        * @param show\r
-        */     \r
-       public static void setRankPreference(Rank rank, boolean show) {\r
-               setPreferredRanks(null);\r
-               getPrefStore().setValue(PreferencesUtil.getPreferenceKey(rank), show);\r
-               \r
-       }\r
+\r
 \r
        /**\r
         * Construct a unique key using <code>Rank</code>'s <code>Uuid</code>\r
@@ -289,25 +232,11 @@ public class PreferencesUtil {
                String code = getNameCodePreference();\r
                return key + "." + code;\r
        }\r
-       \r
-\r
-       public static void setPreferredFeatures(List<Feature> preferredFeatureList) {\r
-               PreferencesUtil.preferredFeatureList = preferredFeatureList;\r
-       }\r
 \r
-\r
-       public static void setPreferredRanks(List<Rank> preferredRankList) {\r
-               PreferencesUtil.preferredRankList = preferredRankList;\r
-       }\r
-\r
-       public static void addPreferredRank(Rank rank) {\r
-               preferredRankList.add(rank);\r
-       }\r
-\r
-       public static void addPreferredFeature(Feature feature) {\r
-               preferredFeatureList.add(feature);              \r
-       }\r
-       \r
+       /**\r
+        * \r
+        * @return\r
+        */\r
        public static SourceViewerDecorationSupport getDecorationSupport() {\r
                if (decorationSupport == null) {\r
                        decorationSupport = new SourceViewerDecorationSupport(null, null, null, EditorsUI.getSharedTextColors());\r
index 9859862b0440ce802b2195aa41f38578d1bdced2..58b12d421ca418b85b212c3e008200db39ae7259 100644 (file)
@@ -8,23 +8,12 @@
 */\r
 package eu.etaxonomy.taxeditor.preference;\r
 \r
-import java.util.HashMap;\r
+import java.util.ArrayList;\r
 import java.util.List;\r
-import java.util.Map;\r
 \r
-import org.eclipse.jface.preference.PreferencePage;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.MouseAdapter;\r
-import org.eclipse.swt.events.MouseEvent;\r
-import org.eclipse.swt.layout.GridLayout;\r
-import org.eclipse.swt.widgets.Button;\r
 import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.ui.IWorkbench;\r
 import org.eclipse.ui.IWorkbenchPreferencePage;\r
 \r
-import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;\r
 import eu.etaxonomy.cdm.model.name.Rank;\r
 import eu.etaxonomy.taxeditor.store.CdmStore;\r
 \r
@@ -35,93 +24,15 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @author p.ciardelli\r
  * @created 17.09.2008\r
  * @version 1.0\r
+ * @author n.hoffmann\r
  */\r
-public class RankMenuPreferences extends PreferencePage implements\r
+public class RankMenuPreferences extends AbstractMenuPreferences implements\r
                IWorkbenchPreferencePage {\r
 \r
        public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.preferences.ranks";\r
-       \r
-       private Map<Rank, Button> rankButtons;\r
-\r
-       private Button toggleButton;\r
 \r
        public RankMenuPreferences() {\r
-               super();\r
-               setDescription("Choose which ranks to display in the property sheet drop-down menu.");\r
-       }\r
-\r
-\r
-       /**\r
-        * Create contents of the preference page\r
-        * @param parent\r
-        */\r
-       @Override\r
-       public Control createContents(Composite parent) {\r
-\r
-               rankButtons = new HashMap<Rank, Button>();\r
-               \r
-               Composite container = new Composite(parent, SWT.NULL);\r
-               final GridLayout gridLayout = new GridLayout();\r
-               gridLayout.numColumns = 3;\r
-               container.setLayout(gridLayout);\r
-\r
-               CdmStore.getDefault();\r
-               OrderedTermVocabulary<Rank> ranks = CdmStore.getRanks();\r
-               \r
-               for (Rank rank : ranks) {\r
-                                               \r
-                       Button button = new Button(container, SWT.CHECK);\r
-                       button.setText(rank.getLabel());\r
-                       rankButtons.put(rank, button);\r
-                       \r
-                       if (PreferencesUtil.getRankPreference(rank)) {\r
-                               button.setSelection(true);\r
-                       }\r
-               }\r
-               \r
-               Composite toggleContainer = new Composite(parent, SWT.NULL);\r
-               toggleContainer.setLayout(new GridLayout());\r
-               \r
-               toggleButton = new Button(toggleContainer, SWT.TOGGLE);\r
-               toggleButton.setText("Toggle Selection");\r
-               toggleButton.addMouseListener(new MouseAdapter(){\r
-\r
-                       /* (non-Javadoc)\r
-                        * @see org.eclipse.swt.events.MouseAdapter#mouseDown(org.eclipse.swt.events.MouseEvent)\r
-                        */\r
-                       @Override\r
-                       public void mouseDown(MouseEvent e) {\r
-                               setSelectionForAll(toggleButton.getSelection());\r
-                       }                       \r
-               });\r
-               \r
-               return container;\r
-       }\r
-\r
-\r
-       /* (non-Javadoc)\r
-        * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)\r
-        */\r
-       public void init(IWorkbench workbench) {\r
-               setPreferenceStore(PreferencesUtil.getPrefStore());\r
-       }\r
-       \r
-       /* (non-Javadoc)\r
-        * @see org.eclipse.jface.preference.PreferencePage#performDefaults()\r
-        */\r
-       protected void performDefaults() {\r
-               setSelectionForAll(true);\r
-       }\r
-       \r
-       /**\r
-        * Set all buttons to the given value\r
-        * \r
-        * @param selection true to activate all of the checkboxes, false otherwise\r
-        */\r
-       private void setSelectionForAll(boolean selection){\r
-               for (Button button : rankButtons.values()) {\r
-                       button.setSelection(selection);\r
-               }\r
+               super(CdmStore.getRanks(), PreferencesUtil.getPreferredRanks(), "Rank Preferences", "Choose which ranks to display in the property sheet drop-down menu.");\r
        }\r
        \r
        /* (non-Javadoc)\r
@@ -129,11 +40,21 @@ public class RankMenuPreferences extends PreferencePage implements
         */\r
        public boolean performOk() {\r
                \r
-               for (Rank rank : rankButtons.keySet()) {\r
-                       Button button = rankButtons.get(rank);\r
-                       PreferencesUtil.setRankPreference(rank, button.getSelection());\r
+               List<Rank> preferredRanks = new ArrayList<Rank>();\r
+               for (Object element : getTableViewer().getCheckedElements()){\r
+                       preferredRanks.add((Rank) element);\r
                }\r
                \r
+               PreferencesUtil.setPreferredRanks(preferredRanks);\r
+               \r
                return true;\r
        }\r
+\r
+       /* (non-Javadoc)\r
+        * @see eu.etaxonomy.taxeditor.preference.AbstractMenuPreferences#createButtons(org.eclipse.swt.widgets.Composite)\r
+        */\r
+       @Override\r
+       protected void createButtons(Composite buttonContainer) {\r
+               // not used\r
+       }\r
 }\r
diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureWizard.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureWizard.java
new file mode 100644 (file)
index 0000000..d3b85d7
--- /dev/null
@@ -0,0 +1,63 @@
+// $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.wizards;
+
+import org.apache.log4j.Logger;
+import org.eclipse.jface.wizard.Wizard;
+
+import eu.etaxonomy.cdm.model.description.Feature;
+
+/**
+ * @author n.hoffmann
+ * @created 12.06.2009
+ * @version 1.0
+ */
+public class FeatureWizard extends Wizard {
+       private static final Logger logger = Logger.getLogger(FeatureWizard.class);
+       
+       private Feature selectedFeature = null;
+
+       /**
+        * 
+        */
+       public FeatureWizard(){}
+       
+       /**
+        * 
+        * @param selectedFeature
+        */
+       public FeatureWizard(Feature selectedFeature){
+               this.selectedFeature = selectedFeature;
+       }
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.wizard.Wizard#addPages()
+        */
+       @Override
+       public void addPages() {
+               super.addPages();
+               
+               addPage(selectedFeature == null ? new FeatureWizardNewPage() : new FeatureWizardEditPage(selectedFeature));
+       }
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.wizard.Wizard#performFinish()
+        */
+       @Override
+       public boolean performFinish() {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+
+
+
+}
diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureWizardEditPage.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureWizardEditPage.java
new file mode 100644 (file)
index 0000000..39a20da
--- /dev/null
@@ -0,0 +1,43 @@
+// $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.wizards;
+
+import org.apache.log4j.Logger;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.widgets.Composite;
+
+import eu.etaxonomy.cdm.model.description.Feature;
+
+/**
+ * @author n.hoffmann
+ * @created 12.06.2009
+ * @version 1.0
+ */
+public class FeatureWizardEditPage extends WizardPage {
+
+       /**
+        * @param selectedFeature
+        */
+       public FeatureWizardEditPage(Feature selectedFeature) {
+               super("Edit Feature");
+       }
+
+       private static final Logger logger = Logger
+                       .getLogger(FeatureWizardEditPage.class);
+
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+        */
+       public void createControl(Composite parent) {
+               // TODO Auto-generated method stub
+
+       }
+}
diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureWizardNewPage.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/wizards/FeatureWizardNewPage.java
new file mode 100644 (file)
index 0000000..f1a645e
--- /dev/null
@@ -0,0 +1,41 @@
+// $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.wizards;
+
+import org.apache.log4j.Logger;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * @author n.hoffmann
+ * @created 12.06.2009
+ * @version 1.0
+ */
+public class FeatureWizardNewPage extends WizardPage {
+
+       /**
+        * 
+        */
+       public FeatureWizardNewPage() {
+               super("Create new Feature");
+       }
+
+       private static final Logger logger = Logger
+                       .getLogger(FeatureWizardNewPage.class);
+
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+        */
+       public void createControl(Composite parent) {
+               // TODO Auto-generated method stub
+
+       }
+}
index 5b4f81c0e662ca6a21a011a1b218a6d2be78bb67..426b3d9408813e6d1d8f41ad21dbb964721cd91b 100644 (file)
@@ -151,8 +151,8 @@ public class CdmStore{
                return applicationController.getTermService().getVocabulary(VocabularyEnum.Feature);
        }
        
-       public static TermVocabulary<Feature> getFeatures() {
-               return getDefault().getFeaturesInternal();
+       public static SortedSet<Feature> getFeatures() {
+               return getDefault().getFeaturesInternal().getTermsOrderedByLabels(getDefaultLanguage());
        }
 
        public SortedSet<NameRelationshipType> getNameRelationshipTypes() {
@@ -168,17 +168,13 @@ public class CdmStore{
                return getDefault().getNomenclaturalStatusTypesInternal().getTerms();
        }
        
-       public OrderedTermVocabulary<Rank> getRanksInternal(){
+       private OrderedTermVocabulary<Rank> getRanksInternal(){
                TermVocabulary<Rank> vocabulary = applicationController.getTermService().getVocabulary(VocabularyEnum.Rank);
                return HibernateProxyHelper.deproxy(vocabulary, OrderedTermVocabulary.class);
        }
        
-       public static OrderedTermVocabulary<Rank> getRanks(){
-               return getDefault().getRanksInternal();
-       }
-       
-       public static List<Rank> getPreferredRanks(){
-               return PreferencesUtil.getPreferredRanks();
+       public static SortedSet<Rank> getRanks(){
+               return getDefault().getRanksInternal().getOrderedTerms(null);
        }
 
        public List<Taxon> getRootTaxa() {