From: Leif Åstrand Date: Thu, 8 Mar 2012 14:53:04 +0000 (+0200) Subject: Update TwinColSelect to update its sizes when needed (#8313) X-Git-Tag: 7.0.0.alpha2~377 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8ab2e6d4a0e890899e58d4f01ea03e773abe974a;p=vaadin-framework.git Update TwinColSelect to update its sizes when needed (#8313) --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/TwinColSelectConnector.java b/src/com/vaadin/terminal/gwt/client/ui/TwinColSelectConnector.java index 89a526a95c..c15718c9ec 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/TwinColSelectConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/TwinColSelectConnector.java @@ -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(); + } + } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTwinColSelect.java b/src/com/vaadin/terminal/gwt/client/ui/VTwinColSelect.java index a7fe89017b..cb495293cc 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTwinColSelect.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTwinColSelect.java @@ -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);