Example #1
0
        /// <summary>
        /// Populates the display list with the provided data elements.
        /// </summary>
        ///
        /// <param name="data">The data to use when populating the list.</param>
        ///
        /// <remarks>
        /// Any existing view elements will be removed from the list before populating
        /// the list with <paramref name="data"/>. One display element is added for each
        /// element in <paramref name="data"/>, and the display element is automatically
        /// populated with the corresponding data element. Any existing display elements
        /// will be reused in order to reduce object instantiation costs.
        /// </remarks>
        public void Populate(List <D> data)
        {
            _data = data ?? throw new ArgumentNullException();

            // "Remove" all active elements.
            foreach (var element in this)
            {
                OnElementRemoved(element);
                ElementRemoved?.Invoke(element);
            }

            // Add a display element for every data element in the list.
            for (int index = 0; index < _data.Count; index += 1)
            {
                var element = GetOrAddElement(index);
                element.Populate(_data[index]);

                OnElementAdded(element);
                ElementAdded?.Invoke(element);
            }

            // Disable any leftover display elements that were previously active in the
            // list but are no longer needed.
            for (int index = _data.Count; index < _elements.Count; index += 1)
            {
                _elements[index].gameObject.SetActive(false);
            }

            OnPopulated();
        }
Example #2
0
        internal bool AddElement(GraphElement element)
        {
            Ensure.Argument.NotNull(element, nameof(element));

            var owner = element.Owner;

            if (owner != null)
            {
                if (owner == this)
                {
                    return(false);
                }

                throw new InvalidOperationException(
                          "Attempt to add element which belongs to another graph to current graph.");
            }

            bool added = _elements.Add(element);

            Debug.Assert(added);
            element._OnAddedToGraph(this);

            OnElementAdded(element);
            ElementAdded?.Invoke(this, element);

            return(true);
        }
Example #3
0
        public void AddingRecursively(Node <T> node, T data)
        {
            switch (ComparerT.Compare(node.Data, data) <= 0)
            {
            case true:
                if (node.Right == null)
                {
                    node.Right = new Node <T>(data);
                    Count++;
                    TreeEventArgs <T> args = new TreeEventArgs <T>(data, $"Element {data} was added into the tree");
                    ElementAdded?.Invoke(this, args);
                }
                else
                {
                    AddingRecursively(node.Right, data);
                }
                break;

            case false:
                if (node.Left == null)
                {
                    node.Left = new Node <T>(data);
                    Count++;
                    TreeEventArgs <T> args = new TreeEventArgs <T>(data, $"Element {data} was added into the tree");
                    ElementAdded?.Invoke(this, args);
                }
                else
                {
                    AddingRecursively(node.Left, data);
                }
                break;
            }
        }
Example #4
0
 private void OnElementAdded(System.Drawing.PointF pointF)
 {
     if (ElementAdded != null)
     {
         ElementAdded.Invoke(this, pointF);
     }
 }
Example #5
0
        public void AddNew(TModel modelObject)
        {
            var modelObjectKeyValue = KeyAttribute.GetKeyValue(modelObject);

            AssertKeyNotExists(modelObjectKeyValue);
            UpdateCollection(modelObjectKeyValue, modelObject);
            ElementAdded?.Invoke(modelObject);
        }
Example #6
0
        /// <summary>
        /// Adds element to the tree according to comparer
        /// </summary>
        /// <param name="item">Object that should be added in tree</param>
        /// <exception cref="ArgumentNullException">Thrown if parameter was null</exception>
        public void Add(T item)
        {
            if (item is null)
            {
                throw new ArgumentNullException(nameof(item));
            }
            var newNode = new TreeNode <T>(_comparer)
            {
                Value = item
            };
            TreeNode <T> before = null;
            var          after  = _head;

            while (after != null)
            {
                before = after;
                if (_comparer.Compare(after.Value, item) > 0)
                {
                    after = after.Left;
                }
                else if (_comparer.Compare(after.Value, item) < 0)
                {
                    after = after.Right;
                }
                else if (_comparer.Compare(item, after.Value) == 0)
                {
                    while (!(after is null))
                    {
                        if (after.Right is null)
                        {
                            after.Right = newNode;
                            Count++;
                            ElementAdded?.Invoke(this, new TreeEventArgs <T>(item, "Aded"));
                            return;
                        }
                        after = after.Right;
                    }
                }
            }

            if (_head == null)
            {
                _head = newNode;
            }
            else
            {
                if (before.CompareTo(item) > 0)
                {
                    before.Left = newNode;
                }
                else
                {
                    before.Right = newNode;
                }
            }
            ElementAdded?.Invoke(this, new TreeEventArgs <T>(item, "Aded"));
            Count++;
        }
        public void Add(T element)
        {
            if (content.Contains(element))
            {
                throw new Exception($"Container already contains {element}");
            }

            content.Add(element);
            ElementAdded?.Invoke(this, new ElementEventArgs <T>(element));
        }
Example #8
0
        /// <summary>
        /// Adds an element to the hash set.
        /// </summary>
        public void Add(T element)
        {
            var contains = hashSet.Contains(element);

            ((ICollection <T>)hashSet).Add(element);
            if (!contains)
            {
                ElementAdded?.Invoke(this, new ElementAddedEventArgs <T>(element));
            }
        }
Example #9
0
        UIElement AddElementRaw(Panel panel, UIElement prefab, IAccessor accessor)
        {
            var newElement = GameObject.Instantiate(prefab, elementContainer);

            newElement.Panel           = panel;
            newElement.FieldAccesorRaw = accessor;
            currentElements.Add(newElement);
            ElementAdded?.Invoke(newElement);
            return(newElement);
        }
        private void OnElementAdded(ElementAdded e)
        {
            var element = GetElement(e.Item.Element);

            if (element != null)
            {
                element.Update();
            }
            else
            {
                Add(e.Item);
            }
        }
Example #11
0
 public virtual void Add(Set <T> elem)
 {
     if (elems.Contains(elem))
     {
         return;
     }
     if (BeforeElementAdded != null && !BeforeElementAdded.Invoke(elem))
     {
         return;
     }
     elems.Add(elem);
     ElemCount = elems.OfType <SetElement <T> >().Count();
     ElementAdded?.Invoke(elem);
 }
Example #12
0
        public Type Add(Type element)
        {
            var returnVal = default(Type);

            lock (buffer)
            {
                buffer.AddFirst(element);
                if (buffer.Count > MaxSize)
                {
                    returnVal = buffer.Last.Value;
                    buffer.RemoveLast();
                }
            }
            ElementAdded.Fire(element);
            return(returnVal);
        }
Example #13
0
 /// <summary>
 /// Adds element to the tree according to comparer
 /// </summary>
 /// <param name="item">Object that should be added in tree</param>
 /// <exception cref="ArgumentNullException">Thrown if parameter was null</exception>
 public void Add(T item)
 {
     if (item is null)
     {
         throw new ArgumentNullException("item", "item can`t be null");
     }
     if (Root is null)
     {
         Root = new Node <T>(item);
         Count++;
         TreeEventArgs <T> args = new TreeEventArgs <T>(item, $"Element {item} was added into the tree(Root)");
         ElementAdded?.Invoke(this, args);
     }
     else
     {
         AddingRecursively(Root, item);
     }
 }
        /// <summary>
        /// Adds element to the tree according to comparer
        /// </summary>
        /// <param name="item">Object that should be added in tree</param>
        /// <exception cref="ArgumentNullException">Thrown if parameter was null</exception>
        public void Add(T item)
        {
            if (item is null)
            {
                throw new ArgumentNullException("item");
            }

            var node     = new BinaryTreeNode <T>(item);
            var EventArg = new TreeEventArgs <T>(item, "Item has been added");

            if (root == null)
            {
                root = node;
            }
            else
            {
                BinaryTreeNode <T> current = root, parent = null;

                while (current != null)
                {
                    parent = current;
                    if (Comparer.Compare(item, current.Value) < 0)
                    {
                        current = current.Left;
                    }
                    else
                    {
                        current = current.Right;
                    }
                }

                if (Comparer.Compare(item, parent.Value) < 0)
                {
                    parent.Left = node;
                }
                else
                {
                    parent.Right = node;
                }
            }
            Count++;
            ElementAdded?.Invoke(this, EventArg);
        }
Example #15
0
 public void Add(T element)
 {
     List.Add(element);
     ElementAdded.Invoke(element);
 }
Example #16
0
 private void NotifyElementAdded(T item)
 {
     ElementAdded?.Invoke(item);
     CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
 }
Example #17
0
 protected void OnAdded(SvgElement element)
 {
     ElementAdded?.Invoke(this._document, new SvgElementEventArgs {
         Element = element
     });
 }
Example #18
0
 internal void OnLayoutElementAdded(LayoutElement element)
 {
     ElementAdded?.Invoke(this, new LayoutElementEventArgs(element));
 }