示例#1
0
        /// <summary>
        /// Sets this command for execution
        /// </summary>
        /// <param name="c">PIMClass to be derived from</param>
        /// <param name="d">Diagram to which to add the PSM Class as one of roots</param>
        /// <param name="h">Optional Element holder where the final PSMClass will be placed</param>
        public void Set(PIMClass c, PSMDiagram d, ElementHolder <PSMClass> h)
        {
            Class = c;
            HolderBase <PSMDiagram> DiagramHolder = new HolderBase <PSMDiagram>()
            {
                Element = d
            };

            if (h != null)
            {
                pSMClassHolder = h;
            }
            else
            {
                pSMClassHolder = new ElementHolder <PSMClass>();
            }

            NewPSMClassCommand c1 = NewPSMClassCommandFactory.Factory().Create(Controller) as NewPSMClassCommand;

            c1.RepresentedClass = Class;
            c1.CreatedClass     = pSMClassHolder;
            Commands.Add(c1);

            PSMClassToDiagram_ModelCommand c3 = PSMClassToDiagram_ModelCommandFactory.Factory().Create(Controller) as PSMClassToDiagram_ModelCommand;

            c3.Set(pSMClassHolder, DiagramHolder);
            Commands.Add(c3);

            AddPSMClassToRoots_ModelCommand c4 = AddPSMClassToRoots_ModelCommandFactory.Factory().Create(Controller) as AddPSMClassToRoots_ModelCommand;

            c4.Set(pSMClassHolder, DiagramHolder);
            Commands.Add(c4);

            ActivateDiagramCommand c5 = ActivateDiagramCommandFactory.Factory().Create(Controller) as ActivateDiagramCommand;

            c5.Set(d);
            Commands.Add(c5);
        }
示例#2
0
        public void Execute(object parameter)
        {
            IStackedCommand undoneCommand = GetUndoneCommand();

            undoneCommand.UnExecute();
            if (undoneCommand is DiagramCommandBase)
            {
                ActivateDiagramCommand c = ActivateDiagramCommandFactory.Factory().Create(Controller) as ActivateDiagramCommand;
                c.Set((undoneCommand as DiagramCommandBase).Controller.Diagram);
                Debug.WriteLine("Changing active diagram due to Undo");
                c.Execute();
            }
            if (undoneCommand is MacroCommand <DiagramController> )
            {
                ActivateDiagramCommand c = ActivateDiagramCommandFactory.Factory().Create(Controller) as ActivateDiagramCommand;
                c.Set((undoneCommand as MacroCommand <DiagramController>).Controller.Diagram);
                Debug.WriteLine("Changing active diagram due to Undo");
                c.Execute();
            }
            if (UndoExecuted != null)
            {
                UndoExecuted(undoneCommand);
            }
        }
示例#3
0
        public bool Set(IEnumerable <Element> deleted, DiagramController activeDiagramController)
        {
            ActiveDiagramController = activeDiagramController;
            Deleted = new List <Element>(deleted.Count());
            foreach (Element deletable in deleted)
            {
                Deleted.Add(deletable);
            }

            ElementDependencies           dependencies = ElementDependencies.FindElementDependenciesInModel(Deleted);
            DeleteDependentElementsDialog dialog       = new DeleteDependentElementsDialog(dependencies);

            dialog.DeleteLevel = DeleteDependentElementsDialog.EDeleteLevel.Model;

            if (dependencies.Count == 0 || dialog.ShowDialog() == true)
            {
                if (dependencies.Count == 0)
                {
                    dialog.Close();
                }
                // add all selected dependent elements, remove those that were not selected
                foreach (KeyValuePair <Element, bool> _flag in dependencies.Flags)
                {
                    if (_flag.Value == false)
                    {
                        Deleted.Remove(_flag.Key);
                    }
                    else
                    {
                        foreach (Element element in dependencies[_flag.Key])
                        {
                            if (!Deleted.Contains(element))
                            {
                                Deleted.Add(element);
                            }
                        }
                    }
                }

                // test whether elements are not used in other diagrams
                ElementDiagramDependencies dependentDiagrams;
                if (ActiveDiagramController != null)
                {
                    dependentDiagrams = ElementDiagramDependencies.FindElementDiagramDependencies(Controller.Project, Deleted, ActiveDiagramController.Diagram);
                }
                else
                {
                    dependentDiagrams = ElementDiagramDependencies.FindElementDiagramDependencies(Controller.Project, Deleted, null);
                }

                if (dependentDiagrams.Count > 0 &&
                    !(dependentDiagrams.Count == 1 &&
                      ActiveDiagramController != null &&
                      dependentDiagrams.Single().Value.Count == 1 &&
                      dependentDiagrams.Single().Value.Single() == ActiveDiagramController.Diagram
                      )
                    )
                {
                    ReferencingDiagramsDialog referencingDiagramsDialog = new ReferencingDiagramsDialog(dependentDiagrams);
                    referencingDiagramsDialog.ShowDialog();
                    if (referencingDiagramsDialog.cbOpen.IsChecked == true)
                    {
                        foreach (KeyValuePair <Element, List <Diagram> > pair in dependentDiagrams)
                        {
                            foreach (Diagram diagram in pair.Value)
                            {
                                ActivateDiagramCommand c = ActivateDiagramCommandFactory.Factory().Create(Controller) as ActivateDiagramCommand;
                                c.Set(diagram);
                                c.Execute();
                            }
                        }
                    }
                }
                else
                {
                    deleteFromModelCommand =
                        (DeleteFromModelCommand)DeleteFromModelCommandFactory.Factory().Create(Controller);
                    deleteFromModelCommand.DeletedElements = Deleted;
                    if (ActiveDiagramController != null)
                    {
                        deleteFromModelCommand.CallingDiagram = ActiveDiagramController.Diagram;
                    }
                    else
                    {
                        deleteFromModelCommand.CallingDiagram = null;
                    }

                    if (ActiveDiagramController != null && ActiveDiagramController.Diagram != null)
                    {
                        deleteFromDiagramCommand =
                            (DeleteFromDiagramCommand)DeleteFromDiagramCommandFactory.Factory().Create(ActiveDiagramController);
                        deleteFromDiagramCommand.DeletedElements = Deleted.Where(e => ActiveDiagramController.Diagram.IsElementPresent(e)).ToList();
                        Commands.Add(deleteFromDiagramCommand);
                    }

                    Commands.Add(deleteFromModelCommand);
                    return(true);
                }
            }
            return(false);
        }