Esempio n. 1
0
 protected override ObjectDescriptor GetObjectDescriptor(EFElement obj, EditingContext editingContext)
 {
     return(PropertyWindowViewModel.GetObjectDescriptor(obj, editingContext, true));
 }
        /// <summary>
        ///     This uses the XRef in our context to find the Model item that is the basis for
        ///     each DSL object in the selection collection.  For each Model item, we get the correct
        ///     item descriptor and create a new selection array of these.
        /// </summary>
        /// <param name="objects"></param>
        /// <returns></returns>
        private ArrayList ConvertDslModelElementArrayToItemDescriptors(object[] objects, bool gettingAllObjects)
        {
            // save off this reference
            var selectedDesignerObjects = objects;

            // create a new array to hold the item descriptors
            var selectedModelObjects           = new List <EFObject>();
            var selectedModelObjectDescriptors = new ArrayList();

            foreach (var o in selectedDesignerObjects)
            {
                DslModeling.ModelElement dslElem = null;
                var elemList = o as DslDiagrams.ElementListCompartment;
                var presElem = o as DslDiagrams.PresentationElement;
                if (elemList != null)
                {
                    // if the user selects a compartment element, we want to display the entity-type and the shape property.
                    if (elemList.IsNestedChild &&
                        elemList.ParentShape != null)
                    {
                        presElem = elemList.ParentShape;
                        dslElem  = presElem.ModelElement;
                    }
                    else
                    {
                        // they have selected one of the compartments, probably wanting to show
                        // the right-click context menu
                        continue;
                    }
                }
                else if (presElem != null)
                {
                    // if this is a shape, gets it corresponding DSL object
                    dslElem = presElem.ModelElement;
                }
                else
                {
                    // o is a non-shape
                    dslElem = o as DslModeling.ModelElement;
                }

                // there might be no ModelElement corresponding to the selected object
                if (dslElem != null)
                {
                    EFObject modelElem;
                    // If an EntityType is selected in DSL canvas, we want to show the property of the EntityTypeShape.
                    if (dslElem is EntityType &&
                        presElem != null)
                    {
                        modelElem = XRef.GetExisting(presElem);
                    }
                    else
                    {
                        modelElem = XRef.GetExisting(dslElem);
                    }
                    // model element might not be yet created
                    if (modelElem != null)
                    {
                        selectedModelObjects.Add(modelElem);
                        selectedModelObjectDescriptors.Add(PropertyWindowViewModel.GetObjectDescriptor(modelElem, Context, true));
                    }
                }
            }

            if (gettingAllObjects == false)
            {
                // update the selection for the Entity Designer in case anyone else is interested
                if (Context != null &&
                    Context.Items != null)
                {
                    Context.Items.SetValue(new EntityDesignerSelection(selectedModelObjects));
                }
            }

            return(selectedModelObjectDescriptors);
        }