]> source.dussan.org Git - vaadin-framework.git/commitdiff
Update TwinColSelect to update its sizes when needed (#8313)
authorLeif Åstrand <leif@vaadin.com>
Thu, 8 Mar 2012 14:53:04 +0000 (16:53 +0200)
committerLeif Åstrand <leif@vaadin.com>
Thu, 8 Mar 2012 14:53:04 +0000 (16:53 +0200)
src/com/vaadin/terminal/gwt/client/ui/TwinColSelectConnector.java
src/com/vaadin/terminal/gwt/client/ui/VTwinColSelect.java

index 89a526a95cb6b9cfb054987c3d2f9eaa1b7d1cc6..c15718c9ec19ecd0acc6f4307f4ec71d316ad277 100644 (file)
@@ -7,9 +7,11 @@ package com.vaadin.terminal.gwt.client.ui;
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.DirectionalManagedLayout;
 import com.vaadin.terminal.gwt.client.UIDL;
 
-public class TwinColSelectConnector extends OptionGroupBaseConnector {
+public class TwinColSelectConnector extends OptionGroupBaseConnector implements
+        DirectionalManagedLayout {
 
     @Override
     public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
@@ -31,4 +33,20 @@ public class TwinColSelectConnector extends OptionGroupBaseConnector {
     public VTwinColSelect getWidget() {
         return (VTwinColSelect) super.getWidget();
     }
+
+    public void layoutVertically() {
+        if (isUndefinedHeight()) {
+            getWidget().clearInternalHeights();
+        } else {
+            getWidget().setInternalHeights();
+        }
+    }
+
+    public void layoutHorizontally() {
+        if (isUndefinedWidth()) {
+            getWidget().clearInternalWidths();
+        } else {
+            getWidget().setInternalWidths();
+        }
+    }
 }
index a7fe89017b7bc7ae431b2cb4819040d1fb6f32c8..cb495293cc08c60f08a61482c9ffd4d6ff801f7d 100644 (file)
@@ -58,8 +58,6 @@ public class VTwinColSelect extends VOptionGroupBase implements KeyDownHandler,
 
     private final Panel panel;
 
-    private boolean widthSet = false;
-
     /**
      * A ListBox which catches double clicks
      * 
@@ -225,32 +223,6 @@ public class VTwinColSelect extends VOptionGroupBase implements KeyDownHandler,
             }
         }
 
-        int cols = -1;
-        if (getColumns() > 0) {
-            cols = getColumns();
-        } else if (!widthSet) {
-            cols = DEFAULT_COLUMN_COUNT;
-        }
-
-        if (cols >= 0) {
-            String colWidth = cols + "em";
-            String containerWidth = (2 * cols + 4) + "em";
-            // Caption wrapper width == optionsSelect + buttons +
-            // selectionsSelect
-            String captionWrapperWidth = (2 * cols + 4 - 0.5) + "em";
-
-            options.setWidth(colWidth);
-            if (optionsCaption != null) {
-                optionsCaption.setWidth(colWidth);
-            }
-            selections.setWidth(colWidth);
-            if (selectionsCaption != null) {
-                selectionsCaption.setWidth(colWidth);
-            }
-            buttons.setWidth("3.5em");
-            optionsContainer.setWidth(containerWidth);
-            captionWrapper.setWidth(captionWrapperWidth);
-        }
         if (getRows() > 0) {
             options.setVisibleItemCount(getRows());
             selections.setVisibleItemCount(getRows());
@@ -359,18 +331,12 @@ public class VTwinColSelect extends VOptionGroupBase implements KeyDownHandler,
         }
     }
 
-    @Override
-    public void setHeight(String height) {
-        super.setHeight(height);
-        if ("".equals(height)) {
-            options.setHeight("");
-            selections.setHeight("");
-        } else {
-            setInternalHeights();
-        }
+    void clearInternalHeights() {
+        selections.setHeight("");
+        options.setHeight("");
     }
 
-    private void setInternalHeights() {
+    void setInternalHeights() {
         int captionHeight = 0;
         int totalHeight = getOffsetHeight();
 
@@ -386,18 +352,36 @@ public class VTwinColSelect extends VOptionGroupBase implements KeyDownHandler,
 
     }
 
-    @Override
-    public void setWidth(String width) {
-        super.setWidth(width);
-        if (!"".equals(width) && width != null) {
-            setInternalWidths();
-            widthSet = true;
+    void clearInternalWidths() {
+        int cols = -1;
+        if (getColumns() > 0) {
+            cols = getColumns();
         } else {
-            widthSet = false;
+            cols = DEFAULT_COLUMN_COUNT;
+        }
+
+        if (cols >= 0) {
+            String colWidth = cols + "em";
+            String containerWidth = (2 * cols + 4) + "em";
+            // Caption wrapper width == optionsSelect + buttons +
+            // selectionsSelect
+            String captionWrapperWidth = (2 * cols + 4 - 0.5) + "em";
+
+            options.setWidth(colWidth);
+            if (optionsCaption != null) {
+                optionsCaption.setWidth(colWidth);
+            }
+            selections.setWidth(colWidth);
+            if (selectionsCaption != null) {
+                selectionsCaption.setWidth(colWidth);
+            }
+            buttons.setWidth("3.5em");
+            optionsContainer.setWidth(containerWidth);
+            captionWrapper.setWidth(captionWrapperWidth);
         }
     }
 
-    private void setInternalWidths() {
+    void setInternalWidths() {
         DOM.setStyleAttribute(getElement(), "position", "relative");
         int bordersAndPaddings = Util.measureHorizontalPaddingAndBorder(
                 buttons.getElement(), 0);