]> source.dussan.org Git - vaadin-framework.git/commitdiff
Transfer read-only and immediate flags via shared state (#8304).
authorHenri Sara <hesara@vaadin.com>
Wed, 22 Feb 2012 13:00:37 +0000 (15:00 +0200)
committerHenri Sara <hesara@vaadin.com>
Wed, 22 Feb 2012 13:00:37 +0000 (15:00 +0200)
19 files changed:
src/com/vaadin/terminal/gwt/client/ComponentState.java
src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java
src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VCheckBoxPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VDateFieldPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VFilterSelectPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VLinkPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VOptionGroupBasePaintable.java
src/com/vaadin/terminal/gwt/client/ui/VPopupCalendarPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java
src/com/vaadin/terminal/gwt/client/ui/VScrollTablePaintable.java
src/com/vaadin/terminal/gwt/client/ui/VSliderPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VTextFieldPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VTreePaintable.java
src/com/vaadin/terminal/gwt/client/ui/VUploadPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VViewPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java
src/com/vaadin/terminal/gwt/client/ui/richtextarea/VRichTextAreaPaintable.java
src/com/vaadin/ui/AbstractComponent.java

index 2df7f20dee492ebf4ef09492c02957453ba8f1ce..ac478cd1d3e79f20c01877cf34731a9d10d77f25 100644 (file)
@@ -16,6 +16,8 @@ import com.vaadin.terminal.gwt.client.communication.SharedState;
 public class ComponentState extends SharedState {
     private String height = "";
     private String width = "";
+    private boolean readOnly = false;
+    private boolean immediate = false;
 
     /**
      * Returns the component height as set by the server.
@@ -93,7 +95,22 @@ public class ComponentState extends SharedState {
         return "".equals(getWidth());
     }
 
-    // TODO more fields to move here: style, readonly, immediate, disabled,
-    // caption and description
+    public boolean isReadOnly() {
+        return readOnly;
+    }
+
+    public void setReadOnly(boolean readOnly) {
+        this.readOnly = readOnly;
+    }
+
+    public boolean isImmediate() {
+        return immediate;
+    }
+
+    public void setImmediate(boolean immediate) {
+        this.immediate = immediate;
+    }
+
+    // TODO more fields to move here: style, disabled, caption and description
 
 }
index 5564c6984ea6320bfb91231ccd16929665855c0a..d6404b03fc323653f65f778ba7536ff1730d306f 100644 (file)
@@ -32,8 +32,6 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget {
     public static final String ATTRIBUTE_REQUIRED = "required";
     public static final String ATTRIBUTE_ERROR = "error";
     public static final String ATTRIBUTE_HIDEERRORS = "hideErrors";
-    public static final String ATTRIBUTE_READONLY = "readonly";
-    public static final String ATTRIBUTE_IMMEDIATE = "immediate";
     public static final String ATTRIBUTE_DISABLED = "disabled";
     public static final String ATTRIBUTE_STYLE = "style";
 
@@ -211,7 +209,7 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget {
 
         // Style names
         String styleName = getStyleNameFromUIDL(getWidgetForPaintable()
-                .getStylePrimaryName(), uidl,
+                .getStylePrimaryName(), uidl, getState(),
                 getWidgetForPaintable() instanceof Field);
         getWidgetForPaintable().setStyleName(styleName);
 
@@ -308,17 +306,19 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget {
 
     /**
      * Generates the style name for the widget based on the given primary style
-     * name (typically returned by Widget.getPrimaryStyleName()) and the UIDL.
-     * An additional "modified" style name can be added if the field parameter
-     * is set to true.
+     * name (typically returned by Widget.getPrimaryStyleName()) and the UIDL
+     * and shared state of the component. An additional "modified" style name
+     * can be added if the field parameter is set to true.
      * 
      * @param primaryStyleName
      * @param uidl
-     * @param isField
+     * @param state
+     *            component shared state
+     * @param field
      * @return
      */
     protected static String getStyleNameFromUIDL(String primaryStyleName,
-            UIDL uidl, boolean field) {
+            UIDL uidl, ComponentState state, boolean field) {
         boolean enabled = !uidl.getBooleanAttribute(ATTRIBUTE_DISABLED);
 
         StringBuffer styleBuf = new StringBuffer();
@@ -329,7 +329,7 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget {
             styleBuf.append(" ");
             styleBuf.append(ApplicationConnection.DISABLED_CLASSNAME);
         }
-        if (uidl.getBooleanAttribute(ATTRIBUTE_READONLY)) {
+        if (state.isReadOnly()) {
             styleBuf.append(" ");
             styleBuf.append("v-readonly");
         }
index 8d4a6954a16f6fc55fa7ed803cd71ad12478988a..1e8349b4ad0118e1b228fe2da4c3268fad6f2447 100644 (file)
@@ -70,8 +70,7 @@ public abstract class VAbstractSplitPanelPaintable extends
         getWidgetForPaintable().id = uidl.getId();
         getWidgetForPaintable().rendering = true;
 
-        getWidgetForPaintable().immediate = uidl
-                .hasAttribute(ATTRIBUTE_IMMEDIATE);
+        getWidgetForPaintable().immediate = getState().isImmediate();
 
         super.updateFromUIDL(uidl, client);
         if (!isRealUpdate(uidl)) {
index daacbe03e5de1f36bd80890bddbd6c84550c6da1..9624ddd4e632533795943e15a082eda10a19fb43 100644 (file)
@@ -62,7 +62,7 @@ public class VCheckBoxPaintable extends VAbstractPaintableWidget {
                     "none");
         }
 
-        if (uidl.hasAttribute(ATTRIBUTE_READONLY)) {
+        if (getState().isReadOnly()) {
             getWidgetForPaintable().setEnabled(false);
         }
 
@@ -90,8 +90,7 @@ public class VCheckBoxPaintable extends VAbstractPaintableWidget {
         getWidgetForPaintable()
                 .setValue(
                         uidl.getBooleanVariable(getWidgetForPaintable().VARIABLE_STATE));
-        getWidgetForPaintable().immediate = uidl
-                .getBooleanAttribute(VAbstractPaintableWidget.ATTRIBUTE_IMMEDIATE);
+        getWidgetForPaintable().immediate = getState().isImmediate();
     }
 
     @Override
index 0798cd1e60150aec8b6ea512b42eb9e0c355c980..ac33712c6e6e514d432bbe1beca721b9e894ad8a 100644 (file)
@@ -25,11 +25,9 @@ public class VDateFieldPaintable extends VAbstractPaintableWidget {
         // Save details
         getWidgetForPaintable().client = client;
         getWidgetForPaintable().paintableId = uidl.getId();
-        getWidgetForPaintable().immediate = uidl
-                .getBooleanAttribute(ATTRIBUTE_IMMEDIATE);
+        getWidgetForPaintable().immediate = getState().isImmediate();
 
-        getWidgetForPaintable().readonly = uidl
-                .getBooleanAttribute(ATTRIBUTE_READONLY);
+        getWidgetForPaintable().readonly = getState().isReadOnly();
         getWidgetForPaintable().enabled = !uidl
                 .getBooleanAttribute(ATTRIBUTE_DISABLED);
 
index cd1c4e122dbf5b199757ce1cd9a0f1217903f19c..581baad8f9cf427258f754e274e8eaea0b6bd103 100644 (file)
@@ -28,8 +28,7 @@ public class VFilterSelectPaintable extends VAbstractPaintableWidget {
         getWidgetForPaintable().client = client;
         getWidgetForPaintable().paintableId = uidl.getId();
 
-        getWidgetForPaintable().readonly = uidl
-                .hasAttribute(ATTRIBUTE_READONLY);
+        getWidgetForPaintable().readonly = getState().isReadOnly();
         getWidgetForPaintable().enabled = !uidl
                 .hasAttribute(ATTRIBUTE_DISABLED);
 
@@ -59,8 +58,7 @@ public class VFilterSelectPaintable extends VAbstractPaintableWidget {
                     .getIntAttribute("filteringmode");
         }
 
-        getWidgetForPaintable().immediate = uidl
-                .hasAttribute(ATTRIBUTE_IMMEDIATE);
+        getWidgetForPaintable().immediate = getState().isImmediate();
 
         getWidgetForPaintable().nullSelectionAllowed = uidl
                 .hasAttribute("nullselect");
index 432365eaa7e7ca122bbbe81b9534bbb1a750eb68..938e20fb91e7956c63da938f3c3c726c61a9c1c3 100644 (file)
@@ -31,8 +31,7 @@ public class VLinkPaintable extends VAbstractPaintableWidget {
 
         getWidgetForPaintable().enabled = uidl.hasAttribute(ATTRIBUTE_DISABLED) ? false
                 : true;
-        getWidgetForPaintable().readonly = uidl
-                .hasAttribute(ATTRIBUTE_READONLY) ? true : false;
+        getWidgetForPaintable().readonly = getState().isReadOnly();
 
         if (uidl.hasAttribute("name")) {
             getWidgetForPaintable().target = uidl.getStringAttribute("name");
index 2fc538d114c995c2c7ec2266d3772f0f8722d4fe..6b11c8ffe928f2a8c0c7edf8632262f689e8c212 100644 (file)
@@ -25,14 +25,12 @@ public abstract class VOptionGroupBasePaintable extends
         getWidgetForPaintable().selectedKeys = uidl
                 .getStringArrayVariableAsSet("selected");
 
-        getWidgetForPaintable().readonly = uidl
-                .getBooleanAttribute(ATTRIBUTE_READONLY);
+        getWidgetForPaintable().readonly = getState().isReadOnly();
         getWidgetForPaintable().disabled = uidl
                 .getBooleanAttribute(ATTRIBUTE_DISABLED);
         getWidgetForPaintable().multiselect = "multi".equals(uidl
                 .getStringAttribute("selectmode"));
-        getWidgetForPaintable().immediate = uidl
-                .getBooleanAttribute(ATTRIBUTE_IMMEDIATE);
+        getWidgetForPaintable().immediate = getState().isImmediate();
         getWidgetForPaintable().nullSelectionAllowed = uidl
                 .getBooleanAttribute("nullselect");
         getWidgetForPaintable().nullSelectionItemAvailable = uidl
index 042d7307389e7e133143e64bcdf8e38191b7bfa6..3bf7f844e862b5d8dac890d42ed471943eb37719 100644 (file)
@@ -35,7 +35,8 @@ public class VPopupCalendarPaintable extends VTextualDatePaintable {
         super.updateFromUIDL(uidl, client);
 
         String popupStyleNames = getStyleNameFromUIDL(
-                VPopupCalendar.POPUP_PRIMARY_STYLE_NAME, uidl, false);
+                VPopupCalendar.POPUP_PRIMARY_STYLE_NAME, uidl, getState(),
+                false);
         popupStyleNames += " "
                 + VDateField.CLASSNAME
                 + "-"
index 17d02d5374454c049fd51b119e3ad7041a23aa43..44fea19f76d67595b37fa397db66faf45fcd5cf5 100644 (file)
@@ -59,6 +59,7 @@ import com.google.gwt.user.client.ui.UIObject;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.BrowserInfo;
+import com.vaadin.terminal.gwt.client.ComponentState;
 import com.vaadin.terminal.gwt.client.Container;
 import com.vaadin.terminal.gwt.client.Focusable;
 import com.vaadin.terminal.gwt.client.MouseEventDetails;
@@ -971,7 +972,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
         }
     }
 
-    void updateSelectionProperties(UIDL uidl) {
+    void updateSelectionProperties(UIDL uidl, ComponentState state) {
         setMultiSelectMode(uidl.hasAttribute("multiselectmode") ? uidl
                 .getIntAttribute("multiselectmode") : MULTISELECT_MODE_DEFAULT);
 
@@ -979,7 +980,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
                 .getBooleanAttribute("nsa") : true;
 
         if (uidl.hasAttribute("selectmode")) {
-            if (uidl.getBooleanAttribute(VAbstractPaintableWidget.ATTRIBUTE_READONLY)) {
+            if (state.isReadOnly()) {
                 selectMode = SelectMode.NONE;
             } else if (uidl.getStringAttribute("selectmode").equals("multi")) {
                 selectMode = SelectMode.MULTI;
index a95ac5ef79f4b1b92dc847e949ba80d0769e6dec..7bd2fae3374fa36516d8ca54c7e88b8712388f0d 100644 (file)
@@ -72,8 +72,7 @@ public class VScrollTablePaintable extends VAbstractPaintableWidgetContainer {
 
         getWidgetForPaintable().client = client;
         getWidgetForPaintable().paintableId = uidl.getStringAttribute("id");
-        getWidgetForPaintable().immediate = uidl
-                .getBooleanAttribute(ATTRIBUTE_IMMEDIATE);
+        getWidgetForPaintable().immediate = getState().isImmediate();
 
         int previousTotalRows = getWidgetForPaintable().totalRows;
         getWidgetForPaintable().updateTotalRows(uidl);
@@ -81,7 +80,7 @@ public class VScrollTablePaintable extends VAbstractPaintableWidgetContainer {
 
         getWidgetForPaintable().updateDragMode(uidl);
 
-        getWidgetForPaintable().updateSelectionProperties(uidl);
+        getWidgetForPaintable().updateSelectionProperties(uidl, getState());
 
         if (uidl.hasAttribute("alb")) {
             getWidgetForPaintable().bodyActionKeys = uidl
index 2c25c6b16e22f7a30043188283ccffaed666d3a0..e119bfec5c2f169c174aae7b40d95b8d5ecff56d 100644 (file)
@@ -24,15 +24,14 @@ public class VSliderPaintable extends VAbstractPaintableWidget {
             return;
         }
 
-        getWidgetForPaintable().immediate = uidl
-                .getBooleanAttribute(ATTRIBUTE_IMMEDIATE);
+        getWidgetForPaintable().immediate = getState().isImmediate();
         getWidgetForPaintable().disabled = uidl
                 .getBooleanAttribute(ATTRIBUTE_DISABLED);
-        getWidgetForPaintable().readonly = uidl
-                .getBooleanAttribute(ATTRIBUTE_READONLY);
+        getWidgetForPaintable().readonly = getState().isReadOnly();
 
         getWidgetForPaintable().vertical = uidl.hasAttribute("vertical");
 
+        // TODO should these style names be used?
         String style = "";
         if (uidl.hasAttribute(ATTRIBUTE_STYLE)) {
             style = uidl.getStringAttribute(ATTRIBUTE_STYLE);
index 5736e775650167300e18df81b41c15a73adc0341..5714d6f8d19350e46b39abbd655afafd5a4c0b67 100644 (file)
@@ -27,11 +27,7 @@ public class VTextFieldPaintable extends VAbstractPaintableWidget implements
             return;
         }
 
-        if (uidl.getBooleanAttribute(ATTRIBUTE_READONLY)) {
-            getWidgetForPaintable().setReadOnly(true);
-        } else {
-            getWidgetForPaintable().setReadOnly(false);
-        }
+        getWidgetForPaintable().setReadOnly(getState().isReadOnly());
 
         getWidgetForPaintable().inputPrompt = uidl
                 .getStringAttribute(VTextField.ATTR_INPUTPROMPT);
@@ -40,8 +36,7 @@ public class VTextFieldPaintable extends VAbstractPaintableWidget implements
                 uidl.hasAttribute("maxLength") ? uidl
                         .getIntAttribute("maxLength") : -1);
 
-        getWidgetForPaintable().immediate = uidl
-                .getBooleanAttribute(ATTRIBUTE_IMMEDIATE);
+        getWidgetForPaintable().immediate = getState().isImmediate();
 
         getWidgetForPaintable().listenTextChangeEvents = client
                 .hasEventListeners(this, "ie");
index acb8f8b467d8d0fa193433da2ad0bc346f2f52fb..7ee67df69c484c7232a9a9949069f6b31457c0de 100644 (file)
@@ -41,13 +41,11 @@ public class VTreePaintable extends VAbstractPaintableWidget {
 
         getWidgetForPaintable().paintableId = uidl.getId();
 
-        getWidgetForPaintable().immediate = uidl
-                .hasAttribute(ATTRIBUTE_IMMEDIATE);
+        getWidgetForPaintable().immediate = getState().isImmediate();
 
         getWidgetForPaintable().disabled = uidl
                 .getBooleanAttribute(ATTRIBUTE_DISABLED);
-        getWidgetForPaintable().readonly = uidl
-                .getBooleanAttribute(ATTRIBUTE_READONLY);
+        getWidgetForPaintable().readonly = getState().isReadOnly();
 
         getWidgetForPaintable().dragMode = uidl.hasAttribute("dragMode") ? uidl
                 .getIntAttribute("dragMode") : 0;
index cabf17be73b4f2dafcb2aa4160ef095f19b96eb3..ca622c35c6fc3d4566807ae34f0bb668e1111198 100644 (file)
@@ -25,8 +25,7 @@ public class VUploadPaintable extends VAbstractPaintableWidget {
             getWidgetForPaintable().submit();
             return;
         }
-        getWidgetForPaintable().setImmediate(
-                uidl.getBooleanAttribute(ATTRIBUTE_IMMEDIATE));
+        getWidgetForPaintable().setImmediate(getState().isImmediate());
         getWidgetForPaintable().client = client;
         getWidgetForPaintable().paintableId = uidl.getId();
         getWidgetForPaintable().nextUploadId = uidl.getIntAttribute("nextid");
@@ -43,8 +42,7 @@ public class VUploadPaintable extends VAbstractPaintableWidget {
         getWidgetForPaintable().fu.setName(getWidgetForPaintable().paintableId
                 + "_file");
 
-        if (uidl.hasAttribute(ATTRIBUTE_DISABLED)
-                || uidl.hasAttribute(ATTRIBUTE_READONLY)) {
+        if (uidl.hasAttribute(ATTRIBUTE_DISABLED) || getState().isReadOnly()) {
             getWidgetForPaintable().disableUpload();
         } else if (!uidl.getBooleanAttribute("state")) {
             // Enable the button only if an upload is not in progress
index ea4a4dee7bc8c606a3e118fee9cee767adb756bf..65c7bd2635ca5c7562b808d5fe85aa719f5683ff 100644 (file)
@@ -41,8 +41,7 @@ public class VViewPaintable extends VAbstractPaintableWidgetContainer {
         boolean firstPaint = getWidgetForPaintable().connection == null;
         getWidgetForPaintable().connection = client;
 
-        getWidgetForPaintable().immediate = uidl
-                .hasAttribute(ATTRIBUTE_IMMEDIATE);
+        getWidgetForPaintable().immediate = getState().isImmediate();
         getWidgetForPaintable().resizeLazy = uidl
                 .hasAttribute(VView.RESIZE_LAZY);
         String newTheme = uidl.getStringAttribute("theme");
index b018554e0cf29b79857f8ea9ddb4eaecd74c8f9c..3e060996bfdcde6cefcb8328fd6c915b2a14e826 100644 (file)
@@ -90,11 +90,9 @@ public class VWindowPaintable extends VAbstractPaintableWidgetContainer
 
         clickEventHandler.handleEventHandlerRegistration(client);
 
-        getWidgetForPaintable().immediate = uidl
-                .hasAttribute(ATTRIBUTE_IMMEDIATE);
+        getWidgetForPaintable().immediate = getState().isImmediate();
 
-        getWidgetForPaintable().setClosable(
-                !uidl.getBooleanAttribute(ATTRIBUTE_READONLY));
+        getWidgetForPaintable().setClosable(!getState().isReadOnly());
 
         // Initialize the position form UIDL
         int positionx = uidl.getIntVariable("positionx");
index 9fa6aeeda0468a1c64daa39bde3125dcf2f43ea0..4a88fba9c18fa616c60cf51323ca56bee3f16613 100644 (file)
@@ -40,10 +40,8 @@ public class VRichTextAreaPaintable extends VAbstractPaintableWidget implements
             return;
         }
 
-        getWidgetForPaintable().setReadOnly(
-                uidl.getBooleanAttribute(ATTRIBUTE_READONLY));
-        getWidgetForPaintable().immediate = uidl
-                .getBooleanAttribute(ATTRIBUTE_IMMEDIATE);
+        getWidgetForPaintable().setReadOnly(getState().isReadOnly());
+        getWidgetForPaintable().immediate = getState().isImmediate();
         int newMaxLength = uidl.hasAttribute("maxLength") ? uidl
                 .getIntAttribute("maxLength") : -1;
         if (newMaxLength >= 0) {
index 2a0370e24fd71e176fba07ccd3aacd91086bfeee..0a2914b8aa3b5c175cd684c095a2e6807d2b0312 100644 (file)
@@ -776,15 +776,6 @@ public abstract class AbstractComponent implements Component, MethodEventSource
                             VAbstractPaintableWidget.ATTRIBUTE_STYLE,
                             getStyle());
                 }
-                if (isReadOnly()) {
-                    target.addAttribute(
-                            VAbstractPaintableWidget.ATTRIBUTE_READONLY, true);
-                }
-
-                if (isImmediate()) {
-                    target.addAttribute(
-                            VAbstractPaintableWidget.ATTRIBUTE_IMMEDIATE, true);
-                }
                 if (!isEnabled()) {
                     target.addAttribute(
                             VAbstractPaintableWidget.ATTRIBUTE_DISABLED, true);
@@ -903,6 +894,9 @@ public abstract class AbstractComponent implements Component, MethodEventSource
             sharedState.setWidth("" + getCSSWidth());
         }
 
+        sharedState.setImmediate(isImmediate());
+        sharedState.setReadOnly(isReadOnly());
+
         // if (getCaption() != null) {
         // state.put(ComponentState.STATE_CAPTION, getCaption());
         // }
@@ -912,13 +906,6 @@ public abstract class AbstractComponent implements Component, MethodEventSource
         // if (styles != null && styles.size() > 0) {
         // state.put(ComponentState.STATE_STYLE, getStyle());
         // }
-        // if (isReadOnly()) {
-        // state.put(ComponentState.STATE_READONLY, true);
-        // }
-        //
-        // if (isImmediate()) {
-        // state.put(ComponentState.STATE_IMMEDIATE, true);
-        // }
         // if (!isEnabled()) {
         // state.put(ComponentState.STATE_DISABLED, true);
         // }