From: Artur Signell Date: Tue, 13 Mar 2012 15:59:26 +0000 (+0200) Subject: #8500 Allow component containers to hide their children even though X-Git-Tag: 7.0.0.alpha2~338 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=79871340bdcfc7eda7e2800966e2e62215154649;p=vaadin-framework.git #8500 Allow component containers to hide their children even though the children are visible. Allows Tabsheet to disallow updates to all tabs except the selected. --- diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 04f64ecaea..615112168b 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -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()); } } diff --git a/src/com/vaadin/ui/AbstractComponentContainer.java b/src/com/vaadin/ui/AbstractComponentContainer.java index 20b79e8a06..01b5a7ad4c 100644 --- a/src/com/vaadin/ui/AbstractComponentContainer.java +++ b/src/com/vaadin/ui/AbstractComponentContainer.java @@ -382,4 +382,14 @@ public abstract class AbstractComponentContainer extends AbstractComponent public Iterator 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 diff --git a/src/com/vaadin/ui/CustomField.java b/src/com/vaadin/ui/CustomField.java index 5436cd0480..a462cccfb4 100644 --- a/src/com/vaadin/ui/CustomField.java +++ b/src/com/vaadin/ui/CustomField.java @@ -253,4 +253,7 @@ public abstract class CustomField extends AbstractField implements // content never detached } + public boolean isComponentVisible(Component childComponent) { + return true; + } } diff --git a/src/com/vaadin/ui/Form.java b/src/com/vaadin/ui/Form.java index c4ae0457a9..c39f043b21 100644 --- a/src/com/vaadin/ui/Form.java +++ b/src/com/vaadin/ui/Form.java @@ -1420,4 +1420,8 @@ public class Form extends AbstractField implements Item.Editor, return count; } + + public boolean isComponentVisible(Component childComponent) { + return true; + }; } diff --git a/src/com/vaadin/ui/HasComponents.java b/src/com/vaadin/ui/HasComponents.java index e6f71fb3ed..af3d76ba9c 100644 --- a/src/com/vaadin/ui/HasComponents.java +++ b/src/com/vaadin/ui/HasComponents.java @@ -21,4 +21,22 @@ public interface HasComponents extends Component, Iterable { */ public Iterator 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). + *

+ * 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. + *

+ * + * @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); } diff --git a/src/com/vaadin/ui/TabSheet.java b/src/com/vaadin/ui/TabSheet.java index 89c363e554..96e9feb6d3 100644 --- a/src/com/vaadin/ui/TabSheet.java +++ b/src/com/vaadin/ui/TabSheet.java @@ -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(); + } }