/** * Finds the {@link VaadinSession} to which this connector belongs. If the * connector has not been attached, <code>null</code> is returned. * * @return The connector's session, or <code>null</code> if not attached */ protected VaadinSession getSession() { UI uI = getUI(); if (uI == null) { return null; } else { return uI.getSession(); } }
/** * Sets the expected value of a state property so that changes can be * properly sent to the client. This needs to be done in cases where a state * change originates from the client, since otherwise the server-side would * fail to recognize if the value is changed back to its previous value. * * @param propertyName * the name of the shared state property to update * @param newValue * the new diffstate reference value */ protected void updateDiffstate(String propertyName, JsonValue newValue) { if (!isAttached()) { return; } JsonObject diffState = getUI().getConnectorTracker().getDiffState(this); if (diffState == null) { return; } assert diffState.hasKey(propertyName) : "Diffstate for " + getClass().getName() + " has no property named " + propertyName; diffState.put(propertyName, newValue); } }
@Override public void markAsDirty() { assert getSession() == null || getSession().hasLock() : buildLockAssertMessage( "markAsDirty()"); UI uI = getUI(); if (uI != null) { uI.getConnectorTracker().markDirty(this); } }
@Override public void attach() { markAsDirty(); getUI().getConnectorTracker().registerConnector(this); for (ClientConnector connector : getAllChildrenIterable(this)) { connector.attach(); } fireEvent(new AttachEvent(this)); }
/** * {@inheritDoc} * * <p> * The {@link #getSession()} and {@link #getUI()} methods might return * <code>null</code> after this method is called. * </p> */ @Override public void detach() { for (ClientConnector connector : getAllChildrenIterable(this)) { connector.detach(); } fireEvent(new DetachEvent(this)); getUI().getConnectorTracker().unregisterConnector(this); }
/** * Returns the shared state for this connector. * * @param markAsDirty * true if the connector should automatically be marked dirty, * false otherwise * * @return The shared state for this connector. Never null. * @see #getState() */ protected SharedState getState(boolean markAsDirty) { assert getSession() == null || getSession().hasLock() : buildLockAssertMessage( "getState()"); if (null == sharedState) { sharedState = createState(); } if (markAsDirty) { UI ui = getUI(); if (ui != null && !ui.getConnectorTracker().isDirty(this) && !ui.getConnectorTracker().isWritingResponse()) { ui.getConnectorTracker().markDirty(this); } } return sharedState; }