From e0dc2c597fc9643639d273c442e1f380dc2e38ac Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 23 Feb 2012 16:25:32 +0200 Subject: [PATCH] #8278 Added helper for RPC initialization and moved Button/NativeButton RPC initialization to paintable. --- .../client/ui/VAbstractPaintableWidget.java | 16 ++++++++ .../terminal/gwt/client/ui/VButton.java | 41 +++---------------- .../gwt/client/ui/VButtonPaintable.java | 30 ++++++++++++++ .../terminal/gwt/client/ui/VNativeButton.java | 19 ++------- .../gwt/client/ui/VNativeButtonPaintable.java | 10 +++++ src/com/vaadin/ui/Button.java | 4 +- 6 files changed, 67 insertions(+), 53 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java index fb6f785ed0..bff6f8ea3b 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java @@ -15,6 +15,8 @@ import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.VPaintableMap; import com.vaadin.terminal.gwt.client.VPaintableWidget; import com.vaadin.terminal.gwt.client.VPaintableWidgetContainer; +import com.vaadin.terminal.gwt.client.communication.ClientToServerRpc; +import com.vaadin.terminal.gwt.client.communication.ClientToServerRpc.InitializableClientToServerRpc; import com.vaadin.terminal.gwt.client.communication.SharedState; public abstract class VAbstractPaintableWidget implements VPaintableWidget { @@ -375,4 +377,18 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget { public final void setState(SharedState state) { this.state = (ComponentState) state; } + + /** + * Initialize the given RPC proxy object so it is connected to this + * paintable. + * + * @param clientToServerRpc + * The RPC instance to initialize. Must have been created using + * GWT.create(). + */ + protected T initRPC(T clientToServerRpc) { + ((InitializableClientToServerRpc) clientToServerRpc).initRpc(getId(), + getConnection()); + return clientToServerRpc; + } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VButton.java b/src/com/vaadin/terminal/gwt/client/ui/VButton.java index 9797349d9e..6e8f03b18c 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VButton.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VButton.java @@ -4,7 +4,6 @@ package com.vaadin.terminal.gwt.client.ui; -import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; @@ -26,8 +25,7 @@ import com.vaadin.terminal.gwt.client.EventId; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VTooltip; -import com.vaadin.terminal.gwt.client.communication.ClientToServerRpc; -import com.vaadin.terminal.gwt.client.communication.ClientToServerRpc.InitializableClientToServerRpc; +import com.vaadin.terminal.gwt.client.ui.VButtonPaintable.ButtonClientToServerRpc; public class VButton extends FocusWidget implements ClickHandler, FocusHandler, BlurHandler { @@ -35,27 +33,6 @@ public class VButton extends FocusWidget implements ClickHandler, FocusHandler, public static final String CLASSNAME = "v-button"; private static final String CLASSNAME_PRESSED = "v-pressed"; - /** - * RPC interface for calls from client to server. - * - * @since 7.0 - */ - public interface ButtonClientToServerRpc extends ClientToServerRpc { - /** - * Button click event. - * - * @param mouseEventDetails - * serialized mouse event details - */ - public void click(String mouseEventDetails); - - /** - * Indicate to the server that the client has disabled the button as a - * result of a click. - */ - public void disableOnClick(); - } - // mouse movement is checked before synthesizing click event on mouseout protected static int MOVE_THRESHOLD = 3; protected int mousedownX = 0; @@ -111,7 +88,8 @@ public class VButton extends FocusWidget implements ClickHandler, FocusHandler, protected HandlerRegistration blurHandlerRegistration; protected int clickShortcut = 0; - private ButtonClientToServerRpc buttonRpcProxy; + //TODO Move this to VButtonPaintable + ButtonClientToServerRpc buttonRpcProxy; public VButton() { super(DOM.createDiv()); @@ -323,26 +301,17 @@ public class VButton extends FocusWidget implements ClickHandler, FocusHandler, } if (disableOnClick) { setEnabled(false); - getButtonRpcProxy().disableOnClick(); + buttonRpcProxy.disableOnClick(); } // Add mouse details MouseEventDetails details = new MouseEventDetails( event.getNativeEvent(), getElement()); - getButtonRpcProxy().click(details.serialize()); + buttonRpcProxy.click(details.serialize()); clickPending = false; } - protected ButtonClientToServerRpc getButtonRpcProxy() { - if (null == buttonRpcProxy) { - buttonRpcProxy = GWT.create(ButtonClientToServerRpc.class); - ((InitializableClientToServerRpc) buttonRpcProxy).initRpc( - paintableId, client); - } - return buttonRpcProxy; - } - /* * ALL BELOW COPY-PASTED FROM GWT CustomButton */ diff --git a/src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java index 8b09ac6285..5976e7653e 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java @@ -11,14 +11,44 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.ComponentState; import com.vaadin.terminal.gwt.client.EventHelper; import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.communication.ClientToServerRpc; public class VButtonPaintable extends VAbstractPaintableWidget { + /** + * RPC interface for calls from client to server. + * + * @since 7.0 + */ + public interface ButtonClientToServerRpc extends ClientToServerRpc { + /** + * Button click event. + * + * @param mouseEventDetails + * serialized mouse event details + */ + public void click(String mouseEventDetails); + + /** + * Indicate to the server that the client has disabled the button as a + * result of a click. + */ + public void disableOnClick(); + } + @Override protected boolean delegateCaptionHandling() { return false; } + @Override + public void init() { + super.init(); + ButtonClientToServerRpc rpcProxy = GWT + .create(ButtonClientToServerRpc.class); + getWidgetForPaintable().buttonRpcProxy = initRPC(rpcProxy); + } + @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { diff --git a/src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java b/src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java index 3deb3d56b2..da11154208 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java @@ -4,7 +4,6 @@ package com.vaadin.terminal.gwt.client.ui; -import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Element; import com.google.gwt.event.dom.client.BlurEvent; import com.google.gwt.event.dom.client.BlurHandler; @@ -22,8 +21,7 @@ import com.vaadin.terminal.gwt.client.EventId; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VTooltip; -import com.vaadin.terminal.gwt.client.communication.ClientToServerRpc.InitializableClientToServerRpc; -import com.vaadin.terminal.gwt.client.ui.VButton.ButtonClientToServerRpc; +import com.vaadin.terminal.gwt.client.ui.VButtonPaintable.ButtonClientToServerRpc; public class VNativeButton extends Button implements ClickHandler, FocusHandler, BlurHandler { @@ -36,7 +34,7 @@ public class VNativeButton extends Button implements ClickHandler, protected ApplicationConnection client; - private ButtonClientToServerRpc buttonRpcProxy; + ButtonClientToServerRpc buttonRpcProxy; protected Element errorIndicatorElement; @@ -121,26 +119,17 @@ public class VNativeButton extends Button implements ClickHandler, } if (disableOnClick) { setEnabled(false); - getButtonRpcProxy().disableOnClick(); + buttonRpcProxy.disableOnClick(); } // Add mouse details MouseEventDetails details = new MouseEventDetails( event.getNativeEvent(), getElement()); - getButtonRpcProxy().click(details.serialize()); + buttonRpcProxy.click(details.serialize()); clickPending = false; } - protected ButtonClientToServerRpc getButtonRpcProxy() { - if (null == buttonRpcProxy) { - buttonRpcProxy = GWT.create(ButtonClientToServerRpc.class); - ((InitializableClientToServerRpc) buttonRpcProxy).initRpc( - paintableId, client); - } - return buttonRpcProxy; - } - public void onFocus(FocusEvent arg0) { client.updateVariable(paintableId, EventId.FOCUS, "", true); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java index b3e8cda832..3ff93fea06 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java @@ -10,9 +10,19 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.ComponentState; import com.vaadin.terminal.gwt.client.EventHelper; import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.ui.VButtonPaintable.ButtonClientToServerRpc; public class VNativeButtonPaintable extends VAbstractPaintableWidget { + @Override + public void init() { + super.init(); + + ButtonClientToServerRpc rpcProxy = GWT + .create(ButtonClientToServerRpc.class); + getWidgetForPaintable().buttonRpcProxy = initRPC(rpcProxy); + } + @Override protected boolean delegateCaptionHandling() { return false; diff --git a/src/com/vaadin/ui/Button.java b/src/com/vaadin/ui/Button.java index 84abcdc294..61f3002bcc 100644 --- a/src/com/vaadin/ui/Button.java +++ b/src/com/vaadin/ui/Button.java @@ -20,9 +20,9 @@ import com.vaadin.event.ShortcutAction.ModifierKey; import com.vaadin.event.ShortcutListener; import com.vaadin.terminal.gwt.client.ComponentState; import com.vaadin.terminal.gwt.client.MouseEventDetails; -import com.vaadin.terminal.gwt.client.ui.VButton.ButtonClientToServerRpc; -import com.vaadin.terminal.gwt.client.ui.VButtonPaintable; import com.vaadin.terminal.gwt.client.ui.ButtonState; +import com.vaadin.terminal.gwt.client.ui.VButtonPaintable; +import com.vaadin.terminal.gwt.client.ui.VButtonPaintable.ButtonClientToServerRpc; import com.vaadin.terminal.gwt.server.RpcTarget; import com.vaadin.tools.ReflectTools; import com.vaadin.ui.ClientWidget.LoadStyle; -- 2.39.5