- added collecting area section to general section DerivedUnit DetailsView (fixes...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / DerivedUnitGeneralDetailElement.java
index 45eec3ef23ff560ba8b206ee017c1c7cb4345b1d..1ac5b58dea93b3758db25b287f039bbc055e2c58 100644 (file)
@@ -10,6 +10,8 @@
 
 package eu.etaxonomy.taxeditor.ui.section.occurrence;
 
+import org.eclipse.ui.forms.widgets.ExpandableComposite;
+
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
 import eu.etaxonomy.cdm.model.agent.AgentBase;
 import eu.etaxonomy.cdm.model.common.LanguageString;
@@ -20,9 +22,11 @@ import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
 import eu.etaxonomy.taxeditor.ui.element.GatheringEventUnitElement;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement;
+import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
 import eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection;
 import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
 import eu.etaxonomy.taxeditor.ui.element.PointElement;
@@ -40,9 +44,12 @@ import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
 public class DerivedUnitGeneralDetailElement extends
                AbstractCdmDetailElement<DerivedUnitFacade> {
 
+    boolean showOnlyDerivedUnitData = false;
+
        private ToggleableTextElement toggleableText_titleCache;
        private EnumComboElement<SpecimenOrObservationType> combo_specorobstype;
        private EntitySelectionElement<NamedArea> selection_country;
+    private CollectingAreasDetailSection section_collectingAreas;
        private LanguageStringWithLabelElement languageText_locality;
        private PointElement element_point;
        private NumberWithLabelElement number_elevation;
@@ -52,7 +59,7 @@ public class DerivedUnitGeneralDetailElement extends
        private EntitySelectionElement<Collection> selection_collection;
        private TextWithLabelElement text_accessionNumber;
        private GatheringEventUnitElement element_elevation;
-
+       private CheckboxElement checkIsPublish;
 
 
        /**
@@ -61,7 +68,7 @@ public class DerivedUnitGeneralDetailElement extends
         */
        public DerivedUnitGeneralDetailElement(CdmFormFactory formFactory,
                        ICdmFormElement formElement) {
-               super(formFactory, formElement);
+           super(formFactory, formElement);
        }
 
        /*
@@ -77,32 +84,40 @@ public class DerivedUnitGeneralDetailElement extends
                toggleableText_titleCache = formFactory.createToggleableTextField(
                                formElement, "Title Cache", entity.getTitleCache(),
                                entity.isProtectedTitleCache(), style);
+        //TODO for DerivateEditor do not use facade anymore to avoid this special case handling #4539
+               if(showOnlyDerivedUnitData){
+                   toggleableText_titleCache.setEnabled(false);
+               }
+               else{
+                   combo_specorobstype = formFactory.createEnumComboElement(SpecimenOrObservationType.class, formElement, style);
+                   combo_specorobstype.setSelection(entity.getType());
+                   selection_country = formFactory.createSelectionElement(NamedArea.class, getConversationHolder(),
+                           formElement, "Country",
+                           entity.getCountry(), EntitySelectionElement.NOTHING, style);
 
-        if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.DETERMINATION_ONLY_FOR_FIELD_UNITS)){
-            combo_specorobstype = formFactory.createEnumComboElement(SpecimenOrObservationType.class, formElement,
-                    style);
-            combo_specorobstype.setSelection(entity.getType());
-        }
-               selection_country = formFactory.createSelectionElement(NamedArea.class, getConversationHolder(),
-                               formElement, "Country",
-                               entity.getCountry(), EntitySelectionElement.NOTHING, style);
-               languageText_locality = formFactory
-                               .createLanguageStringWithLabelElement(formElement, "Locality",
-                                               entity.getLocality(), style);
-               element_point = formFactory.createPointElement(formElement,
-                               entity.getExactLocation(), style);
-               element_elevation = formFactory.createGatheringEventUnitElement(
-                               formElement, "Elevation : ", entity, MinMaxTextSection.UnitType.ELEVATION,  style);
-
-               element_date = formFactory.createTimePeriodElement(formElement, "Date",
-                               entity.getGatheringPeriod(), style);
-               selection_collector = formFactory
-                               .createSelectionElement(AgentBase.class,
-                                               getConversationHolder(), formElement, "Collector",
-                                               entity.getCollector(), EntitySelectionElement.ALL,
-                                               style);
-               text_collectingNumber = formFactory.createTextWithLabelElement(formElement,
-                               "Collecting number", entity.getFieldNumber(), style);
+               if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION)){
+                   section_collectingAreas = formFactory.createCollectingAreasDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
+                   section_collectingAreas.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+                   section_collectingAreas.setEntity(entity);
+               }
+                   languageText_locality = formFactory
+                           .createLanguageStringWithLabelElement(formElement, "Locality",
+                                   entity.getLocality(), style);
+                   element_point = formFactory.createPointElement(formElement,
+                           entity.getExactLocation(), style);
+                   element_elevation = formFactory.createGatheringEventUnitElement(
+                           formElement, "Elevation : ", entity, MinMaxTextSection.UnitType.ELEVATION,  style);
+
+                   element_date = formFactory.createTimePeriodElement(formElement, "Date",
+                           entity.getGatheringPeriod(), style);
+                   selection_collector = formFactory
+                           .createSelectionElement(AgentBase.class,
+                                   getConversationHolder(), formElement, "Collector",
+                                   entity.getCollector(), EntitySelectionElement.ALL,
+                                   style);
+                   text_collectingNumber = formFactory.createTextWithLabelElement(formElement,
+                           "Collecting number", entity.getFieldNumber(), style);
+               }
                selection_collection = formFactory
                                .createSelectionElement(Collection.class,
                                                getConversationHolder(), formElement, "Collection",
@@ -111,6 +126,7 @@ public class DerivedUnitGeneralDetailElement extends
                text_accessionNumber = formFactory.createTextWithLabelElement(
                                formElement, "Accession Number", entity.getAccessionNumber(),
                                style);
+        checkIsPublish = formFactory.createCheckbox(formElement, "Publish", entity.isPublish(), style);
 
        }
 
@@ -148,6 +164,8 @@ public class DerivedUnitGeneralDetailElement extends
                        getEntity().setAccessionNumber(text_accessionNumber.getText());
                } else if (eventSource == combo_specorobstype) {
                        getEntity().setType(combo_specorobstype.getSelection());
+               } else if (eventSource == checkIsPublish) {
+                   getEntity().innerDerivedUnit().setPublish(checkIsPublish.getSelection());
                }
 
                if (eventSource != toggleableText_titleCache) {
@@ -155,4 +173,8 @@ public class DerivedUnitGeneralDetailElement extends
                }
        }
 
+    public void setShowOnlyDerivedUnitData(boolean showOnlyDerivedUnitData) {
+        this.showOnlyDerivedUnitData = showOnlyDerivedUnitData;
+    }
+
 }