ref #8475 First (unstable) implementation of FeatureState details
authorPatrick Plitzner <p.plitzner@bgbm.org>
Fri, 16 Aug 2019 13:09:08 +0000 (15:09 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Fri, 16 Aug 2019 13:09:43 +0000 (15:09 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditor.java
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/feature/AbstractApplicableElement.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/InapplicableIfCollectionElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/InapplicableIfEntityCollectionSection.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/OnlyApplicableIfCollectionElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/OnlyApplicableIfEntityCollectionSection.java

index 19a1fb1205dc5cd8d30c265f38723c60f54752a5..1c0ff6f2a6d3a3c935cc1f0c34dfac28431c9e8a 100644 (file)
@@ -79,6 +79,17 @@ public class FeatureTreeEditor implements IFeatureTreeEditor, ISelectionChangedL
         IE4ViewerPart, IPartContentHasDetails, IPartContentHasSupplementalData,
         IContextListener, IConversationEnabled, IDirtyMarkable {
 
+    private static final List<String> TREE_PROPERTY_PATH = Arrays.asList(new String[] {
+            "root", //$NON-NLS-1$
+            "root.children", //$NON-NLS-1$
+            "root.children.inapplicableIf", //$NON-NLS-1$
+            "root.children.inapplicableIf.feature", //$NON-NLS-1$
+            "root.children.inapplicableIf.state", //$NON-NLS-1$
+            "root.children.onlyApplicableIf", //$NON-NLS-1$
+            "root.children.onlyApplicableIf.feature", //$NON-NLS-1$
+            "root.children.onlyApplicableIf.state", //$NON-NLS-1$
+    });
+
     private ConversationHolder conversation;
 
     private ICdmEntitySession cdmEntitySession;
@@ -135,7 +146,7 @@ public class FeatureTreeEditor implements IFeatureTreeEditor, ISelectionChangedL
             }
         });
 
-        List<TermTree> trees = CdmStore.getService(ITermTreeService.class).list(TermTree.class, null, null, null, null);
+        List<TermTree> trees = CdmStore.getService(ITermTreeService.class).list(TermTree.class, null, null, null, TREE_PROPERTY_PATH);
         viewer.setComparator(new FeatureTreeViewerComparator());
         viewer.setInput(trees);
 
index a8456ae6f3530028f7758ecaac21c9cc7e28aabe..73316c3843c10805f4efda31ad5b71447230be42 100644 (file)
@@ -59,8 +59,6 @@ import eu.etaxonomy.cdm.model.common.Annotation;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.Credit;
 import eu.etaxonomy.cdm.model.common.Extension;
-import eu.etaxonomy.cdm.model.permission.GrantedAuthorityImpl;
-import eu.etaxonomy.cdm.model.permission.Group;
 import eu.etaxonomy.cdm.model.common.ICdmBase;
 import eu.etaxonomy.cdm.model.common.IdentifiableSource;
 import eu.etaxonomy.cdm.model.common.Identifier;
@@ -69,7 +67,6 @@ import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.common.LanguageString;
 import eu.etaxonomy.cdm.model.common.Marker;
 import eu.etaxonomy.cdm.model.common.TimePeriod;
-import eu.etaxonomy.cdm.model.permission.User;
 import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
 import eu.etaxonomy.cdm.model.common.VersionableEntity;
 import eu.etaxonomy.cdm.model.description.CategoricalData;
@@ -78,6 +75,7 @@ import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
 import eu.etaxonomy.cdm.model.description.Distribution;
 import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.FeatureState;
 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
 import eu.etaxonomy.cdm.model.description.KeyStatement;
 import eu.etaxonomy.cdm.model.description.MeasurementUnit;
@@ -107,6 +105,9 @@ import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
 import eu.etaxonomy.cdm.model.name.TextualTypeDesignation;
 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
 import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
+import eu.etaxonomy.cdm.model.permission.GrantedAuthorityImpl;
+import eu.etaxonomy.cdm.model.permission.Group;
+import eu.etaxonomy.cdm.model.permission.User;
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
@@ -2882,10 +2883,10 @@ public class CdmFormFactory extends FormToolkit {
             element = new MeasurementUnitCollectionElement(this, parentElement, (MeasurementUnit) entity, removeListener, backgroundColor, style);
         } else if (entity instanceof StatisticalMeasure) {
             element = new StatisticalMeasureCollectionElement(this, parentElement, (StatisticalMeasure) entity, removeListener, backgroundColor, style);
-        } else if (entity instanceof State && parentElement instanceof InapplicableIfEntityCollectionSection) {
-            element = new InapplicableIfCollectionElement(this, parentElement, (State) entity, removeListener, backgroundColor, style);
-        } else if (entity instanceof State && parentElement instanceof OnlyApplicableIfEntityCollectionSection) {
-            element = new OnlyApplicableIfCollectionElement(this, parentElement, (State) entity, removeListener, backgroundColor, style);
+        } else if (entity instanceof FeatureState && parentElement instanceof InapplicableIfEntityCollectionSection) {
+            element = new InapplicableIfCollectionElement(this, parentElement, (FeatureState) entity, removeListener, backgroundColor, style);
+        } else if (entity instanceof FeatureState && parentElement instanceof OnlyApplicableIfEntityCollectionSection) {
+            element = new OnlyApplicableIfCollectionElement(this, parentElement, (FeatureState) entity, removeListener, backgroundColor, style);
         }
 
         //check for parent section when entity is null
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/AbstractApplicableElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/AbstractApplicableElement.java
new file mode 100644 (file)
index 0000000..77d0db1
--- /dev/null
@@ -0,0 +1,100 @@
+/**
+* Copyright (C) 2019 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.feature;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.FeatureState;
+import eu.etaxonomy.cdm.model.description.State;
+import eu.etaxonomy.cdm.model.term.TermNode;
+import eu.etaxonomy.cdm.model.term.TermVocabulary;
+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;
+import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
+
+/**
+ * @author pplitzner
+ * @since Aug 16, 2019
+ *
+ */
+public abstract class AbstractApplicableElement extends AbstractEntityCollectionElement<FeatureState> {
+
+    private TermComboElement<State> comboState;
+    private EntitySelectionElement<Feature> selectFeature;
+
+    public AbstractApplicableElement(CdmFormFactory formFactory, AbstractFormSection section, FeatureState entity,
+            SelectionListener removeListener, Color backgroundColor, int style) {
+        super(formFactory, section, entity, removeListener, backgroundColor, style);
+
+    }
+
+    @Override
+    public void createControls(ICdmFormElement element, int style) {
+        selectFeature = formFactory.createSelectionElement(Feature.class, element, "Feature", null, EntitySelectionElement.SELECTABLE, SWT.NONE);
+        comboState = formFactory.createDefinedTermComboElement(Collections.EMPTY_LIST, element, getComboLabel(), null, style);
+        comboState.setEnabled(false);
+    }
+
+    protected abstract String getComboLabel();
+
+    @Override
+    public void setEntity(FeatureState entity) {
+        this.entity = entity;
+        Feature feature = entity.getFeature();
+        selectFeature.setEntity(feature);
+        if(feature!=null){
+            updateCombo(feature);
+        }
+    }
+
+    private void updateCombo(Feature feature){
+        comboState.setEnabled(true);
+        List<State> stateTerms = new ArrayList<State>();
+        Set<TermVocabulary<State>> stateVocabularies = feature.getSupportedCategoricalEnumerations();
+        for (TermVocabulary<State> termVocabulary : stateVocabularies) {
+            stateTerms.addAll(termVocabulary.getTerms());
+        }
+        comboState.setTerms(stateTerms);
+        comboState.setSelection(entity.getState());
+        if(getEntity().getId()>0){
+            comboState.removeEmptyElement();
+        }
+    }
+
+    @Override
+    public void handleEvent(Object eventSource) {
+        if(eventSource==selectFeature){
+            Feature feature = selectFeature.getSelection();
+            entity.setFeature(feature);
+            updateCombo(feature);
+        }
+        else if(eventSource==comboState && comboState.getSelection()!=null){
+            if(getParentElement() instanceof OnlyApplicableIfEntityCollectionSection){
+                OnlyApplicableIfEntityCollectionSection parentElement = (OnlyApplicableIfEntityCollectionSection) getParentElement();
+                TermNode node = parentElement.getEntity();
+                node.removeApplicableState(entity);
+                State state = comboState.getSelection();
+                entity.setState(state);
+                node.addApplicableState(entity);
+                parentElement.removeElementAndUpdate(null);
+            }
+        }
+    }
+}
index d4f5aff8f22f6c2d451712ab51015c4e8bfafa0d..e180ba56c2208aea9a1ee48c9c612c10d9098e5c 100644 (file)
@@ -11,57 +11,26 @@ package eu.etaxonomy.taxeditor.ui.section.feature;
 import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.graphics.Color;
 
-import eu.etaxonomy.cdm.model.description.State;
-import eu.etaxonomy.cdm.model.term.TermNode;
-import eu.etaxonomy.cdm.model.term.TermType;
-import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
+import eu.etaxonomy.cdm.model.description.FeatureState;
 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 InapplicableIfCollectionElement extends AbstractEntityCollectionElement<State> {
+public class InapplicableIfCollectionElement extends AbstractApplicableElement {
 
-    private TermComboElement<State> comboState;
-
-    public InapplicableIfCollectionElement(CdmFormFactory formFactory, AbstractFormSection section, State entity,
+    public InapplicableIfCollectionElement(CdmFormFactory formFactory, AbstractFormSection section, FeatureState entity,
             SelectionListener removeListener, Color backgroundColor, int style) {
         super(formFactory, section, entity, removeListener, backgroundColor, style);
-
-    }
-
-    @Override
-    public void createControls(ICdmFormElement element, int style) {
-        comboState = formFactory.createDefinedTermComboElement(TermType.State, element, "Inapplicable if", null, style);
-    }
-
-    @Override
-    public void setEntity(State entity) {
-        this.entity = entity;
-        if(entity.getId()!=0){
-            comboState.setSelection(entity);
-            comboState.removeEmptyElement();
-        }
     }
 
     @Override
-    public void handleEvent(Object eventSource) {
-        if(eventSource==comboState && comboState.getSelection()!=null){
-            if(getParentElement() instanceof InapplicableIfEntityCollectionSection){
-                InapplicableIfEntityCollectionSection parentElement = (InapplicableIfEntityCollectionSection) getParentElement();
-                TermNode node = parentElement.getEntity();
-                node.removeInapplicableState(entity);
-                State state = comboState.getSelection();
-                node.addInapplicableState(state);
-                entity = state;
-                parentElement.removeElementAndUpdate(null);
-            }
-        }
+    protected String getComboLabel() {
+        // TODO Auto-generated method stub
+        return "Inapplicable if";
     }
 
 }
index 5d239c4726e75f6c8dbb27e1c386cd4aa87e8f07..4a37534824f84bfa3f1573e9cd1b0fdb9a84df22 100644 (file)
@@ -13,19 +13,19 @@ import java.util.Collection;
 import java.util.Comparator;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
-import eu.etaxonomy.cdm.model.description.State;
+import eu.etaxonomy.cdm.model.description.FeatureState;
 import eu.etaxonomy.cdm.model.term.TermNode;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
 import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator;
-import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.AbstractUnboundEntityCollectionSection;
 
 /**
  * @author pplitzner
  * @date 06.03.2018
  *
  */
-public class InapplicableIfEntityCollectionSection extends AbstractUnboundEntityCollectionSection<TermNode, State>{
+public class InapplicableIfEntityCollectionSection extends AbstractEntityCollectionSection<TermNode, FeatureState>{
 
     public InapplicableIfEntityCollectionSection(CdmFormFactory formFactory, ConversationHolder conversation,
             ICdmFormElement parentElement, int style) {
@@ -36,7 +36,7 @@ public class InapplicableIfEntityCollectionSection extends AbstractUnboundEntity
      * {@inheritDoc}
      */
     @Override
-    protected Collection<State> getEntityCollection(TermNode entity) {
+    public Collection<FeatureState> getCollection(TermNode entity) {
         return entity.getInapplicableIf();
     }
 
@@ -44,31 +44,32 @@ public class InapplicableIfEntityCollectionSection extends AbstractUnboundEntity
      * {@inheritDoc}
      */
     @Override
-    public Comparator<State> getComparator() {
+    public Comparator<FeatureState> getComparator() {
         return new DefaultCdmBaseComparator<>();
     }
 
+
     /**
      * {@inheritDoc}
      */
     @Override
-    public State createNewElement() {
-        return State.NewInstance();
+    public FeatureState createNewElement() {
+        return FeatureState.NewInstance();
     }
 
     /**
      * {@inheritDoc}
      */
     @Override
-    public void addElement(State element) {
-        //never called
+    public void addElement(FeatureState element) {
+        getEntity().addInapplicableState(element);
     }
 
     /**
      * {@inheritDoc}
      */
     @Override
-    public State addExisting() {
+    public FeatureState addExisting() {
         return null;
     }
 
@@ -84,20 +85,20 @@ public class InapplicableIfEntityCollectionSection extends AbstractUnboundEntity
      * {@inheritDoc}
      */
     @Override
-    public void removeElement(State element) {
+    public void removeElement(FeatureState element) {
         getEntity().removeInapplicableState(element);
     }
 
     /** {@inheritDoc} */
     @Override
     public String getEmptyString() {
-        return "No state added yet.";
+        return "No feature state added yet.";
     }
 
     /** {@inheritDoc} */
     @Override
     protected String getTooltipString() {
-        return "Add a state";
+        return "Add a feature state";
     }
 
 }
index 47336cd3a8b1778e569906cf6aed1621c24e6d94..86592b628a9d0aac6787843b64a61c680699210a 100644 (file)
@@ -11,57 +11,26 @@ package eu.etaxonomy.taxeditor.ui.section.feature;
 import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.graphics.Color;
 
-import eu.etaxonomy.cdm.model.description.State;
-import eu.etaxonomy.cdm.model.term.TermNode;
-import eu.etaxonomy.cdm.model.term.TermType;
-import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
+import eu.etaxonomy.cdm.model.description.FeatureState;
 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 OnlyApplicableIfCollectionElement extends AbstractEntityCollectionElement<State> {
+public class OnlyApplicableIfCollectionElement extends AbstractApplicableElement {
 
-    private TermComboElement<State> comboState;
-
-    public OnlyApplicableIfCollectionElement(CdmFormFactory formFactory, AbstractFormSection section, State entity,
-            SelectionListener removeListener, Color backgroundColor, int style) {
+    public OnlyApplicableIfCollectionElement(CdmFormFactory formFactory, AbstractFormSection section,
+            FeatureState entity, SelectionListener removeListener, Color backgroundColor, int style) {
         super(formFactory, section, entity, removeListener, backgroundColor, style);
-
     }
 
     @Override
-    public void createControls(ICdmFormElement element, int style) {
-        comboState = formFactory.createDefinedTermComboElement(TermType.State, element, "Only applicable if", null, style);
+    protected String getComboLabel() {
+        return "Only applicable if";
     }
 
-    @Override
-    public void setEntity(State entity) {
-        this.entity = entity;
-        if(entity.getId()!=0){
-            comboState.setSelection(entity);
-            comboState.removeEmptyElement();
-        }
-    }
-
-    @Override
-    public void handleEvent(Object eventSource) {
-        if(eventSource==comboState && comboState.getSelection()!=null){
-            if(getParentElement() instanceof OnlyApplicableIfEntityCollectionSection){
-                OnlyApplicableIfEntityCollectionSection parentElement = (OnlyApplicableIfEntityCollectionSection) getParentElement();
-                TermNode node = parentElement.getEntity();
-                node.removeApplicableState(entity);
-                State state = comboState.getSelection();
-                node.addApplicableState(state);
-                entity = state;
-                parentElement.removeElementAndUpdate(null);
-            }
-        }
-    }
 
 }
index 78d3c5e1442ccce091ba52b815b07cecd5d5b181..d4fa4b1f825218c6b6b87647da82b1afbd7c379e 100644 (file)
@@ -13,19 +13,19 @@ import java.util.Collection;
 import java.util.Comparator;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
-import eu.etaxonomy.cdm.model.description.State;
+import eu.etaxonomy.cdm.model.description.FeatureState;
 import eu.etaxonomy.cdm.model.term.TermNode;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
 import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator;
-import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.AbstractUnboundEntityCollectionSection;
 
 /**
  * @author pplitzner
  * @date 06.03.2018
  *
  */
-public class OnlyApplicableIfEntityCollectionSection extends AbstractUnboundEntityCollectionSection<TermNode, State>{
+public class OnlyApplicableIfEntityCollectionSection extends AbstractEntityCollectionSection<TermNode, FeatureState>{
 
     public OnlyApplicableIfEntityCollectionSection(CdmFormFactory formFactory, ConversationHolder conversation,
             ICdmFormElement parentElement, int style) {
@@ -36,7 +36,7 @@ public class OnlyApplicableIfEntityCollectionSection extends AbstractUnboundEnti
      * {@inheritDoc}
      */
     @Override
-    protected Collection<State> getEntityCollection(TermNode entity) {
+    public Collection<FeatureState> getCollection(TermNode entity) {
         return entity.getOnlyApplicableIf();
     }
 
@@ -44,7 +44,7 @@ public class OnlyApplicableIfEntityCollectionSection extends AbstractUnboundEnti
      * {@inheritDoc}
      */
     @Override
-    public Comparator<State> getComparator() {
+    public Comparator<FeatureState> getComparator() {
         return new DefaultCdmBaseComparator<>();
     }
 
@@ -52,23 +52,23 @@ public class OnlyApplicableIfEntityCollectionSection extends AbstractUnboundEnti
      * {@inheritDoc}
      */
     @Override
-    public State createNewElement() {
-        return State.NewInstance();
+    public FeatureState createNewElement() {
+        return FeatureState.NewInstance();
     }
 
     /**
      * {@inheritDoc}
      */
     @Override
-    public void addElement(State element) {
-        //never called
+    public void addElement(FeatureState element) {
+        getEntity().addApplicableState(element);
     }
 
     /**
      * {@inheritDoc}
      */
     @Override
-    public State addExisting() {
+    public FeatureState addExisting() {
         return null;
     }
 
@@ -84,20 +84,20 @@ public class OnlyApplicableIfEntityCollectionSection extends AbstractUnboundEnti
      * {@inheritDoc}
      */
     @Override
-    public void removeElement(State element) {
+    public void removeElement(FeatureState element) {
         getEntity().removeApplicableState(element);
     }
 
     /** {@inheritDoc} */
     @Override
     public String getEmptyString() {
-        return "No state added yet.";
+        return "No feature state added yet.";
     }
 
     /** {@inheritDoc} */
     @Override
     protected String getTooltipString() {
-        return "Add a state";
+        return "Add a feature state";
     }
 
 }