CdmFormFactory : added createmethods for GatheringEventUnitElement, MinMaxTextSection...
authorCherian Mathew <c.mathew@bgbm.org>
Tue, 23 Jul 2013 15:24:34 +0000 (15:24 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Tue, 23 Jul 2013 15:24:34 +0000 (15:24 +0000)
MinMaxTextSection : new section for the min / max / text values of elevation / distance to ground / distance to water surface of the gathering event part of the DerivedUnitFacade
GatheringEventUnitElement : new element for elevation / distance to ground / distance to water surface units

.gitattributes
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/GatheringEventUnitElement.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/MinMaxTextSection.java [new file with mode: 0644]

index 89892641c92eaf08453798e57b6c2bc52c6eb65d..b9d3beb9605feffa5ba3d0ef70f285567c8ecfc5 100644 (file)
@@ -1272,6 +1272,7 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/Cdm
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmPropertyChangeEvent.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CheckboxElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/DateDetailSection.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/GatheringEventUnitElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/ICdmFormElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/IEnableableFormElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/IEntityElement.java -text
@@ -1288,6 +1289,7 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/Key
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/LabelElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/LanguageStringWithLabelElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/LayoutConstants.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/MinMaxTextSection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/MultilanguageTextElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/NumberWithLabelElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/PartialElement.java -text
index 8632612ec4065f146e3140b754650143e7f651fe..125151046b99aa1002f441aeea26d802aaba5ab4 100644 (file)
@@ -40,6 +40,7 @@ import org.joda.time.Partial;
 import org.springframework.security.core.GrantedAuthority;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.agent.Person;
 import eu.etaxonomy.cdm.model.agent.Team;
@@ -89,6 +90,7 @@ import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
 import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
+import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
@@ -96,6 +98,7 @@ import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
 import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
+import eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection.UnitType;
 import eu.etaxonomy.taxeditor.ui.openurl.IOpenUrlEnabled;
 import eu.etaxonomy.taxeditor.ui.openurl.OpenUrlSelectorElement;
 import eu.etaxonomy.taxeditor.ui.password.EditPasswordElement;
@@ -795,6 +798,41 @@ public class CdmFormFactory extends FormToolkit {
                parentElement.addElement(element);
                return element;
        }
+       
+       /**
+        * <p>
+        * createTermComboElement
+        * </p>
+        * 
+        * @param termComboType
+        *            a
+        *            {@link eu.eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.TermComboType}
+        *            object.
+        * @param parentElement
+        *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
+        *            object.
+        * @param labelString
+        *            a {@link java.lang.String} object.
+        * @param selection
+        *            a {@link eu.etaxonomy.cdm.model.common.DefinedTermBase}
+        *            object.
+        * @param style
+        *            a int.
+        * @return a {@link eu.etaxonomy.taxeditor.ui.combo.TermComboElement}
+        *         object.
+        */
+       
+       public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
+                       TermType termType, 
+                       ICdmFormElement parentElement,
+                       String labelString, 
+                       T selection, 
+                       int style) {
+               TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termType, labelString, selection, style);
+               adapt(element);
+               parentElement.addElement(element);
+               return element;
+       }
 
        /**
         * <p>
@@ -1051,6 +1089,40 @@ public class CdmFormFactory extends FormToolkit {
                parentElement.addElement(element);
                return element;
        }
+       
+       /**
+        * <p>
+        * createGatheringEventUnitElement
+        * </p>
+        * 
+        * @param parentElement
+        *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
+        *            object.
+        * @param labelString
+        *            a {@link java.lang.String} object.
+        * @param timePeriod
+        *            a {@link eu.etaxonomy.cdm.model.common.GatheringEvent} object.
+        * @param style
+        *            a int.
+        * @return a {@link eu.etaxonomy.taxeditor.ui.element.GatheringEventUnitElement}
+        *         object.
+        */
+       public GatheringEventUnitElement createGatheringEventUnitElement(
+                       ICdmFormElement parentElement, 
+                       String labelString,
+                       DerivedUnitFacade gatheringEvent, 
+                       MinMaxTextSection.UnitType unitType,                    
+                       int style) {
+               GatheringEventUnitElement element = new GatheringEventUnitElement(this, 
+                               parentElement,
+                               labelString, 
+                               gatheringEvent, 
+                               unitType,
+                               style);
+               adapt(element);
+               parentElement.addElement(element);
+               return element;
+       }
 
        /**
         * <p>
@@ -1096,6 +1168,26 @@ public class CdmFormFactory extends FormToolkit {
                adapt(section);
                return section;
        }
+       
+       /**
+        * <p>
+        * createDateDetailSection
+        * </p>
+        * 
+        * @param parentElement
+        *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
+        *            object.
+        * @param style
+        *            a int.
+        * @return a {@link eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection}
+        *         object.
+        */
+       public MinMaxTextSection createMinMaxTextSection(ICdmFormElement parentElement, UnitType unitType, int style) {
+               MinMaxTextSection section = new MinMaxTextSection(this, parentElement, unitType, style);
+               parentElement.addElement(section);
+               adapt(section);
+               return section;
+       }
 
        /**
         * <p>
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/GatheringEventUnitElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/GatheringEventUnitElement.java
new file mode 100644 (file)
index 0000000..b144231
--- /dev/null
@@ -0,0 +1,112 @@
+// $Id$
+/**
+ * Copyright (C) 2007 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.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.forms.widgets.Section;
+
+import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
+import eu.etaxonomy.cdm.model.common.TimePeriod;
+import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
+
+/**
+ * <p>
+ * GatheringEventUnitElement class.
+ * </p>
+ * 
+ * @author c.mathew
+ * @created 23 Jul. 2013
+ * @version 1.0
+ */
+public class GatheringEventUnitElement extends AbstractCdmFormElement implements ISelectable {
+       
+       private final Label label;
+       private final MinMaxTextSection section_minMaxText;
+
+       /**
+        * <p>
+        * Constructor for TimePeriodElement.
+        * </p>
+        * 
+        * @param style
+        *            a int.
+        * @param formFactory
+        *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
+        *            object.
+        * @param parentElement
+        *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
+        *            object.
+        * @param labelString
+        *            a {@link java.lang.String} object.
+        * @param timePeriod
+        *            a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
+        */
+       public GatheringEventUnitElement(CdmFormFactory formFactory,
+                       ICdmFormElement parentElement, 
+                       String labelString,
+                       DerivedUnitFacade gatheringEvent, 
+                       MinMaxTextSection.UnitType unitType,
+                       final int style) {
+               super(formFactory, parentElement);
+
+               label = formFactory.createLabel(getLayoutComposite(), labelString);
+               addControl(label);
+
+               section_minMaxText = formFactory.createMinMaxTextSection(this,
+                               unitType,
+                               Section.TWISTIE);
+               
+               addControl(section_minMaxText); 
+
+               section_minMaxText.setEntity(gatheringEvent);
+               
+               formFactory.addPropertyChangeListener(this);
+       }
+
+
+       /** {@inheritDoc} */
+       @Override
+       public void propertyChange(PropertyChangeEvent event) {
+               if (event == null) {
+                       return;
+               }
+               Object eventSource = event.getSource();
+
+               if (getElements().contains(eventSource)) {
+                       handleEvent(eventSource);
+               }
+       }
+
+       private void handleEvent(Object eventSource) {
+               if (eventSource == section_minMaxText) {                        
+                       firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
+               }
+       }
+
+       /** {@inheritDoc} */
+       @Override
+       public void setBackground(Color color) {
+               label.setBackground(color);
+               section_minMaxText.setBackground(color);
+       }
+       
+       @Override
+       public void setSelected(boolean selected) {
+               setBackground(selected ? SELECTED : getPersistentBackground());
+       }
+
+       public void setLabel(String string) {
+               label.setText(string);
+       }
+}
+
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/MinMaxTextSection.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/MinMaxTextSection.java
new file mode 100644 (file)
index 0000000..6fb22d5
--- /dev/null
@@ -0,0 +1,274 @@
+// $Id$
+/**
+ * Copyright (C) 2007 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.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.layout.RowLayout;
+
+import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
+import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.model.common.TimePeriod;
+import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
+
+/**
+ * <p>
+ * MinMaxTextSection class.
+ * </p>
+ * 
+ * @author c.mathew
+ * @created 23 Jul 2013
+ * @version 1.0
+ */
+public class MinMaxTextSection extends AbstractFormSection<DerivedUnitFacade> {
+
+       private final TextWithLabelElement text_freeText;
+       private final NumberWithLabelElement text_minVal;
+       private final NumberWithLabelElement text_maxVal;
+       private int cursorPosition;
+       
+       // unit types handled by this section
+       public enum UnitType {
+               ELEVATION,
+               DIST_TO_GROUND,
+               DIST_TO_WATER
+       }
+
+       private UnitType unitType = UnitType.ELEVATION;
+
+       /**
+        * <p>
+        * Constructor for DateDetailSection.
+        * </p>
+        * 
+        * @param formFactory
+        *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
+        *            object.
+        * @param parentElement
+        *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
+        *            object.
+        * @param style
+        *            a int.
+        */
+       protected MinMaxTextSection(CdmFormFactory formFactory,
+                       ICdmFormElement parentElement, UnitType unitType, int style) {
+               super(formFactory, parentElement, style);
+               this.unitType = unitType;
+               getLayoutComposite().setLayout(LayoutConstants.LAYOUT(2, false));
+
+               text_minVal = formFactory.createNumberTextWithLabelElement(this,
+                               "Min : ", getMinimum(), style);
+               
+               text_maxVal = formFactory.createNumberTextWithLabelElement(this,
+                               "Max : ", getMaximum(), style);
+       
+               text_freeText = formFactory.createTextWithLabelElement(this,
+                               "Freetext : ", getFreetext(), style);
+
+               formFactory.addPropertyChangeListener(this);
+       }
+
+       /**
+        * <p>
+        * Setter for the field <code>timePeriod</code>.
+        * </p>
+        * 
+        * @param timePeriod
+        *            a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
+        */
+       @Override
+       public void setEntity(DerivedUnitFacade gatheringEvent) {
+               super.setEntity(gatheringEvent);
+               updateValues();
+       }
+
+       private void updateValues() {
+               if(getEntity() != null) {
+                       switch(unitType) {
+                       case ELEVATION:
+                               if(getEntity().getAbsoluteElevation() != null) {
+                                       text_minVal.setNumber(getEntity().getAbsoluteElevation());
+                               }
+                               if(getEntity().getAbsoluteElevationMaximum() != null) {
+                                       text_maxVal.setNumber(getEntity().getAbsoluteElevation());
+                               }
+                               if(getEntity().getAbsoluteElevationText() != null) {
+                                       text_freeText.setText(getEntity().getAbsoluteElevationText());
+                               }
+                               break;
+                       case DIST_TO_GROUND:
+                               if(getEntity().getDistanceToGround() != null) {
+                                       text_minVal.setNumber(getEntity().getDistanceToGround());
+                               }
+                               if(getEntity().getDistanceToGroundMax() != null) {
+                                       text_maxVal.setNumber(getEntity().getDistanceToGroundMax());
+                               }
+                               if(getEntity().getDistanceToGroundText() != null) {
+                                       text_freeText.setText(getEntity().getDistanceToGroundText());
+                               }
+                               break;                  
+                       case DIST_TO_WATER:
+                               if(getEntity().getDistanceToWaterSurface() != null) {
+                                       text_minVal.setNumber(getEntity().getDistanceToWaterSurface());
+                               }
+                               if(getEntity().getDistanceToWaterSurfaceMax() != null) {
+                                       text_maxVal.setNumber(getEntity().getDistanceToWaterSurfaceMax());
+                               }
+                               if(getEntity().getDistanceToWaterSurfaceText() != null) {
+                                       text_freeText.setText(getEntity().getDistanceToWaterSurfaceText());
+                               }
+                               break;          
+                       default:
+                               break;
+                       }
+
+               }
+       }
+       /** {@inheritDoc} */
+       @Override
+       public void propertyChange(PropertyChangeEvent event) {
+               if (event == null) {
+                       return;
+               }
+               Object eventSource = event.getSource();
+
+               if (getElements().contains(eventSource)) {
+                       if (event instanceof CdmPropertyChangeEvent) {
+                               if (((CdmPropertyChangeEvent) event).hasException()) {
+                                       handleException((CdmPropertyChangeEvent) event);
+                                       return;
+                               }
+                       }
+                       handleEvent(eventSource);
+               }
+       }
+
+       /**
+        * @param event
+        */
+       private void handleException(CdmPropertyChangeEvent event) {
+               firePropertyChangeEvent(new CdmPropertyChangeEvent(this,
+                               event.getException()));
+       }
+
+       private void handleEvent(Object eventSource) {
+               if (eventSource == text_minVal) {                       
+                       updateMinimum();
+               } else if (eventSource == text_maxVal) {
+                       updateMaximum();
+               } else if (eventSource == text_freeText) {
+                       updateFreetext();               
+               } 
+               firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
+       }
+
+
+       
+       /*
+        * (non-Javadoc)
+        * 
+        * @see eu.etaxonomy.taxeditor.forms.AbstractFormSection#dispose()
+        */
+       /** {@inheritDoc} */
+       @Override
+       public void dispose() {
+               formFactory.removePropertyChangeListener(this);
+               super.dispose();
+       }
+       
+       private void updateMinimum() {
+               switch(unitType) {
+               case ELEVATION:
+                       getEntity().setAbsoluteElevation(text_minVal.getInteger());
+                       break;
+               case DIST_TO_GROUND:
+                       getEntity().setDistanceToGround(text_minVal.getDouble());
+                       break;                  
+               case DIST_TO_WATER:
+                       getEntity().setDistanceToWaterSurface(text_minVal.getDouble());
+                       break;                          
+               }
+       }
+       
+       private Number getMinimum() {
+               if(getEntity() == null) {
+                       return null;
+               }
+               switch(unitType) {
+               case ELEVATION:
+                       return getEntity().getAbsoluteElevation();                      
+               case DIST_TO_GROUND:
+                       return getEntity().getDistanceToGround();                       
+               case DIST_TO_WATER:
+                       return getEntity().getDistanceToWaterSurface();                                 
+               }
+               return null;
+       }
+       
+       private void updateMaximum() {
+               switch(unitType) {
+               case ELEVATION:
+                       getEntity().setAbsoluteElevationMax(text_maxVal.getInteger());
+                       break;
+               case DIST_TO_GROUND:
+                       getEntity().setDistanceToGroundMax(text_maxVal.getDouble());
+                       break;                  
+               case DIST_TO_WATER:
+                       getEntity().setDistanceToWaterSurfaceMax(text_maxVal.getDouble());
+                       break;                          
+               }
+       }
+       
+       private Number getMaximum() {
+               if(getEntity() == null) {
+                       return null;
+               }
+               switch(unitType) {
+               case ELEVATION:
+                       return getEntity().getAbsoluteElevationMaximum();                       
+               case DIST_TO_GROUND:
+                       return getEntity().getDistanceToGroundMax();                    
+               case DIST_TO_WATER:
+                       return getEntity().getDistanceToWaterSurfaceMax();                                      
+               }
+               return null;
+       }
+       
+       private void updateFreetext() {
+               switch(unitType) {
+               case ELEVATION:
+                       getEntity().setAbsoluteElevationText(text_freeText.getText());
+                       break;
+               case DIST_TO_GROUND:
+                       getEntity().setDistanceToGroundText(text_freeText.getText());
+                       break;                  
+               case DIST_TO_WATER:
+                       getEntity().setDistanceToWaterSurfaceText(text_freeText.getText());
+                       break;                          
+               }
+       }       
+       
+       private String getFreetext() {
+               if(getEntity() == null) {
+                       return null;
+               }
+               switch(unitType) {
+               case ELEVATION:
+                       return getEntity().getAbsoluteElevationText();                  
+               case DIST_TO_GROUND:
+                       return getEntity().getDistanceToGroundText();                   
+               case DIST_TO_WATER:
+                       return getEntity().getDistanceToWaterSurfaceText();                                     
+               }
+               return null;
+       }
+
+}
+