]> source.dussan.org Git - vaadin-framework.git/commitdiff
SplitPanel now updates it's position back to server when user drags it in the browser.
authorJouni Koivuviita <jouni.koivuviita@itmill.com>
Thu, 9 Oct 2008 09:35:41 +0000 (09:35 +0000)
committerJouni Koivuviita <jouni.koivuviita@itmill.com>
Thu, 9 Oct 2008 09:35:41 +0000 (09:35 +0000)
svn changeset:5616/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/ISplitPanel.java
src/com/itmill/toolkit/ui/SplitPanel.java

index 0319b56696ae711f7d8875331d399328538d7b2b..ce0726cc59447227482dc52a9c7a61f94e3aadb7 100644 (file)
@@ -75,6 +75,10 @@ public class ISplitPanel extends ComplexPanel implements Container,
 
     RenderInformation renderInformation = new RenderInformation();
 
+    private String id;
+
+    private boolean immediate;
+
     public ISplitPanel() {
         this(ORIENTATION_HORIZONTAL);
     }
@@ -148,6 +152,9 @@ public class ISplitPanel extends ComplexPanel implements Container,
 
     public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
         this.client = client;
+        id = uidl.getId();
+
+        immediate = uidl.hasAttribute("immediate");
 
         if (client.updateComponent(this, uidl, true)) {
             return;
@@ -334,6 +341,7 @@ public class ISplitPanel extends ComplexPanel implements Container,
         secondChild = w;
     }
 
+    @Override
     public void onBrowserEvent(Event event) {
         switch (DOM.eventGetType(event)) {
         case Event.ONMOUSEMOVE:
@@ -400,6 +408,7 @@ public class ISplitPanel extends ComplexPanel implements Container,
             newX = getOffsetWidth() - getSplitterSize();
         }
         DOM.setStyleAttribute(splitter, "left", newX + "px");
+        updateSplitPosition(newX);
     }
 
     private void onVerticalMouseMove(int y) {
@@ -412,6 +421,7 @@ public class ISplitPanel extends ComplexPanel implements Container,
             newY = getOffsetHeight() - getSplitterSize();
         }
         DOM.setStyleAttribute(splitter, "top", newY + "px");
+        updateSplitPosition(newY);
     }
 
     public void onMouseUp(Event event) {
@@ -525,4 +535,15 @@ public class ISplitPanel 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) {
+        // We always send pixel values to server
+        client.updateVariable(id, "position", pos, immediate);
+    }
+
 }
index 6a7cb9e056865ab8c8e6479cee3eaafcf5199fe8..38efecbb035c3c4fe739ae79f293db89c9224590 100644 (file)
@@ -5,9 +5,11 @@
 package com.itmill.toolkit.ui;
 
 import java.util.Iterator;
+import java.util.Map;
 
 import com.itmill.toolkit.terminal.PaintException;
 import com.itmill.toolkit.terminal.PaintTarget;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
 
 /**
  * SplitPanel.
@@ -75,6 +77,7 @@ public class SplitPanel extends AbstractLayout {
      * 
      * @return the Component UIDL tag as string.
      */
+    @Override
     public String getTag() {
         if (orientation == ORIENTATION_HORIZONTAL) {
             return "hsplitpanel";
@@ -90,6 +93,7 @@ public class SplitPanel extends AbstractLayout {
      * @param c
      *            the component to be added.
      */
+    @Override
     public void addComponent(Component c) {
         if (firstComponent == null) {
             firstComponent = c;
@@ -127,6 +131,7 @@ public class SplitPanel extends AbstractLayout {
      * @param c
      *            the component to be removed.
      */
+    @Override
     public void removeComponent(Component c) {
         super.removeComponent(c);
         if (c == firstComponent) {
@@ -192,6 +197,7 @@ public class SplitPanel extends AbstractLayout {
      * @throws PaintException
      *             if the paint operation failed.
      */
+    @Override
     public void paintContent(PaintTarget target) throws PaintException {
         super.paintContent(target);
 
@@ -297,4 +303,22 @@ public class SplitPanel extends AbstractLayout {
         return locked;
     }
 
+    /*
+     * Invoked when a variable of the component changes. Don't add a JavaDoc
+     * comment here, we use the default documentation from implemented
+     * interface.
+     */
+    @Override
+    public void changeVariables(Object source, Map variables) {
+
+        super.changeVariables(source, variables);
+
+        if (variables.containsKey("position") && !isLocked()) {
+            Integer newPos = (Integer) variables.get("position");
+            // Client always sends pixel values
+            setSplitPosition(newPos, UNITS_PIXELS);
+        }
+
+    }
+
 }