Search in sources :

Example 46 with TreeItem

use of javafx.scene.control.TreeItem in project Gargoyle by callakrsos.

the class ProjectFileTreeItemCreator method createJavaProjectMemberNode.

public TreeItem<FileWrapper> createJavaProjectMemberNode(final FileWrapper f) {
    TreeItem<FileWrapper> treeItem = new JavaProjectMemberFileTreeItem(f) {

        private boolean isLeaf;

        private boolean isFirstTimeChildren = true;

        private boolean isFirstTimeLeaf = true;

        @Override
        public ObservableList<TreeItem<FileWrapper>> getChildren() {
            if (isFirstTimeChildren) {
                isFirstTimeChildren = false;
                super.getChildren().setAll(buildChildren(this, FILE_TREE_TYPE.JAVA_PROJECT_MEMBER));
            }
            return super.getChildren();
        }

        @Override
        public boolean isLeaf() {
            if (isFirstTimeLeaf) {
                isFirstTimeLeaf = false;
                FileWrapper f = (FileWrapper) getValue();
                File file = f.getFile();
                if (file.isDirectory()) {
                    isLeaf = file.list().length == 0 ? true : false;
                } else {
                    isLeaf = f.isFile();
                }
            }
            return isLeaf;
        }
    };
    treeItem.expandedProperty().addListener((oba, oldval, newval) -> {
        FileWrapper value = f;
        File file = value.getFile();
        if (newval) {
            cacheExpaned.add(file);
        } else {
            cacheExpaned.remove(file);
        }
    });
    if (cacheExpaned.contains(f.getFile())) {
        treeItem.setExpanded(true);
    }
    return treeItem;
}
Also used : TreeItem(javafx.scene.control.TreeItem) File(java.io.File)

Example 47 with TreeItem

use of javafx.scene.control.TreeItem in project Gargoyle by callakrsos.

the class ProjectFileTreeItemCreator method buildChildren.

private ObservableList<TreeItem<FileWrapper>> buildChildren(TreeItem<FileWrapper> treeItem, FILE_TREE_TYPE type) {
    FileWrapper f = treeItem.getValue();
    boolean isParentSvnConnected = f.isSVNConnected();
    File parentWcDbFile = f.getWcDbFile();
    if (f == null) {
        return FXCollections.emptyObservableList();
    }
    if (f.isFile()) {
        return FXCollections.emptyObservableList();
    }
    File[] files = f.listFiles();
    if (files != null) {
        ObservableList<TreeItem<FileWrapper>> children = FXCollections.observableArrayList();
        switch(type) {
            case NOMAL:
                for (File childFile : files) {
                    TreeItem<FileWrapper> createNode = createDefaultNode(createFileWrapper(childFile));
                    children.add(createNode);
                }
                break;
            case JAVA_PROJECT:
                for (File childFile : files) {
                    TreeItem<FileWrapper> createNode = createJavaProjectMemberNode(createFileWrapper(childFile, fw -> {
                        fw.setWcDbFile(parentWcDbFile);
                        fw.setSVNConnected(isParentSvnConnected);
                    }));
                    children.add(createNode);
                }
                break;
            case JAVA_PROJECT_MEMBER:
                for (File childFile : files) {
                    TreeItem<FileWrapper> createNode = createJavaProjectMemberNode(createFileWrapper(childFile, fw -> {
                        fw.setWcDbFile(parentWcDbFile);
                        fw.setSVNConnected(isParentSvnConnected);
                    }));
                    children.add(createNode);
                }
                break;
        }
        return children;
    }
    return FXCollections.emptyObservableList();
}
Also used : FilenameFilter(java.io.FilenameFilter) Logger(org.slf4j.Logger) TreeItem(javafx.scene.control.TreeItem) ObjectInputStream(java.io.ObjectInputStream) LoggerFactory(org.slf4j.LoggerFactory) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) FXCollections(javafx.collections.FXCollections) IOException(java.io.IOException) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) FileInputStream(java.io.FileInputStream) RuntimeClassUtil(com.kyj.fx.voeditor.visual.util.RuntimeClassUtil) File(java.io.File) HashSet(java.util.HashSet) Consumer(java.util.function.Consumer) ObjectOutputStream(java.io.ObjectOutputStream) ObservableList(javafx.collections.ObservableList) TreeItem(javafx.scene.control.TreeItem) File(java.io.File)

Example 48 with TreeItem

use of javafx.scene.control.TreeItem in project Gargoyle by callakrsos.

the class ProjectFileTreeItemCreator method createFileNode.

public TreeItem<FileWrapper> createFileNode(final FileWrapper f) {
    return new FileTreeItem(f) {

        private boolean isLeaf;

        private boolean isFirstTimeChildren = true;

        private boolean isFirstTimeLeaf = true;

        @Override
        public ObservableList<TreeItem<FileWrapper>> getChildren() {
            if (isFirstTimeChildren) {
                isFirstTimeChildren = false;
                super.getChildren().setAll(buildChildren(this, FILE_TREE_TYPE.NOMAL));
            }
            return super.getChildren();
        }

        @Override
        public boolean isLeaf() {
            if (isFirstTimeLeaf) {
                isFirstTimeLeaf = false;
                FileWrapper f = (FileWrapper) getValue();
                File file = f.getFile();
                if (file.isDirectory()) {
                    isLeaf = file.list().length == 0 ? true : false;
                } else {
                    isLeaf = f.isFile();
                }
            }
            return isLeaf;
        }
    };
}
Also used : TreeItem(javafx.scene.control.TreeItem) File(java.io.File)

Example 49 with TreeItem

use of javafx.scene.control.TreeItem in project Gargoyle by callakrsos.

the class CheckBoxFxControlsTreeItem method createNode.

/**
	 * 파일 트리를 생성하기 위한 노드를 반환한다.
	 *
	 * @Date 2015. 10. 14.
	 * @param f
	 * @return
	 * @User KYJ
	 */
public TreeItem<Node> createNode(final Node f) {
    TreeItem<Node> treeItem = new CheckBoxTreeItem<Node>(f) {

        private boolean isLeaf;

        private boolean isFirstTimeChildren = true;

        private boolean isFirstTimeLeaf = true;

        @Override
        public ObservableList<TreeItem<Node>> getChildren() {
            if (isFirstTimeChildren) {
                isFirstTimeChildren = false;
                super.getChildren().setAll(buildChildren(this));
            }
            return super.getChildren();
        }

        @Override
        public boolean isLeaf() {
            if (isFirstTimeLeaf) {
                isFirstTimeLeaf = false;
                Node f = getValue();
                if (f == null) {
                    isLeaf = true;
                } else if (f instanceof Control) {
                    isLeaf = ((Control) f).getChildrenUnmodifiable().isEmpty();
                } else if (f instanceof Parent) {
                    isLeaf = ((Parent) f).getChildrenUnmodifiable().isEmpty();
                } else if (f instanceof Shape)
                    isLeaf = true;
                else
                    isLeaf = false;
            }
            return isLeaf;
        }

        private ObservableList<TreeItem<Node>> buildChildren(TreeItem<Node> treeItem) {
            Node f = treeItem.getValue();
            if (f == null) {
                return FXCollections.emptyObservableList();
            }
            treeItem.setGraphic(getImage(getName(f)));
            List<Node> childrens = getChildrens(f);
            if (childrens == null || childrens.isEmpty()) {
                return FXCollections.emptyObservableList();
            } else {
                ObservableList<TreeItem<Node>> children = FXCollections.observableArrayList();
                for (Node child : childrens) {
                    children.add(createNode(child));
                }
                return children;
            }
        }
    };
    treeItem.setGraphic(getImage(getName(f)));
    return treeItem;
}
Also used : Control(javafx.scene.control.Control) Shape(javafx.scene.shape.Shape) TreeItem(javafx.scene.control.TreeItem) CheckBoxTreeItem(javafx.scene.control.CheckBoxTreeItem) Parent(javafx.scene.Parent) CheckBoxTreeItem(javafx.scene.control.CheckBoxTreeItem) Node(javafx.scene.Node)

Example 50 with TreeItem

use of javafx.scene.control.TreeItem in project org.csstudio.display.builder by kasemir.

the class WidgetTree method setSelectedWidgets.

/**
 * Called by selection handler when selected widgets have changed, or on new model
 *  @param widgets Widgets to select in tree
 */
public void setSelectedWidgets(final List<Widget> widgets) {
    if (!active.compareAndSet(false, true))
        return;
    try {
        final MultipleSelectionModel<TreeItem<WidgetOrTab>> selection = tree_view.getSelectionModel();
        selection.clearSelection();
        for (Widget widget : widgets) selection.select(widget2tree.get(widget));
        // If something's selected, show it.
        // Otherwise leave tree at current position.
        final int index = selection.getSelectedIndex();
        if (index >= 0)
            tree_view.scrollTo(index);
    } finally {
        active.set(false);
    }
}
Also used : TreeItem(javafx.scene.control.TreeItem) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) Widget(org.csstudio.display.builder.model.Widget)

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