/** Unbinds this dialog from its backing properties. */ public void free() { backingDescriptor.ifPresent(PropertyDescriptorSpec::unbind); backingDescriptor.setValue(null); backingDescriptorList.setValue(null); this.nameProperty().setValue(""); // necessary to get the validator to reevaluate each time }
/** * Binds the underlying property to a source of values (UI property). The UI * property is also initialised using a setter. * * @param underlying The underlying property * @param ui The property exposed to the user (the one in this wizard) * @param setter Setter to initialise the UI value * @param <T> Type of values */ public static <T> void rewireInit(Property<T> underlying, ObservableValue<? extends T> ui, Consumer<? super T> setter) { setter.accept(underlying.getValue()); rewire(underlying, ui); }
@Override protected Node createUndecoratedEditor() { final ChoiceBox<T> box = new ChoiceBox<>(alternatives); final T val = currentValue.getValue(); if (alternatives.contains(val)) { box.setValue(val); } else { box.setValue(alternatives.get(0)); } currentValue.bindBidirectional(box.valueProperty()); return box; } }
private <T> void installListener(Property<T> property, ChangeListener<? super T> listener) { property.addListener(listener); toDispose.add(() -> property.removeListener(listener)); }
public void afterChange(T newSource, P oldValue) { targetProperty = newSource != null ? targetPropertyGetter.getProperty(newSource) : null; P newValue = targetProperty != null ? targetProperty.getValue() : null; if (targetProperty != null) { targetProperty.addListener(targetChangeListener); targetProperty.addListener(targetInvalidationListener); if (newValue != oldValue) { targetInvalidationListener.invalidated(ChainedProperty.this); targetChangeListener.changed(ChainedProperty.this, oldValue, newValue); } } }
@Autowired public ImageScreenController(final CachedMedia cachedMedia) { this.cachedMedia = cachedMedia; imageProp.addListener((observable, oldValue, newValue) -> bindViewSizeToParent()); }
/** * Set the value of a JavaFX property in the current thread and then in the JavaFX thread. * Actually, if a visible node of the JavaFX scene graph is bound to the property, it * will be only possible to update its value in the JavaFX thread. * <p/> * If the property is bound, this method does nothing. */ private static void updateProperty(final Object value, final Property finalProperty) { if (finalProperty.isBound()) { System.out.println("Impossible to set the value " + value + " to " + finalProperty.getName() + ". Property is bound."); return; } try { finalProperty.setValue(value); } catch (RuntimeException e) { Platform.runLater(new Runnable() { @Override public void run() { finalProperty.setValue(value); } }); } }
@Override protected Subscription observeTargetObservable(Property<U> mapped) { if(boundTo != null) { mapped.bind(boundTo); } Subscription s1 = super.observeTargetObservable(mapped); Subscription s2 = () -> { if(boundTo != null) { mapped.unbind(); if(resetOnUnbind) { mapped.setValue(resetTo); } } }; return s1.and(s2); }
@Override public void dispose() { property.removeListener(l); } };
public P beforeChange(T oldSource) { P oldValue = targetProperty != null ? targetProperty.getValue() : null; if (targetProperty != null) { targetProperty.removeListener(targetChangeListener); targetProperty.removeListener(targetInvalidationListener); } return oldValue; }
public ConditionalBinding( Property<T> target, ObservableValue<? extends T> source, ObservableValue<Boolean> condition) { this.target = new WeakReference<>(target); this.source = source; this.condition = condition; // add an empty listener to target just to maintain a strong reference // to this object for the lifetime of target target.addListener(this); condition.addListener((ChangeListener<Boolean>) this); if(condition.getValue()) { target.bind(source); } }
@Override @SuppressWarnings("unchecked") public EventListener installListener(T element) { ElementChangeHandler ecl = new ElementChangeHandler<>(element); for (Property<?> property : element.properties()) { if (matches(property.getName())) { property.addListener(ecl); } } return ecl; }
@Override public void bind(ObservableValue<? extends Number> observable) { wrapped.bind(observable); }
@Override @SuppressWarnings("unchecked") public void uninstallListener(T element, EventListener listener) { if (listener instanceof ChangeListener) { ChangeListener cl = (ChangeListener) listener; for (Property<?> property : element.properties()) { if (matches(property.getName())) { property.removeListener(cl); } } } }
@Override public boolean isBound() { return wrapped.isBound(); }
@Override public void unsubscribe() { if(!unsubscribed) { condition.removeListener((ChangeListener<Boolean>) this); Property<T> tgt = this.target.get(); if(tgt != null) { tgt.removeListener(this); tgt.unbind(); } unsubscribed = true; } } }
/** * Unbinds the given property with the field. * * @param binding * The property to be unbound with. * * @return Returns the current field to allow for chaining. */ public F unbind(P binding) { persistentValue.unbindBidirectional(binding); binding.removeListener(externalBindingListener); return (F) this; }