From: Matti Tahvonen Date: Wed, 1 Sep 2010 12:11:07 +0000 (+0000) Subject: fixes #5534 X-Git-Tag: 6.7.0.beta1~1234 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=152c0947749903c763c15d4ab2fc3515fb787172;p=vaadin-framework.git fixes #5534 svn changeset:14678/svn branch:6.4 --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java index 60c6af7614..ee1c204315 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java @@ -4300,6 +4300,9 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, // still ensure all selects are removed from (not necessary rendered) selectedRowKeys.clear(); selectedRowRanges.clear(); + // also notify server that it clears all previous selections (the client + // side does not know about the invisible ones) + client.updateVariable(paintableId, "clearSelections", true, false); } /** diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index 770e0416c1..e66a37a449 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -1881,37 +1881,67 @@ public class Table extends AbstractSelect implements Action.Container, final String[] ka = (String[]) variables.get("selected"); final String[] ranges = (String[]) variables.get("selectedRanges"); - // Converts the key-array to id-set - final LinkedList s = new LinkedList(); + Set renderedItemIds = getCurrentlyRenderedItemIds(); + + HashSet newValue = new HashSet( + (Collection) getValue()); + + if (variables.containsKey("clearSelections")) { + // the client side has instructed to swipe all previous selections + newValue.clear(); + } else { + /* + * first clear all selections that are currently rendered rows (the + * ones that the client side counterpart is aware of) + */ + newValue.removeAll(renderedItemIds); + } + + /* + * Then add (possibly some of them back) rows that are currently + * selected on the client side (the ones that the client side is aware + * of). + */ for (int i = 0; i < ka.length; i++) { + // key to id final Object id = itemIdMapper.get(ka[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); + newValue.add(id); } } - if (!isNullSelectionAllowed() && s.size() < 1) { + if (!isNullSelectionAllowed() && newValue.size() < 1) { // empty selection not allowed, keep old value requestRepaint(); return; } - // Add range items + /* Add range items aka shift clicked multiselection areas */ if (ranges != null) { for (String range : ranges) { String[] limits = range.split("-"); int start = Integer.valueOf(limits[0]); int end = Integer.valueOf(limits[1]); - s.addAll(getItemIdsInRange(start, end)); + newValue.addAll(getItemIdsInRange(start, end)); } } - setValue(s, true); + setValue(newValue, true); + + } + private Set getCurrentlyRenderedItemIds() { + HashSet ids = new HashSet(); + if (pageBuffer != null) { + for (int i = 0; i < pageBuffer[CELL_ITEMID].length; i++) { + ids.add(pageBuffer[CELL_ITEMID][i]); + } + } + return ids; } /* Component basics */