Пример #1
0
        private static void FixUpDiagramView(LibraryModelContext model)
        {
            foreach (DiagramClass diagramClass in model.DiagramClasses)
            {
                DiagramClassView vm = new DiagramClassView(model.Store);
                vm.IsExpanded   = true;
                vm.DiagramClass = diagramClass;

                // add shapes views
                foreach (PresentationElementClass p in diagramClass.PresentationElements)
                {
                    if (p is ShapeClass)
                    {
                        ShapeClass shapeClass = p as ShapeClass;
                        if (shapeClass.Parent == null)
                        {
                            RootDiagramNode node = new RootDiagramNode(p.Store);
                            node.PresentationElementClass = p;

                            vm.RootDiagramNodes.Add(node);
                        }
                        else
                        {
                            EmbeddingDiagramNode newNode = new EmbeddingDiagramNode(model.Store);
                            newNode.PresentationElementClass = p;
                        }
                    }
                    else
                    {
                        RootDiagramNode node = new RootDiagramNode(p.Store);
                        node.PresentationElementClass = p;

                        vm.RootDiagramNodes.Add(node);
                    }
                }

                foreach (PresentationElementClass p in diagramClass.PresentationElements)
                {
                    if (p is ShapeClass)
                    {
                        ShapeClass shapeClass = p as ShapeClass;
                        if (shapeClass.Parent != null)
                        {
                            EmbeddingDiagramNode source = shapeClass.Parent.DiagramTreeNode as EmbeddingDiagramNode;
                            EmbeddingDiagramNode target = p.DiagramTreeNode as EmbeddingDiagramNode;

                            if (source != null && target != null)
                            {
                                new EmbeddingDiagramNodeHasEmbeddingDiagramNodes(source, target);
                            }
                        }
                    }
                }

                model.ViewContext.DiagramView.DiagramClassViews.Add(vm);
            }
        }
Пример #2
0
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="diagramClass">Element to be hosted by this view model.</param>
        public DiagramClassViewModel(ViewModelStore viewModelStore, DiagramClassView diagramClassView, DiagramViewModel parent)
            : base(viewModelStore, diagramClassView.DiagramClass)
        {
            this.diagramClassView = diagramClassView;
            this.parent           = parent;

            this.rootNodeVMs   = new ObservableCollection <RootDiagramNodeViewModel>();
            this.rootNodeVMsRO = new ReadOnlyObservableCollection <RootDiagramNodeViewModel>(this.rootNodeVMs);

            this.includedDCVMs   = new ObservableCollection <IncludedDiagramClassViewModel>();
            this.includedDCVMsRO = new ReadOnlyObservableCollection <IncludedDiagramClassViewModel>(includedDCVMs);

            this.importedDCCVMs   = new ObservableCollection <ImportedDiagramClassViewModel>();
            this.importedDCCVMsRO = new ReadOnlyObservableCollection <ImportedDiagramClassViewModel>(importedDCCVMs);

            if (this.DiagramClassView != null)
            {
                this.EventManager.GetEvent <ModelElementPropertyChangedEvent>().Subscribe(this.DiagramClassView.Id, new Action <ElementPropertyChangedEventArgs>(OnElementPropertyChanged));

                if (this.DiagramClassView.DiagramClass != null)
                {
                    this.EventManager.GetEvent <ModelElementPropertyChangedEvent>().Subscribe(this.DiagramClassView.DiagramClass.Id, new Action <ElementPropertyChangedEventArgs>(OnElementPropertyChanged));
                }

                this.EventManager.GetEvent <ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DiagramClassViewHasRootDiagramNodes.DomainClassId),
                                                                                    true, this.DiagramClassView.Id, new Action <ElementAddedEventArgs>(OnRootDiagramNodeAdded));

                this.EventManager.GetEvent <ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DiagramClassViewHasRootDiagramNodes.DomainClassId),
                                                                                      true, this.DiagramClassView.Id, new Action <ElementDeletedEventArgs>(OnRootDiagramNodeRemoved));

                this.EventManager.GetEvent <ModelRolePlayerMovedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DiagramClassViewHasRootDiagramNodes.DomainClassId),
                                                                                   this.DiagramClassView.Id, new Action <RolePlayerOrderChangedEventArgs>(OnRootDiagramNodeMoved));

                this.EventManager.GetEvent <ModelRolePlayerChangedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRole(DiagramClassViewHasRootDiagramNodes.DiagramClassViewDomainRoleId),
                                                                                     new Action <RolePlayerChangedEventArgs>(OnRootDiagramNodeChanged));
            }

            if (this.GetHostedElement() is DesignerDiagramClass)
            {
                this.EventManager.GetEvent <ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DesignerDiagramClassReferencesIncludedDiagramClasses.DomainClassId),
                                                                                    true, this.GetHostedElement().Id, new Action <ElementAddedEventArgs>(OnIncludedDDCAdded));

                this.EventManager.GetEvent <ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DesignerDiagramClassReferencesIncludedDiagramClasses.DomainClassId),
                                                                                      true, this.GetHostedElement().Id, new Action <ElementDeletedEventArgs>(OnIncludedDDCRemoved));

                this.EventManager.GetEvent <ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DesignerDiagramClassReferencesImportedDiagramClasses.DomainClassId),
                                                                                    true, this.GetHostedElement().Id, new Action <ElementAddedEventArgs>(OnImportedDCAdded));

                this.EventManager.GetEvent <ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DesignerDiagramClassReferencesImportedDiagramClasses.DomainClassId),
                                                                                      true, this.GetHostedElement().Id, new Action <ElementDeletedEventArgs>(OnImportedDCRemoved));
            }
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="diagramClass">Element to be hosted by this view model.</param>
        public DiagramClassViewModel(ViewModelStore viewModelStore, DiagramClassView diagramClassView, DiagramViewModel parent)
            : base(viewModelStore, diagramClassView.DiagramClass)
        {
            this.diagramClassView = diagramClassView;
            this.parent = parent;

            this.rootNodeVMs = new ObservableCollection<RootDiagramNodeViewModel>();
            this.rootNodeVMsRO = new ReadOnlyObservableCollection<RootDiagramNodeViewModel>(this.rootNodeVMs);

            this.includedDCVMs = new ObservableCollection<IncludedDiagramClassViewModel>();
            this.includedDCVMsRO = new ReadOnlyObservableCollection<IncludedDiagramClassViewModel>(includedDCVMs);

            this.importedDCCVMs = new ObservableCollection<ImportedDiagramClassViewModel>();
            this.importedDCCVMsRO = new ReadOnlyObservableCollection<ImportedDiagramClassViewModel>(importedDCCVMs);

            if (this.DiagramClassView != null)
            {
                this.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Subscribe(this.DiagramClassView.Id, new Action<ElementPropertyChangedEventArgs>(OnElementPropertyChanged));
                
                if (this.DiagramClassView.DiagramClass != null)
                    this.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Subscribe(this.DiagramClassView.DiagramClass.Id, new Action<ElementPropertyChangedEventArgs>(OnElementPropertyChanged));

                this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DiagramClassViewHasRootDiagramNodes.DomainClassId),
                    true, this.DiagramClassView.Id, new Action<ElementAddedEventArgs>(OnRootDiagramNodeAdded));

                this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DiagramClassViewHasRootDiagramNodes.DomainClassId),
                    true, this.DiagramClassView.Id, new Action<ElementDeletedEventArgs>(OnRootDiagramNodeRemoved));

                this.EventManager.GetEvent<ModelRolePlayerMovedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DiagramClassViewHasRootDiagramNodes.DomainClassId),
                    this.DiagramClassView.Id, new Action<RolePlayerOrderChangedEventArgs>(OnRootDiagramNodeMoved));

                this.EventManager.GetEvent<ModelRolePlayerChangedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRole(DiagramClassViewHasRootDiagramNodes.DiagramClassViewDomainRoleId),
                    new Action<RolePlayerChangedEventArgs>(OnRootDiagramNodeChanged));
            }

            if (this.GetHostedElement() is DesignerDiagramClass)
            {
                this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DesignerDiagramClassReferencesIncludedDiagramClasses.DomainClassId),
                    true, this.GetHostedElement().Id, new Action<ElementAddedEventArgs>(OnIncludedDDCAdded));

                this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DesignerDiagramClassReferencesIncludedDiagramClasses.DomainClassId),
                    true, this.GetHostedElement().Id, new Action<ElementDeletedEventArgs>(OnIncludedDDCRemoved));

                this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DesignerDiagramClassReferencesImportedDiagramClasses.DomainClassId),
                    true, this.GetHostedElement().Id, new Action<ElementAddedEventArgs>(OnImportedDCAdded));

                this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DesignerDiagramClassReferencesImportedDiagramClasses.DomainClassId),
                    true, this.GetHostedElement().Id, new Action<ElementDeletedEventArgs>(OnImportedDCRemoved));
            }
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="diagramClass">Element to be hosted by this view model.</param>
        public ModalDiagramViewModel(ViewModelStore viewModelStore, DiagramClassView diagramClassView, DiagramViewModel parent)
            : base(viewModelStore, diagramClassView, parent)
        {
            ModalDiagram diagramClass = diagramClassView.DiagramClass as ModalDiagram;
            if (diagramClass.DomainClass != null)
            {
                this.ReferenceVM = new BaseModelElementViewModel(this.ViewModelStore, diagramClass, true);
            }

            this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(ModalDiagramReferencesDomainClass.DomainClassId),
                true, diagramClass.Id, new Action<ElementAddedEventArgs>(OnReferenceAdded));

            this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(ModalDiagramReferencesDomainClass.DomainClassId),
                true, diagramClass.Id, new Action<ElementDeletedEventArgs>(OnReferenceRemoved));

            this.EventManager.GetEvent<ModelRolePlayerChangedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRole(ModalDiagramReferencesDomainClass.DomainClassDomainRoleId),
                new Action<RolePlayerChangedEventArgs>(OnReferenceChanged));
        }
Пример #5
0
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="diagramClass">Element to be hosted by this view model.</param>
        public ModalDiagramViewModel(ViewModelStore viewModelStore, DiagramClassView diagramClassView, DiagramViewModel parent)
            : base(viewModelStore, diagramClassView, parent)
        {
            ModalDiagram diagramClass = diagramClassView.DiagramClass as ModalDiagram;

            if (diagramClass.DomainClass != null)
            {
                this.ReferenceVM = new BaseModelElementViewModel(this.ViewModelStore, diagramClass, true);
            }

            this.EventManager.GetEvent <ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(ModalDiagramReferencesDomainClass.DomainClassId),
                                                                                true, diagramClass.Id, new Action <ElementAddedEventArgs>(OnReferenceAdded));

            this.EventManager.GetEvent <ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(ModalDiagramReferencesDomainClass.DomainClassId),
                                                                                  true, diagramClass.Id, new Action <ElementDeletedEventArgs>(OnReferenceRemoved));

            this.EventManager.GetEvent <ModelRolePlayerChangedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRole(ModalDiagramReferencesDomainClass.DomainClassDomainRoleId),
                                                                                 new Action <RolePlayerChangedEventArgs>(OnReferenceChanged));
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="diagramClass">Element to be hosted by this view model.</param>
        public SpecificElementsDiagramViewModel(ViewModelStore viewModelStore, DiagramClassView diagramClassView, DiagramViewModel parent)
            : base(viewModelStore, diagramClassView, parent)
        {
            this.referenceVMs = new ObservableCollection<BaseModelElementViewModel>();
            this.deleteCommand = new DelegateCommand<BaseModelElementViewModel>(DeleteCommand_Executed);

            SpecificElementsDiagram diagramClass = diagramClassView.DiagramClass as SpecificElementsDiagram;
            foreach (DomainClass d in diagramClass.DomainClasses)
                this.AddReference(d);

            this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(SpecificElementsDiagramReferencesDomainClasses.DomainClassId),
                true, diagramClass.Id, new Action<ElementAddedEventArgs>(OnReferenceAdded));

            this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(SpecificElementsDiagramReferencesDomainClasses.DomainClassId),
                true, diagramClass.Id, new Action<ElementDeletedEventArgs>(OnReferenceRemoved));

            this.EventManager.GetEvent<ModelRolePlayerChangedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRole(SpecificElementsDiagramReferencesDomainClasses.DomainClassDomainRoleId),
                new Action<RolePlayerChangedEventArgs>(OnReferenceChanged));
            this.EventManager.GetEvent<ModelRolePlayerChangedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRole(SpecificElementsDiagramReferencesDomainClasses.SpecificElementsDiagramDomainRoleId),
                new Action<RolePlayerChangedEventArgs>(OnReferenceChanged));
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="diagramClass">Element to be hosted by this view model.</param>
        public SpecificElementsDiagramViewModel(ViewModelStore viewModelStore, DiagramClassView diagramClassView, DiagramViewModel parent)
            : base(viewModelStore, diagramClassView, parent)
        {
            this.referenceVMs  = new ObservableCollection <BaseModelElementViewModel>();
            this.deleteCommand = new DelegateCommand <BaseModelElementViewModel>(DeleteCommand_Executed);

            SpecificElementsDiagram diagramClass = diagramClassView.DiagramClass as SpecificElementsDiagram;

            foreach (DomainClass d in diagramClass.DomainClasses)
            {
                this.AddReference(d);
            }

            this.EventManager.GetEvent <ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(SpecificElementsDiagramReferencesDomainClasses.DomainClassId),
                                                                                true, diagramClass.Id, new Action <ElementAddedEventArgs>(OnReferenceAdded));

            this.EventManager.GetEvent <ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(SpecificElementsDiagramReferencesDomainClasses.DomainClassId),
                                                                                  true, diagramClass.Id, new Action <ElementDeletedEventArgs>(OnReferenceRemoved));

            this.EventManager.GetEvent <ModelRolePlayerChangedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRole(SpecificElementsDiagramReferencesDomainClasses.DomainClassDomainRoleId),
                                                                                 new Action <RolePlayerChangedEventArgs>(OnReferenceChanged));
            this.EventManager.GetEvent <ModelRolePlayerChangedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRole(SpecificElementsDiagramReferencesDomainClasses.SpecificElementsDiagramDomainRoleId),
                                                                                 new Action <RolePlayerChangedEventArgs>(OnReferenceChanged));
        }
Пример #8
0
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            if (e.ModelElement != null)
            {
                if (e.ModelElement.Store.TransactionManager.CurrentTransaction != null)
                {
                    if (e.ModelElement.Store.TransactionManager.CurrentTransaction.IsSerializing)
                    {
                        return;
                    }
                }
            }

            if (e.ModelElement == null)
            {
                return;
            }

            if (ImmutabilityExtensionMethods.GetLocks(e.ModelElement) != Locks.None)
            {
                return;
            }

            ModelContext modelContext = e.ModelElement as ModelContext;

            if (modelContext != null)
            {
                if (modelContext.ViewContext == null)
                {
                    ViewContext viewContext = new ViewContext(modelContext.Store);
                    viewContext.DomainModelTreeView = new DomainModelTreeView(modelContext.Store);
                    viewContext.DiagramView         = new DiagramView(modelContext.Store);
                    modelContext.ViewContext        = viewContext;
                    modelContext.MetaModel.View.ViewContexts.Add(viewContext);
                }

                if (modelContext.DiagramClasses.Count == 0)
                {
                    DesignerDiagramClass ddC = new DesignerDiagramClass(modelContext.Store);
                    //ddC.Name = "DesignerDiagram";
                    ddC.Name  = NameHelper.GetUniqueName(modelContext.Store, DesignerDiagramClass.DomainClassId);
                    ddC.Title = "Designer";
                    modelContext.DiagramClasses.Add(ddC);

                    DiagramClassView vm = new DiagramClassView(modelContext.Store);
                    vm.IsExpanded   = true;
                    vm.DiagramClass = ddC;
                    modelContext.ViewContext.DiagramView.DiagramClassViews.Add(vm);
                }

                DomainClass domainClass = modelContext.Store.ElementFactory.CreateElement(DomainClass.DomainClassId) as DomainClass;
                domainClass.IsDomainModel = true;
                Microsoft.VisualStudio.Modeling.ElementOperations elementOperations = new Microsoft.VisualStudio.Modeling.ElementOperations(modelContext.Store as IServiceProvider, modelContext.Store.DefaultPartition);
                Microsoft.VisualStudio.Modeling.ElementGroup      elementGroup      = new Microsoft.VisualStudio.Modeling.ElementGroup(modelContext.Store.DefaultPartition);
                elementGroup.Add(domainClass);
                elementGroup.MarkAsRoot(domainClass);
                elementOperations.MergeElementGroup(modelContext, elementGroup);
                domainClass.Name = NameHelper.GetUniqueName(modelContext.Store, DomainClass.DomainClassId);

                SerializedDomainModel child = new SerializedDomainModel(domainClass.Store);
                child.DomainClass       = domainClass;
                child.SerializationName = domainClass.SerializationName;

                if (modelContext.SerializationModel == null)
                {
                    modelContext.SerializationModel = new SerializationModel(modelContext.Store);
                }

                modelContext.SerializationModel.SerializedDomainModel = child;
                SerializationHelper.AddSerializationDomainProperties(domainClass.Store, domainClass);
            }
        }
        /// <summary>
        /// Add new diagram class command executed.
        /// </summary>
        private void AddNewDiagramClassCommand_Executed()
        {
            using (Transaction transaction = Store.TransactionManager.BeginTransaction("Create new diagram class + vm"))
            {
                // create new diagram class
                DiagramClass diagramClass = Store.ElementFactory.CreateElement(DiagramClass.DomainClassId) as DiagramClass;
                Microsoft.VisualStudio.Modeling.ElementOperations elementOperations = new Microsoft.VisualStudio.Modeling.ElementOperations(Store as IServiceProvider, Store.DefaultPartition);
                Microsoft.VisualStudio.Modeling.ElementGroup elementGroup = new Microsoft.VisualStudio.Modeling.ElementGroup(Store.DefaultPartition);
                elementGroup.Add(diagramClass);
                elementGroup.MarkAsRoot(diagramClass);
                elementOperations.MergeElementGroup(this.diagramView.ViewContext.ModelContext, elementGroup);
                diagramClass.Name = NameHelper.GetUniqueName(Store, DiagramClass.DomainClassId);

                diagramClass.Title = diagramClass.Name;

                DiagramClassView view = new DiagramClassView(this.Store);
                view.DiagramClass = diagramClass;
                this.diagramView.DiagramClassViews.Add(view);

                transaction.Commit();
            }
        }
        /// <summary>
        /// Add new diagram class from template command executed.
        /// </summary>
        private void AddNewDiagramClassFromTemplateCommand_Executed()
        {
            DiagramClassTemplateSelectorViewModel vm = new DiagramClassTemplateSelectorViewModel(this.ViewModelStore);
            bool? result = this.GlobalServiceProvider.Resolve<IUIVisualizerService>().ShowDialog("DiagramClassTemplateSelector", vm);
            if (result == true)
            {
                using (Transaction transaction = Store.TransactionManager.BeginTransaction("Create new templated diagram class + vm"))
                {
                    // create new diagram class
                    DiagramClass diagramClass;

                    if (vm.SelectedTemplateVM.UniqueId == DiagramClassTemplateIds.GeneralGraphicalDependencyTemplate)
                        diagramClass = Store.ElementFactory.CreateElement(DependencyDiagram.DomainClassId) as DependencyDiagram;
                    else if (vm.SelectedTemplateVM.UniqueId == DiagramClassTemplateIds.SpecificGraphicalDependencyTemplate)
                        diagramClass = Store.ElementFactory.CreateElement(SpecificDependencyDiagram.DomainClassId) as SpecificDependencyDiagram;
                    else if (vm.SelectedTemplateVM.UniqueId == DiagramClassTemplateIds.ModalDiagramTemplate)
                        diagramClass = Store.ElementFactory.CreateElement(ModalDiagram.DomainClassId) as ModalDiagram;
                    else if (vm.SelectedTemplateVM.UniqueId == DiagramClassTemplateIds.SpecificElementsDiagramTemplate)
                        diagramClass = Store.ElementFactory.CreateElement(SpecificElementsDiagram.DomainClassId) as SpecificElementsDiagram;
                    else if (vm.SelectedTemplateVM.UniqueId == DiagramClassTemplateIds.DesignerSurfaceDiagramTemplate)
                        diagramClass = Store.ElementFactory.CreateElement(DesignerSurfaceDiagram.DomainClassId) as DesignerSurfaceDiagram;
                    else
                    {
                        throw new NotSupportedException();
                    }

                    (diagramClass as TemplatedDiagramClass).UniqueId = vm.SelectedTemplateVM.UniqueId;
                    (diagramClass as TemplatedDiagramClass).Name = vm.SelectedTemplateVM.Name;
                    (diagramClass as TemplatedDiagramClass).Title = vm.SelectedTemplateVM.DisplayName;
                    (diagramClass as TemplatedDiagramClass).Description = vm.SelectedTemplateVM.Description;
                    diagramClass.IsCustom = true;

                    Microsoft.VisualStudio.Modeling.ElementOperations elementOperations = new Microsoft.VisualStudio.Modeling.ElementOperations(Store as IServiceProvider, Store.DefaultPartition);
                    Microsoft.VisualStudio.Modeling.ElementGroup elementGroup = new Microsoft.VisualStudio.Modeling.ElementGroup(Store.DefaultPartition);
                    elementGroup.Add(diagramClass);
                    elementGroup.MarkAsRoot(diagramClass);
                    elementOperations.MergeElementGroup(this.diagramView.ViewContext.ModelContext, elementGroup);

                    DiagramClassView view = new DiagramClassView(this.Store);
                    view.DiagramClass = diagramClass;
                    this.diagramView.DiagramClassViews.Add(view);

                    transaction.Commit();
                }
            }
        }
 /// <summary>
 /// Deletes the diagram class view model that is hosting the given node.
 /// </summary>
 /// <param name="node">Node.</param>
 public void DeleteDiagramClassView(DiagramClassView node)
 {
     for (int i = this.rootNodeVMs.Count - 1; i >= 0; i--)
         if (this.rootNodeVMs[i].DiagramClassView.Id == node.Id)
         {
             this.rootNodeVMs[i].Dispose();
             this.rootNodeVMs.RemoveAt(i);
         }
 }
        /// <summary>
        /// Adds a new diagram class view model for the given node.
        /// </summary>
        /// <param name="node">Node.</param>
        public void AddDiagramClassView(DiagramClassView node)
        {
            // verify that node hasnt been added yet
            foreach (DiagramClassViewModel viewModel in this.rootNodeVMs)
                if (viewModel.DiagramClassView.Id == node.Id)
                    return;

            if (node.DiagramClass is SpecificDependencyDiagram)
            {
                SpecificDependencyDiagramViewModel vm = new SpecificDependencyDiagramViewModel(this.ViewModelStore, node, this);
                this.rootNodeVMs.Add(vm);
            }
            else if (node.DiagramClass is DependencyDiagram)
            {
                DependencyDiagramViewModel vm = new DependencyDiagramViewModel(this.ViewModelStore, node, this);
                this.rootNodeVMs.Add(vm);
            }
            else if (node.DiagramClass is ModalDiagram)
            {
                ModalDiagramViewModel vm = new ModalDiagramViewModel(this.ViewModelStore, node, this);
                this.rootNodeVMs.Add(vm);
            }
            else if (node.DiagramClass is SpecificElementsDiagram)
            {
                SpecificElementsDiagramViewModel vm = new SpecificElementsDiagramViewModel(this.ViewModelStore, node, this);
                this.rootNodeVMs.Add(vm);
            }
            else
            {
                DiagramClassViewModel vm = new DiagramClassViewModel(this.ViewModelStore, node, this);
                this.rootNodeVMs.Add(vm);
            }
        }
Пример #13
0
 /// <summary>
 /// Constuctor.
 /// </summary>
 /// <param name="viewModelStore">The store this view model belongs to.</param>
 /// <param name="diagramClass">Element to be hosted by this view model.</param>
 public SpecificDependencyDiagramViewModel(ViewModelStore viewModelStore, DiagramClassView diagramClassView, DiagramViewModel parent)
     : base(viewModelStore, diagramClassView, parent)
 {
 }
Пример #14
0
        public static void PostProcessModelLoad(MetaModel model)
        {
            // package and custom editor GUIDs
            if (model.PackageGuid == null || model.PackageGuid == Guid.Empty)
            {
                model.PackageGuid = Guid.NewGuid();
            }
            if (model.CustomExtensionGuid == null || model.CustomExtensionGuid == Guid.Empty)
            {
                model.CustomExtensionGuid = Guid.NewGuid();
            }


            #region relationship targets fixup
            ReadOnlyCollection <DomainRelationship> rels = model.AllRelationships;
            foreach (DomainRelationship rel in rels)
            {
                if (rel.Target.RolePlayer == null)
                {
                    ReferenceRelationship referenceRelationship = rel as ReferenceRelationship;
                    if (referenceRelationship != null)
                    {
                        if (referenceRelationship.ReferenceRSNode != null)
                        {
                            referenceRelationship.ReferenceRSNode.Delete();
                        }

                        if (referenceRelationship.SerializedReferenceRelationship != null)
                        {
                            referenceRelationship.SerializedReferenceRelationship.Delete();
                        }
                    }

                    EmbeddingRelationship embeddingRelationship = rel as EmbeddingRelationship;
                    if (embeddingRelationship != null)
                    {
                        if (embeddingRelationship.EmbeddingRSNode != null)
                        {
                            embeddingRelationship.EmbeddingRSNode.Delete();
                        }

                        if (embeddingRelationship.SerializedEmbeddingRelationship != null)
                        {
                            embeddingRelationship.SerializedEmbeddingRelationship.Delete();
                        }
                    }

                    rel.Delete();
                }
            }
            #endregion

            #region inconsistent serialization elements
            foreach (BaseModelContext context in model.ModelContexts)
            {
                if (context is LibraryModelContext)
                {
                    LibraryModelContext lib = context as LibraryModelContext;
                    if (lib.SerializationModel != null)
                    {
                        for (int i = lib.SerializationModel.Children.Count - 1; i >= 0; i--)
                        {
                            SerializationClass c = lib.SerializationModel.Children[i];
                            if (c is SerializedDomainClass)
                            {
                                SerializedDomainClass s = c as SerializedDomainClass;
                                if (s.DomainClass == null)
                                {
                                    s.Delete();
                                }

                                continue;
                            }
                            else if (c is SerializedEmbeddingRelationship)
                            {
                                SerializedEmbeddingRelationship s = c as SerializedEmbeddingRelationship;
                                if (s.EmbeddingRelationship == null)
                                {
                                    s.Delete();
                                }

                                continue;
                            }
                            else if (c is SerializedReferenceRelationship)
                            {
                                SerializedReferenceRelationship s = c as SerializedReferenceRelationship;
                                if (s.ReferenceRelationship == null)
                                {
                                    s.Delete();
                                }

                                continue;
                            }

                            // element has not been deleted, see if its properties are ok
                            for (int y = c.Properties.Count - 1; y >= 0; y--)
                            {
                                if (c.Properties[y] == null)
                                {
                                    c.Properties[y].Delete();
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            #region derived classes serialization items fixup
            if (model.MetaModelLibraries.Count > 0)
            {
                ReadOnlyCollection <ModelElement> elements = model.Store.ElementDirectory.FindElements(DomainClassReferencesBaseClass.DomainClassId);
                foreach (ModelElement m in elements)
                {
                    DomainClassReferencesBaseClass con = m as DomainClassReferencesBaseClass;
                    if (con != null)
                    {
                        if (con.BaseClass != null)
                        {
                            if (con.BaseClass.ModelContext.MetaModel != model)
                            {
                                foreach (DomainClass derivedClass in con.BaseClass.DerivedClasses)
                                {
                                    FixUpDerivedClasses(derivedClass, model);
                                }
                            }
                        }
                    }
                }

                ReadOnlyCollection <ModelElement> elementsCon = model.Store.ElementDirectory.FindElements(DomainRelationshipReferencesBaseRelationship.DomainClassId);
                foreach (ModelElement m in elementsCon)
                {
                    DomainRelationshipReferencesBaseRelationship con = m as DomainRelationshipReferencesBaseRelationship;
                    if (con != null)
                    {
                        if (con.BaseRelationship != null)
                        {
                            if (con.BaseRelationship.ModelContext.MetaModel != model)
                            {
                                foreach (DomainRelationship derivedClass in con.BaseRelationship.DerivedRelationships)
                                {
                                    FixUpDerivedRelationships(derivedClass, model);
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            #region check if model contains all required elements
            // property grid editors
            if (model.PropertyGridEditors.Count == 0)
            {
                FixUpPropertyGridEditors(model);
            }

            // domain types
            if (model.DomainTypes.Count == 0)
            {
                FixUpDomainTypes(model);
            }

            // model context
            if (model.ModelContexts.Count == 0)
            {
                FixUpModelContext(model);
            }

            // validation
            if (model.Validation == null)
            {
                model.Validation = new Validation(model.Store);
            }

            if (model.View == null)
            {
                model.View = new View(model.Store);
            }

            if (model.View.ModelTree == null)
            {
                model.View.ModelTree = new ModelTree(model.Store);
            }

            foreach (BaseModelContext mContext in model.ModelContexts)
            {
                if (mContext is LibraryModelContext)
                {
                    LibraryModelContext m = mContext as LibraryModelContext;
                    if (m.DiagramClasses.Count == 0 && m is ModelContext)
                    {
                        DesignerDiagramClass ddC = new DesignerDiagramClass(model.Store);
                        ddC.Name  = "DesignerDiagram";
                        ddC.Title = "Designer";

                        m.DiagramClasses.Add(ddC);
                    }

                    if (m.ViewContext == null)
                    {
                        m.ViewContext = new ViewContext(model.Store);
                        m.ViewContext.DomainModelTreeView = new DomainModelTreeView(model.Store);
                        m.ViewContext.DiagramView         = new DiagramView(model.Store);

                        model.View.ViewContexts.Add(m.ViewContext);

                        FixUpDomainModelTreeView(m);
                        FixUpDiagramView(m);
                    }

                    if (m.ViewContext.DiagramView == null || m.ViewContext.DomainModelTreeView == null)
                    {
                        if (m.ViewContext.DomainModelTreeView == null)
                        {
                            m.ViewContext.DomainModelTreeView = new DomainModelTreeView(model.Store);
                            FixUpDomainModelTreeView(m);
                        }

                        if (m.ViewContext.DiagramView == null)
                        {
                            m.ViewContext.DiagramView = new DiagramView(model.Store);
                            FixUpDiagramView(m);
                        }
                    }

                    // diagram class view for designer diagram
                    if (m.ViewContext.DiagramView.DiagramClassViews.Count == 0 && m is ModelContext)
                    {
                        DiagramClassView vm = new DiagramClassView(model.Store);
                        vm.IsExpanded = true;
                        foreach (DiagramClass d in m.DiagramClasses)
                        {
                            if (d is DesignerDiagramClass)
                            {
                                vm.DiagramClass = d;
                                break;
                            }
                        }

                        m.ViewContext.DiagramView.DiagramClassViews.Add(vm);
                    }

                    // serialization
                    if (m.SerializationModel == null)
                    {
                        m.SerializationModel = new SerializationModel(model.Store);
                    }

                    // serialized domain model
                    if (m is ModelContext)
                    {
                        if (m.SerializationModel.SerializedDomainModel == null)
                        {
                            FixUpSerializedDomainModel(m as ModelContext);
                        }
                    }
                }
            }
            #endregion

            // view ids.
            if (model.View != null)
            {
                if (model.View.ModelTreeId == null || model.View.ModelTreeId == Guid.Empty)
                {
                    model.View.ModelTreeId = Guid.NewGuid();
                }

                if (model.View.DependenciesViewId == null || model.View.DependenciesViewId == Guid.Empty)
                {
                    model.View.DependenciesViewId = Guid.NewGuid();
                }

                if (model.View.ErrorListId == null || model.View.ErrorListId == Guid.Empty)
                {
                    model.View.ErrorListId = Guid.NewGuid();
                }

                if (model.View.PropertyGridId == null || model.View.PropertyGridId == Guid.Empty)
                {
                    model.View.PropertyGridId = Guid.NewGuid();
                }

                if (model.View.SearchId == null || model.View.SearchId == Guid.Empty)
                {
                    model.View.SearchId = Guid.NewGuid();
                }

                if (model.View.SearchResultId == null || model.View.SearchResultId == Guid.Empty)
                {
                    model.View.SearchResultId = Guid.NewGuid();
                }

                if (model.View.PluginWindowId == null || model.View.PluginWindowId == Guid.Empty)
                {
                    model.View.PluginWindowId = Guid.NewGuid();
                }
            }
        }