diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-08-15 16:12:50 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-08-20 08:53:45 +0300 |
commit | a80335107906f1c41c1f42d2462dd838e8ea5b6c (patch) | |
tree | f85219d1fccb8304e0c1fcc92d1310b31a6300de /server/src/com/vaadin | |
parent | 890356e6ab17661364a04d60ded9fe01628b0830 (diff) | |
download | vaadin-framework-a80335107906f1c41c1f42d2462dd838e8ea5b6c.tar.gz vaadin-framework-a80335107906f1c41c1f42d2462dd838e8ea5b6c.zip |
Introduce ClientConnector.beforeClientResponse(boolean initial) #9228
Remove Component.updateState() to use the new method instead.
Diffstat (limited to 'server/src/com/vaadin')
11 files changed, 93 insertions, 29 deletions
diff --git a/server/src/com/vaadin/terminal/AbstractClientConnector.java b/server/src/com/vaadin/terminal/AbstractClientConnector.java index 0eb38a3d13..bc1cd2af1a 100644 --- a/server/src/com/vaadin/terminal/AbstractClientConnector.java +++ b/server/src/com/vaadin/terminal/AbstractClientConnector.java @@ -518,4 +518,9 @@ public abstract class AbstractClientConnector implements ClientConnector { return getParent().isConnectorEnabled(); } } + + @Override + public void beforeClientResponse(boolean initial) { + // Do nothing by default + } } diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 96ae70f27c..ffee517550 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -819,6 +819,7 @@ public abstract class AbstractCommunicationManager implements Serializable { if (repaintAll) { getClientCache(root).clear(); rootConnectorTracker.markAllConnectorsDirty(); + rootConnectorTracker.markAllClientSidesUninitialized(); // Reset sent locales locales = null; @@ -833,9 +834,9 @@ public abstract class AbstractCommunicationManager implements Serializable { "Found " + dirtyVisibleConnectors.size() + " dirty connectors to paint"); for (ClientConnector connector : dirtyVisibleConnectors) { - if (connector instanceof Component) { - ((Component) connector).updateState(); - } + boolean initialized = rootConnectorTracker + .isClientSideInitialized(connector); + connector.beforeClientResponse(!initialized); } rootConnectorTracker.markAllConnectorsClean(); @@ -1251,6 +1252,10 @@ public abstract class AbstractCommunicationManager implements Serializable { dragAndDropService.printJSONResponse(outWriter); } + for (ClientConnector connector : dirtyVisibleConnectors) { + rootConnectorTracker.markClientSideInitialized(connector); + } + writePerformanceData(outWriter); } diff --git a/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java b/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java index eef4e240ec..c9fe2563f9 100644 --- a/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java +++ b/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java @@ -157,4 +157,24 @@ public interface ClientConnector extends Connector, RpcTarget { * attached to any Root */ public Root getRoot(); + + /** + * Called before the shared state and RPC invocations are sent to the + * client. Gives the connector an opportunity to set computed/dynamic state + * values or to invoke last minute RPC methods depending on other component + * features. + * <p> + * This method must not alter the component hierarchy in any way. Calling + * requestRepaint() from this method will have no effect. + * </p> + * + * @param initial + * <code>true</code> if the client-side connector will be created + * and initialized after this method has been invoked. + * <code>false</code> if there is already an initialized + * client-side connector. + * + * @since 7.0 + */ + public void beforeClientResponse(boolean initial); } diff --git a/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java b/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java index bb96c6e53e..56d5ed1393 100644 --- a/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java +++ b/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java @@ -322,4 +322,9 @@ public class DragAndDropService implements VariableOwner, ClientConnector { public Root getRoot() { return null; } + + @Override + public void beforeClientResponse(boolean initial) { + // Nothing to do + } } diff --git a/server/src/com/vaadin/ui/AbsoluteLayout.java b/server/src/com/vaadin/ui/AbsoluteLayout.java index 9851a79bcd..a3bc577fe3 100644 --- a/server/src/com/vaadin/ui/AbsoluteLayout.java +++ b/server/src/com/vaadin/ui/AbsoluteLayout.java @@ -169,8 +169,8 @@ public class AbsoluteLayout extends AbstractLayout implements } @Override - public void updateState() { - super.updateState(); + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); // This could be in internalRemoveComponent and internalSetComponent if // Map<Connector,String> was supported. We cannot get the child diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java index fb3993d0cf..cde5217ca1 100644 --- a/server/src/com/vaadin/ui/AbstractComponent.java +++ b/server/src/com/vaadin/ui/AbstractComponent.java @@ -717,13 +717,9 @@ public abstract class AbstractComponent extends AbstractClientConnector return (ComponentState) super.getState(); } - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Component#updateState() - */ @Override - public void updateState() { + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); // TODO This logic should be on the client side and the state should // simply be a data object with "width" and "height". if (getHeight() >= 0 diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index 2d14acf442..67a1826100 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -1620,8 +1620,8 @@ public abstract class AbstractField<T> extends AbstractComponent implements } @Override - public void updateState() { - super.updateState(); + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); // Hide the error indicator if needed getState().setHideErrors(shouldHideErrors()); diff --git a/server/src/com/vaadin/ui/AbstractTextField.java b/server/src/com/vaadin/ui/AbstractTextField.java index c8bbadd0ab..86315f801f 100644 --- a/server/src/com/vaadin/ui/AbstractTextField.java +++ b/server/src/com/vaadin/ui/AbstractTextField.java @@ -97,8 +97,8 @@ public abstract class AbstractTextField extends AbstractField<String> implements } @Override - public void updateState() { - super.updateState(); + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); String value = getValue(); if (value == null) { diff --git a/server/src/com/vaadin/ui/Component.java b/server/src/com/vaadin/ui/Component.java index ac668168f2..ff7ed47930 100644 --- a/server/src/com/vaadin/ui/Component.java +++ b/server/src/com/vaadin/ui/Component.java @@ -637,18 +637,6 @@ public interface Component extends ClientConnector, Sizeable, Serializable { public ComponentState getState(); /** - * Called before the shared state is sent to the client. Gives the component - * an opportunity to set computed/dynamic state values e.g. state values - * that depend on other component features. - * <p> - * This method must not alter the component hierarchy in any way. - * </p> - * - * @since 7.0 - */ - public void updateState(); - - /** * Adds an unique id for component that get's transferred to terminal for * testing purposes. Keeping identifiers unique is the responsibility of the * programmer. diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java index 12ad377b62..27dfebd95e 100644 --- a/server/src/com/vaadin/ui/ConnectorTracker.java +++ b/server/src/com/vaadin/ui/ConnectorTracker.java @@ -25,6 +25,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import com.vaadin.terminal.AbstractClientConnector; +import com.vaadin.terminal.gwt.client.ServerConnector; import com.vaadin.terminal.gwt.server.ClientConnector; /** @@ -50,6 +51,7 @@ public class ConnectorTracker implements Serializable { private final HashMap<String, ClientConnector> connectorIdToConnector = new HashMap<String, ClientConnector>(); private Set<ClientConnector> dirtyConnectors = new HashSet<ClientConnector>(); + private Set<ClientConnector> uninitializedConnectors = new HashSet<ClientConnector>(); private Root root; @@ -91,6 +93,7 @@ public class ConnectorTracker implements Serializable { .get(connectorId); if (previouslyRegistered == null) { connectorIdToConnector.put(connectorId, connector); + uninitializedConnectors.add(connector); getLogger().fine( "Registered " + connector.getClass().getSimpleName() + " (" + connectorId + ")"); @@ -136,6 +139,47 @@ public class ConnectorTracker implements Serializable { "Unregistered " + connector.getClass().getSimpleName() + " (" + connectorId + ")"); connectorIdToConnector.remove(connectorId); + uninitializedConnectors.remove(connector); + } + + /** + * Checks whether the given connector has already been initialized in the + * browser. The given connector should be registered with this connector + * tracker. + * + * @param connector + * the client connector to check + * @return <code>true</code> if the initial state has previously been sent + * to the browser, <code>false</code> if the client-side doesn't + * already know anything about the connector. + */ + public boolean isClientSideInitialized(ClientConnector connector) { + assert connectorIdToConnector.get(connector.getConnectorId()) == connector : "Connector should be registered with this ConnectorTracker"; + return !uninitializedConnectors.contains(connector); + } + + /** + * Marks the given connector as initialized, meaning that the client-side + * state has been initialized for the connector. + * + * @see #isClientSideInitialized(ClientConnector) + * + * @param connector + * the connector that should be marked as initialized + */ + public void markClientSideInitialized(ClientConnector connector) { + uninitializedConnectors.remove(connector); + } + + /** + * Marks all currently registered connectors as uninitialized. This should + * be done when the client-side has been reset but the server-side state is + * retained. + * + * @see #isClientSideInitialized(ClientConnector) + */ + public void markAllClientSidesUninitialized() { + uninitializedConnectors.addAll(connectorIdToConnector.values()); } /** @@ -175,6 +219,7 @@ public class ConnectorTracker implements Serializable { "cleanConnectorMap unregistered connector " + getConnectorAndParentInfo(connector) + "). This should have been done when the connector was detached."); + uninitializedConnectors.remove(connector); iterator.remove(); } } diff --git a/server/src/com/vaadin/ui/CssLayout.java b/server/src/com/vaadin/ui/CssLayout.java index c43f347e68..0192debc4a 100644 --- a/server/src/com/vaadin/ui/CssLayout.java +++ b/server/src/com/vaadin/ui/CssLayout.java @@ -197,8 +197,8 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier { } @Override - public void updateState() { - super.updateState(); + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); getState().getChildCss().clear(); for (Iterator<Component> ci = getComponentIterator(); ci.hasNext();) { Component child = ci.next(); |