Verified Owner
Top Description Fields Constructors Methods
org.jabref.logic.util

public final Class ObservablesHelper

extends Object
Class Inheritance
Imports
java.util.List, java.util.concurrent.Callable, javafx.beans.Observable, javafx.beans.binding.Bindings, .ObjectBinding, javafx.beans.property.Property, javafx.collections.FXCollections, .ObservableList, org.slf4j.Logger, .LoggerFactory

Utility methods for working with JavaFX Observable objects in non-GUI logic code.

GUI code should use BindingsHelper from jabgui instead.

Field Summary

Modifier and TypeField and Description
private static final Logger

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <
The type of the closable resource, which must implement AutoCloseable.
T extends AutoCloseable
>
ObjectBinding<T>

Returns:

An ObjectBinding<T> that automatically closes previous instances upon recalculation or disposal.
createClosableObjectBinding
(final Callable<T>
The factory Callable used to compute the new resource.
func
,
final Observable...
The observables that this binding should listen to for invalidation.
dependencies
)

Creates an ObjectBinding that safely manages the lifecycle of AutoCloseable resources.

public static <T extends AutoCloseable> ObjectBinding<T>
createClosableObjectBinding(final Callable<T> func, final List<Property<?>> dependencies)

public static <T> ObjectBinding<T>
createObjectBinding(final Callable<T> func, final List<? extends Observable> dependencies)

public static <T> void
onChange(List<? extends Observable> observables, Runnable... actions)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGGERback to summary
private static final Logger LOGGER

Constructor Detail

ObservablesHelperback to summary
private ObservablesHelper()

Method Detail

createClosableObjectBindingback to summary
public static <T extends AutoCloseable> ObjectBinding<T> createClosableObjectBinding(final Callable<T> func, final Observable... dependencies)

Creates an ObjectBinding that safely manages the lifecycle of AutoCloseable resources.

Standard JavaFX bindings are lazy and stateless, which can lead to resource leaks when binding to heavy or stateful objects (like file streams, external processes, or specialized internal components). This utility creates a binding that retains a reference to its previously calculated value and guarantees that AutoCloseable#close() is invoked on the old value immediately before a new value is computed.

Lifecycle & Memory Management:

  • Lazy Evaluation: Old resources are closed only when a new value is explicitly requested via .get() after invalidation.
  • Disposal: The active resource is automatically closed when ObjectBinding#dispose() is called.

Note

Exceptions thrown during the closing of old resources or the computation of new ones are caught and logged to prevent crashing the JavaFX application thread. If computation fails, the binding will evaluate to null.

Parameters
<T>
The type of the closable resource, which must implement AutoCloseable.
func:Callable<T>

The factory Callable used to compute the new resource.

dependencies:Observable[]

The observables that this binding should listen to for invalidation.

Returns:ObjectBinding<T>

An ObjectBinding<T> that automatically closes previous instances upon recalculation or disposal.

createClosableObjectBindingback to summary
public static <T extends AutoCloseable> ObjectBinding<T> createClosableObjectBinding(final Callable<T> func, final List<Property<?>> dependencies)
createObjectBindingback to summary
public static <T> ObjectBinding<T> createObjectBinding(final Callable<T> func, final List<? extends Observable> dependencies)
onChangeback to summary
public static <T> void onChange(List<? extends Observable> observables, Runnable... actions)