Java Code Examples for javafx.scene.control.TreeItem#getParent()
The following examples show how to use
javafx.scene.control.TreeItem#getParent() .
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: ScenegraphTreeView.java From scenic-view with GNU General Public License v3.0 | 6 votes |
private void removeForNode(final TreeItem<SVNode> treeItem) { if (treeItem != null) { final List<TreeItem<SVNode>> treeItemChildren = treeItem.getChildren(); if (treeItemChildren != null) { /** * Do not use directly the list as it will suffer concurrent * modifications */ @SuppressWarnings("unchecked") final TreeItem<SVNode> children[] = treeItemChildren.toArray(new TreeItem[treeItemChildren.size()]); for (int i = 0; i < children.length; i++) { removeForNode(children[i]); } } // This does not seem to delete the TreeItem from the tree -- only // moves // it up a level visually /** * I don't know why this protection is needed */ if (treeItem.getParent() != null) { treeItem.getParent().getChildren().remove(treeItem); } treeViewData.remove(treeItem.getValue()); } }
Example 2
Source File: JFXTreeTableView.java From JFoenix with Apache License 2.0 | 6 votes |
@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; }
Example 3
Source File: FileBrowseService.java From AsciidocFX with Apache License 2.0 | 6 votes |
public int findIndex(TreeItem<Item> changedItem) { TreeItem<Item> item = changedItem; int result = 0; while (true) { TreeItem<Item> parent = item.getParent(); if (Objects.isNull(parent)) { break; } int index = parent.getChildren().indexOf(item); result += index; item = parent; } return result; }
Example 4
Source File: ScanCommandTree.java From phoebus with Eclipse Public License 1.0 | 6 votes |
private void reveal(final TreeItem<ScanCommand> item) { // Expand tree up to parent because 'getRow' will // only find items that are expanded TreeItem<ScanCommand> parent = item.getParent(); while (parent != null) { if (! parent.isExpanded()) parent.setExpanded(true); parent = parent.getParent(); } // Scroll to the active command final int row = getRow(active_item); if (row >= 0) { // Try to show one command above the desired one to get some context if (row > 1) scrollTo(row-1); else scrollTo(row); } }
Example 5
Source File: JavaFXElementPropertyAccessor.java From marathonv5 with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private String getTreeTableItemText(TreeTableView<?> treeTableView, TreeItem<?> lastPathComponent) { @SuppressWarnings("rawtypes") TreeTableColumn treeTableColumn = treeTableView.getTreeColumn(); if (treeTableColumn == null) { treeTableColumn = treeTableView.getColumns().get(0); } ObservableValue<?> cellObservableValue = treeTableColumn.getCellObservableValue(lastPathComponent); String original = cellObservableValue.getValue().toString(); String itemText = original; int suffixIndex = 0; TreeItem<?> parent = lastPathComponent.getParent(); if (parent == null) return itemText; ObservableList<?> children = parent.getChildren(); for (int i = 0; i < children.indexOf(lastPathComponent); i++) { TreeItem<?> child = (TreeItem<?>) children.get(i); cellObservableValue = treeTableColumn.getCellObservableValue(child); String current = cellObservableValue.getValue().toString(); if (current.equals(original)) { itemText = String.format("%s(%d)", original, ++suffixIndex); } } return itemText; }
Example 6
Source File: JavaFXElementPropertyAccessor.java From marathonv5 with Apache License 2.0 | 6 votes |
private String getTreeItemText(TreeItem<?> lastPathComponent) { if (lastPathComponent == null || lastPathComponent.getValue() == null) { return ""; } String original = lastPathComponent.getValue().toString(); String itemText = original; int suffixIndex = 0; TreeItem<?> parent = lastPathComponent.getParent(); if (parent == null) return itemText; ObservableList<?> children = parent.getChildren(); for (int i = 0; i < children.indexOf(lastPathComponent); i++) { TreeItem<?> child = (TreeItem<?>) children.get(i); String current = child.getValue().toString(); if (current.equals(original)) { itemText = String.format("%s(%d)", original, ++suffixIndex); } } return itemText; }
Example 7
Source File: ModFuncContextMenu.java From erlyberly with GNU General Public License v3.0 | 6 votes |
private void onExportedFunctionTrace(ActionEvent e) { TreeItem<ModFunc> selectedItem = selectedTreeItemProperty().get(); if(selectedItem == null) return; if(selectedItem.getValue() == null) return; if(!selectedItem.getValue().isModule()) selectedItem = selectedItem.getParent(); // get all the functions we may trace HashSet<ModFunc> funcs = new HashSet<ModFunc>(); recurseModFuncItems(selectedItem, funcs); // filter the exported ones HashSet<ModFunc> exported = new HashSet<ModFunc>(); for (ModFunc modFunc : funcs) { if(modFunc.isExported()) { exported.add(modFunc); } } // trace 'em toggleTraceMod(exported); }
Example 8
Source File: DependencyResolveDialog.java From SmartModInserter with GNU Lesser General Public License v3.0 | 5 votes |
private boolean updateResult() { TreeItem item = solutions.getSelectionModel().getModelItem(solutions.getSelectionModel().getSelectedIndex()); if (!(item instanceof ModSetTreeItem)) { item = item.getParent(); } if (item instanceof ModSetTreeItem) { setResult(((ModSetTreeItem) item).getSolution()); return true; } return false; }
Example 9
Source File: MainWindowController.java From old-mzmine3 with GNU General Public License v2.0 | 5 votes |
public void removeRawData(ActionEvent event) { // Get selected tree items ObservableList<TreeItem<Object>> rows = null; if (rawDataTree.getSelectionModel() != null) { rows = rawDataTree.getSelectionModel().getSelectedItems(); } // Loop through all selected tree items if (rows != null) { for (int i = rows.size() - 1; i >= 0; i--) { TreeItem<Object> row = rows.get(i); if (!(row.getValue() instanceof RawDataFile)) continue; // Remove feature table from current project RawDataFile rawDataFile = (RawDataFile) row.getValue(); MZmineCore.getCurrentProject().removeFile(rawDataFile); // Remove raw data file from tree table view TreeItem<?> parent = row.getParent(); if (parent == null) continue; parent.getChildren().remove(row); } rawDataTree.getSelectionModel().clearSelection(); } }
Example 10
Source File: ModFuncContextMenu.java From erlyberly with GNU General Public License v3.0 | 5 votes |
private void onModuleTrace(ActionEvent e) { TreeItem<ModFunc> selectedItem = selectedTreeItemProperty().get(); if(selectedItem == null) return; if(selectedItem.getValue() == null) return; if(!selectedItem.getValue().isModule()) selectedItem = selectedItem.getParent(); HashSet<ModFunc> funcs = new HashSet<ModFunc>(); recurseModFuncItems(selectedItem, funcs); toggleTraceMod(funcs); }
Example 11
Source File: MainWindowController.java From old-mzmine3 with GNU General Public License v2.0 | 5 votes |
public void removeFeatureTable(ActionEvent event) { // Get selected tree items ObservableList<TreeItem<Object>> rows = null; if (featureTree.getSelectionModel() != null) { rows = featureTree.getSelectionModel().getSelectedItems(); } // Loop through all selected tree items if (rows != null) { for (int i = rows.size() - 1; i >= 0; i--) { TreeItem<Object> row = rows.get(i); if (!(row.getValue() instanceof FeatureTable)) continue; // Remove feature table from current project FeatureTable featureTable = (FeatureTable) row.getValue(); MZmineCore.getCurrentProject().removeFeatureTable(featureTable); // Remove feature table from tree table view TreeItem<?> parent = row.getParent(); if (parent == null) continue; parent.getChildren().remove(row); } featureTree.getSelectionModel().clearSelection(); } }
Example 12
Source File: CoursesTreeView.java From iliasDownloaderTool with GNU General Public License v2.0 | 5 votes |
public void fileStatusChanged(IliasFile iliasFile) { TreeItem<IliasTreeNode> treeItem = getItem(iliasFile); setGraphic(treeItem, iliasFile.getGraphic()); while (treeItem.getParent() != null) { treeItem = treeItem.getParent(); IliasFolder folder = (IliasFolder) treeItem.getValue(); setGraphic(treeItem, folder.getGraphic()); } }
Example 13
Source File: MaterialEditorController.java From OEE-Designer with MIT License | 5 votes |
@FXML private void onDeleteMaterial() throws Exception { if (selectedMaterialItem == null || !selectedMaterialItem.getValue().isMaterial()) { AppUtils.showErrorDialog(DesignerLocalizer.instance().getErrorString("material.deletion")); return; } // confirm ButtonType type = AppUtils.showConfirmationDialog( DesignerLocalizer.instance().getLangString("delete.material", getSelectedMaterial().getName())); if (type.equals(ButtonType.CANCEL)) { return; } try { // delete Material toDelete = getSelectedMaterial(); PersistenceService.instance().delete(toDelete); // remove this material from the tree TreeItem<MaterialNode> childNode = tvMaterials.getSelectionModel().getSelectedItem(); TreeItem<MaterialNode> parentNode = childNode.getParent(); parentNode.getChildren().remove(childNode); tvMaterials.refresh(); parentNode.setExpanded(true); // update category list populateCategories(); // clear editor onNewMaterial(); } catch (Exception e) { AppUtils.showErrorDialog(e); } }
Example 14
Source File: MaterialEditorController.java From OEE-Designer with MIT License | 5 votes |
private void updateCategory(TreeItem<MaterialNode> materialItem) throws Exception { Material material = materialItem.getValue().getMaterial(); String parentCategory = materialItem.getParent().getValue().getCategory(); if (!material.getCategory().equals(parentCategory)) { // remove from category TreeItem<MaterialNode> categoryNode = materialItem.getParent(); categoryNode.getChildren().remove(materialItem); if (categoryNode.getChildren().size() == 0) { // remove category too categoryNode.getParent().getChildren().remove(categoryNode); } // add to new category TreeItem<MaterialNode> newItem = new TreeItem<>(new MaterialNode(material)); resetGraphic(newItem); ObservableList<TreeItem<MaterialNode>> categoryItems = tvMaterials.getRoot().getChildren(); TreeItem<MaterialNode> parentItem = null; for (TreeItem<MaterialNode> categoryItem : categoryItems) { if (categoryItem.getValue().getCategory().equals(material.getCategory())) { // existing category parentItem = categoryItem; break; } } if (parentItem == null) { // new category parentItem = new TreeItem<>(new MaterialNode(material.getCategory())); parentItem.setGraphic(ImageManager.instance().getImageView(Images.CATEGORY)); tvMaterials.getRoot().getChildren().add(parentItem); } parentItem.getChildren().add(newItem); } }
Example 15
Source File: UomEditorController.java From OEE-Designer with MIT License | 5 votes |
@FXML private void onDeleteUom() { if (selectedUomItem == null || !selectedUomItem.getValue().isUnitOfMeasure()) { AppUtils.showErrorDialog(DesignerLocalizer.instance().getErrorString("unit.cannot.be.null")); return; } // confirm ButtonType type = AppUtils.showConfirmationDialog( DesignerLocalizer.instance().getLangString("uom.delete", getSelectedUom().getDisplayString())); if (type.equals(ButtonType.CANCEL)) { return; } try { // delete UnitOfMeasure toDelete = getSelectedUom(); PersistenceService.instance().delete(toDelete); // remove this UOM from the tree TreeItem<UomNode> childNode = tvUoms.getSelectionModel().getSelectedItem(); TreeItem<UomNode> parentNode = childNode.getParent(); parentNode.getChildren().remove(childNode); tvUoms.refresh(); parentNode.setExpanded(true); // update category list populateCategories(); // clear editor onNewUom(); } catch (Exception e) { AppUtils.showErrorDialog(e); } }
Example 16
Source File: ReasonEditorController.java From OEE-Designer with MIT License | 5 votes |
private void addEditedReason(TreeItem<ReasonNode> item) { if (!editedReasonItems.contains(item)) { // check for parent if (item.getParent() != null && editedReasonItems.contains(item.getParent())) { return; } editedReasonItems.add(item); } }
Example 17
Source File: PhysicalModelController.java From OEE-Designer with MIT License | 4 votes |
@FXML private void onDeleteEntity() { PlantEntity selectedEntity = getSelectedEntity(); if (selectedEntity == null) { AppUtils.showErrorDialog(DesignerLocalizer.instance().getErrorString("no.entity")); return; } // confirm ButtonType type = AppUtils.showConfirmationDialog( DesignerLocalizer.instance().getLangString("confirm.delete", selectedEntity.getName())); if (type.equals(ButtonType.CANCEL)) { return; } try { // delete from db if previously saved PlantEntity parentEntity = selectedEntity.getParent(); if (parentEntity != null) { // remove from parent with orphan removal parentEntity.removeChild(selectedEntity); PersistenceService.instance().save(parentEntity); } else { // cascade delete PersistenceService.instance().delete(selectedEntity); } // remove this entity from the tree TreeItem<EntityNode> selectedEntityItem = tvEntities.getSelectionModel().getSelectedItem(); TreeItem<EntityNode> parentNode = selectedEntityItem.getParent(); parentNode.getChildren().remove(selectedEntityItem); tvEntities.getSelectionModel().clearSelection(); tvEntities.refresh(); parentNode.setExpanded(true); onNewEntity(); } catch (Exception e) { AppUtils.showErrorDialog(e); } }
Example 18
Source File: DirectoryItem.java From Recaf with MIT License | 4 votes |
/** * Expand all parents to this item. */ public void expandParents() { TreeItem<?> item = this; while ((item = item.getParent()) != null) item.setExpanded(true); }
Example 19
Source File: ReasonEditorController.java From OEE-Designer with MIT License | 4 votes |
@FXML private void onDeleteReason() { Reason selectedReason = getSelectedReason(); if (selectedReason == null) { AppUtils.showErrorDialog(DesignerLocalizer.instance().getErrorString("no.reason.selected")); return; } // confirm ButtonType type = AppUtils.showConfirmationDialog( DesignerLocalizer.instance().getLangString("delete.reason", selectedReason.getName())); if (type.equals(ButtonType.CANCEL)) { return; } try { Reason parentReason = selectedReason.getParent(); if (parentReason != null) { // remove from parent with orphan removal parentReason.removeChild(selectedReason); PersistenceService.instance().save(parentReason); } else { // cascade delete PersistenceService.instance().delete(selectedReason); } // remove this reason from the tree TreeItem<ReasonNode> selectedReasonItem = tvReasons.getSelectionModel().getSelectedItem(); TreeItem<ReasonNode> parentNode = selectedReasonItem.getParent(); parentNode.getChildren().remove(selectedReasonItem); // clear fields onNewReason(); tvReasons.getSelectionModel().clearSelection(); tvReasons.refresh(); parentNode.setExpanded(true); } catch (Exception e) { AppUtils.showErrorDialog(e); } }
Example 20
Source File: ScenegraphTreeView.java From scenic-view with GNU General Public License v3.0 | 4 votes |
void doRemoveNode(final SVNode node) { try { if (ConnectorUtils.isNormalNode(node)) { TreeItem<SVNode> selected = null; if (scenicView.getSelectedNode() == node) { getSelectionModel().clearSelection(); setSelectedNode(null); } else { // Ugly workaround selected = getSelectionModel().getSelectedItem(); } final TreeItem<SVNode> treeItem = getTreeItem(node); /** * TODO Analyze this problem: * * In some situations a parent node could be removed by * visibility and after that a children could also change its * visibility to false triggering a removal that actually does * not exist. In those situations we should keep visibility * listener on the parent and remove it to its childrens. Anyway * this need to be tested deeply and this protection is not so * dangerous */ if (treeItem == null) { Logger.print("Removing unfound treeItem:" + node.getExtendedId()); return; } final List<TreeItem<SVNode>> treeItemChildren = treeItem.getChildren(); if (treeItemChildren != null) { /** * Do not use directly the list as it will suffer concurrent * modifications */ @SuppressWarnings("unchecked") final TreeItem<SVNode> children[] = treeItemChildren.toArray(new TreeItem[treeItemChildren.size()]); for (int i = 0; i < children.length; i++) { doRemoveNode(children[i].getValue()); } } // This does not seem to delete the TreeItem from the tree -- // only // moves // it up a level visually /** * I don't know why this protection is needed */ if (treeItem.getParent() != null) { treeItem.getParent().getChildren().remove(treeItem); } treeViewData.remove(treeItem.getValue()); if (selected != null) { // Ugly workaround getSelectionModel().select(selected); } } } catch (final NullPointerException e2) { throw new RuntimeException("Error while removing node:" + node.getExtendedId(), e2); } }