/** * Handle changes to published properties that are component references. If the old and new * values are the same, no action is taken. Otherwise, the client is notified of the new value * (if syncToClient is true) and a {@link PropertychangeEvent} is fired. * * @param <T> The type of the referenced component. * @param propertyName The property name. * @param reference The property reference object. * @param newValue The new value. * @param syncToClient If true, notify client of change. * @return True if property value changed. */ protected <T extends BaseComponent> boolean propertyChange(String propertyName, ComponentReference<T> reference, T newValue, boolean syncToClient) { T oldValue = reference.getReference(); if (reference.setReference(newValue)) { propertyChange(propertyName, oldValue, newValue, false); if (syncToClient) { sync(propertyName, reference); } return true; } return false; }
/** * Sets the component to be referenced by the script language's "self" variable. If "self" is * explicitly included in the variable map passed to {@link #execute(Map)}, that value will be * used instead. * * @param self The component to be referenced by the script language's "self" variable. */ @PropertySetter(value = "self", description = "The component to be referenced by the script language's \"self\" variable.") public void setSelf(BaseComponent self) { BaseComponent oldSelf = this.self.getReference(); if (oldSelf != self) { this.self.setReference(self); propertyChange("self", oldSelf, self, false); } }
public ComponentReference(T component, Consumer<BaseComponent> onDestroy) { this.onDestroy = onDestroy; setReference(component); }