示例#1
0
        public void GoToPimClass(PIMClass pimClass)
        {
            ElementDiagramDependencies dependentDiagrams = ElementDiagramDependencies.FindElementDiagramDependencies(MainWindow.CurrentProject, new[] { pimClass }, null);

            if (dependentDiagrams.Count == 1)
            {
                if (dependentDiagrams[pimClass].Count == 1)
                {
                    ActivateDiagramWithElement(dependentDiagrams[pimClass][0], pimClass);
                }
                else
                {
                    SelectItemsDialog d = new SelectItemsDialog();
                    d.ToStringAction = diagram => ((Diagram)diagram).Caption;
                    d.SetItems(dependentDiagrams[pimClass]);
                    if (d.ShowDialog() == true)
                    {
                        foreach (Diagram diagram in d.selectedObjects.Cast <Diagram>())
                        {
                            ActivateDiagramWithElement(diagram, pimClass);
                        }
                    }
                }
            }
            else if (dependentDiagrams.Count == 0)
            {
                XCaseYesNoBox.ShowOK("PIM class not used in diagrams", "PIM class is not used in any diagram. You can edit it via Navigator window. ");
            }
        }
示例#2
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);
        }