Search in sources :

Example 66 with TreeItem

use of javafx.scene.control.TreeItem in project ariADDna by StnetixDevTeam.

the class TreeViewFactory method get.

/**
 * temporary method
 *
 * @return
 */
public TreeView get() {
    TreeView<String> tree = new TreeView<>();
    tree.setShowRoot(false);
    TreeItem<String> root = new TreeItem<>("");
    tree.setRoot(root);
    ChangeListener<Boolean> expandedListener = (obs, wasExpanded, isNowExpanded) -> {
        if (isNowExpanded) {
            System.out.println("expand");
            ReadOnlyProperty<?> expandedProperty = (ReadOnlyProperty<?>) obs;
            Object itemThatWasJustExpanded = expandedProperty.getBean();
            for (TreeItem<String> item : tree.getRoot().getChildren()) {
                if (item != itemThatWasJustExpanded) {
                    item.setExpanded(false);
                }
            }
        }
    };
    for (int i = 1; i <= 4; i++) {
        TreeItem<String> item = new TreeItem<>("Top level " + i);
        item.expandedProperty().addListener(expandedListener);
        root.getChildren().add(item);
        for (int j = 1; j <= 4; j++) {
            TreeItem<String> subItem = new TreeItem<>("Sub item " + i + ":" + j);
            item.getChildren().add(subItem);
        }
    }
    PseudoClass subElementPseudoClass = PseudoClass.getPseudoClass("sub-tree-item");
    tree.setCellFactory((TreeView<String> tv) -> {
        TreeCell<String> cell = new TreeCell<String>() {

            @Override
            public void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                setDisclosureNode(null);
                if (empty) {
                    setText("");
                    setGraphic(null);
                } else {
                    // appropriate text for item
                    setText(item);
                }
            }
        };
        cell.treeItemProperty().addListener((obs, oldTreeItem, newTreeItem) -> {
            cell.pseudoClassStateChanged(subElementPseudoClass, newTreeItem != null && newTreeItem.getParent() != cell.getTreeView().getRoot());
        });
        return cell;
    });
    return tree;
}
Also used : Component(org.springframework.stereotype.Component) PseudoClass(javafx.css.PseudoClass) TreeItem(javafx.scene.control.TreeItem) TreeCell(javafx.scene.control.TreeCell) ReadOnlyProperty(javafx.beans.property.ReadOnlyProperty) ChangeListener(javafx.beans.value.ChangeListener) TreeView(javafx.scene.control.TreeView) PseudoClass(javafx.css.PseudoClass) ReadOnlyProperty(javafx.beans.property.ReadOnlyProperty) TreeItem(javafx.scene.control.TreeItem) TreeCell(javafx.scene.control.TreeCell) TreeView(javafx.scene.control.TreeView)

Example 67 with TreeItem

use of javafx.scene.control.TreeItem in project DistributedFractalNetwork by Budder21.

the class FractalEditor method moveUp.

/**
 * @param item
 */
private static void moveUp(TreeItem item) {
    // TODO move layers up
    System.out.println("moveUp");
    if (item.getParent() instanceof TreeItem) {
        TreeItem parent = item.getParent();
        List<TreeItem> list = new ArrayList<TreeItem>();
        Object prev = null;
        for (Object child : parent.getChildren()) {
            if (child == item) {
                list.add((TreeItem) child);
            } else {
                if (prev != null)
                    list.add((TreeItem) prev);
                prev = child;
            }
        }
        if (prev != null)
            list.add((TreeItem) prev);
        parent.getChildren().clear();
        parent.getChildren().addAll(list);
    }
}
Also used : TreeItem(javafx.scene.control.TreeItem) CheckBoxTreeItem(javafx.scene.control.CheckBoxTreeItem) ArrayList(java.util.ArrayList)

Example 68 with TreeItem

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

the class TreeTableController method getCategoryProducts.

private ObservableList<TreeItem<DataWrapper>> getCategoryProducts(TradeName tradeName, ProductGroup group) {
    ObservableList<TreeItem<DataWrapper>> result = FXCollections.observableArrayList();
    for (CategoryProduct cp : loadCp(group, tradeName)) {
        TreeItem<DataWrapper> item = new TreeItem<>();
        CategoryProductWrapper categoryProductWrapper = new CategoryProductWrapper(item, cp);
        item.setValue(categoryProductWrapper);
        item.getChildren().add(loading);
        item.expandedProperty().addListener(new ChangeListener<Boolean>() {

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

                    @Override
                    public void run() {
                        item.getChildren().addAll(getProducts(cp));
                        item.getChildren().remove(loading);
                    }
                }).start();
            }
        });
        result.add(item);
    }
    return result;
}
Also used : CategoryProduct(eu.ggnet.dwoss.uniqueunit.ee.entity.CategoryProduct) TreeItem(javafx.scene.control.TreeItem)

Example 69 with TreeItem

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

the class TreeTableController method getProducts.

private ObservableList<TreeItem<DataWrapper>> getProducts(CategoryProduct cp) {
    ObservableList<TreeItem<DataWrapper>> result = FXCollections.observableArrayList();
    for (Product product : loadProducts(cp)) {
        TreeItem<DataWrapper> item = new TreeItem<>();
        ProductWrapper productWrapper = new ProductWrapper(item, product);
        item.setValue(productWrapper);
        item.getChildren().add(loading);
        item.expandedProperty().addListener(new ChangeListener<Boolean>() {

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

                    @Override
                    public void run() {
                        item.getChildren().addAll(getUnitCollections(product));
                        item.getChildren().remove(loading);
                    }
                }).start();
            }
        });
        result.add(item);
    }
    return result;
}
Also used : TreeItem(javafx.scene.control.TreeItem) CategoryProduct(eu.ggnet.dwoss.uniqueunit.ee.entity.CategoryProduct) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product)

Example 70 with TreeItem

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

the class TreeTableController method getTradeNames.

private ObservableList<TreeItem<DataWrapper>> getTradeNames() {
    ObservableList<TreeItem<DataWrapper>> result = FXCollections.observableArrayList();
    for (TradeName tradeName : TradeName.values()) {
        TreeItem<DataWrapper> item = new TreeItem<>(new TradeNameWrapper(tradeName));
        item.getChildren().addAll(getProductGroups(tradeName));
        result.add(item);
    }
    return result;
}
Also used : TradeName(eu.ggnet.dwoss.rules.TradeName) TreeItem(javafx.scene.control.TreeItem)

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