]> source.dussan.org Git - vaadin-framework.git/commitdiff
#8500 Allow component containers to hide their children even though
authorArtur Signell <artur@vaadin.com>
Tue, 13 Mar 2012 15:59:26 +0000 (17:59 +0200)
committerArtur Signell <artur@vaadin.com>
Wed, 14 Mar 2012 14:00:47 +0000 (16:00 +0200)
the children are visible. Allows Tabsheet to disallow updates to all
tabs except the selected.

src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
src/com/vaadin/ui/AbstractComponentContainer.java
src/com/vaadin/ui/CustomField.java
src/com/vaadin/ui/Form.java
src/com/vaadin/ui/HasComponents.java
src/com/vaadin/ui/TabSheet.java

index 04f64ecaead173f464b232734fe8762af4291b76..615112168b772bf69ac72aaf6df7beee0a12610b 100644 (file)
@@ -946,22 +946,23 @@ public abstract class AbstractCommunicationManager implements
             JSONObject hierarchyInfo = new JSONObject();
             for (Paintable p : hierarchyPendingQueue) {
                 if (p instanceof HasComponents) {
-                    HasComponents cc = (HasComponents) p;
-                    String connectorId = paintableIdMap.get(cc);
+                    HasComponents parent = (HasComponents) p;
+                    String parentConnectorId = paintableIdMap.get(parent);
                     JSONArray children = new JSONArray();
 
-                    for (Component child : getChildComponents(cc)) {
-                        if (child.getState().isVisible()) {
+                    for (Component child : getChildComponents(parent)) {
+                        if (child.getState().isVisible()
+                                && parent.isComponentVisible(child)) {
                             String childConnectorId = getPaintableId(child);
                             children.put(childConnectorId);
                         }
                     }
                     try {
-                        hierarchyInfo.put(connectorId, children);
+                        hierarchyInfo.put(parentConnectorId, children);
                     } catch (JSONException e) {
                         throw new PaintException(
                                 "Failed to send hierarchy information about "
-                                        + connectorId + " to the client: "
+                                        + parentConnectorId + " to the client: "
                                         + e.getMessage());
                     }
                 }
index 20b79e8a067ee59de81ea8e80027b7413f876cd8..01b5a7ad4cace5842eeb546b6181dbe1729c431f 100644 (file)
@@ -382,4 +382,14 @@ public abstract class AbstractComponentContainer extends AbstractComponent
     public Iterator<Component> iterator() {
         return getComponentIterator();
     }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * com.vaadin.ui.HasComponents#isComponentVisible(com.vaadin.ui.Component)
+     */
+    public boolean isComponentVisible(Component childComponent) {
+        return true;
+    }
 }
\ No newline at end of file
index 5436cd0480650e75393f4098ebe27a58c09bdcc1..a462cccfb47491265020e3f0c44ed209c0dadc11 100644 (file)
@@ -253,4 +253,7 @@ public abstract class CustomField<T> extends AbstractField<T> implements
         // content never detached
     }
 
+    public boolean isComponentVisible(Component childComponent) {
+        return true;
+    }
 }
index c4ae0457a9b52673654332e0962977f89ec839d3..c39f043b2119f887c511ac87254148818427be23 100644 (file)
@@ -1420,4 +1420,8 @@ public class Form extends AbstractField<Object> implements Item.Editor,
 
         return count;
     }
+
+    public boolean isComponentVisible(Component childComponent) {
+        return true;
+    };
 }
index e6f71fb3ed26e21679c8bac17ac6ade385876b32..af3d76ba9cabcd48260dcdd93531df2fdf333e63 100644 (file)
@@ -21,4 +21,22 @@ public interface HasComponents extends Component, Iterable<Component> {
      */
     public Iterator<Component> getComponentIterator();
 
+    /**
+     * Checks if the child component is visible. This method allows hiding a
+     * child component from updates and communication to and from the client.
+     * This is useful for components that show only a limited number of its
+     * children at any given time and want to allow updates only for the
+     * children that are visible (e.g. TabSheet has one tab open at a time).
+     * <p>
+     * Note that this will prevent updates from reaching the child even though
+     * the child itself is set to visible. Also if a child is set to invisible
+     * this will not force it to be visible.
+     * </p>
+     * 
+     * @param childComponent
+     *            The child component to check
+     * @return true if the child component is visible to the user, false
+     *         otherwise
+     */
+    public boolean isComponentVisible(Component childComponent);
 }
index 89c363e554945af2adaf06e1fbbcd49e360ff235..96e9feb6d35451da624baf8a463ed63c831c66ca 100644 (file)
@@ -1286,4 +1286,9 @@ public class TabSheet extends AbstractComponentContainer implements Focusable,
         removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
 
     }
+
+    @Override
+    public boolean isComponentVisible(Component childComponent) {
+        return childComponent == getSelectedTab();
+    }
 }