/** * @deprecated As of 7.1. In 7.2 and later, use * {@link ConnectorTracker#getConnector(String) * uI.getConnectorTracker().getConnector(connectorId)} instead. * See ticket #11411. */ @Deprecated public ClientConnector getConnector(UI uI, String connectorId) { return uI.getConnectorTracker().getConnector(connectorId); }
/** * Removes StreamVariables that belong to connectors that are no longer * attached to the session. */ private void cleanStreamVariables() { if (pidToNameToStreamVariable != null) { ConnectorTracker connectorTracker = uI.getConnectorTracker(); Iterator<String> iterator = pidToNameToStreamVariable.keySet() .iterator(); while (iterator.hasNext()) { String connectorId = iterator.next(); if (connectorTracker.getConnector(connectorId) == null) { // Owner is no longer attached to the session Map<String, StreamVariable> removed = pidToNameToStreamVariable .get(connectorId); for (String key : removed.keySet()) { streamVariableToSeckey.remove(removed.get(key)); } iterator.remove(); } } } }
/** * Requests that the given UI should be fully re-rendered on the client * side. * * @since 7.1 @deprecated. As of 7.1. Should be refactored once locales are * fixed (#11378) */ @Deprecated public void repaintAll(UI ui) { getClientCache(ui).clear(); ui.getConnectorTracker().markAllConnectorsDirty(); ui.getConnectorTracker().markAllClientSidesUninitialized(); }
private void cleanStreamVariable(VaadinSession session, final UI ui, final ClientConnector owner, final String variableName) { session.accessSynchronously(() -> ui.getConnectorTracker() .cleanStreamVariable(owner.getConnectorId(), variableName)); } }
.getConnectorTracker().getDirtyVisibleConnectors();
/** * Encodes the given value to JSON. * <p> * This is a helper method that can be invoked by an {@link #encode(Object) * encode(T)} override if serializing a value of type other than * {@link #getPresentationType() the presentation type} is desired. For * instance, a {@code Renderer<Date>} could first turn a date value into a * formatted string and return {@code encode(dateString, String.class)}. * * @param value * the value to be encoded * @param type * the type of the value * @return a JSON representation of the given value */ protected <U> JsonValue encode(U value, Class<U> type) { return JsonCodec .encode(value, null, type, getUI().getConnectorTracker()) .getEncodedValue(); }
/** * @deprecated As of 7.1. See #11411. */ @Deprecated public static JsonObject encodeState(ClientConnector connector, SharedState state) { UI uI = connector.getUI(); ConnectorTracker connectorTracker = uI.getConnectorTracker(); Class<? extends SharedState> stateType = connector.getStateType(); JsonValue diffState = connectorTracker.getDiffState(connector); if (diffState == null) { // Use an empty state object as reference for full // repaints diffState = REFERENCE_DIFF_STATES.get(stateType); if (diffState == null) { diffState = createReferenceDiffStateState(stateType); REFERENCE_DIFF_STATES.put(stateType, diffState); } } EncodeResult encodeResult = JsonCodec.encode(state, diffState, stateType, uI.getConnectorTracker()); connectorTracker.setDiffState(connector, (JsonObject) encodeResult.getEncodedValue()); return (JsonObject) encodeResult.getDiff(); }
/** * 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); } }
/** * 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; }
UI ui = getUI(); if (ui != null) { ui.getConnectorTracker().getDiffState(Grid.this) .remove(diffStateKey);
private String getStreamVariableTargetUrl(String name, StreamVariable value) { String connectorId = getConnectorId(); UI ui = getUI(); int uiId = ui.getUIId(); String key = uiId + "/" + connectorId + "/" + name; ConnectorTracker connectorTracker = ui.getConnectorTracker(); connectorTracker.addStreamVariable(connectorId, name, value); String secKey = connectorTracker.getSeckey(value); return ApplicationConstants.APP_PROTOCOL_PREFIX + ServletPortletHelper.UPLOAD_URL_PREFIX + key + "/" + secKey; }
/** * Triggered when the user unchecks the select all checkbox. * * @param userOriginated * {@code true} if originated from client side by user */ protected void onDeselectAll(boolean userOriginated) { if (userOriginated) { verifyUserCanSelectAll(); // all selected state has been update in client side already getState(false).allSelected = false; getUI().getConnectorTracker().getDiffState(this).put("allSelected", false); } else { getState().allSelected = false; } updateSelection(Collections.emptySet(), new LinkedHashSet<>(selection), userOriginated); }
/** * @deprecated As of 7.1. See #11411. */ @Deprecated public String getStreamVariableTargetUrl(ClientConnector owner, String name, StreamVariable value) { /* * We will use the same APP/* URI space as ApplicationResources but * prefix url with UPLOAD * * e.g. APP/UPLOAD/[UIID]/[PID]/[NAME]/[SECKEY] * * SECKEY is created on each paint to make URL's unpredictable (to * prevent CSRF attacks). * * NAME and PID from URI forms a key to fetch StreamVariable when * handling post */ String paintableId = owner.getConnectorId(); UI ui = owner.getUI(); int uiId = ui.getUIId(); String key = uiId + "/" + paintableId + "/" + name; ConnectorTracker connectorTracker = ui.getConnectorTracker(); connectorTracker.addStreamVariable(paintableId, name, value); String seckey = connectorTracker.getSeckey(value); return ApplicationConstants.APP_PROTOCOL_PREFIX + ServletPortletHelper.UPLOAD_URL_PREFIX + key + "/" + seckey; }
.getConnectorTracker().getDirtyVisibleConnectors();
@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); }
/** * Triggered when the user checks the select all checkbox. * * @param userOriginated * {@code true} if originated from client side by user */ protected void onSelectAll(boolean userOriginated) { if (userOriginated) { verifyUserCanSelectAll(); // all selected state has been updated in client side already getState(false).allSelected = true; getUI().getConnectorTracker().getDiffState(this).put("allSelected", true); } else { getState().allSelected = true; } Stream<T> allItemsStream; DataProvider<T, ?> dataProvider = getGrid().getDataProvider(); // this will fetch everything from backend if (dataProvider instanceof HierarchicalDataProvider) { allItemsStream = fetchAllHierarchical( (HierarchicalDataProvider<T, ?>) dataProvider); } else { allItemsStream = fetchAll(dataProvider); } LinkedHashSet<T> allItems = new LinkedHashSet<>(); allItemsStream.forEach(allItems::add); updateSelection(allItems, Collections.emptySet(), userOriginated); }
.getConnectorTracker().getDirtyVisibleConnectors();
if (!getConnectorTracker().hasDirtyConnectors()) {