Ejemplo n.º 1
0
        public static void UnparentShape(ShapeClass shapeClass)
        {
            EmbeddingDiagramNode node = shapeClass.DiagramTreeNode as EmbeddingDiagramNode;

            if (node == null)
            {
                return;
            }

            if (shapeClass != null)
            {
                shapeClass.Parent.Children.Remove(shapeClass);
                //shapeClass.DiagramTreeNode = null;
            }

            RootDiagramNode rootNode = new RootDiagramNode(shapeClass.Store);

            List <EmbeddingDiagramNode> nodesToMove = new List <EmbeddingDiagramNode>();

            foreach (EmbeddingDiagramNode n in node.EmbeddingDiagramNodes)
            {
                nodesToMove.Add(n);
            }
            foreach (EmbeddingDiagramNode n in nodesToMove)
            {
                n.SourceEmbeddingDiagramNode = rootNode;
            }

            shapeClass.DiagramTreeNode = rootNode;
            shapeClass.DiagramClass.DiagramClassView.RootDiagramNodes.Add(rootNode);
        }
        public static void UnparentShape(ShapeClass shapeClass)
        {
            EmbeddingDiagramNode node = shapeClass.DiagramTreeNode as EmbeddingDiagramNode;
            if (node == null)
                return;

            if (shapeClass != null)
            {
                shapeClass.Parent.Children.Remove(shapeClass);
                //shapeClass.DiagramTreeNode = null;
            }

            RootDiagramNode rootNode = new RootDiagramNode(shapeClass.Store);

            List<EmbeddingDiagramNode> nodesToMove = new List<EmbeddingDiagramNode>();
            foreach (EmbeddingDiagramNode n in node.EmbeddingDiagramNodes)
                nodesToMove.Add(n);
            foreach (EmbeddingDiagramNode n in nodesToMove)
            {
                n.SourceEmbeddingDiagramNode = rootNode;
            }

            shapeClass.DiagramTreeNode = rootNode;
            shapeClass.DiagramClass.DiagramClassView.RootDiagramNodes.Add(rootNode);
        }
Ejemplo n.º 3
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);
            }
        }
        public override void ModelFinalize(CopyPaste.ModelProtoElement protoElement, CopyPaste.ModelProtoGroupMerger groupMerger)
        {
            base.ModelFinalize(protoElement, groupMerger);

            RootDiagramNode node = new RootDiagramNode(this.Store);

            node.PresentationElementClass = this;

            this.DiagramClass.DiagramClassView.RootDiagramNodes.Add(node);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Deletes the view model that is hosting the given node.
        /// </summary>
        /// <param name="node">Node.</param>
        public void DeleteRootDiagramNode(RootDiagramNode node)
        {
            for (int i = this.rootNodeVMs.Count - 1; i >= 0; i--)
            {
                if (this.rootNodeVMs[i].RootDiagramNode.Id == node.Id)
                {
                    this.rootNodeVMs[i].Dispose();
                    this.rootNodeVMs.RemoveAt(i);
                }
            }

            foreach (RootDiagramNodeViewModel viewModel in this.rootNodeVMs)
            {
                viewModel.UpdateNodePosition();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds a new root view model for the given node.
        /// </summary>
        /// <param name="node">Node.</param>
        public void AddRootDiagramNode(RootDiagramNode node)
        {
            // verify that node hasnt been added yet
            foreach (RootDiagramNodeViewModel viewModel in this.rootNodeVMs)
            {
                if (viewModel.RootDiagramNode.Id == node.Id)
                {
                    return;
                }
            }

            RootDiagramNodeViewModel vm = new RootDiagramNodeViewModel(this.ViewModelStore, node, this);

            this.rootNodeVMs.Add(vm);

            foreach (RootDiagramNodeViewModel viewModel in this.rootNodeVMs)
            {
                viewModel.UpdateNodePosition();
            }
        }
 /// <summary>
 /// Constructor. This view model constructed with 'bHookUpEvents=true' does react on model changes.
 /// </summary>
 /// <param name="viewModelStore">The store this view model belongs to.</param>
 /// <param name="embeddingDiagramNode">Element represented by this view model.</param>
 public RootDiagramNodeViewModel(ViewModelStore viewModelStore, RootDiagramNode rootDiagramNode, DiagramClassViewModel parent)
     : base(viewModelStore, rootDiagramNode, null)
 {
     this.parent = parent;
 }
        /// <summary>
        /// AddMappingToNewMappingShapeClass command executed.
        /// </summary>
        private void AddMappingToNewMappingShapeClassCommand_Executed()
        {
            CategorizedSelectionViewModel vm = SelectionHelper.CreateCategorizedVMWithoutImported(this.modelTreeView.ViewContext.ModelContext.MetaModel, this.ViewModelStore, SelectionHelperTarget.DiagramClass);
            bool? result = this.GlobalServiceProvider.Resolve<IUIVisualizerService>().ShowDialog("CategorizedSelectionPopup", vm);
            if (result == true)
            {
                if (vm.SelectedViewModel != null)
                {
                    DiagramClass diagramClass = vm.SelectedViewModel.Element as DiagramClass;

                    using (Transaction transaction = Store.TransactionManager.BeginTransaction("Add new mapping shape class"))
                    {
                        List<DomainClass> domainClasses = new List<DomainClass>();
                        foreach (BaseModelElementViewModel selectedVM in this.SelectedItems)
                            if (selectedVM.Element is DomainClass)
                                domainClasses.Add(selectedVM.Element as DomainClass);

                        foreach (DomainClass domainClass in domainClasses)
                        {
                            MappingRelationshipShapeClass shape = DiagramTreeOperations.CreateMappingRelationshipShapeClass(diagramClass.DiagramClassView.DiagramClass);
                            RootDiagramNode node = new RootDiagramNode(this.Store);
                            node.PresentationElementClass = shape;

                            diagramClass.DiagramClassView.RootDiagramNodes.Add(node);

                            shape.DomainClass = domainClass;
                        }

                        transaction.Commit();
                    }
                }
            }

            vm.Dispose();
            GC.Collect();

            /*
            List<DiagramClass> sortedClasses = this.modelTreeView.ViewContext.ModelContext.DiagramClasses.ToList();
            sortedClasses.Sort(CompareDiagramClassesByName);

            List<SelectableViewModel> vms = new List<SelectableViewModel>();
            foreach (DiagramClass d in sortedClasses)
                vms.Add(new DiagramClassSelectableViewModel(this.ViewModelStore, d));

            SelectionViewModel vm = new SelectionViewModel(this.ViewModelStore, vms);

            bool? result = this.GlobalServiceProvider.Resolve<IUIVisualizerService>().ShowDialog("TargetSelectorForm", vm);
            if (result == true)
            {
                if (vm.SelectedViewModel != null)
                {
                    DiagramClass diagramClass = vm.SelectedViewModel.Element as DiagramClass;

                    using (Transaction transaction = Store.TransactionManager.BeginTransaction("Add new mapping shape class"))
                    {
                        List<DomainClass> domainClasses = new List<DomainClass>();
                        foreach (BaseModelElementViewModel selectedVM in this.SelectedItems)
                            if (selectedVM.Element is DomainClass)
                                domainClasses.Add(selectedVM.Element as DomainClass);

                        foreach (DomainClass domainClass in domainClasses)
                        {
                            MappingRelationshipShapeClass shape = DiagramTreeOperations.CreateMappingRelationshipShapeClass(diagramClass.DiagramClassView.DiagramClass);
                            RootDiagramNode node = new RootDiagramNode(this.Store);
                            node.PresentationElementClass = shape;

                            diagramClass.DiagramClassView.RootDiagramNodes.Add(node);

                            shape.DomainClass = domainClass;
                        }

                        transaction.Commit();
                    }
                }
            }

            vm.Dispose();
            GC.Collect();
            */
        }
        /// <summary>
        /// AddNewRelationshipShapeClass command executed.
        /// </summary>
        private void AddNewRelationshipShapeClassCommand_Executed()
        {
            using (Transaction transaction = Store.TransactionManager.BeginTransaction("Add new Shape Class"))
            {
                foreach (BaseModelElementViewModel vm in this.SelectedItems)
                    if (vm is DiagramClassViewModel)
                    {
                        RelationshipShapeClass shape = DiagramTreeOperations.CreateRelationshipShapeClass((vm as DiagramClassViewModel).DiagramClassView.DiagramClass);
                        RootDiagramNode node = new RootDiagramNode(this.Store);
                        node.PresentationElementClass = shape;

                        (vm as DiagramClassViewModel).DiagramClassView.RootDiagramNodes.Add(node);
                    }

                transaction.Commit();
            }         
        }
        /// <summary>
        /// AddNewShapeClass command executed.
        /// </summary>
        private void AddNewShapeClassCommand_Executed()
        {
            using (Transaction transaction = Store.TransactionManager.BeginTransaction("Add new shape class"))
            {
                foreach (BaseModelElementViewModel vm in this.SelectedItems)
                    if (vm is DiagramClassViewModel)
                    {
                        ShapeClass shape = DiagramTreeOperations.CreateShapeClass((vm as DiagramClassViewModel).DiagramClassView.DiagramClass);
                        RootDiagramNode node = new RootDiagramNode(this.Store);
                        node.PresentationElementClass = shape;

                        (vm as DiagramClassViewModel).DiagramClassView.RootDiagramNodes.Add(node);
                    }
                    else if (vm is EmbeddingDiagramNodeViewModel)
                    {
                        ShapeClass orgShape = (vm as EmbeddingDiagramNodeViewModel).EmbeddingDiagramNode.PresentationElementClass as ShapeClass;

                        ShapeClass shape = DiagramTreeOperations.CreateShapeClass(orgShape.DiagramClass);
                        EmbeddingDiagramNode newNode = new EmbeddingDiagramNode(this.Store);
                        newNode.PresentationElementClass = shape;

                        orgShape.Children.Add(shape);
                        if (orgShape.DiagramTreeNode is EmbeddingDiagramNode)
                            newNode.SourceEmbeddingDiagramNode = orgShape.DiagramTreeNode as EmbeddingDiagramNode;
                    }
                
                transaction.Commit();
            }
        }
 /// <summary>
 /// Constructor. This view model constructed with 'bHookUpEvents=true' does react on model changes.
 /// </summary>
 /// <param name="viewModelStore">The store this view model belongs to.</param>
 /// <param name="embeddingDiagramNode">Element represented by this view model.</param>
 public RootDiagramNodeViewModel(ViewModelStore viewModelStore, RootDiagramNode rootDiagramNode, DiagramClassViewModel parent)
     : base(viewModelStore, rootDiagramNode, null)
 {
     this.parent = parent;
 }
        /// <summary>
        /// Deletes the view model that is hosting the given node.
        /// </summary>
        /// <param name="node">Node.</param>
        public void DeleteRootDiagramNode(RootDiagramNode node)
        {
            for (int i = this.rootNodeVMs.Count - 1; i >= 0; i--)
                if (this.rootNodeVMs[i].RootDiagramNode.Id == node.Id)
                {
                    this.rootNodeVMs[i].Dispose();
                    this.rootNodeVMs.RemoveAt(i);
                }

            foreach (RootDiagramNodeViewModel viewModel in this.rootNodeVMs)
                viewModel.UpdateNodePosition();
        }
        /// <summary>
        /// Adds a new root view model for the given node.
        /// </summary>
        /// <param name="node">Node.</param>
        public void AddRootDiagramNode(RootDiagramNode node)
        {
            // verify that node hasnt been added yet
            foreach (RootDiagramNodeViewModel viewModel in this.rootNodeVMs)
                if (viewModel.RootDiagramNode.Id == node.Id)
                    return;

            RootDiagramNodeViewModel vm = new RootDiagramNodeViewModel(this.ViewModelStore, node, this);
            this.rootNodeVMs.Add(vm);

            foreach (RootDiagramNodeViewModel viewModel in this.rootNodeVMs)
                viewModel.UpdateNodePosition();
        }