public static <T> void addListListener(ObservableList<T> list,
      Consumer<T> addAction,
      Consumer<T> removeAction) {
    list.addListener((ListChangeListener<? super T>) c -> {
      while (c.next()) {
        if (!c.wasPermutated() && !c.wasUpdated()) {
          for (T remitem : c.getRemoved()) {
            removeAction.accept(remitem);
          }
          for (T additem : c.getAddedSubList()) {
            addAction.accept(additem);
          }
        }
      }
    });
  }
Adds a {@link ListChangeListener} to an {@link ObservableList}.

@param list to add a listener to
@param addAction action to be performed when an object was added to the {@link ObservableList}
@param removeAction action to be performed when an object was removed
                    from the {@link ObservableList}
@param <T> type of the {@link ObservableList}
workbenchfx-core/src/main/java/com/dlsc/workbenchfx/util/WorkbenchUtils.java