* 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;
}
* <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
return null;
}
+ /**
+ * 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.
*
}
/**
- * 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);
}
}
}
private Paintable getComponent(Element element) {
- return Util.getChildPaintableForElement(client, VCssLayout.this,
- element);
+ return Util
+ .getPaintableForElement(client, VCssLayout.this, element);
}
}
}
/**
- * 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);
}
}
}
/**
- * 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);
}
}
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));
}
/**
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));
}
/**
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));
}
/**
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));
}
/**