remove structural modifier combo
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / feature / CharacterDetailElement.java
index 87e0af057f93b3e31b92e005313fcdec616400a0..3ac875a3c146ec6a116237eb6378d7760611fe76 100644 (file)
@@ -8,24 +8,24 @@
 */
 package eu.etaxonomy.taxeditor.ui.section.feature;
 
+import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
 
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.description.Character;
-import eu.etaxonomy.cdm.model.term.DefinedTerm;
-import eu.etaxonomy.cdm.model.term.FeatureNode;
 import eu.etaxonomy.cdm.model.term.Representation;
-import eu.etaxonomy.cdm.model.term.TermType;
 import eu.etaxonomy.taxeditor.editor.definedterm.TermBasePropertyTester;
 import eu.etaxonomy.taxeditor.model.ColorResources;
 import eu.etaxonomy.taxeditor.preference.Resources;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.StoreUtil;
-import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
 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.LabelElement;
 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;
@@ -34,23 +34,26 @@ import eu.etaxonomy.taxeditor.ui.section.vocabulary.StateVocabularyCollectionSec
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.StatisticalMeasureCollectionSection;
 
 /**
- *
  * @author pplitzner
  * @since Dec 21, 2017
- *
  */
 public class CharacterDetailElement extends AbstractCdmDetailElement<Character> {
 
     private ICdmFormElement parentFormElement;
 
-    protected RepresentationElement element_Representation;
+    private RepresentationElement element_Representation;
 
-    private TermComboElement<DefinedTerm> comboStructuralModifier;
+   // private TermComboElement<DefinedTerm> comboStructuralModifier;
 
     private CheckboxElement supportsQuantitativeData;
 
     private CheckboxElement supportsCategoricalData;
 
+    private CheckboxElement availableForTaxon;
+    private CheckboxElement availableForTaxonName;
+    private CheckboxElement availableForSpecimenOrObservation;
+
+
     private StateVocabularyCollectionSection sectionStateVocabularies;
 
     private MeasurementUnitCollectionSection sectionMeasurementUnits;
@@ -58,6 +61,21 @@ public class CharacterDetailElement extends AbstractCdmDetailElement<Character>
     private StatisticalMeasureCollectionSection sectionStatisticalMeasures;
 
     private RecommendedModifierVocabulariesCollectionSection sectionModifierVocabularies;
+    private Label labelText_structure;
+    private Text text_structure;
+
+    private Label labelText_property;
+    private Text text_property;
+
+    private RemovableTextElement ratioTo;
+//    private Label labelText_ratioTo;
+//    private Text text_ratioTo;
+//    private Button button_remove;
+
+
+//    private TextWithLabelElement text_structure;
+//    private TextWithLabelElement text_property;
+
 
        public CharacterDetailElement(CdmFormFactory formFactory,
                        ICdmFormElement formElement) {
@@ -67,57 +85,83 @@ public class CharacterDetailElement extends AbstractCdmDetailElement<Character>
        @Override
        protected void createControls(ICdmFormElement formElement, Character entity, int style) {
            this.parentFormElement = formElement;
-           element_Representation = formFactory.createTranslatableRepresentationElement(formElement,  getEntity().getPreferredRepresentation(CdmStore.getDefaultLanguage()),getEntity(), 100, style, true);
-           Label lblStructure = new Label(formElement.getLayoutComposite(), style);
-           lblStructure.setText("Structure");
-           Label lblStructureText = new Label(formElement.getLayoutComposite(), style);
-           lblStructureText.setText(getPath(entity.getStructure()));
-           lblStructureText.setForeground(ColorResources.getColor(Resources.BLACK));
-           Label lblProperty = new Label(formElement.getLayoutComposite(), style);
-           lblProperty.setText("Property");
-           Label lblPropertyText = new Label(formElement.getLayoutComposite(), style);
-           lblPropertyText.setForeground(ColorResources.getColor(Resources.BLACK));
-           lblPropertyText.setText(getPath(entity.getProperty()));
-
-        comboStructuralModifier = formFactory.createDefinedTermComboElement(TermType.StructureModifier, formElement, "Structural Modifier", entity.getStructureModifier(), style);
+           element_Representation = formFactory.createTranslatableRepresentationElement(formElement,  entity.getPreferredRepresentation(CdmStore.getDefaultLanguage()),entity, 100, style, true);
+           if (labelText_property != null){
+               labelText_structure.dispose();
+           }
+           labelText_structure = new Label(formElement.getLayoutComposite(), SWT.NONE);
+           labelText_structure.setText("Structure");
+           if (text_structure != null){
+               text_structure.dispose();
+           }
+           text_structure = new Text(formElement.getLayoutComposite(), SWT.WRAP);
+        text_structure.setText( CharacterNodeDetailElement.getStructureText(entity));
+        text_structure.setEditable(false);
+        text_structure.setLayoutData(LayoutConstants.FILL());
+        text_structure.setForeground(ColorResources.getColor(Resources.BLACK));
+        if (labelText_property != null){
+            labelText_property.dispose();
+        }
+        labelText_property =  new Label(formElement.getLayoutComposite(), SWT.NONE);
+           labelText_property.setText("Property");
+           if (text_property != null){
+               text_property.dispose();
+           }
+           text_property = new Text(formElement.getLayoutComposite(), SWT.WRAP);
+           text_property.setEditable(false);
+           text_property.setText( CharacterNodeDetailElement.getPropertyText(entity));
+           text_property.setLayoutData(LayoutConstants.FILL());
+           text_property.setForeground(ColorResources.getColor(Resources.BLACK));
+
+     //   comboStructuralModifier = formFactory.createDefinedTermComboElement(TermType.StructureModifier, formElement, "Structural Modifier", entity.getStructureModifier(), style);
+
+        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);
 
+           LabelElement availableLabel = formFactory.createLabel(formElement, "Available for");
+        availableLabel.setBold();
+
+        availableForTaxon = formFactory.createCheckbox(formElement, "Taxon", entity.isAvailableForTaxon(), style);
+        availableForTaxonName = formFactory.createCheckbox(formElement, "Taxon Name", entity.isAvailableForTaxonName(), style);
+        availableForSpecimenOrObservation = formFactory.createCheckbox(formElement, "Occurrence", entity.isAvailableForOccurrence(), style);
+
         if (supportsCategoricalData.getSelection()) {
-            sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(),
+            sectionStateVocabularies = formFactory.createStateVocabulariesSection(
                     parentFormElement, StoreUtil.getSectionStyle(StateVocabularyCollectionSection.class, entity.getClass().getCanonicalName(), true));
             sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
-            sectionStateVocabularies.setEntity(getEntity());
+            sectionStateVocabularies.setEntity(entity);
         }
         if (supportsQuantitativeData.getSelection()) {
-            sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(),
+            sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(
                     parentFormElement, StoreUtil.getSectionStyle(MeasurementUnitCollectionSection.class, entity.getClass().getCanonicalName(), true));
             sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
-            sectionMeasurementUnits.setEntity(getEntity());
+            sectionMeasurementUnits.setEntity(entity);
 
-            sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(getConversationHolder(),
+            sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(
                     parentFormElement, StoreUtil.getSectionStyle(StatisticalMeasureCollectionSection.class, entity.getClass().getCanonicalName(), true));
             sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
-            sectionStatisticalMeasures.setEntity(getEntity());
+            sectionStatisticalMeasures.setEntity(entity);
         }
         if (supportsCategoricalData.getSelection() || supportsQuantitativeData.getSelection()) {
             sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
-                    getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, entity.getClass().getCanonicalName(), true));
+                    parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, entity.getClass().getCanonicalName(), true));
             sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
-            sectionModifierVocabularies.setEntity(getEntity());
+            sectionModifierVocabularies.setEntity(entity);
         }
-    }
 
-       private String getPath(FeatureNode node){
-           String path = node.getTerm().getLabel();
-           FeatureNode parent = node.getParent();
-           while(parent != null && parent.getTerm()!=null){
-               path = parent.getTerm().getLabel() + "/" + path;
-               parent = parent.getParent();
-           }
-           return path;
-       }
+
+    }
+//     public void createText(ICdmFormElement formElement, String label, String path) {
+//         labelText = new Label(formElement.getLayoutComposite(), SWT.NONE);
+//        labelText.setText(label);
+//        Text text = new Text(formElement.getLayoutComposite(), SWT.WRAP);
+//        text.setText(path);
+//        text.setEditable(false);
+//        text.setLayoutData(LayoutConstants.FILL());
+//        text.setForeground(ColorResources.getColor(Resources.BLACK));
+//    }
 
     @Override
     public void setEntity(Character entity) {
@@ -127,13 +171,19 @@ public class CharacterDetailElement extends AbstractCdmDetailElement<Character>
 
        @Override
        public void handleEvent(Object eventSource) {
-           if(eventSource == comboStructuralModifier){
-               getEntity().setStructureModifier(comboStructuralModifier.getSelection());
-           }
-           if(eventSource == supportsQuantitativeData || eventSource == supportsCategoricalData){
-               //if any type is selected disable supportsTextData
-               getEntity().setSupportsTextData(false);
-           }
+//         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);
+//         }
            if(eventSource == supportsQuantitativeData){
                getEntity().setSupportsQuantitativeData(supportsQuantitativeData.getSelection());
                if(supportsQuantitativeData.getSelection()){
@@ -167,6 +217,19 @@ public class CharacterDetailElement extends AbstractCdmDetailElement<Character>
             }
             getEntity().setTitleCache(null);
         }
+           else if(eventSource == availableForSpecimenOrObservation){
+            getEntity().setAvailableForOccurrence(availableForSpecimenOrObservation.getSelection());
+
+        }
+           else if(eventSource == availableForTaxon){
+            getEntity().setAvailableForTaxon(availableForTaxon.getSelection());
+
+        }
+           else if(eventSource == availableForTaxonName){
+            getEntity().setAvailableForTaxonName(availableForTaxonName.getSelection());
+
+        }
+
        }
 
        private void activateQuantitativeWidgets(){
@@ -176,20 +239,20 @@ public class CharacterDetailElement extends AbstractCdmDetailElement<Character>
            removeCategoricalWidgets();
 
            //measurement units
-           sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(),
-                   parentFormElement, StoreUtil.getSectionStyle(MeasurementUnitCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
+           sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(parentFormElement,
+                   StoreUtil.getSectionStyle(MeasurementUnitCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
            sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
            sectionMeasurementUnits.setEntity(getEntity());
 
            //statistical measures
            sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(
-                   getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(StatisticalMeasureCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
+                   parentFormElement, StoreUtil.getSectionStyle(StatisticalMeasureCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
            sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
            sectionStatisticalMeasures.setEntity(getEntity());
 
            //modifiers
            sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
-                   getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
+                   parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
            sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
            sectionModifierVocabularies.setEntity(getEntity());
        }
@@ -209,14 +272,14 @@ public class CharacterDetailElement extends AbstractCdmDetailElement<Character>
            removeQuantitativeWidgets();
 
            //states
-           sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(),
+           sectionStateVocabularies = formFactory.createStateVocabulariesSection(
                 parentFormElement, StoreUtil.getSectionStyle(StateVocabularyCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
         sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
         sectionStateVocabularies.setEntity(getEntity());
 
         //modifiers
         sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
-                getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
+                parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
         sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
         sectionModifierVocabularies.setEntity(getEntity());
        }
@@ -228,4 +291,26 @@ public class CharacterDetailElement extends AbstractCdmDetailElement<Character>
            }
        }
 
+       @Override
+       public void fillFields() {
+               if (getEntity()!= null) {
+                       element_Representation.setTerm(getEntity(), isEnabled());
+//                     comboStructuralModifier.setSelection(getEntity().getStructureModifier());
+                       supportsQuantitativeData.setSelection(getEntity().isSupportsQuantitativeData());
+                       supportsCategoricalData.setSelection(getEntity().isSupportsCategoricalData());;
+                       availableForTaxon.setSelection(getEntity().isAvailableForTaxon());
+                       availableForTaxonName.setSelection(getEntity().isAvailableForTaxonName());
+                       availableForSpecimenOrObservation.setSelection(getEntity().isAvailableForOccurrence());
+                       sectionStateVocabularies.setEntity(getEntity());
+                       sectionMeasurementUnits.setEntity(getEntity());
+                       sectionStatisticalMeasures.setEntity(getEntity());
+                       sectionModifierVocabularies.setEntity(getEntity());
+
+                       text_structure.setText(CharacterNodeDetailElement.getStructureText(getEntity()));
+                       text_property.setText(CharacterNodeDtoDetailElement.getPropertyText(getEntity()));
+                       ratioTo.setText(CharacterNodeDetailElement.getRatioToText(getEntity()));
+               }
+
+       }
+
 }