示例#1
0
        public override TreePath PathFromNode(object aNode)
        {
            TreePath tp = new TreePath();

            if ((aNode == null) || (Items == null) || (Items.Count == 0))
            {
                return(tp);
            }

            if (RespectHierarchy == false)
            {
                int i = Items.IndexOf(aNode);
                if (i > -1)
                {
                    tp.AppendIndex(i);
                }
                return(tp);
            }
            int[] idx = HierarchicalList.IndexOf(Items, aNode);
            if (idx != null)
            {
                foreach (int j in idx)
                {
                    tp.AppendIndex(j);
                }
            }
            return(tp);
        }
示例#2
0
        public override bool IterParent(out TreeIter aParent, TreeIter aChild)
        {
            aParent = TreeIter.Zero;
            object node = NodeFromIter(aChild);

            if (node == null)
            {
                return(false);
            }
            if (RespectHierarchy == true)
            {
                TreePath tp = PathFromNode(node);
                if ((tp.Indices == null) || (tp.Indices.Length <= 1))
                {
                    return(false);
                }
                if (tp.Up() == false)
                {
                    return(false);
                }
                object o = HierarchicalList.Get(Items, tp.Indices);
                if (o != null)
                {
                    aParent = IterFromNode(o);
                    return(true);
                }
            }
            return(false);
        }
        public object this [int[] aIdx] {
            get {
                if ((aIdx == null) || (aIdx.Length == 0))
                {
                    throw new NullReferenceException("Hierarchical index (int[]) can't be null or empty");
                }

                if (IsFiltered == false)
                {
                    if (TypeValidator.IsCompatible(ParentView.GetType(), typeof(IObservableList)) == true)
                    {
                        return((ParentView as IObservableList)[aIdx]);
                    }
                    else
                    {
                        return(HierarchicalList.Get((IList)ParentView, aIdx));
                    }
                }

                if ((aIdx[0] < 0) || (aIdx[0] >= Count))
                {
                    throw new IndexOutOfRangeException(string.Format("Index {0} is out of range", aIdx.PathToString()));
                }

                return(HierarchicalList.Get(this, aIdx));
            }
        }
        protected override void ElementChangedInMaster(object aList, int[] aIdx)
        {
            if (IsFiltered == false)
            {
                OnElementChanged(aIdx);
                return;
            }

            // Check if level is higher
            if (aIdx.Length > 1)
            {
                if (itemVisibility[aIdx[0]] == false)
                {
                    return;
                }
                int[] lidx = aIdx.CopyPath();
                lidx[0] = localIndex.IndexOf(aIdx[0]);
                OnElementChanged(lidx);
                lidx = null;
                return;
            }

            // Correct local index
            bool   prevState = itemVisibility[aIdx[0]];
            object obj       = HierarchicalList.Get((IList)ParentView, aIdx);
            bool   valid     = OnIsVisibleInFilter(obj);

            itemVisibility[aIdx[0]] = valid;
            if ((prevState == valid) && (valid == false))
            {
                return;
            }

            int[] idx = aIdx.CopyPath();
            if ((prevState == valid) && (valid == true))
            {
                idx[0] = localIndex.IndexOf(aIdx[0]);
                OnElementChanged(idx);
                return;
            }

            if (valid == true)
            {
                idx[0] = localIndex.SortedAdd(aIdx[0]);
                OnElementAdded(idx);
                OnPropertyChanged("Count");
            }
            else
            {
                idx[0] = localIndex.IndexOf(aIdx[0]);
                localIndex.Remove(aIdx[0]);
                OnElementRemoved(idx, obj);
                OnPropertyChanged("Count");
            }
            idx = null;
        }
示例#5
0
        public override bool IterNext(ref TreeIter aIter)
        {
            object node = NodeFromIter(aIter);

            if ((node == null) || (Items == null) || (Items.Count == 0))
            {
                return(false);
            }
            if (RespectHierarchy == false)
            {
                object lastNode;
                //Check for "Collection was modified" Exception
                try {
                    lastNode = cachedEnumerator != null ? cachedEnumerator.Current : null;
                } catch (InvalidOperationException ex) {
                    lastNode = null;
                }
                if (lastNode == node)
                {
                    return(GetCacheNext(ref aIter));
                }
                else
                {
                    cachedEnumerator = Items.GetEnumerator();
                    while (cachedEnumerator.MoveNext())
                    {
                        if (node == cachedEnumerator.Current)
                        {
                            return(GetCacheNext(ref aIter));
                        }
                    }
                    cachedEnumerator = null;
                    return(false);
                }
            }
            else
            {
                int[] path = HierarchicalList.IndexOf(Items, node);                  //FIXME Need optimaze access like RespectHierarchy == false
                if (path == null)
                {
                    return(false);
                }
                path [path.Length - 1] += 1;
                object o = HierarchicalList.Get(Items, path);
                if (o == null)
                {
                    return(false);
                }
                aIter = IterFromNode(o);
                return(true);
            }
        }
        protected override void ElementAddedIntoMaster(object aList, int[] aIdx)
        {
            if (IsFiltered == false)
            {
                OnElementAdded(aIdx);
                OnPropertyChanged("Count");
                return;
            }

            // Correct local index
            object obj   = HierarchicalList.Get((IList)ParentView, aIdx);
            bool   valid = OnIsVisibleInFilter(obj);

            if (aIdx.Length == 1)
            {
                itemVisibility.SafeInsert(aIdx[0], valid);
                if (valid == true)
                {
                    localIndex.SortedAdd(aIdx[0]);
                }
            }

            // Handle messaging
            int[] idx = aIdx.CopyPath();
            idx[0] = localIndex.IndexOf(aIdx[0]);
            if (aIdx.Length > 1)
            {
                if (OnIsVisibleInFilter(obj) == false)
                {
                    return;
                }
                if (idx[0] != -1)
                {
                    OnElementAdded(idx);
                }
                idx = null;
                return;
            }
            if (idx[0] > -1)
            {
                for (int i = 0; i < localIndex.Count; i++)
                {
                    if (localIndex[i] > aIdx[0])
                    {
                        localIndex[i]++;
                    }
                }
                OnElementAdded(idx);
                OnPropertyChanged("Count");
            }
            idx = null;
        }
示例#7
0
 public override object GetNodeAtPath(TreePath aPath)
 {
     if (Items == null)
     {
         return(null);
     }
     if (aPath.Indices.Length == 0)
     {
         return(null);
     }
     if (RespectHierarchy == true)
     {
         return(HierarchicalList.Get(Items, aPath.Indices));
     }
     if (aPath.Indices [0] < 0 || aPath.Indices [0] >= Items.Count)
     {
         return(null);
     }
     return(Items [aPath.Indices [0]]);
 }
 /// <summary>
 /// Resolves any object in this list, supports hierarchy
 /// </summary>
 /// <param name="aIdx">
 /// Hierarchical path <see cref="System.Int32"/>
 /// </param>
 public object this [int[] aIdx] {
     get { return(HierarchicalList.Get(this, aIdx)); }
 }