Package org.apache.pivot.wtk.content

Examples of org.apache.pivot.wtk.content.TreeNode


        treeView.expandBranch(new Path(0));
    }

    @SuppressWarnings("unchecked")
    private static TreeNode build(Object value) {
        TreeNode treeNode;

        if (value instanceof Map<?, ?>) {
            TreeBranch treeBranch = new TreeBranch("{}");

            Map<String, Object> map = (Map<String, Object>)value;
            for (String key : map) {
                TreeNode valueNode = build(map.get(key));

                String text = valueNode.getText();
                if (text == null) {
                    valueNode.setText(key);
                } else {
                    valueNode.setText(key + " : " + text);
                }

                treeBranch.add(valueNode);
            }

            treeNode = treeBranch;
        } else if (value instanceof List<?>) {
            TreeBranch treeBranch = new TreeBranch("[]");

            List<Object> list = (List<Object>)value;
            for (int i = 0, n = list.getLength(); i < n; i++) {
                TreeNode itemNode = build(list.get(i));

                String text = itemNode.getText();
                if (text == null) {
                    itemNode.setText("[" + i + "]");
                } else {
                    itemNode.setText("[" + i + "] " + text);
                }

                treeBranch.add(itemNode);
            }

            treeNode = treeBranch;
        } else if (value instanceof String) {
            treeNode = new TreeNode("\"" + value.toString() + "\"");
        } else if (value instanceof Number) {
            treeNode = new TreeNode(value.toString());
        } else if (value instanceof Boolean) {
            treeNode = new TreeNode(value.toString());
        } else {
            treeNode = new TreeNode("null");
        }

        return treeNode;
    }
View Full Code Here


        treeView.expandBranch(new Path(0));
    }

    @SuppressWarnings("unchecked")
    private static TreeNode build(Object value) {
        TreeNode treeNode;

        if (value instanceof Map<?, ?>) {
            TreeBranch treeBranch = new TreeBranch("{}");
            treeBranch.setComparator(new Comparator<TreeNode>() {
                @Override
                public int compare(TreeNode treeNode1, TreeNode treeNode2) {
                    return treeNode1.getText().compareTo(treeNode2.getText());
                }
            });

            Map<String, Object> map = (Map<String, Object>)value;
            for (String key : map) {
                TreeNode valueNode = build(map.get(key));

                String text = valueNode.getText();
                if (text == null) {
                    valueNode.setText(key);
                } else {
                    valueNode.setText(key + " : " + text);
                }

                treeBranch.add(valueNode);
            }

            treeNode = treeBranch;
        } else if (value instanceof List<?>) {
            TreeBranch treeBranch = new TreeBranch("[]");

            List<Object> list = (List<Object>)value;
            for (int i = 0, n = list.getLength(); i < n; i++) {
                TreeNode itemNode = build(list.get(i));

                String text = itemNode.getText();
                if (text == null) {
                    itemNode.setText("[" + i + "]");
                } else {
                    itemNode.setText("[" + i + "] " + text);
                }

                treeBranch.add(itemNode);
            }

            treeNode = treeBranch;
        } else if (value instanceof String) {
            treeNode = new TreeNode("\"" + value.toString() + "\"");
        } else if (value instanceof Number) {
            treeNode = new TreeNode(value.toString());
        } else if (value instanceof Boolean) {
            treeNode = new TreeNode(value.toString());
        } else {
            treeNode = new TreeNode("null");
        }

        return treeNode;
    }
View Full Code Here

        });
        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);
                    }
                }
            }
View Full Code Here

            private final Decorator focusDecorator = new ShadeDecorator(0.2f, Color.RED);
            private Component previousSelectedComponent = null;

            @Override
            public void selectedNodeChanged(TreeView treeViewArgument, Object previousSelectedNode) {
                TreeNode node = (TreeNode) treeViewArgument.getSelectedNode();
                if (previousSelectedComponent != null
                    && previousSelectedComponent.getDecorators().indexOf(focusDecorator) > -1) {
                    previousSelectedComponent.getDecorators().remove(focusDecorator);
                    previousSelectedComponent = null;
                }
                if (node == null || !(node.getUserData() instanceof Component)) {
                    // TODO make the inspectors able to deal with things like
                    // TablePane.Row
                    componentPropertyInspector.setSource(null);
                    componentStyleInspector.setSource(null);
                    return;
                }
                Component selectedComp = (Component) node.getUserData();
                if (selectedComp != null
                    && selectedComp.getDecorators().indexOf(focusDecorator) == -1) {
                    selectedComp.getDecorators().add(focusDecorator);
                    previousSelectedComponent = selectedComp;
                }

                if (selectedComp instanceof FakeWindow) {
                    selectedComp = ((FakeWindow) selectedComp).window;
                }
                componentPropertyInspector.setSource(selectedComp);
                componentStyleInspector.setSource(selectedComp);
            }

            @Override
            public void selectedPathsChanged(TreeView treeViewArgument, Sequence<Path> previousSelectedPaths) {
                // if the selection becomes empty, remove the decorator
                if (treeViewArgument.getSelectedNode() == null && previousSelectedComponent != null
                    && previousSelectedComponent.getDecorators().indexOf(focusDecorator) > -1) {
                    previousSelectedComponent.getDecorators().remove(focusDecorator);
                }
            }

        });

        playgroundCardPane.getComponentMouseButtonListeners().add(
            new ComponentMouseButtonListener.Adapter() {
                @Override
                public boolean mouseClick(Component component, Button button, int x, int y,
                    int count) {
                    if (count == 1) {
                        Component comp = playgroundCardPane.getDescendantAt(x, y);
                        if (comp != null) {
                            TreeNode treeNode = componentToTreeNode.get(comp);
                            Path path = getPathForNode(treeView, treeNode);
                            if (path != null) {
                                treeView.setSelectedPath(path);
                                return true;
                            }
View Full Code Here

        // We don't want the RowSequence object to show up in the tree, it 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);
                }
            }
            // An empty branch looks untidy if it has an arrow next to it,
            // 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;
    }
View Full Code Here

                    EventLogger eventLoggerLocal = (EventLogger)getComponent();

                    boolean checked = (checkState == TreeView.NodeCheckState.CHECKED);

                    List<?> treeData = treeView.getTreeData();
                    TreeNode treeNode = (TreeNode)Sequence.Tree.get(treeData, path);

                    if (treeNode instanceof List<?>) {
                        if (previousCheckState == TreeView.NodeCheckState.CHECKED
                            || checkState == TreeView.NodeCheckState.CHECKED) {
                            // Propagate downward
View Full Code Here

    private void setEventIncluded(Method event, boolean included) {
        List<TreeNode> treeData = (List<TreeNode>)declaredEventsTreeView.getTreeData();

        Sequence.Tree.ItemIterator<TreeNode> iter = Sequence.Tree.depthFirstIterator(treeData);
        while (iter.hasNext()) {
            TreeNode treeNode = iter.next();

            if (treeNode instanceof EventNode) {
                EventNode eventNode = (EventNode)treeNode;

                if (eventNode.getEvent() == event) {
View Full Code Here

                    EventLogger eventLogger = (EventLogger)getComponent();

                    boolean checked = (checkState == TreeView.NodeCheckState.CHECKED);

                    List<?> treeData = treeView.getTreeData();
                    TreeNode treeNode = (TreeNode)Sequence.Tree.get(treeData, path);

                    if (treeNode instanceof List<?>) {
                        if (previousCheckState == TreeView.NodeCheckState.CHECKED
                            || checkState == TreeView.NodeCheckState.CHECKED) {
                            // Propagate downward
View Full Code Here

    private void setEventIncluded(Method event, boolean included) {
        List<TreeNode> treeData = (List<TreeNode>)declaredEventsTreeView.getTreeData();

        Sequence.Tree.ItemIterator<TreeNode> iter = Sequence.Tree.depthFirstIterator(treeData);
        while (iter.hasNext()) {
            TreeNode treeNode = iter.next();

            if (treeNode instanceof EventNode) {
                EventNode eventNode = (EventNode)treeNode;

                if (eventNode.getEvent() == event) {
View Full Code Here

            private final Decorator focusDecorator = new ShadeDecorator(0.2f, Color.RED);
            private Component previousSelectedComponent = null;

            @Override
            public void selectedNodeChanged(TreeView treeView, Object previousSelectedNode) {
                TreeNode node = (TreeNode) treeView.getSelectedNode();
                if (previousSelectedComponent != null
                    && previousSelectedComponent.getDecorators().indexOf(focusDecorator) > -1) {
                    previousSelectedComponent.getDecorators().remove(focusDecorator);
                    previousSelectedComponent = null;
                }
                if (node == null || !(node.getUserData() instanceof Component)) {
                    // TODO make the inspectors able to deal with things like
                    // TablePane.Row
                    componentPropertyInspector.setSource(null);
                    componentStyleInspector.setSource(null);
                    return;
                }
                Component selectedComp = (Component) node.getUserData();
                if (selectedComp != null
                    && selectedComp.getDecorators().indexOf(focusDecorator) == -1) {
                    selectedComp.getDecorators().add(focusDecorator);
                    previousSelectedComponent = selectedComp;
                }

                if (selectedComp instanceof FakeWindow) {
                    selectedComp = ((FakeWindow) selectedComp).window;
                }
                componentPropertyInspector.setSource(selectedComp);
                componentStyleInspector.setSource(selectedComp);
            }

            @Override
            public void selectedPathsChanged(TreeView treeView, Sequence<Path> previousSelectedPaths) {
                // if the selection becomes empty, remove the decorator
                if (treeView.getSelectedNode() == null && previousSelectedComponent != null
                    && previousSelectedComponent.getDecorators().indexOf(focusDecorator) > -1) {
                    previousSelectedComponent.getDecorators().remove(focusDecorator);
                }
            }

        });

        playgroundCardPane.getComponentMouseButtonListeners().add(
            new ComponentMouseButtonListener.Adapter() {
                @Override
                public boolean mouseClick(Component component, Button button, int x, int y,
                    int count) {
                    if (count == 1) {
                        Component comp = playgroundCardPane.getDescendantAt(x, y);
                        if (comp != null) {
                            TreeNode treeNode = componentToTreeNode.get(comp);
                            Path path = getPathForNode(treeView, treeNode);
                            if (path != null) {
                                treeView.setSelectedPath(path);
                                return true;
                            }
View Full Code Here

TOP

Related Classes of org.apache.pivot.wtk.content.TreeNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.