]> source.dussan.org Git - vaadin-framework.git/commitdiff
Split VCheckBox into paintable + widget
authorArtur Signell <artur@vaadin.com>
Mon, 30 Jan 2012 06:49:35 +0000 (08:49 +0200)
committerArtur Signell <artur@vaadin.com>
Mon, 30 Jan 2012 06:49:35 +0000 (08:49 +0200)
src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java
src/com/vaadin/terminal/gwt/client/ui/VCheckBoxPaintable.java [new file with mode: 0644]

index d306bab39efcb3e852624f14055aea97eb916e9a..d92d7e37edf090e9cab41800b942838f0f824af5 100644 (file)
@@ -16,16 +16,13 @@ import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.EventHelper;
 import com.vaadin.terminal.gwt.client.EventId;
 import com.vaadin.terminal.gwt.client.MouseEventDetails;
-import com.vaadin.terminal.gwt.client.VPaintableWidget;
-import com.vaadin.terminal.gwt.client.UIDL;
 import com.vaadin.terminal.gwt.client.Util;
 import com.vaadin.terminal.gwt.client.VTooltip;
 
 public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements
-        VPaintableWidget, Field, FocusHandler, BlurHandler {
+        Field, FocusHandler, BlurHandler {
 
     public static final String VARIABLE_STATE = "state";
 
@@ -37,12 +34,12 @@ public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements
 
     ApplicationConnection client;
 
-    private Element errorIndicatorElement;
+    Element errorIndicatorElement;
 
-    private Icon icon;
+    Icon icon;
 
-    private HandlerRegistration focusHandlerRegistration;
-    private HandlerRegistration blurHandlerRegistration;
+    HandlerRegistration focusHandlerRegistration;
+    HandlerRegistration blurHandlerRegistration;
 
     public VCheckBox() {
         setStyleName(CLASSNAME);
@@ -71,61 +68,6 @@ public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements
         }
     }
 
-    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-        // Save details
-        this.client = client;
-        id = uidl.getId();
-
-        // Ensure correct implementation
-        if (client.updateComponent(this, uidl, false)) {
-            return;
-        }
-
-        focusHandlerRegistration = EventHelper.updateFocusHandler(this, client,
-                focusHandlerRegistration);
-        blurHandlerRegistration = EventHelper.updateBlurHandler(this, client,
-                blurHandlerRegistration);
-
-        if (uidl.hasAttribute("error")) {
-            if (errorIndicatorElement == null) {
-                errorIndicatorElement = DOM.createSpan();
-                errorIndicatorElement.setInnerHTML("&nbsp;");
-                DOM.setElementProperty(errorIndicatorElement, "className",
-                        "v-errorindicator");
-                DOM.appendChild(getElement(), errorIndicatorElement);
-                DOM.sinkEvents(errorIndicatorElement, VTooltip.TOOLTIP_EVENTS
-                        | Event.ONCLICK);
-            } else {
-                DOM.setStyleAttribute(errorIndicatorElement, "display", "");
-            }
-        } else if (errorIndicatorElement != null) {
-            DOM.setStyleAttribute(errorIndicatorElement, "display", "none");
-        }
-
-        if (uidl.hasAttribute("readonly")) {
-            setEnabled(false);
-        }
-
-        if (uidl.hasAttribute("icon")) {
-            if (icon == null) {
-                icon = new Icon(client);
-                DOM.insertChild(getElement(), icon.getElement(), 1);
-                icon.sinkEvents(VTooltip.TOOLTIP_EVENTS);
-                icon.sinkEvents(Event.ONCLICK);
-            }
-            icon.setUri(uidl.getStringAttribute("icon"));
-        } else if (icon != null) {
-            // detach icon
-            DOM.removeChild(getElement(), icon.getElement());
-            icon = null;
-        }
-
-        // Set text
-        setText(uidl.getStringAttribute("caption"));
-        setValue(uidl.getBooleanVariable(VARIABLE_STATE));
-        immediate = uidl.getBooleanAttribute("immediate");
-    }
-
     @Override
     public void onBrowserEvent(Event event) {
         if (icon != null && (event.getTypeInt() == Event.ONCLICK)
@@ -137,7 +79,7 @@ public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements
             Util.notifyParentOfSizeChange(this, true);
         }
         if (client != null) {
-            client.handleTooltipEvent(event, this);
+            client.handleWidgetTooltipEvent(event, this);
         }
     }
 
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCheckBoxPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VCheckBoxPaintable.java
new file mode 100644 (file)
index 0000000..03233c6
--- /dev/null
@@ -0,0 +1,96 @@
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.user.client.DOM;\r
+import com.google.gwt.user.client.Event;\r
+import com.google.gwt.user.client.ui.Widget;\r
+import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.EventHelper;\r
+import com.vaadin.terminal.gwt.client.UIDL;\r
+import com.vaadin.terminal.gwt.client.VTooltip;\r
+\r
+public class VCheckBoxPaintable extends VAbstractPaintableWidget {\r
+\r
+    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+        // Save details\r
+        getWidgetForPaintable().client = client;\r
+        getWidgetForPaintable().id = uidl.getId();\r
+\r
+        // Ensure correct implementation\r
+        if (client.updateComponent(this, uidl, false)) {\r
+            return;\r
+        }\r
+\r
+        getWidgetForPaintable().focusHandlerRegistration = EventHelper\r
+                .updateFocusHandler(this, client,\r
+                        getWidgetForPaintable().focusHandlerRegistration);\r
+        getWidgetForPaintable().blurHandlerRegistration = EventHelper\r
+                .updateBlurHandler(this, client,\r
+                        getWidgetForPaintable().blurHandlerRegistration);\r
+\r
+        if (uidl.hasAttribute("error")) {\r
+            if (getWidgetForPaintable().errorIndicatorElement == null) {\r
+                getWidgetForPaintable().errorIndicatorElement = DOM\r
+                        .createSpan();\r
+                getWidgetForPaintable().errorIndicatorElement\r
+                        .setInnerHTML("&nbsp;");\r
+                DOM.setElementProperty(\r
+                        getWidgetForPaintable().errorIndicatorElement,\r
+                        "className", "v-errorindicator");\r
+                DOM.appendChild(getWidgetForPaintable().getElement(),\r
+                        getWidgetForPaintable().errorIndicatorElement);\r
+                DOM.sinkEvents(getWidgetForPaintable().errorIndicatorElement,\r
+                        VTooltip.TOOLTIP_EVENTS | Event.ONCLICK);\r
+            } else {\r
+                DOM.setStyleAttribute(\r
+                        getWidgetForPaintable().errorIndicatorElement,\r
+                        "display", "");\r
+            }\r
+        } else if (getWidgetForPaintable().errorIndicatorElement != null) {\r
+            DOM.setStyleAttribute(\r
+                    getWidgetForPaintable().errorIndicatorElement, "display",\r
+                    "none");\r
+        }\r
+\r
+        if (uidl.hasAttribute("readonly")) {\r
+            getWidgetForPaintable().setEnabled(false);\r
+        }\r
+\r
+        if (uidl.hasAttribute("icon")) {\r
+            if (getWidgetForPaintable().icon == null) {\r
+                getWidgetForPaintable().icon = new Icon(client);\r
+                DOM.insertChild(getWidgetForPaintable().getElement(),\r
+                        getWidgetForPaintable().icon.getElement(), 1);\r
+                getWidgetForPaintable().icon\r
+                        .sinkEvents(VTooltip.TOOLTIP_EVENTS);\r
+                getWidgetForPaintable().icon.sinkEvents(Event.ONCLICK);\r
+            }\r
+            getWidgetForPaintable().icon\r
+                    .setUri(uidl.getStringAttribute("icon"));\r
+        } else if (getWidgetForPaintable().icon != null) {\r
+            // detach icon\r
+            DOM.removeChild(getWidgetForPaintable().getElement(),\r
+                    getWidgetForPaintable().icon.getElement());\r
+            getWidgetForPaintable().icon = null;\r
+        }\r
+\r
+        // Set text\r
+        getWidgetForPaintable().setText(uidl.getStringAttribute("caption"));\r
+        getWidgetForPaintable()\r
+                .setValue(\r
+                        uidl.getBooleanVariable(getWidgetForPaintable().VARIABLE_STATE));\r
+        getWidgetForPaintable().immediate = uidl\r
+                .getBooleanAttribute("immediate");\r
+    }\r
+\r
+    @Override\r
+    public VCheckBox getWidgetForPaintable() {\r
+        return (VCheckBox) super.getWidgetForPaintable();\r
+    }\r
+\r
+    @Override\r
+    protected Widget createWidget() {\r
+        return GWT.create(VCheckBox.class);\r
+    }\r
+\r
+}\r