summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenri Sara <henri.sara@itmill.com>2011-02-23 11:10:59 +0000
committerHenri Sara <henri.sara@itmill.com>2011-02-23 11:10:59 +0000
commit097fd02fbfbfdf241081087bb055a800398433d3 (patch)
tree6b2a949550b19366b009078b38aa2e78fb12ead9
parent33f6cd47adb0dcc72bdfce3cdeeb6c93a510bea4 (diff)
downloadvaadin-framework-097fd02fbfbfdf241081087bb055a800398433d3.tar.gz
vaadin-framework-097fd02fbfbfdf241081087bb055a800398433d3.zip
#6493 API for getting the deepest clicked component in layout click events
svn changeset:17390/svn branch:6.5
-rw-r--r--src/com/vaadin/event/LayoutEvents.java31
-rw-r--r--src/com/vaadin/terminal/gwt/client/Util.java55
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java10
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java4
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java10
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java10
-rw-r--r--src/com/vaadin/ui/AbsoluteLayout.java9
-rw-r--r--src/com/vaadin/ui/AbstractOrderedLayout.java9
-rw-r--r--src/com/vaadin/ui/CssLayout.java9
-rw-r--r--src/com/vaadin/ui/GridLayout.java9
10 files changed, 128 insertions, 28 deletions
diff --git a/src/com/vaadin/event/LayoutEvents.java b/src/com/vaadin/event/LayoutEvents.java
index e35d527347..0e77bb82ed 100644
--- a/src/com/vaadin/event/LayoutEvents.java
+++ b/src/com/vaadin/event/LayoutEvents.java
@@ -31,18 +31,43 @@ public interface LayoutEvents {
* An event fired when the layout has been clicked. The event contains
* information about the target layout (component) and the child component
* that was clicked. If no child component was found it is set to null.
- *
*/
public static class LayoutClickEvent extends ClickEvent {
- private Component childComponent;
+ private final Component clickedComponent;
+ private final Component childComponent;
public LayoutClickEvent(Component source,
- MouseEventDetails mouseEventDetails, Component childComponent) {
+ MouseEventDetails mouseEventDetails,
+ Component clickedComponent, Component childComponent) {
super(source, mouseEventDetails);
+ this.clickedComponent = clickedComponent;
this.childComponent = childComponent;
}
+ /**
+ * Returns the component that was clicked, which is somewhere inside the
+ * parent layout on which the listener was registered.
+ *
+ * For the direct child component of the layout, see
+ * {@link #getChildComponent()}.
+ *
+ * @return clicked {@link Component}, null if none found
+ */
+ public Component getClickedComponent() {
+ return clickedComponent;
+ }
+
+ /**
+ * Returns the direct child component of the layout which contains the
+ * clicked component.
+ *
+ * For the clicked component inside that child component of the layout,
+ * see {@link #getClickedComponent()}.
+ *
+ * @return direct child {@link Component} of the layout which contains
+ * the clicked Component, null if none found
+ */
public Component getChildComponent() {
return childComponent;
}
diff --git a/src/com/vaadin/terminal/gwt/client/Util.java b/src/com/vaadin/terminal/gwt/client/Util.java
index 2a92a6c1fd..00519a5c15 100644
--- a/src/com/vaadin/terminal/gwt/client/Util.java
+++ b/src/com/vaadin/terminal/gwt/client/Util.java
@@ -816,6 +816,11 @@ public class Util {
* <literal>element</literal> is not part of any child component, null is
* returned.
*
+ * This method returns the immediate child of the parent that contains the
+ * element. See
+ * {@link #getPaintableForElement(ApplicationConnection, Container, Element)}
+ * for the deepest nested paintable of parent that contains the element.
+ *
* @param client
* A reference to ApplicationConnection
* @param parent
@@ -855,6 +860,56 @@ public class Util {
}
/**
+ * Locates the nested child component of <literal>parent</literal> which
+ * contains the element <literal>element</literal>. The child component is
+ * also returned if "element" is part of its caption. If
+ * <literal>element</literal> is not part of any child component, null is
+ * returned.
+ *
+ * This method returns the deepest nested Paintable. See
+ * {@link #getChildPaintableForElement(ApplicationConnection, Container, Element)}
+ * for the immediate child component of parent that contains the element.
+ *
+ * @param client
+ * A reference to ApplicationConnection
+ * @param parent
+ * The widget that contains <literal>element</literal>.
+ * @param element
+ * An element that is a sub element of the parent
+ * @return The Paintable which the element is a part of. Null if the element
+ * does not belong to a child.
+ */
+ public static Paintable getPaintableForElement(
+ ApplicationConnection client, Container parent, Element element) {
+ Element rootElement = ((Widget) parent).getElement();
+ while (element != null && element != rootElement) {
+ Paintable paintable = client.getPaintable(element);
+ if (paintable == null) {
+ String ownerPid = VCaption.getCaptionOwnerPid(element);
+ if (ownerPid != null) {
+ paintable = client.getPaintable(ownerPid);
+ }
+ }
+
+ if (paintable != null) {
+ // check that inside the rootElement
+ while (element != null && element != rootElement) {
+ element = (Element) element.getParentElement();
+ }
+ if (element != rootElement) {
+ return null;
+ } else {
+ return paintable;
+ }
+ }
+
+ element = (Element) element.getParentElement();
+ }
+
+ return null;
+ }
+
+ /**
* Will (attempt) to focus the given DOM Element.
*
* @param el
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java
index 50e33c4c19..747b7eab51 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java
@@ -427,17 +427,17 @@ public class VAbsoluteLayout extends ComplexPanel implements Container {
}
/**
- * Returns the child component which contains "element". The child component
- * is also returned if "element" is part of its caption.
+ * Returns the deepest nested child component which contains "element". The
+ * child component is also returned if "element" is part of its caption.
*
* @param element
- * An element that is a sub element of the root element in this
- * layout
+ * An element that is a nested sub element of the root element in
+ * this layout
* @return The Paintable which the element is a part of. Null if the element
* belongs to the layout and not to a child.
*/
private Paintable getComponent(Element element) {
- return Util.getChildPaintableForElement(client, this, element);
+ return Util.getPaintableForElement(client, this, element);
}
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java
index e0a74735b7..98677a8556 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java
@@ -253,8 +253,8 @@ public class VCssLayout extends SimplePanel implements Paintable, Container {
}
private Paintable getComponent(Element element) {
- return Util.getChildPaintableForElement(client, VCssLayout.this,
- element);
+ return Util
+ .getPaintableForElement(client, VCssLayout.this, element);
}
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java
index e5e3efd7c8..8556990450 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java
@@ -1111,17 +1111,17 @@ public class VGridLayout extends SimplePanel implements Paintable, Container {
}
/**
- * Returns the child component which contains "element". The child component
- * is also returned if "element" is part of its caption.
+ * Returns the deepest nested child component which contains "element". The
+ * child component is also returned if "element" is part of its caption.
*
* @param element
- * An element that is a sub element of the root element in this
- * layout
+ * An element that is a nested sub element of the root element in
+ * this layout
* @return The Paintable which the element is a part of. Null if the element
* belongs to the layout and not to a child.
*/
private Paintable getComponent(Element element) {
- return Util.getChildPaintableForElement(client, this, element);
+ return Util.getPaintableForElement(client, this, element);
}
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java
index bf64219a7b..4c5a563d6d 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java
@@ -954,17 +954,17 @@ public class VOrderedLayout extends CellBasedLayout {
}
/**
- * Returns the child component which contains "element". The child component
- * is also returned if "element" is part of its caption.
+ * Returns the deepest nested child component which contains "element". The
+ * child component is also returned if "element" is part of its caption.
*
* @param element
- * An element that is a sub element of the root element in this
- * layout
+ * An element that is a nested sub element of the root element in
+ * this layout
* @return The Paintable which the element is a part of. Null if the element
* belongs to the layout and not to a child.
*/
private Paintable getComponent(Element element) {
- return Util.getChildPaintableForElement(client, this, element);
+ return Util.getPaintableForElement(client, this, element);
}
}
diff --git a/src/com/vaadin/ui/AbsoluteLayout.java b/src/com/vaadin/ui/AbsoluteLayout.java
index 538cc26c77..a30cae529b 100644
--- a/src/com/vaadin/ui/AbsoluteLayout.java
+++ b/src/com/vaadin/ui/AbsoluteLayout.java
@@ -585,9 +585,14 @@ public class AbsoluteLayout extends AbstractLayout {
private void fireClick(Map<String, Object> parameters) {
MouseEventDetails mouseDetails = MouseEventDetails
.deSerialize((String) parameters.get("mouseDetails"));
- Component childComponent = (Component) parameters.get("component");
+ Component clickedComponent = (Component) parameters.get("component");
+ Component childComponent = clickedComponent;
+ while (childComponent != null && !components.contains(childComponent)) {
+ childComponent = childComponent.getParent();
+ }
- fireEvent(new LayoutClickEvent(this, mouseDetails, childComponent));
+ fireEvent(new LayoutClickEvent(this, mouseDetails, clickedComponent,
+ childComponent));
}
/**
diff --git a/src/com/vaadin/ui/AbstractOrderedLayout.java b/src/com/vaadin/ui/AbstractOrderedLayout.java
index 7bd52f8feb..28d6f66792 100644
--- a/src/com/vaadin/ui/AbstractOrderedLayout.java
+++ b/src/com/vaadin/ui/AbstractOrderedLayout.java
@@ -363,9 +363,14 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
private void fireClick(Map<String, Object> parameters) {
MouseEventDetails mouseDetails = MouseEventDetails
.deSerialize((String) parameters.get("mouseDetails"));
- Component childComponent = (Component) parameters.get("component");
+ Component clickedComponent = (Component) parameters.get("component");
+ Component childComponent = clickedComponent;
+ while (childComponent != null && !components.contains(childComponent)) {
+ childComponent = childComponent.getParent();
+ }
- fireEvent(new LayoutClickEvent(this, mouseDetails, childComponent));
+ fireEvent(new LayoutClickEvent(this, mouseDetails, clickedComponent,
+ childComponent));
}
/**
diff --git a/src/com/vaadin/ui/CssLayout.java b/src/com/vaadin/ui/CssLayout.java
index db5bae678b..5953ba5181 100644
--- a/src/com/vaadin/ui/CssLayout.java
+++ b/src/com/vaadin/ui/CssLayout.java
@@ -264,9 +264,14 @@ public class CssLayout extends AbstractLayout {
private void fireClick(Map<String, Object> parameters) {
MouseEventDetails mouseDetails = MouseEventDetails
.deSerialize((String) parameters.get("mouseDetails"));
- Component childComponent = (Component) parameters.get("component");
+ Component clickedComponent = (Component) parameters.get("component");
+ Component childComponent = clickedComponent;
+ while (childComponent != null && !components.contains(childComponent)) {
+ childComponent = childComponent.getParent();
+ }
- fireEvent(new LayoutClickEvent(this, mouseDetails, childComponent));
+ fireEvent(new LayoutClickEvent(this, mouseDetails, clickedComponent,
+ childComponent));
}
/**
diff --git a/src/com/vaadin/ui/GridLayout.java b/src/com/vaadin/ui/GridLayout.java
index fc16daa7c7..503b3d2b8e 100644
--- a/src/com/vaadin/ui/GridLayout.java
+++ b/src/com/vaadin/ui/GridLayout.java
@@ -1392,9 +1392,14 @@ public class GridLayout extends AbstractLayout implements
private void fireClick(Map<String, Object> parameters) {
MouseEventDetails mouseDetails = MouseEventDetails
.deSerialize((String) parameters.get("mouseDetails"));
- Component childComponent = (Component) parameters.get("component");
+ Component clickedComponent = (Component) parameters.get("component");
+ Component childComponent = clickedComponent;
+ while (childComponent != null && !components.contains(childComponent)) {
+ childComponent = childComponent.getParent();
+ }
- fireEvent(new LayoutClickEvent(this, mouseDetails, childComponent));
+ fireEvent(new LayoutClickEvent(this, mouseDetails, clickedComponent,
+ childComponent));
}
/**