javafx.collections.ListChangeListener Java Examples

The following examples show how to use javafx.collections.ListChangeListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CSSFXMonitor.java    From scenic-view with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onChanged(javafx.collections.ListChangeListener.Change<? extends String> c) {
    while (c.next()) {
        if (c.wasRemoved()) {
            for (String removedURI : c.getRemoved()) {
                if (!isAManagedSourceURI(removedURI)) {
                    registrar.unregister(origin, removedURI);
                }
            }
        }
        if (c.wasAdded()) {
            for (String newURI : c.getAddedSubList()) {
                if (!isAManagedSourceURI(newURI)) {
                    registrar.register(origin, newURI, c.getList());
                }
            }
        }
    }
}
 
Example #2
Source File: FilterController.java    From trex-stateless-gui with Apache License 2.0 6 votes vote down vote up
public FilterController() {
    Initialization.initializeFXML(this, "/fxml/pkt_capture/Filter.fxml");
    PortsManager.getInstance().addPortServiceModeChangedListener(this::updateFilters);
    updateFilters();

    applyBtn.setOnAction(event -> {
        onUpdateHandlers.forEach(UpdateFilterHandler::onFilterUpdate);
        applyBtn.setDisable(true);
    });

    rxFilter
            .getCheckModel()
            .getCheckedItems()
            .addListener((ListChangeListener<String>) c -> applyBtn.setDisable(!applyBtnDisabled));

    txFilter
            .getCheckModel()
            .getCheckedItems()
            .addListener((ListChangeListener<String>) c -> applyBtn.setDisable(!applyBtnDisabled));

    bpfFilter
            .textProperty()
            .addListener((observableValue, oldValue, newValue) -> applyBtn.setDisable(!applyBtnDisabled));
}
 
Example #3
Source File: Chart.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
protected void rendererChanged(final ListChangeListener.Change<? extends Renderer> change) {
    FXUtils.assertJavaFxThread();
    while (change.next()) {
        // handle added renderer
        change.getAddedSubList().forEach(renderer -> {
            // update legend and recalculateLayout on datasetChange
            renderer.getDatasets().addListener(datasetChangeListener);
            // add listeners to all datasets already in the renderer
            renderer.getDatasets().forEach(set -> set.addListener(dataSetDataListener));
        });

        // handle removed renderer
        change.getRemoved().forEach(renderer -> {
            renderer.getDatasets().removeListener(datasetChangeListener);
            renderer.getDatasets().forEach(set -> set.removeListener(dataSetDataListener));
        });
    }
    // reset change to allow derived classes to add additional listeners to renderer changes
    change.reset();

    requestLayout();
    updateLegend(getDatasets(), getRenderers());
}
 
Example #4
Source File: MultiSelect.java    From tornadofx-controls with Apache License 2.0 6 votes vote down vote up
private void configureItemChangeListener() {
	items.addListener((ListChangeListener<E>) c -> {
		while (c.next()) {
			if (c.wasRemoved())
				getChildren().remove(c.getFrom(), c.getTo() + 1);

			if (c.wasAdded()) {
				for (int i = 0; i < c.getAddedSize(); i++) {
					E item = c.getAddedSubList().get(i);
					Node cell = getCellFactory().apply(this, item);
					getChildren().add(i + c.getFrom(), cell);
				}
			}
		}
	});
}
 
Example #5
Source File: TableViewer.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
protected void rendererChanged(final ListChangeListener.Change<? extends Renderer> change) {
    boolean dataSetChanges = false;
    while (change.next()) {
        // handle added renderer
        change.getAddedSubList().forEach(renderer -> renderer.getDatasets().addListener(datasetChangeListener));
        if (!change.getAddedSubList().isEmpty()) {
            dataSetChanges = true;
        }

        // handle removed renderer
        change.getRemoved().forEach(renderer -> renderer.getDatasets().removeListener(datasetChangeListener));
        if (!change.getRemoved().isEmpty()) {
            dataSetChanges = true;
        }
    }

    if (dataSetChanges) {
        datasetsChanged(null);
    }
}
 
Example #6
Source File: DataViewer.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
public DataViewer() {
    super();
    HBox.setHgrow(this, Priority.ALWAYS);
    VBox.setVgrow(this, Priority.ALWAYS);
    getStylesheets().add(getClass().getResource("DataViewer.css").toExternalForm());

    dataViewRoot.getSubDataViews().addListener(subDataViewChangeListener);
    dataViewRoot.activeSubViewProperty().addListener(activeSubDataViewChangeListener);
    userToolBarItems.addListener((ListChangeListener<Node>) change -> updateToolBar());
    showListStyleDataViews.addListener((ch, o, n) -> updateToolBar());
    selectedViewProperty().addListener((ch, o, n) -> updateToolBar());

    windowDecorationProperty().addListener((ch, o, n) -> updateWindowDecorations(dataViewRoot));
    detachableWindowProperty().addListener((ch, o, n) -> updateDetachableWindowProperty(dataViewRoot));
    windowDecorationVisible().addListener((ch, o, n) -> setWindowDecoration(Boolean.TRUE.equals(n) ? WindowDecoration.BAR : WindowDecoration.NONE));
    closeWindowButtonVisibleProperty().addListener(closeWindowButtonHandler);

    final Label spacer = new Label();
    HBox.setHgrow(spacer, Priority.ALWAYS);
    toolBar = new ToolBar(separator1, viewList, separator2, spacer);
    this.setCenter(dataViewRoot);
    requestLayout();
}
 
Example #7
Source File: WorkbenchUtils.java    From WorkbenchFX with Apache License 2.0 6 votes vote down vote up
/**
 * 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}
 */
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);
        }
      }
    }
  });
}
 
Example #8
Source File: ToolBarFlowPane.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
public void registerListener() {
    this.getChildren().addListener((ListChangeListener.Change<? extends Node> c) -> adjustToolBarWidth());

    setOnMouseClicked(mevt -> {
        if (chart.toolBarPinnedProperty().isBound()) {
            return;
        }
        chart.setToolBarPinned(!chart.isToolBarPinned());
    });
    chart.toolBarPinnedProperty().addListener((obj, valOld, valNew) -> {
        if (valNew) {
            chart.setPinnedSide(javafx.geometry.Side.TOP);
            this.setBackground(new Background(new BackgroundFill(selectedColour, CornerRadii.EMPTY, Insets.EMPTY)));
        } else {
            chart.setPinnedSide(null);
            this.setBackground(new Background(new BackgroundFill(defaultColour, CornerRadii.EMPTY, Insets.EMPTY)));
        }
        chart.requestLayout();
    });
}
 
Example #9
Source File: TableManageController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
protected void tableChanged(ListChangeListener.Change<? extends P> change) {
//        while (change.next()) {
//            if (change.wasPermutated()) {
//                for (int i = change.getFrom(); i < change.getTo(); ++i) {
//
//                }
//            } else if (change.wasUpdated()) {
//
//            } else {
//                for (P remitem : change.getRemoved()) {
//
//                }
//                for (P additem : change.getAddedSubList()) {
//                }
//            }
//        }
        checkSelected();
    }
 
Example #10
Source File: NotificationBarPane.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
public NotificationBarPane(Node content) {
    super(content);
    progressBar = new ProgressBar();
    label = new Label("infobar!");
    bar = new HBox(label);
    bar.setMinHeight(0.0);
    bar.getStyleClass().add("info-bar");
    bar.setFillHeight(true);
    setBottom(bar);
    // Figure out the height of the bar based on the CSS. Must wait until after we've been added to the parent node.
    sceneProperty().addListener(o -> {
        if (getParent() == null) return;
        getParent().applyCss();
        getParent().layout();
        barHeight = bar.getHeight();
        bar.setPrefHeight(0.0);
    });
    items = FXCollections.observableArrayList();
    items.addListener((ListChangeListener<? super Item>) change -> {
        config();
        showOrHide();
    });
}
 
Example #11
Source File: MetaDataRenderer.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
public InfoHBox() {
    super();
    setMouseTransparent(true);

    // adjust size to 0 if there are no messages to show
    getChildren().addListener((ListChangeListener<Node>) ch -> {
        if (getChildren().isEmpty()) {
            setMinWidth(0);
            setSpacing(0);
            setPadding(Insets.EMPTY);
        } else {
            setPadding(new Insets(5, 5, 5, 5));
            setMinWidth(200);
            setSpacing(5);
        }
    });
}
 
Example #12
Source File: SyncSettingsController.java    From ariADDna with Apache License 2.0 6 votes vote down vote up
/**
 * Native init method.
 * Create VUFS folders tree view
 * @param location
 * @param resources
 */
@Override
public void initialize(URL location, ResourceBundle resources) {
    //TODO: replace to getting elements from Repository
    CheckBoxTreeItem<String> root = new CheckBoxTreeItem<>("Root");
    root.setExpanded(true);
    CheckBoxTreeItem<String> folder1 = new CheckBoxTreeItem<>("Folder1");
    folder1.getChildren().addAll(
            new CheckBoxTreeItem<>("MyFoto"),
            new CheckBoxTreeItem<>("OtherFiles")
    );
    root.getChildren().addAll(
            folder1,
            new CheckBoxTreeItem<>("Documents"),
            new CheckBoxTreeItem<>("WorkFiles"),
            new CheckBoxTreeItem<>("Projects"));

    // Create the CheckTreeView with the data
    final CheckTreeView<String> checkTreeView = new CheckTreeView<>(root);
    checkTreeView.getCheckModel().getCheckedItems()
            .addListener((ListChangeListener<TreeItem<String>>) c -> {
                System.out.println(checkTreeView.getCheckModel().getCheckedItems());
            });
    checkTreeView.setId("sync-tree-view");
    container.getChildren().add(checkTreeView);
}
 
Example #13
Source File: ContentBehavior.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void onChanged(
		ListChangeListener.Change<? extends Object> change) {
	// System.out.println("Content changed " + change);
	// XXX: An atomic operation (including setAll()) on the
	// ObservableList will lead to an atomic change here; we do not have
	// to iterate through the individual changes but may simply
	// synchronize with the list as it emerges after the changes have
	// been applied.
	// while (change.next()) {
	// if (change.wasRemoved()) {
	// removeContentPartChildren(getHost(),
	// ImmutableList.copyOf(change.getRemoved()));
	// } else if (change.wasAdded()) {
	// addContentPartChildren(getHost(),
	// ImmutableList.copyOf(change.getAddedSubList()),
	// change.getFrom());
	// } else if (change.wasPermutated()) {
	// throw new UnsupportedOperationException(
	// "Reorder not yet implemented");
	// }
	// }
	synchronizeContentPartChildren(getHost(), change.getList());
}
 
Example #14
Source File: MapPane.java    From BlockMap with MIT License 6 votes vote down vote up
public MapPane(WorldRendererCanvas renderer) {
	this.renderer = Objects.requireNonNull(renderer);
	catchEvents = new Region();
	ListChangeListener<Node> l = c -> {
		getChildren().clear();
		getChildren().addAll(decorationLayers);
		getChildren().add(catchEvents);
		getChildren().addAll(pinLayers);
		getChildren().addAll(settingsLayers);
	};
	settingsLayers.addListener(l);
	pinLayers.addListener(l);
	decorationLayers.addListener(l);

	catchEvents.setPickOnBounds(true);
	EventHandler<? super Event> refireEvent = event -> decorationLayers.forEach(l1 -> l1.fireEvent(event));
	catchEvents.addEventFilter(EventType.ROOT, refireEvent);
	pinLayers.addListener((ListChangeListener<Node>) e -> {
		while (e.next()) {
			e.getRemoved().forEach(n -> n.removeEventFilter(EventType.ROOT, refireEvent));
			e.getAddedSubList().forEach(n -> n.addEventFilter(EventType.ROOT, refireEvent));
		}
	});

	decorationLayers.add(renderer);
}
 
Example #15
Source File: DescriptiveStatisticsTimelineView.java    From AILibs with GNU Affero General Public License v3.0 6 votes vote down vote up
public DescriptiveStatisticsTimelineView(final ObservableList<Double> scores) {
	super(new NumberAxis(), new NumberAxis());

	// defining the axes
	this.getXAxis().setLabel("elapsed time (s)");

	// defining a series
	this.scores = scores;
	this.performanceSeries = new Series<>();
	this.getData().add(this.performanceSeries);
	this.update();
	scores.addListener(new ListChangeListener<Double>() {

		@Override
		public void onChanged(final Change<? extends Double> c) {
			DescriptiveStatisticsTimelineView.this.update();
		}
	});
}
 
Example #16
Source File: ProposalListPresentation.java    From bisq-core with GNU Affero General Public License v3.0 6 votes vote down vote up
@Inject
public ProposalListPresentation(ProposalService proposalService,
                                BsqStateService bsqStateService,
                                MyProposalListService myProposalListService,
                                BsqWalletService bsqWalletService,
                                ProposalValidator proposalValidator) {
    this.proposalService = proposalService;
    this.bsqStateService = bsqStateService;
    this.myProposalListService = myProposalListService;
    this.bsqWalletService = bsqWalletService;
    this.proposalValidator = proposalValidator;

    bsqStateService.addBsqStateListener(this);
    myProposalListService.addListener(this);

    proposalService.getTempProposals().addListener((ListChangeListener<Proposal>) c -> {
        updateLists();
    });
    proposalService.getProposalPayloads().addListener((ListChangeListener<ProposalPayload>) c -> {
        updateLists();
    });
}
 
Example #17
Source File: ColorPalettePreviewField.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public ColorPalettePreviewField(SimpleColorPalette palette) {
  super();
  rects = new ArrayList<>();
  listeners = new ArrayList<>();
  setPalette(palette);

  setMinWidth(RECT_HEIGHT * 10);
  setMaxWidth(RECT_HEIGHT * 20);
  setPrefWidth(palette.size() * RECT_HEIGHT);

  validDrag = false;

  palette.addListener((ListChangeListener<Color>) c -> {
    while (c.next()) {
      this.setPrefWidth(palette.size() * RECT_HEIGHT);
      if (c.wasRemoved() && selected >= palette.size()) {
        selected = palette.size() - 1;
      }
    }
    updatePreview();
  });
}
 
Example #18
Source File: CSSFXMonitor.java    From scenic-view with GNU General Public License v3.0 6 votes vote down vote up
private void monitorStages(ObservableList<? extends Window> observableStages) {
    // first listen for changes
    observableStages.addListener(new ListChangeListener<Window>() {
        @Override
        public void onChanged(javafx.collections.ListChangeListener.Change<? extends Window> c) {
            while (c.next()) {
                if (c.wasRemoved()) {
                    for (Window removedStage : c.getRemoved()) {
                        unregisterStage(removedStage);
                    }
                }
                if (c.wasAdded()) {
                    for (Window addedStage : c.getAddedSubList()) {
                        registerStage(addedStage);
                    }
                }
            }
        }
    });

    // then process already existing stages
    for (Window stage : observableStages) {
        registerStage(stage);
    }

}
 
Example #19
Source File: CSSFXMonitor.java    From scenic-view with GNU General Public License v3.0 6 votes vote down vote up
private void monitorScenes(ObservableList<Scene> observableScenes) {
    // first listen for changes
    observableScenes.addListener(new ListChangeListener<Scene>() {
        @Override
        public void onChanged(javafx.collections.ListChangeListener.Change<? extends Scene> c) {
            while (c.next()) {
                if (c.wasRemoved()) {
                    for (Scene removedScene : c.getRemoved()) {
                        unregisterScene(removedScene);
                    }
                }
                if (c.wasAdded()) {
                    for (Scene addedScene : c.getAddedSubList()) {
                        registerScene(addedScene);
                    }
                }
            }
        }
    });
    
    // then add existing values
    for (Scene s : observableScenes) {
        registerScene(s);
    }
}
 
Example #20
Source File: ListListenerHelperEx.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Infers the elementary changes constituting the change of the
 * {@link ObservableList}.
 *
 * @param <E>
 *            The element type of the {@link ObservableList} that was
 *            changed.
 * @param change
 *            The (atomic) change to infer elementary changes from.
 * @return A list of elementary changes.
 */
protected static <E> List<ElementarySubChange<E>> getElementaryChanges(
		ListChangeListener.Change<? extends E> change) {
	List<ElementarySubChange<E>> elementarySubChanges = new ArrayList<>();
	while (change.next()) {
		if (change.wasReplaced()) {
			elementarySubChanges.add(ElementarySubChange.replaced(
					change.getRemoved(), change.getAddedSubList(),
					change.getFrom(), change.getTo()));
		} else if (change.wasRemoved()) {
			elementarySubChanges.add(ElementarySubChange.removed(
					change.getRemoved(), change.getFrom(), change.getTo()));
		} else if (change.wasAdded()) {
			elementarySubChanges.add(ElementarySubChange.added(
					new ArrayList<>(change.getAddedSubList()),
					change.getFrom(), change.getTo()));
		} else if (change.wasPermutated()) {
			// find permutation
			int[] permutation = CollectionUtils.getPermutation(change);
			elementarySubChanges.add(ElementarySubChange.<E> permutated(
					permutation, change.getFrom(), change.getTo()));
		}
	}
	change.reset();
	return elementarySubChanges;
}
 
Example #21
Source File: PVList.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private void createContextMenu()
{
    // Publish selected items as PV
    final ListChangeListener<PVInfo> sel_changed = change ->
    {
        final List<ProcessVariable> pvs = change.getList()
                                                .stream()
                                                .map(info -> new ProcessVariable(info.name.get()))
                                                .collect(Collectors.toList());
        SelectionService.getInstance().setSelection(PVListApplication.DISPLAY_NAME, pvs);
    };
    table.getSelectionModel().getSelectedItems().addListener(sel_changed);
    table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

    // Context menu with selection-based entries, i.e. PV contributions
    final ContextMenu menu = new ContextMenu();
    table.setOnContextMenuRequested(event ->
    {
        menu.getItems().clear();
        ContextMenuHelper.addSupportedEntries(table, menu);
        menu.show(table.getScene().getWindow());
    });
    table.setContextMenu(menu);
}
 
Example #22
Source File: Main.java    From youtube-comment-suite with MIT License 5 votes vote down vote up
@Override
public void initialize(URL location, ResourceBundle resources) {
    logger.debug("Initialize Main");

    headerToggleGroup.getToggles().addListener((ListChangeListener<Toggle>) c -> {
        while (c.next()) {
            for (final Toggle addedToggle : c.getAddedSubList()) {
                ((ToggleButton) addedToggle).addEventFilter(MouseEvent.MOUSE_RELEASED, mouseEvent -> {
                    if (addedToggle.equals(headerToggleGroup.getSelectedToggle()))
                        mouseEvent.consume();
                });
            }
        }
    });

    settingsIcon.setImage(ImageLoader.SETTINGS.getImage());
    btnSettings.setOnAction(ae -> runLater(() -> {
        logger.debug("Open Settings");
        settings.setManaged(true);
        settings.setVisible(true);
    }));

    btnSearchComments.setOnAction(ae -> runLater(() -> {
        headerIcon.setImage(ImageLoader.SEARCH.getImage());
        content.getChildren().clear();
        content.getChildren().add(searchComments);
    }));
    btnManageGroups.setOnAction(ae -> runLater(() -> {
        headerIcon.setImage(ImageLoader.MANAGE.getImage());
        content.getChildren().clear();
        content.getChildren().add(manageGroups);
    }));
    btnSearchYoutube.setOnAction(ae -> runLater(() -> {
        headerIcon.setImage(ImageLoader.YOUTUBE.getImage());
        content.getChildren().clear();
        content.getChildren().add(searchYoutube);
    }));

    btnManageGroups.fire();
}
 
Example #23
Source File: ListExpressionHelperEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Fires notifications to all attached
 * {@link javafx.beans.InvalidationListener InvalidationListeners}, and
 * {@link ListChangeListener ListChangeListeners}.
 *
 * @param change
 *            The change that needs to be propagated.
 */
@Override
public void fireValueChangedEvent(
		ListChangeListener.Change<? extends E> change) {
	if (change != null) {
		notifyInvalidationListeners();
		// XXX: We do not notify change listeners here, as the identity of
		// the observed value did not change (see
		// https://bugs.openjdk.java.net/browse/JDK-8089169)
		notifyListChangeListeners(
				new AtomicChange<>(observableValue, change));
	}
}
 
Example #24
Source File: DirtyState.java    From tornadofx-controls with Apache License 2.0 5 votes vote down vote up
private void monitorChanges() {
    properties.addListener((ListChangeListener<Property>) change -> {
        while (change.next()) {
            if (change.wasAdded()) change.getAddedSubList().forEach(p -> p.addListener(dirtyListener));
            if (change.wasRemoved()) change.getRemoved().forEach(p -> p.removeListener(dirtyListener));
        }
    });
}
 
Example #25
Source File: Field.java    From tornadofx-controls with Apache License 2.0 5 votes vote down vote up
public void configureHGrow( Priority priority ){
    // Configure hgrow for current children
    getInputContainer().getChildren().forEach( node -> HBox.setHgrow(node, priority));

    // Add listener to support inputs added later
    getInputContainer().getChildren().addListener((ListChangeListener<Node>) c1 -> {
        while (c1.next()) if (c1.wasAdded()) c1.getAddedSubList().forEach( node -> {
            HBox.setHgrow(node, priority);
            syncVgrowConstraints( node );
        });

    });
}
 
Example #26
Source File: ConvolutionKernelManagerController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
protected void initList() {
    try {
        nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
        widthColumn.setCellValueFactory(new PropertyValueFactory<>("width"));
        heightColumn.setCellValueFactory(new PropertyValueFactory<>("height"));
        modifyColumn.setCellValueFactory(new PropertyValueFactory<>("modifyTime"));
        createColumn.setCellValueFactory(new PropertyValueFactory<>("createTime"));
        desColumn.setCellValueFactory(new PropertyValueFactory<>("description"));

        tableData.addListener(new ListChangeListener() {
            @Override
            public void onChanged(ListChangeListener.Change change) {
                checkTableData();
            }
        });
        loadList();

        tableView.setItems(tableData);
        tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
        tableView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {
            @Override
            public void changed(ObservableValue ov, Object t, Object t1) {
                checkTableSelected();
            }
        });
        checkTableSelected();
        tableView.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                if (event.getClickCount() > 1) {
                    editAction();
                }
            }
        });

    } catch (Exception e) {
        logger.error(e.toString());
    }
}
 
Example #27
Source File: TreeNode.java    From OEE-Designer with MIT License 5 votes vote down vote up
private void init() {
    // Add this node to parents children
    if (null != parent) { parent.getChildren().add(this); }

    children.addListener((ListChangeListener<TreeNode>) c -> {
        while (c.next()) {
            if (c.wasRemoved()) { c.getRemoved().forEach(removedItem -> removedItem.removeAllTreeNodeEventListeners()); }
        }
        getTreeRoot().fireTreeNodeEvent(CHILDREN_CHANGED);
    });
}
 
Example #28
Source File: SimpleControl.java    From PreferencesFX with Apache License 2.0 5 votes vote down vote up
@Override
public void setupValueChangedListeners() {
  field.validProperty().addListener(
      (observable, oldValue, newValue) -> updateStyle(INVALID_CLASS, !newValue)
  );
  field.requiredProperty().addListener(
      (observable, oldValue, newValue) -> updateStyle(REQUIRED_CLASS, newValue)
  );
  field.changedProperty().addListener(
      (observable, oldValue, newValue) -> updateStyle(CHANGED_CLASS, newValue)
  );
  field.editableProperty().addListener(
      (observable, oldValue, newValue) -> updateStyle(DISABLED_CLASS, !newValue)
  );

  field.getStyleClass().addListener((ListChangeListener<String>) c -> {
    while (c.next()) {
      if (c.wasRemoved()) {
        fieldLabel.getStyleClass().removeAll(c.getRemoved());
        node.getStyleClass().removeAll(c.getRemoved());
      }

      if (c.wasAdded()) {
        fieldLabel.getStyleClass().addAll(c.getAddedSubList());
        node.getStyleClass().addAll(c.getAddedSubList());
      }
    }
  });
}
 
Example #29
Source File: FilterableTreeItem.java    From PreferencesFX with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private ListChangeListener<? super TreeItem<T>> getChildrenListener() {
  try {
    final Field field = TreeItem.class.getDeclaredField("childrenListener");
    if (!field.isAccessible()) {
      field.setAccessible(true);
    }
    final Object value = field.get(this);
    return (ListChangeListener<? super TreeItem<T>>) value;
  } catch (NoSuchFieldException | IllegalAccessException | RuntimeException e) {
    throw new RuntimeException("Could not get field: TreeItem.childrenListener", e);
  }
}
 
Example #30
Source File: EditorAreaComponent.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Handle the request to close a file editor.
 */
@FxThread
private void processChangeTabs(@NotNull ListChangeListener.Change<? extends Tab> change) {

    if (!change.next()) {
        return;
    }

    var removed = change.getRemoved();
    if (removed == null || removed.isEmpty()) {
        return;
    }

    removed.forEach(tab -> {

        var properties = tab.getProperties();
        var fileEditor = (FileEditor) properties.get(KEY_EDITOR);
        var editFile = fileEditor.getEditFile();

        DictionaryUtils.runInWriteLock(getOpenedEditors(), editFile, ObjectDictionary::remove);

        fileEditor.notifyClosed();

        if (isIgnoreOpenedFiles()) {
            return;
        }

        var workspace = WORKSPACE_MANAGER.getCurrentWorkspace();
        if (workspace != null) {
            workspace.removeOpenedFile(editFile);
        }
    });
}