Search in sources :

Example 1 with TreeBranch

use of org.apache.pivot.wtk.content.TreeBranch in project pivot by apache.

the class BXMLExplorerDocument method analyseObjectTree.

@SuppressWarnings("unchecked")
private TreeNode analyseObjectTree(Object container) {
    // doesn't look neat
    if (container instanceof TablePane) {
        TreeBranch branch = new TreeBranch(nameForObject(container));
        TablePane table = (TablePane) container;
        for (TablePane.Row row : table.getRows()) {
            TreeNode childBranch = analyseObjectTree(row);
            branch.add(childBranch);
        }
        setComponentIconOnTreeNode(container, branch);
        return branch;
    }
    // We don't want to analyse the components that are added as part of the
    // skin, so use similar logic to BXMLSerializer
    DefaultProperty defaultProperty = container.getClass().getAnnotation(DefaultProperty.class);
    if (defaultProperty != null) {
        TreeBranch branch = new TreeBranch(nameForObject(container));
        String defaultPropertyName = defaultProperty.value();
        BeanAdapter beanAdapter = new BeanAdapter(container);
        if (!beanAdapter.containsKey(defaultPropertyName)) {
            throw new IllegalStateException("default property " + defaultPropertyName + " not found on " + container);
        }
        Object defaultPropertyValue = beanAdapter.get(defaultPropertyName);
        if (defaultPropertyValue != null) {
            if (defaultPropertyValue instanceof Component) {
                TreeNode childBranch = analyseObjectTree(defaultPropertyValue);
                branch.add(childBranch);
            }
        }
        // so make empty branches into nodes.
        if (branch.isEmpty()) {
            TreeNode node = new TreeNode(branch.getText());
            setComponentIconOnTreeNode(container, node);
            return node;
        }
        setComponentIconOnTreeNode(container, branch);
        return branch;
    }
    if (container instanceof Sequence<?>) {
        TreeBranch branch = new TreeBranch(nameForObject(container));
        Iterable<Object> sequence = (Iterable<Object>) container;
        for (Object child : sequence) {
            TreeNode childBranch = analyseObjectTree(child);
            branch.add(childBranch);
        }
        setComponentIconOnTreeNode(container, branch);
        return branch;
    }
    TreeNode node = new TreeNode(nameForObject(container));
    setComponentIconOnTreeNode(container, node);
    return node;
}
Also used : Sequence(org.apache.pivot.collections.Sequence) DefaultProperty(org.apache.pivot.beans.DefaultProperty) TreeBranch(org.apache.pivot.wtk.content.TreeBranch) TreeNode(org.apache.pivot.wtk.content.TreeNode) BeanAdapter(org.apache.pivot.beans.BeanAdapter) Component(org.apache.pivot.wtk.Component) TablePane(org.apache.pivot.wtk.TablePane)

Example 2 with TreeBranch

use of org.apache.pivot.wtk.content.TreeBranch in project pivot by apache.

the class Pivot718 method controlTree.

private void controlTree(BXMLSerializer bxmlSerializer) {
    treeDelButton = (PushButton) bxmlSerializer.getNamespace().get("treeDelButton");
    tree = (TreeView) bxmlSerializer.getNamespace().get("tree");
    tree.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {

        @Override
        public void selectedPathAdded(TreeView treeView, Path path) {
            System.out.println("selectedPathAdded");
        }

        @Override
        public void selectedPathRemoved(TreeView treeView, Path path) {
            System.out.println("selectedPathRemoved");
        }

        @Override
        public void selectedPathsChanged(TreeView treeView, Sequence<Path> previousSelectedPaths) {
            System.out.println("selectedPathsChanged");
        }

        @Override
        public void selectedNodeChanged(TreeView treeView, Object previousSelectedNode) {
            System.out.println("selectedNodeChanged");
        }
    });
    treeDelButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            TreeNode selectedNode = (TreeNode) tree.getSelectedNode();
            System.out.println("delete :: " + selectedNode);
            if (selectedNode != null) {
                TreeBranch parent = selectedNode.getParent();
                if (parent != null) {
                    parent.remove(selectedNode);
                }
            }
        }
    });
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) TreeBranch(org.apache.pivot.wtk.content.TreeBranch) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) TreeNode(org.apache.pivot.wtk.content.TreeNode) TreeViewSelectionListener(org.apache.pivot.wtk.TreeViewSelectionListener) TreeView(org.apache.pivot.wtk.TreeView)

Example 3 with TreeBranch

use of org.apache.pivot.wtk.content.TreeBranch in project pivot by apache.

the class Pivot734 method controlTree.

private void controlTree(BXMLSerializer bxmlSerializer) {
    treeButtonAdd = (PushButton) bxmlSerializer.getNamespace().get("treeButtonAdd");
    treeButtonRemove = (PushButton) bxmlSerializer.getNamespace().get("treeButtonRemove");
    tree = (TreeView) bxmlSerializer.getNamespace().get("tree");
    boolean treeStyleForShowEmptyBranchControls = tree.getStyles().getBoolean(Style.showEmptyBranchControls);
    System.out.println("tree style for showEmptyBranchControls is " + treeStyleForShowEmptyBranchControls);
    tree.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {

        @Override
        public void selectedPathAdded(TreeView treeView, Path path) {
            System.out.println("selectedPathAdded");
        }

        @Override
        public void selectedPathRemoved(TreeView treeView, Path path) {
            System.out.println("selectedPathRemoved");
        }

        @Override
        public void selectedPathsChanged(TreeView treeView, Sequence<Path> previousSelectedPaths) {
            System.out.println("selectedPathsChanged");
        }

        @Override
        public void selectedNodeChanged(TreeView treeView, Object previousSelectedNode) {
            System.out.println("selectedNodeChanged");
        }
    });
    treeButtonAdd.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            Object x = tree.getSelectedNode();
            System.out.println("add a 'new branch' element to the selected element :: " + x);
            if (x != null && x instanceof TreeBranch) {
                ((TreeBranch) x).add(newBranch);
            }
        }
    });
    treeButtonRemove.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            Object x = tree.getSelectedNode();
            System.out.println("remove a 'new branch' element under the selected element :: " + x);
            if (x != null && x instanceof TreeBranch) {
                ((TreeBranch) x).remove(newBranch);
            }
        }
    });
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) TreeBranch(org.apache.pivot.wtk.content.TreeBranch) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) TreeViewSelectionListener(org.apache.pivot.wtk.TreeViewSelectionListener) TreeView(org.apache.pivot.wtk.TreeView)

Example 4 with TreeBranch

use of org.apache.pivot.wtk.content.TreeBranch in project pivot by apache.

the class Pivot734WithWorkaround method controlTree.

private void controlTree(BXMLSerializer bxmlSerializer) {
    treeButtonAdd = (PushButton) bxmlSerializer.getNamespace().get("treeButtonAdd");
    treeButtonRemove = (PushButton) bxmlSerializer.getNamespace().get("treeButtonRemove");
    tree = (TreeView) bxmlSerializer.getNamespace().get("tree");
    boolean treeStyleForShowEmptyBranchControls = tree.getStyles().getBoolean(Style.showEmptyBranchControls);
    System.out.println("tree style for showEmptyBranchControls is " + treeStyleForShowEmptyBranchControls);
    tree.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {

        @Override
        public void selectedPathAdded(TreeView treeView, Path path) {
            System.out.println("selectedPathAdded");
        }

        @Override
        public void selectedPathRemoved(TreeView treeView, Path path) {
            System.out.println("selectedPathRemoved");
        }

        @Override
        public void selectedPathsChanged(TreeView treeView, Sequence<Path> previousSelectedPaths) {
            System.out.println("selectedPathsChanged");
        }

        @Override
        public void selectedNodeChanged(TreeView treeView, Object previousSelectedNode) {
            System.out.println("selectedNodeChanged");
        }
    });
    treeButtonAdd.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            Object x = tree.getSelectedNode();
            System.out.println("add a 'new branch' element to the selected element :: " + x);
            if (x != null && x instanceof TreeBranch) {
                // workaround for PIVOT-734
                Path path = tree.getSelectedPath();
                tree.setBranchExpanded(path, true);
                // end of workaround for PIVOT-734
                ((TreeBranch) x).add(newBranch);
            }
        }
    });
    treeButtonRemove.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            Object x = tree.getSelectedNode();
            System.out.println("remove a 'new branch' element under the selected element :: " + x);
            if (x != null && x instanceof TreeBranch) {
                ((TreeBranch) x).remove(newBranch);
            }
        }
    });
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) TreeBranch(org.apache.pivot.wtk.content.TreeBranch) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) TreeViewSelectionListener(org.apache.pivot.wtk.TreeViewSelectionListener) TreeView(org.apache.pivot.wtk.TreeView)

Example 5 with TreeBranch

use of org.apache.pivot.wtk.content.TreeBranch in project pivot by apache.

the class JSONViewer method setValue.

private void setValue(Object value) {
    assert (value instanceof Map<?, ?> || value instanceof List<?>);
    // Remove prompt decorator
    if (promptDecorator != null) {
        treeView.getDecorators().remove(promptDecorator);
        promptDecorator = null;
    }
    TreeBranch treeData = new TreeBranch();
    treeData.add(build(value));
    treeView.setTreeData(treeData);
    treeView.expandBranch(new Path(0));
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) TreeBranch(org.apache.pivot.wtk.content.TreeBranch) List(org.apache.pivot.collections.List) FileList(org.apache.pivot.io.FileList) Map(org.apache.pivot.collections.Map)

Aggregations

TreeBranch (org.apache.pivot.wtk.content.TreeBranch)8 Path (org.apache.pivot.collections.Sequence.Tree.Path)4 TreeNode (org.apache.pivot.wtk.content.TreeNode)4 Button (org.apache.pivot.wtk.Button)3 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)3 PushButton (org.apache.pivot.wtk.PushButton)3 TreeView (org.apache.pivot.wtk.TreeView)3 TreeViewSelectionListener (org.apache.pivot.wtk.TreeViewSelectionListener)3 List (org.apache.pivot.collections.List)2 Map (org.apache.pivot.collections.Map)2 FileList (org.apache.pivot.io.FileList)2 Component (org.apache.pivot.wtk.Component)2 FileInputStream (java.io.FileInputStream)1 Method (java.lang.reflect.Method)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 BeanAdapter (org.apache.pivot.beans.BeanAdapter)1 DefaultProperty (org.apache.pivot.beans.DefaultProperty)1 ArrayList (org.apache.pivot.collections.ArrayList)1 HashMap (org.apache.pivot.collections.HashMap)1 Sequence (org.apache.pivot.collections.Sequence)1