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."); } 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; Store.GetAll <ModelDiagramData>().FirstOrDefault(d => d.Name == diagram.Name)?.SetDiagram((EFModelDiagram)diagram); t1.Commit(); } } EFModelDocView existingView = DocViews.OfType <EFModelDocView>().FirstOrDefault(v => v.Diagram.Name == diagram.Name); if (existingView != null) { existingView.Show(); } else { base.OpenView(logicalView, viewContext); } }
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); }
protected virtual global::Sawczyn.EFDesigner.EFModel.EFModelDiagram GetDiagram(MexModeling::ViewContext viewContext) { return(this.GetDiagrams().SingleOrDefault(item => item.Name.Equals(viewContext.DiagramName, global::System.StringComparison.Ordinal))); }