/** * Add this extension to the target connector. This method is protected to * allow subclasses to require a more specific type of target. * * @param target * the connector to attach this extension to */ protected void extend(AbstractClientConnector target) { target.addExtension(this); }
@Override public Registration addAttachListener(AttachListener listener) { return addListener(AttachEvent.ATTACH_EVENT_IDENTIFIER, AttachEvent.class, listener, AttachListener.attachMethod); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.getDeclaringClass() == Object.class) { // Don't add Object methods such as toString and hashCode as // invocations return method.invoke(this, args); } addMethodInvocationToQueue(rpcInterfaceName, method, args); return null; }
@Override public void markAsDirty() { assert getSession() == null || getSession().hasLock() : buildLockAssertMessage( "markAsDirty()"); UI uI = getUI(); if (uI != null) { uI.getConnectorTracker().markDirty(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; }
/** * Add an extension to this connector. This method is protected to allow * extensions to select which targets they can extend. * * @param extension * the extension to add */ protected void addExtension(Extension extension) { ClientConnector previousParent = extension.getParent(); if (equals(previousParent)) { // Nothing to do, already attached return; } else if (previousParent != null) { throw new IllegalStateException( "Moving an extension from one parent to another is not supported"); } extensions.add(extension); extension.setParent(this); markAsDirty(); }
@Override public Class<? extends SharedState> getStateType() { // Lazy load because finding type can be expensive because of the // exceptions flying around if (stateType == null) { // Cache because we don't need to do this once per instance stateType = STATE_TYPE_CACHE.computeIfAbsent(this.getClass(), key -> findStateType()); } return stateType; }
@Override public void detach() { super.detach(); if (actionManager != null) { // Remove any existing viewer. UI cast is just to make the // compiler happy actionManager.setViewer((UI) null); } }
@Override public void attach() { super.attach(); if (delayedFocus) { focus(); } setActionManagerViewer(); if (locale != null) { getUI().getLocaleService().addLocale(locale); } }
@Override public void beforeClientResponse(boolean initial) { super.beforeClientResponse(initial); // TODO This logic should be on the client side and the state should // simply be a data object with "width" and "height". if (getHeight() >= 0 && (getHeightUnits() != Unit.PERCENTAGE || ComponentSizeValidator.parentCanDefineHeight(this))) { getState().height = "" + getCSSHeight(); } else { getState().height = ""; } if (getWidth() >= 0 && (getWidthUnits() != Unit.PERCENTAGE || ComponentSizeValidator.parentCanDefineWidth(this))) { getState().width = "" + getCSSWidth(); } else { getState().width = ""; } ErrorMessage error = getErrorMessage(); if (null != error) { getState().errorMessage = error.getFormattedHtmlMessage(); getState().errorLevel = error.getErrorLevel(); } else { getState().errorMessage = null; getState().errorLevel = null; } }
public void invokeCallback(String name, Object... arguments) { if (callbacks.containsKey(name)) { throw new IllegalStateException("Can't call callback " + name + " on the client because a callback with the same name is registered on the server."); } JsonArray args = (JsonArray) JsonCodec .encode(arguments, null, Object[].class, null) .getEncodedValue(); connector.addMethodInvocationToQueue( JavaScriptCallbackRpc.class.getName(), CALL_METHOD, new Object[] { name, args }); }
@Override public Registration addDetachListener(DetachListener listener) { return addListener(DetachEvent.DETACH_EVENT_IDENTIFIER, DetachEvent.class, listener, DetachListener.detachMethod); }