コード例 #1
0
ファイル: DocData.cs プロジェクト: pmfai25/EFDesigner
        public override void OpenView(global::System.Guid logicalView, object viewContext)
        {
            MexModeling::ViewContext modelingViewContext = viewContext as MexModeling::ViewContext;

            if (modelingViewContext == null)
            {
                base.OpenView(logicalView, viewContext);
                return;
            }

            if (string.IsNullOrEmpty(modelingViewContext.DiagramName))
            {
                throw new global::System.ArgumentException("the name of the diagram to open cannot be empty.");
            }

            //TODO: don't fetch the default diagram. It's already showing
            DslDiagrams::Diagram diagram = this.GetDiagram(modelingViewContext);

            if (diagram == null)
            {
                if (modelingViewContext.DiagramType == null)
                {
                    throw new global::System.ArgumentException("the type of the diagram to open must be specified.");
                }

                if (!(modelingViewContext.DiagramType.IsSubclassOf(typeof(DslDiagrams::Diagram))))
                {
                    throw new global::System.ArgumentException("the type of the diagram to open must inherit from Microsoft.VisualStudio.Modeling.Diagrams.Diagram class.");
                }

                // No diagram associated with specified name, so create and set the name
                DslModeling::ModelElement rootElement = modelingViewContext.RootElement ?? this.RootElement;

                using (DslModeling::Transaction t1 = this.Store.TransactionManager.BeginTransaction("DocData:OpenView:CreateDiagram", true))
                {
                    diagram = (DslDiagrams::Diagram)global::System.Activator.CreateInstance(modelingViewContext.DiagramType,
                                                                                            this.PartitionMapper.PartitionForClass(this.Store.DefaultPartition, DslDiagrams::Diagram.DomainClassId),
                                                                                            new DslModeling::PropertyAssignment(DslDiagrams::Diagram.NameDomainPropertyId, modelingViewContext.DiagramName));

                    // Set the ModelElement associated with the newly created diagram.
                    diagram.ModelElement = rootElement;

                    if (diagram is global::Sawczyn.EFDesigner.EFModel.EFModelDiagram eFModelDiagram)
                    {
                        EFModelSynchronizationHelper.FixUp(eFModelDiagram);
                        //foreach (DslDiagrams::ShapeElement childShape in eFModelDiagram.NestedChildShapes)
                        //   childShape.Hide();
                    }

                    t1.Commit();
                }
            }

            base.OpenView(logicalView, viewContext);
        }
コード例 #2
0
ファイル: DocData.cs プロジェクト: vincedan/EFDesigner
        public override void OpenView(global::System.Guid logicalView, object viewContext)
        {
            var modelingViewContext = viewContext as MexModeling::ViewContext;

            if (modelingViewContext == null)
            {
                base.OpenView(logicalView, viewContext);
                return;
            }

            if (string.IsNullOrEmpty(modelingViewContext.DiagramName))
            {
                throw new global::System.ArgumentException("the name of the diagram to open cannot be empty.");
            }

            //TODO: don't fetch the default diagram. It's already showing
            DslDiagrams::Diagram diagram = this.GetDiagram(modelingViewContext);

            if (diagram == null)
            {
                if (modelingViewContext.DiagramType == null)
                {
                    throw new global::System.ArgumentException("the type of the diagram to open must be specified.");
                }

                if (!(modelingViewContext.DiagramType.IsSubclassOf(typeof(DslDiagrams::Diagram))))
                {
                    throw new global::System.ArgumentException("the type of the diagram to open must inherit from Microsoft.VisualStudio.Modeling.Diagrams.Diagram class.");
                }

                // No diagram associated with specified name
                // Create a new diagram by using specified type
                // Set automatically the name of the new diagram
                var rootElement = modelingViewContext.RootElement ?? this.RootElement;

                using (var transaction = this.Store.TransactionManager.BeginTransaction("DocData:OpenView", true))
                {
                    diagram = (DslDiagrams::Diagram)global::System.Activator.CreateInstance(modelingViewContext.DiagramType,
                                                                                            this.PartitionMapper.PartitionForClass(this.Store.DefaultPartition, DslDiagrams::Diagram.DomainClassId),
                                                                                            new DslModeling::PropertyAssignment(DslDiagrams::Diagram.NameDomainPropertyId, modelingViewContext.DiagramName));

                    // Set the ModelElement associated with the newly created diagram.
                    diagram.ModelElement = rootElement;

                    // new diagrams appear empty to start
                    foreach (ClassShape shape in diagram.GetChildElements(diagram).OfType <ClassShape>())
                    {
                        shape.Visible = false;
                    }
                    foreach (EnumShape shape in diagram.GetChildElements(diagram).OfType <EnumShape>())
                    {
                        shape.Visible = false;
                    }

                    transaction.Commit();
                }


                var eFModelDiagram = diagram as global::Sawczyn.EFDesigner.EFModel.EFModelDiagram;
                if (null != eFModelDiagram)
                {
                    EFModelSynchronizationHelper.FixUp(eFModelDiagram);
                }
            }

            base.OpenView(logicalView, viewContext);
        }