public void invalidateResults(boolean error) { xpathResultListView.getItems().clear(); parent.resetXPathResults(); violationsTitledPane.setTitle("Matched nodes" + (error ? "\t(error)" : "")); }
private void onRemoveFileClicked() { File f = fileListView.getSelectionModel().getSelectedItem(); fileListView.getItems().remove(f); }
private Button addButton(final ListView<String> listView) { final Button button = new Button("Add Item", FontAwesome.PLUS.view()); button.setOnAction(e -> { final int newIndex = listView.getItems().size(); final Set<String> set = new HashSet<>(strings); final AtomicInteger i = new AtomicInteger(0); while (!set.add(DEFAULT_FIELD + i.incrementAndGet())) {} listView.getItems().add(DEFAULT_FIELD + i.get()); listView.scrollTo(newIndex); listView.getSelectionModel().select(newIndex); // There is a strange behavior in JavaFX if you try to start editing // a field on the same animation frame as another field lost focus. // Therefore, we wait one animation cycle before setting the field // into the editing state runLater(() -> listView.edit(newIndex)); }); return button; }
private Button removeButton(final ListView<String> listView) { final Button button = new Button("Remove Selected", FontAwesome.TIMES.view()); button.setOnAction(e -> { final int selectedIdx = listView.getSelectionModel().getSelectedIndex(); if (selectedIdx != -1 && listView.getItems().size() > 1) { final int newSelectedIdx = (selectedIdx == listView.getItems().size() - 1) ? selectedIdx - 1 : selectedIdx; listView.getItems().remove(selectedIdx); listView.getSelectionModel().select(newSelectedIdx); } }); return button; }
private void updateListHeight() { final double height = Math.min(suggestionList.getItems().size(), getSkinnable().getCellLimit()) * suggestionList.getFixedCellSize(); suggestionList.setPrefHeight(height + suggestionList.getFixedCellSize() / 2); }
private void moveItem(int direction) { // Checking selected item if (fileListView.getSelectionModel().getSelectedItem() == null) { return; } // Calculate new index using move direction int newIndex = fileListView.getSelectionModel().getSelectedIndex() + direction; if (newIndex < 0 || newIndex >= fileListView.getItems().size()) { return; } File selected = fileListView.getSelectionModel().getSelectedItem(); // Removing removable element fileListView.getItems().remove(selected); // Insert it in new position fileListView.getItems().add(newIndex, selected); //Restore Selection fileListView.scrollTo(newIndex); fileListView.getSelectionModel().select(newIndex); }
@Override protected void layoutChildren() { super.layoutChildren(); if (itemChanged) { if (suggestionList.getItems().size() > 0) { suggestionList.getSelectionModel().select(0); suggestionList.scrollTo(0); } itemChanged = false; } } };
private void onSelectFileClicked() { FileChooser chooser = new FileChooser(); chooser.setTitle("Add files to the auxilliary classpath"); chooser.getExtensionFilters().addAll( new FileChooser.ExtensionFilter("Java archives", "*.jar", "*.war", "*.ear"), new FileChooser.ExtensionFilter("Java class files", "*.class") ); List<File> files = chooser.showOpenMultipleDialog(designerRoot.getMainStage()); fileListView.getItems().addAll(files); }
private double estimateHeight() { // compute the border/padding for the list double borderWidth = snapVerticalInsets(); // compute the gap between list cells JFXListView<T> listview = (JFXListView<T>) getSkinnable(); double gap = listview.isExpanded() ? ((JFXListView<T>) getSkinnable()).getVerticalGap() * (getSkinnable().getItems() .size()) : 0; // compute the height of each list cell double cellsHeight = 0; for (int i = 0; i < flow.getCellCount(); i++) { ListCell<T> cell = flow.getCell(i); cellsHeight += cell.getHeight(); } return cellsHeight + gap + borderWidth; }
onApply.accept(fileListView.getItems()); });
javaList.getItems().add(ITEM + i);
suggestionList.setFixedCellSize(control.getFixedCellSize()); control.fixedCellSizeProperty().addListener(observable -> suggestionList.setFixedCellSize(control.getFixedCellSize())); suggestionList.getItems().addListener((InvalidationListener) observable -> { itemChanged = true; updateListHeight();
@Override protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) { final int itemsCount = getSkinnable().getItems().size(); if (getSkinnable().maxHeightProperty().isBound() || itemsCount <= 0) { return super.computePrefHeight(width, topInset, rightInset, bottomInset, leftInset); } final double fixedCellSize = getSkinnable().getFixedCellSize(); double computedHeight = fixedCellSize != Region.USE_COMPUTED_SIZE ? fixedCellSize * itemsCount + snapVerticalInsets() : estimateHeight(); double height = super.computePrefHeight(width, topInset, rightInset, bottomInset, leftInset); if (height > computedHeight) { height = computedHeight; } if (getSkinnable().getMaxHeight() > 0 && computedHeight > getSkinnable().getMaxHeight()) { return getSkinnable().getMaxHeight(); } return height; }
@Override public void initialize(URL location, ResourceBundle resources) { BooleanBinding noSelection = fileListView.getSelectionModel().selectedItemProperty().isNull(); removeFileButton.disableProperty().bind(noSelection); moveItemUpButton.disableProperty().bind(noSelection.or(fileListView.getSelectionModel().selectedIndexProperty().isEqualTo(0))); // we can't just map the val because we need an ObservableNumberValue IntegerBinding lastIndexBinding = Bindings.createIntegerBinding(() -> fileListView.getItems().size() - 1, Val.wrap(fileListView.itemsProperty()).flatMap(LiveList::sizeOf)); moveItemDownButton.disableProperty().bind(noSelection.or(fileListView.getSelectionModel().selectedIndexProperty().isEqualTo(lastIndexBinding))); fileListView.setCellFactory(DesignerUtil.simpleListCellFactory(File::getName, File::getAbsolutePath)); selectFilesButton.setOnAction(e -> onSelectFileClicked()); removeFileButton.setOnAction(e -> onRemoveFileClicked()); moveItemUpButton.setOnAction(e -> moveUp()); moveItemDownButton.setOnAction(e -> moveDown()); }
yearsListView.getItems().add(Integer.toString(1900 + i));
/** * Get the number of rows in the list. * * @param list * @return number of rows in list */ public static int numberOfRowsIn(ListView<?> list) { return list.getItems().size(); }
void selectAllValues() { checkListView.getItems().stream() .forEach(item -> item.selectedProperty().set(true)); } void unSelectAllValues() {
void unSelectAllValues() { checkListView.getItems().stream() .forEach(item -> item.selectedProperty().set(false)); } void selectValue(Object value) {
private void moveToTargetAll() { move(getSourceListView(), getTargetListView(), new ArrayList<>( getSourceListView().getItems())); getSourceListView().getSelectionModel().clearSelection(); }