Package org.apache.pivot.collections.Sequence.Tree

Examples of org.apache.pivot.collections.Sequence.Tree.Path


                    && !nodeInfo.isCheckmarkDisabled()
                    && x >= nodeX + checkboxX
                    && x < nodeX + checkboxX + checkboxWidth
                    && y >= nodeY + checkboxY
                    && y < nodeY + checkboxY + checkboxHeight) {
                    Path path = nodeInfo.getPath();
                    treeView.setNodeChecked(path, !nodeInfo.isChecked());
                } else {
                    if (selectPath != null
                        && count == 1
                        && button == Mouse.Button.LEFT) {
View Full Code Here


        TreeView.SelectMode selectMode = treeView.getSelectMode();

        switch (keyCode) {
        case Keyboard.KeyCode.UP: {
            if (selectMode != TreeView.SelectMode.NONE) {
                Path firstSelectedPath = treeView.getFirstSelectedPath();

                int index;
                if (firstSelectedPath != null) {
                    NodeInfo previousSelectedNode = getNodeInfoAt(firstSelectedPath);
                    index = visibleNodes.indexOf(previousSelectedNode);
                } else {
                    // Select the last visible node
                    index = visibleNodes.getLength();
                }

                NodeInfo newSelectedNode = null;
                do {
                    newSelectedNode = (--index >= 0) ? visibleNodes.get(index) : null;
                } while (newSelectedNode != null
                    && newSelectedNode.isDisabled());

                if (newSelectedNode != null) {
                    if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)
                        && treeView.getSelectMode() == TreeView.SelectMode.MULTI) {
                        treeView.addSelectedPath(newSelectedNode.getPath());
                    } else {
                        treeView.setSelectedPath(newSelectedNode.getPath());
                    }
                    treeView.scrollAreaToVisible(getNodeBounds(newSelectedNode));
                }
                consumed = true;
            }

            break;
        }

        case Keyboard.KeyCode.DOWN: {
            if (selectMode != TreeView.SelectMode.NONE) {
                Path lastSelectedPath = treeView.getLastSelectedPath();

                int index;
                if (lastSelectedPath != null) {
                    NodeInfo previousSelectedNode = getNodeInfoAt(lastSelectedPath);
                    index = visibleNodes.indexOf(previousSelectedNode);
                } else {
                    // Select the first visible node
                    index = -1;
                }

                NodeInfo newSelectedNode = null;
                int n = visibleNodes.getLength();
                do {
                    newSelectedNode = (++index <= n - 1) ? visibleNodes.get(index) : null;
                } while (newSelectedNode != null
                    && newSelectedNode.isDisabled());

                if (newSelectedNode != null) {
                    if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)
                        && treeView.getSelectMode() == TreeView.SelectMode.MULTI) {
                        treeView.addSelectedPath(newSelectedNode.getPath());
                    } else {
                        treeView.setSelectedPath(newSelectedNode.getPath());
                    }
                    treeView.scrollAreaToVisible(getNodeBounds(newSelectedNode));
                }
                consumed = true;
            }

            break;
        }

        case Keyboard.KeyCode.LEFT: {
            if (showBranchControls) {
                Sequence<Path> paths = treeView.getSelectedPaths();

                if (paths != null
                    && paths.getLength() > 0) {
                    Path path = paths.get(paths.getLength() - 1);
                    NodeInfo nodeInfo = getNodeInfoAt(path);

                    if (nodeInfo instanceof BranchInfo) {
                        BranchInfo branchInfo = (BranchInfo)nodeInfo;

                        if (branchInfo.isExpanded()) {
                            treeView.collapseBranch(branchInfo.getPath());
                        }
                    }

                    consumed = true;
                }
            }

            break;
        }

        case Keyboard.KeyCode.RIGHT: {
            if (showBranchControls) {
                Sequence<Path> paths = treeView.getSelectedPaths();

                if (paths != null
                    && paths.getLength() > 0) {
                    Path path = paths.get(paths.getLength() - 1);
                    NodeInfo nodeInfo = getNodeInfoAt(path);

                    if (nodeInfo instanceof BranchInfo) {
                        BranchInfo branchInfo = (BranchInfo)nodeInfo;
View Full Code Here

        TreeView treeView = (TreeView)getComponent();

        if (keyCode == Keyboard.KeyCode.SPACE) {
            if (treeView.getCheckmarksEnabled()
                && treeView.getSelectMode() == TreeView.SelectMode.SINGLE) {
                Path selectedPath = treeView.getSelectedPath();

                if (selectedPath != null) {
                    NodeInfo nodeInfo = getNodeInfoAt(selectedPath);

                    if (!nodeInfo.isCheckmarkDisabled()) {
View Full Code Here

    // TreeView.Skin methods

    @Override
    public Path getNodeAt(int y) {
        Path path = null;

        NodeInfo nodeInfo = getNodeInfoAt(y);

        if (nodeInfo != null) {
            path = nodeInfo.getPath();
View Full Code Here

                // Only branch nodes can be affected by this event
                if (nodeInfo instanceof BranchInfo) {
                    BranchInfo branchInfo = (BranchInfo)nodeInfo;

                    // Update the cached entry for this branch
                    Path path = branchInfo.getPath();
                    branchInfo.setCheckState(treeView.getNodeCheckState(path));

                    // Add the branch's children to the queue
                    if (branchInfo.children != null) {
                        for (int i = 0, n = branchInfo.children.getLength(); i < n; i++) {
View Full Code Here

        }

        TreeBranch treeData = new TreeBranch();
        treeData.add(build(value));
        treeView.setTreeData(treeData);
        treeView.expandBranch(new Path(0));
    }
View Full Code Here

        treeView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener.Adapter() {
            @Override
            public boolean mouseClick(Component component, Mouse.Button button, int x, int y,
                int count) {
                if (button == Mouse.Button.LEFT && count == 2) {
                    Path path = treeView.getNodeAt(y);

                    if (path != null) {
                        List<?> treeData = treeView.getTreeData();
                        Object node = Tree.get(treeData, path);
View Full Code Here

    @Override
    public void open(Display display, Window owner) {
        super.open(display, owner);

        Path initialSelectedPath = null;
        Path firstComponentPath = null;

        Tree.ItemIterator<?> itemIterator = Tree.depthFirstIterator(treeView.getTreeData());
        while (itemIterator.hasNext()) {
            Object node = itemIterator.next();

            if (node instanceof ComponentNode) {
                ComponentNode componentNode = (ComponentNode)node;
                Path path = itemIterator.getPath();

                if (firstComponentPath == null) {
                    firstComponentPath = path;
                }

                if (classProperty != null) {
                    // class property was set; open the corresponding
                    // component node
                    if (componentNode.getText().equals(classProperty)) {
                        splitPane.setSplitRatio(0);
                        splitPane.setLocked(true);

                        initialSelectedPath = path;
                        break;
                    }
                } else {
                    // class property was *not* set; open the first component
                    // node we find
                    initialSelectedPath = path;
                    break;
                }
            }
        }

        // Default the initial selected path to the first component
        if (initialSelectedPath == null) {
            initialSelectedPath = firstComponentPath;
        }

        if (initialSelectedPath != null) {
            // Select the path
            treeView.setSelectedPath(initialSelectedPath);

            // Ensure that it's visible to the user
            Path branchPath = new Path(initialSelectedPath, initialSelectedPath.getLength() - 1);
            while (branchPath.getLength() > 0) {
                treeView.expandBranch(branchPath);
                branchPath.remove(branchPath.getLength() - 1, 1);
            }

            final Path path = initialSelectedPath;
            ApplicationContext.queueCallback(new Runnable() {
                @Override
                public void run() {
                    treeView.scrollAreaToVisible(treeView.getNodeBounds(path));
                }
View Full Code Here

            return nodeInfo;
        }

        @SuppressWarnings("unchecked")
        public Path getPath() {
            Path path = Path.forDepth(depth);

            NodeInfo nodeInfo = this;

            while (nodeInfo.parent != null) {
                List<Object> parentData = (List<Object>)nodeInfo.parent.data;
                int index = parentData.indexOf(nodeInfo.data);
                path.insert(index, 0);

                nodeInfo = nodeInfo.parent;
            }

            return path;
View Full Code Here

            List<TreeNode> parentData;

            if (n == 1) {
                parentData = (List<TreeNode>)treeData;
            } else {
                Path parentPath = new Path(path, n - 1);
                parentData = (List<TreeNode>)Sequence.Tree.get(treeData, parentPath);
            }

            if (parentData.getComparator() == null) {
                parentData.update(path.get(n - 1), treeNode);
            } else {
                parentData.remove(path.get(n - 1), 1);
                parentData.add(treeNode);

                // Re-select the node, and make sure it's visible
                path = new Path(path, n - 1);
                path.add(parentData.indexOf(treeNode));
                treeView.setSelectedPath(path);
                treeView.scrollAreaToVisible(treeView.getNodeBounds(path));
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.pivot.collections.Sequence.Tree.Path

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.