Example usage for javafx.collections ObservableList addListener

List of usage examples for javafx.collections ObservableList addListener

Introduction

In this page you can find the example usage for javafx.collections ObservableList addListener.

Prototype

public void addListener(ListChangeListener<? super E> listener);

Source Link

Document

Add a listener to this observable list.

Usage

From source file:Main.java

public static void main(String[] args) {
    List<String> list = new ArrayList<String>();

    ObservableList<String> observableList = FXCollections.observableList(list);
    observableList.addListener(new ListChangeListener() {
        @Override/* w  ww. j a va 2  s.  c o m*/
        public void onChanged(ListChangeListener.Change change) {
            System.out.println("change!");
        }
    });
    observableList.add("item one");
    list.add("item two");
    System.out.println("Size: " + observableList.size());

}

From source file:Main.java

public static void main(String[] args) {
    List<String> list = new ArrayList<String>();

    ObservableList<String> observableList = FXCollections.observableList(list);
    observableList.addListener(new ListChangeListener() {

        @Override/*from www .  ja  va2  s  .  c  o m*/
        public void onChanged(ListChangeListener.Change change) {
            System.out.println("Detected a change! ");
            while (change.next()) {
                System.out.println("Was added? " + change.wasAdded());
                System.out.println("Was removed? " + change.wasRemoved());
                System.out.println("Was replaced? " + change.wasReplaced());
                System.out.println("Was permutated? " + change.wasPermutated());
            }
        }
    });
    observableList.add("item one");
    list.add("item two");
    System.out.println("Size: " + observableList.size());

}

From source file:Main.java

public static void main(String[] args) {
    ObservableList<String> list = FXCollections.observableArrayList("one", "two");
    System.out.println(list);// w  ww .  ja  v a2 s.c  o  m

    list.addListener(Main::onChanged);

    list.addAll("A", "B");
    System.out.println("After addAll() - list: " + list);

    list.remove(1, 3);
    System.out.println("After remove() - list: " + list);

    list.retainAll("one");
    System.out.println("After retainAll() - list: " + list);

    list.set(0, "ONE");
    System.out.println("After set() - list: " + list);
}

From source file:ninja.eivind.hotsreplayuploader.window.nodes.UploaderNode.java

private void bindList() {
    final ObservableList<ReplayFile> files = uploaderService.getFiles();
    newReplaysCount.setText(String.valueOf(files.size()));
    files.addListener(
            (ListChangeListener<ReplayFile>) c -> newReplaysCount.setText(String.valueOf(files.size())));
    newReplaysView.setItems(files.sorted(new ReplayFileComparator()));
    newReplaysView.setCellFactory(new CustomListCellFactory(uploaderService));

    uploadedReplays.textProperty().bind(uploaderService.getUploadedCount());
}

From source file:org.sleuthkit.autopsy.timeline.ui.detailview.DetailViewPane.java

/**
 * Observe the list of events that should be highlighted in this view.
 *
 *
 * @param highlightedEvents the ObservableList of events that should be
 *                          highlighted in this view.
 *///from  w w w.j av a2s .  c  om
public void setHighLightedEvents(ObservableList<TimeLineEvent> highlightedEvents) {
    highlightedEvents.addListener((Observable observable) -> {
        /*
         * build a predicate that matches events with the same description
         * as any of the events in highlightedEvents or which are selected
         */
        Predicate<EventNodeBase<?>> highlightPredicate = highlightedEvents.stream() // => events
                .map(TimeLineEvent::getDescription)// => event descriptions 
                .map(new Function<String, Predicate<EventNodeBase<?>>>() {
                    @Override
                    public Predicate<EventNodeBase<?>> apply(String description) {
                        return eventNode -> StringUtils.equalsIgnoreCase(eventNode.getDescription(),
                                description);
                    }
                })// => predicates that match strings agains the descriptions of the events in highlightedEvents
                .reduce(getSelectedNodes()::contains, Predicate::or); // => predicate that matches an of the descriptions or selected nodes
        getChart().setHighlightPredicate(highlightPredicate); //use this predicate to highlight nodes
    });
}