List of usage examples for javafx.scene.control TreeItem getChildren
public ObservableList<TreeItem<T>> getChildren()
From source file:musicmetadatak1009705.FolderTreeView.java
public TreeView<File> proxyCreateNode(ArrayList<TreeItem> arrayListTreeItem) { TreeItem<File> proxyItem = new TreeItem<>(); proxyItem.setExpanded(true);/* w ww.ja va 2 s .co m*/ for (TreeItem<File> item : arrayListTreeItem) { proxyItem.getChildren().addAll(item); } TreeView<File> tree = new TreeView<>(proxyItem); tree.setShowRoot(false); return tree; }
From source file:sonicScream.models.Script.java
/** * Returns the Script's tree with everything removed but each entry's title * and its wave file list, and flattens the hierarchy. * Initializes the rootNode if it has not yet been initialized. * @param forceUpdate If true, will force the method to regenerate the simple tree from the current rootNode tree. * @return A simplified version of the Script's tree. *//*from ww w. j a v a2s .c om*/ public TreeItem<String> getSimpleTree(boolean forceUpdate) { if (_simpleRootNode != null && !forceUpdate) { return _simpleRootNode; } if (_rootNode == null) { _rootNode = getRootNode(); } TreeItem<String> local = new TreeItem<String>("root"); for (TreeItem<String> child : getRootNode().getChildren()) { List<TreeItem<String>> localWaveStrings = FXCollections.observableArrayList(); List<TreeItem<String>> waveStrings = getWaveStrings(child).orElse(null); if (waveStrings == null) continue; for (TreeItem<String> wave : waveStrings) { TreeItem<String> sound = new TreeItem<String>(); //Remove whitespace, quotes, and value# text. String waveValue = wave.getValue().trim(); int thirdQuoteIndex = StringUtils.ordinalIndexOf(waveValue, "\"", 3); waveValue = (waveValue.substring(thirdQuoteIndex + 1, waveValue.length() - 1)); sound.setValue(waveValue); localWaveStrings.add(sound); } TreeItem<String> localChild = new TreeItem<>(child.getValue()); localChild.getChildren().setAll(localWaveStrings); local.getChildren().add(localChild); } _simpleRootNode = local; return _simpleRootNode; }
From source file:ubicrypt.ui.ctrl.HomeController.java
private void refreshItems(final TreeItem<ITreeItem> root) { root.getChildren().forEach(item -> { final ITreeItem value = item.getValue(); if (value instanceof FileItem) { ((FileItem) value).isUp2date(); }//from w ww.j ava 2s .com refreshItems(item); }); }
From source file:sonicScream.models.Script.java
/** * Takes the currently active simple tree, and uses its values to update the main * rootNode tree, then returns the newly-updated tree. * @return The newly-updated tree./*from w ww .j av a2s .co m*/ */ public TreeItem<String> updateRootNodeWithSimpleTree() { if (_simpleRootNode == null) { return getRootNode(); } for (TreeItem<String> entry : _simpleRootNode.getChildren()) { List<TreeItem<String>> sounds = entry.getChildren(); for (int i = 0; i < sounds.size(); i++) { TreeItem<String> currentEntryInRoot = TreeUtils.findKey(_rootNode, entry.getValue()); List<TreeItem<String>> rootSounds = TreeUtils.getWaveStrings(currentEntryInRoot).orElseThrow(null); if (rootSounds != null && rootSounds.size() > i) { if (rootSounds.get(i).getValue().contains(sounds.get(i).getValue())) { continue; } String rootSoundString = rootSounds.get(i).getValue(); String soundPrefix = StringUtils.substringBetween(rootSoundString, "\"", "\""); soundPrefix = soundPrefix.substring(0, soundPrefix.length() - 1); //Remove the number from the prefix String value = "\"" + soundPrefix + i + "\" \"" + sounds.get(i).getValue() + "\""; rootSounds.get(i).setValue(value); } } } return _rootNode; }
From source file:org.dataconservancy.packaging.gui.presenter.impl.EditPackageContentsPresenterImplTest.java
/** * Helper function for getting a child with a given ID * @param parent the parent TreeItem/* w ww . j a v a2 s .co m*/ * @param id the ID * @return a child with a given ID */ private TreeItem<Node> findChild(TreeItem<Node> parent, URI id) { for (TreeItem<Node> ti : parent.getChildren()) { if (ti.getValue().getIdentifier().equals(id)) { parent.setExpanded(true); return ti; } } return null; }
From source file:com.exalttech.trex.ui.controllers.PacketViewerController.java
/** * Build packet detail tree/*w w w . j av a 2 s . c o m*/ * * @param packetData */ private void buildPacketDetailTree(String packetData) { String[] mainNode = packetData.split("\n"); TreeItem root = new TreeItem(); packetDetailTree.setRoot(root); packetDetailTree.setShowRoot(false); for (String node : mainNode) { node = node.replaceAll("\r", "").trim(); if ("[".equals(node.substring(0, 1))) { TreeItem subRoot = new TreeItem(node); root.getChildren().add(subRoot); } else { TreeItem sub = new TreeItem(node); ((TreeItem) root.getChildren().get(root.getChildren().size() - 1)).getChildren().add(sub); } } }
From source file:sonicScream.controllers.CategoryTabController.java
private void recursiveSetNodeExpanded(TreeItem<String> root, boolean expanded) { if (root.getParent() != null) //Don't want to collapse the root! {// w w w . ja va 2 s .c om root.setExpanded(expanded); } for (TreeItem<String> item : root.getChildren()) { if (item.getChildren().isEmpty()) { item.setExpanded(expanded); } else { recursiveSetNodeExpanded(item, expanded); } } }
From source file:com.cdd.bao.editor.endpoint.BrowseEndpoint.java
private void rebuildTree() { currentlyRebuilding = true;/*from www .j a v a2s. c o m*/ treeRoot.getChildren().clear(); for (int n = 0; n < schemaList.length; n++) { TreeItem<Branch> item = new TreeItem<>(new Branch(this, schemaList[n])); item.setExpanded(true); treeRoot.getChildren().add(item); for (int i = 0; i < schemaList[n].numAssays(); i++) { Schema.Assay assay = schemaList[n].getAssay(i); item.getChildren().add(new TreeItem<Branch>(new Branch(this, schemaList[n], assay))); } } currentlyRebuilding = false; }
From source file:ubicrypt.ui.ctrl.HomeController.java
@PostConstruct public void init() { gProgress = new GeneralProgress(inProgress, inProgressMessage); treeView.setCellFactory(treeView1 -> new TreeCellFactory(treeView1, fileUntracker, appEvents, gProgress)); addProvider.setOnMouseClicked(event -> ctx.browse("selectProvider")); addFile.setOnMouseClicked(event -> { if (!localConfig.getProviders().stream().findAny().isPresent()) { ctx.browse("selectProvider"); return; }/*from w w w . jav a 2 s .c om*/ fileAdder.accept(emptyPath); }); settings.setOnMouseClicked(event -> ctx.browse("settings")); filesRoot = new TreeItem<>(new RootFilesItem(event -> fileAdder.accept(emptyPath))); TreeItem<ITreeItem> root = new TreeItem<>(); treeView.setRoot(root); root.getChildren().add(filesRoot); treeView.setShowRoot(false); localConfig.getLocalFiles().stream().filter(Utils.ignoredFiles) .forEach(localFile -> addFiles(localFile.getPath().iterator(), basePath, filesRoot, localFile)); //providers providersRoot = new TreeItem<>(new RootProvidersItem()); root.getChildren().add(providersRoot); localConfig.getProviders().stream().forEach(providerAdder); //provider status events providerEvent.subscribe(pevent -> { switch (pevent.getEvent()) { case added: log.info("new provider added:{}", pevent.getHook().getProvider()); final Optional<TreeItem<ITreeItem>> optItem = providersRoot.getChildren().stream() .filter(item -> ((ProviderItem) item.getValue()).getProvider() .equals(pevent.getHook().getProvider())) .findFirst(); if (!optItem.isPresent()) { providerAdder.accept(pevent.getHook().getProvider()); } pevent.getHook().getStatusEvents().subscribe(event -> { Function<String, String> classLabel; log.info("provider status {}:{}", event, pevent.getHook().getProvider()); switch (event) { case error: classLabel = code -> format("tree-provider-%s-error", code); break; default: //TODO:labels for other statuses classLabel = code -> format("tree-provider-%s", code); } optItem.ifPresent(item -> { final ProviderItem providerItem = (ProviderItem) item.getValue(); final Node graphics = providerItem.getGraphics(); graphics.getStyleClass().clear(); providerDescriptors.stream() .filter(pd -> pd.getType().equals(providerItem.getProvider().getClass())) .map(ProviderDescriptor::getCode).findFirst() .ifPresent(code -> graphics.getStyleClass().add(classLabel.apply(code))); }); }); break; case removed: //TODO: remove provider break; default: log.warn("unmanaged event:{}", pevent.getEvent()); } }); //remote file events fileEvents.filter(fileEvent -> fileEvent.getLocation() == FileEvent.Location.remote) .subscribe(fileEvent -> { log.debug("file remote event:{}", fileEvent); //update file icon final UbiFile<UbiFile> file = fileEvent.getFile(); Observable.create(fileInSync.call(file)).subscribe(res -> { searchFile(filesRoot, file).ifPresent(treeView -> { final Node graphics = treeView.getValue().getGraphics(); graphics.getStyleClass().clear(); graphics.getStyleClass().add(format("tree-file-saved-%s", res)); }); }); }); //local file events fileEvents.filter(fileEvent -> fileEvent.getLocation() == FileEvent.Location.local && fileEvent.getType() == FileEvent.Type.created).subscribe(fileEvent -> { log.debug("file local event:{}", fileEvent); localConfig.getLocalFiles().stream().filter(fileEvent.getFile()::equals).findFirst().ifPresent( fe -> addFiles(fileEvent.getFile().getPath().iterator(), basePath, filesRoot, fe)); searchFile(filesRoot, fileEvent.getFile()).ifPresent(treeView -> { final Node graphics = treeView.getValue().getGraphics(); graphics.getStyleClass().clear(); graphics.getStyleClass().add(format("tree-file-saved-%s", true)); }); }); //file progress monitor progressEvents.subscribe(progress -> { Platform.runLater(() -> { if (progress.isCompleted()) { log.debug("progress completed"); if (!filesInProgress.remove(progress)) { log.warn("progress not tracked. progress file:{}, element:{}", progress.getProvenience().getFile()); } Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(2), ae -> { progressFile.setText(""); progressProvider.setText(""); progressBar.setProgress(0D); })); timeline.play(); } else { filesInProgress.add(progress); } if (filesInProgress.isEmpty()) { // footer.setVisible(false); return; } footer.setVisible(true); filesInProgress.stream().findFirst().ifPresent(pr -> { progressFile.setText(StringUtils .abbreviate(pr.getProvenience().getFile().getPath().getFileName().toString(), 30)); progressProvider.setText(StringUtils.abbreviate(pr.getTarget().toString(), 30)); progressBar.setProgress((double) progress.getChunk() / pr.getProvenience().getFile().getSize()); }); }); }); //sync-done events appEvents.subscribe(ClassMatcher.newMatcher().on(SyncBeginEvent.class, event -> { log.info("sync begin received"); Platform.runLater(() -> { gProgress.startProgress("Synchronizing providers"); addFile.setDisable(true); addProvider.setDisable(true); }); }).on(SynchDoneEvent.class, event -> { log.debug("sync done"); refreshItems(filesRoot); Platform.runLater(() -> { gProgress.stopProgress(); addFile.setDisable(false); addProvider.setDisable(false); }); })); }
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);//from w w w . j a v a 2 s . com 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()); } }