From 5abe444f28b89cc6c06cc178912a8fa3e03107c9 Mon Sep 17 00:00:00 2001 From: John Ahlroos Date: Fri, 31 Aug 2012 16:13:40 +0300 Subject: [PATCH] Add helper methods for checking state --- client/src/com/vaadin/client/LayoutManager.java | 3 ++- client/src/com/vaadin/client/VCaption.java | 7 ++++--- .../com/vaadin/client/ui/AbstractComponentConnector.java | 3 ++- client/src/com/vaadin/client/ui/UI/UIConnector.java | 3 ++- .../src/com/vaadin/client/ui/combobox/VFilterSelect.java | 4 ++-- client/src/com/vaadin/client/ui/form/FormConnector.java | 3 ++- .../src/com/vaadin/client/ui/formlayout/VFormLayout.java | 3 ++- .../com/vaadin/client/ui/menubar/MenuBarConnector.java | 2 +- client/src/com/vaadin/client/ui/panel/PanelConnector.java | 3 ++- .../vaadin/client/ui/popupview/PopupViewConnector.java | 3 ++- .../client/ui/splitpanel/AbstractSplitPanelConnector.java | 3 ++- client/src/com/vaadin/client/ui/tabsheet/VTabsheet.java | 3 ++- server/src/com/vaadin/ui/AbstractComponent.java | 4 ++-- shared/src/com/vaadin/shared/ui/ComponentStateUtil.java | 8 ++++++++ 14 files changed, 35 insertions(+), 17 deletions(-) diff --git a/client/src/com/vaadin/client/LayoutManager.java b/client/src/com/vaadin/client/LayoutManager.java index a0d8761581..7b6fe19a37 100644 --- a/client/src/com/vaadin/client/LayoutManager.java +++ b/client/src/com/vaadin/client/LayoutManager.java @@ -1077,7 +1077,8 @@ public class LayoutManager { int assignedHeight) { assert component.isRelativeHeight(); - float percentSize = parsePercent(component.getState().height); + float percentSize = parsePercent(component.getState().height == null ? "" + : component.getState().height); int effectiveHeight = Math.round(assignedHeight * (percentSize / 100)); reportOuterHeight(component, effectiveHeight); diff --git a/client/src/com/vaadin/client/VCaption.java b/client/src/com/vaadin/client/VCaption.java index a3d3a7034e..aadc7b88ad 100644 --- a/client/src/com/vaadin/client/VCaption.java +++ b/client/src/com/vaadin/client/VCaption.java @@ -25,6 +25,7 @@ import com.vaadin.client.ui.Icon; import com.vaadin.shared.AbstractFieldState; import com.vaadin.shared.ComponentConstants; import com.vaadin.shared.ComponentState; +import com.vaadin.shared.ui.ComponentStateUtil; public class VCaption extends HTML { @@ -110,8 +111,7 @@ public class VCaption extends HTML { placedAfterComponent = true; String style = CLASSNAME; - if (owner.getState().styles != null - && !owner.getState().styles.isEmpty()) { + if (ComponentStateUtil.hasStyles(owner.getState())) { for (String customStyle : owner.getState().styles) { style += " " + CLASSNAME + "-" + customStyle; } @@ -192,7 +192,8 @@ public class VCaption extends HTML { captionText = null; } - if (owner.getState().description != null && captionText != null) { + if (ComponentStateUtil.hasDescription(owner.getState()) + && captionText != null) { addStyleDependentName("hasdescription"); } else { removeStyleDependentName("hasdescription"); diff --git a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java index 8ac113e72e..d5e8dc0ba0 100644 --- a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java +++ b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java @@ -42,6 +42,7 @@ import com.vaadin.client.ui.datefield.PopupDateFieldConnector; import com.vaadin.shared.ComponentConstants; import com.vaadin.shared.ComponentState; import com.vaadin.shared.Connector; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.TabIndexState; public abstract class AbstractComponentConnector extends AbstractConnector @@ -282,7 +283,7 @@ public abstract class AbstractComponentConnector extends AbstractConnector // add additional user defined style names as class names, prefixed with // component default class name. remove nonexistent style names. - if (state.styles != null && !state.styles.isEmpty()) { + if (ComponentStateUtil.hasStyles(state)) { // add new style names List newStyles = new ArrayList(); newStyles.addAll(state.styles); diff --git a/client/src/com/vaadin/client/ui/UI/UIConnector.java b/client/src/com/vaadin/client/ui/UI/UIConnector.java index b22e9af09b..cb8b0ece9e 100644 --- a/client/src/com/vaadin/client/ui/UI/UIConnector.java +++ b/client/src/com/vaadin/client/ui/UI/UIConnector.java @@ -52,6 +52,7 @@ import com.vaadin.client.ui.layout.MayScrollChildren; import com.vaadin.client.ui.notification.VNotification; import com.vaadin.client.ui.window.WindowConnector; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.Connect.LoadStyle; import com.vaadin.shared.ui.ui.PageClientRpc; @@ -119,7 +120,7 @@ public class UIConnector extends AbstractComponentContainerConnector implements // this also implicitly removes old styles String styles = ""; styles += getWidget().getStylePrimaryName() + " "; - if (getState().styles != null && !getState().styles.isEmpty()) { + if (ComponentStateUtil.hasStyles(getState())) { for (String style : getState().styles) { styles += style + " "; } diff --git a/client/src/com/vaadin/client/ui/combobox/VFilterSelect.java b/client/src/com/vaadin/client/ui/combobox/VFilterSelect.java index efca4ca083..8692622892 100644 --- a/client/src/com/vaadin/client/ui/combobox/VFilterSelect.java +++ b/client/src/com/vaadin/client/ui/combobox/VFilterSelect.java @@ -72,6 +72,7 @@ import com.vaadin.client.ui.menubar.MenuBar; import com.vaadin.client.ui.menubar.MenuItem; import com.vaadin.shared.ComponentState; import com.vaadin.shared.EventId; +import com.vaadin.shared.ui.ComponentStateUtil; /** * Client side implementation of the Select component. @@ -580,8 +581,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, */ public void updateStyleNames(UIDL uidl, ComponentState componentState) { setStyleName(CLASSNAME + "-suggestpopup"); - if (componentState.styles == null - || componentState.styles.isEmpty()) { + if (ComponentStateUtil.hasStyles(componentState)) { for (String style : componentState.styles) { if (!"".equals(style)) { addStyleDependentName(style); diff --git a/client/src/com/vaadin/client/ui/form/FormConnector.java b/client/src/com/vaadin/client/ui/form/FormConnector.java index 1be137dcaa..25b4a76a09 100644 --- a/client/src/com/vaadin/client/ui/form/FormConnector.java +++ b/client/src/com/vaadin/client/ui/form/FormConnector.java @@ -29,6 +29,7 @@ import com.vaadin.client.ui.ShortcutActionHandler; import com.vaadin.client.ui.layout.ElementResizeEvent; import com.vaadin.client.ui.layout.ElementResizeListener; import com.vaadin.client.ui.layout.MayScrollChildren; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.form.FormState; import com.vaadin.ui.Form; @@ -112,7 +113,7 @@ public class FormConnector extends AbstractComponentContainerConnector getWidget().errorMessage.setVisible(false); } - if (getState().description != null) { + if (ComponentStateUtil.hasDescription(getState())) { getWidget().desc.setInnerHTML(getState().description); if (getWidget().desc.getParentElement() == null) { getWidget().fieldSet.insertAfter(getWidget().desc, diff --git a/client/src/com/vaadin/client/ui/formlayout/VFormLayout.java b/client/src/com/vaadin/client/ui/formlayout/VFormLayout.java index c39b945220..f2f6e0bc72 100644 --- a/client/src/com/vaadin/client/ui/formlayout/VFormLayout.java +++ b/client/src/com/vaadin/client/ui/formlayout/VFormLayout.java @@ -38,6 +38,7 @@ import com.vaadin.client.ui.AbstractFieldConnector; import com.vaadin.client.ui.Icon; import com.vaadin.shared.ComponentConstants; import com.vaadin.shared.ComponentState; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.MarginInfo; /** @@ -66,7 +67,7 @@ public class VFormLayout extends SimplePanel { */ private String[] getStylesFromState(ComponentState state, boolean enabled) { List styles = new ArrayList(); - if (state.styles != null && !state.styles.isEmpty()) { + if (ComponentStateUtil.hasStyles(state)) { for (String name : state.styles) { styles.add(name); } diff --git a/client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java b/client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java index 7dcbbadcd3..fcd1a3bdac 100644 --- a/client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java +++ b/client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java @@ -143,7 +143,7 @@ public class MenuBarConnector extends AbstractComponentConnector implements // this is the top-level style that also propagates to items - // any item specific styles are set above in // currentItem.updateFromUIDL(item, client) - if (getState().styles != null && !getState().styles.isEmpty()) { + if (ComponentStateUtil.hasStyles(getState())) { for (String style : getState().styles) { currentMenu.addStyleDependentName(style); } diff --git a/client/src/com/vaadin/client/ui/panel/PanelConnector.java b/client/src/com/vaadin/client/ui/panel/PanelConnector.java index 35adf95066..35a2681590 100644 --- a/client/src/com/vaadin/client/ui/panel/PanelConnector.java +++ b/client/src/com/vaadin/client/ui/panel/PanelConnector.java @@ -33,6 +33,7 @@ import com.vaadin.client.ui.ShortcutActionHandler; import com.vaadin.client.ui.SimpleManagedLayout; import com.vaadin.client.ui.layout.MayScrollChildren; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.panel.PanelServerRpc; import com.vaadin.shared.ui.panel.PanelState; @@ -116,7 +117,7 @@ public class PanelConnector extends AbstractComponentContainerConnector String captionClass = captionBaseClass; String contentClass = contentBaseClass; String decoClass = decoBaseClass; - if (getState().styles != null && !getState().styles.isEmpty()) { + if (ComponentStateUtil.hasStyles(getState())) { for (String style : getState().styles) { captionClass += " " + captionBaseClass + "-" + style; contentClass += " " + contentBaseClass + "-" + style; diff --git a/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java b/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java index efc6c8c4d7..8def4d244d 100644 --- a/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java +++ b/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java @@ -23,6 +23,7 @@ import com.vaadin.client.VCaption; import com.vaadin.client.VCaptionWrapper; import com.vaadin.client.ui.AbstractComponentContainerConnector; import com.vaadin.client.ui.PostLayoutListener; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.Connect; import com.vaadin.ui.PopupView; @@ -69,7 +70,7 @@ public class PopupViewConnector extends AbstractComponentContainerConnector // showPopupOnTop(popup, hostReference); getWidget().preparePopup(getWidget().popup); getWidget().popup.updateFromUIDL(popupUIDL, client); - if (getState().styles != null && !getState().styles.isEmpty()) { + if (ComponentStateUtil.hasStyles(getState())) { final StringBuffer styleBuf = new StringBuffer(); final String primaryName = getWidget().popup .getStylePrimaryName(); diff --git a/client/src/com/vaadin/client/ui/splitpanel/AbstractSplitPanelConnector.java b/client/src/com/vaadin/client/ui/splitpanel/AbstractSplitPanelConnector.java index a0bfc36298..229d3894cf 100644 --- a/client/src/com/vaadin/client/ui/splitpanel/AbstractSplitPanelConnector.java +++ b/client/src/com/vaadin/client/ui/splitpanel/AbstractSplitPanelConnector.java @@ -37,6 +37,7 @@ import com.vaadin.client.ui.SimpleManagedLayout; import com.vaadin.client.ui.splitpanel.VAbstractSplitPanel.SplitterMoveHandler; import com.vaadin.client.ui.splitpanel.VAbstractSplitPanel.SplitterMoveHandler.SplitterMoveEvent; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelRpc; import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelState; import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelState.SplitterState; @@ -129,7 +130,7 @@ public abstract class AbstractSplitPanelConnector extends clickEventHandler.handleEventHandlerRegistration(); - if (getState().styles != null && !getState().styles.isEmpty()) { + if (ComponentStateUtil.hasStyles(getState())) { getWidget().componentStyleNames = getState().styles; } else { getWidget().componentStyleNames = new LinkedList(); diff --git a/client/src/com/vaadin/client/ui/tabsheet/VTabsheet.java b/client/src/com/vaadin/client/ui/tabsheet/VTabsheet.java index bd77c0d7d9..b2ad68e79b 100644 --- a/client/src/com/vaadin/client/ui/tabsheet/VTabsheet.java +++ b/client/src/com/vaadin/client/ui/tabsheet/VTabsheet.java @@ -58,6 +58,7 @@ import com.vaadin.client.VCaption; import com.vaadin.client.ui.label.VLabel; import com.vaadin.shared.ComponentState; import com.vaadin.shared.EventId; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.tabsheet.TabsheetBaseConstants; import com.vaadin.shared.ui.tabsheet.TabsheetConstants; @@ -739,7 +740,7 @@ public class VTabsheet extends VTabsheetBase implements Focusable, void handleStyleNames(UIDL uidl, ComponentState state) { // Add proper stylenames for all elements (easier to prevent unwanted // style inheritance) - if (state.styles != null && !state.styles.isEmpty()) { + if (ComponentStateUtil.hasStyles(state)) { final List styles = state.styles; if (!currentStyle.equals(styles.toString())) { currentStyle = styles.toString(); diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java index e367d39b07..97883b780f 100644 --- a/server/src/com/vaadin/ui/AbstractComponent.java +++ b/server/src/com/vaadin/ui/AbstractComponent.java @@ -155,7 +155,7 @@ public abstract class AbstractComponent extends AbstractClientConnector @Override public String getStyleName() { String s = ""; - if (getState().styles != null) { + if (ComponentStateUtil.hasStyles(getState())) { for (final Iterator it = getState().styles.iterator(); it .hasNext();) { s += it.next(); @@ -214,7 +214,7 @@ public abstract class AbstractComponent extends AbstractClientConnector @Override public void removeStyleName(String style) { - if (getState().styles != null) { + if (ComponentStateUtil.hasStyles(getState())) { String[] styleParts = style.split(" +"); for (String part : styleParts) { if (part.length() > 0) { diff --git a/shared/src/com/vaadin/shared/ui/ComponentStateUtil.java b/shared/src/com/vaadin/shared/ui/ComponentStateUtil.java index 556c46518f..dd2611f04b 100644 --- a/shared/src/com/vaadin/shared/ui/ComponentStateUtil.java +++ b/shared/src/com/vaadin/shared/ui/ComponentStateUtil.java @@ -18,6 +18,14 @@ public final class ComponentStateUtil { return state.height == null || "".equals(state.height); } + public static final boolean hasDescription(ComponentState state) { + return state.description != null && !"".equals(state.description); + } + + public static final boolean hasStyles(ComponentState state) { + return state.styles != null && !state.styles.isEmpty(); + } + /** * Removes an event listener id. * -- 2.39.5