ref #9537: add button to ratioTo element
authorKatja Luther <k.luther@bgbm.org>
Thu, 1 Apr 2021 09:32:19 +0000 (11:32 +0200)
committerKatja Luther <k.luther@bgbm.org>
Thu, 1 Apr 2021 09:34:12 +0000 (11:34 +0200)
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/RemovableTextElement.java [new file with mode: 0755]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/CharacterDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/CharacterDtoDetailElement.java

index 7ac4541eb5708fb8195f8ea309220bfdabf70457..7f8222b2c62c194a3580c833034f34ae6e12d0cc 100644 (file)
@@ -212,18 +212,18 @@ import eu.etaxonomy.taxeditor.ui.section.feature.CharacterNodeDtoDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.feature.CharacterNodeDtoDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.feature.FeatureDistributionDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.feature.FeatureDistributionDetailSection;
-import eu.etaxonomy.taxeditor.ui.section.feature.TermNodeDetailElement;
-import eu.etaxonomy.taxeditor.ui.section.feature.TermNodeDetailSection;
-import eu.etaxonomy.taxeditor.ui.section.feature.TermTreeDetailElement;
-import eu.etaxonomy.taxeditor.ui.section.feature.TermTreeDetailElementForNode;
-import eu.etaxonomy.taxeditor.ui.section.feature.TermTreeDetailSection;
-import eu.etaxonomy.taxeditor.ui.section.feature.TermTreeDetailSectionForNode;
 import eu.etaxonomy.taxeditor.ui.section.feature.InapplicableIfCollectionElement;
 import eu.etaxonomy.taxeditor.ui.section.feature.InapplicableIfEntityCollectionSection;
 import eu.etaxonomy.taxeditor.ui.section.feature.InapplicableIfEntityCollectionSectionForNode;
 import eu.etaxonomy.taxeditor.ui.section.feature.OnlyApplicableIfCollectionElement;
 import eu.etaxonomy.taxeditor.ui.section.feature.OnlyApplicableIfEntityCollectionSection;
 import eu.etaxonomy.taxeditor.ui.section.feature.OnlyApplicableIfEntityCollectionSectionForNode;
+import eu.etaxonomy.taxeditor.ui.section.feature.TermNodeDetailElement;
+import eu.etaxonomy.taxeditor.ui.section.feature.TermNodeDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.feature.TermTreeDetailElement;
+import eu.etaxonomy.taxeditor.ui.section.feature.TermTreeDetailElementForNode;
+import eu.etaxonomy.taxeditor.ui.section.feature.TermTreeDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.feature.TermTreeDetailSectionForNode;
 import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityCollectionElement;
 import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityDetailSection;
@@ -1370,6 +1370,20 @@ public class CdmFormFactory extends FormToolkit {
         return createToggleableTextField(parentElement, labelString, initialText, initialState, CacheRelevance.CACHE1, style);
     }
 
+    /**
+     * like {@link #createToggleableTextField(ICdmFormElement, String, String, boolean, CacheRelevance, int)}
+     * but with predefined cache relevance == 1
+     */
+    public RemovableTextElement createRemovableTextField(ICdmFormElement parentElement, String labelString,
+            String initialText, int style) {
+        RemovableTextElement element = new RemovableTextElement(this, parentElement, labelString, initialText,
+                style | orientation);
+
+        adapt(element);
+        parentElement.addElement(element);
+        return element;
+    }
+
 
     /**
      * createTimePeriodElement
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/RemovableTextElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/RemovableTextElement.java
new file mode 100755 (executable)
index 0000000..ae23839
--- /dev/null
@@ -0,0 +1,98 @@
+/**
+* Copyright (C) 2021 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.apache.commons.lang3.StringUtils;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+import eu.etaxonomy.taxeditor.model.ImageResources;
+
+/**
+ * @author k.luther
+ * @since Apr 1, 2021
+ */
+public class RemovableTextElement extends AbstractCdmFormElement implements SelectionListener {
+
+    private final Text text_cache;
+    private final Button btnRemoveElement;
+    private final Label label;
+    private final Composite container;
+    private boolean state;
+
+    protected RemovableTextElement(CdmFormFactory formFactory, ICdmFormElement parentElement,
+            String labelString, String initialText, int style) {
+        super(formFactory, parentElement);
+
+        label = formFactory.createLabel(getLayoutComposite(), labelString, style);
+        addControl(label);
+
+        container = formFactory.createComposite(getLayoutComposite(), SWT.WRAP);
+        container.setLayout(LayoutConstants.LAYOUT(2, false));
+        container.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
+        addControl(container);
+
+        text_cache = formFactory.createText(container, initialText, SWT.WRAP | SWT.MULTI);
+        addControl(text_cache);
+        text_cache.setEnabled(false);
+        text_cache.setLayoutData(LayoutConstants.FILL());
+
+        btnRemoveElement = formFactory.createButton(container, "Edit", SWT.TOGGLE);
+        btnRemoveElement.setText("");
+        btnRemoveElement.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
+        addControl(btnRemoveElement);
+        btnRemoveElement.addSelectionListener(this);
+        if (initialText != null){
+            setState(true);
+        }else {
+            setState(false);
+        }
+
+    }
+
+
+    @Override
+    public void widgetSelected(SelectionEvent e) {
+       setText(null);
+       firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
+    }
+
+    @Override
+    public void widgetDefaultSelected(SelectionEvent e) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void setText(String text){
+        if (text == null){
+            this.text_cache.setText("");
+        }
+        if (StringUtils.isBlank(text)){
+            setState(false);
+        }else{
+            setState(true);
+        }
+    }
+
+
+    public boolean isState() {
+        return state;
+    }
+
+
+    public void setState(boolean state) {
+        this.state = state;
+    }
+
+}
index 4e7ed3be98cb6a0bc12c92263bc115a15ed99de2..976ca74bf73f127ef69759791da8602d49e0c99c 100644 (file)
@@ -27,6 +27,7 @@ import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
+import eu.etaxonomy.taxeditor.ui.element.RemovableTextElement;
 import eu.etaxonomy.taxeditor.ui.element.RepresentationElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitCollectionSection;
@@ -65,8 +66,12 @@ public class CharacterDetailElement extends AbstractCdmDetailElement<Character>
     private Label labelText_property;
     private Text text_property;
 
-    private Label labelText_ratioTo;
-    private Text text_ratioTo;
+    private RemovableTextElement ratioTo;
+//    private Label labelText_ratioTo;
+//    private Text text_ratioTo;
+//    private Button button_remove;
+
+
 //    private TextWithLabelElement text_structure;
 //    private TextWithLabelElement text_property;
 
@@ -109,19 +114,7 @@ public class CharacterDetailElement extends AbstractCdmDetailElement<Character>
 
         comboStructuralModifier = formFactory.createDefinedTermComboElement(TermType.StructureModifier, formElement, "Structural Modifier", entity.getStructureModifier(), style);
 
-        if (labelText_ratioTo != null){
-            labelText_ratioTo.dispose();
-        }
-        labelText_ratioTo =  new Label(formElement.getLayoutComposite(), SWT.NONE);
-        labelText_ratioTo.setText("Ratio to");
-        if (text_ratioTo != null){
-            text_ratioTo.dispose();
-        }
-        text_ratioTo = new Text(formElement.getLayoutComposite(), SWT.WRAP);
-        text_ratioTo.setEditable(false);
-        text_ratioTo.setText( CharacterNodeDetailElement.getRatioToText(entity));
-        text_ratioTo.setLayoutData(LayoutConstants.FILL());
-        text_ratioTo.setForeground(ColorResources.getColor(Resources.BLACK));
+        ratioTo = formFactory.createRemovableTextField(formElement, "Ratio to", CharacterNodeDetailElement.getRatioToText(entity), style);
 
            supportsQuantitativeData = formFactory.createCheckbox(formElement, "Supports Quantitative Data", entity.isSupportsQuantitativeData(), style);
            supportsCategoricalData = formFactory.createCheckbox(formElement, "Supports Categorical Data", entity.isSupportsCategoricalData(), style);
@@ -150,6 +143,7 @@ public class CharacterDetailElement extends AbstractCdmDetailElement<Character>
             sectionModifierVocabularies.setEntity(entity);
         }
 
+
     }
 //     public void createText(ICdmFormElement formElement, String label, String path) {
 //         labelText = new Label(formElement.getLayoutComposite(), SWT.NONE);
@@ -172,6 +166,12 @@ public class CharacterDetailElement extends AbstractCdmDetailElement<Character>
            if(eventSource == comboStructuralModifier){
                getEntity().setStructureModifier(comboStructuralModifier.getSelection());
            }
+           if(eventSource == ratioTo){
+               if (!ratioTo.isState()){
+                   getEntity().setRatioToStructure(null);
+               }
+        }
+
 //         if(eventSource == supportsQuantitativeData || eventSource == supportsCategoricalData){
 //             //if any type is selected disable supportsTextData
 //             getEntity().setSupportsTextData(false);
index 1280a621fabee71144764201310aedbe88618da0..64779e4555b7f3bb755659a9ae1abb5c551088b5 100755 (executable)
@@ -33,6 +33,7 @@ import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
+import eu.etaxonomy.taxeditor.ui.element.RemovableTextElement;
 import eu.etaxonomy.taxeditor.ui.element.RepresentationElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitCollectionSection;
@@ -75,8 +76,8 @@ public class CharacterDtoDetailElement extends AbstractCdmDetailElement<Characte
     private Label labelText_property;
     private Text text_property;
 
-    private Label labelText_ratioTo;
-    private Text text_ratioTo;
+    private RemovableTextElement ratioTo;
+
 //    private TextWithLabelElement text_structure;
 //    private TextWithLabelElement text_property;
 
@@ -120,21 +121,23 @@ public class CharacterDtoDetailElement extends AbstractCdmDetailElement<Characte
 
         comboStructuralModifier = formFactory.createDefinedTermComboElementDto(TermType.StructureModifier, formElement, "Structural Modifier", entity.getStructureModifier(), style);
 
-        if (labelText_ratioTo != null){
-            labelText_ratioTo.dispose();
-        }
-        labelText_ratioTo =  new Label(formElement.getLayoutComposite(), SWT.NONE);
-        labelText_ratioTo.setText("Ratio to");
-        if (text_ratioTo != null){
-            text_ratioTo.dispose();
-        }
-        text_ratioTo = new Text(formElement.getLayoutComposite(), SWT.WRAP);
-        text_ratioTo.setEditable(false);
-        if (entity.getRatioTo() != null){
-            text_ratioTo.setText(entity.getRatioTo().getPath());
-        }
-        text_ratioTo.setLayoutData(LayoutConstants.FILL());
-        text_ratioTo.setForeground(ColorResources.getColor(Resources.BLACK));
+//        if (labelText_ratioTo != null){
+//            labelText_ratioTo.dispose();
+//        }
+//        labelText_ratioTo =  new Label(formElement.getLayoutComposite(), SWT.NONE);
+//        labelText_ratioTo.setText("Ratio to");
+//        if (text_ratioTo != null){
+//            text_ratioTo.dispose();
+//        }
+//        text_ratioTo = new Text(formElement.getLayoutComposite(), SWT.WRAP);
+//        text_ratioTo.setEditable(false);
+//        if (entity.getRatioTo() != null){
+//            text_ratioTo.setText(entity.getRatioTo().getPath());
+//        }
+//        text_ratioTo.setLayoutData(LayoutConstants.FILL());
+//        text_ratioTo.setForeground(ColorResources.getColor(Resources.BLACK));
+
+        ratioTo = formFactory.createRemovableTextField(formElement, "Ratio to", entity.getRatioTo() != null? entity.getRatioTo().getPath():null, style);
 
            supportsQuantitativeData = formFactory.createCheckbox(formElement, "Supports Quantitative Data", ((FeatureDto) entity).isSupportsQuantitativeData(), style);
            supportsCategoricalData = formFactory.createCheckbox(formElement, "Supports Categorical Data", ((FeatureDto) entity).isSupportsCategoricalData(), style);
@@ -193,6 +196,12 @@ public class CharacterDtoDetailElement extends AbstractCdmDetailElement<Characte
            if(eventSource == comboStructuralModifier){
                getEntity().setStructureModifier(TermDto.fromTerm(comboStructuralModifier.getSelection()));
            }
+           if(eventSource == ratioTo){
+               if (!ratioTo.isState()){
+                   getEntity().setRatioTo(null);
+               }
+        }
+
 //         if(eventSource == supportsQuantitativeData || eventSource == supportsCategoricalData){
 //             //if any type is selected disable supportsTextData
 //             getEntity().setSupportsCategoricalData(supportsCategoricalData.getSelection());