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

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


            treeViewNodeListeners.nodeUpdated(TreeView.this, path, index);
        }

        @Override
        public void listCleared(List<Object> list) {
            Path path = getPath();

            // Release each child handler
            for (int i = 0, n = getLength(); i < n; i++) {
                BranchHandler handler = get(i);
View Full Code Here


        @Override
        public void comparatorChanged(List<Object> list,
            Comparator<Object> previousComparator) {
            if (list.getComparator() != null) {
                Path path = getPath();

                // Release all child handlers. This is safe because of the
                // calls to clearPaths(). Failure to do this would result in
                // the indices of our child handlers not matching those of the
                // backing data structures, which would yield very hard to find
View Full Code Here

         * @param index
         * The index of the inserted item within its parent.
         */
        private int incrementPaths(ArrayList<Path> paths, Path basePath, int index) {
            // Calculate the child's path
            Path childPath = new Path(basePath);
            childPath.add(index);

            // Find the child path's place in our sorted paths sequence
            int i = ArrayList.binarySearch(paths, childPath, PATH_COMPARATOR);
            if (i < 0) {
                i = -(i + 1);
            }

            // Temporarily clear the comparator while we update the list
            paths.setComparator(null);

            int n = paths.getLength();
            try {
                // Update all affected paths by incrementing the appropriate path element
                for (int depth = basePath.getLength(); i < n; i++) {
                    Path affectedPath = paths.get(i);

                    if (!Sequence.Tree.isDescendant(basePath, affectedPath)) {
                        // All paths from here forward are guaranteed to be unaffected
                        break;
                    }

                    Integer[] elements = affectedPath.toArray();
                    elements[depth]++;
                    paths.update(i, new ImmutablePath(elements));
                }
            } finally {
                // Restore the comparator
View Full Code Here

        private int clearAndDecrementPaths(ArrayList<Path> paths, Path basePath, int index,
            int count) {
            int depth = basePath.getLength();

            // Find the index of the first path to clear (inclusive)
            Path testPath = new Path(basePath);
            testPath.add(index);

            int start = ArrayList.binarySearch(paths, testPath, PATH_COMPARATOR);
            if (start < 0) {
                start = -(start + 1);
            }

            // Find the index of the last path to clear (exclusive)
            testPath.update(depth, index + count);

            int end = ArrayList.binarySearch(paths, testPath, PATH_COMPARATOR);
            if (end < 0) {
                end = -(end + 1);
            }

            // Clear affected paths
            if (end > start) {
                paths.remove(start, end - start);
            }

            // Decrement paths as necessary
            int n = paths.getLength();
            for (int i = start; i < n; i++) {
                Path affectedPath = paths.get(i);

                if (!Sequence.Tree.isDescendant(basePath, affectedPath)) {
                    // All paths from here forward are guaranteed to be unaffected
                    break;
                }

                Integer[] elements = affectedPath.toArray();
                elements[depth] -= count;
                paths.update(i, new ImmutablePath(elements));
            }

            return (n - start);
View Full Code Here

         * @param index
         * The index of the updated item within its parent.
         */
        private void clearPaths(ArrayList<Path> paths, Path basePath, int index) {
            // Calculate the child's path
            Path childPath = new Path(basePath);
            childPath.add(index);

            // Find the child path's place in our sorted paths sequence
            int clearIndex = ArrayList.binarySearch(paths, childPath, PATH_COMPARATOR);
            if (clearIndex < 0) {
                clearIndex = -(clearIndex + 1);
            }

            // Remove the child and all descendants from the paths list
            for (int i = clearIndex, n = paths.getLength(); i < n; i++) {
                Path affectedPath = paths.get(clearIndex);

                if (!Sequence.Tree.isDescendant(childPath, affectedPath)) {
                    break;
                }

View Full Code Here

            index = (index < 0 ? -(index + 1) : index + 1);

            // Remove all descendants from the paths list
            int n = paths.getLength();
            for (int i = index; i < n; i++) {
                Path affectedPath = paths.get(index);

                if (!Sequence.Tree.isDescendant(basePath, affectedPath)) {
                    break;
                }
View Full Code Here

                        if (previousCheckState == TreeView.NodeCheckState.CHECKED
                            || checkState == TreeView.NodeCheckState.CHECKED) {
                            // Propagate downward
                            List<?> treeBranch = (List<?>)treeNode;

                            Path childPath = new Path(path);
                            int lastIndex = childPath.getLength();
                            childPath.add(0);

                            for (int i = 0, n = treeBranch.getLength(); i < n; i++) {
                                childPath.update(lastIndex, i);
                                treeView.setNodeChecked(childPath, checked);

                                EventNode eventNode = (EventNode)treeBranch.get(i);
                                Method event = eventNode.getEvent();

                                if (checked) {
                                    eventLogger.getIncludeEvents().add(event);
                                } else {
                                    eventLogger.getIncludeEvents().remove(event);
                                }
                            }
                        }
                    } else {
                        Path parentPath = new Path(path, path.getLength() - 1);

                        EventNode eventNode = (EventNode)treeNode;
                        Method event = eventNode.getEvent();

                        if (checked) {
                            List<?> treeBranch = (List<?>)Sequence.Tree.get(treeData, parentPath);

                            Path childPath = new Path(path);
                            int lastIndex = parentPath.getLength();

                            int i = 0, n = treeBranch.getLength();
                            while (i < n) {
                                childPath.update(lastIndex, i);

                                if (!treeView.isNodeChecked(childPath)) {
                                    break;
                                }
View Full Code Here

                    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

                if (x != null && x instanceof TreeBranch)
                {
                    TreeBranch treeBranch = new TreeBranch("new branch");

                    // workaround for PIVOT-734
                    Path path = tree.getSelectedPath();
                    tree.setBranchExpanded(path, true);

                    ((TreeBranch)x).add(treeBranch);
                }
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

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.