Search in sources :

Example 71 with TreeItem

use of javafx.scene.control.TreeItem in project dwoss by gg-net.

the class TreeTableController method getProductGroups.

private ObservableList<TreeItem<DataWrapper>> getProductGroups(TradeName tradeName) {
    ObservableList<TreeItem<DataWrapper>> result = FXCollections.observableArrayList();
    for (ProductGroup group : ProductGroup.values()) {
        TreeItem<DataWrapper> item = new TreeItem<>();
        ProductGroupWrapper productGroupWrapper = new ProductGroupWrapper(group, tradeName, item);
        item.setValue(productGroupWrapper);
        item.getChildren().add(loading);
        item.expandedProperty().addListener(new ChangeListener<Boolean>() {

            @Override
            public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
                if (productGroupWrapper.isLoading()) {
                    return;
                }
                productGroupWrapper.setLoading(true);
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        item.getChildren().addAll(getCategoryProducts(productGroupWrapper.getTradeName(), productGroupWrapper.getProductGroup()));
                        item.getChildren().remove(loading);
                    }
                }).start();
                L.info("Products loaded");
            }
        });
        result.add(item);
    }
    return result;
}
Also used : ProductGroup(eu.ggnet.dwoss.rules.ProductGroup) TreeItem(javafx.scene.control.TreeItem)

Example 72 with TreeItem

use of javafx.scene.control.TreeItem in project Smartcity-Smarthouse by TechnionYP5777.

the class MainSystemGuiController method setupFSTreeView.

private void setupFSTreeView(SystemCore model) {
    TreeItem<String> rootElement = new TreeItem<>("File System View");
    rootElement.setExpanded(true);
    createTree(model.getFileSystem().getReadOnlyFileSystem(), rootElement);
    TreeTableColumn<String, String> fsViewCol = new TreeTableColumn<>();
    fsViewCol.prefWidthProperty().bind(fsTreeView.widthProperty());
    fsViewCol.setCellValueFactory((CellDataFeatures<String, String> p) -> new ReadOnlyStringWrapper(p.getValue().getValue()));
    fsTreeView.setRoot(rootElement);
    fsTreeView.getColumns().add(fsViewCol);
    mainSplitPane.getItems().add(fsTreeView);
    mainSplitPane.getDividers().get(0).setPosition(0.7);
}
Also used : CellDataFeatures(javafx.scene.control.TreeTableColumn.CellDataFeatures) TreeItem(javafx.scene.control.TreeItem) TreeTableColumn(javafx.scene.control.TreeTableColumn) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper)

Example 73 with TreeItem

use of javafx.scene.control.TreeItem in project trex-stateless-gui by cisco-system-traffic-generator.

the class PacketViewerController method buildPacketDetailTree.

/**
 * Build packet detail tree
 *
 * @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);
        }
    }
}
Also used : TreeItem(javafx.scene.control.TreeItem)

Example 74 with TreeItem

use of javafx.scene.control.TreeItem in project tokentool by RPTools.

the class TokenTool_Controller method cacheOverlays.

private TreeItem<Path> cacheOverlays(File dir, TreeItem<Path> parent, int THUMB_SIZE) throws IOException {
    log.debug("Caching " + dir.getAbsolutePath());
    TreeItem<Path> root = new TreeItem<>(dir.toPath());
    root.setExpanded(false);
    File[] files = dir.listFiles();
    final String I18N_CACHE_TEXT = I18N.getString("TokenTool.treeview.caching");
    final Task<Void> task = new Task<Void>() {

        @Override
        protected Void call() throws Exception {
            for (File file : files) {
                if (loadOverlaysThread.isInterrupted())
                    break;
                if (file.isDirectory()) {
                    cacheOverlays(file, root, THUMB_SIZE);
                } else {
                    Path filePath = file.toPath();
                    TreeItem<Path> imageNode = new TreeItem<>(filePath, ImageUtil.getOverlayThumb(new ImageView(), filePath));
                    root.getChildren().add(imageNode);
                    loadCount.getAndIncrement();
                    overlayTreeProgressBar.progressProperty().set(loadCount.doubleValue() / overlayCount);
                }
            }
            if (parent != null) {
                // When we show the overlay image, the TreeItem value is empty so we need to
                // sort those to the bottom for a cleaner look and keep sub dir's at the top.
                // If a node has no children then it's an overlay, otherwise it's a directory...
                root.getChildren().sort(new Comparator<TreeItem<Path>>() {

                    @Override
                    public int compare(TreeItem<Path> o1, TreeItem<Path> o2) {
                        if (o1.getChildren().size() == 0 && o2.getChildren().size() == 0)
                            return 0;
                        else if (o1.getChildren().size() == 0)
                            return Integer.MAX_VALUE;
                        else if (o2.getChildren().size() == 0)
                            return Integer.MIN_VALUE;
                        else
                            return o1.getValue().compareTo(o2.getValue());
                    }
                });
                parent.getChildren().add(root);
                parent.getChildren().sort(new Comparator<TreeItem<Path>>() {

                    @Override
                    public int compare(TreeItem<Path> o1, TreeItem<Path> o2) {
                        if (o1.getChildren().size() == 0 && o2.getChildren().size() == 0)
                            return 0;
                        else if (o1.getChildren().size() == 0)
                            return Integer.MAX_VALUE;
                        else if (o2.getChildren().size() == 0)
                            return Integer.MIN_VALUE;
                        else
                            return o1.getValue().compareTo(o2.getValue());
                    }
                });
            }
            return null;
        }
    };
    overlayTreeProgressBar.progressProperty().addListener(observable -> {
        Platform.runLater(() -> progressBarLabel.setText(I18N_CACHE_TEXT + Math.round(overlayCount - loadCount.doubleValue()) + "..."));
    });
    // Only add this listener to the parent task so it's only called once
    if (parent == null) {
        overlayTreeProgressBar.progressProperty().addListener(observable -> {
            Platform.runLater(() -> {
                if (overlayTreeProgressBar.getProgress() >= 1)
                    treeViewFinish();
            });
        });
    }
    executorService.execute(task);
    return root;
}
Also used : Path(java.nio.file.Path) Task(javafx.concurrent.Task) TreeItem(javafx.scene.control.TreeItem) ImageView(javafx.scene.image.ImageView) File(java.io.File)

Example 75 with TreeItem

use of javafx.scene.control.TreeItem in project tokentool by RPTools.

the class TokenTool method cacheOverlays.

/**
 * @author Jamz
 * @throws IOException
 * @since 2.0
 *     <p>This method loads and processes all the overlays found in user.home/overlays and it can
 *     take a minute to load as it creates thumbnail versions for the comboBox so we call this
 *     during the init and display progress in the preLoader (splash screen).
 */
private TreeItem<Path> cacheOverlays(File dir, TreeItem<Path> parent, int THUMB_SIZE) throws IOException {
    TreeItem<Path> root = new TreeItem<>(dir.toPath());
    root.setExpanded(false);
    log.debug("caching " + dir.getAbsolutePath());
    File[] files = dir.listFiles();
    for (File file : files) {
        if (file.isDirectory()) {
            cacheOverlays(file, root, THUMB_SIZE);
        } else {
            Path filePath = file.toPath();
            TreeItem<Path> imageNode = new TreeItem<>(filePath, ImageUtil.getOverlayThumb(new ImageView(), filePath));
            root.getChildren().add(imageNode);
            notifyPreloader(new Preloader.ProgressNotification((double) loadCount++ / overlayCount));
        }
    }
    if (parent != null) {
        // When we show the overlay image, the TreeItem value is "" so we need to
        // sort those to the bottom for a cleaner look and keep sub dir's at the top.
        // If a node has no children then it's an overlay, otherwise it's a directory...
        root.getChildren().sort(new Comparator<TreeItem<Path>>() {

            @Override
            public int compare(TreeItem<Path> o1, TreeItem<Path> o2) {
                if (o1.getChildren().size() == 0 && o2.getChildren().size() == 0)
                    return 0;
                else if (o1.getChildren().size() == 0)
                    return Integer.MAX_VALUE;
                else if (o2.getChildren().size() == 0)
                    return Integer.MIN_VALUE;
                else
                    return o1.getValue().compareTo(o2.getValue());
            }
        });
        parent.getChildren().add(root);
    }
    return root;
}
Also used : Path(java.nio.file.Path) TreeItem(javafx.scene.control.TreeItem) Preloader(javafx.application.Preloader) ImageView(javafx.scene.image.ImageView) File(java.io.File)

Aggregations

TreeItem (javafx.scene.control.TreeItem)76 File (java.io.File)15 TreeView (javafx.scene.control.TreeView)11 ArrayList (java.util.ArrayList)10 List (java.util.List)10 ObjectProperty (javafx.beans.property.ObjectProperty)9 MenuItem (javafx.scene.control.MenuItem)9 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 IOException (java.io.IOException)7 Optional (java.util.Optional)7 FXCollections (javafx.collections.FXCollections)7 ListChangeListener (javafx.collections.ListChangeListener)7 ObservableList (javafx.collections.ObservableList)7 ActionEvent (javafx.event.ActionEvent)7 ContextMenu (javafx.scene.control.ContextMenu)7 Stage (javafx.stage.Stage)7 FXML (javafx.fxml.FXML)6 Button (javafx.scene.control.Button)6