aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/vaadin/event/FieldEvents.java13
-rw-r--r--src/com/vaadin/terminal/gwt/client/EventHelper.java74
-rw-r--r--src/com/vaadin/terminal/gwt/client/EventId.java6
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VButton.java26
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java24
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java13
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java26
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VOptionGroup.java96
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VTextField.java13
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java11
-rw-r--r--src/com/vaadin/ui/Button.java36
-rw-r--r--src/com/vaadin/ui/DateField.java16
-rw-r--r--src/com/vaadin/ui/OptionGroup.java40
-rw-r--r--src/com/vaadin/ui/Select.java15
-rw-r--r--src/com/vaadin/ui/TextField.java27
-rw-r--r--tests/src/com/vaadin/tests/components/FocusAndBlurListeners.java54
16 files changed, 422 insertions, 68 deletions
diff --git a/src/com/vaadin/event/FieldEvents.java b/src/com/vaadin/event/FieldEvents.java
index e810798b07..5aff31e1bf 100644
--- a/src/com/vaadin/event/FieldEvents.java
+++ b/src/com/vaadin/event/FieldEvents.java
@@ -6,6 +6,7 @@ package com.vaadin.event;
import java.lang.reflect.Method;
+import com.vaadin.terminal.gwt.client.EventId;
import com.vaadin.tools.ReflectTools;
import com.vaadin.ui.Component;
import com.vaadin.ui.Field;
@@ -97,8 +98,14 @@ public interface FieldEvents {
*
* @since 6.2
*/
+ @SuppressWarnings("serial")
public class FocusEvent extends Component.Event {
+ /**
+ * Identifier for event that can be used in {@link EventRouter}
+ */
+ public static final String EVENT_ID = EventId.FOCUS;
+
public FocusEvent(Component source) {
super(source);
}
@@ -131,8 +138,14 @@ public interface FieldEvents {
*
* @since 6.2
*/
+ @SuppressWarnings("serial")
public class BlurEvent extends Component.Event {
+ /**
+ * Identifier for event that can be used in {@link EventRouter}
+ */
+ public static final String EVENT_ID = EventId.BLUR;
+
public BlurEvent(Component source) {
super(source);
}
diff --git a/src/com/vaadin/terminal/gwt/client/EventHelper.java b/src/com/vaadin/terminal/gwt/client/EventHelper.java
new file mode 100644
index 0000000000..0b2f6ef4df
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/client/EventHelper.java
@@ -0,0 +1,74 @@
+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.BlurHandler;
+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.HandlerRegistration;
+
+/**
+ * Helper class for attaching/detaching handlers for Vaadin client side
+ * components, based on identifiers in UIDL. Helpers expect Paintables to be
+ * both listeners and sources for events. This helper cannot be used for more
+ * complex widgets.
+ * <p>
+ * Possible current registration is given as parameter. The returned
+ * registration (possibly the same as given, should be store for next update.
+ * <p>
+ * Pseudocode what helpers do:
+ *
+ * <pre>
+ *
+ * if paintable has event listener in UIDL
+ * if registration is null
+ * register paintable as as handler for event
+ * return the registration
+ * else
+ * if registration is not null
+ * remove the handler from paintable
+ * return null
+ *
+ *
+ * </pre>
+ *
+ */
+public class EventHelper {
+
+ public static HandlerRegistration updateFocusHandler(Paintable 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;
+
+ }
+ return null;
+ }
+
+ public static HandlerRegistration updateBlurHandler(Paintable paintable,
+ ApplicationConnection client,
+ HandlerRegistration handlerRegistration) {
+ if (client.hasEventListeners(paintable, BLUR)) {
+ if (handlerRegistration == null) {
+ handlerRegistration = ((HasBlurHandlers) paintable)
+ .addBlurHandler((BlurHandler) paintable);
+ }
+ return handlerRegistration;
+ } else if (handlerRegistration != null) {
+ handlerRegistration.removeHandler();
+ handlerRegistration = null;
+
+ }
+ return null;
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/EventId.java b/src/com/vaadin/terminal/gwt/client/EventId.java
new file mode 100644
index 0000000000..c6b725a562
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/client/EventId.java
@@ -0,0 +1,6 @@
+package com.vaadin.terminal.gwt.client;
+
+public interface EventId {
+ public static final String BLUR = "blur";
+ public static final String FOCUS = "focus";
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VButton.java b/src/com/vaadin/terminal/gwt/client/ui/VButton.java
index 36d9f5ec1e..6eb9fb2925 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VButton.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VButton.java
@@ -7,20 +7,28 @@ 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.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.EventHelper;
+import com.vaadin.terminal.gwt.client.EventId;
import com.vaadin.terminal.gwt.client.Paintable;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VTooltip;
-public class VButton extends FocusWidget implements Paintable, ClickHandler {
+public class VButton extends FocusWidget implements Paintable, ClickHandler,
+ FocusHandler, BlurHandler {
public static final String CLASSNAME = "v-button";
private static final String CLASSNAME_PRESSED = "v-pressed";
@@ -69,6 +77,9 @@ public class VButton extends FocusWidget implements Paintable, ClickHandler {
private boolean disallowNextClick = false;
private boolean isHovering;
+ private HandlerRegistration focusHandlerRegistration;
+ private HandlerRegistration blurHandlerRegistration;
+
public VButton() {
super(DOM.createDiv());
setTabIndex(0);
@@ -97,6 +108,11 @@ public class VButton extends FocusWidget implements Paintable, ClickHandler {
return;
}
+ focusHandlerRegistration = EventHelper.updateFocusHandler(this, client,
+ focusHandlerRegistration);
+ blurHandlerRegistration = EventHelper.updateBlurHandler(this, client,
+ blurHandlerRegistration);
+
// Save details
this.client = client;
id = uidl.getId();
@@ -455,4 +471,12 @@ public class VButton extends FocusWidget implements Paintable, ClickHandler {
return ret;
}-*/;
+ public void onFocus(FocusEvent arg0) {
+ client.updateVariable(id, EventId.FOCUS, "", true);
+ }
+
+ public void onBlur(BlurEvent arg0) {
+ client.updateVariable(id, EventId.BLUR, "", true);
+ }
+
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java b/src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java
index 389c2210d3..88b3f876dd 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VCheckBox.java
@@ -8,20 +8,27 @@ import com.google.gwt.dom.client.InputElement;
import com.google.gwt.dom.client.LabelElement;
import com.google.gwt.dom.client.Node;
import com.google.gwt.dom.client.NodeList;
+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.BrowserInfo;
+import com.vaadin.terminal.gwt.client.EventHelper;
+import com.vaadin.terminal.gwt.client.EventId;
import com.vaadin.terminal.gwt.client.Paintable;
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
- Paintable, Field {
+ Paintable, Field, FocusHandler, BlurHandler {
public static final String CLASSNAME = "v-checkbox";
@@ -37,6 +44,9 @@ public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements
private boolean isBlockMode = false;
+ private HandlerRegistration focusHandlerRegistration;
+ private HandlerRegistration blurHandlerRegistration;
+
public VCheckBox() {
setStyleName(CLASSNAME);
addClickHandler(new ClickHandler() {
@@ -68,6 +78,10 @@ public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements
return;
}
+ focusHandlerRegistration = EventHelper.updateFocusHandler(this, client,
+ focusHandlerRegistration);
+ blurHandlerRegistration = EventHelper.updateBlurHandler(this, client, blurHandlerRegistration);
+
if (uidl.hasAttribute("error")) {
if (errorIndicatorElement == null) {
errorIndicatorElement = DOM.createSpan();
@@ -172,4 +186,12 @@ public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements
isBlockMode = true;
}
}
+
+ public void onFocus(FocusEvent arg0) {
+ client.updateVariable(id, EventId.FOCUS, "", true);
+ }
+
+ public void onBlur(BlurEvent arg0) {
+ client.updateVariable(id, EventId.BLUR, "", true);
+ }
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java
index 669b5b90ea..003b16cea1 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java
@@ -40,6 +40,7 @@ import com.google.gwt.user.client.ui.PopupPanel.PositionCallback;
import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;
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.Focusable;
import com.vaadin.terminal.gwt.client.Paintable;
import com.vaadin.terminal.gwt.client.UIDL;
@@ -542,8 +543,6 @@ public class VFilterSelect extends Composite implements Paintable, Field,
public static final int FILTERINGMODE_CONTAINS = 2;
private static final String CLASSNAME = "v-filterselect";
- public static final String FOCUS_EVENT_IDENTIFIER = "focus";
- public static final String BLUR_EVENT_IDENTIFIER = "blur";
protected int pageLength = 10;
@@ -1081,10 +1080,8 @@ public class VFilterSelect extends Composite implements Paintable, Field,
}
addStyleDependentName("focus");
- if (client.hasEventListeners(this, FOCUS_EVENT_IDENTIFIER)) {
- client
- .updateVariable(paintableId, FOCUS_EVENT_IDENTIFIER, "",
- true);
+ if (client.hasEventListeners(this, EventId.FOCUS)) {
+ client.updateVariable(paintableId, EventId.FOCUS, "", true);
}
}
@@ -1106,8 +1103,8 @@ public class VFilterSelect extends Composite implements Paintable, Field,
}
removeStyleDependentName("focus");
- if (client.hasEventListeners(this, BLUR_EVENT_IDENTIFIER)) {
- client.updateVariable(paintableId, BLUR_EVENT_IDENTIFIER, "", true);
+ if (client.hasEventListeners(this, EventId.BLUR)) {
+ client.updateVariable(paintableId, EventId.BLUR, "", true);
}
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java b/src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java
index ef7e183698..21e74bab09 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VNativeButton.java
@@ -5,8 +5,13 @@
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.Command;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.DeferredCommand;
@@ -14,12 +19,15 @@ 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.EventHelper;
+import com.vaadin.terminal.gwt.client.EventId;
import com.vaadin.terminal.gwt.client.Paintable;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VTooltip;
-public class VNativeButton extends Button implements Paintable, ClickHandler {
+public class VNativeButton extends Button implements Paintable, ClickHandler,
+ FocusHandler, BlurHandler {
public static final String CLASSNAME = "v-nativebutton";
@@ -42,6 +50,9 @@ public class VNativeButton extends Button implements Paintable, ClickHandler {
*/
private boolean clickPending;
+ private HandlerRegistration focusHandlerRegistration;
+ private HandlerRegistration blurHandlerRegistration;
+
public VNativeButton() {
setStyleName(CLASSNAME);
@@ -63,6 +74,11 @@ public class VNativeButton extends Button implements Paintable, ClickHandler {
return;
}
+ focusHandlerRegistration = EventHelper.updateFocusHandler(this, client,
+ focusHandlerRegistration);
+ blurHandlerRegistration = EventHelper.updateBlurHandler(this, client,
+ blurHandlerRegistration);
+
// Save details
this.client = client;
id = uidl.getId();
@@ -189,4 +205,12 @@ public class VNativeButton extends Button implements Paintable, ClickHandler {
clickPending = false;
}
+ public void onFocus(FocusEvent arg0) {
+ client.updateVariable(id, EventId.FOCUS, "", true);
+ }
+
+ public void onBlur(BlurEvent arg0) {
+ client.updateVariable(id, EventId.BLUR, "", true);
+ }
+
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VOptionGroup.java b/src/com/vaadin/terminal/gwt/client/ui/VOptionGroup.java
index a8ce1d124e..f49cd5098b 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VOptionGroup.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VOptionGroup.java
@@ -4,20 +4,32 @@
package com.vaadin.terminal.gwt.client.ui;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
+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.FocusEvent;
+import com.google.gwt.event.dom.client.FocusHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.FocusWidget;
import com.google.gwt.user.client.ui.Focusable;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.EventId;
import com.vaadin.terminal.gwt.client.UIDL;
-public class VOptionGroup extends VOptionGroupBase {
+public class VOptionGroup extends VOptionGroupBase implements FocusHandler,
+ BlurHandler {
public static final String CLASSNAME = "v-select-optiongroup";
@@ -25,12 +37,61 @@ public class VOptionGroup extends VOptionGroupBase {
private final Map optionsToKeys;
+ private boolean sendFocusEvents = false;
+ private boolean sendBlurEvents = false;
+ private List<HandlerRegistration> focusHandlers = null;
+ private List<HandlerRegistration> blurHandlers = null;
+
+ /**
+ * used to check whether a blur really was a blur of the complete
+ * optiongroup: if a control inside this optiongroup gains focus right after
+ * blur of another control inside this optiongroup (meaning: if onFocus
+ * fires after onBlur has fired), the blur and focus won't be sent to the
+ * server side as only a focus change inside this optiongroup occured
+ */
+ private boolean blurOccured = false;
+
public VOptionGroup() {
super(CLASSNAME);
panel = (Panel) optionsContainer;
optionsToKeys = new HashMap();
}
+ @Override
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ super.updateFromUIDL(uidl, client);
+
+ sendFocusEvents = client.hasEventListeners(this, EventId.FOCUS);
+ sendBlurEvents = client.hasEventListeners(this, EventId.BLUR);
+
+ if (focusHandlers != null) {
+ for (HandlerRegistration reg : focusHandlers) {
+ reg.removeHandler();
+ }
+ focusHandlers.clear();
+ focusHandlers = null;
+
+ for (HandlerRegistration reg : blurHandlers) {
+ reg.removeHandler();
+ }
+ blurHandlers.clear();
+ blurHandlers = null;
+ }
+
+ if (sendFocusEvents || sendBlurEvents) {
+ focusHandlers = new ArrayList<HandlerRegistration>();
+ blurHandlers = new ArrayList<HandlerRegistration>();
+
+ // add focus and blur handlers to checkboxes / radio buttons
+ for (Widget wid : panel) {
+ if (wid instanceof CheckBox) {
+ focusHandlers.add(((CheckBox) wid).addFocusHandler(this));
+ blurHandlers.add(((CheckBox) wid).addBlurHandler(this));
+ }
+ }
+ }
+ }
+
/*
* Return true if no elements were changed, false otherwise.
*/
@@ -96,4 +157,37 @@ public class VOptionGroup extends VOptionGroupBase {
}
}
+ public void onFocus(FocusEvent arg0) {
+ if (!blurOccured) {
+ // no blur occured before this focus event
+ // panel was blurred => fire the event to the server side if
+ // requested by server side
+ if (sendFocusEvents) {
+ client.updateVariable(id, EventId.FOCUS, "", true);
+ }
+ } else {
+ // blur occured before this focus event
+ // another control inside the panel (checkbox / radio box) was
+ // blurred => do not fire the focus and set blurOccured to false, so
+ // blur will not be fired, too
+ blurOccured = false;
+ }
+ }
+
+ public void onBlur(BlurEvent arg0) {
+ blurOccured = true;
+ if (sendBlurEvents) {
+ DeferredCommand.addCommand(new Command() {
+ public void execute() {
+ // check whether blurOccured still is true and then send the
+ // event out to the server
+ if (blurOccured) {
+ client.updateVariable(id, EventId.BLUR, "",
+ true);
+ blurOccured = false;
+ }
+ }
+ });
+ }
+ }
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextField.java b/src/com/vaadin/terminal/gwt/client/ui/VTextField.java
index f4bc96f66a..2f8d8edff9 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VTextField.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VTextField.java
@@ -18,6 +18,7 @@ import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.TextBoxBase;
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.Paintable;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
@@ -54,8 +55,6 @@ public class VTextField extends TextBoxBase implements Paintable, Field,
private static final String CLASSNAME_PROMPT = "prompt";
private static final String ATTR_INPUTPROMPT = "prompt";
- public static final String FOCUS_EVENT_IDENTIFIER = "focus";
- public static final String BLUR_EVENT_IDENTIFIER = "blur";
private String inputPrompt = null;
private boolean prompting = false;
@@ -185,10 +184,9 @@ public class VTextField extends TextBoxBase implements Paintable, Field,
boolean sendBlurEvent = false;
boolean sendValueChange = false;
- if (blurred
- && client.hasEventListeners(this, BLUR_EVENT_IDENTIFIER)) {
+ if (blurred && client.hasEventListeners(this, EventId.BLUR)) {
sendBlurEvent = true;
- client.updateVariable(id, BLUR_EVENT_IDENTIFIER, "", false);
+ client.updateVariable(id, EventId.BLUR, "", false);
}
String newText = getText();
@@ -225,9 +223,8 @@ public class VTextField extends TextBoxBase implements Paintable, Field,
}
}
focusedTextField = this;
- if (client.hasEventListeners(this, FOCUS_EVENT_IDENTIFIER)) {
- client.updateVariable(client.getPid(this), FOCUS_EVENT_IDENTIFIER,
- "", true);
+ if (client.hasEventListeners(this, EventId.FOCUS)) {
+ client.updateVariable(client.getPid(this), EventId.FOCUS, "", true);
}
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java b/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java
index cbb5f3d7fc..510676b3a4 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java
@@ -19,6 +19,7 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.ClientExceptionHandler;
import com.vaadin.terminal.gwt.client.ContainerResizedListener;
+import com.vaadin.terminal.gwt.client.EventId;
import com.vaadin.terminal.gwt.client.Focusable;
import com.vaadin.terminal.gwt.client.LocaleNotLoadedException;
import com.vaadin.terminal.gwt.client.LocaleService;
@@ -30,8 +31,6 @@ public class VTextualDate extends VDateField implements Paintable, Field,
private static final String PARSE_ERROR_CLASSNAME = CLASSNAME
+ "-parseerror";
- public static final String FOCUS_EVENT_IDENTIFIER = "focus";
- public static final String BLUR_EVENT_IDENTIFIER = "blur";
private final TextBox text;
@@ -60,8 +59,8 @@ public class VTextualDate extends VDateField implements Paintable, Field,
+ VTextField.CLASSNAME_FOCUS);
if (client != null
&& client.hasEventListeners(VTextualDate.this,
- FOCUS_EVENT_IDENTIFIER)) {
- client.updateVariable(id, FOCUS_EVENT_IDENTIFIER, "", true);
+ EventId.FOCUS)) {
+ client.updateVariable(id, EventId.FOCUS, "", true);
}
}
});
@@ -71,8 +70,8 @@ public class VTextualDate extends VDateField implements Paintable, Field,
+ VTextField.CLASSNAME_FOCUS);
if (client != null
&& client.hasEventListeners(VTextualDate.this,
- BLUR_EVENT_IDENTIFIER)) {
- client.updateVariable(id, BLUR_EVENT_IDENTIFIER, "", true);
+ EventId.BLUR)) {
+ client.updateVariable(id, EventId.BLUR, "", true);
}
}
});
diff --git a/src/com/vaadin/ui/Button.java b/src/com/vaadin/ui/Button.java
index 004bf43a8f..038186ce16 100644
--- a/src/com/vaadin/ui/Button.java
+++ b/src/com/vaadin/ui/Button.java
@@ -11,6 +11,11 @@ import java.util.Map;
import com.vaadin.data.Property;
import com.vaadin.event.ShortcutListener;
+import com.vaadin.event.FieldEvents;
+import com.vaadin.event.FieldEvents.BlurEvent;
+import com.vaadin.event.FieldEvents.BlurListener;
+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.gwt.client.ui.VButton;
@@ -26,7 +31,8 @@ import com.vaadin.ui.themes.BaseTheme;
*/
@SuppressWarnings("serial")
@ClientWidget(VButton.class)
-public class Button extends AbstractField {
+public class Button extends AbstractField implements FieldEvents.BlurNotifier,
+ FieldEvents.FocusNotifier {
/* Private members */
@@ -143,7 +149,7 @@ public class Button extends AbstractField {
* @param variables
*/
@Override
- public void changeVariables(Object source, Map variables) {
+ public void changeVariables(Object source, Map<String, Object> variables) {
super.changeVariables(source, variables);
if (!isReadOnly() && variables.containsKey("state")) {
@@ -173,6 +179,13 @@ public class Button extends AbstractField {
}
}
}
+
+ if (variables.containsKey(FocusEvent.EVENT_ID)) {
+ fireEvent(new FocusEvent(this));
+ }
+ if (variables.containsKey(BlurEvent.EVENT_ID)) {
+ fireEvent(new BlurEvent(this));
+ }
}
/**
@@ -348,6 +361,25 @@ public class Button extends AbstractField {
super.setInternalValue(newValue);
}
+ public void addListener(BlurListener listener) {
+ addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
+ BlurListener.blurMethod);
+ }
+
+ public void removeListener(BlurListener listener) {
+ removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
+ }
+
+ public void addListener(FocusListener listener) {
+ addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
+ FocusListener.focusMethod);
+ }
+
+ public void removeListener(FocusListener listener) {
+ removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
+
+ }
+
/*
* Actions
*/
diff --git a/src/com/vaadin/ui/DateField.java b/src/com/vaadin/ui/DateField.java
index fca0cc472c..45fd45716d 100644
--- a/src/com/vaadin/ui/DateField.java
+++ b/src/com/vaadin/ui/DateField.java
@@ -21,7 +21,6 @@ import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.gwt.client.ui.VDateField;
import com.vaadin.terminal.gwt.client.ui.VPopupCalendar;
-import com.vaadin.terminal.gwt.client.ui.VTextualDate;
/**
* <p>
@@ -93,9 +92,6 @@ public class DateField extends AbstractField implements
*/
protected static final String TYPE_INLINE = "inline";
- private static final String BLUR_EVENT = VTextualDate.BLUR_EVENT_IDENTIFIER;
- private static final String FOCUS_EVENT = VTextualDate.FOCUS_EVENT_IDENTIFIER;
-
/**
* Specified widget type.
*/
@@ -370,11 +366,11 @@ public class DateField extends AbstractField implements
}
}
- if (variables.containsKey(FOCUS_EVENT)) {
+ if (variables.containsKey(FocusEvent.EVENT_ID)) {
fireEvent(new FocusEvent(this));
}
- if (variables.containsKey(BLUR_EVENT)) {
+ if (variables.containsKey(BlurEvent.EVENT_ID)) {
fireEvent(new BlurEvent(this));
}
}
@@ -576,21 +572,21 @@ public class DateField extends AbstractField implements
}
public void addListener(FocusListener listener) {
- addListener(FOCUS_EVENT, FocusEvent.class, listener,
+ addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
FocusListener.focusMethod);
}
public void removeListener(FocusListener listener) {
- removeListener(FOCUS_EVENT, FocusEvent.class, listener);
+ removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
}
public void addListener(BlurListener listener) {
- addListener(BLUR_EVENT, BlurEvent.class, listener,
+ addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
BlurListener.blurMethod);
}
public void removeListener(BlurListener listener) {
- removeListener(BLUR_EVENT, BlurEvent.class, listener);
+ removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
}
/**
diff --git a/src/com/vaadin/ui/OptionGroup.java b/src/com/vaadin/ui/OptionGroup.java
index ab925f8785..d8baf0bf5c 100644
--- a/src/com/vaadin/ui/OptionGroup.java
+++ b/src/com/vaadin/ui/OptionGroup.java
@@ -5,8 +5,14 @@
package com.vaadin.ui;
import java.util.Collection;
+import java.util.Map;
import com.vaadin.data.Container;
+import com.vaadin.event.FieldEvents;
+import com.vaadin.event.FieldEvents.BlurEvent;
+import com.vaadin.event.FieldEvents.BlurListener;
+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.gwt.client.ui.VOptionGroup;
@@ -16,7 +22,8 @@ import com.vaadin.terminal.gwt.client.ui.VOptionGroup;
*/
@SuppressWarnings("serial")
@ClientWidget(VOptionGroup.class)
-public class OptionGroup extends AbstractSelect {
+public class OptionGroup extends AbstractSelect implements
+ FieldEvents.BlurNotifier, FieldEvents.FocusNotifier {
public OptionGroup() {
super();
@@ -40,4 +47,35 @@ public class OptionGroup extends AbstractSelect {
super.paintContent(target);
}
+ @Override
+ public void changeVariables(Object source, Map<String, Object> variables) {
+ super.changeVariables(source, variables);
+
+ if (variables.containsKey(FocusEvent.EVENT_ID)) {
+ fireEvent(new FocusEvent(this));
+ }
+ if (variables.containsKey(BlurEvent.EVENT_ID)) {
+ fireEvent(new BlurEvent(this));
+ }
+ }
+
+ public void addListener(BlurListener listener) {
+ addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
+ BlurListener.blurMethod);
+ }
+
+ public void removeListener(BlurListener listener) {
+ removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
+ }
+
+ public void addListener(FocusListener listener) {
+ addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
+ FocusListener.focusMethod);
+ }
+
+ public void removeListener(FocusListener listener) {
+ removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
+
+ }
+
}
diff --git a/src/com/vaadin/ui/Select.java b/src/com/vaadin/ui/Select.java
index 4174001d87..31c4ff6ef7 100644
--- a/src/com/vaadin/ui/Select.java
+++ b/src/com/vaadin/ui/Select.java
@@ -46,9 +46,6 @@ import com.vaadin.terminal.gwt.client.ui.VFilterSelect;
public class Select extends AbstractSelect implements AbstractSelect.Filtering,
FieldEvents.BlurNotifier, FieldEvents.FocusNotifier {
- private static final String BLUR_EVENT_ID = VFilterSelect.BLUR_EVENT_IDENTIFIER;
- private static final String FOCUS_EVENT_ID = VFilterSelect.FOCUS_EVENT_IDENTIFIER;
-
/**
* Holds value of property pageLength. 0 disables paging.
*/
@@ -432,10 +429,10 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering,
}
}
- if (variables.containsKey(FOCUS_EVENT_ID)) {
+ if (variables.containsKey(FocusEvent.EVENT_ID)) {
fireEvent(new FocusEvent(this));
}
- if (variables.containsKey(BLUR_EVENT_ID)) {
+ if (variables.containsKey(BlurEvent.EVENT_ID)) {
fireEvent(new BlurEvent(this));
}
@@ -496,21 +493,21 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering,
}
public void addListener(BlurListener listener) {
- addListener(BLUR_EVENT_ID, BlurEvent.class, listener,
+ addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
BlurListener.blurMethod);
}
public void removeListener(BlurListener listener) {
- removeListener(BLUR_EVENT_ID, BlurEvent.class, listener);
+ removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
}
public void addListener(FocusListener listener) {
- addListener(FOCUS_EVENT_ID, FocusEvent.class, listener,
+ addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
FocusListener.focusMethod);
}
public void removeListener(FocusListener listener) {
- removeListener(FOCUS_EVENT_ID, FocusEvent.class, listener);
+ removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
}
diff --git a/src/com/vaadin/ui/TextField.java b/src/com/vaadin/ui/TextField.java
index a3f76160a7..88451717ce 100644
--- a/src/com/vaadin/ui/TextField.java
+++ b/src/com/vaadin/ui/TextField.java
@@ -89,9 +89,6 @@ public class TextField extends AbstractField implements
*/
private int maxLength = -1;
- private static final String BLUR_EVENT = VTextField.BLUR_EVENT_IDENTIFIER;
- private static final String FOCUS_EVENT = VTextField.FOCUS_EVENT_IDENTIFIER;
-
/* Constructors */
/**
@@ -280,11 +277,11 @@ public class TextField extends AbstractField implements
}
}
- if (variables.containsKey(FOCUS_EVENT)) {
- fireFocus(variables.get(FOCUS_EVENT));
+ if (variables.containsKey(FocusEvent.EVENT_ID)) {
+ fireEvent(new FocusEvent(this));
}
- if (variables.containsKey(BLUR_EVENT)) {
- fireBlur(variables.get(BLUR_EVENT));
+ if (variables.containsKey(BlurEvent.EVENT_ID)) {
+ fireEvent(new BlurEvent(this));
}
}
@@ -619,30 +616,22 @@ public class TextField extends AbstractField implements
requestRepaint();
}
- private void fireFocus(Object object) {
- fireEvent(new FocusEvent(this));
- }
-
- private void fireBlur(Object object) {
- fireEvent(new BlurEvent(this));
- }
-
public void addListener(FocusListener listener) {
- addListener(FOCUS_EVENT, FocusEvent.class, listener,
+ addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
FocusListener.focusMethod);
}
public void removeListener(FocusListener listener) {
- removeListener(FOCUS_EVENT, FocusEvent.class, listener);
+ removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
}
public void addListener(BlurListener listener) {
- addListener(BLUR_EVENT, BlurEvent.class, listener,
+ addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
BlurListener.blurMethod);
}
public void removeListener(BlurListener listener) {
- removeListener(BLUR_EVENT, BlurEvent.class, listener);
+ removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
}
}
diff --git a/tests/src/com/vaadin/tests/components/FocusAndBlurListeners.java b/tests/src/com/vaadin/tests/components/FocusAndBlurListeners.java
index 32f1de752a..3ef26c7e1c 100644
--- a/tests/src/com/vaadin/tests/components/FocusAndBlurListeners.java
+++ b/tests/src/com/vaadin/tests/components/FocusAndBlurListeners.java
@@ -6,12 +6,18 @@ import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.event.FieldEvents.FocusListener;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.DateField;
import com.vaadin.ui.Label;
import com.vaadin.ui.Layout;
+import com.vaadin.ui.NativeButton;
+import com.vaadin.ui.OptionGroup;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
public class FocusAndBlurListeners extends TestBase {
@@ -37,26 +43,72 @@ public class FocusAndBlurListeners extends TestBase {
@Override
protected void setup() {
Layout l = getLayout();
+
TextField tf = new TextField("TextField");
l.addComponent(tf);
+
DateField df = new DateField("DateField");
l.addComponent(df);
ComboBox cb = new ComboBox("ComboBox");
-
l.addComponent(cb);
+ Button btn = new Button("Button");
+ l.addComponent(btn);
+
+ NativeButton nbtn = new NativeButton("NativeButton");
+ l.addComponent(nbtn);
+
+ CheckBox chkb = new CheckBox("CheckBox");
+ l.addComponent(chkb);
+
+ OptionGroup og = createOptionGroup("OptionGroup");
+ og.setMultiSelect(false);
+ l.addComponent(og);
+
+ final OptionGroup ogm = createOptionGroup("OptionGroup (multiselect)");
+ ogm.setMultiSelect(true);
+ l.addComponent(ogm);
+
+ btn.addListener(new ClickListener() {
+
+ private int i;
+
+ public void buttonClick(ClickEvent event) {
+ ogm.addItem("newItem" + i++);
+
+ }
+ });
+
tf.addListener(focusListener);
tf.addListener(blurListener);
df.addListener(focusListener);
df.addListener(blurListener);
cb.addListener(focusListener);
cb.addListener(blurListener);
+ btn.addListener(focusListener);
+ btn.addListener(blurListener);
+ nbtn.addListener(focusListener);
+ nbtn.addListener(blurListener);
+ chkb.addListener(focusListener);
+ chkb.addListener(blurListener);
+ og.addListener(focusListener);
+ og.addListener(blurListener);
+ ogm.addListener(focusListener);
+ ogm.addListener(blurListener);
l.addComponent(messages);
}
+ private OptionGroup createOptionGroup(String caption) {
+ OptionGroup og = new OptionGroup(caption);
+ og.addItem("Option 0");
+ og.addItem("Option 1");
+ og.addItem("Option 2");
+ return og;
+ }
+
@Override
protected String getDescription() {
return "Testing blur and focus listeners added in 6.2";