예제 #1
0
        /// <summary>
        /// Gets the selected elements.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <returns></returns>
        public static IList <object> GetSelectedElements(IServiceProvider provider)
        {
            ModelingDocView docView = DesignerHelper.GetModelingDocView(provider);

            if (docView != null)
            {
                if (docView.SelectionCount > 0)
                {
                    IList <object> elements = new List <object>(docView.SelectionCount);

                    foreach (object component in docView.GetSelectedComponents())
                    {
                        ShapeElement selectedShape   = component as ShapeElement;
                        ModelElement selectedElement = component as ModelElement;
                        if (selectedShape != null)
                        {
                            elements.Add(selectedShape.ModelElement);
                        }
                        else if (selectedElement != null)
                        {
                            elements.Add(selectedElement);
                        }
                    }

                    return(elements);
                }
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Gets the selected element.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <returns></returns>
        public static ModelElement GetSelectedElement(IServiceProvider provider)
        {
            ModelingDocView docView = DesignerHelper.GetModelingDocView(provider);

            if (docView != null)
            {
                if (docView.SelectionCount == 1)
                {
                    foreach (object component in docView.GetSelectedComponents())
                    {
                        ShapeElement selectionShape   = component as ShapeElement;
                        ModelElement selectionElement = component as ModelElement;

                        if (selectionShape != null)
                        {
                            return(selectionShape.ModelElement);
                        }
                        else if (selectionElement != null)
                        {
                            return(selectionElement);
                        }
                    }
                }
            }

            return(null);
        }
예제 #3
0
        public void OnDocumentSelectionChanged(object sender, EventArgs e)
        {
            if (sender != null)
            {
                ModelingDocView view = sender as ModelingDocView;
                if (view != null)
                {
                    ICollection selection = view.GetSelectedComponents();
                    if (selection.Count == 1)
                    {
                        IEnumerator enumerator = selection.GetEnumerator();
                        enumerator.MoveNext();
                        ClassShape shape = enumerator.Current as ClassShape;
                        if (shape != null)
                        {
                            ModelClass modelClass = shape.ModelElement as ModelClass;
                            if (modelClass != null)
                            {
                                control.Display(modelClass);
                                return;
                            }
                        }

                        ModelProperty property = enumerator.Current as ModelProperty;
                        if (property != null)
                        {
                            control.Display(property.ModelClass);
                            return;
                        }
                    }
                }

                control.Clear();
            }
        }