diff options
Diffstat (limited to 'server/src/com')
28 files changed, 103 insertions, 89 deletions
diff --git a/server/src/com/vaadin/terminal/AbstractClientConnector.java b/server/src/com/vaadin/terminal/AbstractClientConnector.java index bc1cd2af1a..a8da553a62 100644 --- a/server/src/com/vaadin/terminal/AbstractClientConnector.java +++ b/server/src/com/vaadin/terminal/AbstractClientConnector.java @@ -31,9 +31,12 @@ import java.util.NoSuchElementException; import java.util.logging.Logger; import com.vaadin.Application; +import com.vaadin.external.json.JSONException; +import com.vaadin.external.json.JSONObject; import com.vaadin.shared.communication.ClientRpc; import com.vaadin.shared.communication.ServerRpc; import com.vaadin.shared.communication.SharedState; +import com.vaadin.terminal.gwt.server.AbstractCommunicationManager; import com.vaadin.terminal.gwt.server.ClientConnector; import com.vaadin.terminal.gwt.server.ClientMethodInvocation; import com.vaadin.terminal.gwt.server.RpcManager; @@ -137,14 +140,18 @@ public abstract class AbstractClientConnector implements ClientConnector { registerRpc(implementation, type); } - @Override - public SharedState getState() { + protected SharedState getState() { if (null == sharedState) { sharedState = createState(); } return sharedState; } + @Override + public JSONObject encodeState() throws JSONException { + return AbstractCommunicationManager.encodeState(this, getState()); + } + /** * Creates the shared state bean to be used in server to client * communication. diff --git a/server/src/com/vaadin/terminal/AbstractJavaScriptExtension.java b/server/src/com/vaadin/terminal/AbstractJavaScriptExtension.java index aae71640aa..1def6df697 100644 --- a/server/src/com/vaadin/terminal/AbstractJavaScriptExtension.java +++ b/server/src/com/vaadin/terminal/AbstractJavaScriptExtension.java @@ -166,7 +166,7 @@ public abstract class AbstractJavaScriptExtension extends AbstractExtension { } @Override - public JavaScriptExtensionState getState() { + protected JavaScriptExtensionState getState() { return (JavaScriptExtensionState) super.getState(); } } diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 99376ffd1f..7ea4a7d097 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -880,49 +880,19 @@ public abstract class AbstractCommunicationManager implements Serializable { // processing. JSONObject sharedStates = new JSONObject(); for (ClientConnector connector : dirtyVisibleConnectors) { - SharedState state = connector.getState(); - if (null != state) { - // encode and send shared state - try { - Class<? extends SharedState> stateType = connector - .getStateType(); - Object diffState = rootConnectorTracker - .getDiffState(connector); - if (diffState == null) { - diffState = new JSONObject(); - // Use an empty state object as reference for full - // repaints - boolean emptyInitialState = JavaScriptConnectorState.class - .isAssignableFrom(stateType); - if (!emptyInitialState) { - try { - SharedState referenceState = stateType - .newInstance(); - diffState = JsonCodec.encode(referenceState, - null, stateType, - root.getConnectorTracker()); - } catch (Exception e) { - getLogger().log( - Level.WARNING, - "Error creating reference object for state of type " - + stateType.getName()); - } - } - rootConnectorTracker.setDiffState(connector, diffState); - } - JSONObject stateJson = (JSONObject) JsonCodec.encode(state, - diffState, stateType, root.getConnectorTracker()); + // encode and send shared state + try { + JSONObject stateJson = connector.encodeState(); - if (stateJson.length() != 0) { - sharedStates.put(connector.getConnectorId(), stateJson); - } - } catch (JSONException e) { - throw new PaintException( - "Failed to serialize shared state for connector " - + connector.getClass().getName() + " (" - + connector.getConnectorId() + "): " - + e.getMessage(), e); + if (stateJson != null && stateJson.length() != 0) { + sharedStates.put(connector.getConnectorId(), stateJson); } + } catch (JSONException e) { + throw new PaintException( + "Failed to serialize shared state for connector " + + connector.getClass().getName() + " (" + + connector.getConnectorId() + "): " + + e.getMessage(), e); } } outWriter.print("\"state\":"); @@ -1273,6 +1243,37 @@ public abstract class AbstractCommunicationManager implements Serializable { writePerformanceData(outWriter); } + public static JSONObject encodeState(ClientConnector connector, + SharedState state) throws JSONException { + Root root = connector.getRoot(); + ConnectorTracker connectorTracker = root.getConnectorTracker(); + Class<? extends SharedState> stateType = connector.getStateType(); + Object diffState = connectorTracker.getDiffState(connector); + if (diffState == null) { + diffState = new JSONObject(); + // Use an empty state object as reference for full + // repaints + boolean emptyInitialState = JavaScriptConnectorState.class + .isAssignableFrom(stateType); + if (!emptyInitialState) { + try { + SharedState referenceState = stateType.newInstance(); + diffState = JsonCodec.encode(referenceState, null, + stateType, root.getConnectorTracker()); + } catch (Exception e) { + getLogger().log( + Level.WARNING, + "Error creating reference object for state of type " + + stateType.getName()); + } + } + connectorTracker.setDiffState(connector, diffState); + } + JSONObject stateJson = (JSONObject) JsonCodec.encode(state, diffState, + stateType, root.getConnectorTracker()); + return stateJson; + } + /** * Resolves a resource URI, registering the URI with this * {@code AbstractCommunicationManager} if needed and returns a fully diff --git a/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java b/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java index c9fe2563f9..87524fe28f 100644 --- a/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java +++ b/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java @@ -18,6 +18,8 @@ package com.vaadin.terminal.gwt.server; import java.util.Collection; import java.util.List; +import com.vaadin.external.json.JSONException; +import com.vaadin.external.json.JSONObject; import com.vaadin.shared.Connector; import com.vaadin.shared.communication.SharedState; import com.vaadin.terminal.AbstractClientConnector; @@ -177,4 +179,16 @@ public interface ClientConnector extends Connector, RpcTarget { * @since 7.0 */ public void beforeClientResponse(boolean initial); + + /** + * Called by the framework to encode the state to a JSONObject. This is + * typically done by calling the static method + * {@link AbstractCommunicationManager#encodeState(ClientConnector, SharedState)} + * . + * + * @return a JSON object with the encoded connector state + * @throws JSONException + * if the state can not be encoded + */ + public JSONObject encodeState() throws JSONException; } diff --git a/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java b/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java index 56d5ed1393..981d2569d1 100644 --- a/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java +++ b/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java @@ -31,6 +31,8 @@ import com.vaadin.event.dd.DropTarget; import com.vaadin.event.dd.TargetDetails; import com.vaadin.event.dd.TargetDetailsImpl; import com.vaadin.event.dd.acceptcriteria.AcceptCriterion; +import com.vaadin.external.json.JSONException; +import com.vaadin.external.json.JSONObject; import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.communication.SharedState; import com.vaadin.shared.ui.dd.DragEventType; @@ -235,12 +237,6 @@ public class DragAndDropService implements VariableOwner, ClientConnector { } @Override - public SharedState getState() { - // TODO Auto-generated method stub - return null; - } - - @Override public String getConnectorId() { return ApplicationConstants.DRAG_AND_DROP_CONNECTOR_ID; } @@ -327,4 +323,10 @@ public class DragAndDropService implements VariableOwner, ClientConnector { public void beforeClientResponse(boolean initial) { // Nothing to do } + + @Override + public JSONObject encodeState() throws JSONException { + // TODO Auto-generated method stub + return null; + } } diff --git a/server/src/com/vaadin/ui/AbsoluteLayout.java b/server/src/com/vaadin/ui/AbsoluteLayout.java index a3bc577fe3..8981895717 100644 --- a/server/src/com/vaadin/ui/AbsoluteLayout.java +++ b/server/src/com/vaadin/ui/AbsoluteLayout.java @@ -61,7 +61,7 @@ public class AbsoluteLayout extends AbstractLayout implements } @Override - public AbsoluteLayoutState getState() { + protected AbsoluteLayoutState getState() { return (AbsoluteLayoutState) super.getState(); } diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java index cde5217ca1..1eb95311cd 100644 --- a/server/src/com/vaadin/ui/AbstractComponent.java +++ b/server/src/com/vaadin/ui/AbstractComponent.java @@ -713,7 +713,7 @@ public abstract class AbstractComponent extends AbstractClientConnector * @return updated component shared state */ @Override - public ComponentState getState() { + protected ComponentState getState() { return (ComponentState) super.getState(); } diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index b914fb4c46..8ac7b21daf 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -1615,7 +1615,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements } @Override - public AbstractFieldState getState() { + protected AbstractFieldState getState() { return (AbstractFieldState) super.getState(); } diff --git a/server/src/com/vaadin/ui/AbstractJavaScriptComponent.java b/server/src/com/vaadin/ui/AbstractJavaScriptComponent.java index c442bf2204..67b6447ef9 100644 --- a/server/src/com/vaadin/ui/AbstractJavaScriptComponent.java +++ b/server/src/com/vaadin/ui/AbstractJavaScriptComponent.java @@ -17,6 +17,8 @@ package com.vaadin.ui; import com.vaadin.shared.ui.JavaScriptComponentState; import com.vaadin.terminal.JavaScriptCallbackHelper; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.ui.JavaScriptWidget; /** * Base class for Components with all client-side logic implemented using @@ -90,9 +92,8 @@ import com.vaadin.terminal.JavaScriptCallbackHelper; * {@link #addFunction(String, JavaScriptFunction)} on the server will * automatically be present as a function that triggers the registered function * on the server.</li> - * <li>Any field name referred to using - * {@link #callFunction(String, Object...)} on the server will be called if a - * function has been assigned to the field.</li> + * <li>Any field name referred to using {@link #callFunction(String, Object...)} + * on the server will be called if a function has been assigned to the field.</li> * </ul> * <p> * @@ -168,7 +169,7 @@ public abstract class AbstractJavaScriptComponent extends AbstractComponent { } @Override - public JavaScriptComponentState getState() { + protected JavaScriptComponentState getState() { return (JavaScriptComponentState) super.getState(); } } diff --git a/server/src/com/vaadin/ui/AbstractLayout.java b/server/src/com/vaadin/ui/AbstractLayout.java index dd1d5eab12..6743b09211 100644 --- a/server/src/com/vaadin/ui/AbstractLayout.java +++ b/server/src/com/vaadin/ui/AbstractLayout.java @@ -29,7 +29,7 @@ public abstract class AbstractLayout extends AbstractComponentContainer implements Layout { @Override - public AbstractLayoutState getState() { + protected AbstractLayoutState getState() { return (AbstractLayoutState) super.getState(); } diff --git a/server/src/com/vaadin/ui/AbstractMedia.java b/server/src/com/vaadin/ui/AbstractMedia.java index 51a3bcd2be..7a29c8f4ce 100644 --- a/server/src/com/vaadin/ui/AbstractMedia.java +++ b/server/src/com/vaadin/ui/AbstractMedia.java @@ -33,7 +33,7 @@ import com.vaadin.terminal.gwt.server.ResourceReference; public abstract class AbstractMedia extends AbstractComponent { @Override - public AbstractMediaState getState() { + protected AbstractMediaState getState() { return (AbstractMediaState) super.getState(); } diff --git a/server/src/com/vaadin/ui/AbstractOrderedLayout.java b/server/src/com/vaadin/ui/AbstractOrderedLayout.java index 3ac4e76bdb..cac9c05fb8 100644 --- a/server/src/com/vaadin/ui/AbstractOrderedLayout.java +++ b/server/src/com/vaadin/ui/AbstractOrderedLayout.java @@ -63,7 +63,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements } @Override - public AbstractOrderedLayoutState getState() { + protected AbstractOrderedLayoutState getState() { return (AbstractOrderedLayoutState) super.getState(); } @@ -394,6 +394,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements return components.get(index); } + @Override public void setMargin(boolean enabled) { setMargin(new MarginInfo(enabled)); } @@ -403,6 +404,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements * * @see com.vaadin.ui.Layout.MarginHandler#getMargin() */ + @Override public MarginInfo getMargin() { return new MarginInfo(getState().getMarginsBitmask()); } @@ -412,6 +414,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements * * @see com.vaadin.ui.Layout.MarginHandler#setMargin(MarginInfo) */ + @Override public void setMargin(MarginInfo marginInfo) { getState().setMarginsBitmask(marginInfo.getBitMask()); requestRepaint(); diff --git a/server/src/com/vaadin/ui/AbstractSplitPanel.java b/server/src/com/vaadin/ui/AbstractSplitPanel.java index 03e8a2dfb6..68964e2c35 100644 --- a/server/src/com/vaadin/ui/AbstractSplitPanel.java +++ b/server/src/com/vaadin/ui/AbstractSplitPanel.java @@ -520,7 +520,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { } @Override - public AbstractSplitPanelState getState() { + protected AbstractSplitPanelState getState() { return (AbstractSplitPanelState) super.getState(); } diff --git a/server/src/com/vaadin/ui/AbstractTextField.java b/server/src/com/vaadin/ui/AbstractTextField.java index 86315f801f..54d15eff26 100644 --- a/server/src/com/vaadin/ui/AbstractTextField.java +++ b/server/src/com/vaadin/ui/AbstractTextField.java @@ -92,7 +92,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements } @Override - public AbstractTextFieldState getState() { + protected AbstractTextFieldState getState() { return (AbstractTextFieldState) super.getState(); } diff --git a/server/src/com/vaadin/ui/Button.java b/server/src/com/vaadin/ui/Button.java index f568d770e8..c55a955679 100644 --- a/server/src/com/vaadin/ui/Button.java +++ b/server/src/com/vaadin/ui/Button.java @@ -509,7 +509,7 @@ public class Button extends AbstractComponent implements } @Override - public ButtonState getState() { + protected ButtonState getState() { return (ButtonState) super.getState(); } diff --git a/server/src/com/vaadin/ui/CheckBox.java b/server/src/com/vaadin/ui/CheckBox.java index 158c9d0032..6da86b9711 100644 --- a/server/src/com/vaadin/ui/CheckBox.java +++ b/server/src/com/vaadin/ui/CheckBox.java @@ -106,7 +106,7 @@ public class CheckBox extends AbstractField<Boolean> { } @Override - public CheckBoxState getState() { + protected CheckBoxState getState() { return (CheckBoxState) super.getState(); } diff --git a/server/src/com/vaadin/ui/Component.java b/server/src/com/vaadin/ui/Component.java index ff7ed47930..89e282d4e1 100644 --- a/server/src/com/vaadin/ui/Component.java +++ b/server/src/com/vaadin/ui/Component.java @@ -23,7 +23,6 @@ import java.util.Locale; import com.vaadin.Application; import com.vaadin.event.FieldEvents; -import com.vaadin.shared.ComponentState; import com.vaadin.terminal.ErrorMessage; import com.vaadin.terminal.Resource; import com.vaadin.terminal.Sizeable; @@ -624,19 +623,6 @@ public interface Component extends ClientConnector, Sizeable, Serializable { public Locale getLocale(); /** - * Returns the current shared state bean for the component. The state (or - * changes to it) is communicated from the server to the client. - * - * Subclasses can use a more specific return type for this method. - * - * @return The state object for the component - * - * @since 7.0 - */ - @Override - public ComponentState getState(); - - /** * 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/CssLayout.java b/server/src/com/vaadin/ui/CssLayout.java index 0192debc4a..c80986b768 100644 --- a/server/src/com/vaadin/ui/CssLayout.java +++ b/server/src/com/vaadin/ui/CssLayout.java @@ -211,7 +211,7 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier { } @Override - public CssLayoutState getState() { + protected CssLayoutState getState() { return (CssLayoutState) super.getState(); } diff --git a/server/src/com/vaadin/ui/CustomLayout.java b/server/src/com/vaadin/ui/CustomLayout.java index d47b2f92b3..0948a92e5b 100644 --- a/server/src/com/vaadin/ui/CustomLayout.java +++ b/server/src/com/vaadin/ui/CustomLayout.java @@ -123,7 +123,7 @@ public class CustomLayout extends AbstractLayout implements Vaadin6Component { } @Override - public CustomLayoutState getState() { + protected CustomLayoutState getState() { return (CustomLayoutState) super.getState(); } diff --git a/server/src/com/vaadin/ui/Form.java b/server/src/com/vaadin/ui/Form.java index a1ec0f9917..8efd85009c 100644 --- a/server/src/com/vaadin/ui/Form.java +++ b/server/src/com/vaadin/ui/Form.java @@ -200,7 +200,7 @@ public class Form extends AbstractField<Object> implements Item.Editor, } @Override - public FormState getState() { + protected FormState getState() { return (FormState) super.getState(); } diff --git a/server/src/com/vaadin/ui/GridLayout.java b/server/src/com/vaadin/ui/GridLayout.java index b31ab82741..52aef4c253 100644 --- a/server/src/com/vaadin/ui/GridLayout.java +++ b/server/src/com/vaadin/ui/GridLayout.java @@ -141,7 +141,7 @@ public class GridLayout extends AbstractLayout implements } @Override - public GridLayoutState getState() { + protected GridLayoutState getState() { return (GridLayoutState) super.getState(); } diff --git a/server/src/com/vaadin/ui/JavaScript.java b/server/src/com/vaadin/ui/JavaScript.java index 35cc1893f6..5984c63e7a 100644 --- a/server/src/com/vaadin/ui/JavaScript.java +++ b/server/src/com/vaadin/ui/JavaScript.java @@ -66,7 +66,7 @@ public class JavaScript extends AbstractExtension { } @Override - public JavaScriptManagerState getState() { + protected JavaScriptManagerState getState() { return (JavaScriptManagerState) super.getState(); } diff --git a/server/src/com/vaadin/ui/Label.java b/server/src/com/vaadin/ui/Label.java index 10fa741058..d0a6059865 100644 --- a/server/src/com/vaadin/ui/Label.java +++ b/server/src/com/vaadin/ui/Label.java @@ -151,7 +151,7 @@ public class Label extends AbstractComponent implements Property<String>, } @Override - public LabelState getState() { + protected LabelState getState() { return (LabelState) super.getState(); } diff --git a/server/src/com/vaadin/ui/Panel.java b/server/src/com/vaadin/ui/Panel.java index ba68238707..985eed8a28 100644 --- a/server/src/com/vaadin/ui/Panel.java +++ b/server/src/com/vaadin/ui/Panel.java @@ -489,7 +489,7 @@ public class Panel extends AbstractComponentContainer implements Scrollable, } @Override - public PanelState getState() { + protected PanelState getState() { return (PanelState) super.getState(); } diff --git a/server/src/com/vaadin/ui/Root.java b/server/src/com/vaadin/ui/Root.java index 020ff869fa..4b90d613bb 100644 --- a/server/src/com/vaadin/ui/Root.java +++ b/server/src/com/vaadin/ui/Root.java @@ -498,7 +498,7 @@ public abstract class Root extends AbstractComponentContainer implements } @Override - public RootState getState() { + protected RootState getState() { return (RootState) super.getState(); } diff --git a/server/src/com/vaadin/ui/TextArea.java b/server/src/com/vaadin/ui/TextArea.java index fed06b561a..f885781d46 100644 --- a/server/src/com/vaadin/ui/TextArea.java +++ b/server/src/com/vaadin/ui/TextArea.java @@ -81,7 +81,7 @@ public class TextArea extends AbstractTextField { } @Override - public TextAreaState getState() { + protected TextAreaState getState() { return (TextAreaState) super.getState(); } diff --git a/server/src/com/vaadin/ui/Video.java b/server/src/com/vaadin/ui/Video.java index 95a38c59d5..04ecc9af06 100644 --- a/server/src/com/vaadin/ui/Video.java +++ b/server/src/com/vaadin/ui/Video.java @@ -44,7 +44,7 @@ import com.vaadin.terminal.gwt.server.ResourceReference; public class Video extends AbstractMedia { @Override - public VideoState getState() { + protected VideoState getState() { return (VideoState) super.getState(); } diff --git a/server/src/com/vaadin/ui/Window.java b/server/src/com/vaadin/ui/Window.java index d1d2c25d8b..705e093bce 100644 --- a/server/src/com/vaadin/ui/Window.java +++ b/server/src/com/vaadin/ui/Window.java @@ -838,7 +838,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, } @Override - public WindowState getState() { + protected WindowState getState() { return (WindowState) super.getState(); } } |