- added state vocabulary section to Feature DetailView (#4448)
authorPatric Plitzner <p.plitzner@bgbm.org>
Tue, 28 Apr 2015 08:38:48 +0000 (08:38 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Tue, 28 Apr 2015 08:38:48 +0000 (08:38 +0000)
 - implemented measurement unit section

.gitattributes
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/StateDataElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/FeatureDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/MeasurementUnitCollectionElement.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/MeasurementUnitCollectionSection.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/StateVocabularyCollectionElement.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/StateVocabularyCollectionSection.java

index 707e0c1..31c2a8e 100644 (file)
@@ -1757,9 +1757,12 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/voc
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/DefinedTermDetailElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/DefinedTermDetailSection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/FeatureDetailElement.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/MeasurementUnitCollectionElement.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/MeasurementUnitCollectionSection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/NamedAreaDetailElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/NamedAreaDetailSection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/NamedAreaLevelDetailSection.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/StateVocabularyCollectionElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/StateVocabularyCollectionSection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/TermVocabularyDetailElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/TermVocabularyDetailSection.java -text
index 0ec1e7d..25c0777 100644 (file)
@@ -75,6 +75,7 @@ import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
 import eu.etaxonomy.cdm.model.description.KeyStatement;
 import eu.etaxonomy.cdm.model.description.QuantitativeData;
+import eu.etaxonomy.cdm.model.description.State;
 import eu.etaxonomy.cdm.model.description.StateData;
 import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
 import eu.etaxonomy.cdm.model.description.TaxonInteraction;
@@ -307,6 +308,8 @@ import eu.etaxonomy.taxeditor.ui.section.vocabulary.DefinedTermDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.DefinedTermDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.FeatureDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.vocabulary.StateVocabularyCollectionElement;
+import eu.etaxonomy.taxeditor.ui.section.vocabulary.StateVocabularyCollectionSection;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermVocabularyDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermVocabularyDetailSection;
 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
@@ -2302,6 +2305,12 @@ public class CdmFormFactory extends FormToolkit {
         return section;
     }
 
+    public StateVocabularyCollectionSection createSectionStateVocabularies(ConversationHolder conversation, ICdmFormElement parentElement, int style){
+        StateVocabularyCollectionSection section = new StateVocabularyCollectionSection(this, conversation, parentElement, style);
+        addAndAdaptSection(parentElement, section);
+        return section;
+    }
+
     public CollectingAreasDetailSection createCollectingAreasDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
         CollectingAreasDetailSection section = new CollectingAreasDetailSection(this, conversation, parentElement, style);
         addAndAdaptSection(parentElement, section);
@@ -2533,6 +2542,8 @@ public class CdmFormFactory extends FormToolkit {
             else{
                 element = new IdentifierDetailElement(this, parentElement, (Identifier) entity, removeListener, style);
             }
+        } else if (entity instanceof TermVocabulary) {
+            element = new StateVocabularyCollectionElement(this, parentElement, (TermVocabulary<State>) entity, removeListener, backgroundColor, style);
         }
 
         if (element == null) {
index e40c90d..3ee690b 100644 (file)
 
 package eu.etaxonomy.taxeditor.ui.section.description;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
 import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.ui.forms.widgets.ExpandableComposite;
 
 import eu.etaxonomy.cdm.model.common.LanguageString;
 import eu.etaxonomy.cdm.model.common.TermType;
+import eu.etaxonomy.cdm.model.common.TermVocabulary;
 import eu.etaxonomy.cdm.model.description.State;
 import eu.etaxonomy.cdm.model.description.StateData;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -58,6 +63,12 @@ public class StateDataElement extends AbstractEntityCollectionElement<StateData>
        @Override
        public void setEntity(StateData entity) {
                this.entity = entity;
+               List<State> stateTerms = new ArrayList<State>();
+               Set<TermVocabulary<State>> stateVocabularies = getEntity().getCategoricalData().getFeature().getSupportedCategoricalEnumerations();
+               for (TermVocabulary<State> termVocabulary : stateVocabularies) {
+                   stateTerms.addAll(termVocabulary.getTerms());
+        }
+               combo_state.setTerms(stateTerms);
                combo_state.setSelection(entity.getState());
                section_modifiers.setEntity(entity);
                if(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
index 441cd85..7c79e1f 100644 (file)
@@ -9,10 +9,13 @@
 */\r
 package eu.etaxonomy.taxeditor.ui.section.vocabulary;\r
 \r
+import org.eclipse.ui.forms.widgets.ExpandableComposite;\r
+\r
 import eu.etaxonomy.cdm.model.description.Feature;\r
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;\r
 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;\r
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;\r
+import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;\r
 \r
 /**\r
  * @author l.morris\r
@@ -21,6 +24,8 @@ import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
  */\r
 public class FeatureDetailElement extends DefinedTermDetailElement<Feature> {\r
 \r
+    private ICdmFormElement parentFormElement;\r
+\r
     private CheckboxElement supportsTextData;\r
 \r
     private CheckboxElement supportsQuantitativeData;\r
@@ -35,6 +40,8 @@ public class FeatureDetailElement extends DefinedTermDetailElement<Feature> {
 \r
     private CheckboxElement supportsCommonTaxonName;\r
 \r
+    private StateVocabularyCollectionSection sectionStateVocabularies;\r
+\r
     /**\r
         * @param formFactory\r
         * @param formElement\r
@@ -50,6 +57,7 @@ public class FeatureDetailElement extends DefinedTermDetailElement<Feature> {
        @Override\r
        protected void createControls(ICdmFormElement formElement, Feature entity, int style) {\r
            super.createControls(formElement, entity, style);\r
+           this.parentFormElement = formElement;\r
            supportsTextData = formFactory.createCheckbox(formElement, "Supports Text Data", entity.isSupportsTextData(), style);\r
            supportsQuantitativeData = formFactory.createCheckbox(formElement, "Supports Quantitive Data", entity.isSupportsQuantitativeData(), style);\r
            supportsDistribution = formFactory.createCheckbox(formElement, "Supports Distribution", entity.isSupportsDistribution(), style);\r
@@ -57,6 +65,12 @@ public class FeatureDetailElement extends DefinedTermDetailElement<Feature> {
            supportsTaxonInteraction = formFactory.createCheckbox(formElement, "Supports Taxon Interaction", entity.isSupportsTaxonInteraction(), style);\r
            supportsCategoricalData = formFactory.createCheckbox(formElement, "Supports Categorical Data", entity.isSupportsCategoricalData(), style);\r
            supportsCommonTaxonName = formFactory.createCheckbox(formElement, "Supports Common Taxon Name", entity.isSupportsCommonTaxonName(), style);\r
+\r
+        if(supportsCategoricalData.getSelection()){\r
+            sectionStateVocabularies = formFactory.createSectionStateVocabularies(getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);\r
+            sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));\r
+            sectionStateVocabularies.setEntity(getEntity());\r
+        }\r
        }\r
 \r
        /* (non-Javadoc)\r
@@ -82,6 +96,16 @@ public class FeatureDetailElement extends DefinedTermDetailElement<Feature> {
            }\r
            else if(eventSource == supportsCategoricalData){\r
                getEntity().setSupportsCategoricalData(supportsCategoricalData.getSelection());\r
+               if(supportsCategoricalData.getSelection()){\r
+                   sectionStateVocabularies = formFactory.createSectionStateVocabularies(getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);\r
+                   sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));\r
+                   sectionStateVocabularies.setEntity(getEntity());\r
+               }\r
+               else{\r
+                   if(sectionStateVocabularies!=null){\r
+                       removeElementsAndControls(sectionStateVocabularies);\r
+                   }\r
+               }\r
            }\r
            else if(eventSource == supportsCommonTaxonName){\r
                getEntity().setSupportsCommonTaxonName(supportsCommonTaxonName.getSelection());\r
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/MeasurementUnitCollectionElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/MeasurementUnitCollectionElement.java
new file mode 100644 (file)
index 0000000..9b62d34
--- /dev/null
@@ -0,0 +1,75 @@
+// $Id$
+/**
+* Copyright (C) 2015 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.ui.section.vocabulary;
+
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+
+import eu.etaxonomy.cdm.model.common.TermType;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.MeasurementUnit;
+import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
+import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
+
+/**
+ * @author pplitzner
+ * @date Apr 27, 2015
+ *
+ */
+public class MeasurementUnitCollectionElement extends AbstractEntityCollectionElement<MeasurementUnit> {
+
+
+    private TermComboElement<MeasurementUnit> comboStateVocabulary;
+
+    /**
+     * @param formFactory
+     * @param section
+     * @param entity
+     * @param removeListener
+     * @param isChoosableEntity
+     * @param backgroundColor
+     * @param style
+     */
+    public MeasurementUnitCollectionElement(CdmFormFactory formFactory, AbstractFormSection section, MeasurementUnit entity,
+            SelectionListener removeListener, Color backgroundColor, int style) {
+        super(formFactory, section, entity, removeListener, false, backgroundColor, style);
+
+    }
+
+    @Override
+    public void createControls(ICdmFormElement element, int style) {
+        comboStateVocabulary = formFactory.createDefinedTermComboElement(TermType.MeasurementUnit, element, "Measurement unit", null, style);
+    }
+
+    @Override
+    public void setEntity(MeasurementUnit entity) {
+        this.entity = entity;
+        if(entity.getId()!=0){
+            comboStateVocabulary.setSelection(entity);
+        }
+    }
+
+    @Override
+    public void handleEvent(Object eventSource) {
+        if(eventSource==comboStateVocabulary && comboStateVocabulary.getSelection()!=null){
+            if(getParentElement() instanceof MeasurementUnitCollectionSection){
+                Feature feature = ((MeasurementUnitCollectionSection) getParentElement()).getEntity();
+                feature.removeRecommendedMeasurementUnit(entity);
+                MeasurementUnit measurementUnit = comboStateVocabulary.getSelection();
+                feature.addRecommendedMeasurementUnit(measurementUnit);
+                entity = measurementUnit;
+            }
+        }
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/MeasurementUnitCollectionSection.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/MeasurementUnitCollectionSection.java
new file mode 100644 (file)
index 0000000..8ba031b
--- /dev/null
@@ -0,0 +1,87 @@
+// $Id$
+/**
+* Copyright (C) 2015 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.ui.section.vocabulary;
+
+import java.util.Collection;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.MeasurementUnit;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.AbstractUnboundEntityCollectionSection;
+
+/**
+ * @author pplitzner
+ * @date Apr 27, 2015
+ *
+ */
+public class MeasurementUnitCollectionSection extends AbstractUnboundEntityCollectionSection<Feature, MeasurementUnit> {
+
+    public MeasurementUnitCollectionSection(CdmFormFactory formFactory,
+            ConversationHolder conversation, ICdmFormElement parentElement, int style) {
+        super(formFactory, conversation, parentElement, "Recommended measurement units", style);
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.ui.section.occurrence.dna.AbstractNullEntityCollectionSection#getEntityCollection(java.lang.Object)
+     */
+    /** {@inheritDoc} */
+    @Override
+    protected Collection<MeasurementUnit> getEntityCollection(Feature entity) {
+        return entity.getRecommendedMeasurementUnits();
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#createNewElement()
+     */
+    /** {@inheritDoc} */
+    @Override
+    public MeasurementUnit createNewElement() {
+        return MeasurementUnit.NewInstance();
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#addElement(eu.etaxonomy.cdm.model.common.IVersionableEntity)
+     */
+    /** {@inheritDoc} */
+    @Override
+    public void addElement(MeasurementUnit element) {
+        //never gets called
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#removeElement(eu.etaxonomy.cdm.model.common.IVersionableEntity)
+     */
+    /** {@inheritDoc} */
+    @Override
+    public void removeElement(MeasurementUnit element) {
+        getEntity().removeRecommendedMeasurementUnit(element);
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#getEmptyString()
+     */
+    /** {@inheritDoc} */
+    @Override
+    public String getEmptyString() {
+        return "No recommended measurement units yet.";
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#getTooltipString()
+     */
+    /** {@inheritDoc} */
+    @Override
+    protected String getTooltipString() {
+        return "Add a measurement unit";
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/StateVocabularyCollectionElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/StateVocabularyCollectionElement.java
new file mode 100644 (file)
index 0000000..a8094ed
--- /dev/null
@@ -0,0 +1,76 @@
+// $Id$
+/**
+* Copyright (C) 2015 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.ui.section.vocabulary;
+
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+
+import eu.etaxonomy.cdm.model.common.TermType;
+import eu.etaxonomy.cdm.model.common.TermVocabulary;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.State;
+import eu.etaxonomy.taxeditor.ui.combo.VocabularyComboElement;
+import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
+
+/**
+ * @author pplitzner
+ * @date Apr 27, 2015
+ *
+ */
+public class StateVocabularyCollectionElement extends AbstractEntityCollectionElement<TermVocabulary<State>> {
+
+
+    private VocabularyComboElement<State, TermVocabulary<State>> comboStateVocabulary;
+
+    /**
+     * @param formFactory
+     * @param section
+     * @param entity
+     * @param removeListener
+     * @param isChoosableEntity
+     * @param backgroundColor
+     * @param style
+     */
+    public StateVocabularyCollectionElement(CdmFormFactory formFactory, AbstractFormSection section, TermVocabulary<State> entity,
+            SelectionListener removeListener, Color backgroundColor, int style) {
+        super(formFactory, section, entity, removeListener, false, backgroundColor, style);
+
+    }
+
+    @Override
+    public void createControls(ICdmFormElement element, int style) {
+        comboStateVocabulary = formFactory.createVocabularyComboElement(TermType.State, "State vocabularies", null, element, style);
+    }
+
+    @Override
+    public void setEntity(TermVocabulary<State> entity) {
+        this.entity = entity;
+        if(entity.getId()!=0){
+            comboStateVocabulary.setSelection(entity);
+        }
+    }
+
+    @Override
+    public void handleEvent(Object eventSource) {
+        if(eventSource==comboStateVocabulary && comboStateVocabulary.getSelection()!=null){
+            if(getParentElement() instanceof StateVocabularyCollectionSection){
+                Feature feature = ((StateVocabularyCollectionSection) getParentElement()).getEntity();
+                feature.removeSupportedCategoricalEnumeration(entity);
+                TermVocabulary<State> vocabulary = comboStateVocabulary.getSelection();
+                feature.addSupportedCategoricalEnumeration(vocabulary);
+                entity = vocabulary;
+            }
+        }
+    }
+
+}
index a7b4b6f..f37d156 100644 (file)
@@ -12,6 +12,7 @@ package eu.etaxonomy.taxeditor.ui.section.vocabulary;
 import java.util.Collection;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.model.common.TermType;
 import eu.etaxonomy.cdm.model.common.TermVocabulary;
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.State;
@@ -46,7 +47,7 @@ public class StateVocabularyCollectionSection extends AbstractUnboundEntityColle
     /** {@inheritDoc} */
     @Override
     public TermVocabulary<State> createNewElement() {
-        return null;
+        return TermVocabulary.NewInstance(TermType.State);
     }
 
     /* (non-Javadoc)