]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add helper methods for checking state
authorJohn Ahlroos <john@vaadin.com>
Fri, 31 Aug 2012 13:13:40 +0000 (16:13 +0300)
committerJohn Ahlroos <john@vaadin.com>
Fri, 31 Aug 2012 13:13:40 +0000 (16:13 +0300)
14 files changed:
client/src/com/vaadin/client/LayoutManager.java
client/src/com/vaadin/client/VCaption.java
client/src/com/vaadin/client/ui/AbstractComponentConnector.java
client/src/com/vaadin/client/ui/UI/UIConnector.java
client/src/com/vaadin/client/ui/combobox/VFilterSelect.java
client/src/com/vaadin/client/ui/form/FormConnector.java
client/src/com/vaadin/client/ui/formlayout/VFormLayout.java
client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java
client/src/com/vaadin/client/ui/panel/PanelConnector.java
client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java
client/src/com/vaadin/client/ui/splitpanel/AbstractSplitPanelConnector.java
client/src/com/vaadin/client/ui/tabsheet/VTabsheet.java
server/src/com/vaadin/ui/AbstractComponent.java
shared/src/com/vaadin/shared/ui/ComponentStateUtil.java

index a0d87615818eae3e2317580b7fe7a06c8092b16b..7b6fe19a378b2ef77c5e81b8a249339eaca220ab 100644 (file)
@@ -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);
index a3d3a7034ec10a3b36b84a1abff72fd114412104..aadc7b88ad5b8b1e8cb30dc4eada23297fad916f 100644 (file)
@@ -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");
index 8ac113e72ecc04f79023bd8d8f726867fa0709ef..d5e8dc0ba0e48b4c562df3be4b913a354e742d7f 100644 (file)
@@ -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<String> newStyles = new ArrayList<String>();
             newStyles.addAll(state.styles);
index b22e9af09b78d2773a13fae27e48213873b6eb6c..cb8b0ece9ea85bd8ef48ef04981753eb3d4e5424 100644 (file)
@@ -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 + " ";
             }
index efca4ca083fb99c265a772ea4ab8be4c633abf66..86926228929e9973a09c23c4d6628acdb5b1d0d5 100644 (file)
@@ -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);
index 1be137dcaa86e4d8b8db0b25d802c834a61b0cfe..25b4a76a0914eb8309c1c7315ded1d8881e3b983 100644 (file)
@@ -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,
index c39b945220b3778ea50b55fd7c2e20da22907736..f2f6e0bc726c4de4f4e88a52e46656793afa5b60 100644 (file)
@@ -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<String> styles = new ArrayList<String>();
-        if (state.styles != null && !state.styles.isEmpty()) {
+        if (ComponentStateUtil.hasStyles(state)) {
             for (String name : state.styles) {
                 styles.add(name);
             }
index 7dcbbadcd394945e34fec500b76b078f541c1eaf..fcd1a3bdacdea2c2e6c11bace4094b1876ef22b5 100644 (file)
@@ -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);
                     }
index 35adf950662930c373ad89fa8ce45bdc68b06e6a..35a26815908fca8535c1f46e10bcde15d92a9435 100644 (file)
@@ -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;
index efc6c8c4d7b722130f3d2173f6e5d199a5a57121..8def4d244d2fdaeb0c4810366670eb3784032650 100644 (file)
@@ -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();
index a0bfc362989f76a803af5819829557226ae87a73..229d3894cfea30939a8b2fcc36fb960a9b260074 100644 (file)
@@ -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<String>();
index bd77c0d7d97ec7ec176963643f8b20842e04210a..b2ad68e79b858ecdc11d971dffbbd5487770f0e1 100644 (file)
@@ -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<String> styles = state.styles;
             if (!currentStyle.equals(styles.toString())) {
                 currentStyle = styles.toString();
index e367d39b0742deb9be44ee12e7d986be9ce93456..97883b780ffecf89cf8654505dc7fd72a9c22e69 100644 (file)
@@ -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<String> 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) {
index 556c46518f74f90df04adfc4d648b83281f8171d..dd2611f04b6c3d35ca665470caf7bf7ceccc6c52 100644 (file)
@@ -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.
      *