}
/**
- * <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);