From 089f43092d7bf6f99e5abca56415d8cf6fcc3cf2 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Tue, 26 Oct 2010 14:58:06 +0000 Subject: [PATCH] #4611 add getComponentCount() method for ComponentContainer implementations svn changeset:15724/svn branch:6.5 --- src/com/vaadin/ui/AbsoluteLayout.java | 10 ++++++++++ src/com/vaadin/ui/AbstractOrderedLayout.java | 10 ++++++++++ src/com/vaadin/ui/CssLayout.java | 10 ++++++++++ src/com/vaadin/ui/CustomComponent.java | 10 ++++++++++ src/com/vaadin/ui/CustomLayout.java | 10 ++++++++++ src/com/vaadin/ui/GridLayout.java | 10 ++++++++++ src/com/vaadin/ui/Panel.java | 4 ++-- src/com/vaadin/ui/PopupView.java | 10 ++++++++++ src/com/vaadin/ui/SplitPanel.java | 20 ++++++++++++++++++-- src/com/vaadin/ui/TabSheet.java | 10 ++++++++++ 10 files changed, 100 insertions(+), 4 deletions(-) diff --git a/src/com/vaadin/ui/AbsoluteLayout.java b/src/com/vaadin/ui/AbsoluteLayout.java index eca11b7984..538cc26c77 100644 --- a/src/com/vaadin/ui/AbsoluteLayout.java +++ b/src/com/vaadin/ui/AbsoluteLayout.java @@ -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. diff --git a/src/com/vaadin/ui/AbstractOrderedLayout.java b/src/com/vaadin/ui/AbstractOrderedLayout.java index fd7e3a39d4..7bd52f8feb 100644 --- a/src/com/vaadin/ui/AbstractOrderedLayout.java +++ b/src/com/vaadin/ui/AbstractOrderedLayout.java @@ -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. * diff --git a/src/com/vaadin/ui/CssLayout.java b/src/com/vaadin/ui/CssLayout.java index 4f8e00dec4..db5bae678b 100644 --- a/src/com/vaadin/ui/CssLayout.java +++ b/src/com/vaadin/ui/CssLayout.java @@ -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. * diff --git a/src/com/vaadin/ui/CustomComponent.java b/src/com/vaadin/ui/CustomComponent.java index e06fb321e3..a598b5b3bb 100644 --- a/src/com/vaadin/ui/CustomComponent.java +++ b/src/com/vaadin/ui/CustomComponent.java @@ -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. * diff --git a/src/com/vaadin/ui/CustomLayout.java b/src/com/vaadin/ui/CustomLayout.java index 1d08860b50..0c11ff6114 100644 --- a/src/com/vaadin/ui/CustomLayout.java +++ b/src/com/vaadin/ui/CustomLayout.java @@ -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. * diff --git a/src/com/vaadin/ui/GridLayout.java b/src/com/vaadin/ui/GridLayout.java index ae678198f9..08e3168791 100644 --- a/src/com/vaadin/ui/GridLayout.java +++ b/src/com/vaadin/ui/GridLayout.java @@ -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. * diff --git a/src/com/vaadin/ui/Panel.java b/src/com/vaadin/ui/Panel.java index 017855a9a0..4d00cddfdd 100644 --- a/src/com/vaadin/ui/Panel.java +++ b/src/com/vaadin/ui/Panel.java @@ -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() diff --git a/src/com/vaadin/ui/PopupView.java b/src/com/vaadin/ui/PopupView.java index 506b5380a7..4e1f387504 100644 --- a/src/com/vaadin/ui/PopupView.java +++ b/src/com/vaadin/ui/PopupView.java @@ -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. * diff --git a/src/com/vaadin/ui/SplitPanel.java b/src/com/vaadin/ui/SplitPanel.java index cc8a19aa3d..2fe5f43d97 100644 --- a/src/com/vaadin/ui/SplitPanel.java +++ b/src/com/vaadin/ui/SplitPanel.java @@ -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. * diff --git a/src/com/vaadin/ui/TabSheet.java b/src/com/vaadin/ui/TabSheet.java index ffbacefce1..89a35ce69f 100644 --- a/src/com/vaadin/ui/TabSheet.java +++ b/src/com/vaadin/ui/TabSheet.java @@ -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. * -- 2.39.5