- removed empty element from combo dropdown #4448
authorPatric Plitzner <p.plitzner@bgbm.org>
Tue, 26 May 2015 15:07:14 +0000 (15:07 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Tue, 26 May 2015 15:07:14 +0000 (15:07 +0000)
.gitattributes
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermComboElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/VocabularyComboElement.java
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/section/vocabulary/MeasurementUnitCollectionElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/RecommendedModifierVocabulariesElement.java [moved from eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/StateModifierElement.java with 73% similarity]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/StateVocabularyCollectionElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/StatisticalMeasureCollectionElement.java

index 3167e48d30034e0b08302c76f1e4a08704a670b4..c04da5788a5976610f666f917a7bdd30b31dafb8 100644 (file)
@@ -1580,7 +1580,6 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/des
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/ScopeSection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/StateDataElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/StateDataSection.java -text
-eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/StateModifierElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/StatisticalMeasurementValueElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/StatisticalMeasurementValueSection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/detail/AbstractDetailedDescriptionDetailElement.java -text
@@ -1773,6 +1772,7 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/voc
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/NamedAreaDetailSection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/NamedAreaLevelDetailSection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/RecommendedModifierVocabulariesCollectionSection.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/RecommendedModifierVocabulariesElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/StateVocabularyCollectionElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/StateVocabularyCollectionSection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/StatisticalMeasureCollectionElement.java -text
index 14336ea794cc628fa30c21ba6b1b4caf1fbf268c..6f80b90d835853f1e4a67ae7f2ed89467667c51f 100644 (file)
@@ -155,8 +155,6 @@ public class TermComboElement<T extends DefinedTermBase>
        public void setSelection(T selection) {
                this.selection = selection;
 
-               this.selection = selection;
-
                Listener[] listeners = combo.getListeners(SWT.Selection);
 
                for (Listener listener : listeners) {
@@ -429,4 +427,10 @@ public class TermComboElement<T extends DefinedTermBase>
                populateTerms(customPreferredTerms);
        }
 
+       public void removeEmptyElement(){
+           if(addEmptyElement){
+               terms.remove(emptyElement);
+               combo.remove(EMPTY_ELEMENT_LABEL);
+           }
+       }
 }
index 9520de1b44ba894c8770d6b85df47df3aed35f99..bc920ea69b6501b01c33444eb8b5e4d1ea8e4401 100644 (file)
@@ -373,4 +373,9 @@ public class VocabularyComboElement<TERM extends DefinedTermBase<TERM>, VOC exte
                combo.setVisibleItemCount(count);
        }
 
+    public void removeEmptyElement(){
+        terms.remove(emptyElement);
+        combo.remove(EMPTY_ELEMENT_LABEL);
+    }
+
 }
index 8734cd94a6e813eb754128fb0060e50278d09384..6373d42ae2170711e3d21cfa675e108057e3efab 100644 (file)
@@ -150,7 +150,6 @@ import eu.etaxonomy.taxeditor.ui.section.description.ScopeElement;
 import eu.etaxonomy.taxeditor.ui.section.description.ScopeSection;
 import eu.etaxonomy.taxeditor.ui.section.description.StateDataElement;
 import eu.etaxonomy.taxeditor.ui.section.description.StateDataSection;
-import eu.etaxonomy.taxeditor.ui.section.description.StateModifierElement;
 import eu.etaxonomy.taxeditor.ui.section.description.StatisticalMeasurementValueElement;
 import eu.etaxonomy.taxeditor.ui.section.description.StatisticalMeasurementValueSection;
 import eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement;
@@ -314,6 +313,7 @@ import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitCollectionEle
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitCollectionSection;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.RecommendedModifierVocabulariesCollectionSection;
+import eu.etaxonomy.taxeditor.ui.section.vocabulary.RecommendedModifierVocabulariesElement;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.StateVocabularyCollectionElement;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.StateVocabularyCollectionSection;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.StatisticalMeasureCollectionElement;
@@ -2532,7 +2532,7 @@ public class CdmFormFactory extends FormToolkit {
                 element = new StateVocabularyCollectionElement(this, parentElement, (TermVocabulary<State>) entity, removeListener, backgroundColor, style);
                 break;
             case Modifier:
-                element = new StateModifierElement(this, parentElement, (TermVocabulary<DefinedTerm>) entity, removeListener, backgroundColor, style);
+                element = new RecommendedModifierVocabulariesElement(this, parentElement, (TermVocabulary<DefinedTerm>) entity, removeListener, backgroundColor, style);
                 break;
             default:
                 break;
index 40f1fcc86b044dc3e681272a6cc231418dc6a9eb..26a68223e3ca548854141a8dc4dc16d70f39ae4a 100644 (file)
@@ -56,6 +56,7 @@ public class MeasurementUnitCollectionElement extends AbstractEntityCollectionEl
         this.entity = entity;
         if(entity.getId()!=0){
             comboMeasurementUnit.setSelection(entity);
+            comboMeasurementUnit.removeEmptyElement();
         }
     }
 
@@ -63,11 +64,14 @@ public class MeasurementUnitCollectionElement extends AbstractEntityCollectionEl
     public void handleEvent(Object eventSource) {
         if(eventSource==comboMeasurementUnit && comboMeasurementUnit.getSelection()!=null){
             if(getParentElement() instanceof MeasurementUnitCollectionSection){
-                Feature feature = ((MeasurementUnitCollectionSection) getParentElement()).getEntity();
+                MeasurementUnitCollectionSection parentElement = (MeasurementUnitCollectionSection) getParentElement();
+                Feature feature = parentElement.getEntity();
                 feature.removeRecommendedMeasurementUnit(entity);
                 MeasurementUnit measurementUnit = comboMeasurementUnit.getSelection();
                 feature.addRecommendedMeasurementUnit(measurementUnit);
                 entity = measurementUnit;
+                //update the parent section to re-set the listeners to the persisted measurement unit
+                parentElement.removeElementAndUpdate(null);
             }
         }
     }
@@ -7,7 +7,7 @@
 * 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.section.description;
+package eu.etaxonomy.taxeditor.ui.section.vocabulary;
 
 import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.graphics.Color;
@@ -21,14 +21,13 @@ import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
-import eu.etaxonomy.taxeditor.ui.section.vocabulary.RecommendedModifierVocabulariesCollectionSection;
 
 /**
  * @author pplitzner
  * @date Apr 27, 2015
  *
  */
-public class StateModifierElement extends AbstractEntityCollectionElement<TermVocabulary<DefinedTerm>> {
+public class RecommendedModifierVocabulariesElement extends AbstractEntityCollectionElement<TermVocabulary<DefinedTerm>> {
 
 
     private VocabularyComboElement<DefinedTerm, TermVocabulary<DefinedTerm>> comboStateVocabulary;
@@ -42,7 +41,7 @@ public class StateModifierElement extends AbstractEntityCollectionElement<TermVo
      * @param backgroundColor
      * @param style
      */
-    public StateModifierElement(CdmFormFactory formFactory, AbstractFormSection section, TermVocabulary<DefinedTerm> entity,
+    public RecommendedModifierVocabulariesElement(CdmFormFactory formFactory, AbstractFormSection section, TermVocabulary<DefinedTerm> entity,
             SelectionListener removeListener, Color backgroundColor, int style) {
         super(formFactory, section, entity, removeListener, false, backgroundColor, style);
 
@@ -50,7 +49,7 @@ public class StateModifierElement extends AbstractEntityCollectionElement<TermVo
 
     @Override
     public void createControls(ICdmFormElement element, int style) {
-        comboStateVocabulary = formFactory.createVocabularyComboElement(TermType.Modifier, "State modifiers", null, element, style);
+        comboStateVocabulary = formFactory.createVocabularyComboElement(TermType.Modifier, "Modifier Vocabulary", null, element, style);
     }
 
     @Override
@@ -58,6 +57,7 @@ public class StateModifierElement extends AbstractEntityCollectionElement<TermVo
         this.entity = entity;
         if(entity.getId()!=0){
             comboStateVocabulary.setSelection(entity);
+            comboStateVocabulary.removeEmptyElement();
         }
     }
 
@@ -65,11 +65,14 @@ public class StateModifierElement extends AbstractEntityCollectionElement<TermVo
     public void handleEvent(Object eventSource) {
         if(eventSource==comboStateVocabulary && comboStateVocabulary.getSelection()!=null){
             if(getParentElement() instanceof RecommendedModifierVocabulariesCollectionSection){
-                Feature feature = ((RecommendedModifierVocabulariesCollectionSection) getParentElement()).getEntity();
+                RecommendedModifierVocabulariesCollectionSection parentElement = (RecommendedModifierVocabulariesCollectionSection) getParentElement();
+                Feature feature = parentElement.getEntity();
                 feature.removeRecommendedModifierEnumeration(entity);
                 TermVocabulary<DefinedTerm> vocabulary = comboStateVocabulary.getSelection();
                 feature.addRecommendedModifierEnumeration(vocabulary);
                 entity = vocabulary;
+                //update the parent section to re-set the listeners to the persisted measurement unit
+                parentElement.removeElementAndUpdate(null);
             }
         }
     }
index a8094ed724620e542d623ad166cc130b794321bf..de856abb9353933f8e6c6e325a21c7463f608ec8 100644 (file)
@@ -49,7 +49,7 @@ public class StateVocabularyCollectionElement extends AbstractEntityCollectionEl
 
     @Override
     public void createControls(ICdmFormElement element, int style) {
-        comboStateVocabulary = formFactory.createVocabularyComboElement(TermType.State, "State vocabularies", null, element, style);
+        comboStateVocabulary = formFactory.createVocabularyComboElement(TermType.State, "State vocabulary", null, element, style);
     }
 
     @Override
@@ -57,6 +57,7 @@ public class StateVocabularyCollectionElement extends AbstractEntityCollectionEl
         this.entity = entity;
         if(entity.getId()!=0){
             comboStateVocabulary.setSelection(entity);
+            comboStateVocabulary.removeEmptyElement();
         }
     }
 
@@ -64,11 +65,14 @@ public class StateVocabularyCollectionElement extends AbstractEntityCollectionEl
     public void handleEvent(Object eventSource) {
         if(eventSource==comboStateVocabulary && comboStateVocabulary.getSelection()!=null){
             if(getParentElement() instanceof StateVocabularyCollectionSection){
-                Feature feature = ((StateVocabularyCollectionSection) getParentElement()).getEntity();
+                StateVocabularyCollectionSection parentElement = (StateVocabularyCollectionSection) getParentElement();
+                Feature feature = parentElement.getEntity();
                 feature.removeSupportedCategoricalEnumeration(entity);
                 TermVocabulary<State> vocabulary = comboStateVocabulary.getSelection();
                 feature.addSupportedCategoricalEnumeration(vocabulary);
                 entity = vocabulary;
+                //update the parent section to re-set the listeners to the persisted measurement unit
+                parentElement.removeElementAndUpdate(null);
             }
         }
     }
index 237a5d369674bae77d505101dcde833a6d3723f3..57ee1dabda08e0a12538e6052aa2d2f257bfa171 100644 (file)
@@ -56,6 +56,7 @@ public class StatisticalMeasureCollectionElement extends AbstractEntityCollectio
         this.entity = entity;
         if(entity.getId()!=0){
             comboStatisticalMeasure.setSelection(entity);
+            comboStatisticalMeasure.removeEmptyElement();
         }
     }
 
@@ -63,11 +64,14 @@ public class StatisticalMeasureCollectionElement extends AbstractEntityCollectio
     public void handleEvent(Object eventSource) {
         if(eventSource==comboStatisticalMeasure && comboStatisticalMeasure.getSelection()!=null){
             if(getParentElement() instanceof StatisticalMeasureCollectionSection){
-                Feature feature = ((StatisticalMeasureCollectionSection) getParentElement()).getEntity();
+                StatisticalMeasureCollectionSection parentElement = (StatisticalMeasureCollectionSection) getParentElement();
+                Feature feature = parentElement.getEntity();
                 feature.removeRecommendedStatisticalMeasure(entity);
                 StatisticalMeasure statisticalMeasure = comboStatisticalMeasure.getSelection();
                 feature.addRecommendedStatisticalMeasure(statisticalMeasure);
                 entity = statisticalMeasure;
+                //update the parent section to re-set the listeners to the persisted measurement unit
+                parentElement.removeElementAndUpdate(null);
             }
         }
     }