コード例 #1
0
ファイル: PIM_Association.cs プロジェクト: mff-uk/xcase
        internal IEnumerable <ContextMenuItem> AssociationMenuItems()
        {
            ContextMenuItem addCommentary = new ContextMenuItem("Add commentary");

            addCommentary.Icon   = ContextMenuIcon.GetContextIcon("comment");
            addCommentary.Click += delegate
            {
                NewModelCommentToDiagramCommand command = (NewModelCommentToDiagramCommand)CommandFactoryBase <NewModelCommentaryToDiagramCommandFactory> .Factory().Create(Controller.DiagramController);

                command.AnnotatedElement = Association;
                if (Diamond != null)
                {
                    command.X = Diamond.Left + Diamond.ActualWidth + 20;
                    command.Y = Diamond.Top + 20;
                }
                else
                {
                    Point p = FindClosestPoint(simpleAssociationJunction.GetBounds().GetCenter());
                    command.X = p.X + 20;
                    command.Y = p.Y + 20;
                }
                command.Set(Controller.DiagramController.ModelController, null);
                command.Execute();
            };
            ContextMenuItem demo = new ContextMenuItem("Binding demo - show that binding to association properties works");

            demo.Click += demo_Click;
            ContextMenuItem resetLabels = new ContextMenuItem("Reset all labels position");

            resetLabels.Click += delegate { ResetAllLabelsPositions(); };

            ContextMenuItem switchDiamond = new ContextMenuItem("Switch diamond ");

            switchDiamond.Click += delegate
            {
                ViewController.SwitchAssociationDiamond(ViewHelper, Association, Controller.DiagramController);
            };

            return(new[]
            {
                resetLabels,
                                                #if DEBUG
                demo,
                                                #endif
                addCommentary,
                switchDiamond
            });
        }
コード例 #2
0
        /// <summary>
        /// Returns context menu items.
        /// </summary>
        /// <returns></returns>
        internal IEnumerable <ContextMenuItem> GeneralizationMenuItems()
        {
            ContextMenuItem addCommentary = new ContextMenuItem("Add commentary");

            addCommentary.Click += delegate
            {
                NewModelCommentToDiagramCommand command = (NewModelCommentToDiagramCommand)CommandFactoryBase <NewModelCommentaryToDiagramCommandFactory> .Factory().Create(Controller.DiagramController);

                command.AnnotatedElement = Generalization;

                Point p = JunctionGeometryHelper.FindClosestPoint(GeneralizationJunction, GeneralizationJunction.GetBounds().GetCenter());
                command.X = p.X + 20;
                command.Y = p.Y + 20;

                command.Set(Controller.DiagramController.ModelController, null);
                command.Execute();
            };
            return(new ContextMenuItem[] { addCommentary });
        }
コード例 #3
0
ファイル: ReverseEngineering.cs プロジェクト: mff-uk/xcase
        void GeneratePSM(I_PSMHasChildren current)
        {
            foreach (I_PSMHasParent child in current.Children)
            {
                //TODO: Macrocommand
                if (child is P_PSMClass)
                {
                    //UPDATE GUI: This is wrong, but better than crash due to detected deadlock:
                    X.l.Content = (++currentClassCount).ToString() + "/" + X.ClassesCount.ToString() + " PSM Classes";
                    X.p.Value   = currentClassCount;
                    if (currentClassCount % (Math.Min(25, X.ClassesCount / 10) + 1) == 0)
                    {
                        Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
                    }

                    P_PSMClass C = child as P_PSMClass;
                    ElementHolder <PSMClass> hldPSMClass = new ElementHolder <PSMClass>();
                    NewPSMClassCommand       c0          = NewPSMClassCommandFactory.Factory().Create(DiagramController.ModelController) as NewPSMClassCommand;
                    c0.RepresentedClass = tempPIMClass;
                    c0.CreatedClass     = hldPSMClass;
                    c0.Execute();
                    C.Super = hldPSMClass.Element;
                    //TODO commandy
                    hldPSMClass.Element.Name        = C.Name.Name;
                    hldPSMClass.Element.ElementName = C.ElementLabel;

                    PSMClassToDiagram_ModelCommand c1_1 = PSMClassToDiagram_ModelCommandFactory.Factory().Create(DiagramController.ModelController) as PSMClassToDiagram_ModelCommand;
                    c1_1.Set(hldPSMClass, new HolderBase <PSMDiagram>(DiagramController.Diagram as PSMDiagram));
                    c1_1.Execute();

                    //Attributes
                    foreach (P_PSMAttribute A in C.Attributes)
                    {
                        NewAttributeCommand c5 = NewAttributeCommandFactory.Factory().Create(DiagramController.ModelController) as NewAttributeCommand;
                        c5.Owner   = C.Super as PSMClass;
                        c5.Name    = A.Alias;
                        c5.Default = A.DefaultValue;
                        c5.Lower   = A.Lower;
                        c5.Upper   = A.Upper;
                        ElementHolder <Property> h = new ElementHolder <Property>();
                        c5.createdAttributeHolder = h;
                        //Model.SimpleDataType T = DiagramController.Project.Schema..
                        //c5.Type.Element  //XmlSchemaType.GetBuiltInSimpleType(A.type);
                        c5.Execute();
                        (h.Element as PSMAttribute).Alias = A.Alias;
                    }

                    if (current is P_PSMDiagram)
                    {
                        AddPSMClassToRoots_ModelCommand c1 = AddPSMClassToRoots_ModelCommandFactory.Factory().Create(DiagramController.ModelController) as AddPSMClassToRoots_ModelCommand;
                        c1.Set(hldPSMClass, new HolderBase <PSMDiagram>(DiagramController.Diagram as PSMDiagram));
                        c1.Execute();
                    }
                    else
                    {
                        if (C.ExtensionOf != null)
                        {
                            NewPSMSpecializationCommand c2s = NewPSMSpecializationCommandFactory.Factory().Create(DiagramController.ModelController) as NewPSMSpecializationCommand;
                            c2s.GeneralPSMClass = new ElementHolder <PSMClass>()
                            {
                                Element = (current as P_PSMClass).Super as PSMClass
                            };
                            c2s.SpecificPSMClass = new ElementHolder <PSMClass>()
                            {
                                Element = C.Super as PSMClass
                            };
                            ElementHolder <Generalization> hldGeneralization = new ElementHolder <Generalization>();
                            c2s.CreatedGeneralization = hldGeneralization;
                            c2s.Execute();

                            ElementToDiagramCommand <Generalization, GeneralizationViewHelper> c5s = (ElementToDiagramCommand <Generalization, GeneralizationViewHelper>) ElementToDiagramCommandFactory <Generalization, GeneralizationViewHelper> .Factory().Create(DiagramController);

                            c5s.IncludedElement = hldGeneralization;
                            c5s.Execute();
                        }
                        else
                        {
                            NewPSMAssociationCommand       c2       = NewPSMAssociationCommandFactory.Factory().Create(DiagramController.ModelController) as NewPSMAssociationCommand;
                            ElementHolder <PSMAssociation> hldAssoc = new ElementHolder <PSMAssociation>();
                            c2.Lower = C.MinOccurs;
                            c2.Upper = C.MaxOccurs;
                            c2.Set((current as P_PSMBase).Super, hldPSMClass.Element, hldAssoc, null);
                            c2.Execute();

                            ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper> c5 = (ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper>) ElementToDiagramCommandFactory <PSMAssociation, PSMAssociationViewHelper> .Factory().Create(DiagramController);

                            c5.IncludedElement = hldAssoc;
                            c5.Execute();
                        }
                    }
                    GeneratePSM(C);
                }
                else if (!(current is P_PSMDiagram) && child is P_PSMContentChoice)
                {
                    NewPSMContentChoiceCommand c3 = NewPSMContentChoiceCommandFactory.Factory().Create(DiagramController) as NewPSMContentChoiceCommand;
                    c3.Parent = (current as P_PSMBase).Super;
                    c3.Execute();
                    (child as P_PSMContentChoice).Super = c3.CreatedChoice.Element;
                    GeneratePSM(child as P_PSMContentChoice);
                }
                else if (!(current is P_PSMDiagram) && child is P_PSMAttributeContainer)
                {
                    NewPSMAttributeContainerCommand c4 = NewPSMAttributeContainerCommandFactory.Factory().Create(DiagramController) as NewPSMAttributeContainerCommand;

                    PSMClass owner = null;
                    if (current is P_PSMClass)
                    {
                        owner = c4.PSMClass = (current as P_PSMClass).Super as PSMClass;
                    }
                    else if (current is P_PSMContentChoice)
                    {
                        c4.PSMSuper = (current as P_PSMContentChoice).Super as PSMSuperordinateComponent;
                        owner       = c4.PSMClass = (current as P_PSMContentChoice).P_PSMClass.Super as PSMClass;
                    }
                    else if (current is P_PSMContentContainer)
                    {
                        c4.PSMSuper = (current as P_PSMContentContainer).Super as PSMSuperordinateComponent;
                        owner       = c4.PSMClass = (current as P_PSMContentContainer).P_PSMClass.Super as PSMClass;
                    }

                    foreach (P_PSMAttribute A in (child as P_PSMAttributeContainer).Attributes)
                    {
                        NewAttributeCommand c5 = NewAttributeCommandFactory.Factory().Create(DiagramController.ModelController) as NewAttributeCommand;
                        c5.Owner   = owner;
                        c5.Name    = A.Alias;
                        c5.Default = A.DefaultValue;
                        c5.Lower   = A.Lower;
                        c5.Upper   = A.Upper;
                        ElementHolder <Property> h = new ElementHolder <Property>();
                        c5.createdAttributeHolder = h;
                        c5.Execute();
                        (h.Element as PSMAttribute).Alias = A.Alias;
                        c4.PSMAttributes.Add(h.Element as PSMAttribute);
                    }
                    c4.Execute();
                }
                else if ((current is P_PSMClass) && child is P_PSMComment)
                {
                    NewModelCommentToDiagramCommand C = NewModelCommentaryToDiagramCommandFactory.Factory().Create(DiagramController) as NewModelCommentToDiagramCommand;
                    C.AnnotatedElement = (current as P_PSMClass).Super;
                    C.Text             = (child as P_PSMComment).text;
                    C.Set(DiagramController.ModelController, DiagramController.ModelController.Model);
                    C.Execute();
                }
                else if (!(current is P_PSMDiagram) && child is P_PSMContentContainer)
                {
                    P_PSMContentContainer         CC = child as P_PSMContentContainer;
                    NewPSMContentContainerCommand C  = NewPSMContentContainerCommandFactory.Factory().Create(DiagramController) as NewPSMContentContainerCommand;
                    if (current is P_PSMBase)
                    {
                        C.Parent = (current as P_PSMBase).Super;
                    }
                    C.Name = CC.ElementLabel;
                    C.Execute();
                    CC.Super = C.CreatedContainer.Element;

                    GeneratePSM(CC);
                }
            }
        }