summaryrefslogtreecommitdiffstats
path: root/server/src/com
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-11-20 14:49:52 +0200
committerVaadin Code Review <review@vaadin.com>2012-11-20 13:15:35 +0000
commit0308bf8b7b85ead586f21db82cd370c53fac46d6 (patch)
tree0b550ad3b68134b599c7a146723923f67e1d04cb /server/src/com
parent40e7287b82df23e9105f51b7ca086e93fb8903c5 (diff)
downloadvaadin-framework-0308bf8b7b85ead586f21db82cd370c53fac46d6.tar.gz
vaadin-framework-0308bf8b7b85ead586f21db82cd370c53fac46d6.zip
Moved isComponentVisible to separate interface (#10303)
HasComponents.isComponentVisible is now SelectiveRenderer.isRendered Change-Id: Ic3b9cd65278ffc2a38ee20c76ec771ee057268bf
Diffstat (limited to 'server/src/com')
-rw-r--r--server/src/com/vaadin/server/AbstractCommunicationManager.java43
-rw-r--r--server/src/com/vaadin/server/JsonCodec.java4
-rw-r--r--server/src/com/vaadin/server/LegacyPaint.java28
-rw-r--r--server/src/com/vaadin/ui/AbstractComponent.java3
-rw-r--r--server/src/com/vaadin/ui/AbstractComponentContainer.java11
-rw-r--r--server/src/com/vaadin/ui/AbstractSingleComponentContainer.java11
-rw-r--r--server/src/com/vaadin/ui/ConnectorTracker.java3
-rw-r--r--server/src/com/vaadin/ui/CustomField.java5
-rw-r--r--server/src/com/vaadin/ui/Form.java5
-rw-r--r--server/src/com/vaadin/ui/HasComponents.java19
-rw-r--r--server/src/com/vaadin/ui/SelectiveRenderer.java50
-rw-r--r--server/src/com/vaadin/ui/TabSheet.java4
-rw-r--r--server/src/com/vaadin/ui/Table.java5
13 files changed, 84 insertions, 107 deletions
diff --git a/server/src/com/vaadin/server/AbstractCommunicationManager.java b/server/src/com/vaadin/server/AbstractCommunicationManager.java
index 74e5d5fd20..57878bef31 100644
--- a/server/src/com/vaadin/server/AbstractCommunicationManager.java
+++ b/server/src/com/vaadin/server/AbstractCommunicationManager.java
@@ -85,6 +85,7 @@ import com.vaadin.ui.ConnectorTracker;
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;
@@ -933,7 +934,7 @@ public abstract class AbstractCommunicationManager implements Serializable {
for (ClientConnector child : AbstractClientConnector
.getAllChildrenIterable(connector)) {
- if (isVisible(child)) {
+ if (isConnectorVisibleToClient(child)) {
children.put(child.getConnectorId());
}
}
@@ -1402,53 +1403,59 @@ public abstract class AbstractCommunicationManager implements Serializable {
/**
* 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> {
@@ -2219,7 +2226,7 @@ public abstract class AbstractCommunicationManager implements Serializable {
ConnectorTracker connectorTracker) {
ArrayList<ClientConnector> dirtyConnectors = new ArrayList<ClientConnector>();
for (ClientConnector c : connectorTracker.getDirtyConnectors()) {
- if (isVisible(c)) {
+ if (isConnectorVisibleToClient(c)) {
dirtyConnectors.add(c);
}
}
diff --git a/server/src/com/vaadin/server/JsonCodec.java b/server/src/com/vaadin/server/JsonCodec.java
index 55e0fd69ed..89ef060ef0 100644
--- a/server/src/com/vaadin/server/JsonCodec.java
+++ b/server/src/com/vaadin/server/JsonCodec.java
@@ -654,7 +654,7 @@ public class JsonCodec implements Serializable {
Connector connector = (Connector) value;
if (value instanceof Component
&& !(AbstractCommunicationManager
- .isVisible((Component) value))) {
+ .isComponentVisibleToClient((Component) value))) {
return encodeNull();
}
return new EncodeResult(connector.getConnectorId());
@@ -847,7 +847,7 @@ public class JsonCodec implements Serializable {
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(),
diff --git a/server/src/com/vaadin/server/LegacyPaint.java b/server/src/com/vaadin/server/LegacyPaint.java
index 971aec682f..17c02955f4 100644
--- a/server/src/com/vaadin/server/LegacyPaint.java
+++ b/server/src/com/vaadin/server/LegacyPaint.java
@@ -19,7 +19,6 @@ import java.io.Serializable;
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 {
@@ -51,7 +50,7 @@ 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;
}
@@ -65,34 +64,9 @@ public class LegacyPaint implements Serializable {
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();
- }
-
}
diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java
index fc6f176e2a..7e7a595a2e 100644
--- a/server/src/com/vaadin/ui/AbstractComponent.java
+++ b/server/src/com/vaadin/ui/AbstractComponent.java
@@ -349,7 +349,8 @@ public abstract class AbstractComponent extends AbstractClientConnector
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;
diff --git a/server/src/com/vaadin/ui/AbstractComponentContainer.java b/server/src/com/vaadin/ui/AbstractComponentContainer.java
index c60f312293..b5cc3da861 100644
--- a/server/src/com/vaadin/ui/AbstractComponentContainer.java
+++ b/server/src/com/vaadin/ui/AbstractComponentContainer.java
@@ -343,15 +343,4 @@ public abstract class AbstractComponentContainer extends AbstractComponent
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
diff --git a/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java b/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java
index 20660ce955..7297318e95 100644
--- a/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java
+++ b/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java
@@ -102,17 +102,6 @@ public abstract class AbstractSingleComponentContainer extends
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) {
diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java
index ddb02129d4..8b1a940c4b 100644
--- a/server/src/com/vaadin/ui/ConnectorTracker.java
+++ b/server/src/com/vaadin/ui/ConnectorTracker.java
@@ -247,7 +247,8 @@ public class ConnectorTracker implements Serializable {
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);
diff --git a/server/src/com/vaadin/ui/CustomField.java b/server/src/com/vaadin/ui/CustomField.java
index 23460d824e..c3331609a5 100644
--- a/server/src/com/vaadin/ui/CustomField.java
+++ b/server/src/com/vaadin/ui/CustomField.java
@@ -150,9 +150,4 @@ public abstract class CustomField<T> extends AbstractField<T> implements
public Iterator<Component> iterator() {
return new ComponentIterator();
}
-
- @Override
- public boolean isComponentVisible(Component childComponent) {
- return true;
- }
}
diff --git a/server/src/com/vaadin/ui/Form.java b/server/src/com/vaadin/ui/Form.java
index 94a9f9b73a..62a6de4fe6 100644
--- a/server/src/com/vaadin/ui/Form.java
+++ b/server/src/com/vaadin/ui/Form.java
@@ -1375,11 +1375,6 @@ public class Form extends AbstractField<Object> implements Item.Editor,
}
@Override
- public boolean isComponentVisible(Component childComponent) {
- return true;
- };
-
- @Override
public void setVisible(boolean visible) {
if (isVisible() == visible) {
return;
diff --git a/server/src/com/vaadin/ui/HasComponents.java b/server/src/com/vaadin/ui/HasComponents.java
index 4f6320f6b2..d2ca45fa42 100644
--- a/server/src/com/vaadin/ui/HasComponents.java
+++ b/server/src/com/vaadin/ui/HasComponents.java
@@ -41,25 +41,6 @@ public interface HasComponents extends Component, Iterable<Component> {
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.
*
diff --git a/server/src/com/vaadin/ui/SelectiveRenderer.java b/server/src/com/vaadin/ui/SelectiveRenderer.java
new file mode 100644
index 0000000000..47fd9bf0ee
--- /dev/null
+++ b/server/src/com/vaadin/ui/SelectiveRenderer.java
@@ -0,0 +1,50 @@
+/*
+ * 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);
+
+}
diff --git a/server/src/com/vaadin/ui/TabSheet.java b/server/src/com/vaadin/ui/TabSheet.java
index 227743e9f4..1a76aa88bc 100644
--- a/server/src/com/vaadin/ui/TabSheet.java
+++ b/server/src/com/vaadin/ui/TabSheet.java
@@ -70,7 +70,7 @@ import com.vaadin.ui.themes.Runo;
* @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,
@@ -1290,7 +1290,7 @@ public class TabSheet extends AbstractComponentContainer implements Focusable,
}
@Override
- public boolean isComponentVisible(Component childComponent) {
+ public boolean isRendered(Component childComponent) {
return childComponent == getSelectedTab();
}
diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java
index 352b9212a7..f224e13dfd 100644
--- a/server/src/com/vaadin/ui/Table.java
+++ b/server/src/com/vaadin/ui/Table.java
@@ -5579,11 +5579,6 @@ public class Table extends AbstractSelect implements Action.Container,
return iterator();
}
- @Override
- public boolean isComponentVisible(Component childComponent) {
- return true;
- }
-
private final Logger getLogger() {
if (logger == null) {
logger = Logger.getLogger(Table.class.getName());