diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-02-07 13:19:09 +0200 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-02-07 13:19:09 +0200 |
commit | de6b8ddf4184b30a6588cc57e185ebc782a11693 (patch) | |
tree | 49830a565b5e1a39b6fc717e9bd66714c4b2810f /src | |
parent | 787eedd131c5694a7db55d3b89bf4ddb4a6d673f (diff) | |
download | vaadin-framework-de6b8ddf4184b30a6588cc57e185ebc782a11693.tar.gz vaadin-framework-de6b8ddf4184b30a6588cc57e185ebc782a11693.zip |
Add VPaintableWidgetContainer.getChildren() (#8323)
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/VPaintableWidgetContainer.java | 4 | ||||
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidgetContainer.java | 68 |
2 files changed, 54 insertions, 18 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/VPaintableWidgetContainer.java b/src/com/vaadin/terminal/gwt/client/VPaintableWidgetContainer.java index baf266546d..da48eeb2fb 100644 --- a/src/com/vaadin/terminal/gwt/client/VPaintableWidgetContainer.java +++ b/src/com/vaadin/terminal/gwt/client/VPaintableWidgetContainer.java @@ -4,6 +4,8 @@ package com.vaadin.terminal.gwt.client; +import java.util.Collection; + import com.google.gwt.user.client.ui.HasWidgets; /** @@ -40,6 +42,6 @@ public interface VPaintableWidgetContainer extends VPaintableWidget { * @return A collection of children for this paintable. An empty collection * if there are no children. */ - // public Collection<VPaintableWidget> getChildren(); + public Collection<VPaintableWidget> getChildren(); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidgetContainer.java b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidgetContainer.java index 1f78c02f58..87bf245217 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidgetContainer.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidgetContainer.java @@ -1,17 +1,51 @@ -/* -@VaadinApache2LicenseForJavaFiles@ - */ -package com.vaadin.terminal.gwt.client.ui; - -import com.vaadin.terminal.gwt.client.VPaintableWidgetContainer; - -public abstract class VAbstractPaintableWidgetContainer extends - VAbstractPaintableWidget implements VPaintableWidgetContainer { - - /** - * Default constructor - */ - public VAbstractPaintableWidgetContainer() { - } - -} +/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+package com.vaadin.terminal.gwt.client.ui;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import com.google.gwt.user.client.ui.HasWidgets;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.VPaintableMap;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+import com.vaadin.terminal.gwt.client.VPaintableWidgetContainer;
+
+public abstract class VAbstractPaintableWidgetContainer extends
+ VAbstractPaintableWidget implements VPaintableWidgetContainer {
+
+ /**
+ * Default constructor
+ */
+ public VAbstractPaintableWidgetContainer() {
+ }
+
+ public Collection<VPaintableWidget> getChildren() {
+ Collection<VPaintableWidget> children = new ArrayList<VPaintableWidget>();
+
+ addDescendantPaintables(getWidgetForPaintable(), children,
+ VPaintableMap.get(getConnection()));
+
+ return children;
+ }
+
+ private static void addDescendantPaintables(Widget widget,
+ Collection<VPaintableWidget> paintables, VPaintableMap paintableMap) {
+ // FIXME: Store hierarchy instead of doing lookup every time
+
+ if (widget instanceof HasWidgets) {
+ for (Widget child : (HasWidgets) widget) {
+ VPaintableWidget paintable = paintableMap.getPaintable(child);
+ if (paintable != null) {
+ // If child is a paintable, add it to the collection
+ paintables.add(paintable);
+ } else {
+ // Else keep looking for paintables inside the child widget
+ addDescendantPaintables(child, paintables, paintableMap);
+ }
+ }
+ }
+ }
+
+}
|