Added the ability to clear the selection of a combo
authorn.hoffmann <n.hoffmann@localhost>
Tue, 31 Jan 2012 15:52:07 +0000 (15:52 +0000)
committern.hoffmann <n.hoffmann@localhost>
Tue, 31 Jan 2012 15:52:07 +0000 (15:52 +0000)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermComboElement.java

index c19921f36129f48b454a2a7f38997d5c2b606cac..ac7e878a55c3ec55f31aca868aa6a235685d229c 100644 (file)
@@ -127,24 +127,28 @@ public class TermComboElement<T extends DefinedTermBase>
        }
 
        /**
-        * <p>
-        * Setter for the field <code>selection</code>.
-        * </p>
+        * <p>Sets the selection of the combo to the given T object.</p>
+        * <p>Passing <code>null</code> to this method will set the selection to 
+        * the empty element and effectively clear the selection</p>
         * 
         * @param selection
-        *            a T object.
+        *            a T object or <code>null</code> to clear the selection
         */
-       public void setSelection(T selection) {
+       public void setSelection(T selection) {                 
                Listener[] listeners = combo.getListeners(SWT.Selection);
 
                for (Listener listener : listeners) {
                        combo.removeListener(SWT.Selection, listener);
                }
-
-               int index = terms.indexOf(selection);
-               if (index == -1) {
-                       createTermNotInPreferredTerms(selection);
+               int index;
+               if(selection == null){
+                       index = 0;
+               }else{
                        index = terms.indexOf(selection);
+                       if (index == -1) {
+                               createTermNotInPreferredTerms(selection);
+                               index = terms.indexOf(selection);
+                       }
                }
                combo.select(index);