Esempio n. 1
0
        /// <summary>
        /// Adds a new derived class to each of the given domain classes.
        /// </summary>
        /// <param name="sources">DomainClasses to add a derived from.</param>
        public static void AddNewInheritanceRelationshipNewDerivedClass(List <DomainClass> sources)
        {
            if (sources.Count == 0)
            {
                return;
            }

            using (Transaction transaction = sources[0].Store.TransactionManager.BeginTransaction("Create new inheritance rs"))
            {
                foreach (DomainClass source in sources)
                {
                    // Create new domain class to act as the derived class
                    DomainClass target = source.Store.ElementFactory.CreateElement(DomainClass.DomainClassId) as DomainClass;
                    Microsoft.VisualStudio.Modeling.ElementOperations elementOperations = new Microsoft.VisualStudio.Modeling.ElementOperations(source.Store as IServiceProvider, source.Store.DefaultPartition);
                    Microsoft.VisualStudio.Modeling.ElementGroup      elementGroup      = new Microsoft.VisualStudio.Modeling.ElementGroup(source.Store.DefaultPartition);
                    elementGroup.Add(target);
                    elementGroup.MarkAsRoot(target);
                    elementOperations.MergeElementGroup(source.ModelContext, elementGroup);
                    target.Name = NameHelper.GetUniqueName(source.Store, DomainClass.DomainClassId);

                    // create a new embedding relationship
                    AddNewInheritanceRelationship(target, source, true);
                }
                transaction.Commit();
            }
        }
Esempio n. 2
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 domain class command executed.
        /// </summary>
        private void AddNewDomainClassCommand_Executed()
        {
            using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Create new domain class + Root node"))
            {
                // create new domain class
                DomainClass domainClass = this.Store.ElementFactory.CreateElement(DomainClass.DomainClassId) as DomainClass;
                Microsoft.VisualStudio.Modeling.ElementOperations elementOperations = new Microsoft.VisualStudio.Modeling.ElementOperations(this.Store as IServiceProvider, this.Store.DefaultPartition);
                Microsoft.VisualStudio.Modeling.ElementGroup elementGroup = new Microsoft.VisualStudio.Modeling.ElementGroup(this.Store.DefaultPartition);
                elementGroup.Add(domainClass);
                elementGroup.MarkAsRoot(domainClass);
                elementOperations.MergeElementGroup(this.modelTreeView.ViewContext.ModelContext, elementGroup);
                domainClass.Name = NameHelper.GetUniqueName(Store, DomainClass.DomainClassId);

                transaction.Commit();
            }
        }
        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();
                }
            }
        }