summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArtur Signell <artur.signell@itmill.com>2009-11-26 08:20:13 +0000
committerArtur Signell <artur.signell@itmill.com>2009-11-26 08:20:13 +0000
commit6bbd59bf720d8e71154e5741f54be2e1f8d9c15d (patch)
tree8e1ca5d7b98ec29084994f986ff3252563a29d68 /src
parent970b9f272357a389abb7cc7e0e35f07c42d9e7ac (diff)
downloadvaadin-framework-6bbd59bf720d8e71154e5741f54be2e1f8d9c15d.tar.gz
vaadin-framework-6bbd59bf720d8e71154e5741f54be2e1f8d9c15d.zip
Split test case into Layout click test and textfield focus/blur test + auto test for layout click.
Simplified ClickEventHandler/LayoutClickEventHandler and made them public so they are available to other components. svn changeset:10054/svn branch:event-framework-3234
Diffstat (limited to 'src')
-rw-r--r--src/TestListeners.java198
-rw-r--r--src/com/vaadin/terminal/gwt/client/MouseEventDetails.java12
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/ClickEventHandler.java14
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/LayoutClickEventHandler.java2
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java8
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java7
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java7
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java7
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VPanel.java7
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VTextField.java35
-rw-r--r--src/com/vaadin/ui/TextField.java14
11 files changed, 63 insertions, 248 deletions
diff --git a/src/TestListeners.java b/src/TestListeners.java
deleted file mode 100644
index 87255b4eac..0000000000
--- a/src/TestListeners.java
+++ /dev/null
@@ -1,198 +0,0 @@
-import com.vaadin.Application;
-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.event.LayoutEvents.LayoutClickEvent;
-import com.vaadin.event.LayoutEvents.LayoutClickListener;
-import com.vaadin.event.MouseEvents.ClickEvent;
-import com.vaadin.event.MouseEvents.ClickListener;
-import com.vaadin.terminal.ExternalResource;
-import com.vaadin.terminal.gwt.client.MouseEventDetails;
-import com.vaadin.ui.AbsoluteLayout;
-import com.vaadin.ui.Component;
-import com.vaadin.ui.Embedded;
-import com.vaadin.ui.GridLayout;
-import com.vaadin.ui.HorizontalLayout;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.Layout;
-import com.vaadin.ui.TextField;
-import com.vaadin.ui.VerticalLayout;
-import com.vaadin.ui.Window;
-
-public class TestListeners extends Application implements LayoutClickListener,
- ClickListener, FocusListener {
-
- @Override
- public void init() {
- Window w = new Window("main window");
- setMainWindow(w);
- HorizontalLayout hl = new HorizontalLayout();
- w.setContent(hl);
-
- final AbsoluteLayout al = new AbsoluteLayout();
- al.setWidth("200px");
- al.setHeight("200px");
- al.addComponent(new TextField("This is its caption",
- "This is a textfield"), "top: 20px; left: 0px; width: 100px;");
- al.addComponent(new TextField("Antoerh caption",
- "This is another textfield"),
- "top: 120px; left: 0px; width: 100px;");
-
- final LayoutClickListener lcl = new LayoutClickListener() {
-
- public void layoutClick(LayoutClickEvent event) {
- System.out.println("AL: Click on " + event.getChildComponent());
- // al.removeListener(this);
-
- }
- };
- al.addListener(lcl);
-
- final GridLayout vl = new GridLayout();
- vl.addComponent(al);
- vl.setSpacing(true);
- for (int i = 0; i < 10; i++) {
- vl.addComponent(new Label("Component " + i));
- ExternalResource res = new ExternalResource(
- "http://vaadin.com/image/image_gallery?uuid=07c1f6d5-2e94-4f4d-a707-b548bf22279d&groupId=10919&t=1241012632062");
- Embedded e = new Embedded("an image", res);
- e.setType(Embedded.TYPE_IMAGE);
- e.addListener(new ClickListener() {
-
- public void click(ClickEvent event) {
- TestListeners.this.click(event);
-
- }
- });
- // e.addListener(this);
- vl.addComponent(e);
- TextField tf = new TextField("tf");
- tf.setInputPrompt("Please enter a value");
-
- // tf.addListener(this);
- tf.addListener(new BlurListener() {
-
- public void blur(BlurEvent event) {
- getMainWindow().showNotification(
- "Blurred " + event.getComponent());
-
- }
- });
- tf.addListener(new FocusListener() {
-
- public void focus(FocusEvent event) {
- getMainWindow().showNotification(
- "Focused " + event.getComponent());
-
- }
- });
- vl.addComponent(tf);
- }
-
- // vl.addListener(this);
- vl.addListener(new LayoutClickListener() {
-
- public void layoutClick(LayoutClickEvent event) {
- TestListeners.this.layoutClick(event);
- vl.removeListener(this);
- }
- });
- vl.setMargin(true);
-
- hl.addComponent(vl);
- hl.addComponent(createClickableGridLayout());
- hl.addComponent(createClickableVerticalLayout());
- }
-
- private Layout createClickableGridLayout() {
-
- GridLayout gl = new GridLayout(3, 3);
- addContent(gl, 5);
-
- gl.addListener(new LayoutClickListener() {
-
- public void layoutClick(LayoutClickEvent event) {
- getMainWindow().showNotification(
- "GL-click on " + event.getChildComponent());
-
- }
- });
-
- return wrap(gl, "Clickable GridLayout");
- }
-
- private Layout createClickableVerticalLayout() {
-
- VerticalLayout gl = new VerticalLayout();
- addContent(gl, 5);
-
- gl.addListener(new LayoutClickListener() {
-
- public void layoutClick(LayoutClickEvent event) {
- getMainWindow().showNotification(
- "VL-click on " + event.getChildComponent());
-
- }
- });
-
- return wrap(gl, "Clickable VerticalLayout");
- }
-
- private void addContent(Layout gl, int nr) {
- for (int i = 1; i < nr; i++) {
- Label l = new Label("This is label " + i);
- l.setWidth(null);
- gl.addComponent(l);
- }
- for (int i = nr; i < nr * 2; i++) {
- gl.addComponent(new TextField("This is tf" + i, "this is tf " + i));
- }
- }
-
- private Layout wrap(Component c, String caption) {
- VerticalLayout vl = new VerticalLayout();
- Label l = new Label(caption);
- l.setWidth(null);
- vl.addComponent(l);
- vl.addComponent(c);
-
- return vl;
- }
-
- public void layoutClick(LayoutClickEvent event) {
- if (event.getChildComponent() == null) {
- getMainWindow().showNotification("You missed!");
- } else {
- getMainWindow().showNotification(
- "Clicked on " + event.getChildComponent() + "!");
- // getMainWindow().removeComponent(event.getChildComponent());
- }
-
- }
-
- public void click(ClickEvent event) {
- getMainWindow().showNotification(
- "Clicked on " + event.getComponent() + " using "
- + getButton(event));
- }
-
- private String getButton(ClickEvent event) {
- if (event.getButton() == MouseEventDetails.BUTTON_LEFT) {
- return "left";
- } else if (event.getButton() == MouseEventDetails.BUTTON_RIGHT) {
- return "right";
- } else {
- return "middle";
- }
- }
-
- public void focus(FocusEvent event) {
- TextField tf = (TextField) event.getComponent();
- // tf.addStyleName("a");
- // tf.setValue("");
- getMainWindow().requestRepaintAll();
-
- }
-
-}
diff --git a/src/com/vaadin/terminal/gwt/client/MouseEventDetails.java b/src/com/vaadin/terminal/gwt/client/MouseEventDetails.java
index 3a9a64657c..0a20b112d3 100644
--- a/src/com/vaadin/terminal/gwt/client/MouseEventDetails.java
+++ b/src/com/vaadin/terminal/gwt/client/MouseEventDetails.java
@@ -90,6 +90,18 @@ public class MouseEventDetails {
return instance;
}
+ public String getButtonName() {
+ if (button == BUTTON_LEFT) {
+ return "left";
+ } else if (button == BUTTON_RIGHT) {
+ return "right";
+ } else if (button == BUTTON_MIDDLE) {
+ return "middle";
+ }
+
+ return "";
+ }
+
public Class<MouseEventDetails> getType() {
return MouseEventDetails.class;
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/ClickEventHandler.java b/src/com/vaadin/terminal/gwt/client/ui/ClickEventHandler.java
index aae416ba6a..0e60246d48 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/ClickEventHandler.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/ClickEventHandler.java
@@ -19,8 +19,8 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.terminal.gwt.client.Paintable;
-abstract class ClickEventHandler implements ClickHandler, DoubleClickHandler,
- ContextMenuHandler, MouseUpHandler {
+public abstract class ClickEventHandler implements ClickHandler,
+ DoubleClickHandler, ContextMenuHandler, MouseUpHandler {
private HandlerRegistration clickHandlerRegistration;
private HandlerRegistration doubleClickHandlerRegistration;
@@ -29,13 +29,15 @@ abstract class ClickEventHandler implements ClickHandler, DoubleClickHandler,
protected String clickEventIdentifier;
protected Paintable paintable;
+ private ApplicationConnection client;
- ClickEventHandler(Paintable paintable, String clickEventIdentifier) {
+ public ClickEventHandler(Paintable paintable, String clickEventIdentifier) {
this.paintable = paintable;
this.clickEventIdentifier = clickEventIdentifier;
}
- public void handleHandlerRegistration() {
+ public void handleEventHandlerRegistration(ApplicationConnection client) {
+ this.client = client;
// Handle registering/unregistering of click handler depending on if
// server side listeners have been added or removed.
if (hasEventListener()) {
@@ -70,7 +72,9 @@ abstract class ClickEventHandler implements ClickHandler, DoubleClickHandler,
protected abstract <H extends EventHandler> HandlerRegistration registerHandler(
final H handler, DomEvent.Type<H> type);
- public abstract ApplicationConnection getApplicationConnection();
+ protected ApplicationConnection getApplicationConnection() {
+ return client;
+ }
public boolean hasEventListener() {
return getApplicationConnection().hasEventListeners(paintable,
diff --git a/src/com/vaadin/terminal/gwt/client/ui/LayoutClickEventHandler.java b/src/com/vaadin/terminal/gwt/client/ui/LayoutClickEventHandler.java
index c19d0b1c7d..8cf55ca952 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/LayoutClickEventHandler.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/LayoutClickEventHandler.java
@@ -9,7 +9,7 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.terminal.gwt.client.Paintable;
-abstract class LayoutClickEventHandler extends ClickEventHandler {
+public abstract class LayoutClickEventHandler extends ClickEventHandler {
LayoutClickEventHandler(Paintable paintable, String clickEventIdentifier) {
super(paintable, clickEventIdentifier);
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java
index a83df137f4..63f865082b 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java
@@ -56,11 +56,6 @@ public class VAbsoluteLayout extends ComplexPanel implements Container {
this, CLICK_EVENT_IDENTIFIER) {
@Override
- public ApplicationConnection getApplicationConnection() {
- return client;
- }
-
- @Override
protected Paintable getChildComponent(Element element) {
return getComponent(element);
}
@@ -154,7 +149,7 @@ public class VAbsoluteLayout extends ComplexPanel implements Container {
return;
}
- clickEventHandler.handleHandlerRegistration();
+ clickEventHandler.handleEventHandlerRegistration(client);
HashSet<String> unrenderedPids = new HashSet<String>(
pidToComponentWrappper.keySet());
@@ -417,7 +412,6 @@ public class VAbsoluteLayout extends ComplexPanel implements Container {
}
}
-
private Paintable getComponent(Element target) {
while (target != null && target != canvas) {
Paintable paintable = client.getPaintable(target);
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java b/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java
index adf8d7c354..871e2ae35f 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java
@@ -40,11 +40,6 @@ public class VEmbedded extends HTML implements Paintable {
CLICK_EVENT_IDENTIFIER) {
@Override
- public ApplicationConnection getApplicationConnection() {
- return client;
- }
-
- @Override
protected <H extends EventHandler> HandlerRegistration registerHandler(
H handler, Type<H> type) {
return addDomHandler(handler, type);
@@ -64,7 +59,7 @@ public class VEmbedded extends HTML implements Paintable {
boolean clearBrowserElement = true;
- clickEventHandler.handleHandlerRegistration();
+ clickEventHandler.handleEventHandlerRegistration(client);
if (uidl.hasAttribute("type")) {
final String type = uidl.getStringAttribute("type");
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java
index c057135862..2dae5626d6 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java
@@ -76,11 +76,6 @@ public class VGridLayout extends SimplePanel implements Paintable, Container {
this, CLICK_EVENT_IDENTIFIER) {
@Override
- public ApplicationConnection getApplicationConnection() {
- return client;
- }
-
- @Override
protected Paintable getChildComponent(Element element) {
return getComponent(element);
}
@@ -112,7 +107,7 @@ public class VGridLayout extends SimplePanel implements Paintable, Container {
rendering = false;
return;
}
- clickEventHandler.handleHandlerRegistration();
+ clickEventHandler.handleEventHandlerRegistration(client);
canvas.setWidth("0px");
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java
index 0f548680a1..cb5624142f 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java
@@ -56,11 +56,6 @@ public class VOrderedLayout extends CellBasedLayout {
this, CLICK_EVENT_IDENTIFIER) {
@Override
- public ApplicationConnection getApplicationConnection() {
- return client;
- }
-
- @Override
protected Paintable getChildComponent(Element element) {
return getComponent(element);
}
@@ -100,7 +95,7 @@ public class VOrderedLayout extends CellBasedLayout {
return;
}
- clickEventHandler.handleHandlerRegistration();
+ clickEventHandler.handleEventHandlerRegistration(client);
if (allowOrientationUpdate) {
handleOrientationUpdate(uidl);
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPanel.java b/src/com/vaadin/terminal/gwt/client/ui/VPanel.java
index e6386e7a7c..8b054160a8 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VPanel.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VPanel.java
@@ -80,11 +80,6 @@ public class VPanel extends SimplePanel implements Container {
CLICK_EVENT_IDENTIFIER) {
@Override
- public ApplicationConnection getApplicationConnection() {
- return client;
- }
-
- @Override
protected <H extends EventHandler> HandlerRegistration registerHandler(
H handler, Type<H> type) {
return addDomHandler(handler, type);
@@ -126,7 +121,7 @@ public class VPanel extends SimplePanel implements Container {
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
rendering = true;
if (!uidl.hasAttribute("cached")) {
- clickEventHandler.handleHandlerRegistration();
+ clickEventHandler.handleEventHandlerRegistration(client);
// Handle caption displaying and style names, prior generics.
// Affects size
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextField.java b/src/com/vaadin/terminal/gwt/client/ui/VTextField.java
index 5e5d0bf687..fe2c03496c 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VTextField.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VTextField.java
@@ -169,13 +169,39 @@ public class VTextField extends TextBoxBase implements Paintable, Field,
}
public void onChange(ChangeEvent event) {
+ valueChange(false);
+ }
+
+ /**
+ * Called when the field value might have changed and/or the field was
+ * blurred. These are combined so the blur event is sent in the same batch
+ * as a possible value change event (these are often connected).
+ *
+ * @param blurred
+ * true if the field was blurred
+ */
+ public void valueChange(boolean blurred) {
if (client != null && id != null) {
+ boolean sendBlurEvent = false;
+ boolean sendValueChange = false;
+
+ if (blurred
+ && client.hasEventListeners(this, BLUR_EVENT_IDENTIFIER)) {
+ sendBlurEvent = true;
+ client.updateVariable(id, BLUR_EVENT_IDENTIFIER, "", false);
+ }
+
String newText = getText();
if (!prompting && newText != null
&& !newText.equals(valueBeforeEdit)) {
- client.updateVariable(id, "text", getText(), immediate);
+ sendValueChange = immediate;
+ client.updateVariable(id, "text", getText(), false);
valueBeforeEdit = newText;
}
+
+ if (sendBlurEvent || sendValueChange) {
+ client.sendPendingVariableChanges();
+ }
}
}
@@ -213,11 +239,8 @@ public class VTextField extends TextBoxBase implements Paintable, Field,
setText(inputPrompt);
addStyleDependentName(CLASSNAME_PROMPT);
}
- onChange(null);
- if (client.hasEventListeners(this, BLUR_EVENT_IDENTIFIER)) {
- client.updateVariable(client.getPid(this), BLUR_EVENT_IDENTIFIER,
- "", true);
- }
+
+ valueChange(true);
}
private void setPrompting(boolean prompting) {
diff --git a/src/com/vaadin/ui/TextField.java b/src/com/vaadin/ui/TextField.java
index ee2f1097f3..59cf6640ce 100644
--- a/src/com/vaadin/ui/TextField.java
+++ b/src/com/vaadin/ui/TextField.java
@@ -248,13 +248,6 @@ public class TextField extends AbstractField {
super.changeVariables(source, variables);
- if (variables.containsKey(FOCUS_EVENT)) {
- fireFocus(variables.get(FOCUS_EVENT));
- }
- if (variables.containsKey(BLUR_EVENT)) {
- fireBlur(variables.get(BLUR_EVENT));
- }
-
// Sets the text
if (variables.containsKey("text") && !isReadOnly()) {
@@ -285,6 +278,13 @@ public class TextField extends AbstractField {
}
}
+ if (variables.containsKey(FOCUS_EVENT)) {
+ fireFocus(variables.get(FOCUS_EVENT));
+ }
+ if (variables.containsKey(BLUR_EVENT)) {
+ fireBlur(variables.get(BLUR_EVENT));
+ }
+
}
/* Text field configuration */