internal void Initialize(object source, IndexPath sourceIndexPath, bool throwOnAccess)
 {
     m_source          = source;
     m_sourceIndexPath = sourceIndexPath;
     m_throwOnAccess   = throwOnAccess;
     Children          = null;
 }
Beispiel #2
0
        public static void Traverse(
            SelectionNode root,
            bool realizeChildren,
            Action <TreeWalkNodeInfo> nodeAction)
        {
            var pendingNodes = new List <TreeWalkNodeInfo>();
            var current      = new IndexPath(null);

            pendingNodes.Add(new TreeWalkNodeInfo(root, current));

            while (pendingNodes.Count > 0)
            {
                var nextNode = pendingNodes.Last();
                pendingNodes.RemoveLast();
                int count = realizeChildren ? nextNode.Node.DataCount: nextNode.Node.ChildrenNodeCount;
                for (int i = count - 1; i >= 0; i--)
                {
                    SelectionNode child     = nextNode.Node.GetAt(i, realizeChildren);
                    var           childPath = nextNode.Path.CloneWithChildIndex(i);
                    if (child != null)
                    {
                        pendingNodes.Add(new TreeWalkNodeInfo(child, childPath, nextNode.Node));
                    }
                }

                // Queue the children first and then perform the action. This way
                // the action can remove the children in the action if necessary
                nodeAction(nextNode);
            }
        }
Beispiel #3
0
        public void SelectRangeRegressionTest()
        {
            RunOnUIThread.Execute(() =>
            {
                var selectionModel = new SelectionModel()
                {
                    Source = CreateNestedData(1, 2, 3)
                };

                // length of start smaller than end used to cause an out of range error.
                selectionModel.SelectRange(IndexPath.CreateFrom(0), IndexPath.CreateFrom(1, 1));

                ValidateSelection(selectionModel,
                                  new List <IndexPath>()
                {
                    Path(0, 0),
                    Path(0, 1),
                    Path(0, 2),
                    Path(0),
                    Path(1, 0),
                    Path(1, 1)
                },
                                  new List <IndexPath>()
                {
                    Path(),
                    Path(1)
                },
                                  1 /* selectedInnerNodes */);
            });
        }
Beispiel #4
0
 public void ValidateCanSetSelectedIndex()
 {
     RunOnUIThread.Execute(() =>
     {
         var model           = new SelectionModel();
         var ip              = IndexPath.CreateFrom(34);
         model.SelectedIndex = ip;
         Verify.AreEqual(0, ip.CompareTo(model.SelectedIndex));
     });
 }
Beispiel #5
0
        static IndexPath StartPath(IndexPath path, int length)
        {
            List <int> subPath = new List <int>();

            for (int i = 0; i < length; i++)
            {
                subPath.Add(path.GetAt(i));
            }

            return(new IndexPath(subPath));
        }
Beispiel #6
0
 private void Select(SelectionModel manager, IndexPath index, bool select)
 {
     Log.Comment((select ? "Selecting " : "DeSelecting ") + index);
     if (select)
     {
         manager.SelectAt(index);
     }
     else
     {
         manager.DeselectAt(index);
     }
 }
Beispiel #7
0
 private void SelectRangeFromAnchor(SelectionModel manager, IndexPath index, bool select)
 {
     Log.Comment("SelectRangeFromAnchor " + index + " select: " + select.ToString());
     if (select)
     {
         manager.SelectRangeFromAnchorTo(index);
     }
     else
     {
         manager.DeselectRangeFromAnchorTo(index);
     }
 }
Beispiel #8
0
        private object GetData(SelectionModel selectionModel, IndexPath indexPath)
        {
            var data = selectionModel.Source;

            for (int i = 0; i < indexPath.GetSize(); i++)
            {
                var listData = data as IList;
                data = listData[indexPath.GetAt(i)];
            }

            return(data);
        }
Beispiel #9
0
        static bool IsSubSet(IndexPath path, IndexPath subset)
        {
            bool isSubset = true;

            for (int i = 0; i < subset.GetSize(); i++)
            {
                isSubset = path.GetAt(i) == subset.GetAt(i);
                if (!isSubset)
                {
                    break;
                }
            }

            return(isSubset);
        }
Beispiel #10
0
        private bool Contains(List <IndexPath> list, IndexPath index)
        {
            bool contains = false;

            foreach (var item in list)
            {
                if (item.CompareTo(index) == 0)
                {
                    contains = true;
                    break;
                }
            }

            return(contains);
        }
Beispiel #11
0
        private bool AreEqual(IndexPath a, IndexPath b)
        {
            if (a.GetSize() != b.GetSize())
            {
                return(false);
            }

            for (int i = 0; i < a.GetSize(); i++)
            {
                if (a.GetAt(i) != b.GetAt(i))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #12
0
        static bool IsSubSet(IndexPath path, IndexPath subset)
        {
            var subsetSize = subset.GetSize();

            if (path.GetSize() < subsetSize)
            {
                return(false);
            }

            for (int i = 0; i < subsetSize; i++)
            {
                if (path.GetAt(i) != subset.GetAt(i))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #13
0
        public static void TraverseIndexPath(
            SelectionNode root,
            IndexPath path,
            bool realizeChildren,
            Action <SelectionNode, IndexPath, int /*depth*/, int /*childIndex*/> nodeAction)
        {
            var node = root;

            for (int depth = 0; depth < path.GetSize(); depth++)
            {
                int childIndex = path.GetAt(depth);
                nodeAction(node, path, depth, childIndex);

                if (depth < path.GetSize() - 1)
                {
                    node = node.GetAt(childIndex, realizeChildren);
                }
            }
        }
Beispiel #14
0
        private static void Traverse(object root, Action <TreeWalkNodeInfo> nodeAction)
        {
            var       pendingNodes = new Stack <TreeWalkNodeInfo>();
            IndexPath current      = Path(null);

            pendingNodes.Push(new TreeWalkNodeInfo()
            {
                Current = root, Path = current
            });

            while (pendingNodes.Count > 0)
            {
                var currentNode   = pendingNodes.Pop();
                var currentObject = currentNode.Current as IList;

                if (currentObject != null)
                {
                    for (int i = currentObject.Count - 1; i >= 0; i--)
                    {
                        var        child = currentObject[i];
                        List <int> path  = new List <int>();
                        for (int idx = 0; idx < currentNode.Path.GetSize(); idx++)
                        {
                            path.Add(currentNode.Path.GetAt(idx));
                        }

                        path.Add(i);
                        var childPath = IndexPath.CreateFromIndices(path);
                        if (child != null)
                        {
                            pendingNodes.Push(new TreeWalkNodeInfo()
                            {
                                Current = child, Path = childPath
                            });
                        }
                    }
                }

                nodeAction(currentNode);
            }
        }
Beispiel #15
0
        public int CompareTo(IndexPath other)
        {
            var rhsPath       = other;
            int compareResult = 0;
            int lhsCount      = m_path.Count;
            int rhsCount      = rhsPath.m_path.Count;

            if (lhsCount == 0 || rhsCount == 0)
            {
                // one of the paths are empty, compare based on size
                compareResult = (lhsCount - rhsCount);
            }
            else
            {
                // both paths are non-empty, but can be of different size
                for (int i = 0; i < Math.Min(lhsCount, rhsCount); i++)
                {
                    if (m_path[i] < rhsPath.m_path[i])
                    {
                        compareResult = -1;
                        break;
                    }
                    else if (m_path[i] > rhsPath.m_path[i])
                    {
                        compareResult = 1;
                        break;
                    }
                }

                // if both match upto min(lhsCount, rhsCount), compare based on size
                compareResult = compareResult == 0 ? (lhsCount - rhsCount) : compareResult;
            }

            if (compareResult != 0)
            {
                compareResult = compareResult > 0 ? 1 : -1;
            }

            return(compareResult);
        }
Beispiel #16
0
 public static IndexPath Path(params int[] path)
 {
     return(IndexPath.CreateFromIndices(path));
 }
Beispiel #17
0
 public TreeWalkNodeInfo(SelectionNode node, IndexPath indexPath)
     : this(node, indexPath, null)
 {
 }
Beispiel #18
0
 private void SetAnchorIndex(SelectionModel manager, IndexPath index)
 {
     Log.Comment("SetAnchor " + index);
     manager.AnchorIndex = index;
 }
Beispiel #19
0
        public static void TraverseRangeRealizeChildren(
            SelectionNode root,
            IndexPath start,
            IndexPath end,
            Action <TreeWalkNodeInfo> nodeAction)
        {
            Debug.Assert(start.CompareTo(end) == -1);

            var       pendingNodes = new List <TreeWalkNodeInfo>();
            IndexPath current      = start;

            // Build up the stack to account for the depth first walk up to the
            // start index path.
            TraverseIndexPath(
                root,
                start,
                true, /* realizeChildren */
                (node, path, depth, childIndex) =>
            {
                var currentPath  = StartPath(path, depth);
                bool isStartPath = IsSubSet(start, currentPath);
                bool isEndPath   = IsSubSet(end, currentPath);

                int startIndex = depth < start.GetSize() && isStartPath ? Math.Max(0, start.GetAt(depth)) : 0;
                int endIndex   = depth < end.GetSize() && isEndPath ? Math.Min(node.DataCount - 1, end.GetAt(depth)) : node.DataCount - 1;

                for (int i = endIndex; i >= startIndex; i--)
                {
                    var child = node.GetAt(i, true /* realizeChild */);
                    if (child != null)
                    {
                        var childPath = currentPath.CloneWithChildIndex(i);
                        pendingNodes.Add(new TreeWalkNodeInfo(child, childPath, node));
                    }
                }
            });

            // From the start index path, do a depth first walk as long as the
            // current path is less than the end path.
            while (pendingNodes.Count > 0)
            {
                var info = pendingNodes.Last();
                pendingNodes.RemoveLast();
                int  depth       = info.Path.GetSize();
                bool isStartPath = IsSubSet(start, info.Path);
                bool isEndPath   = IsSubSet(end, info.Path);
                int  startIndex  = depth < start.GetSize() && isStartPath?start.GetAt(depth) : 0;

                int endIndex = depth < end.GetSize() && isEndPath?end.GetAt(depth) : info.Node.DataCount - 1;

                for (int i = endIndex; i >= startIndex; i--)
                {
                    var child = info.Node.GetAt(i, true /* realizeChild */);
                    if (child != null)
                    {
                        var childPath = info.Path.CloneWithChildIndex(i);
                        pendingNodes.Add(new TreeWalkNodeInfo(child, childPath, info.Node));
                    }
                }

                nodeAction(info);

                if (info.Path.CompareTo(end) == 0)
                {
                    // We reached the end index path. stop iterating.
                    break;
                }
            }
        }
Beispiel #20
0
 public TreeWalkNodeInfo(SelectionNode node, IndexPath indexPath, SelectionNode parent)
 {
     Node       = node;
     Path       = indexPath;
     ParentNode = parent;
 }
 internal SelectionModelChildrenRequestedEventArgs(object source, IndexPath sourceIndexPath, bool throwOnAccess)
 {
     Initialize(source, sourceIndexPath, throwOnAccess);
 }
Beispiel #22
0
 public SelectedItemInfo(SelectionNode node, IndexPath path)
 {
     Node = new WeakReference <SelectionNode>(node);
     Path = path;
 }