]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fuxes #3904: VSplitPanel sends unnecessary split position events
authorJouni Koivuviita <jouni.koivuviita@itmill.com>
Wed, 23 Dec 2009 11:50:57 +0000 (11:50 +0000)
committerJouni Koivuviita <jouni.koivuviita@itmill.com>
Wed, 23 Dec 2009 11:50:57 +0000 (11:50 +0000)
svn changeset:10541/svn branch:6.2

src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java
src/com/vaadin/ui/SplitPanel.java

index 82839f2f31dfe3c3270b922b333b07c31c2526c7..ffada5325263eee3c49e79deea936fd6e2cb4e93 100644 (file)
@@ -434,7 +434,6 @@ public class VSplitPanel extends ComplexPanel implements Container,
             newX = getOffsetWidth() - getSplitterSize();
         }
         DOM.setStyleAttribute(splitter, "left", newX + "px");
-        updateSplitPosition(newX);
         if (origX != newX) {
             resized = true;
         }
@@ -450,7 +449,6 @@ public class VSplitPanel extends ComplexPanel implements Container,
             newY = getOffsetHeight() - getSplitterSize();
         }
         DOM.setStyleAttribute(splitter, "top", newY + "px");
-        updateSplitPosition(newY);
         if (origY != newY) {
             resized = true;
         }
@@ -463,6 +461,7 @@ public class VSplitPanel extends ComplexPanel implements Container,
         }
         resizing = false;
         onMouseMove(event);
+        updateSplitPositionToServer();
     }
 
     /**
@@ -593,12 +592,14 @@ public class VSplitPanel extends ComplexPanel implements Container,
 
     /**
      * Updates the new split position back to server.
-     * 
-     * @param pos
-     *            The new position of the split handle.
      */
-    private void updateSplitPosition(int pos) {
+    private void updateSplitPositionToServer() {
         // We always send pixel values to server
+        final String position = orientation == ORIENTATION_HORIZONTAL ? splitter
+                .getStyle().getProperty("left")
+                : splitter.getStyle().getProperty("top");
+        final int pos = Integer.parseInt(position.substring(0, position
+                .length() - 2));
         client.updateVariable(id, "position", pos, immediate);
     }
 
index 916c8bb5cc3a674816578807029762c43e857cb4..5e67b9336924e42864e83a0c396b4490dfd10024 100644 (file)
@@ -284,7 +284,7 @@ public class SplitPanel extends AbstractLayout {
      *            the new size of the first region in percentage
      */
     public void setSplitPosition(int pos) {
-        setSplitPosition(pos, UNITS_PERCENTAGE);
+        setSplitPosition(pos, UNITS_PERCENTAGE, true);
     }
 
     /**
@@ -296,9 +296,27 @@ public class SplitPanel extends AbstractLayout {
      *            the unit (from {@link Sizeable}) in which the size is given.
      */
     public void setSplitPosition(int pos, int unit) {
+        setSplitPosition(pos, unit, true);
+    }
+
+    /**
+     * Moves the position of the splitter.
+     * 
+     * @param pos
+     *            the new size of the first region in percentage
+     * @param unit
+     *            the unit (from {@link Sizeable}) in which the size is given.
+     * @param repaintNotNeeded
+     *            true if client side needs to be updated. Use false if the
+     *            position info has come from the client side, thus it already
+     *            knows the position.
+     */
+    private void setSplitPosition(int pos, int unit, boolean repaintNeeded) {
         this.pos = pos;
         posUnit = unit;
-        requestRepaint();
+        if (repaintNeeded) {
+            requestRepaint();
+        }
     }
 
     /**
@@ -335,8 +353,8 @@ public class SplitPanel extends AbstractLayout {
 
         if (variables.containsKey("position") && !isLocked()) {
             Integer newPos = (Integer) variables.get("position");
-            // Client always sends pixel values
-            setSplitPosition(newPos, UNITS_PIXELS);
+            // Client always sends pixel values. Repaint is not needed.
+            setSplitPosition(newPos, UNITS_PIXELS, false);
         }
 
         if (variables.containsKey(SPLITTER_CLICK_EVENT)) {