]> source.dussan.org Git - vaadin-framework.git/commitdiff
ENHANCEMENT: SplitPanel.setLocked(boolean locked) - allows locking the splitpanel...
authorJouni Koivuviita <jouni.koivuviita@itmill.com>
Mon, 25 Feb 2008 09:30:01 +0000 (09:30 +0000)
committerJouni Koivuviita <jouni.koivuviita@itmill.com>
Mon, 25 Feb 2008 09:30:01 +0000 (09:30 +0000)
svn changeset:3907/svn branch:trunk

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

index 1fc864c1ff9d74e6fc07f7fdbf8e69747fa840d3..e17271bf339de53faab0591877df71ae208f3b90 100644 (file)
@@ -49,6 +49,10 @@ public class ISplitPanel extends ComplexPanel implements Paintable,
 
     private int origMouseY;
 
+    private boolean locked;
+
+    private String splitterStyleName;
+
     public ISplitPanel() {
         this(ORIENTATION_HORIZONTAL);
     }
@@ -99,15 +103,16 @@ public class ISplitPanel extends ComplexPanel implements Paintable,
             DOM.setStyleAttribute(splitter, "height", "100%");
             DOM.setStyleAttribute(firstContainer, "height", "100%");
             DOM.setStyleAttribute(secondContainer, "height", "100%");
-            DOM.setElementProperty(splitter, "className", CLASSNAME
-                    + "-hsplitter");
         } else {
             DOM.setStyleAttribute(splitter, "width", "100%");
             DOM.setStyleAttribute(firstContainer, "width", "100%");
             DOM.setStyleAttribute(secondContainer, "width", "100%");
-            DOM.setElementProperty(splitter, "className", CLASSNAME
-                    + "-vsplitter");
         }
+
+        splitterStyleName = CLASSNAME
+                + (orientation == ORIENTATION_HORIZONTAL ? "-hsplitter"
+                        : "-vsplitter");
+        DOM.setElementProperty(splitter, "className", splitterStyleName);
     }
 
     public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
@@ -117,6 +122,14 @@ public class ISplitPanel extends ComplexPanel implements Paintable,
 
         setSplitPosition(uidl.getStringAttribute("position"));
 
+        locked = uidl.hasAttribute("locked");
+        if (locked) {
+            DOM.setElementProperty(splitter, "className", splitterStyleName
+                    + "-locked");
+        } else {
+            DOM.setElementProperty(splitter, "className", splitterStyleName);
+        }
+
         final Paintable newFirstChild = client.getPaintable(uidl
                 .getChildUIDL(0));
         final Paintable newSecondChild = client.getPaintable(uidl
@@ -278,6 +291,9 @@ public class ISplitPanel extends ComplexPanel implements Paintable,
     }
 
     public void onMouseDown(Event event) {
+        if (locked) {
+            return;
+        }
         final Element trg = DOM.eventGetTarget(event);
         if (DOM.compare(trg, splitter)
                 || DOM.compare(trg, DOM.getChild(splitter, 0))) {
index dd4c96c4b942e90e580e56a9673f91c3ce1a6ff0..eda36ffb80e8fbb52d7f7bf86379474e7bd65923 100644 (file)
@@ -47,6 +47,8 @@ public class SplitPanel extends AbstractLayout {
 
     private int posUnit = UNITS_PERCENTAGE;
 
+    private boolean locked = false;
+
     /**
      * Creates a new split panel. The orientation of the panels is
      * <code>ORIENTATION_VERTICAL</code>.
@@ -196,6 +198,10 @@ public class SplitPanel extends AbstractLayout {
         final String position = pos + UNIT_SYMBOLS[posUnit];
 
         target.addAttribute("position", position);
+        
+        if(isLocked()) {
+            target.addAttribute("locked", true);
+        }
 
         if (firstComponent != null) {
             firstComponent.paint(target);
@@ -269,4 +275,27 @@ public class SplitPanel extends AbstractLayout {
         posUnit = unit;
     }
 
+    /**
+     * Lock the SplitPanels position, disabling the user from dragging the split
+     * handle.
+     * 
+     * @param locked
+     *                Set <code>true</code> if locked, <code>false</code>
+     *                otherwise.
+     */
+    public void setLocked(boolean locked) {
+        this.locked = locked;
+        requestRepaint();
+    }
+
+    /**
+     * Is the SplitPanel handle locked (user not allowed to change split
+     * position by dragging).
+     * 
+     * @return <code>true</code> if locked, <code>false</code> otherwise.
+     */
+    public boolean isLocked() {
+        return locked;
+    }
+
 }