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;
/**
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();
}
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;
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.
}
@Override
- public JavaScriptExtensionState getState() {
+ protected JavaScriptExtensionState getState() {
return (JavaScriptExtensionState) super.getState();
}
}
// 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\":");
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
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;
* @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;
}
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;
return false;
}
- @Override
- public SharedState getState() {
- // TODO Auto-generated method stub
- return null;
- }
-
@Override
public String getConnectorId() {
return ApplicationConstants.DRAG_AND_DROP_CONNECTOR_ID;
public void beforeClientResponse(boolean initial) {
// Nothing to do
}
+
+ @Override
+ public JSONObject encodeState() throws JSONException {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
}
@Override
- public AbsoluteLayoutState getState() {
+ protected AbsoluteLayoutState getState() {
return (AbsoluteLayoutState) super.getState();
}
* @return updated component shared state
*/
@Override
- public ComponentState getState() {
+ protected ComponentState getState() {
return (ComponentState) super.getState();
}
}
@Override
- public AbstractFieldState getState() {
+ protected AbstractFieldState getState() {
return (AbstractFieldState) super.getState();
}
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
* {@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>
*
}
@Override
- public JavaScriptComponentState getState() {
+ protected JavaScriptComponentState getState() {
return (JavaScriptComponentState) super.getState();
}
}
implements Layout {
@Override
- public AbstractLayoutState getState() {
+ protected AbstractLayoutState getState() {
return (AbstractLayoutState) super.getState();
}
public abstract class AbstractMedia extends AbstractComponent {
@Override
- public AbstractMediaState getState() {
+ protected AbstractMediaState getState() {
return (AbstractMediaState) super.getState();
}
}
@Override
- public AbstractOrderedLayoutState getState() {
+ protected AbstractOrderedLayoutState getState() {
return (AbstractOrderedLayoutState) super.getState();
}
return components.get(index);
}
+ @Override
public void setMargin(boolean enabled) {
setMargin(new MarginInfo(enabled));
}
*
* @see com.vaadin.ui.Layout.MarginHandler#getMargin()
*/
+ @Override
public MarginInfo getMargin() {
return new MarginInfo(getState().getMarginsBitmask());
}
*
* @see com.vaadin.ui.Layout.MarginHandler#setMargin(MarginInfo)
*/
+ @Override
public void setMargin(MarginInfo marginInfo) {
getState().setMarginsBitmask(marginInfo.getBitMask());
requestRepaint();
}
@Override
- public AbstractSplitPanelState getState() {
+ protected AbstractSplitPanelState getState() {
return (AbstractSplitPanelState) super.getState();
}
}
@Override
- public AbstractTextFieldState getState() {
+ protected AbstractTextFieldState getState() {
return (AbstractTextFieldState) super.getState();
}
}
@Override
- public ButtonState getState() {
+ protected ButtonState getState() {
return (ButtonState) super.getState();
}
}
@Override
- public CheckBoxState getState() {
+ protected CheckBoxState getState() {
return (CheckBoxState) super.getState();
}
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;
*/
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
}
@Override
- public CssLayoutState getState() {
+ protected CssLayoutState getState() {
return (CssLayoutState) super.getState();
}
}
@Override
- public CustomLayoutState getState() {
+ protected CustomLayoutState getState() {
return (CustomLayoutState) super.getState();
}
}
@Override
- public FormState getState() {
+ protected FormState getState() {
return (FormState) super.getState();
}
}
@Override
- public GridLayoutState getState() {
+ protected GridLayoutState getState() {
return (GridLayoutState) super.getState();
}
}
@Override
- public JavaScriptManagerState getState() {
+ protected JavaScriptManagerState getState() {
return (JavaScriptManagerState) super.getState();
}
}
@Override
- public LabelState getState() {
+ protected LabelState getState() {
return (LabelState) super.getState();
}
}
@Override
- public PanelState getState() {
+ protected PanelState getState() {
return (PanelState) super.getState();
}
}
@Override
- public RootState getState() {
+ protected RootState getState() {
return (RootState) super.getState();
}
}
@Override
- public TextAreaState getState() {
+ protected TextAreaState getState() {
return (TextAreaState) super.getState();
}
public class Video extends AbstractMedia {
@Override
- public VideoState getState() {
+ protected VideoState getState() {
return (VideoState) super.getState();
}
}
@Override
- public WindowState getState() {
+ protected WindowState getState() {
return (WindowState) super.getState();
}
}
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.
* @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.