private void populateTree(ProjectProperty project) { requireNonNull(project); final TreeItem<DocumentProperty> root = branch(project); hierarchy.setRoot(root); hierarchy.getSelectionModel().select(root); }
static ListView<String> createListView(int numOfItems, boolean multipleSelection, boolean disable, boolean horiz) { ListView<String> listView = new ListView<String>(); if (horiz) listView.setOrientation(Orientation.HORIZONTAL); listView.setPrefHeight((24*7)+4); listView.setPrefWidth(horiz ? 200 : 140); listView.getItems().addAll(sampleItems(numOfItems)); listView.setDisable(disable); if (multipleSelection) { listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); listView.getSelectionModel().selectRange(1, 5); } else { listView.getSelectionModel().select(1); } return listView; }
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; }
@Override protected void layoutChildren() { super.layoutChildren(); if (itemChanged) { if (suggestionList.getItems().size() > 0) { suggestionList.getSelectionModel().select(0); suggestionList.scrollTo(0); } itemChanged = false; } } };
private void selectItem() { T item = suggestionList.getSelectionModel().getSelectedItem(); if (item == null) { try { suggestionList.getSelectionModel().select(0); item = suggestionList.getSelectionModel().getSelectedItem(); } catch (Exception e) { } } if (item != null) { control.getSelectionHandler().handle(new JFXAutoCompleteEvent<T>(JFXAutoCompleteEvent.SELECTION, item)); } }
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); }
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; }
TreeView treeView = ... ; // initialize this TreeItem treeItem = ... ; // initialize this, too MultipleSelectionModel msm = treeView.getSelectionModel(); // This line is the not-so-clearly documented magic. int row = treeView.getRow( treeItem ); // Now the row can be selected. msm.select( row );
/** * !!important, do not select 0 automatically. Views that need to select first items must call it * explicitly because in some case (multiple listview view displayed in on page for example), it * leads to unconsistent behaviour. */ public void selectFirstItem() { getSelectionModel().select(0); }
@Override public void run() { listView.scrollTo(selection); listView.getSelectionModel().select(selection); } });
/** * Select the current/new selection * * @param container The list view in which the selection should be updated * @param newSelection The current/new selection */ private void updateNewSelection(ListView<DetailsListElement<E>> container, ListWidgetSelection<E> newSelection) { // select the new element Optional.ofNullable(newSelection).map(ListWidgetSelection::getSelection).ifPresent(selection -> { final int newValueIndex = getControl().getElements().indexOf(selection); container.getSelectionModel().select(newValueIndex); }); } }
/** * Select the current/new selection * * @param container The list view in which the selection should be updated * @param newSelection The current/new selection */ private void updateNewSelection(ListView<CompactListElement<E>> container, ListWidgetSelection<E> newSelection) { // select the new element Optional.ofNullable(newSelection).map(ListWidgetSelection::getSelection).ifPresent(selection -> { final int newValueIndex = getControl().getElements().indexOf(selection); container.getSelectionModel().select(newValueIndex); }); } }
private void updateProposals() { List<ICompletionProposal> list = this.proposalComputer.apply(new ContentAssistContextData(this.offset,this.viewer.getDocument()/*,prefix*/)); if( ! list.isEmpty() ) { this.proposalList.setItems(FXCollections.observableArrayList(list)); this.proposalList.scrollTo(0); this.proposalList.getSelectionModel().select(0); } else { this.stage.hide(); } }
@Override protected void layoutChildren() { super.layoutChildren(); if (itemChanged) { if (suggestionList.getItems().size() > 0) { suggestionList.getSelectionModel().select(0); suggestionList.scrollTo(0); } itemChanged = false; } } };
/** * Selects the first suggestion (if any), so the user can choose it * by pressing enter immediately. */ private void selectFirstSuggestion(AutoCompletePopup<?> autoCompletionPopup){ Skin<?> skin = autoCompletionPopup.getSkin(); if(skin instanceof AutoCompletePopupSkin){ AutoCompletePopupSkin<?> au = (AutoCompletePopupSkin<?>)skin; ListView<?> li = (ListView<?>)au.getNode(); if(li.getItems() != null && !li.getItems().isEmpty()){ li.getSelectionModel().select(0); } } }
@Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { if (newValue != null) { TreeItem<DisplayWorkflowClassesModel> item = search(workflowView.getRoot(), newValue); if (item != null) { workflowView.getSelectionModel().select(item); } else { workflowView.getSelectionModel().clearSelection(); } } if (newValue == null) { workflowView.getSelectionModel().clearSelection(); } } });
private void selectItem() { T item = suggestionList.getSelectionModel().getSelectedItem(); if (item == null) { try { suggestionList.getSelectionModel().select(0); item = suggestionList.getSelectionModel().getSelectedItem(); } catch (Exception e) { } } if (item != null) { control.getSelectionHandler().handle(new JFXAutoCompleteEvent<T>(JFXAutoCompleteEvent.SELECTION, item)); } }
@Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { int lineIndex = getSkinnable().getContent().getLineAtOffset(newValue.intValue()); Line lineObject = StyledTextSkin.this.lineList.get(lineIndex); getFlow().show(lineIndex); for (LineCell c : getCurrentVisibleCells()) { if (c.domainElement == lineObject) { // Adjust the selection if (StyledTextSkin.this.contentView.getSelectionModel().getSelectedItem() != c.domainElement) { StyledTextSkin.this.contentView.getSelectionModel().select(lineObject); } StyledTextLayoutContainer p = (StyledTextLayoutContainer) c.getGraphic(); p.setCaretIndex(newValue.intValue() - p.getStartOffset()); p.requestLayout(); updateCurrentCursorNode(p); return; } } } });
/** * {@inheritDoc} */ @Override public void initializeParts() { super.initializeParts(); getStyleClass().add("simple-listview-control"); fieldLabel = new Label(field.labelProperty().getValue()); listView.setItems(field.getItems()); listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); for (int i = 0; i < field.getItems().size(); i++) { if (field.getSelection().contains(field.getItems().get(i))) { listView.getSelectionModel().select(i); } else { listView.getSelectionModel().clearSelection(i); } } }
public void displayProposals(List<ICompletionProposal> proposalList, int offset, Point2D position) { setup(); this.prefix = ""; //$NON-NLS-1$ this.offset = offset; this.proposalList.setItems(FXCollections.observableArrayList(proposalList)); this.proposalList.getSelectionModel().select(0); this.stage.setX(position.getX()); this.stage.setY(position.getY()); this.stage.setWidth(300); this.stage.setHeight(200); this.stage.show(this.viewer.getTextWidget().getScene().getWindow()); this.stage.requestFocus(); }