Exemple #1
0
        /// <summary>
        /// Tells the command which elements to delete. The method uses
        /// interactive dialogs to specify the initial set of deleted elements and
        /// to ask whether to delete unused elements from the model.
        /// </summary>
        /// <param name="deletedElements">set of deleted elements</param>
        /// <param name="selectionCallback">function that is called, when selected elements are specified in the dialog. Can be set to null.</param>
        /// <returns><code>true</code> when user pressed OK, <code>false</code> when user pressed Cancel in the</returns>
        public bool InitializeCommand(Action <IEnumerable <Element> > selectionCallback, IEnumerable <Element> deletedElements)
        {
            DeleteFromPSMDiagramCommand command = (DeleteFromPSMDiagramCommand)DeleteFromPSMDiagramCommandFactory.Factory().Create(Controller);

            command.ForceDelete = ForceDelete;
            if (!command.InitializeCommand(selectionCallback, deletedElements))
            {
                return(false);
            }

            List <PSMClass> referencedPSMClasses = new List <PSMClass>();


            foreach (PSMClass psmClass in command.DeletedElements.OfType <PSMClass>())
            {
                foreach (PSMClass referencing in GetReferencings(psmClass))
                {
                    SetRepresentedPSMClassCommand convertCommand =
                        (SetRepresentedPSMClassCommand)SetRepresentedPSMClassCommandFactory.Factory().Create(Controller);
                    convertCommand.Set(null, referencing);
                    Commands.Add(convertCommand);
                    if (!command.DeletedElements.Contains(referencing))
                    {
                        referencedPSMClasses.AddIfNotContained(psmClass);
                    }
                }
            }

            if (referencedPSMClasses.Count > 0)
            {
                XCase.Controller.Dialogs.OkCancelDialog d = new XCase.Controller.Dialogs.OkCancelDialog();
                d.PrimaryContent   = "Existing structural representatives";
                d.SecondaryContent = "Following clases are referenced from structural representatives: " +
                                     referencedPSMClasses.ConcatWithSeparator(", ") + ". \r\n\r\nContinue?";
                if (d.ShowDialog() != true)
                {
                    return(false);
                }
            }

            Commands.Add(command);

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Processes one selected TreeView item. Generates commands for addition of PSMClasses, PSMStructuralRepresentatives and PSMAssociations
        /// </summary>
        /// <param name="T">The item to be processed</param>
        private void GenerateCommands(TreeClasses T)
        {
            #region Holders
            ElementHolder <PSMClass>            Child             = new ElementHolder <PSMClass>();
            ElementHolder <PSMAssociationChild> ChildAssociation  = new ElementHolder <PSMAssociationChild>();
            ElementHolder <PSMAssociation>      AssociationHolder = new ElementHolder <PSMAssociation>();
            #endregion

            #region Create new element

            if (T.RootClass == null)
            {
                NewPSMClassCommand c1 = NewPSMClassCommandFactory.Factory().Create(Controller.ModelController) as NewPSMClassCommand;
                c1.RepresentedClass = T.PIMClass;
                c1.CreatedClass     = Child;
                Commands.Add(c1);

                if (T.Represented != null) //Creating PSM Structural Representative
                {
                    SetRepresentedPSMClassCommand c1a = SetRepresentedPSMClassCommandFactory.Factory().Create(Controller) as SetRepresentedPSMClassCommand;
                    c1a.Set(T.Represented, Child);
                    Commands.Add(c1a);
                }

                //Put the newly created PSMClass to the diagram
                ElementToDiagramCommand <PSMClass, PSMElementViewHelper> c2 = ElementToDiagramCommandFactory <PSMClass, PSMElementViewHelper> .Factory().Create(Controller) as ElementToDiagramCommand <PSMClass, PSMElementViewHelper>;

                c2.IncludedElement = Child;
                Commands.Add(c2);
            }
            else //Connecting existing root
            {
                Child.Element = T.RootClass;
                RemovePSMClassFromRootsCommand c = RemovePSMClassFromRootsCommandFactory.Factory().Create(Controller) as RemovePSMClassFromRootsCommand;
                c.Set(Child);
                Commands.Add(c);
            }

            #endregion

            #region PSM Association

            #region Path generation
            //Prepare path for NestingJoin - Path from child to parent consisting of AssociationEnds (PIMSteps)
            List <NestingJoinStep> Path = new List <NestingJoinStep>();
            uint?Lower = 1;
            NUml.Uml2.UnlimitedNatural Upper = 1;
            TreeClasses t = T;
            while (t.ParentTC != null)
            {
                Path.Add(new NestingJoinStep()
                {
                    Association = t.Association, End = t.PIMClass, Start = t.ParentTC.PIMClass
                });
                Lower *= t.Lower;
                if (t.Upper.IsInfinity)
                {
                    Upper = NUml.Uml2.UnlimitedNatural.Infinity;
                }
                else if (!Upper.IsInfinity)
                {
                    Upper = Upper.Value * t.Upper.Value;
                }
                t = t.ParentTC;
            }

            #endregion

            //Add PSMAssociation connecting the parent to the PSMClass
            Commands.Add(new HolderConvertorCommand <PSMClass, PSMAssociationChild>(Child, ChildAssociation));
            NewPSMAssociationCommand c3 = NewPSMAssociationCommandFactory.Factory().Create(Controller.ModelController) as NewPSMAssociationCommand;
            c3.Set(new ElementHolder <PSMSuperordinateComponent>()
            {
                Element = SourcePSMClass
            }, ChildAssociation, AssociationHolder, null);

            //Set PSM association multiplicity
            c3.Upper = Upper;
            c3.Lower = Lower;
            c3.UsedGeneralizations = T.UsedGeneralizations;
            Commands.Add(c3);
            #endregion

            #region Nesting join
            //Set the nestingjoin
            AddSimpleNestingJoinCommand c4 = AddSimpleNestingJoinCommandFactory.Factory().Create(Controller.ModelController) as AddSimpleNestingJoinCommand;
            c4.Set(AssociationHolder, Path);
            Commands.Add(c4);
            #endregion

            #region Association to diagram
            //Add created PSMAssociations to the diagram
            ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper> c5 = (ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper>) ElementToDiagramCommandFactory <PSMAssociation, PSMAssociationViewHelper> .Factory().Create(Controller);

            c5.IncludedElement = AssociationHolder;
            Commands.Add(c5);
            #endregion
        }