コード例 #1
0
        /// <summary>
        ///     The implementation of VsShell.ISelectionContainer.SelectObjects in
        ///     ModelingWindowPane calls DoSelectObjects()
        ///     - base calls to DiagramDocView : ModelingDocView : ModelingWindowPane
        ///     if (this.CurrentDesigner != null) -> sets selection in the current designer
        ///     else calls to ModelingWindowPane which is a no-op
        ///     This seems to only be called when the user chooses an item from the
        ///     drop down box at the top of the properties screen
        /// </summary>
        /// <returns></returns>
        protected override void DoSelectObjects(uint count, object[] objects, uint flags)
        {
            // We have to reverse the logic of the GetSelectX fn above; that is, convert the
            // array of our ItemDescriptors back into an array of Dsl ModelElements before
            // calling the base impl; the base impl will then select the shape
            var  objectsSelected         = new ArrayList();
            var  selectedModelObjects    = new List <EFObject>();
            uint nonPropertyObjectsCount = 0;

            if (count > 0)
            {
                foreach (var o in objects)
                {
                    var typeDesc = o as ObjectDescriptor;
                    Debug.Assert(typeDesc != null, "Something unexpected was selected");
                    if (typeDesc != null)
                    {
                        selectedModelObjects.Add(typeDesc.WrappedItem);

                        // Properties do not have a corresponding ShapeElement; the instance of the DomainClass is just an item
                        // within the ElementListCompartment. Since this override only accepts a list of ShapeElements, we will
                        // have to use the DSLDesignerNavigationHelper to create a DiagramItem that uniquely identifies the
                        // list compartment item and select that.
                        if (typeDesc.WrappedItem is PropertyBase)
                        {
                            DSLDesignerNavigationHelper.NavigateTo(typeDesc.WrappedItem);
                        }
                        else
                        {
                            // For all other EFObjects, we can attempt to get a ShapeElement
                            nonPropertyObjectsCount++;
                            var dslElem  = XRef.GetExisting(typeDesc.WrappedItem);
                            var presElem = dslElem as DslDiagrams.PresentationElement;
                            if (presElem == null)
                            {
                                var shapes =
                                    DslDiagrams.PresentationViewsSubject.GetPresentation(dslElem);

                                // just select the first shape for this item
                                if (shapes != null &&
                                    shapes.Count > 0)
                                {
                                    presElem = shapes[0];
                                }
                            }

                            Debug.Assert(presElem != null, "Why couldn't we find the shape for this ModelElement?");

                            if (presElem != null)
                            {
                                objectsSelected.Add(presElem);
                            }
                        }
                    }
                }

                Debug.Assert(
                    nonPropertyObjectsCount == objectsSelected.Count,
                    "nonPropertyObjectsCount(" + nonPropertyObjectsCount + ") != objectsSelected.Count (" + objectsSelected.Count + ")");
            }

            // update the selection for the Entity Designer in case anyone else is interested
            Context.Items.SetValue(new EntityDesignerSelection(selectedModelObjects));

            if (nonPropertyObjectsCount > 0 &&
                nonPropertyObjectsCount == objectsSelected.Count)
            {
                // If we didn't encounter any property descriptors and the number of those descriptors equals the objects selected,
                // then we can pass this on to the base implementation to perform the selection
                var objectsToSelect = new object[objectsSelected.Count];
                objectsSelected.CopyTo(objectsToSelect, 0);
                base.DoSelectObjects(nonPropertyObjectsCount, objectsToSelect, flags);
            }
            else if (nonPropertyObjectsCount != objectsSelected.Count)
            {
                // We should have found objects to select from all the non-property descriptors. If for some reason we didn't,
                // then we pass this onto the base implementation
                base.DoSelectObjects(count, objects, flags);
            }
        }
コード例 #2
0
        /// <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);
        }