private Class<T> termClass;
+ private List<T> customPreferredTerms;
+
/**
* <p>
for (Listener listener : listeners) {
combo.removeListener(SWT.Selection, listener);
}
- int index;
+ int selectedIndex;
if(selection == null){
- index = 0;
+ // set selection to the emptyElement
+ selectedIndex = 0;
}else{
- index = terms.indexOf(selection);
- if (index == -1) {
+ selectedIndex = terms.indexOf(selection);
+ if (selectedIndex == -1) {
createTermNotInPreferredTerms(selection);
- index = terms.indexOf(selection);
+ selectedIndex = terms.indexOf(selection);
}
}
- combo.select(index);
+ combo.select(selectedIndex);
for (Listener listener : listeners) {
combo.addListener(SWT.Selection, listener);
}
}
+ /**
+ * Fills the combo with elements and sets up the convenience functions
+ * for selection index
+ *
+ * @param preferredTerms
+ */
private void populateTerms(List<T> preferredTerms) {
combo.removeAll();
* @return a {@link java.util.List} object.
*/
protected List<T> getPreferredTerms(){
+ if (customPreferredTerms != null){
+ return customPreferredTerms;
+ }
return getTermManager().getPreferredTerms(termClass);
}
return term.getLabel(CdmStore.getDefaultLanguage());
}
+ /**
+ *
+ *
+ * @param term
+ */
private void createTermNotInPreferredTerms(T term) {
List<T> preferredTerms = getPreferredTerms();
return CdmStore.getTermManager();
}
+ /**
+ *
+ * @return
+ */
public int getVisibleItemCount(){
return combo.getVisibleItemCount();
}
+ /**
+ *
+ * @param count
+ */
public void setVisibleItemCount(int count){
combo.setVisibleItemCount(count);
}
+ /**
+ * <p>A {@link List} of term objects may be passed to this combo box. In this case, the default behaviour
+ * of displaying the preferred terms for the T type will be overridden and the combo will only display the
+ * given terms. Also, any previous selection will be reseted.</p>
+ *
+ * <p>To return to the default of displaying the preferred terms, simply pass <code>null</code>.</p>
+ *
+ * @param terms a {@link List} of T objects or <code>null</code> for default preferred terms
+ */
public void setTerms(List<T> terms) {
- populateTerms(terms);
+ setSelection(null);
+ customPreferredTerms = terms;
+ populateTerms(customPreferredTerms);
}
}
toggleable_cache = formFactory.createToggleableTextField(this, "Name Cache", nonViralName.getNameCache(), nonViralName.isProtectedNameCache(), style);
combo_rank = formFactory.createTermComboElement(Rank.class, this, "Rank", nonViralName.getRank(), style);
-
+
createGenusOrUninomialControls(this, nonViralName, style);
createInfragenerericEpithetControls(this, nonViralName, style);
createSpecificEpithetControls(this, nonViralName, style);