private ListChangeListener<String> getOutputToScreenLogger() { outputListener = new ListChangeListener<String>() { boolean first = true; @Override public void onChanged(ListChangeListener.Change<? extends String> change) { change.next(); Platform.runLater(() -> { List<? extends String> changedList = change.getList(); for (int index = first ? 0 : change.getFrom(); index < change.getTo(); index++) { String added = changedList.get(index); if (added != null) { outputTextArea.appendText(added); } } first = false; }); } }; return new WeakListChangeListener<>(outputListener); }
private AbstractTableView<ITask> createTaskTable(DoubleProperty horizontalScrollValue, DoubleProperty verticalScrollValue) { taskTableView = new TaskTableView<>(horizontalScrollValue, verticalScrollValue); taskTableView.setRoot(new TreeItem<>(new Task())); taskTableView.setRowFactory(new TaskTreeTableViewRowFactory(this, new TaskTableDragAndDrop(this))); taskTableView.setRowFactory(new TaskTreeTableViewRowFactory(this, new TaskTableDragAndDrop(this))); taskListChangeListener = this::taskChangeListenerHandler; project.getTaskList().addListener(new WeakListChangeListener<>(taskListChangeListener)); taskChangeListener = this::refreshSelectedTask; taskTableView.getSelectionModel().selectedItemProperty().addListener(new WeakChangeListener<>(taskChangeListener)); taskTreeItemsChangeListener = this::setSelectedTaskNull; taskTableView.getRoot().getChildren().addListener(new WeakListChangeListener<>(taskTreeItemsChangeListener)); return taskTableView; }
private AbstractTableView<IResource> createResourceTable(DoubleProperty horizontalScrollValue, DoubleProperty verticalScrollValue) { resourceTableView = new ResourceTableView<>(horizontalScrollValue, verticalScrollValue); resourceTableView.setRoot(new TreeItem<>(new Resource())); resourceTableView.setRowFactory(new ResourceTreeTableViewRowFactory(this, new ResourceTableDragAndDrop(this))); resourceListChangeListener = this::resourceChangeListenerHandler; project.getResourceList().addListener(new WeakListChangeListener<>(resourceListChangeListener)); resourceChangeListener = this::refreshSelectedResource; resourceTableView.getSelectionModel().selectedItemProperty().addListener(new WeakChangeListener<>(resourceChangeListener)); resourceTreeItemsChangeListener = this::setSelectedResourceNull; resourceTableView.getRoot().getChildren().addListener(new WeakListChangeListener<>(resourceTreeItemsChangeListener)); return resourceTableView; }
/** * Instantiates a new AutoTreeItem, sets it's Value to passed value and it's Graphic to passed node. * * @param value * the Value * @param node * the Graphic */ @SuppressWarnings("unchecked") public AutoTreeItem(T value, Node node) { super(value, node); if (value != null) { ObservableList<T> valueChildren = value.getChildren(); if (valueChildren != null) { for (T valueChild : valueChildren) { AutoTreeItem<T> treeItemChild = new AutoTreeItem<T>(valueChild); treeItemChild.setExpanded(true); getChildren().add(treeItemChild); } value.getChildren().addListener(new WeakListChangeListener<>(childrenListener)); } } }
private void initListEvents() { this.listChangeListener = new ListChangeListener<SourceType>() { @Override public void onChanged( Change<? extends SourceType> listEvent) { // We have to stage delete events, because if we process them // separately, there will be unwanted ChangeEvents on the // targetList List<TargetType> deleteStaging = new ArrayList<>(); while (listEvent.next()) { if (listEvent.wasUpdated()) { processUpdateEvent(listEvent); } else if (listEvent.wasReplaced()) { processReplaceEvent(listEvent, deleteStaging); } else if (listEvent.wasAdded()) { processAddEvent(listEvent); } else if (listEvent.wasRemoved()) { processRemoveEvent(listEvent, deleteStaging); } } // Process the staged elements processStagingLists(deleteStaging); } }; modelListProperty().addListener( new WeakListChangeListener<>(listChangeListener)); }
@Override protected void registerListeners() { super.registerListeners(); tile.getBarChartItems().addListener(new WeakListChangeListener<>(change -> { while (change.next()) { if (change.wasAdded()) { change.getAddedSubList().forEach(addedItem -> { barChartPane.getChildren().add(addedItem); addedItem.addChartDataEventListener(updateHandler); EventHandler<MouseEvent> clickHandler = e -> tile.fireTileEvent(new TileEvent(EventType.SELECTED_CHART_DATA, addedItem.getChartData())); handlerMap.put(addedItem, clickHandler); addedItem.setOnMousePressed(clickHandler); }); updateChart(); } else if (change.wasRemoved()) { change.getRemoved().forEach(removedItem -> { removedItem.removeChartDataEventListener(updateHandler); removedItem.removeEventHandler(MouseEvent.MOUSE_PRESSED, handlerMap.get(removedItem)); barChartPane.getChildren().remove(removedItem); }); updateChart(); } } })); pane.widthProperty().addListener(paneSizeListener); pane.heightProperty().addListener(paneSizeListener); }
public void setListeners() { resourceListChangeListener = change -> { while (change.next()) { if (change.wasAdded()) { change.getAddedSubList().forEach(this::addResourceLabel); } if (change.wasRemoved()) { change.getRemoved().forEach(this::removeResourceLabel); } } }; taskBar.getTask().getResourceList().addListener(new WeakListChangeListener<>(resourceListChangeListener)); }
/** * Метод инициализирующий листенеры. * */ public void setListeners(MainWindowController controller) { // Листенер который следит за добавлением новых задач. // Нужен для обновления связей при изменении положения задачи в таблице задач (при драг'н'дропе). // Если после драг'н'дропа не обновить связь, то она работает не корректно. // TODO: 04.03.2016 По хорошему необходимо обновлять связь только у тех задач которые добавились, а не перерисовывать все связи. taskListChangeListener = change -> { while (change.next()) { if (change.wasAdded()) { Platform.runLater(() -> refreshRelationsDiagram(controller)); } } }; controller.getProject().getTaskList().addListener(new WeakListChangeListener<>(taskListChangeListener)); }
/** * @param newBeanType * bean type * @param newPropertyName * bean property name * @param newSubject * property value */ public ObservableListBuffering(final Class<?> newBeanType, final String newPropertyName, final ObservableList<E> newSubject) { super(FXCollections.observableArrayList()); if (newBeanType != null || !(newSubject instanceof ReadOnlyProperty<?>)) { beanType = newBeanType; } else { final Object bean = ((ReadOnlyProperty<?>) newSubject).getBean(); beanType = (bean != null ? bean.getClass() : null); } if (newPropertyName != null || !(newSubject instanceof ReadOnlyProperty<?>)) { propertyName = newPropertyName; } else { propertyName = ((ReadOnlyProperty<?>) newSubject).getName(); } subject = Objects.requireNonNull(newSubject); addAll(subject); thisListener = c -> { if (equalsBuffering) { buffering.setValue(!equalsSubject()); } else { buffering.setValue(true); } validate(); }; subjectListener = c -> { if (!buffering.getValue()) { revert(); } }; addListener(thisListener); weakSubjectListener = new WeakListChangeListener<E>(subjectListener); subject.addListener(weakSubjectListener); validate(); }