From 8df52a2848546e4fca474a1afac7b238de13936d Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 30 Jan 2012 08:49:35 +0200 Subject: [PATCH] Split VCheckBox into paintable + widget --- .../terminal/gwt/client/ui/VCheckBox.java | 70 ++------------ .../gwt/client/ui/VCheckBoxPaintable.java | 96 +++++++++++++++++++ 2 files changed, 102 insertions(+), 64 deletions(-) create mode 100644 src/com/vaadin/terminal/gwt/client/ui/VCheckBoxPaintable.java diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java b/src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java index d306bab39e..d92d7e37ed 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java @@ -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(" "); - 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 index 0000000000..03233c6e27 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VCheckBoxPaintable.java @@ -0,0 +1,96 @@ +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.DOM; +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.UIDL; +import com.vaadin.terminal.gwt.client.VTooltip; + +public class VCheckBoxPaintable extends VAbstractPaintableWidget { + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + // Save details + getWidgetForPaintable().client = client; + getWidgetForPaintable().id = uidl.getId(); + + // Ensure correct implementation + if (client.updateComponent(this, uidl, false)) { + return; + } + + getWidgetForPaintable().focusHandlerRegistration = EventHelper + .updateFocusHandler(this, client, + getWidgetForPaintable().focusHandlerRegistration); + getWidgetForPaintable().blurHandlerRegistration = EventHelper + .updateBlurHandler(this, client, + getWidgetForPaintable().blurHandlerRegistration); + + if (uidl.hasAttribute("error")) { + if (getWidgetForPaintable().errorIndicatorElement == null) { + getWidgetForPaintable().errorIndicatorElement = DOM + .createSpan(); + getWidgetForPaintable().errorIndicatorElement + .setInnerHTML(" "); + DOM.setElementProperty( + getWidgetForPaintable().errorIndicatorElement, + "className", "v-errorindicator"); + DOM.appendChild(getWidgetForPaintable().getElement(), + getWidgetForPaintable().errorIndicatorElement); + DOM.sinkEvents(getWidgetForPaintable().errorIndicatorElement, + VTooltip.TOOLTIP_EVENTS | Event.ONCLICK); + } else { + DOM.setStyleAttribute( + getWidgetForPaintable().errorIndicatorElement, + "display", ""); + } + } else if (getWidgetForPaintable().errorIndicatorElement != null) { + DOM.setStyleAttribute( + getWidgetForPaintable().errorIndicatorElement, "display", + "none"); + } + + if (uidl.hasAttribute("readonly")) { + getWidgetForPaintable().setEnabled(false); + } + + if (uidl.hasAttribute("icon")) { + if (getWidgetForPaintable().icon == null) { + getWidgetForPaintable().icon = new Icon(client); + DOM.insertChild(getWidgetForPaintable().getElement(), + getWidgetForPaintable().icon.getElement(), 1); + getWidgetForPaintable().icon + .sinkEvents(VTooltip.TOOLTIP_EVENTS); + getWidgetForPaintable().icon.sinkEvents(Event.ONCLICK); + } + getWidgetForPaintable().icon + .setUri(uidl.getStringAttribute("icon")); + } else if (getWidgetForPaintable().icon != null) { + // detach icon + DOM.removeChild(getWidgetForPaintable().getElement(), + getWidgetForPaintable().icon.getElement()); + getWidgetForPaintable().icon = null; + } + + // Set text + getWidgetForPaintable().setText(uidl.getStringAttribute("caption")); + getWidgetForPaintable() + .setValue( + uidl.getBooleanVariable(getWidgetForPaintable().VARIABLE_STATE)); + getWidgetForPaintable().immediate = uidl + .getBooleanAttribute("immediate"); + } + + @Override + public VCheckBox getWidgetForPaintable() { + return (VCheckBox) super.getWidgetForPaintable(); + } + + @Override + protected Widget createWidget() { + return GWT.create(VCheckBox.class); + } + +} -- 2.39.5