List of usage examples for javafx.scene.control TreeItem TreeItem
public TreeItem(final T value)
From source file:ubicrypt.ui.files.FilesController.java
private synchronized TreeItem<ITreeItem> addFiles(final Iterator<Path> it, final Path rootPath, final TreeItem<ITreeItem> root, final LocalFile file) { if (!it.hasNext()) { return root; }/* w ww . ja v a 2 s.co m*/ final Path path = it.next(); final Path resolvedPath = rootPath.resolve(path); if (Files.isRegularFile(resolvedPath)) { final FileItem item = new FileItem(file); final TreeItem<ITreeItem> fileItem = new TreeItem<>(item); root.getChildren().add(fileItem); root.getChildren().sort((iTreeItemTreeItem, t1) -> iTreeItemTreeItem.getValue().getLabel() .compareTo(t1.getValue().getLabel())); return fileItem; } final Optional<TreeItem<ITreeItem>> optTreeItem = root.getChildren().stream() .filter(ti -> ((FolderItem) ti.getValue()).getPath().equals(path)).findFirst(); if (optTreeItem.isPresent()) { return addFiles(it, resolvedPath, optTreeItem.get(), file); } final TreeItem<ITreeItem> fileItem = new TreeFolderItem(new FolderItem(path, event -> fileAdder.accept(resolvedPath), event -> folderAdder.accept(resolvedPath))); root.getChildren().add(fileItem); root.getChildren().sort((iTreeItemTreeItem, t1) -> iTreeItemTreeItem.getValue().getLabel() .compareTo(t1.getValue().getLabel())); return addFiles(it, resolvedPath, fileItem, file); }
From source file:Testing.TestMain.java
public static List<File> hyperAVAJAVAFileMp3Scan(File root, TreeItem<File> parent) { try {//from ww w.ja v a2 s.c om TreeItem<File> treeRoot = new TreeItem<>(root); String[] extensions = new String[] { "mp3" }; root.getCanonicalPath(); List<File> returnedFiles = new LinkedList<File>(); List<File> files = (List<File>) FileUtils.listFiles(root, extensions, true); for (File file : files) { if (!file.toString().contains("$RECYCLE.BIN")) { System.out.println(file.toString()); returnedFiles.add(file.getCanonicalFile()); } } return returnedFiles; } catch (IOException ex) { Logger.getLogger(TestMain.class.getName()).log(Level.SEVERE, null, ex); return null; } }
From source file:Testing.TestMain.java
public static void treeSample(Stage stage, Collection root) { TreeItem<String> rootItem = new TreeItem<String>("D:\\"); rootItem.setExpanded(true);//from w w w .j a v a 2s . co m for (Iterator it = root.iterator(); it.hasNext();) { Object i = it.next(); TreeItem<String> item = new TreeItem<String>(i.toString()); rootItem.getChildren().add(item); } /* for (int i = 1; i < 6; i++) { TreeItem<String> item = new TreeItem<String>("Message" + i); rootItem.getChildren().add(item); }*/ TreeView<String> tree = new TreeView<String>(rootItem); StackPane rootpane = new StackPane(); rootpane.getChildren().add(tree); stage.setScene(new Scene(rootpane, 300, 250)); stage.show(); }
From source file:acmi.l2.clientmod.xdat.Controller.java
private static void buildTree(IOEntity entity, Field listField, TreeView<Object> elements, String nameFilter) { elements.setRoot(null);//from w w w . j a v a 2 s .co m if (entity == null) return; try { List<IOEntity> list = (List<IOEntity>) listField.get(entity); if (!listField.isAnnotationPresent(Type.class)) { log.log(Level.WARNING, String.format("XDAT.%s: @Type not defined", listField.getName())); Dialogs.show(Alert.AlertType.ERROR, "ReflectiveOperationException", null, String.format("XDAT.%s: @Type not defined", listField.getName())); } else { Class<? extends IOEntity> type = listField.getAnnotation(Type.class).value() .asSubclass(IOEntity.class); TreeItem<Object> rootItem = new TreeItem<>(new ListHolder(entity, list, listField.getName(), type)); elements.setRoot(rootItem); rootItem.getChildren().addAll(list.stream().map(Controller::createTreeItem) .filter(treeItem -> checkTreeNode(treeItem, nameFilter)).collect(Collectors.toList())); } } catch (IllegalAccessException e) { log.log(Level.WARNING, String.format("%s.%s is not accessible", listField.getDeclaringClass().getSimpleName(), listField.getName()), e); Dialogs.show(Alert.AlertType.ERROR, "ReflectiveOperationException", null, listField.getDeclaringClass().getSimpleName() + "." + listField.getName() + " is not accessible"); } }
From source file:eu.fthevenet.binjr.sources.jrds.adapters.JrdsDataAdapter.java
private void attachNode(TreeItem<TimeSeriesBinding<Double>> tree, String id, Map<String, JsonJrdsItem> nodes) throws DataAdapterException { JsonJrdsItem n = nodes.get(id);/*from ww w .j a v a 2 s. co m*/ String currentPath = normalizeId(n.id); TreeItem<TimeSeriesBinding<Double>> newBranch = new TreeItem<>( bindingFactory.of(tree.getValue().getTreeHierarchy(), n.name, currentPath, this)); if (JRDS_FILTER.equals(n.type)) { // add a dummy node so that the branch can be expanded newBranch.getChildren().add(new TreeItem<>(null)); // add a listener that will get the treeview filtered according to the selected filter/tag newBranch.expandedProperty().addListener(new FilteredViewListener(n, newBranch)); } else { if (n.children != null) { for (JsonJrdsItem.JsonTreeRef ref : n.children) { attachNode(newBranch, ref._reference, nodes); } } else { // add a dummy node so that the branch can be expanded newBranch.getChildren().add(new TreeItem<>(null)); // add a listener so that bindings for individual datastore are added lazily to avoid // dozens of individual call to "graphdesc" when the tree is built. newBranch.expandedProperty().addListener(new GraphDescListener(currentPath, newBranch, tree)); } } tree.getChildren().add(newBranch); }
From source file:com.heliosdecompiler.helios.gui.controller.FileTreeController.java
public void updateTree(List<TreeNode> add, List<TreeNode> remove) { Set<TreeItem<TreeNode>> updated = new HashSet<>(); ArrayDeque<TreeNode> queue = new ArrayDeque<>(); queue.addAll(add);/* w w w . j av a2 s. c o m*/ while (!queue.isEmpty()) { TreeNode thisNode = queue.pop(); TreeItem<TreeNode> parent; if (thisNode.getParent() == null) { parent = rootItem; } else { parent = itemMap.get(thisNode.getParent()); } updated.add(parent); TreeItem<TreeNode> thisItem = new TreeItem<>(thisNode); thisItem.addEventHandler(TreeItem.<TreeNode>branchExpandedEvent(), event -> { if (thisItem.getChildren().size() == 1) { thisItem.getChildren().get(0).setExpanded(true); } }); thisItem.setGraphic(new ImageView(new Image(getIconForTreeItem(thisNode)))); FutureTask<Void> call = new FutureTask<>(() -> { parent.getChildren().add(thisItem); return null; }); Platform.runLater(call); try { call.get(); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } itemMap.put(thisNode, thisItem); queue.addAll(thisNode.getChildren()); } for (TreeItem<TreeNode> parent : updated) { if (parent.getChildren().size() > 1) { FutureTask<Void> call = new FutureTask<>(() -> { parent.getChildren().sort((a, b) -> { int ac = a.getValue().getChildren().size(); int bc = b.getValue().getChildren().size(); if (ac == 0 && bc != 0) return 1; else if (ac != 0 && bc == 0) return -1; return a.getValue().getDisplayName().compareTo(b.getValue().getDisplayName()); }); return null; }); Platform.runLater(call); try { call.get(); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } } } queue.addAll(remove); while (!queue.isEmpty()) { TreeNode thisNode = queue.pop(); TreeItem<TreeNode> thisItem = itemMap.remove(thisNode); thisItem.getParent().getChildren().remove(thisItem); queue.addAll(thisNode.getChildren()); } }
From source file:Testing.TestMain.java
private void fileFinder(File dir, TreeItem<File> parent) throws IOException { String[] extensions = new String[] { "mp3" }; TreeItem<File> root = new TreeItem<>(dir); root.setExpanded(true);//from w w w.j a va2 s. c om dir.getCanonicalPath(); List<File> files = (List<File>) FileUtils.listFiles(dir, extensions, true); //Collection collector = hyperStackOverflowFileMp3Scan(dir); //File[] files = null; //collector.toArray(files); for (File file : files) { if (!file.toString().contains("$RECYCLE.BIN")) { if (file.isDirectory()) { System.out.println("directory:" + file.getCanonicalPath()); fileFinder(file, root); } else { System.out.println(" file:" + file.getCanonicalPath()); root.getChildren().add(new TreeItem<>(file)); } } } if (parent == null) { //treeViewFile.setRoot(root); } else { parent.getChildren().add(root); } }
From source file:spdxedit.PackageEditor.java
/** * Opens the modal package editor for the provided package. * * @param pkg The package to edit. * @param relatablePackages Packages to which the edited package may optionally have defined relationships * @param parentWindow The parent window. *///from ww w . j a va 2s .c om public static void editPackage(final SpdxPackage pkg, final List<SpdxPackage> relatablePackages, SpdxDocumentContainer documentContainer, Window parentWindow) { final PackageEditor packageEditor = new PackageEditor(pkg, relatablePackages, documentContainer); final Stage dialogStage = new Stage(); dialogStage.setTitle("Edit SPDX Package: " + pkg.getName()); dialogStage.initStyle(StageStyle.DECORATED); dialogStage.initModality(Modality.APPLICATION_MODAL); dialogStage.setY(parentWindow.getX() + parentWindow.getWidth() / 2); dialogStage.setY(parentWindow.getY() + parentWindow.getHeight() / 2); dialogStage.setResizable(false); try { FXMLLoader loader = new FXMLLoader(NewPackageDialog.class.getResource("/PackageEditor.fxml")); loader.setController(packageEditor); Pane pane = loader.load(); Scene scene = new Scene(pane); dialogStage.setScene(scene); dialogStage.getIcons().clear(); dialogStage.getIcons().add(UiUtils.ICON_IMAGE_VIEW.getImage()); //Populate the file list on appearance dialogStage.setOnShown(event -> { try { final SpdxFile dummyfile = new SpdxFile(pkg.getName(), null, null, null, null, null, null, null, null, null, null, null, null); TreeItem<SpdxFile> root = new TreeItem<>(dummyfile); packageEditor.filesTable.setRoot(root); //Assume a package without is external //TODO: replace with external packages or whatever alternate mechanism in 2.1 packageEditor.btnAddFile.setDisable(pkg.getFiles().length == 0); root.getChildren() .setAll(Stream.of(pkg.getFiles()) .sorted(Comparator.comparing(file -> StringUtils.lowerCase(file.getName()))) //Sort by file name .map(TreeItem<SpdxFile>::new).collect(Collectors.toList())); } catch (InvalidSPDXAnalysisException e) { logger.error("Unable to get files for package " + pkg.getName(), e); } packageEditor.tabFiles.setExpanded(true); }); //Won't assign this event through FXML - don't want to propagate the stage beyond this point. packageEditor.btnOk.setOnMouseClicked(event -> dialogStage.close()); dialogStage.showAndWait(); } catch (IOException ioe) { throw new RuntimeException("Unable to load dialog", ioe); } }
From source file:jduagui.Controller.java
private TreeItem<File> createNode(final File f) { return new TreeItem<File>(f) { private boolean isLeaf; private boolean isFirstTimeChildren = true; private boolean isFirstTimeLeaf = true; @Override//from w w w . j a v a2 s. c o m public ObservableList<TreeItem<File>> getChildren() { if (isFirstTimeChildren) { isFirstTimeChildren = false; super.getChildren().setAll(buildChildren(this)); } return super.getChildren(); } @Override public boolean isLeaf() { if (isFirstTimeLeaf) { isFirstTimeLeaf = false; File f = (File) getValue(); isLeaf = f.isFile(); } return isLeaf; } private ObservableList<TreeItem<File>> buildChildren(TreeItem<File> TreeItem) { File f = TreeItem.getValue(); if (f != null && f.isDirectory() && (!f.getAbsolutePath().equals("/proc/"))) { File[] files = f.listFiles(); if (files != null) { ObservableList<TreeItem<File>> children = FXCollections.observableArrayList(); for (File childFile : files) { children.add(createNode(childFile)); } return children; } } return FXCollections.emptyObservableList(); } }; }
From source file:ubicrypt.ui.ctrl.HomeController.java
private synchronized TreeItem<ITreeItem> addFiles(final Iterator<Path> it, final Path rootPath, final TreeItem<ITreeItem> root, final LocalFile file) { if (!it.hasNext()) { return root; }/*w w w. jav a2s . c o m*/ final Path path = it.next(); final Path resolvedPath = rootPath.resolve(path); if (Files.isRegularFile(resolvedPath)) { final FileItem item = applicationContext.getBean(FileItem.class, file); final TreeItem<ITreeItem> fileItem = new TreeItem<>(item); root.getChildren().add(fileItem); return fileItem; } final Optional<TreeItem<ITreeItem>> optTreeItem = root.getChildren().stream() .filter(ti -> ((FolderItem) ti.getValue()).getPath().equals(path)).findFirst(); if (optTreeItem.isPresent()) { return addFiles(it, resolvedPath, optTreeItem.get(), file); } final TreeItem<ITreeItem> fileItem = new TreeFolderItem( new FolderItem(path, event -> fileAdder.accept(resolvedPath))); root.getChildren().add(fileItem); return addFiles(it, resolvedPath, fileItem, file); }