示例#1
0
        protected void ResetViewOrder(ObjectCollection collection)
        {
            int index = 0;

            foreach (var item in collection)
            {
                // get view
                GameObject view;
                if (!bindingDictionary.TryGetValue(item, out view))
                {
                    Debug.LogErrorFormat("Unknown item {0}", item);
                    continue;
                }

                view.transform.SetSiblingIndex(index++);
            }
        }
示例#2
0
        protected void AddItems(ObjectCollection collection)
        {
            // create view items
            foreach (var item in collection)
            {
                GameObject view;
                if (bindingDictionary.TryGetValue(item, out view))
                {
                    if (viewReferenceCountDictionary == null)
                    {
                        // lazy initialization
                        InitViewReferenceCount();
                    }

                    // increase reference count
                    viewReferenceCountDictionary[view]++;

                    continue;
                }

                // create view
                view = factory.CreateItemView(item);

                // set source
                var dataContext = view.GetComponent <IDataContext>();
                dataContext.Source = item;

                // add to dictionary
                bindingDictionary.Add(item, view);

                if (viewReferenceCountDictionary != null)
                {
                    // set reference count to 1
                    viewReferenceCountDictionary.Add(view, 1);
                }
            }

            if (viewReferenceCountDictionary != null)
            {
                Assert.AreEqual(bindingDictionary.Count, viewReferenceCountDictionary.Count);
            }
        }
示例#3
0
        protected virtual void AddItems(ObjectCollection collection)
        {
            foreach (var item in collection)
            {
                // get TSource
                var source = GetSource(item);

                TTarget target;
                if (sourceToTargetMap.TryGetValue(source, out target))
                {
                    if (referenceCountDictionary == null)
                    {
                        // lazy initialization
                        InitReferenceCount();
                    }

                    // increase reference count
                    referenceCountDictionary[target]++;
                    continue;
                }

                // call create
                target = CreateTarget(source);

                // add it
                targetCollection.Add(target);
                sourceToTargetMap.Add(source, target);

                if (referenceCountDictionary != null)
                {
                    // set reference count to 1
                    referenceCountDictionary.Add(target, 1);
                }
            }

            if (referenceCountDictionary != null)
            {
                Assert.AreEqual(sourceToTargetMap.Count, referenceCountDictionary.Count);
            }
        }
示例#4
0
        /// <summary>
        /// Begins synchronizing.
        /// </summary>
        public void BeginSync()
        {
            if (isSyncing)
            {
                // already started
                return;
            }

            // register event
            sourceCollection.CollectionChanged += OnSourceCollectionChanged;

            // clear targets
            ClearItems();

            // add all
            var items = new ObjectCollection(sourceCollection);

            AddItems(items);

            // set flag
            isSyncing = true;
        }
示例#5
0
 protected virtual void MoveItems(ObjectCollection collection)
 {
     // do nothing
 }
示例#6
0
 protected virtual void ReplaceItems(ObjectCollection oldItems, ObjectCollection newItems)
 {
     RemoveItems(oldItems);
     AddItems(newItems);
 }
示例#7
0
        protected void ResetViewOrder(IEnumerable items)
        {
            var collection = new ObjectCollection(items);

            ResetViewOrder(collection);
        }
示例#8
0
 protected void MoveItems(ObjectCollection collection)
 {
     ResetViewOrder(collection);
 }
示例#9
0
        protected void AddItems(IEnumerable items)
        {
            var collection = new ObjectCollection(items);

            AddItems(collection);
        }