Exemplo n.º 1
0
        public void InitializeCommand(PSMAttributeContainer attributeContainer, IEnumerable <PSMAttribute> attributes)
        {
            MoveAttributesFromAttributeContainerBackToClassCommand command = (MoveAttributesFromAttributeContainerBackToClassCommand)MoveAttributesFromAttributeContainerBackToClassCommandFactory.Factory().Create(Controller);

            command.AttributeContainer = attributeContainer;
            command.Attributes.AddRange(attributes);
            Commands.Add(command);

            if (attributeContainer.PSMAttributes.All(attribute => attributes.Contains(attribute)))
            {
                OkCancelDialog dialog = new OkCancelDialog();
                dialog.PrimaryContent      = "Attribute container is empty.";
                dialog.Title               = "Attribute container is empty";
                dialog.SecondaryContent    = "Attribute container is now empty. Do you wish to remove the container now? ";
                dialog.OkButtonContent     = "Delete";
                dialog.CancelButtonContent = "Leave";

                if (dialog.ShowDialog() == true)
                {
                    DeleteFromPSMDiagramCommand leavecommand = (DeleteFromPSMDiagramCommand)DeleteFromPSMDiagramCommandFactory.Factory().Create(Controller);
                    leavecommand.DeletedElements = new[] { attributeContainer };
                    Commands.Add(leavecommand);
                }
            }
        }
Exemplo n.º 2
0
        internal override void CommandOperation()
        {
            movedChilds = new PSMAssociationChild[UnionLeftOut.Components.Count];
            UnionLeftOut.Components.CopyTo(movedChilds, 0);

            foreach (PSMAssociationChild child in movedChilds)
            {
                UnionLeftOut.Components.Remove(child);
                ((PSMDiagram)Diagram).Roots.Add((PSMClass)child);
            }

            delCmd = DeleteFromPSMDiagramCommandFactory.Factory().Create(Controller) as DeleteFromPSMDiagramCommand;
            delCmd.DeletedElements = new List <Element>();
            delCmd.DeletedElements.Add(UnionLeftOut.ParentAssociation);
            delCmd.DeletedElements.Add(UnionLeftOut);
            delCmd.CommandOperation();
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public void Set(PSMClassUnion classUnion, IEnumerable <PSMAssociation> associations)
        {
            AddedAssociations.AddRange(associations);
            ClassUnion = classUnion;

            ElementHolder <PSMAssociation> leadingAssociationHolder = new ElementHolder <PSMAssociation>(ClassUnion.ParentAssociation);
            ElementHolder <PSMClassUnion>  unionHolder = new ElementHolder <PSMClassUnion>(ClassUnion);

            CopyNestingJoinsCommand c3 = CopyNestingJoinsCommandFactory.Factory().Create(Controller.ModelController) as CopyNestingJoinsCommand;

            c3.Set(leadingAssociationHolder, AddedAssociations);
            this.Commands.Add(c3);

            /*GetClassUnionContentCommand c4 = GetClassUnionContentCommandFactory.Factory().Create(Controller.ModelController) as GetClassUnionContentCommand;
             * c4.Set(joinedAssociations, CreatedUnion);
             * Commands.Add(c4);*/

            DeleteFromPSMDiagramCommand delCommand = DeleteFromPSMDiagramCommandFactory.Factory().Create(Controller) as DeleteFromPSMDiagramCommand;

            delCommand.DeletedElements = new List <Element>(AddedAssociations.Cast <Element>());
            delCommand.CheckOrdering   = false;
            Commands.Add(delCommand);

            PutClassesToUnionCommand c4 = PutClassesToUnionCommandFactory.Factory().Create(Controller.ModelController) as PutClassesToUnionCommand;

            c4.Set(AddedAssociations, unionHolder);
            Commands.Add(c4);

            foreach (PSMAssociation assoc in AddedAssociations)
            {
                PSMClassUnion union = assoc.Child as PSMClassUnion;
                if (union != null)
                {
                    MoveClassUnionContentCommand moveCommand = MoveClassUnionContentCommandFactory.Factory().Create(Controller) as MoveClassUnionContentCommand;
                    moveCommand.Set(union, unionHolder);
                    Commands.Add(moveCommand);
                    DeleteFromPSMDiagramCommand delUnion = DeleteFromPSMDiagramCommandFactory.Factory().Create(Controller) as DeleteFromPSMDiagramCommand;
                    delUnion.DeletedElements = new List <Element>();
                    delUnion.DeletedElements.Add(union);
                    Commands.Add(delUnion);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Tells the command which elements to delete. The method uses
        /// interactive dialogs to specify the initial set of delted elements and
        /// to ask whether to delete unused elements from the model.
        /// </summary>
        /// <param name="deletedElements">set of deleted elements</param>
        public void InitializeCommand(IEnumerable <Element> deletedElements)
        {
            List <Element>                _deleted     = new List <Element>(deletedElements);
            ElementDependencies           dependencies = ElementDependencies.FindPSMDependencies(deletedElements);
            DeleteDependentElementsDialog dialog       = new DeleteDependentElementsDialog(dependencies);

            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);
                    }
                }
                foreach (KeyValuePair <Element, bool> _flag in dependencies.Flags)
                {
                    if (_flag.Value)
                    {
                        foreach (Element element in dependencies[_flag.Key])
                        {
                            if (!_deleted.Contains(element))
                            {
                                _deleted.Add(element);
                            }
                        }
                    }
                }

                DeleteFromPSMDiagramCommand command = (DeleteFromPSMDiagramCommand)DeleteFromPSMDiagramCommandFactory.Factory().Create(Controller);
                command.DeletedElements = _deleted;
                Commands.Add(command);
            }
        }
Exemplo n.º 6
0
        internal override void CommandOperation()
        {
            // The context of each new association includes the entire context of the previous
            // created association + Parent path of the nesting join of the previous association
            // Therefore we progressively cumulate it in this collection.
            List <PIMPath> context = new List <PIMPath>();

            for (int i = 0; i < Associations.Count; ++i)
            {
                // Get a reference to Ai and Ai+1 if defined.
                PSMAssociation association     = Associations[i];
                PSMAssociation nextAssociation = null;
                if (i < Associations.Count - 1)
                {
                    nextAssociation = Associations[i + 1];
                }

                // Remove Ai from the model
                DeleteFromPSMDiagramCommand cmdDel = DeleteFromPSMDiagramCommandFactory.Factory().Create(Controller) as DeleteFromPSMDiagramCommand;
                cmdDel.DeletedElements = new List <Element>();
                cmdDel.DeletedElements.Add(association);
                cmdDel.CommandOperation();
                deletedAssociations.Add(cmdDel);

                // Create a new PSM association A'i
                NewPSMAssociationCommand cmdNew = NewPSMAssociationCommandFactory.Factory().Create(
                    Controller.ModelController) as NewPSMAssociationCommand;
                PSMAssociationChild child = (nextAssociation == null ? GroupedClass : nextAssociation.Child);
                cmdNew.Set((PSMClass)association.Child, child, null, null);
                cmdNew.CommandOperation();
                PSMAssociation newAssociation = cmdNew.CreatedAssociation.Element;
                createdAssociations.Add(cmdNew);

                // Create a nesting join for the new association A'i, all the nesting joins
                // of the associations A1..n will have the GroupedClass as their CoreClass.
                NestingJoin nj = newAssociation.AddNestingJoin(GroupedClass.RepresentedClass);

                // Copy the parent path of the nesting join of Ai to the parent
                // path of A'i and reverse it.
                IEnumerable <PIMStep> revPath = association.NestingJoins[0].Parent.Steps.Reverse();
                foreach (PIMStep step in revPath)
                {
                    nj.Parent.AddStep(step.End, step.Start, step.Association);
                }


                // If Ai+1 is defined then copy its Parent path to the Child path of A'i
                // and reverse it. Set the A'i ending to the child of Ai+1.
                // Thus, the A'i association will look as follows
                //  - A'i: Ai.Child -> Ai+1.Child
                //  - Nesting join: GroupedClass[Ai.ParentPath(reversed) -> Ai+1.ParentPath(reversed)]
                //
                // If Ai+1 is not defined, A'i will end at the GroupedClass and will look as follows
                //  - A'i: Ai.Child -> GroupedClass
                //  - Nesting join: GroupedClass[Ai.ParentPath(reversed) -> .]
                if (nextAssociation != null)
                {
                    revPath = nextAssociation.NestingJoins[0].Parent.Steps.Reverse();
                    foreach (PIMStep step in revPath)
                    {
                        nj.Child.AddStep(step.End, step.Start, step.Association);
                    }
                }

                // Set the context of A'i as a collection of all the parent paths of A'1 .. A'i-1
                foreach (PIMPath path in context)
                {
                    PIMPath newPath = nj.AddContextPath();
                    foreach (PIMStep step in path.Steps)
                    {
                        newPath.AddStep(step.Start, step.End, step.Association);
                    }
                }

                // Add the parent path of A'i to the temporal collection to enable it for A'i+1
                context.Add(nj.Parent);

                // Put A'i on the diagram
                ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper> cmdToDiag =
                    ElementToDiagramCommandFactory <PSMAssociation, PSMAssociationViewHelper> .Factory().Create(Controller)
                    as ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper>;

                cmdToDiag.IncludedElement = new Helpers.ElementHolder <PSMAssociation>(newAssociation);
                cmdToDiag.CommandOperation();
                visualizedAssociations.Add(cmdToDiag);
            }

            // If the grouped class was previously a root of the PSM diagram
            // replace it with the topmost grouping class.
            rootIndex = GroupedClass.Diagram.Roots.IndexOf(GroupedClass);
            if (rootIndex != -1)
            {
                newRoot = Associations[0].Child as PSMClass;
                GroupedClass.Diagram.Roots[rootIndex] = newRoot;
            }
        }
        /// <summary>
        /// Sets this command for use.
        /// </summary>
        /// <param name="parent">Reference to the PSM component that is the root of joined associations</param>
        /// <param name="joinedAssociations">List of associations to be joined to one class union</param>
        public void Set(PSMSuperordinateComponent parent, IEnumerable <PSMAssociation> joinedAssociations)
        {
            JoinedAssociations = new List <PSMAssociation>(joinedAssociations);

            PSMSubordinateComponent first = parent.Components.First(assoc => JoinedAssociations.Contains(assoc as PSMAssociation));
            int?index = parent.Components.IndexOf(first);


            if (ParentHolder == null)
            {
                ParentHolder = new Helpers.ElementHolder <PSMSuperordinateComponent>();
            }
            ParentHolder.Element = parent;

            if (CreatedUnion == null)
            {
                CreatedUnion = new Helpers.ElementHolder <PSMClassUnion>();
            }

            if (CreatedAssocChild == null)
            {
                CreatedAssocChild = new Helpers.ElementHolder <PSMAssociationChild>();
            }

            if (CreatedAssociationHolder == null)
            {
                CreatedAssociationHolder = new Helpers.ElementHolder <PSMAssociation>();
            }

            NewPSMClassUnionCommand c1 = NewPSMClassUnionCommandFactory.Factory().Create(Controller) as NewPSMClassUnionCommand;

            c1.CreatedUnion = CreatedUnion;
            c1.Parent       = parent;
            Commands.Add(c1);

            Helpers.HolderConvertorCommand <PSMClassUnion, PSMAssociationChild> cc =
                new Commands.Helpers.HolderConvertorCommand <PSMClassUnion, PSMAssociationChild>(CreatedUnion,
                                                                                                 CreatedAssocChild);
            Commands.Add(cc);

            NewPSMAssociationCommand newAssocCommand = NewPSMAssociationCommandFactory.Factory().Create(Controller.ModelController) as NewPSMAssociationCommand;

            newAssocCommand.Set(ParentHolder, CreatedAssocChild, CreatedAssociationHolder, index);
            Commands.Add(newAssocCommand);

            CopyNestingJoinsCommand copyNJcommand = CopyNestingJoinsCommandFactory.Factory().Create(Controller.ModelController) as CopyNestingJoinsCommand;

            copyNJcommand.Set(CreatedAssociationHolder, JoinedAssociations);
            Commands.Add(copyNJcommand);

            /*GetClassUnionContentCommand c4 = GetClassUnionContentCommandFactory.Factory().Create(Controller.ModelController) as GetClassUnionContentCommand;
             * c4.Set(joinedAssociations, CreatedUnion);
             * Commands.Add(c4);*/

            PutClassesToUnionCommand putCommand = PutClassesToUnionCommandFactory.Factory().Create(Controller.ModelController) as PutClassesToUnionCommand;

            putCommand.Set(joinedAssociations, CreatedUnion);
            Commands.Add(putCommand);

            DeleteFromPSMDiagramCommand delCommand = DeleteFromPSMDiagramCommandFactory.Factory().Create(Controller) as DeleteFromPSMDiagramCommand;

            delCommand.DeletedElements = new List <Element>(JoinedAssociations.Cast <Element>());
            delCommand.CheckOrdering   = false;
            Commands.Add(delCommand);

            foreach (PSMAssociation assoc in joinedAssociations)
            {
                PSMClassUnion union = assoc.Child as PSMClassUnion;
                if (union != null)
                {
                    MoveClassUnionContentCommand moveCommand = MoveClassUnionContentCommandFactory.Factory().Create(Controller) as MoveClassUnionContentCommand;
                    moveCommand.Set(union, CreatedUnion);
                    Commands.Add(moveCommand);
                    DeleteFromPSMDiagramCommand delUnion = DeleteFromPSMDiagramCommandFactory.Factory().Create(Controller) as DeleteFromPSMDiagramCommand;
                    delUnion.DeletedElements = new List <Element>();
                    delUnion.DeletedElements.Add(union);
                    Commands.Add(delUnion);
                }
            }

            ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper> includeAssociation = (ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper>) ElementToDiagramCommandFactory <PSMAssociation, PSMAssociationViewHelper> .Factory().Create(Controller);

            includeAssociation.IncludedElement = CreatedAssociationHolder;
            Commands.Add(includeAssociation);
        }