]> source.dussan.org Git - vaadin-framework.git/commitdiff
fixes #5534
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 1 Sep 2010 12:11:07 +0000 (12:11 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 1 Sep 2010 12:11:07 +0000 (12:11 +0000)
svn changeset:14678/svn branch:6.4

src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java
src/com/vaadin/ui/Table.java

index 60c6af76146b06098e3cb99a1bfac6ab45229cdb..ee1c2043154be827628063ef9c8fbe805cf9ae1a 100644 (file)
@@ -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);
     }
 
     /**
index 770e0416c1d56a3999155289da3af9f2880dd5ea..e66a37a449f42a16b05780f77e38bb1fd8aea24a 100644 (file)
@@ -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<Object> renderedItemIds = getCurrentlyRenderedItemIds();
+
+        HashSet<Object> newValue = new HashSet<Object>(
+                (Collection<Object>) 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<Object> getCurrentlyRenderedItemIds() {
+        HashSet<Object> ids = new HashSet<Object>();
+        if (pageBuffer != null) {
+            for (int i = 0; i < pageBuffer[CELL_ITEMID].length; i++) {
+                ids.add(pageBuffer[CELL_ITEMID][i]);
+            }
+        }
+        return ids;
     }
 
     /* Component basics */