Great component, unfortunately I can’t use it for my case because selection order is not kept. Is there a chance to improve? Thanks!
Yes, there it is: copy class MultiselectComboBox
into your own code (so that it is higher prioritized at the build path than the original class) and exchange every new HashSet
by new LinkedHashSet
.
Additionally call setOrdered(false)
.
And sort your values in your ValueProvider
when binding and return them in a LinkedHashSet
.
Plus add this method to your MultiselectComboBox
class:
@Override
protected boolean valueEquals(Set<T> value1, Set<T> value2) {
if (super.valueEquals(value1, value2)) {
if (value1 instanceof LinkedHashSet && value2 instanceof LinkedHashSet && value1.size() == value2.size()) {
// Additionally check order of the entries
Iterator<T> iterator1 = ((LinkedHashSet<T>) value1).iterator();
Iterator<T> iterator2 = ((LinkedHashSet<T>) value2).iterator();
while (iterator1.hasNext()) {
if (!Objects.equals(iterator1.next(), iterator2.next())) { return false; }
}
return true;
} else {
return true;
}
}
return false;
}
My usecase was that I wanted a list of months ordered chronologically (March, April, May), not alphabetically (April, March, May). Works for the user as follows:
adding a new month (e.g. August) in the UI adds it at the end of the MultiselectCombobox
, and after saving (and re-applying the domain object to the binder) the MultiselectCombobox
shows March, April, May, August.