From 8bf0589ddac4ecb3b16390985c0277e3de601e73 Mon Sep 17 00:00:00 2001 From: "n.hoffmann" Date: Tue, 31 Jan 2012 15:52:07 +0000 Subject: [PATCH] Added the ability to clear the selection of a combo --- .../taxeditor/ui/combo/TermComboElement.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermComboElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermComboElement.java index c19921f36..ac7e878a5 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermComboElement.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermComboElement.java @@ -127,24 +127,28 @@ public class TermComboElement } /** - *

- * Setter for the field selection. - *

+ *

Sets the selection of the combo to the given T object.

+ *

Passing null to this method will set the selection to + * the empty element and effectively clear the selection

* * @param selection - * a T object. + * a T object or null 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); -- 2.34.1