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;
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));
+ }
+ };
+
}
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;
/**
*/
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;
+
}
}
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.
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;
@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());
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);
}
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();
+ }
}
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) {
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);
// 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();
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);
+
+ }
}
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() {
getWidget().buttonRpcProxy = RpcProxy.create(ButtonServerRpc.class,
this);
+ getWidget().client = getConnection();
+ getWidget().paintableId = getConnectorId();
}
@Override
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());
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);
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();
+ }
+
}
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";
private boolean disallowNextClick = false;
private boolean isHovering;
- protected HandlerRegistration focusHandlerRegistration;
- protected HandlerRegistration blurHandlerRegistration;
-
protected int clickShortcut = 0;
// TODO Move this to VButtonPaintable
ButtonServerRpc buttonRpcProxy;
return ret;
}-*/;
- public void onFocus(FocusEvent arg0) {
- client.updateVariable(paintableId, EventId.FOCUS, "", true);
- }
-
- public void onBlur(BlurEvent arg0) {
- client.updateVariable(paintableId, EventId.BLUR, "", true);
- }
}
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";
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) {
}
}
- @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);
- }
-
}
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";
*/
private boolean clickPending;
- protected HandlerRegistration focusHandlerRegistration;
- protected HandlerRegistration blurHandlerRegistration;
-
protected boolean disableOnClick = false;
public VNativeButton() {
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) {
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;
* @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");
}
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;
@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) {
}
};
+ 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);
}
/**
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.
*
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);
}
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) {
public void removeListener(FocusListener listener) {
removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
-
}
/**