private Comparator<T> termComparator;
+ public Comparator<T> getTermComparator() {
+ return termComparator;
+ }
+
+ public void setTermComparator(Comparator<T> termComparator) {
+ this.termComparator = termComparator;
+ List<T> termsWithoutNull = terms.subList(1, terms.size());
+
+ populateTerms(termsWithoutNull);
+
+ }
+
private final TermType termType;
private final TermVocabulary termVocabulary;
private final Class<T> termClass;
public TermComboElement(CdmFormFactory formFactory,
ICdmFormElement parentElement, TermType termType, String labelString, T selection, boolean addEmptyElement,
- int style, boolean useAbbrevLabel) {
- this(formFactory, parentElement, null, termType, null, labelString, selection, addEmptyElement, style, useAbbrevLabel);
+ int style, boolean useAbbrevLabel, Comparator<T> comparator) {
+ this(formFactory, parentElement, null, termType, null, labelString, selection, addEmptyElement, style, useAbbrevLabel, comparator);
}
public TermComboElement(CdmFormFactory formFactory,
ICdmFormElement parentElement, TermVocabulary<?> termVocabulary, String labelString, T selection, boolean addEmptyElement,
- int style) {
- this(formFactory, parentElement, null, null, termVocabulary, labelString, selection, addEmptyElement, style, false);
+ int style, boolean useAbbrevLabel, Comparator<T> comparator) {
+ this(formFactory, parentElement, null, null, termVocabulary, labelString, selection, addEmptyElement, style, useAbbrevLabel, comparator);
}
public TermComboElement(CdmFormFactory formFactory,
ICdmFormElement parentElement, Class<T> termClass, String labelString, T selection, boolean addEmptyElement,
int style) {
- this(formFactory, parentElement, termClass, null, null, labelString, selection, addEmptyElement, style, false);
+ this(formFactory, parentElement, termClass, null, null, labelString, selection, addEmptyElement, style, false, null);
}
public TermComboElement(CdmFormFactory formFactory,
ICdmFormElement parentElement, Class<T> termClass, String labelString, T selection, boolean addEmptyElement,
int style, boolean useAbbrevLabel) {
- this(formFactory, parentElement, termClass, null, null, labelString, selection, addEmptyElement, style, useAbbrevLabel);
-
+ this(formFactory, parentElement, termClass, null, null, labelString, selection, addEmptyElement, style, useAbbrevLabel, null);
+
}
private TermComboElement(CdmFormFactory formFactory,
ICdmFormElement parentElement, Class<T> termClass, TermType termType, TermVocabulary<?> termVocabulary, String labelString, T selection, boolean addEmptyElement,
- int style, boolean useAbbrevLabel) {
+ int style, boolean useAbbrevLabel, Comparator<T> comparator) {
super(formFactory, parentElement);
this.termType = termType;
this.termClass = termClass;
this.addEmptyElement = addEmptyElement;
this.useAbbrevLabel = useAbbrevLabel;
+ this.termComparator = comparator;
if (labelString != null) {
label.setText(labelString);
}
int i = 1;
int index = 0;
- if(addEmptyElement){
- // Add an empty element for when nothing was selected yet
- combo.add(EMPTY_ELEMENT_LABEL);
- terms.add(emptyElement);
- }
-
if (termComparator != null) {
Collections.sort(preferredTerms, termComparator);
}
+ terms.addAll(preferredTerms);
+
+ List<String> labels = new ArrayList<>();
for (T term : preferredTerms) {
String label = getLabel(term);
if (label == null) {
}
- combo.add(label);
- terms.add(term);
+ labels.add(label);
i++;
if (selection != null) {
}
}
- if (selection != null && index == 0) {
+ String[] items = labels.toArray(new String[0]);
+ combo.setItems(items);
+
+ if(addEmptyElement){
+ // Add an empty element for when nothing was selected yet
+ combo.add(EMPTY_ELEMENT_LABEL, 0);
+ terms.add(0, emptyElement);
+ }
+
+ if (selection != null && index == 0) {
createTermNotInPreferredTerms(selection);
}
combo.select(index);
+
}
protected List<T> getPreferredTerms(){