Esempio n. 1
0
        /// <summary>
        /// Performs custom actions on validation Ending events.
        /// If resources referenced are not available in the same package,
        /// they are cloned and added to the package.</summary>
        /// <param name="sender">Validation context</param>
        /// <param name="e">Event args</param>
        protected override void OnEnding(object sender, System.EventArgs e)
        {
            foreach (ChildEventArgs refInsert in m_referenceInserts)
            {
                UIPackage dstPackage = GetPackage(refInsert.Parent);
                UIRef     uiRef      = refInsert.Child.As <UIRef>();
                DomNode   resource   = uiRef.UIObject.DomNode;
                UIPackage srcPackage = GetPackage(resource);

                if (dstPackage != srcPackage)
                {
                    DomNode[] copies    = DomNode.Copy(new DomNode[] { resource });
                    UIObject  refObject = copies[0].As <UIObject>();
                    uiRef.UIObject = refObject;

                    // add the cloned ref object to the package in the first child array
                    //  of compatible type
                    foreach (ChildInfo childInfo in dstPackage.DomNode.Type.Children)
                    {
                        if (childInfo.Type.IsAssignableFrom(refObject.DomNode.Type))
                        {
                            dstPackage.DomNode.GetChildList(childInfo).Add(refObject.DomNode);
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new UIRef adapter and underlying DomNode</summary>
        /// <param name="uiObj">UIObject being referenced</param>
        /// <returns>New UIRef adapter</returns>
        public static UIRef New(UIObject uiObj)
        {
            DomNode node  = new DomNode(UISchema.UIRefType.Type);
            UIRef   uiRef = node.As <UIRef>();

            uiRef.UIObject = uiObj;
            return(uiRef);
        }
Esempio n. 3
0
        /// <summary>
        /// Performs custom actions after a child is inserted into the DOM subtree</summary>
        /// <param name="sender">Sender (root DOM node)</param>
        /// <param name="e">Child event args</param>
        protected override void OnChildInserted(object sender, ChildEventArgs e)
        {
            // if it's a ref, make sure the referenced resource is in this package
            UIRef uiRef = e.Child.As <UIRef>();

            if (uiRef != null)
            {
                m_referenceInserts.Add(e);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Gets item's display information</summary>
        /// <param name="item">Item being displayed</param>
        /// <param name="info">Item info, to fill out</param>
        public void GetInfo(object item, ItemInfo info)
        {
            DomNode node = item as DomNode;

            if (node != null)
            {
                if (node.Type == UISchema.UIRefType.Type)
                {
                    info.ImageIndex = info.GetImageList().Images.IndexOfKey(Resources.RefImage);
                    string   label    = string.Empty;
                    UIRef    uiRef    = node.As <UIRef>();
                    UIObject uiTarget = uiRef.UIObject;
                    if (uiTarget != null)
                    {
                        label = uiTarget.Name;
                    }

                    info.Label = "[" + label + "]";
                }
                else if (node.Is <Curve>())
                {
                    Curve cv = node.Cast <Curve>();
                    info.Label      = string.IsNullOrWhiteSpace(cv.DisplayName) ? cv.Name : cv.DisplayName;
                    info.ImageIndex = info.GetImageList().Images.IndexOfKey(Resources.CurveImage);
                }
                else
                {
                    NodeTypePaletteItem paletteItem = node.Type.GetTag <NodeTypePaletteItem>();
                    if (paletteItem != null)
                    {
                        info.ImageIndex = info.GetImageList().Images.IndexOfKey(paletteItem.ImageName);
                    }

                    info.Label = node.GetId();
                }

                info.IsLeaf = !GetChildren(item).Any();
            }
            else
            {
                EmptyRef emptyRef = item as EmptyRef;
                if (emptyRef != null)
                {
                    info.Label      = "Ref";
                    info.ImageIndex = info.GetImageList().Images.IndexOfKey(Resources.RefEmptyImage);
                    info.IsLeaf     = true;
                }
            }

            if (string.IsNullOrEmpty(info.Label))
            {
                throw new ArgumentException("info.lable");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Gets item's display information</summary>
        /// <param name="item">Item being displayed</param>
        /// <param name="info">Item info, to fill out</param>
        public void GetInfo(object item, ItemInfo info)
        {
            DomNode node = item as DomNode;

            if (node != null)
            {
                if (node.Type == UISchema.UIRefType.Type)
                {
                    info.ImageIndex = info.GetImageList().Images.IndexOfKey(Resources.RefImage);
                    string   label    = string.Empty;
                    UIRef    uiRef    = node.As <UIRef>();
                    UIObject uiTarget = uiRef.UIObject;
                    if (uiTarget != null)
                    {
                        label = uiTarget.Name;
                    }

                    info.Label = "[" + label + "]";
                }
                else
                {
                    NodeTypePaletteItem paletteItem = node.Type.GetTag <NodeTypePaletteItem>();
                    if (paletteItem != null)
                    {
                        info.ImageIndex = info.GetImageList().Images.IndexOfKey(paletteItem.ImageName);
                        info.Label      = node.GetId();
                    }
                }

                info.IsLeaf = !Enumerable.Any(GetChildren(item));
                return;
            }
            else
            {
                EmptyRef emptyRef = item as EmptyRef;
                if (emptyRef != null)
                {
                    info.Label      = "Ref";
                    info.ImageIndex = info.GetImageList().Images.IndexOfKey(Resources.RefEmptyImage);
                    info.IsLeaf     = true;
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Inserts a reference to an object of given type using a transaction. Called by automated scripts during testing.</summary>
        /// <typeparam name="T">Type of object to insert</typeparam>
        /// <param name="insertingObject">DomNode that contains inserted object</param>
        /// <param name="insertionParent">Parent where object is inserted</param>
        /// <returns>Inserted object</returns>
        public T InsertAsRef <T>(DomNode insertingObject, DomNode insertionParent) where T : class
        {
            ChildInfo childInfo = GetChildInfo(insertionParent, UISchema.UIRefType.Type);
            EmptyRef  emptyRef  = new EmptyRef(insertionParent, childInfo);

            SetInsertionParent(emptyRef);

            insertingObject.SetAttribute(UISchema.UIType.nameAttribute, typeof(T).Name);
            DataObject dataObject = new DataObject(new object[] { insertingObject });

            ITransactionContext transactionContext = this.As <ITransactionContext>();

            transactionContext.DoTransaction(
                delegate
            {
                Insert(dataObject);
            }, "Scripted Insert Object");

            UIRef   uiRef   = emptyRef.Parent.GetChild(childInfo).As <UIRef>();
            DomNode newNode = uiRef.DomNode.As <DomNode>();

            return(newNode.As <T>());
        }
Esempio n. 7
0
        /// <summary>
        /// Inserts the data object into the context</summary>
        /// <param name="insertingObject">Data to insert</param>
        public void Insert(object insertingObject)
        {
            IDataObject dataObject = (IDataObject)insertingObject;

            object[] items = dataObject.GetData(typeof(object[])) as object[];
            if (items == null || items.Length == 0)
            {
                return;
            }

            IEnumerable <DomNode> childNodes = items.AsIEnumerable <DomNode>();
            // if no items are parented, then we should clone the items, which must be from the clipboard
            bool fromScrap = true;

            foreach (DomNode child in childNodes)
            {
                if (child.Parent != null)
                {
                    fromScrap = false;
                    break;
                }
            }
            if (fromScrap)
            {
                childNodes = DomNode.Copy(childNodes);
                // inited extensions for copied DomNodes
                foreach (DomNode child in childNodes)
                {
                    child.InitializeExtensions();
                }
            }

            DomNode parent = m_insertionParent.As <DomNode>();

            if (parent != null)
            {
                foreach (DomNode child in childNodes)
                {
                    ChildInfo childInfo = GetChildInfo(parent, child.Type);
                    if (childInfo != null)
                    {
                        if (childInfo.IsList)
                        {
                            IList <DomNode> list = parent.GetChildList(childInfo);
                            list.Add(child);
                        }
                        else
                        {
                            parent.SetChild(childInfo, child);
                        }
                    }
                }
            }
            else
            {
                EmptyRef emptyRef = m_insertionParent as EmptyRef;
                if (emptyRef != null)
                {
                    foreach (DomNode child in childNodes)
                    {
                        UIRef uiRef = UIRef.New(child.As <UIObject>());
                        emptyRef.Parent.SetChild(emptyRef.ChildInfo, uiRef.DomNode);
                    }
                }
            }
        }