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;
import com.vaadin.terminal.gwt.client.UIDL;
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;
public class VButton extends FocusWidget implements VPaintableWidget,
ClickHandler, FocusHandler, BlurHandler {
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();
+ }
+
public static final String ATTR_DISABLE_ON_CLICK = "dc";
// mouse movement is checked before synthesizing click event on mouseout
private HandlerRegistration blurHandlerRegistration;
private int clickShortcut = 0;
+ private ButtonClientToServerRpc buttonRpcProxy;
public VButton() {
super(DOM.createDiv());
}
if (disableOnClick) {
setEnabled(false);
- client.updateVariable(id, "disabledOnClick", true, false);
+ getButtonRpcProxy().disableOnClick();
}
- client.updateVariable(id, "state", true, false);
-
// Add mouse details
MouseEventDetails details = new MouseEventDetails(
event.getNativeEvent(), getElement());
- client.updateVariable(id, "mousedetails", details.serialize(), true);
+ getButtonRpcProxy().click(details.serialize());
clickPending = false;
}
+ protected ButtonClientToServerRpc getButtonRpcProxy() {
+ if (null == buttonRpcProxy) {
+ buttonRpcProxy = GWT.create(ButtonClientToServerRpc.class);
+ ((InitializableClientToServerRpc) buttonRpcProxy).initRpc(id,
+ client);
+ }
+ return buttonRpcProxy;
+ }
+
/*
* ALL BELOW COPY-PASTED FROM GWT CustomButton
*/
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;
import com.vaadin.terminal.gwt.client.UIDL;
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;
public class VNativeButton extends Button implements VPaintableWidget,
ClickHandler, FocusHandler, BlurHandler {
protected ApplicationConnection client;
+ private ButtonClientToServerRpc buttonRpcProxy;
+
protected Element errorIndicatorElement;
protected final Element captionElement = DOM.createSpan();
}
if (disableOnClick) {
setEnabled(false);
- client.updateVariable(id, "disabledOnClick", true, false);
+ getButtonRpcProxy().disableOnClick();
}
// Add mouse details
MouseEventDetails details = new MouseEventDetails(
event.getNativeEvent(), getElement());
- client.updateVariable(id, "mousedetails", details.serialize(), false);
+ getButtonRpcProxy().click(details.serialize());
- client.updateVariable(id, "state", true, true);
clickPending = false;
}
+ protected ButtonClientToServerRpc getButtonRpcProxy() {
+ if (null == buttonRpcProxy) {
+ buttonRpcProxy = GWT.create(ButtonClientToServerRpc.class);
+ ((InitializableClientToServerRpc) buttonRpcProxy).initRpc(id,
+ client);
+ }
+ return buttonRpcProxy;
+ }
+
public void onFocus(FocusEvent arg0) {
client.updateVariable(id, EventId.FOCUS, "", true);
}
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.terminal.gwt.client.ui.VButton;
+import com.vaadin.terminal.gwt.client.ui.VButton.ButtonClientToServerRpc;
+import com.vaadin.terminal.gwt.server.RpcTarget;
import com.vaadin.tools.ReflectTools;
import com.vaadin.ui.ClientWidget.LoadStyle;
import com.vaadin.ui.Component.Focusable;
@ClientWidget(value = VButton.class, loadStyle = LoadStyle.EAGER)
public class Button extends AbstractComponent implements
FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, Focusable,
- Action.ShortcutNotifier {
+ Action.ShortcutNotifier, RpcTarget {
/* Private members */
* Creates a new push button.
*/
public Button() {
+ // TODO take the implementation out of an anonymous class?
+ registerRpcImplementation(new ButtonClientToServerRpc() {
+ public void click(String mouseEventDetails) {
+ fireClick(MouseEventDetails.deSerialize(mouseEventDetails));
+ }
+
+ public void disableOnClick() {
+ // Could be optimized so the button is not repainted because of
+ // this (client side has already disabled the button)
+ setEnabled(false);
+ }
+ }, ButtonClientToServerRpc.class);
}
/**
public void changeVariables(Object source, Map<String, Object> variables) {
super.changeVariables(source, variables);
- if (variables.containsKey("disabledOnClick")) {
- // Could be optimized so the button is not repainted because of this
- // (client side has already disabled the button)
- setEnabled(false);
- }
-
- if (!isReadOnly() && variables.containsKey("state")) {
- // Send click events when the button is pushed
- if (variables.containsKey("mousedetails")) {
- fireClick(MouseEventDetails.deSerialize((String) variables
- .get("mousedetails")));
- } else {
- // for compatibility with custom implementations which
- // don't send mouse details
- fireClick();
- }
- }
-
if (variables.containsKey(FocusEvent.EVENT_ID)) {
fireEvent(new FocusEvent(this));
}