// Selection change
if (variables.containsKey("selected")) {
- final String[] ka = (String[]) variables.get("selected");
+ final String[] clientSideSelectedKeys = (String[]) variables
+ .get("selected");
// Multiselect mode
if (isMultiSelect()) {
// TODO Optimize by adding repaintNotNeeded when applicable
// Converts the key-array to id-set
- final LinkedList<Object> s = new LinkedList<Object>();
- for (int i = 0; i < ka.length; i++) {
- final Object id = itemIdMapper.get(ka[i]);
+ final LinkedList<Object> acceptedSelections = new LinkedList<Object>();
+ for (int i = 0; i < clientSideSelectedKeys.length; i++) {
+ final Object id = itemIdMapper
+ .get(clientSideSelectedKeys[i]);
if (!isNullSelectionAllowed()
&& (id == null || id == getNullSelectionItemId())) {
// skip empty selection if nullselection is not allowed
requestRepaint();
} else if (id != null && containsId(id)) {
- s.add(id);
+ acceptedSelections.add(id);
}
}
- if (!isNullSelectionAllowed() && s.size() < 1) {
+ if (!isNullSelectionAllowed() && acceptedSelections.size() < 1) {
// empty selection not allowed, keep old value
requestRepaint();
return;
// Limits the deselection to the set of visible items
// (non-visible items can not be deselected)
- Collection<?> visible = getVisibleItemIds();
- if (visible != null) {
- visible = new HashSet<Object>(visible);
+ Collection<?> visibleNotSelected = getVisibleItemIds();
+ if (visibleNotSelected != null) {
+ visibleNotSelected = new HashSet<Object>(visibleNotSelected);
// Don't remove those that will be added to preserve order
- visible.removeAll(s);
+ visibleNotSelected.removeAll(acceptedSelections);
@SuppressWarnings("unchecked")
Set<Object> newsel = (Set<Object>) getValue();
} else {
newsel = new LinkedHashSet<Object>(newsel);
}
- newsel.removeAll(visible);
- newsel.addAll(s);
+ newsel.removeAll(visibleNotSelected);
+ newsel.addAll(acceptedSelections);
setValue(newsel, true);
}
} else {
// Single select mode
if (!isNullSelectionAllowed()
- && (ka.length == 0 || ka[0] == null || ka[0] == getNullSelectionItemId())) {
+ && (clientSideSelectedKeys.length == 0
+ || clientSideSelectedKeys[0] == null || clientSideSelectedKeys[0] == getNullSelectionItemId())) {
requestRepaint();
return;
}
- if (ka.length == 0) {
+ if (clientSideSelectedKeys.length == 0) {
// Allows deselection only if the deselected item is
// visible
final Object current = getValue();
setValue(null, true);
}
} else {
- final Object id = itemIdMapper.get(ka[0]);
+ final Object id = itemIdMapper
+ .get(clientSideSelectedKeys[0]);
if (!isNullSelectionAllowed() && id == null) {
requestRepaint();
} else if (id != null
* The end key
* @return
*/
- private Set<Object> getItemIdsInRange(Object itemId, final int length) {
- HashSet<Object> ids = new LinkedHashSet<Object>();
+ private LinkedHashSet<Object> getItemIdsInRange(Object itemId,
+ final int length) {
+ LinkedHashSet<Object> ids = new LinkedHashSet<Object>();
for (int i = 0; i < length; i++) {
assert itemId != null; // should not be null unless client-server
// are out of sync
final String[] ka = (String[]) variables.get("selected");
final String[] ranges = (String[]) variables.get("selectedRanges");
- Set<Object> renderedItemIds = getCurrentlyRenderedItemIds();
+ Set<Object> renderedButNotSelectedItemIds = getCurrentlyRenderedItemIds();
@SuppressWarnings("unchecked")
HashSet<Object> newValue = new LinkedHashSet<Object>(
requestRepaint();
} else if (id != null && containsId(id)) {
newValue.add(id);
- renderedItemIds.remove(id);
+ renderedButNotSelectedItemIds.remove(id);
}
}
String[] split = range.split("-");
Object startItemId = itemIdMapper.get(split[0]);
int length = Integer.valueOf(split[1]);
- Set<Object> itemIdsInRange = getItemIdsInRange(startItemId,
- length);
+ LinkedHashSet<Object> itemIdsInRange = getItemIdsInRange(
+ startItemId, length);
newValue.addAll(itemIdsInRange);
- renderedItemIds.removeAll(itemIdsInRange);
+ renderedButNotSelectedItemIds.removeAll(itemIdsInRange);
}
}
/*
* finally clear all currently rendered rows (the ones that the client
* side counterpart is aware of) that the client didn't send as selected
*/
- newValue.removeAll(renderedItemIds);
+ newValue.removeAll(renderedButNotSelectedItemIds);
if (!isNullSelectionAllowed() && newValue.isEmpty()) {
// empty selection not allowed, keep old value