private void populateTree(ProjectProperty project) { requireNonNull(project); final TreeItem<DocumentProperty> root = branch(project); hierarchy.setRoot(root); hierarchy.getSelectionModel().select(root); }
private void displayScopes(Node node, boolean focusScopeView) { // current selection TreeItem<Object> previousSelection = scopeHierarchyTreeView.getSelectionModel().getSelectedItem(); ScopeHierarchyTreeItem rootScope = ScopeHierarchyTreeItem.buildAscendantHierarchy(node); scopeHierarchyTreeView.setRoot(rootScope); if (focusScopeView && previousSelection != null) { // Try to find the node that was previously selected and focus it in the new ascendant hierarchy. // Otherwise, when you select a node in the scope tree, since focus of the app is shifted to that // node, the scope hierarchy is reset and you lose the selection - even though obviously the node // you selected is in its own scope hierarchy so it looks buggy. int maxDepth = DesignerIteratorUtil.count(DesignerIteratorUtil.parentIterator(previousSelection, true)); rootScope.tryFindNode(previousSelection.getValue(), maxDepth) .ifPresent(scopeHierarchyTreeView.getSelectionModel()::select); } }
private void prepareTree(ProjectProperty project) { requireNonNull(project); events.notify(new ProjectLoaded(project)); Bindings.bindContent(ui.getSelectedTreeItems(), hierarchy.getSelectionModel().getSelectedItems()); hierarchy.setCellFactory(view -> new DocumentPropertyCell(projectTreeComponent)); hierarchy.getSelectionModel().setSelectionMode(SINGLE); populateTree(project); }
private void focusNodeInTreeView(Node node) { SelectionModel<TreeItem<Node>> selectionModel = astTreeView.getSelectionModel(); // node is different from the old one if (selectedTreeItem == null && node != null || selectedTreeItem != null && !Objects.equals(node, selectedTreeItem.getValue())) { ASTTreeItem found = ((ASTTreeItem) astTreeView.getRoot()).findItem(node); if (found != null) { selectionModel.select(found); } highlightFocusNodeParents(selectedTreeItem, found); selectedTreeItem = found; astTreeView.getFocusModel().focus(selectionModel.getSelectedIndex()); if (!treeViewWrapper.isIndexVisible(selectionModel.getSelectedIndex())) { astTreeView.scrollTo(selectionModel.getSelectedIndex()); } } }
@Override protected void updateItem(Node item, boolean empty) { super.updateItem(item, empty); if (empty || item == null) { setText(null); setGraphic(null); return; } else { setText(item.toString() + (item.getImage() == null ? "" : " \"" + item.getImage() + "\"")); setContextMenu(buildContextMenu(item)); } // Reclicking the selected node in the ast will scroll back to the node in the editor this.addEventHandler(MouseEvent.MOUSE_CLICKED, t -> { if (t.getButton() == MouseButton.PRIMARY && getTreeView().getSelectionModel().getSelectedItem().getValue() == item) { controller.onNodeItemSelected(item); t.consume(); } }); }
@Override protected void beforeParentInit() { xpathAttributesListView.setPlaceholder(new Label("No available attributes")); EventStreams.valuesOf(scopeHierarchyTreeView.getSelectionModel().selectedItemProperty()) .filter(Objects::nonNull) .map(TreeItem::getValue) .filterMap(o -> o instanceof NameDeclaration, o -> (NameDeclaration) o) .filter(nd -> !Objects.equals(nd.getNode(), selectedNode)) .subscribe(declaration -> Platform.runLater(() -> parent.onNodeItemSelected(declaration.getNode(), true))); scopeHierarchyTreeView.setCellFactory(view -> new ScopeHierarchyTreeCell()); hideCommonAttributesProperty() .values() .distinct() .subscribe(show -> displayAttributes(selectedNode)); }
setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); setFitToHeight(true); treeView.getSelectionModel().selectedItemProperty().addListener(observable -> { TreeItem selectedItem = treeView.getSelectionModel().getSelectedItem(); TreeItem temp = selectedItem; int level = treeView.getTreeItemLevel(temp) - (treeView.isShowRoot() ? 0 : 1);
@Override protected void beforeParentInit() { treeViewWrapper = new TreeViewWrapper<>(astTreeView); astTreeView.setCellFactory(treeView -> new ASTTreeCell(parent)); initializeLanguageSelector(); // languageVersionProperty() must be initialized languageVersionProperty().values() .filterMap(Objects::nonNull, LanguageVersion::getLanguage) .distinct() .subscribe(this::updateSyntaxHighlighter); languageVersionProperty().values() .filter(Objects::nonNull) .map(LanguageVersion::getShortName) .map(lang -> "Source Code (" + lang + ")") .subscribe(editorTitledPane::setTitle); EventStreams.valuesOf(astTreeView.getSelectionModel().selectedItemProperty()) .filterMap(Objects::nonNull, TreeItem::getValue) .subscribe(parent::onNodeItemSelected); codeEditorArea.plainTextChanges() .filter(t -> !t.isIdentity()) .successionEnds(AST_REFRESH_DELAY) // Refresh the AST anytime the text, classloader, or language version changes .or(auxclasspathClassLoader.changes()) .or(languageVersionProperty().changes()) .subscribe(tick -> { // Discard the AST if the language version has changed tick.ifRight(c -> astTreeView.setRoot(null)); Platform.runLater(parent::refreshAST); }); codeEditorArea.setParagraphGraphicFactory(lineNumberFactory()); }
@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 handleSelectionChange(Observable o) { this.selectedItems.setAll(this.tree.getSelectionModel() .getSelectedItems().stream().map(t -> t.getValue()) .collect(Collectors.toList())); }
private void handleSelectionChange(Observable o) { this.selectedItems.setAll(this.tree.getSelectionModel() .getSelectedItems().stream().map(t -> t.getValue()) .collect(Collectors.toList())); }
private void handleSelectionChange(Observable o) { this.selectedItems.setAll(this.tree.getSelectionModel() .getSelectedItems().stream().map(t -> t.getValue()) .collect(Collectors.toList())); }
private void handleSelectionChange(Observable o) { this.selectedItems.setAll(this.tree.getSelectionModel() .getSelectedItems().stream().map(t -> t.getValue()) .collect(Collectors.toList())); }
private ContingencyTreeCell() { contingencyTree.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); setOnDragOver(this::onDragOver); setOnDragDropped(this::onDragDropped); }
private void onDragDetected(MouseEvent event) { Dragboard db = substationDetailedView.startDragAndDrop(TransferMode.ANY); ClipboardContent content = new ClipboardContent(); List<EquipmentInfo> listInfo = substationDetailedView.getSelectionModel().getSelectedItems().stream().map(TreeItem :: getValue).collect(Collectors.toList()); content.put(EquipmentInfo.DATA_FORMAT, listInfo); db.setContent(content); event.consume(); }
/** * @{inheritedDoc} */ @Override public synchronized <T extends GenericEvent> void handle(T e) { super.handle(e); if (e.isA(CoreEvent.TreePopulatedFromTemplateEvent)) { LazyTreeItem item = (LazyTreeItem) treeView.getSelectionModel().getSelectedItem(); item.reloadChildren(); } else if (e.isA(CoreEvent.TreeFolderCreatedEvent)) { LazyTreeItem item = (LazyTreeItem) treeView.getSelectionModel().getSelectedItem(); item.reloadChildren(); } }
@Override public void handle(ActionEvent t) { TreeItem<CalendarNode> selectedItem = nodeList.getTreeView().getSelectionModel().getSelectedItem(); if (selectedItem != null) { CalendarNode calendarNode = selectedItem.getValue(); chart.removeNode(calendarNode); } } });
private void onKeyPressed(KeyEvent e) { if (e.getCode() == KeyCode.DELETE) { showRemoveAlert(); } else if (e.getCode() == KeyCode.F2) { TreeItem<Object> item = contingencyTree.getSelectionModel().getSelectedItem(); if (item.getValue() instanceof Contingency) { rename(); } } }
@Override public void handle(ActionEvent event) { final Clipboard clipboard = Clipboard.getSystemClipboard(); final ClipboardContent content = new ClipboardContent(); content.putString(treeView.getSelectionModel().getSelectedItem().getValue().displayName); clipboard.setContent(content); } });
private void rename() { TreeItem<Object> item = contingencyTree.getSelectionModel().getSelectedItem(); Contingency contingency = (Contingency) item.getValue(); TextInputDialog dialog = new TextInputDialog(contingency.getId()); dialog.setTitle(RESOURCE_BUNDLE.getString("RenameContingency")); dialog.setHeaderText(null); dialog.setGraphic(null); dialog.setContentText(RESOURCE_BUNDLE.getString("Name")); TextField inputField = dialog.getEditor(); BooleanBinding isInvalid = Bindings.createBooleanBinding(() -> inputField.getText().equals(contingency.getId()) || inputField.getText().isEmpty(), inputField.textProperty()); dialog.getDialogPane().lookupButton(ButtonType.OK).disableProperty().bind(isInvalid); Optional<String> result = dialog.showAndWait(); result.ifPresent(newName -> { contingency.setId(newName); contingencyTree.refresh(); saved.set(false); }); }