]> source.dussan.org Git - vaadin-framework.git/commitdiff
Button, NativeButton and CheckBox are no longer Vaadin6Components
authorArtur Signell <artur@vaadin.com>
Wed, 11 Apr 2012 14:32:47 +0000 (17:32 +0300)
committerArtur Signell <artur@vaadin.com>
Thu, 12 Apr 2012 06:58:13 +0000 (09:58 +0300)
Added FocusAndBlurServerRpc for sending focus and blur events to any
component.

src/com/vaadin/event/FieldEvents.java
src/com/vaadin/terminal/gwt/client/EventHelper.java
src/com/vaadin/terminal/gwt/client/ui/ButtonConnector.java
src/com/vaadin/terminal/gwt/client/ui/CheckBoxConnector.java
src/com/vaadin/terminal/gwt/client/ui/NativeButtonConnector.java
src/com/vaadin/terminal/gwt/client/ui/VButton.java
src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java
src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java
src/com/vaadin/ui/AbstractComponent.java
src/com/vaadin/ui/Button.java
src/com/vaadin/ui/CheckBox.java

index 28fd6bb4f759d95677ed788a707fc137d321c7dc..20e9fabb3683f4c3f7d98322161de2c449832f2a 100644 (file)
@@ -8,8 +8,10 @@ import java.io.Serializable;
 import java.lang.reflect.Method;
 
 import com.vaadin.terminal.gwt.client.EventId;
+import com.vaadin.terminal.gwt.client.communication.FieldRpc.FocusAndBlurServerRpc;
 import com.vaadin.tools.ReflectTools;
 import com.vaadin.ui.Component;
+import com.vaadin.ui.Component.Event;
 import com.vaadin.ui.Field;
 import com.vaadin.ui.Field.ValueChangeEvent;
 import com.vaadin.ui.TextField;
@@ -247,4 +249,25 @@ public interface FieldEvents {
 
         public void removeListener(TextChangeListener listener);
     }
+
+    public static abstract class FocusAndBlurServerRpcImpl implements
+            FocusAndBlurServerRpc {
+
+        private Component component;
+
+        public FocusAndBlurServerRpcImpl(Component component) {
+            this.component = component;
+        }
+
+        protected abstract void fireEvent(Event event);
+
+        public void blur() {
+            fireEvent(new BlurEvent(component));
+        }
+
+        public void focus() {
+            fireEvent(new FocusEvent(component));
+        }
+    };
+
 }
index 06b9042eb433c361893c6bc9f27f297b41be4c4f..95f5125f1b55643a02deb4159a836330259f0522 100644 (file)
@@ -6,10 +6,12 @@ package com.vaadin.terminal.gwt.client;
 import static com.vaadin.terminal.gwt.client.EventId.BLUR;
 import static com.vaadin.terminal.gwt.client.EventId.FOCUS;
 
+import com.google.gwt.event.dom.client.BlurEvent;
 import com.google.gwt.event.dom.client.BlurHandler;
+import com.google.gwt.event.dom.client.DomEvent.Type;
+import com.google.gwt.event.dom.client.FocusEvent;
 import com.google.gwt.event.dom.client.FocusHandler;
-import com.google.gwt.event.dom.client.HasBlurHandlers;
-import com.google.gwt.event.dom.client.HasFocusHandlers;
+import com.google.gwt.event.shared.EventHandler;
 import com.google.gwt.event.shared.HandlerRegistration;
 
 /**
@@ -40,38 +42,56 @@ import com.google.gwt.event.shared.HandlerRegistration;
  */
 public class EventHelper {
 
-    public static HandlerRegistration updateFocusHandler(
-            ComponentConnector paintable, ApplicationConnection client,
-            HandlerRegistration handlerRegistration) {
-        if (client.hasEventListeners(paintable, FOCUS)) {
-            if (handlerRegistration == null) {
-                handlerRegistration = ((HasFocusHandlers) paintable)
-                        .addFocusHandler((FocusHandler) paintable);
-            }
-            return handlerRegistration;
-        } else if (handlerRegistration != null) {
-            handlerRegistration.removeHandler();
-            handlerRegistration = null;
+    /**
+     * Adds or removes a focus handler depending on if the connector has focus
+     * listeners on the server side or not.
+     * 
+     * @param connector
+     *            The connector to update. Must implement focusHandler.
+     * @param handlerRegistration
+     *            The old registration reference or null no handler has been
+     *            registered previously
+     * @return a new registration handler that can be used to unregister the
+     *         handler later
+     */
+    public static <T extends ComponentConnector & FocusHandler> HandlerRegistration updateFocusHandler(
+            T connector, HandlerRegistration handlerRegistration) {
+        return updateHandler(connector, FOCUS, handlerRegistration,
+                FocusEvent.getType());
+    }
 
-        }
-        return null;
+    /**
+     * Adds or removes a blur handler depending on if the connector has blur
+     * listeners on the server side or not.
+     * 
+     * @param connector
+     *            The connector to update. Must implement BlurHandler.
+     * @param handlerRegistration
+     *            The old registration reference or null no handler has been
+     *            registered previously
+     * @return a new registration handler that can be used to unregister the
+     *         handler later
+     */
+    public static <T extends ComponentConnector & BlurHandler> HandlerRegistration updateBlurHandler(
+            T connector, HandlerRegistration handlerRegistration) {
+        return updateHandler(connector, BLUR, handlerRegistration,
+                BlurEvent.getType());
     }
 
-    public static HandlerRegistration updateBlurHandler(
-            ComponentConnector paintable, ApplicationConnection client,
-            HandlerRegistration handlerRegistration) {
-        if (client.hasEventListeners(paintable, BLUR)) {
+    private static <H extends EventHandler> HandlerRegistration updateHandler(
+            ComponentConnector connector, String eventIdentifier,
+            HandlerRegistration handlerRegistration, Type<H> type) {
+        if (connector.hasEventListener(eventIdentifier)) {
             if (handlerRegistration == null) {
-                handlerRegistration = ((HasBlurHandlers) paintable)
-                        .addBlurHandler((BlurHandler) paintable);
+                handlerRegistration = connector.getWidget().addDomHandler(
+                        (H) connector, type);
             }
-            return handlerRegistration;
         } else if (handlerRegistration != null) {
             handlerRegistration.removeHandler();
             handlerRegistration = null;
-
         }
-        return null;
+        return handlerRegistration;
+
     }
 
 }
index ddc9b5943096917f8ab7a9cf6c437c7de746c669..9d8838751fea89a7c9ddda3babe91e2f259b6d73 100644 (file)
@@ -5,21 +5,25 @@
 package com.vaadin.terminal.gwt.client.ui;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.BlurEvent;
+import com.google.gwt.event.dom.client.BlurHandler;
+import com.google.gwt.event.dom.client.FocusEvent;
+import com.google.gwt.event.dom.client.FocusHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
 import com.google.gwt.user.client.DOM;
 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.MouseEventDetails;
-import com.vaadin.terminal.gwt.client.Paintable;
-import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.communication.FieldRpc.FocusAndBlurServerRpc;
 import com.vaadin.terminal.gwt.client.communication.RpcProxy;
 import com.vaadin.terminal.gwt.client.communication.ServerRpc;
+import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
 import com.vaadin.terminal.gwt.client.ui.Component.LoadStyle;
 import com.vaadin.ui.Button;
 
 @Component(value = Button.class, loadStyle = LoadStyle.EAGER)
 public class ButtonConnector extends AbstractComponentConnector implements
-        Paintable {
+        BlurHandler, FocusHandler {
 
     /**
      * RPC interface for calls from client to server.
@@ -42,6 +46,13 @@ public class ButtonConnector extends AbstractComponentConnector implements
         public void disableOnClick();
     }
 
+    private ButtonServerRpc rpc = RpcProxy.create(ButtonServerRpc.class, this);
+    private FocusAndBlurServerRpc focusBlurProxy = RpcProxy.create(
+            FocusAndBlurServerRpc.class, this);
+
+    private HandlerRegistration focusHandlerRegistration = null;
+    private HandlerRegistration blurHandlerRegistration = null;
+
     @Override
     public boolean delegateCaptionHandling() {
         return false;
@@ -50,27 +61,18 @@ public class ButtonConnector extends AbstractComponentConnector implements
     @Override
     public void init() {
         super.init();
-        getWidget().buttonRpcProxy = RpcProxy.create(ButtonServerRpc.class,
-                this);
+        getWidget().buttonRpcProxy = rpc;
+        getWidget().client = getConnection();
+        getWidget().paintableId = getConnectorId();
     }
 
-    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-
-        // Ensure correct implementation,
-        // but don't let container manage caption etc.
-        if (!isRealUpdate(uidl)) {
-            return;
-        }
-
-        getWidget().focusHandlerRegistration = EventHelper.updateFocusHandler(
-                this, client, getWidget().focusHandlerRegistration);
-        getWidget().blurHandlerRegistration = EventHelper.updateBlurHandler(
-                this, client, getWidget().blurHandlerRegistration);
-
-        // Save details
-        getWidget().client = client;
-        getWidget().paintableId = uidl.getId();
-
+    @Override
+    public void onStateChanged(StateChangeEvent stateChangeEvent) {
+        super.onStateChanged(stateChangeEvent);
+        focusHandlerRegistration = EventHelper.updateFocusHandler(this,
+                focusHandlerRegistration);
+        blurHandlerRegistration = EventHelper.updateBlurHandler(this,
+                blurHandlerRegistration);
         // Set text
         getWidget().setText(getState().getCaption());
 
@@ -93,7 +95,7 @@ public class ButtonConnector extends AbstractComponentConnector implements
 
         if (getState().getIcon() != null) {
             if (getWidget().icon == null) {
-                getWidget().icon = new Icon(client);
+                getWidget().icon = new Icon(getConnection());
                 getWidget().wrapper.insertBefore(getWidget().icon.getElement(),
                         getWidget().captionElement);
             }
@@ -123,4 +125,15 @@ public class ButtonConnector extends AbstractComponentConnector implements
         return (ButtonState) super.getState();
     }
 
+    public void onFocus(FocusEvent event) {
+        // EventHelper.updateFocusHandler ensures that this is called only when
+        // there is a listener on server side
+        focusBlurProxy.focus();
+    }
+
+    public void onBlur(BlurEvent event) {
+        // EventHelper.updateFocusHandler ensures that this is called only when
+        // there is a listener on server side
+        focusBlurProxy.blur();
+    }
 }
index 5c9193f08bd8120222438d9e8c3bd089535979f7..f32980c6367a6a6180694148c588d722ed0adf6b 100644 (file)
@@ -4,38 +4,79 @@
 package com.vaadin.terminal.gwt.client.ui;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.BlurEvent;
+import com.google.gwt.event.dom.client.BlurHandler;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.event.dom.client.FocusEvent;
+import com.google.gwt.event.dom.client.FocusHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
 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.AbstractFieldState;
 import com.vaadin.terminal.gwt.client.EventHelper;
-import com.vaadin.terminal.gwt.client.Paintable;
-import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.MouseEventDetails;
+import com.vaadin.terminal.gwt.client.MouseEventDetailsBuilder;
 import com.vaadin.terminal.gwt.client.VTooltip;
+import com.vaadin.terminal.gwt.client.communication.FieldRpc.FocusAndBlurServerRpc;
+import com.vaadin.terminal.gwt.client.communication.RpcProxy;
+import com.vaadin.terminal.gwt.client.communication.ServerRpc;
+import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
 import com.vaadin.ui.CheckBox;
 
 @Component(CheckBox.class)
 public class CheckBoxConnector extends AbstractFieldConnector implements
-        Paintable {
+        FocusHandler, BlurHandler, ClickHandler {
+
+    public interface CheckBoxServerRpc extends ServerRpc {
+        public void setChecked(boolean checked,
+                MouseEventDetails mouseEventDetails);
+    }
+
+    public static class CheckBoxState extends AbstractFieldState {
+        private boolean checked = false;
+
+        public boolean isChecked() {
+            return checked;
+        }
+
+        public void setChecked(boolean checked) {
+            this.checked = checked;
+        }
+
+    }
+
+    private HandlerRegistration focusHandlerRegistration;
+    private HandlerRegistration blurHandlerRegistration;
+
+    private CheckBoxServerRpc rpc = RpcProxy.create(CheckBoxServerRpc.class,
+            this);
+    private FocusAndBlurServerRpc focusBlurRpc = RpcProxy.create(
+            FocusAndBlurServerRpc.class, this);
 
     @Override
     public boolean delegateCaptionHandling() {
         return false;
     }
 
-    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-        // Save details
-        getWidget().client = client;
-        getWidget().id = uidl.getId();
+    @Override
+    protected void init() {
+        super.init();
+        getWidget().addClickHandler(this);
+        getWidget().client = getConnection();
+        getWidget().id = getConnectorId();
 
-        if (!isRealUpdate(uidl)) {
-            return;
-        }
+    }
 
-        getWidget().focusHandlerRegistration = EventHelper.updateFocusHandler(
-                this, client, getWidget().focusHandlerRegistration);
-        getWidget().blurHandlerRegistration = EventHelper.updateBlurHandler(
-                this, client, getWidget().blurHandlerRegistration);
+    @Override
+    public void onStateChanged(StateChangeEvent stateChangeEvent) {
+        super.onStateChanged(stateChangeEvent);
+
+        focusHandlerRegistration = EventHelper.updateFocusHandler(this,
+                focusHandlerRegistration);
+        blurHandlerRegistration = EventHelper.updateBlurHandler(this,
+                blurHandlerRegistration);
 
         if (null != getState().getErrorMessage()) {
             if (getWidget().errorIndicatorElement == null) {
@@ -62,7 +103,7 @@ public class CheckBoxConnector extends AbstractFieldConnector implements
 
         if (getState().getIcon() != null) {
             if (getWidget().icon == null) {
-                getWidget().icon = new Icon(client);
+                getWidget().icon = new Icon(getConnection());
                 DOM.insertChild(getWidget().getElement(),
                         getWidget().icon.getElement(), 1);
                 getWidget().icon.sinkEvents(VTooltip.TOOLTIP_EVENTS);
@@ -78,11 +119,15 @@ public class CheckBoxConnector extends AbstractFieldConnector implements
 
         // Set text
         getWidget().setText(getState().getCaption());
-        getWidget().setValue(
-                uidl.getBooleanVariable(getWidget().VARIABLE_STATE));
+        getWidget().setValue(getState().isChecked());
         getWidget().immediate = getState().isImmediate();
     }
 
+    @Override
+    public CheckBoxState getState() {
+        return (CheckBoxState) super.getState();
+    }
+
     @Override
     public VCheckBox getWidget() {
         return (VCheckBox) super.getWidget();
@@ -93,4 +138,28 @@ public class CheckBoxConnector extends AbstractFieldConnector implements
         return GWT.create(VCheckBox.class);
     }
 
+    public void onFocus(FocusEvent event) {
+        // EventHelper.updateFocusHandler ensures that this is called only when
+        // there is a listener on server side
+        focusBlurRpc.focus();
+    }
+
+    public void onBlur(BlurEvent event) {
+        // EventHelper.updateFocusHandler ensures that this is called only when
+        // there is a listener on server side
+        focusBlurRpc.blur();
+    }
+
+    public void onClick(ClickEvent event) {
+        if (!isEnabled()) {
+            return;
+        }
+
+        // Add mouse details
+        MouseEventDetails details = MouseEventDetailsBuilder
+                .buildMouseEventDetails(event.getNativeEvent(), getWidget()
+                        .getElement());
+        rpc.setChecked(getWidget().getValue(), details);
+
+    }
 }
index bf1299ed271c9d4642c83eadd925cb75b022788a..6dd7cd0eac9ed3300612d2eed981705b512b4a76 100644 (file)
@@ -4,19 +4,29 @@
 package com.vaadin.terminal.gwt.client.ui;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.BlurEvent;
+import com.google.gwt.event.dom.client.BlurHandler;
+import com.google.gwt.event.dom.client.FocusEvent;
+import com.google.gwt.event.dom.client.FocusHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
 import com.google.gwt.user.client.DOM;
 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.Paintable;
-import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.communication.FieldRpc.FocusAndBlurServerRpc;
 import com.vaadin.terminal.gwt.client.communication.RpcProxy;
+import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
 import com.vaadin.terminal.gwt.client.ui.ButtonConnector.ButtonServerRpc;
 import com.vaadin.ui.NativeButton;
 
 @Component(NativeButton.class)
 public class NativeButtonConnector extends AbstractComponentConnector implements
-        Paintable {
+        BlurHandler, FocusHandler {
+
+    private HandlerRegistration focusHandlerRegistration;
+    private HandlerRegistration blurHandlerRegistration;
+
+    private FocusAndBlurServerRpc focusBlurRpc = RpcProxy.create(
+            FocusAndBlurServerRpc.class, this);
 
     @Override
     public void init() {
@@ -24,6 +34,8 @@ public class NativeButtonConnector extends AbstractComponentConnector implements
 
         getWidget().buttonRpcProxy = RpcProxy.create(ButtonServerRpc.class,
                 this);
+        getWidget().client = getConnection();
+        getWidget().paintableId = getConnectorId();
     }
 
     @Override
@@ -31,21 +43,15 @@ public class NativeButtonConnector extends AbstractComponentConnector implements
         return false;
     }
 
-    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-
-        if (!isRealUpdate(uidl)) {
-            return;
-        }
+    @Override
+    public void onStateChanged(StateChangeEvent stateChangeEvent) {
+        super.onStateChanged(stateChangeEvent);
 
         getWidget().disableOnClick = getState().isDisableOnClick();
-        getWidget().focusHandlerRegistration = EventHelper.updateFocusHandler(
-                this, client, getWidget().focusHandlerRegistration);
-        getWidget().blurHandlerRegistration = EventHelper.updateBlurHandler(
-                this, client, getWidget().blurHandlerRegistration);
-
-        // Save details
-        getWidget().client = client;
-        getWidget().paintableId = uidl.getId();
+        focusHandlerRegistration = EventHelper.updateFocusHandler(this,
+                focusHandlerRegistration);
+        blurHandlerRegistration = EventHelper.updateBlurHandler(this,
+                blurHandlerRegistration);
 
         // Set text
         getWidget().setText(getState().getCaption());
@@ -69,7 +75,7 @@ public class NativeButtonConnector extends AbstractComponentConnector implements
 
         if (getState().getIcon() != null) {
             if (getWidget().icon == null) {
-                getWidget().icon = new Icon(client);
+                getWidget().icon = new Icon(getConnection());
                 getWidget().getElement().insertBefore(
                         getWidget().icon.getElement(),
                         getWidget().captionElement);
@@ -100,4 +106,16 @@ public class NativeButtonConnector extends AbstractComponentConnector implements
         return (ButtonState) super.getState();
     }
 
+    public void onFocus(FocusEvent event) {
+        // EventHelper.updateFocusHandler ensures that this is called only when
+        // there is a listener on server side
+        focusBlurRpc.focus();
+    }
+
+    public void onBlur(BlurEvent event) {
+        // EventHelper.updateFocusHandler ensures that this is called only when
+        // there is a listener on server side
+        focusBlurRpc.blur();
+    }
+
 }
index a8c034c557f110aa78ae8b360a3cad1310d33537..454ca7932076308368909a76172043859d5894d3 100644 (file)
@@ -7,29 +7,22 @@ package com.vaadin.terminal.gwt.client.ui;
 import com.google.gwt.dom.client.Document;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.NativeEvent;
-import com.google.gwt.event.dom.client.BlurEvent;
-import com.google.gwt.event.dom.client.BlurHandler;
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.event.dom.client.FocusEvent;
-import com.google.gwt.event.dom.client.FocusHandler;
 import com.google.gwt.event.dom.client.KeyCodes;
-import com.google.gwt.event.shared.HandlerRegistration;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Event;
 import com.google.gwt.user.client.ui.Accessibility;
 import com.google.gwt.user.client.ui.FocusWidget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.BrowserInfo;
-import com.vaadin.terminal.gwt.client.EventId;
 import com.vaadin.terminal.gwt.client.MouseEventDetails;
 import com.vaadin.terminal.gwt.client.MouseEventDetailsBuilder;
 import com.vaadin.terminal.gwt.client.Util;
 import com.vaadin.terminal.gwt.client.VTooltip;
 import com.vaadin.terminal.gwt.client.ui.ButtonConnector.ButtonServerRpc;
 
-public class VButton extends FocusWidget implements ClickHandler, FocusHandler,
-        BlurHandler {
+public class VButton extends FocusWidget implements ClickHandler {
 
     public static final String CLASSNAME = "v-button";
     private static final String CLASSNAME_PRESSED = "v-pressed";
@@ -85,9 +78,6 @@ public class VButton extends FocusWidget implements ClickHandler, FocusHandler,
     private boolean disallowNextClick = false;
     private boolean isHovering;
 
-    protected HandlerRegistration focusHandlerRegistration;
-    protected HandlerRegistration blurHandlerRegistration;
-
     protected int clickShortcut = 0;
     // TODO Move this to VButtonPaintable
     ButtonServerRpc buttonRpcProxy;
@@ -446,11 +436,4 @@ public class VButton extends FocusWidget implements ClickHandler, FocusHandler,
        return ret;
     }-*/;
 
-    public void onFocus(FocusEvent arg0) {
-        client.updateVariable(paintableId, EventId.FOCUS, "", true);
-    }
-
-    public void onBlur(BlurEvent arg0) {
-        client.updateVariable(paintableId, EventId.BLUR, "", true);
-    }
 }
index d7be367f979faf525dfb0f5790a7f46ca8aab240..f2ac958d2477354f9d832f3ea766871ca12d9643 100644 (file)
@@ -4,27 +4,15 @@
 
 package com.vaadin.terminal.gwt.client.ui;
 
-import com.google.gwt.event.dom.client.BlurEvent;
-import com.google.gwt.event.dom.client.BlurHandler;
-import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.event.dom.client.FocusEvent;
-import com.google.gwt.event.dom.client.FocusHandler;
-import com.google.gwt.event.shared.HandlerRegistration;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.EventId;
-import com.vaadin.terminal.gwt.client.MouseEventDetails;
-import com.vaadin.terminal.gwt.client.MouseEventDetailsBuilder;
 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
-        Field, FocusHandler, BlurHandler {
-
-    public static final String VARIABLE_STATE = "state";
+        Field {
 
     public static final String CLASSNAME = "v-checkbox";
 
@@ -38,28 +26,9 @@ public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements
 
     Icon icon;
 
-    HandlerRegistration focusHandlerRegistration;
-    HandlerRegistration blurHandlerRegistration;
-
     public VCheckBox() {
         setStyleName(CLASSNAME);
-        addClickHandler(new ClickHandler() {
-
-            public void onClick(ClickEvent event) {
-                if (id == null || client == null || !isEnabled()) {
-                    return;
-                }
-
-                // Add mouse details
-                MouseEventDetails details = MouseEventDetailsBuilder
-                        .buildMouseEventDetails(event.getNativeEvent(),
-                                getElement());
-                client.updateVariable(id, "mousedetails", details.serialize(),
-                        false);
-                client.updateVariable(id, VARIABLE_STATE, getValue(), immediate);
-            }
 
-        });
         sinkEvents(VTooltip.TOOLTIP_EVENTS);
         Element el = DOM.getFirstChild(getElement());
         while (el != null) {
@@ -87,22 +56,4 @@ public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements
         }
     }
 
-    @Override
-    public void setWidth(String width) {
-        super.setWidth(width);
-    }
-
-    @Override
-    public void setHeight(String height) {
-        super.setHeight(height);
-    }
-
-    public void onFocus(FocusEvent arg0) {
-        client.updateVariable(id, EventId.FOCUS, "", true);
-    }
-
-    public void onBlur(BlurEvent arg0) {
-        client.updateVariable(id, EventId.BLUR, "", true);
-    }
-
 }
index 7866d326abc608031b5b4926d52023153fcfbd88..b3f60c91adb0c6c4067623bff12ff98fb7d69fe7 100644 (file)
@@ -5,27 +5,20 @@
 package com.vaadin.terminal.gwt.client.ui;
 
 import com.google.gwt.dom.client.Element;
-import com.google.gwt.event.dom.client.BlurEvent;
-import com.google.gwt.event.dom.client.BlurHandler;
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.event.dom.client.FocusEvent;
-import com.google.gwt.event.dom.client.FocusHandler;
-import com.google.gwt.event.shared.HandlerRegistration;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Event;
 import com.google.gwt.user.client.ui.Button;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.BrowserInfo;
-import com.vaadin.terminal.gwt.client.EventId;
 import com.vaadin.terminal.gwt.client.MouseEventDetails;
 import com.vaadin.terminal.gwt.client.MouseEventDetailsBuilder;
 import com.vaadin.terminal.gwt.client.Util;
 import com.vaadin.terminal.gwt.client.VTooltip;
 import com.vaadin.terminal.gwt.client.ui.ButtonConnector.ButtonServerRpc;
 
-public class VNativeButton extends Button implements ClickHandler,
-        FocusHandler, BlurHandler {
+public class VNativeButton extends Button implements ClickHandler {
 
     public static final String CLASSNAME = "v-nativebutton";
 
@@ -50,9 +43,6 @@ public class VNativeButton extends Button implements ClickHandler,
      */
     private boolean clickPending;
 
-    protected HandlerRegistration focusHandlerRegistration;
-    protected HandlerRegistration blurHandlerRegistration;
-
     protected boolean disableOnClick = false;
 
     public VNativeButton() {
@@ -131,14 +121,6 @@ public class VNativeButton extends Button implements ClickHandler,
         clickPending = false;
     }
 
-    public void onFocus(FocusEvent arg0) {
-        client.updateVariable(paintableId, EventId.FOCUS, "", true);
-    }
-
-    public void onBlur(BlurEvent arg0) {
-        client.updateVariable(paintableId, EventId.BLUR, "", true);
-    }
-
     @Override
     public void setEnabled(boolean enabled) {
         if (isEnabled() != enabled) {
index b54f5ee94843223b2afcdaa3a7bf106c0a5bc418..83e6f54ad33e49f8e0fb924c37e54a4fbe3ebe13 100644 (file)
@@ -33,6 +33,7 @@ import com.vaadin.terminal.Resource;
 import com.vaadin.terminal.Terminal;
 import com.vaadin.terminal.gwt.client.ComponentState;
 import com.vaadin.terminal.gwt.client.communication.ClientRpc;
+import com.vaadin.terminal.gwt.client.communication.ServerRpc;
 import com.vaadin.terminal.gwt.server.ClientMethodInvocation;
 import com.vaadin.terminal.gwt.server.ComponentSizeValidator;
 import com.vaadin.terminal.gwt.server.ResourceReference;
@@ -1536,9 +1537,17 @@ public abstract class AbstractComponent implements Component, MethodEventSource
      * @param implementation
      *            RPC interface implementation. Also used to deduce the type.
      */
-    protected <T> void registerRpc(T implementation) {
-        Class<?>[] interfaces = implementation.getClass().getInterfaces();
-        if (interfaces.length != 1) {
+    protected <T extends ServerRpc> void registerRpc(T implementation) {
+        Class<?> cls = implementation.getClass();
+        Class<?>[] interfaces = cls.getInterfaces();
+        while (interfaces.length == 0) {
+            // Search upwards until an interface is found. It must be found as T
+            // extends ServerRpc
+            cls = cls.getSuperclass();
+            interfaces = cls.getInterfaces();
+        }
+        if (interfaces.length != 1
+                || !(ServerRpc.class.isAssignableFrom(interfaces[0]))) {
             throw new RuntimeException(
                     "Use registerRpc(T implementation, Class<T> rpcInterfaceType) if the Rpc implementation implements more than one interface");
         }
index 68e75b2c69988241157ae7435b7ae56f0e5f0ee4..63106945b205715a592aa3a05fe1affd5850d52f 100644 (file)
@@ -6,21 +6,18 @@ package com.vaadin.ui;
 
 import java.io.Serializable;
 import java.lang.reflect.Method;
-import java.util.Map;
 
 import com.vaadin.event.Action;
 import com.vaadin.event.FieldEvents;
 import com.vaadin.event.FieldEvents.BlurEvent;
 import com.vaadin.event.FieldEvents.BlurListener;
+import com.vaadin.event.FieldEvents.FocusAndBlurServerRpcImpl;
 import com.vaadin.event.FieldEvents.FocusEvent;
 import com.vaadin.event.FieldEvents.FocusListener;
 import com.vaadin.event.ShortcutAction;
 import com.vaadin.event.ShortcutAction.KeyCode;
 import com.vaadin.event.ShortcutAction.ModifierKey;
 import com.vaadin.event.ShortcutListener;
-import com.vaadin.terminal.PaintException;
-import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.Vaadin6Component;
 import com.vaadin.terminal.gwt.client.MouseEventDetails;
 import com.vaadin.terminal.gwt.client.ui.ButtonConnector.ButtonServerRpc;
 import com.vaadin.terminal.gwt.client.ui.ButtonState;
@@ -38,7 +35,7 @@ import com.vaadin.ui.Component.Focusable;
 @SuppressWarnings("serial")
 public class Button extends AbstractComponent implements
         FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, Focusable,
-        Action.ShortcutNotifier, Vaadin6Component {
+        Action.ShortcutNotifier {
 
     private ButtonServerRpc rpc = new ButtonServerRpc() {
         public void click(MouseEventDetails mouseEventDetails) {
@@ -52,11 +49,19 @@ public class Button extends AbstractComponent implements
         }
     };
 
+    FocusAndBlurServerRpcImpl focusBlurRpc = new FocusAndBlurServerRpcImpl(this) {
+        @Override
+        protected void fireEvent(Event event) {
+            Button.this.fireEvent(event);
+        }
+    };
+
     /**
      * Creates a new push button.
      */
     public Button() {
         registerRpc(rpc);
+        registerRpc(focusBlurRpc);
     }
 
     /**
@@ -83,26 +88,6 @@ public class Button extends AbstractComponent implements
         addListener(listener);
     }
 
-    /**
-     * Invoked when the value of a variable has changed. Button listeners are
-     * notified if the button is clicked.
-     * 
-     * @param source
-     * @param variables
-     */
-    public void changeVariables(Object source, Map<String, Object> variables) {
-        if (variables.containsKey(FocusEvent.EVENT_ID)) {
-            fireEvent(new FocusEvent(this));
-        }
-        if (variables.containsKey(BlurEvent.EVENT_ID)) {
-            fireEvent(new BlurEvent(this));
-        }
-    }
-
-    public void paintContent(PaintTarget target) throws PaintException {
-        // TODO Remove once Vaadin6Component is no longer implemented
-    }
-
     /**
      * Click event. This event is thrown, when the button is clicked.
      * 
index e53bb5a3b7278805072af0bb86d68281b64138e6..e98cf3638fafc72eed5b5188e673582e167e4b96 100644 (file)
@@ -4,24 +4,50 @@
 
 package com.vaadin.ui;
 
-import java.util.Map;
-
 import com.vaadin.data.Property;
 import com.vaadin.event.FieldEvents.BlurEvent;
 import com.vaadin.event.FieldEvents.BlurListener;
+import com.vaadin.event.FieldEvents.FocusAndBlurServerRpcImpl;
 import com.vaadin.event.FieldEvents.FocusEvent;
 import com.vaadin.event.FieldEvents.FocusListener;
-import com.vaadin.terminal.PaintException;
-import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.Vaadin6Component;
-import com.vaadin.terminal.gwt.client.ui.VCheckBox;
+import com.vaadin.terminal.gwt.client.MouseEventDetails;
+import com.vaadin.terminal.gwt.client.ui.CheckBoxConnector.CheckBoxServerRpc;
+import com.vaadin.terminal.gwt.client.ui.CheckBoxConnector.CheckBoxState;
+
+public class CheckBox extends AbstractField<Boolean> {
+
+    private CheckBoxServerRpc rpc = new CheckBoxServerRpc() {
+
+        public void setChecked(boolean checked,
+                MouseEventDetails mouseEventDetails) {
+            if (isReadOnly()) {
+                return;
+            }
+
+            final Boolean oldValue = getValue();
+            final Boolean newValue = checked;
+
+            if (!newValue.equals(oldValue)) {
+                // The event is only sent if the switch state is changed
+                setValue(newValue);
+            }
+
+        }
+    };
+
+    FocusAndBlurServerRpcImpl focusBlurRpc = new FocusAndBlurServerRpcImpl(this) {
+        @Override
+        protected void fireEvent(Event event) {
+            CheckBox.this.fireEvent(event);
+        }
+    };
 
-public class CheckBox extends AbstractField<Boolean> implements
-        Vaadin6Component {
     /**
      * Creates a new checkbox.
      */
     public CheckBox() {
+        registerRpc(rpc);
+        registerRpc(focusBlurRpc);
         setValue(Boolean.FALSE);
     }
 
@@ -66,32 +92,18 @@ public class CheckBox extends AbstractField<Boolean> implements
         return Boolean.class;
     }
 
-    public void paintContent(PaintTarget target) throws PaintException {
-        Boolean value = getValue();
-        boolean booleanValue = (value != null) ? value : false;
-        target.addVariable(this, VCheckBox.VARIABLE_STATE, booleanValue);
+    @Override
+    public CheckBoxState getState() {
+        return (CheckBoxState) super.getState();
     }
 
-    public void changeVariables(Object source, Map<String, Object> variables) {
-
-        if (!isReadOnly() && variables.containsKey(VCheckBox.VARIABLE_STATE)) {
-            // Gets the new and old states
-            final Boolean newValue = (Boolean) variables
-                    .get(VCheckBox.VARIABLE_STATE);
-            final Boolean oldValue = getValue();
-
-            // The event is only sent if the switch state is changed
-            if (newValue != null && !newValue.equals(oldValue)) {
-                setValue(newValue);
-            }
-        }
-
-        if (variables.containsKey(FocusEvent.EVENT_ID)) {
-            fireEvent(new FocusEvent(this));
-        }
-        if (variables.containsKey(BlurEvent.EVENT_ID)) {
-            fireEvent(new BlurEvent(this));
+    @Override
+    protected void setInternalValue(Boolean newValue) {
+        super.setInternalValue(newValue);
+        if (newValue == null) {
+            newValue = false;
         }
+        getState().setChecked(newValue);
     }
 
     public void addListener(BlurListener listener) {
@@ -110,7 +122,6 @@ public class CheckBox extends AbstractField<Boolean> implements
 
     public void removeListener(FocusListener listener) {
         removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
-
     }
 
     /**