/** * Returns an iterator over the parents of the given node, in innermost to outermost order. */ public static <T> Iterator<TreeItem<T>> parentIterator(TreeItem<T> deepest, boolean includeSelf) { return iteratorFrom(deepest, n -> n.getParent() != null, TreeItem::getParent, includeSelf); }
@Override public int getTreeItemLevel(TreeItem<?> node) { final TreeItem<?> root = getRoot(); if (node == null) { return -1; } if (node == root) { return 0; } int level = 0; TreeItem<?> parent = node.getParent(); while (parent != null) { level++; if (parent == root) { break; } // handle group nodes if (parent.getValue() != null && parent.getValue() instanceof RecursiveTreeObject && ((RecursiveTreeObject<?>) parent.getValue()).getGroupedColumn() != null) { level--; } parent = parent.getParent(); } return level; }
/** * validates the value of the tree item, * this method also hides the column value for the grouped nodes * * @param param tree item * @return true if the value is valid else false */ public final boolean validateValue(CellDataFeatures<S, T> param) { Object rowObject = param.getValue().getValue(); return !((rowObject instanceof RecursiveTreeObject && rowObject.getClass() == RecursiveTreeObject.class) || (param.getTreeTableView() instanceof JFXTreeTableView && ((JFXTreeTableView<?>) param.getTreeTableView()).getGroupOrder().contains(this) // make sure the node is a direct child to a group node && param.getValue().getParent() != null && param.getValue().getParent().getValue() != null && param.getValue().getParent().getValue().getClass() == RecursiveTreeObject.class )); }
/** * only allows editing for items that are not grouped * * @return whether the item is grouped or not */ private boolean checkGroupedColumn() { boolean allowEdit = true; if (getTreeTableRow().getTreeItem() != null) { Object rowObject = getTreeTableRow().getTreeItem().getValue(); if (rowObject instanceof RecursiveTreeObject && rowObject.getClass() == RecursiveTreeObject.class) { allowEdit = false; } else { // check grouped columns in the tableview if (getTableColumn() instanceof JFXTreeTableColumn && ((JFXTreeTableColumn) getTableColumn()).isGrouped()) { // make sure that the object is a direct child to a group node if (getTreeTableRow().getTreeItem().getParent() != null && getTreeTableRow().getTreeItem().getParent().getValue().getClass() == RecursiveTreeObject.class) { allowEdit = false; } } } } return allowEdit; }
List<Node> newPath = new ArrayList<>(); while (temp != null) { TreeItem parent = treeView.isShowRoot() ? temp : temp.getParent(); if (parent != null) { Button button = null; if (temp.isLeaf()) { button = createLastButton(temp, parent.getParent()); button.pseudoClassStateChanged(lastClass, true); } else if (parent.getParent() == null) { button = createFirstButton(temp); button.pseudoClassStateChanged(firstClass, true); container.setPickOnBounds(false); if (parent.getParent() != null) { container.setTranslateX((-getOffset()-1) * level--); temp = temp.getParent();
/** * Construct a flat list for the crumbs * @param bottomMost The crumb node at the end of the path * @return */ private List<TreeItem<T>> constructFlatPath(TreeItem<T> bottomMost){ List<TreeItem<T>> path = new ArrayList<>(); TreeItem<T> current = bottomMost; do { path.add(current); current = current.getParent(); } while (current != null); Collections.reverse(path); return path; }
@Override public void changed(final ObservableValue<? extends TreeItem<String>> observable, final TreeItem<String> oldVal, final TreeItem<String> newVal) { final TreeItem<String> selectedItem = (TreeItem<String>) newVal; TreeItem<String> parent = selectedItem.getParent(); String path = File.separator + selectedItem.getValue(); while (parent != null) { if (parent.getParent() != null) { path = File.separator + parent.getValue() + path; } parent = parent.getParent(); } selectedFile = pathFolder + path; }
MenuItem item3 = new MenuItem("Remove"); item3.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { TreeItem c = (TreeItem)treeView.getSelectionModel().getSelectedItem(); boolean remove = c.getParent().getChildren().remove(c); System.out.println("Remove"); } });
treeViewer.getTree().addListener( SWT.DefaultSelection, new Listener() { @Override public void handleEvent( Event event ) { TreeItem treeItem = ( TreeItem )event.item; Point cursorLocation = event.display.getCursorLocation(); Point localCursorLocation = treeItem.getParent().toControl( cursorLocation ); if( treeItem.getBounds().contains( localCursorLocation ) ) { // put your JFace expand/collapse code here } } } );
private boolean isChildOf(TreeItem<N> targetTreeItem) { return targetTreeItem == dragAndDropMove.getSourceTreeItem().getParent(); }
public void updateItem( Object item, boolean empty ) { super( item, empty ); TreeItem thisTreeItem = getTreeItem(); if ( thisTreeItem.getParent() == rootItem ) thisTreeItem.setContextmenu( providerContextMenu ) else thisTreeItem.setContextmenu( boxContextMenu ) . . }
private void remove() { ObservableList<TreeItem<Object>> selectedItems = contingencyTree.getSelectionModel().getSelectedItems(); List<TreeItem<Object>> items = new ArrayList<>(selectedItems); for (TreeItem<Object> item : items) { if (item.getValue() instanceof Contingency) { item.getParent().getChildren().remove(item); } else { Contingency contingency = (Contingency) item.getParent().getValue(); if (contingency.getElements().size() == 1) { // remove the contingency to avoid empty contingencies item.getParent().getParent().getChildren().remove(item.getParent()); } else { ContingencyElement element = (ContingencyElement) item.getValue(); contingency.removeElement(element); item.getParent().getChildren().remove(item); } } } saved.set(false); }
/** * validates the value of the tree item, * this method also hides the column value for the grouped nodes * * @param param tree item * @return true if the value is valid else false */ public final boolean validateValue(CellDataFeatures<S, T> param) { Object rowObject = param.getValue().getValue(); return !((rowObject instanceof RecursiveTreeObject && rowObject.getClass() == RecursiveTreeObject.class) || (param.getTreeTableView() instanceof JFXTreeTableView && ((JFXTreeTableView<?>) param.getTreeTableView()).getGroupOrder().contains(this) // make sure the node is a direct child to a group node && param.getValue().getParent() != null && param.getValue().getParent().getValue() != null && param.getValue().getParent().getValue().getClass() == RecursiveTreeObject.class )); }
private void initTreeView() { final TreeItem<String> root = new TreeItem<String>("Empty User"); root.setGraphic(ViewUtilities.iconSetter(Material.PERSON, IconDim.SMALL)); this.treeView.setRoot(root); this.treeView.getSelectionModel().selectedItemProperty().addListener((v, oldValue, newValue) -> { if (newValue != null && this.treeView.getTreeItemLevel(newValue) == 2) { this.drawSavedGestureOnCanvas(newValue.getParent(), newValue.getParent().getChildren().indexOf(newValue)); } }); }
private void setOnOkButton(List<? extends TreeItem<N>> selectedTreeItems) { List<TreeItem<N>> parentTreeItems = new ArrayList<>(); for (TreeItem<N> selectedTreeItem : selectedTreeItems) { if (selectedTreeItem.getValue() instanceof Node) { Node nodeSelected = (Node) selectedTreeItem.getValue(); nodeSelected.delete(); } parentTreeItems.add(selectedTreeItem.getParent()); } for (TreeItem<N> parentTreeItem : parentTreeItems) { refreshTreeItem(parentTreeItem); tree.getSelectionModel().clearSelection(); tree.getSelectionModel().select(parentTreeItem); selectedNode.setValue((T) parentTreeItem.getValue()); } }
/** * only allows editing for items that are not grouped * * @return whether the item is grouped or not */ private boolean checkGroupedColumn() { boolean allowEdit = true; if (getTreeTableRow().getTreeItem() != null) { Object rowObject = getTreeTableRow().getTreeItem().getValue(); if (rowObject instanceof RecursiveTreeObject && rowObject.getClass() == RecursiveTreeObject.class) { allowEdit = false; } else { // check grouped columns in the tableview if (getTableColumn() instanceof JFXTreeTableColumn && ((JFXTreeTableColumn) getTableColumn()).isGrouped()) { // make sure that the object is a direct child to a group node if (getTreeTableRow().getTreeItem().getParent() != null && getTreeTableRow().getTreeItem().getParent().getValue().getClass() == RecursiveTreeObject.class) { allowEdit = false; } } } } return allowEdit; }
private void renameNode(TreeItem selectedTreeItem) { Optional<String> result = RenamePane.showAndWaitDialog((Node) selectedTreeItem.getValue()); result.ifPresent(newName -> { if (selectedTreeItem.getValue() instanceof Node) { Node selectedTreeNode = (Node) selectedTreeItem.getValue(); selectedTreeNode.rename(newName); refresh(selectedTreeItem.getParent()); tree.getSelectionModel().clearSelection(); tree.getSelectionModel().select(selectedTreeItem); } }); }
@Override public void changed( ObservableValue<? extends TreeItem<DisplayableNode>> observable, TreeItem<DisplayableNode> oldValue, TreeItem<DisplayableNode> newValue) { TreeItem<DisplayableNode> currentItem = newValue; while (currentItem != null) { if (currentItem.getValue() instanceof StackFrame) { StackFrame sf = (StackFrame) currentItem.getValue(); byte[] sourceBytes = sf.getSourceCode(); String sourceCode = new String(sourceBytes, Charsets.UTF_8); int line = sf.getLine() != null ? sf.getLine() : 0; sourceView.getEngine().loadContent(codeMirrorFormatter.format(sourceCode, CodeFormatLanguage.JAVA, false, line)); return; } currentItem = currentItem.getParent(); } }
private TreeItem<Object> getContingencyItem() { TreeItem<Object> contingencyItem = null; if (getTreeItem() != null) { if (getTreeItem().getValue() instanceof Contingency) { contingencyItem = getTreeItem(); } else if (getTreeItem().getValue() instanceof ContingencyElement) { contingencyItem = getTreeItem().getParent(); } } return contingencyItem; } }
private void dragDroppedEvent(Object value, TreeItem<N> treeItem, DragEvent event, Node node) { if (value instanceof Folder && value != dragAndDropMove.getSource()) { Folder folder = (Folder) node; int count = 0; success = false; treeItemChildrenSize(treeItem, count); accepTransferDrag(folder, success); event.setDropCompleted(success); refreshTreeItem(dragAndDropMove.getSourceTreeItem().getParent()); refreshTreeItem(treeItem); tree.getSelectionModel().clearSelection(); event.consume(); } }