]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add VPaintableWidgetContainer.getChildren() (#8323)
authorLeif Åstrand <leif@vaadin.com>
Tue, 7 Feb 2012 11:19:09 +0000 (13:19 +0200)
committerLeif Åstrand <leif@vaadin.com>
Tue, 7 Feb 2012 11:19:09 +0000 (13:19 +0200)
src/com/vaadin/terminal/gwt/client/VPaintableWidgetContainer.java
src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidgetContainer.java

index baf266546dd26ea8e26fc1a9d2b11415475fefca..da48eeb2fb47f51e31495afe7c2da0a6bd8124e7 100644 (file)
@@ -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();
 
 }
index 1f78c02f58fe0875f0b9a1ba77dcb6acdf38e418..87bf245217207327325a8499fc1e60d7985a25e0 100644 (file)
@@ -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() {
-    }
-
-}
+/*\r
+@VaadinApache2LicenseForJavaFiles@\r
+ */\r
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import com.google.gwt.user.client.ui.HasWidgets;\r
+import com.google.gwt.user.client.ui.Widget;\r
+import com.vaadin.terminal.gwt.client.VPaintableMap;\r
+import com.vaadin.terminal.gwt.client.VPaintableWidget;\r
+import com.vaadin.terminal.gwt.client.VPaintableWidgetContainer;\r
+\r
+public abstract class VAbstractPaintableWidgetContainer extends\r
+        VAbstractPaintableWidget implements VPaintableWidgetContainer {\r
+\r
+    /**\r
+     * Default constructor\r
+     */\r
+    public VAbstractPaintableWidgetContainer() {\r
+    }\r
+\r
+    public Collection<VPaintableWidget> getChildren() {\r
+        Collection<VPaintableWidget> children = new ArrayList<VPaintableWidget>();\r
+\r
+        addDescendantPaintables(getWidgetForPaintable(), children,\r
+                VPaintableMap.get(getConnection()));\r
+\r
+        return children;\r
+    }\r
+\r
+    private static void addDescendantPaintables(Widget widget,\r
+            Collection<VPaintableWidget> paintables, VPaintableMap paintableMap) {\r
+        // FIXME: Store hierarchy instead of doing lookup every time\r
+\r
+        if (widget instanceof HasWidgets) {\r
+            for (Widget child : (HasWidgets) widget) {\r
+                VPaintableWidget paintable = paintableMap.getPaintable(child);\r
+                if (paintable != null) {\r
+                    // If child is a paintable, add it to the collection\r
+                    paintables.add(paintable);\r
+                } else {\r
+                    // Else keep looking for paintables inside the child widget\r
+                    addDescendantPaintables(child, paintables, paintableMap);\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+}\r