import com.vaadin.ui.HasComponents;
import com.vaadin.ui.LegacyComponent;
import com.vaadin.ui.LegacyWindow;
+import com.vaadin.ui.SelectiveRenderer;
import com.vaadin.ui.UI;
import com.vaadin.ui.Window;
for (ClientConnector child : AbstractClientConnector
.getAllChildrenIterable(connector)) {
- if (isVisible(child)) {
+ if (isConnectorVisibleToClient(child)) {
children.put(child.getConnectorId());
}
}
/**
* Checks if the connector is visible in context. For Components,
- * {@link #isVisible(Component)} is used. For other types of connectors, the
- * contextual visibility of its first Component ancestor is used. If no
- * Component ancestor is found, the connector is not visible.
+ * {@link #isComponentVisibleToClient(Component)} is used. For other types
+ * of connectors, the contextual visibility of its first Component ancestor
+ * is used. If no Component ancestor is found, the connector is not visible.
*
* @param connector
* The connector to check
* @return <code>true</code> if the connector is visible to the client,
* <code>false</code> otherwise
*/
- public static boolean isVisible(ClientConnector connector) {
+ public static boolean isConnectorVisibleToClient(ClientConnector connector) {
if (connector instanceof Component) {
- return isVisible((Component) connector);
+ return isComponentVisibleToClient((Component) connector);
} else {
ClientConnector parent = connector.getParent();
if (parent == null) {
return false;
} else {
- return isVisible(parent);
+ return isConnectorVisibleToClient(parent);
}
}
}
/**
- * Checks if the component is visible in context, i.e. returns false if the
- * child is hidden, the parent is hidden or the parent says the child should
- * not be rendered (using
- * {@link HasComponents#isComponentVisible(Component)}
+ * Checks if the component should be visible to the client. Returns false if
+ * the child should not be sent to the client, true otherwise.
*
* @param child
* The child to check
* @return true if the child is visible to the client, false otherwise
*/
- static boolean isVisible(Component child) {
+ public static boolean isComponentVisibleToClient(Component child) {
if (!child.isVisible()) {
return false;
}
-
HasComponents parent = child.getParent();
- if (parent == null) {
+
+ if (parent instanceof SelectiveRenderer) {
+ if (!((SelectiveRenderer) parent).isRendered(child)) {
+ return false;
+ }
+ }
+
+ if (parent != null) {
+ return isComponentVisibleToClient(parent);
+ } else {
if (child instanceof UI) {
- return child.isVisible();
+ // UI has no parent and visibility was checked above
+ return true;
} else {
+ // Component which is not attached to any UI
return false;
}
}
-
- return parent.isComponentVisible(child) && isVisible(parent);
}
private static class NullIterator<E> implements Iterator<E> {
ConnectorTracker connectorTracker) {
ArrayList<ClientConnector> dirtyConnectors = new ArrayList<ClientConnector>();
for (ClientConnector c : connectorTracker.getDirtyConnectors()) {
- if (isVisible(c)) {
+ if (isConnectorVisibleToClient(c)) {
dirtyConnectors.add(c);
}
}
Connector connector = (Connector) value;
if (value instanceof Component
&& !(AbstractCommunicationManager
- .isVisible((Component) value))) {
+ .isComponentVisibleToClient((Component) value))) {
return encodeNull();
}
return new EncodeResult(connector.getConnectorId());
for (Entry<?, ?> entry : map.entrySet()) {
ClientConnector key = (ClientConnector) entry.getKey();
- if (AbstractCommunicationManager.isVisible(key)) {
+ if (AbstractCommunicationManager.isConnectorVisibleToClient(key)) {
EncodeResult encodedValue = encode(entry.getValue(), null,
valueType, connectorTracker);
jsonMap.put(key.getConnectorId(),
import com.vaadin.server.PaintTarget.PaintStatus;
import com.vaadin.ui.Component;
-import com.vaadin.ui.HasComponents;
import com.vaadin.ui.LegacyComponent;
public class LegacyPaint implements Serializable {
public static void paint(Component component, PaintTarget target)
throws PaintException {
// Only paint content of visible components.
- if (!isVisibleInContext(component)) {
+ if (!AbstractCommunicationManager.isComponentVisibleToClient(component)) {
return;
}
if (component instanceof LegacyComponent) {
((LegacyComponent) component).paintContent(target);
}
-
}
target.endPaintable(component);
}
- /**
- * Checks if the component is visible and its parent is visible,
- * recursively.
- * <p>
- * This is only a helper until paint is moved away from this class.
- *
- * @return
- */
- protected static boolean isVisibleInContext(Component c) {
- HasComponents p = c.getParent();
- while (p != null) {
- if (!p.isVisible()) {
- return false;
- }
- p = p.getParent();
- }
- if (c.getParent() != null && !c.getParent().isComponentVisible(c)) {
- return false;
- }
-
- // All parents visible, return this state
- return c.isVisible();
- }
-
}
return false;
} else if (!super.isConnectorEnabled()) {
return false;
- } else if (!getParent().isComponentVisible(this)) {
+ } else if ((getParent() instanceof SelectiveRenderer)
+ && !((SelectiveRenderer) getParent()).isRendered(this)) {
return false;
} else {
return true;
public Iterator<Component> getComponentIterator() {
return iterator();
}
-
- /*
- * (non-Javadoc)
- *
- * @see
- * com.vaadin.ui.HasComponents#isComponentVisible(com.vaadin.ui.Component)
- */
- @Override
- public boolean isComponentVisible(Component childComponent) {
- return true;
- }
}
\ No newline at end of file
fireEvent(new ComponentDetachEvent(this, component));
}
- /*
- * (non-Javadoc)
- *
- * @see
- * com.vaadin.ui.HasComponents#isComponentVisible(com.vaadin.ui.Component)
- */
- @Override
- public boolean isComponentVisible(Component childComponent) {
- return true;
- }
-
@Override
public void setVisible(boolean visible) {
if (isVisible() == visible) {
uninitializedConnectors.remove(connector);
diffStates.remove(connector);
iterator.remove();
- } else if (!AbstractCommunicationManager.isVisible(connector)
+ } else if (!AbstractCommunicationManager
+ .isConnectorVisibleToClient(connector)
&& !uninitializedConnectors.contains(connector)) {
uninitializedConnectors.add(connector);
diffStates.remove(connector);
public Iterator<Component> iterator() {
return new ComponentIterator();
}
-
- @Override
- public boolean isComponentVisible(Component childComponent) {
- return true;
- }
}
return count;
}
- @Override
- public boolean isComponentVisible(Component childComponent) {
- return true;
- };
-
@Override
public void setVisible(boolean visible) {
if (isVisible() == visible) {
@Override
public Iterator<Component> iterator();
- /**
- * 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);
-
/**
* Interface for {@link HasComponents} implementations that support sending
* attach and detach events for components.
--- /dev/null
+/*
+ * Copyright 2011 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.ui;
+
+/**
+ * Interface implemented by {@link HasComponents} implementors that wish to
+ * dynamically be able to prevent given child components from reaching the
+ * client side.
+ *
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0
+ *
+ */
+public interface SelectiveRenderer extends HasComponents {
+ /**
+ * Checks if the child component should be rendered (sent to the client
+ * side). This method allows hiding a child component from updates and
+ * communication to and from the client. It is mostly useful for parents
+ * which show only a limited number of their children at any given time and
+ * want to allow updates only for the visible children (e.g. TabSheet has
+ * one tab open at a time).
+ * <p>
+ * This method can only prevent updates from reaching the client, not force
+ * child components to reach the client. If the child is set to visible,
+ * returning false will prevent the child from being sent to the client. If
+ * a child is set to invisible, this method has no effect.
+ * </p>
+ *
+ * @param childComponent
+ * The child component to check
+ * @return true if the child component may be sent to the client, false
+ * otherwise
+ */
+ public boolean isRendered(Component childComponent);
+
+}
* @since 3.0
*/
public class TabSheet extends AbstractComponentContainer implements Focusable,
- FocusNotifier, BlurNotifier, LegacyComponent {
+ FocusNotifier, BlurNotifier, LegacyComponent, SelectiveRenderer {
/**
* List of component tabs (tab contents). In addition to being on this list,
}
@Override
- public boolean isComponentVisible(Component childComponent) {
+ public boolean isRendered(Component childComponent) {
return childComponent == getSelectedTab();
}
return iterator();
}
- @Override
- public boolean isComponentVisible(Component childComponent) {
- return true;
- }
-
private final Logger getLogger() {
if (logger == null) {
logger = Logger.getLogger(Table.class.getName());