Beispiel #1
0
        public virtual IPartViewJunction GetParts()
        {
            if (Part is IPartViewNode)
            {
                var junction = new AdvancedPartJunction();
                junction.Add(Part);
                return(junction);
            }

            return((IPartViewJunction)Part);
        }
Beispiel #2
0
 public PartLoader(IPartView current, AdvancedPartJunction junction)
     : this(current)
 {
     Junction = junction;
 }
Beispiel #3
0
 public PartLoader(IPartView current)
 {
     Current  = current;
     Junction = null;
 }
Beispiel #4
0
        /// <summary>
        /// Add a new part to the adapter.
        /// </summary>
        /// <param name="type"></param>
        public virtual void Add(JunctionType type)
        {
            var toAdd = CreateNode(null);

            if (toAdd == null)
            {
                return;
            }

            AddHandlers(toAdd);

            // if Parts null, just add node
            if (Part == null)
            {
                Part = toAdd;
            }
            else
            {
                // if we have a selected part, add as a sibling to this, otherwise add it as a sibling to the last item
                var sibling = SelectedPart;
                if (sibling == null)
                {
                    sibling = Part;
                }

                // if the sibling has a container and it's the same type of junction, add it to the same container
                AdvancedPartJunction container = null;
                if (sibling.Container != null && sibling.Container.Type == type)
                {
                    container = sibling.Container;
                }
                else if (sibling == Part && sibling is AdvancedPartJunction && ((AdvancedPartJunction)sibling).Type == type)
                {
                    container = (AdvancedPartJunction)sibling;
                }

                // no parent? (either no container, or the sibling's container is a different junction type)
                if (container == null)
                {
                    container = CreateJunction(type);
                    if (Part == sibling) // root case
                    {
                        Part = container;
                    }
                    else if (sibling.Container != null) // otherwise, replace index in original container
                    {
                        // it seems replacing the index directly messes with UI data templating
                        // so if we remove it and insert the container at the old items location, it works
                        var c     = sibling.Container;
                        var index = c.IndexOf(sibling);
                        c.Remove(sibling);
                        c.Insert(index, container);
                    }
                    container.Add(sibling);
                    AddHandlers(container);
                }

                // and finally, add the new node to the junction
                container.Parts.Add(toAdd);
            }

            toAdd.IsSelected = true;
        }