ref #8990: add temporal data to editor
authorKatja Luther <k.luther@bgbm.org>
Fri, 12 Jun 2020 15:26:59 +0000 (17:26 +0200)
committerKatja Luther <k.luther@bgbm.org>
Fri, 12 Jun 2020 15:26:59 +0000 (17:26 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/FeatureDtoContentProvider.java [new file with mode: 0755]
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/element/DateDetailSection.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/ExtendedTimeDetailSection.java [new file with mode: 0755]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/ExtendedTimePeriodElement.java [new file with mode: 0755]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/PartialElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/TimePeriodElementBase.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/DescriptionElementDetailSection.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/detail/TemporalDataDetailElement.java [new file with mode: 0755]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/FeatureDetailElement.java

diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/FeatureDtoContentProvider.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/FeatureDtoContentProvider.java
new file mode 100755 (executable)
index 0000000..b841f04
--- /dev/null
@@ -0,0 +1,110 @@
+/**
+* Copyright (C) 2020 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.editor.definedterm;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+
+import eu.etaxonomy.cdm.api.service.IVocabularyService;
+import eu.etaxonomy.cdm.persistence.dto.FeatureDto;
+import eu.etaxonomy.cdm.persistence.dto.TermDto;
+import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author k.luther
+ * @since Jun 11, 2020
+ */
+public class FeatureDtoContentProvider extends TermDtoContentProvider {
+
+    boolean isAvailableForTaxon = true;
+    boolean isAvailableForTaxonName = true;
+    boolean isAvailableForOccurrence = true;
+
+    public FeatureDtoContentProvider(boolean isAvailableForTaxon, boolean isAvailableForTaxonName, boolean isAvailableForOccurrence){
+        super();
+        this.isAvailableForOccurrence = isAvailableForOccurrence;
+        this.isAvailableForTaxon = isAvailableForTaxon;
+        this.isAvailableForTaxonName = isAvailableForTaxonName;
+    }
+
+    @Override
+    public Object[] getChildren(Object parentElement) {
+        Collection<TermDto> children = new HashSet<>();
+        if(parentElement instanceof TermVocabularyDto){
+            children.addAll(getChildTerms((TermVocabularyDto)parentElement));
+        } else if(parentElement instanceof FeatureDto){
+                if(((FeatureDto) parentElement).getIncludes()!=null){
+                    for (TermDto child: ((FeatureDto) parentElement).getIncludes()){
+                        if (child instanceof FeatureDto){
+                            FeatureDto featureChild= (FeatureDto)child;
+                            if (featureChild.isAvailableForOccurrence() && isAvailableForOccurrence) {
+                                children.add(featureChild);
+                            }
+                            else if (featureChild.isAvailableForTaxon() && isAvailableForTaxon) {
+                                children.add(featureChild);
+                            }else if (featureChild.isAvailableForTaxonName() && isAvailableForTaxonName) {
+                                children.add(featureChild);
+                            }
+                        }
+                    }
+
+                }
+                if(((FeatureDto) parentElement).getGeneralizationOf()!=null){
+                    for (TermDto child: ((FeatureDto) parentElement).getGeneralizationOf()){
+                        if (child instanceof FeatureDto){
+                            FeatureDto featureChild= (FeatureDto)child;
+                            if (featureChild.isAvailableForOccurrence() && isAvailableForOccurrence) {
+                                children.add(featureChild);
+                            }
+                            else if (featureChild.isAvailableForTaxon() && isAvailableForTaxon) {
+                                children.add(featureChild);
+                            }else if (featureChild.isAvailableForTaxonName() && isAvailableForTaxonName) {
+                                children.add(featureChild);
+                            }
+                        }
+                    }
+
+                }
+        }
+        return children.toArray();
+    }
+
+
+
+    @Override
+    public Collection<TermDto> getChildTerms(TermVocabularyDto voc) {
+        Collection<TermDto> children = getVocabularyToChildTermMap().get(voc);
+        Collection<TermDto> filteredChildren = new HashSet<>();
+        if(children==null || children.isEmpty()){
+            children = new ArrayList<>(CdmStore.getService(IVocabularyService.class).getCompleteTermHierarchy(voc));
+            for (TermDto child: children){
+                if (child instanceof FeatureDto){
+                    FeatureDto featureChild= (FeatureDto)child;
+                    if (featureChild.isAvailableForOccurrence() && isAvailableForOccurrence) {
+                        filteredChildren.add(featureChild);
+                    }
+                    else if (featureChild.isAvailableForTaxon() && isAvailableForTaxon) {
+                        filteredChildren.add(featureChild);
+                    }else if (featureChild.isAvailableForTaxonName() && isAvailableForTaxonName) {
+                        filteredChildren.add(featureChild);
+                    }
+                }
+            }
+
+            getVocabularyToChildTermMap().put(voc, filteredChildren);
+        }else{
+            filteredChildren = children;
+        }
+        return filteredChildren;
+    }
+
+
+}
index 0328fcc7ef20699219c223b9fffc8847cf5cf331..e493dbb3de571bda42d47fb12d7eb7d9f7c2c51e 100644 (file)
@@ -59,6 +59,7 @@ import eu.etaxonomy.cdm.model.agent.Team;
 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.ExtendedTimePeriod;
 import eu.etaxonomy.cdm.model.common.Extension;
 import eu.etaxonomy.cdm.model.common.ICdmBase;
 import eu.etaxonomy.cdm.model.common.IdentifiableSource;
@@ -87,6 +88,7 @@ import eu.etaxonomy.cdm.model.description.StateData;
 import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
 import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
 import eu.etaxonomy.cdm.model.description.TaxonInteraction;
+import eu.etaxonomy.cdm.model.description.TemporalData;
 import eu.etaxonomy.cdm.model.description.TextData;
 import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
@@ -190,6 +192,7 @@ import eu.etaxonomy.taxeditor.ui.section.description.detail.DistributionDetailEl
 import eu.etaxonomy.taxeditor.ui.section.description.detail.IndividualsAssociationDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.description.detail.QuantitativeDataDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.description.detail.TaxonInteractionDetailElement;
+import eu.etaxonomy.taxeditor.ui.section.description.detail.TemporalDataDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.description.detail.TextDataDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.feature.CharacterDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.feature.CharacterDetailSection;
@@ -2584,6 +2587,7 @@ public class CdmFormFactory extends FormToolkit {
 
     public RightsSection createRightsSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
         RightsSection section = new RightsSection(this, conversation, parentElement, style);
+
         addAndAdaptSection(parentElement, section);
         return section;
     }
@@ -3217,9 +3221,12 @@ public class CdmFormFactory extends FormToolkit {
         } else if (entity instanceof TaxonInteraction) {
             detailedDescriptionElement = new TaxonInteractionDetailElement(this, parentElement,
                     (TaxonInteraction) entity, style);
+        } else if (entity instanceof TemporalData) {
+            detailedDescriptionElement = new TemporalDataDetailElement(this, parentElement, (TemporalData) entity, style);
         } else if (entity instanceof TextData) {
             detailedDescriptionElement = new TextDataDetailElement(this, parentElement, (TextData) entity, style);
-        } else {
+        }
+        else {
             throw new IllegalStateException("There is no interface for the given description element");
         }
         adapt(detailedDescriptionElement);
@@ -3328,6 +3335,26 @@ public class CdmFormFactory extends FormToolkit {
         return element;
     }
 
+    /**
+     * @param extendedTimePeriodElement
+     * @param twistie
+     * @return
+     */
+    public ExtendedTimeDetailSection createExtendedTimeDetailSection(
+            ExtendedTimePeriodElement parentElement, int style) {
+        ExtendedTimeDetailSection section = new ExtendedTimeDetailSection(this, parentElement,  style);
+        parentElement.addElement(section);
+        adapt(section);
+        return section;
+    }
+    public ExtendedTimePeriodElement createExtendedTimePeriodElement(
+            ICdmFormElement parentElement, String labelString, ExtendedTimePeriod timePeriod, int style) {
+        ExtendedTimePeriodElement section = new ExtendedTimePeriodElement(this, parentElement, labelString, timePeriod, style);
+        parentElement.addElement(section);
+        adapt(section);
+        return section;
+    }
+
 
 //     public RichTextWithLabelElement createRichTextLabelElement(ICdmFormElement parentElement, String labelString, String initialText, int textHeight, int style) {
 //              RichTextWithLabelElement element = new RichTextWithLabelElement(this, parentElement, labelString,
index deed62ff351da371878b5b75ff97eff6423cc119..d0d8bcb53abf3f116f2b4c6ddd1d246dbde60f60 100644 (file)
@@ -13,13 +13,13 @@ import eu.etaxonomy.taxeditor.l10n.Messages;
 public class DateDetailSection<T extends TimePeriod>\r
                extends AbstractFormSection<T> {\r
        protected TextWithLabelElement text_freeText;\r
-       private PartialElement partialElement_start;\r
-       private PartialElement partialElement_end;\r
-       private CheckboxElement period_continue;\r
-       private TextWithLabelElement text_parseText;\r
-    private TextWithLabelElement text_VerbatimDate = null;\r
-       private int cursorPosition;\r
-       private boolean includeVerbatim;\r
+       protected PartialElement partialElement_start;\r
+       protected PartialElement partialElement_end;\r
+       protected CheckboxElement period_continue;\r
+       protected TextWithLabelElement text_parseText;\r
+    protected TextWithLabelElement text_VerbatimDate = null;\r
+       protected int cursorPosition;\r
+       protected boolean includeVerbatim;\r
 \r
        public int getCursorPosition() {\r
         return cursorPosition;\r
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/ExtendedTimeDetailSection.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/ExtendedTimeDetailSection.java
new file mode 100755 (executable)
index 0000000..8611225
--- /dev/null
@@ -0,0 +1,63 @@
+/**
+* Copyright (C) 2020 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.element;
+
+import eu.etaxonomy.cdm.model.common.ExtendedTimePeriod;
+
+/**
+ * @author k.luther
+ * @since Jun 12, 2020
+ */
+public class ExtendedTimeDetailSection extends DateDetailSection<ExtendedTimePeriod> {
+
+    private PartialElement partialElement_extremeStart;
+    private PartialElement partialElement_extremeEnd;
+    /**
+     * @param formFactory
+     * @param parentElement
+     * @param includeVerbatim
+     * @param style
+     */
+    protected ExtendedTimeDetailSection(CdmFormFactory formFactory, ICdmFormElement parentElement,
+             int style) {
+        super(formFactory, parentElement, false, style);
+
+//        this.includeVerbatim = includeVerbatim;
+
+
+        partialElement_extremeStart = formFactory.createPartialElement(this, "Extreme Start", null, style);
+        partialElement_start = formFactory.createPartialElement(this,
+                "Start ", null, style);
+
+        period_continue = formFactory.createCheckbox(this, "Continue", false, style);
+        period_continue.getMainControl().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(6,1));
+        partialElement_end = formFactory.createPartialElement(this, "End ",
+                null, style);
+
+        partialElement_extremeEnd = formFactory.createPartialElement(this, "Extreme End ",
+                null, style);
+
+        text_freeText = formFactory.createTextWithLabelElement(this,
+                "Freetext", null, style);
+        text_freeText.getMainControl().setLayoutData(
+                LayoutConstants.FILL_HORIZONTALLY(6, 1));
+
+
+        formFactory.addPropertyChangeListener(this);
+
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    protected ExtendedTimePeriod newInstance(){
+        return ExtendedTimePeriod.NewExtendedInstance();
+
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/ExtendedTimePeriodElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/ExtendedTimePeriodElement.java
new file mode 100755 (executable)
index 0000000..d12b254
--- /dev/null
@@ -0,0 +1,76 @@
+/**
+* Copyright (C) 2020 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.element;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.forms.widgets.Section;
+
+import eu.etaxonomy.cdm.model.common.ExtendedTimePeriod;
+
+/**
+ * @author k.luther
+ * @since Jun 12, 2020
+ */
+public class ExtendedTimePeriodElement extends AbstractCdmFormElement implements ISelectable {
+
+    protected ExtendedTimePeriod timePeriod;
+    protected Label label;
+    protected ExtendedTimeDetailSection section_dateDetails;
+
+    /**
+     * @param formFactory
+     * @param parentElement
+     * @param labelString
+     * @param timePeriod
+     * @param style
+     */
+    public ExtendedTimePeriodElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
+            ExtendedTimePeriod timePeriod, int style) {
+        super(formFactory, parentElement);
+        label = formFactory.createLabel(getLayoutComposite(), labelString);
+
+        addControl(label);
+
+        section_dateDetails = createDateDetailSection();
+        addControl(section_dateDetails);
+
+        setTimePeriod(timePeriod);
+
+        formFactory.addPropertyChangeListener(this);
+    }
+
+    protected ExtendedTimeDetailSection createDateDetailSection() {
+        return formFactory.createExtendedTimeDetailSection(this,
+                Section.TWISTIE);
+    }
+
+    @Override
+    public void setBackground(Color color) {
+        label.setBackground(color);
+        section_dateDetails.setBackground(color);
+    }
+
+    @Override
+    public void setSelected(boolean selected) {
+        setBackground(selected ? SELECTED : getPersistentBackground());
+    }
+
+    public void setLabel(String string) {
+        label.setText(string);
+    }
+
+    public void setTimePeriod(ExtendedTimePeriod timePeriod) {
+        this.timePeriod = timePeriod;
+        if (timePeriod != null) {
+            section_dateDetails.setEntity(timePeriod);
+        }
+    }
+
+}
index cbc8fbcd3697a06bc2086a92e7b24942212c6718..bc1d89257f54fa7826b445abf141e31e381de07c 100644 (file)
@@ -49,8 +49,7 @@ public class PartialElement extends AbstractCdmFormElement implements ISelectabl
                super(formFactory, formElement);
 
                TableWrapLayout layout = LayoutConstants.LAYOUT(7, false);
-               layout.horizontalSpacing = 5;
-        formElement.getLayoutComposite().setLayout(layout);
+               formElement.getLayoutComposite().setLayout(layout);
 
                label = formFactory.createLabel(getLayoutComposite(), labelString);
                addControl(label);
index f88fe381c70cc1ce1395bafd1ed7bbc09f31f0fb..2a8a3c3f164c6885fb8877882672085f28279a21 100644 (file)
@@ -4,13 +4,18 @@ import org.eclipse.jface.util.PropertyChangeEvent;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.widgets.Label;
 
-
 import eu.etaxonomy.cdm.model.common.TimePeriod;
 
-public abstract class TimePeriodElementBase<T extends TimePeriod> 
-               extends AbstractCdmFormElement 
+public abstract class TimePeriodElementBase<T extends TimePeriod>
+               extends AbstractCdmFormElement
                implements ISelectable {
-       
+
+
+
+    protected T timePeriod;
+    protected Label label;
+    protected DateDetailSection<T> section_dateDetails;
+
        /**
         * <p>
         * Constructor for TimePeriodElement.
@@ -45,12 +50,8 @@ public abstract class TimePeriodElementBase<T extends TimePeriod>
                formFactory.addPropertyChangeListener(this);
        }
 
-       protected abstract DateDetailSection<T> createDateDetailSection();
-
-       protected T timePeriod;
-       protected Label label;
-       protected DateDetailSection<T> section_dateDetails;
 
+       protected abstract DateDetailSection<T> createDateDetailSection();
 
        /**
         * <p>
index 064904c26819cb063d86f3e91553d33b1a86d50c..92084153f2e0f656e922cfaf9cc519999575003b 100644 (file)
@@ -129,6 +129,7 @@ public class DescriptionElementDetailSection extends
            if(feature.isSupportsQuantitativeData()){count++;}
            if(feature.isSupportsTaxonInteraction()){count++;}
            if(feature.isSupportsTextData()){count++;}
+           if(feature.isSupportsTemporalData()){count++;}
            return count > 1;
        }
 
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/detail/TemporalDataDetailElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/detail/TemporalDataDetailElement.java
new file mode 100755 (executable)
index 0000000..140def9
--- /dev/null
@@ -0,0 +1,43 @@
+/**
+* Copyright (C) 2020 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.description.detail;
+
+import eu.etaxonomy.cdm.model.description.TemporalData;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ExtendedTimePeriodElement;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+
+/**
+ * @author k.luther
+ * @since Jun 12, 2020
+ */
+public class TemporalDataDetailElement extends AbstractDetailedDescriptionDetailElement<TemporalData> {
+
+    ExtendedTimePeriodElement timePeriod;
+
+    /**
+     * @param formFactory
+     * @param formElement
+     * @param entity
+     * @param style
+     */
+    public TemporalDataDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement, TemporalData entity,
+            int style) {
+        super(formFactory, formElement, entity, style);
+
+    }
+
+    @Override
+    protected void createControls(ICdmFormElement formElement, TemporalData entity, int style) {
+        timePeriod = formFactory.createExtendedTimePeriodElement(formElement, "Flowering Season", entity.getPeriod(), style);
+
+
+    }
+
+}
index 0b4571761bd800d97462e2eb4324b35d7ea5bcef..2b631f0c2f21e1529431bbb93320cf9569acf99c 100644 (file)
@@ -38,6 +38,8 @@ public class FeatureDetailElement extends DefinedTermDetailElement<Feature> {
 \r
     private CheckboxElement supportsCommonTaxonName;\r
 \r
+    private CheckboxElement supportsTemporalData;\r
+\r
     private StateVocabularyCollectionSection sectionStateVocabularies;\r
 \r
     private MeasurementUnitCollectionSection sectionMeasurementUnits;\r
@@ -72,6 +74,7 @@ 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
+           supportsTemporalData = formFactory.createCheckbox(formElement, "Supports Temporal Data", entity.isSupportsTemporalData(), style);\r
 \r
         if (supportsCategoricalData.getSelection()) {\r
             sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(),\r
@@ -144,6 +147,9 @@ public class FeatureDetailElement extends DefinedTermDetailElement<Feature> {
            else if(eventSource == supportsCommonTaxonName){\r
                getEntity().setSupportsCommonTaxonName(supportsCommonTaxonName.getSelection());\r
            }\r
+           else if(eventSource == supportsTemporalData){\r
+            getEntity().setSupportsTemporalData(supportsTemporalData.getSelection());\r
+        }\r
            else if(eventSource == availableForSpecimenOrObservation){\r
             getEntity().setAvailableForOccurrence(availableForSpecimenOrObservation.getSelection());\r
         }\r