ref #10365: termTrees should be usable in term selection wizards
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / feature / CharacterDtoDetailElement.java
index 4623257c6136ec4f385b39df59efefad901d1c01..9f079bdedf940d0b834541e872ceff7f6bea56b4 100644 (file)
@@ -75,84 +75,92 @@ public class CharacterDtoDetailElement extends AbstractCdmDetailElement<Characte
 
     private RemovableTextElement ratioTo;
 
+    public CharacterDtoDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
+        super(formFactory, formElement);
+    }
+
+    @Override
+    protected void createControls(ICdmFormElement formElement, CharacterDto entity, int style) {
+        this.parentFormElement = formElement;
 
-       public CharacterDtoDetailElement(CdmFormFactory formFactory,
-                       ICdmFormElement formElement) {
-               super(formFactory, formElement);
-       }
-
-       @Override
-       protected void createControls(ICdmFormElement formElement, CharacterDto entity, int style) {
-           this.parentFormElement = formElement;
-
-           element_Representation = formFactory.createTranslatableRepresentationElementDto(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( entity.getStructure().getPath());
+        element_Representation = formFactory.createTranslatableRepresentationElementDto(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(entity.getStructure().getPath());
         text_structure.setEditable(false);
         text_structure.setLayoutData(LayoutConstants.FILL());
         text_structure.setForeground(ColorResources.getColor(Resources.BLACK));
-        if (labelText_property != null){
+        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(entity.getProperty().getPath());
-           text_property.setLayoutData(LayoutConstants.FILL());
-           text_property.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);
-           LabelElement availableLabel = formFactory.createLabel(formElement, "Available for");
+        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(entity.getProperty().getPath());
+        text_property.setLayoutData(LayoutConstants.FILL());
+        text_property.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);
+        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);
+        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.createStateVocabulariesDtoSection(parentFormElement,
-                    StoreUtil.getSectionStyle(RecommendedStateCollectionSection.class, entity.getClass().getCanonicalName(), true));
+                    StoreUtil.getSectionStyle(RecommendedStateCollectionSection.class,
+                            entity.getClass().getCanonicalName(), true));
             sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
             sectionStateVocabularies.setEntity((entity));
         }
         if (supportsQuantitativeData.getSelection()) {
             sectionMeasurementUnits = formFactory.createMeasurementUnitDtoCollectionSection(parentFormElement,
-                    StoreUtil.getSectionStyle(MeasurementUnitCollectionSection.class, entity.getClass().getCanonicalName(), true));
+                    StoreUtil.getSectionStyle(MeasurementUnitCollectionSection.class,
+                            entity.getClass().getCanonicalName(), true));
             sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
             sectionMeasurementUnits.setEntity((entity));
 
-            sectionStatisticalMeasures = formFactory.createStatisticalMeasureDtoCollectionSection(
-                    parentFormElement, StoreUtil.getSectionStyle(StatisticalMeasureCollectionSection.class, entity.getClass().getCanonicalName(), true));
+            sectionStatisticalMeasures = formFactory.createStatisticalMeasureDtoCollectionSection(parentFormElement,
+                    StoreUtil.getSectionStyle(StatisticalMeasureCollectionSection.class,
+                            entity.getClass().getCanonicalName(), true));
             sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
             sectionStatisticalMeasures.setEntity((entity));
         }
         if (supportsCategoricalData.getSelection() || supportsQuantitativeData.getSelection()) {
             sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesDtoCollectionSection(
-                    parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierCollectionsCollectionSection.class, entity.getClass().getCanonicalName(), true));
+                    parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierCollectionsCollectionSection.class,
+                            entity.getClass().getCanonicalName(), true));
             sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
             sectionModifierVocabularies.setEntity((entity));
         }
 
     }
 
-       public String getPropertyText() {
-        return getEntity().getProperty()!=null?getEntity().getProperty().getPath():"[no property]";
+    public String getPropertyText() {
+        return getEntity().getProperty() != null ? getEntity().getProperty().getPath() : "[no property]";
     }
 
     public String getStructureText(Character entity) {
-        return entity.getStructure()!=null?entity.getStructure().getPath():"[no structure]";
+        return entity.getStructure() != null ? entity.getStructure().getPath() : "[no structure]";
     }
 
     @Override
@@ -161,143 +169,142 @@ public class CharacterDtoDetailElement extends AbstractCdmDetailElement<Characte
         setEnabled(TermBasePropertyTester.isModifiable(entity));
     }
 
-       @Override
-       public void handleEvent(Object eventSource) {
-           if(eventSource == ratioTo){
-               if (!ratioTo.isState()){
-                   getEntity().setRatioTo(null);
-               }
+    @Override
+    public void handleEvent(Object eventSource) {
+        if (eventSource == ratioTo) {
+            if (!ratioTo.isState()) {
+                getEntity().setRatioTo(null);
+                element_Representation.setTermDto(getEntity(), enabled);
+            }
         }
 
-           if(eventSource == supportsQuantitativeData){
-               getEntity().setSupportsQuantitativeData(supportsQuantitativeData.getSelection());
-               getEntity().setSupportsCategoricalData(supportsCategoricalData.getSelection());
-               if(supportsQuantitativeData.getSelection()){
-                   activateQuantitativeWidgets();
-               }
-               else{
-                   removeQuantitativeWidgets();
-               }
+        if (eventSource == supportsQuantitativeData) {
+            getEntity().setSupportsQuantitativeData(supportsQuantitativeData.getSelection());
+            getEntity().setSupportsCategoricalData(supportsCategoricalData.getSelection());
+            if (supportsQuantitativeData.getSelection()) {
+                activateQuantitativeWidgets();
+            } else {
+                removeQuantitativeWidgets();
+            }
             StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
-           }
-           else if(eventSource == supportsCategoricalData){
-               getEntity().setSupportsCategoricalData(supportsCategoricalData.getSelection());
-               getEntity().setSupportsQuantitativeData(supportsQuantitativeData.getSelection());
+        } else if (eventSource == supportsCategoricalData) {
+            getEntity().setSupportsCategoricalData(supportsCategoricalData.getSelection());
+            getEntity().setSupportsQuantitativeData(supportsQuantitativeData.getSelection());
             if (supportsCategoricalData.getSelection()) {
                 activateCategoricalWidgets();
+            } else {
+                removeCategoricalWidgets();
             }
-               else{
-                   removeCategoricalWidgets();
-               }
             StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
-           }
-           else if (eventSource == element_Representation) {
+        } else if (eventSource == element_Representation) {
             Representation selectedRepresentation = element_Representation.getSelectedRepresentation();
-            if(selectedRepresentation!=null){
+            if (selectedRepresentation != null) {
                 Language representationLanguage = selectedRepresentation.getLanguage();
-                if(representationLanguage==null){
+                if (representationLanguage == null) {
                     representationLanguage = Language.getDefaultLanguage();
                 }
             }
-        }
-           else if(eventSource == availableForSpecimenOrObservation){
+        } else if (eventSource == availableForSpecimenOrObservation) {
             getEntity().setAvailableForOccurrence(availableForSpecimenOrObservation.getSelection());
 
-        }
-           else if(eventSource == availableForTaxon){
+        } else if (eventSource == availableForTaxon) {
             getEntity().setAvailableForTaxon(availableForTaxon.getSelection());
 
-        }
-           else if(eventSource == availableForTaxonName){
+        } else if (eventSource == availableForTaxonName) {
             getEntity().setAvailableForTaxonName(availableForTaxonName.getSelection());
 
         }
-       }
-
-       private void activateQuantitativeWidgets(){
-           //disable categorical widgets
-           supportsCategoricalData.setSelection(false);
-           getEntity().setSupportsCategoricalData(false);
-           removeCategoricalWidgets();
-
-           //measurement units
-           sectionMeasurementUnits = formFactory.createMeasurementUnitDtoCollectionSection(parentFormElement,
-                   StoreUtil.getSectionStyle(MeasurementUnitCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
-           sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
-           sectionMeasurementUnits.setEntity((getEntity()));
-
-           //statistical measures
-           sectionStatisticalMeasures = formFactory.createStatisticalMeasureDtoCollectionSection(
-                   parentFormElement, StoreUtil.getSectionStyle(StatisticalMeasureCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
-           sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
-           sectionStatisticalMeasures.setEntity((getEntity()));
-
-           //modifiers
-           sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesDtoCollectionSection(
-                   parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierCollectionsCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
-           sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
-           sectionModifierVocabularies.setEntity((getEntity()));
-       }
-
-       private void removeQuantitativeWidgets(){
-           if(sectionMeasurementUnits!=null){
-               removeElementsAndControls(sectionMeasurementUnits);
-               removeElementsAndControls(sectionStatisticalMeasures);
-               removeElementsAndControls(sectionModifierVocabularies);
-           }
-       }
-
-       private void activateCategoricalWidgets(){
-           //disable quantitative widgeets
-           supportsQuantitativeData.setSelection(false);
-           getEntity().setSupportsQuantitativeData(false);
-           removeQuantitativeWidgets();
-
-           //states
-           sectionStateVocabularies = formFactory.createStateVocabulariesDtoSection(parentFormElement,
-                   StoreUtil.getSectionStyle(RecommendedStateCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
+    }
+
+    private void activateQuantitativeWidgets() {
+        // disable categorical widgets
+        supportsCategoricalData.setSelection(false);
+        getEntity().setSupportsCategoricalData(false);
+        removeCategoricalWidgets();
+
+        // measurement units
+        sectionMeasurementUnits = formFactory.createMeasurementUnitDtoCollectionSection(parentFormElement,
+                StoreUtil.getSectionStyle(MeasurementUnitCollectionSection.class,
+                        getEntity().getClass().getCanonicalName(), true));
+        sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+        sectionMeasurementUnits.setEntity((getEntity()));
+
+        // statistical measures
+        sectionStatisticalMeasures = formFactory.createStatisticalMeasureDtoCollectionSection(parentFormElement,
+                StoreUtil.getSectionStyle(StatisticalMeasureCollectionSection.class,
+                        getEntity().getClass().getCanonicalName(), true));
+        sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+        sectionStatisticalMeasures.setEntity((getEntity()));
+
+        // modifiers
+        sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesDtoCollectionSection(
+                parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierCollectionsCollectionSection.class,
+                        getEntity().getClass().getCanonicalName(), true));
+        sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+        sectionModifierVocabularies.setEntity((getEntity()));
+    }
+
+    private void removeQuantitativeWidgets() {
+        if (sectionMeasurementUnits != null) {
+            removeElementsAndControls(sectionMeasurementUnits);
+            removeElementsAndControls(sectionStatisticalMeasures);
+            removeElementsAndControls(sectionModifierVocabularies);
+        }
+    }
+
+    private void activateCategoricalWidgets() {
+        // disable quantitative widgeets
+        supportsQuantitativeData.setSelection(false);
+        getEntity().setSupportsQuantitativeData(false);
+        removeQuantitativeWidgets();
+
+        // states
+        sectionStateVocabularies = formFactory.createStateVocabulariesDtoSection(parentFormElement,
+                StoreUtil.getSectionStyle(RecommendedStateCollectionSection.class,
+                        getEntity().getClass().getCanonicalName(), true));
         sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
         sectionStateVocabularies.setEntity((getEntity()));
 
-        //modifiers
+        // modifiers
         sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesDtoCollectionSection(
-                parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierCollectionsCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
+                parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierCollectionsCollectionSection.class,
+                        getEntity().getClass().getCanonicalName(), true));
         sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
         sectionModifierVocabularies.setEntity((getEntity()));
-       }
+    }
 
-       private void removeCategoricalWidgets(){
-           if(sectionStateVocabularies!=null){
-               removeElementsAndControls(sectionStateVocabularies);
-               removeElementsAndControls(sectionModifierVocabularies);
-           }
-       }
+    private void removeCategoricalWidgets() {
+        if (sectionStateVocabularies != null) {
+            removeElementsAndControls(sectionStateVocabularies);
+            removeElementsAndControls(sectionModifierVocabularies);
+        }
+    }
 
-       @Override
+    @Override
     public void propertyChange(PropertyChangeEvent event) {
-           EventUtility.postEvent(WorkbenchEventConstants.ADD_SAVE_CANDIDATE, getEntity().getUuid());
-           super.propertyChange(event);
-
-       }
-
-       @Override
-       public void fillFields() {
-               if (getEntity() != null) {
-                       element_Representation.setTermDto(getEntity(), true);
-                       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(getEntity().getStructure().getPath());
-                       text_property.setText(getEntity().getProperty().getPath());
-                       ratioTo.setText(getEntity().getRatioTo() != null? getEntity().getRatioTo().getPath():null);
-               }
-
-       }
+        EventUtility.postEvent(WorkbenchEventConstants.ADD_SAVE_CANDIDATE, getEntity().getUuid());
+        super.propertyChange(event);
+
+    }
+
+    @Override
+    public void fillFields() {
+        if (getEntity() != null) {
+            element_Representation.setTermDto(getEntity(), true);
+            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(getEntity().getStructure().getPath());
+            text_property.setText(getEntity().getProperty().getPath());
+            ratioTo.setText(getEntity().getRatioTo() != null ? getEntity().getRatioTo().getPath() : null);
+        }
+
+    }
 
 }