]> source.dussan.org Git - vaadin-framework.git/commitdiff
#4611 add getComponentCount() method for ComponentContainer implementations
authorHenri Sara <henri.sara@itmill.com>
Tue, 26 Oct 2010 14:58:06 +0000 (14:58 +0000)
committerHenri Sara <henri.sara@itmill.com>
Tue, 26 Oct 2010 14:58:06 +0000 (14:58 +0000)
svn changeset:15724/svn branch:6.5

src/com/vaadin/ui/AbsoluteLayout.java
src/com/vaadin/ui/AbstractOrderedLayout.java
src/com/vaadin/ui/CssLayout.java
src/com/vaadin/ui/CustomComponent.java
src/com/vaadin/ui/CustomLayout.java
src/com/vaadin/ui/GridLayout.java
src/com/vaadin/ui/Panel.java
src/com/vaadin/ui/PopupView.java
src/com/vaadin/ui/SplitPanel.java
src/com/vaadin/ui/TabSheet.java

index eca11b79849c61e5985176d6089e07e962b0ba18..538cc26c779a6c7149d9e5fca8509968a300518f 100644 (file)
@@ -50,6 +50,16 @@ public class AbsoluteLayout extends AbstractLayout {
         return components.iterator();
     }
 
+    /**
+     * Gets the number of contained components. Consistent with the iterator
+     * returned by {@link #getComponentIterator()}.
+     * 
+     * @return the number of contained components
+     */
+    public int getComponentCount() {
+        return components.size();
+    }
+
     /**
      * Replaces one component with another one. The new component inherits the
      * old components position.
index fd7e3a39d40f82cfaf26cddafeb4c3357d682abc..7bd52f8feb43028e6db29eedfb7a87ed15c7d10a 100644 (file)
@@ -126,6 +126,16 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
         return components.iterator();
     }
 
+    /**
+     * Gets the number of contained components. Consistent with the iterator
+     * returned by {@link #getComponentIterator()}.
+     * 
+     * @return the number of contained components
+     */
+    public int getComponentCount() {
+        return components.size();
+    }
+
     /**
      * Paints the content of this component.
      * 
index 4f8e00dec4575b81f22d423170fdbcc876198a87..db5bae678bb23478f546e150c1688f0027ba1fb7 100644 (file)
@@ -147,6 +147,16 @@ public class CssLayout extends AbstractLayout {
         return components.iterator();
     }
 
+    /**
+     * Gets the number of contained components. Consistent with the iterator
+     * returned by {@link #getComponentIterator()}.
+     * 
+     * @return the number of contained components
+     */
+    public int getComponentCount() {
+        return components.size();
+    }
+
     /**
      * Paints the content of this component.
      * 
index e06fb321e3366cae5fbff31fa4c7b3f4a59b04cb..a598b5b3bb8d879d492cbb36588a550000e6a98d 100644 (file)
@@ -174,6 +174,16 @@ public class CustomComponent extends AbstractComponentContainer {
         return new ComponentIterator();
     }
 
+    /**
+     * Gets the number of contained components. Consistent with the iterator
+     * returned by {@link #getComponentIterator()}.
+     * 
+     * @return the number of contained components (zero or one)
+     */
+    public int getComponentCount() {
+        return (root != null ? 1 : 0);
+    }
+
     /**
      * This method is not supported by CustomComponent.
      * 
index 1d08860b5023739bf054b08a6daa82a5abba68b0..0c11ff61146b52032e15a584b199ac4ded83324d 100644 (file)
@@ -184,6 +184,16 @@ public class CustomLayout extends AbstractLayout {
         return slots.values().iterator();
     }
 
+    /**
+     * Gets the number of contained components. Consistent with the iterator
+     * returned by {@link #getComponentIterator()}.
+     * 
+     * @return the number of contained components
+     */
+    public int getComponentCount() {
+        return slots.values().size();
+    }
+
     /**
      * Gets the child-component by its location.
      * 
index ae678198f9630826fddf3cf0035d331454e22de5..08e3168791d5ea217da122601ad9df094b661710 100644 (file)
@@ -398,6 +398,16 @@ public class GridLayout extends AbstractLayout implements
         return Collections.unmodifiableCollection(components).iterator();
     }
 
+    /**
+     * Gets the number of contained components. Consistent with the iterator
+     * returned by {@link #getComponentIterator()}.
+     * 
+     * @return the number of contained components
+     */
+    public int getComponentCount() {
+        return components.size();
+    }
+
     /**
      * Paints the contents of this component.
      * 
index 017855a9a0644695213a1dd240e85bd8f4bcc978..4d00cddfddb4e02f53059e86f45e12aa718d47b2 100644 (file)
@@ -282,8 +282,8 @@ public class Panel extends AbstractComponentContainer implements Scrollable,
     }
 
     /**
-     * Gets the component container iterator for going trough all the components
-     * in the container.
+     * Gets the component container iterator for going through all the
+     * components in the container.
      * 
      * @return the Iterator of the components inside the container.
      * @see com.vaadin.ui.ComponentContainer#getComponentIterator()
index 506b5380a7884930e7aa3f9bdcfc799138c37402..4e1f3875047a7595927136d00407b9bee8e88bfb 100644 (file)
@@ -226,6 +226,16 @@ public class PopupView extends AbstractComponentContainer {
         return new SingleComponentIterator(visibleComponent);
     }
 
+    /**
+     * Gets the number of contained components. Consistent with the iterator
+     * returned by {@link #getComponentIterator()}.
+     * 
+     * @return the number of contained components (zero or one)
+     */
+    public int getComponentCount() {
+        return (visibleComponent != null ? 1 : 0);
+    }
+
     /**
      * Not supported in this implementation.
      * 
index cc8a19aa3deabad78701ff874de489a2e2311a14..2fe5f43d97140a98b4d97400e9bd6e22ef9e4e09 100644 (file)
@@ -74,8 +74,7 @@ public class SplitPanel extends AbstractLayout {
         int i = 0;
 
         public boolean hasNext() {
-            if (i < (firstComponent == null ? 0 : 1)
-                    + (secondComponent == null ? 0 : 1)) {
+            if (i < getComponentCount()) {
                 return true;
             }
             return false;
@@ -230,6 +229,23 @@ public class SplitPanel extends AbstractLayout {
         return new ComponentIterator();
     }
 
+    /**
+     * Gets the number of contained components. Consistent with the iterator
+     * returned by {@link #getComponentIterator()}.
+     * 
+     * @return the number of contained components (zero, one or two)
+     */
+    public int getComponentCount() {
+        int count = 0;
+        if (firstComponent != null) {
+            count++;
+        }
+        if (secondComponent != null) {
+            count++;
+        }
+        return count;
+    }
+
     /**
      * Paints the content of this component.
      * 
index ffbacefce11f93ef2d3544c5618b22dbdf79fdc7..89a35ce69f63c1ca957933b4573fac4b09a128bc 100644 (file)
@@ -123,6 +123,16 @@ public class TabSheet extends AbstractComponentContainer {
         return Collections.unmodifiableList(components).iterator();
     }
 
+    /**
+     * Gets the number of contained components (tabs). Consistent with the
+     * iterator returned by {@link #getComponentIterator()}.
+     * 
+     * @return the number of contained components
+     */
+    public int getComponentCount() {
+        return components.size();
+    }
+
     /**
      * Removes a component and its corresponding tab.
      *