Example usage for javafx.beans Observable removeListener

List of usage examples for javafx.beans Observable removeListener

Introduction

In this page you can find the example usage for javafx.beans Observable removeListener.

Prototype

void removeListener(InvalidationListener listener);

Source Link

Document

Removes the given listener from the list of listeners, that are notified whenever the value of the Observable becomes invalid.

Usage

From source file:acmi.l2.clientmod.xdat.Controller.java

private PropertySheet createPropertySheet(TreeView<Object> elements) {
    PropertySheet properties = new PropertySheet();
    properties.setSkin(new PropertySheetSkin(properties));

    elements.getSelectionModel().selectedItemProperty().addListener((selected, oldValue, newSelection) -> {
        properties.getItems().clear();//w  ww.  j av  a2 s  .c o m

        if (newSelection == null)
            return;

        Object obj = newSelection.getValue();

        if (obj instanceof ListHolder)
            return;

        if (!map.containsKey(obj.getClass())) {
            map.put(obj.getClass(), loadProperties(obj));
        }
        List<PropertySheetItem> props = map.get(obj.getClass());
        props.forEach(property -> {
            property.setObject(obj);
            ChangeListener<Object> addToHistory = (observable1, oldValue1, newValue) -> editor.getHistory()
                    .valueChanged(treeItemToScriptString(newSelection), property.getName(), newValue);
            property.addListener(addToHistory);

            selected.addListener(new InvalidationListener() {
                @Override
                public void invalidated(Observable observable) {
                    property.removeListener(addToHistory);
                    observable.removeListener(this);
                }
            });
        });
        properties.getItems().setAll(props);
    });

    return properties;
}