@@ -22,6 +22,7 @@ import com.google.gwt.event.shared.GwtEvent; | |||
import com.google.web.bindery.event.shared.HandlerRegistration; | |||
import com.vaadin.shared.Connector; | |||
import com.vaadin.shared.communication.ClientRpc; | |||
import com.vaadin.shared.communication.SharedState; | |||
import com.vaadin.terminal.gwt.client.communication.StateChangeEvent.StateChangeHandler; | |||
/** | |||
@@ -142,4 +143,13 @@ public interface ServerConnector extends Connector { | |||
public void setChildren(List<ServerConnector> children); | |||
public List<ServerConnector> getChildren(); | |||
/** | |||
* Gets the current shared state of the connector. | |||
* | |||
* @since 7.0. | |||
* @return state The shared state object. Can be any sub type of | |||
* {@link SharedState}. Never null. | |||
*/ | |||
public SharedState getState(); | |||
} |
@@ -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. |
@@ -166,7 +166,7 @@ public abstract class AbstractJavaScriptExtension extends AbstractExtension { | |||
} | |||
@Override | |||
public JavaScriptExtensionState getState() { | |||
protected JavaScriptExtensionState getState() { | |||
return (JavaScriptExtensionState) super.getState(); | |||
} | |||
} |
@@ -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 |
@@ -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; | |||
} |
@@ -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; | |||
@@ -234,12 +236,6 @@ public class DragAndDropService implements VariableOwner, ClientConnector { | |||
return false; | |||
} | |||
@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; | |||
} | |||
} |
@@ -61,7 +61,7 @@ public class AbsoluteLayout extends AbstractLayout implements | |||
} | |||
@Override | |||
public AbsoluteLayoutState getState() { | |||
protected AbsoluteLayoutState getState() { | |||
return (AbsoluteLayoutState) super.getState(); | |||
} | |||
@@ -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(); | |||
} | |||
@@ -1615,7 +1615,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements | |||
} | |||
@Override | |||
public AbstractFieldState getState() { | |||
protected AbstractFieldState getState() { | |||
return (AbstractFieldState) super.getState(); | |||
} | |||
@@ -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(); | |||
} | |||
} |
@@ -29,7 +29,7 @@ public abstract class AbstractLayout extends AbstractComponentContainer | |||
implements Layout { | |||
@Override | |||
public AbstractLayoutState getState() { | |||
protected AbstractLayoutState getState() { | |||
return (AbstractLayoutState) super.getState(); | |||
} | |||
@@ -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(); | |||
} | |||
@@ -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(); |
@@ -520,7 +520,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { | |||
} | |||
@Override | |||
public AbstractSplitPanelState getState() { | |||
protected AbstractSplitPanelState getState() { | |||
return (AbstractSplitPanelState) super.getState(); | |||
} | |||
@@ -92,7 +92,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements | |||
} | |||
@Override | |||
public AbstractTextFieldState getState() { | |||
protected AbstractTextFieldState getState() { | |||
return (AbstractTextFieldState) super.getState(); | |||
} | |||
@@ -509,7 +509,7 @@ public class Button extends AbstractComponent implements | |||
} | |||
@Override | |||
public ButtonState getState() { | |||
protected ButtonState getState() { | |||
return (ButtonState) super.getState(); | |||
} | |||
@@ -106,7 +106,7 @@ public class CheckBox extends AbstractField<Boolean> { | |||
} | |||
@Override | |||
public CheckBoxState getState() { | |||
protected CheckBoxState getState() { | |||
return (CheckBoxState) super.getState(); | |||
} | |||
@@ -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; | |||
@@ -623,19 +622,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 |
@@ -211,7 +211,7 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier { | |||
} | |||
@Override | |||
public CssLayoutState getState() { | |||
protected CssLayoutState getState() { | |||
return (CssLayoutState) super.getState(); | |||
} | |||
@@ -123,7 +123,7 @@ public class CustomLayout extends AbstractLayout implements Vaadin6Component { | |||
} | |||
@Override | |||
public CustomLayoutState getState() { | |||
protected CustomLayoutState getState() { | |||
return (CustomLayoutState) super.getState(); | |||
} | |||
@@ -200,7 +200,7 @@ public class Form extends AbstractField<Object> implements Item.Editor, | |||
} | |||
@Override | |||
public FormState getState() { | |||
protected FormState getState() { | |||
return (FormState) super.getState(); | |||
} | |||
@@ -141,7 +141,7 @@ public class GridLayout extends AbstractLayout implements | |||
} | |||
@Override | |||
public GridLayoutState getState() { | |||
protected GridLayoutState getState() { | |||
return (GridLayoutState) super.getState(); | |||
} | |||
@@ -66,7 +66,7 @@ public class JavaScript extends AbstractExtension { | |||
} | |||
@Override | |||
public JavaScriptManagerState getState() { | |||
protected JavaScriptManagerState getState() { | |||
return (JavaScriptManagerState) super.getState(); | |||
} | |||
@@ -151,7 +151,7 @@ public class Label extends AbstractComponent implements Property<String>, | |||
} | |||
@Override | |||
public LabelState getState() { | |||
protected LabelState getState() { | |||
return (LabelState) super.getState(); | |||
} | |||
@@ -489,7 +489,7 @@ public class Panel extends AbstractComponentContainer implements Scrollable, | |||
} | |||
@Override | |||
public PanelState getState() { | |||
protected PanelState getState() { | |||
return (PanelState) super.getState(); | |||
} | |||
@@ -498,7 +498,7 @@ public abstract class Root extends AbstractComponentContainer implements | |||
} | |||
@Override | |||
public RootState getState() { | |||
protected RootState getState() { | |||
return (RootState) super.getState(); | |||
} | |||
@@ -81,7 +81,7 @@ public class TextArea extends AbstractTextField { | |||
} | |||
@Override | |||
public TextAreaState getState() { | |||
protected TextAreaState getState() { | |||
return (TextAreaState) super.getState(); | |||
} | |||
@@ -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(); | |||
} | |||
@@ -838,7 +838,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, | |||
} | |||
@Override | |||
public WindowState getState() { | |||
protected WindowState getState() { | |||
return (WindowState) super.getState(); | |||
} | |||
} |
@@ -17,8 +17,6 @@ package com.vaadin.shared; | |||
import java.io.Serializable; | |||
import com.vaadin.shared.communication.SharedState; | |||
/** | |||
* Interface implemented by all classes that are capable of communicating with | |||
* the server or the client side. | |||
@@ -40,15 +38,6 @@ import com.vaadin.shared.communication.SharedState; | |||
* @since 7.0.0 | |||
*/ | |||
public interface Connector extends Serializable { | |||
/** | |||
* Gets the current shared state of the connector. | |||
* | |||
* @since 7.0. | |||
* @return state The shared state object. Can be any sub type of | |||
* {@link SharedState}. Never null. | |||
*/ | |||
public SharedState getState(); | |||
/** | |||
* Returns the id for this connector. This is set by the framework and does | |||
* not change during the lifetime of a connector. |