コード例 #1
0
        public override void Execute(object parameter)
        {
            PSM_Class psmClass = (PSM_Class)ActiveDiagramView.SelectedItems.Single();

            SelectAttributesDialog dialog = new SelectAttributesDialog
            {
                ShowAliasTextBox = false,
                PSMElementsOnly  = true,
                MessageText      = "Select attributes you wish to move to an attribute container:",
                Element          = psmClass.ClassController.Class
            };

            if (dialog.ShowDialog() == true)
            {
                NewPSMAttributeContainerCommand c = (NewPSMAttributeContainerCommand)NewPSMAttributeContainerCommandFactory.Factory().Create(ActiveDiagramView.Controller);
                c.PSMClass = (PSMClass)(psmClass.Controller.Element);
                c.PSMAttributes.AddRange(dialog.SelectedPSMAttributes);
                c.Execute();
            }
        }
コード例 #2
0
ファイル: PanelWindow.xaml.cs プロジェクト: mff-uk/xcase
        //public void DrawPSMExample(int x, int y)
        //{
        //    PIM_Class clPurchase, clCustomer1, clCustomer2, clShop,
        //        clDealer, clItem, clAddress, clProduct, clRegion;
        //    XCaseAttributeContainer acCustomer1, acCustomer2,
        //        acAddress, acRegion, acProduct, acItem;
        //    XCaseAssociationChoice asc1, asc2;
        //    XCaseAssociationContainer ascoItems;
        //    List<string> prPurchase = new List<string>() { "date" },
        //        prShop = new List<string>() { "shop-number" },
        //        prDealer = new List<string>() { "dealer-number" },
        //        prProduct = new List<string>() { "product-number" },
        //        atCustomer1 = new List<string>() { "customer-number" },
        //        atCustomer2 = new List<string>() { "name", "email" },
        //        atAddress = new List<string>() { "street", "postcode", "city" },
        //        atRegion = new List<string>() { "name AS region" },
        //        atProduct = new List<string>() { "unit-price", "title" },
        //        atItem = new List<string>() { "amount" };

        //    clPurchase = AddClass("Purchase", null, "purchase", prPurchase, null, 364 + x, 65 + y);
        //    clCustomer1 = AddClass("Customer", null, null, null, null, 51 + x, 256 + y);
        //    clCustomer2 = AddClass("Customer", null, "new-customer", null, null, 172 + x, 239 + y);
        //    clShop = AddClass("Shop", null, "from-shop", prShop, null, 309 + x, 254 + y);
        //    clDealer = AddClass("Dealer", null, "from-dealer", prDealer, null, 430 + x, 229 + y);
        //    clItem = AddClass("Item", null, "item", null, null, 561 + x, 273 + y);
        //    clAddress = AddClass("Address", null, "delivery-address", null, null, 262 + x, 352 + y);
        //    clProduct = AddClass("Product", null, null, prProduct, null, 443 + x, 379 + y);
        //    clRegion = AddClass("Region", null, null, null, null, 344 + x, 460 + y);

        //    acCustomer1 = AddAttributeContainer(atCustomer1, 36 + x, 320 + y);
        //    acCustomer2 = AddAttributeContainer(atCustomer2, 153 + x, 332 + y);
        //    acAddress = AddAttributeContainer(atAddress, 193 + x, 434 + y);
        //    acRegion = AddAttributeContainer(atRegion, 353 + x, 515 + y);
        //    acProduct = AddAttributeContainer(atProduct, 468 + x, 455 + y);
        //    acItem = AddAttributeContainer(atItem, 586 + x, 364 + y);

        //    ascoItems = AddAssociationContainer("items", 532 + x, 147 + y);

        //    asc1 = AddAssociationChoice(150 + x, 150 + y);
        //    asc2 = AddAssociationChoice(395 + x, 150 + y);

        //    AddAssociation(clPurchase, asc1);
        //    AddAssociation(asc1, clCustomer1, EJunctionCapStyle.Straight, EJunctionCapStyle.FullArrow, "buyer", "0..*", "1");
        //    AddAssociation(asc1, clCustomer2, EJunctionCapStyle.Straight, EJunctionCapStyle.FullArrow, "buyer", "0..*", "1");
        //    AddAssociation(clCustomer1, acCustomer1);
        //    AddAssociation(clCustomer2, acCustomer2);
        //    AddAssociation(clCustomer2, clAddress, EJunctionCapStyle.Straight, EJunctionCapStyle.FullArrow, "deliver to", "0..1", "0..1");
        //    AddAssociation(clAddress, acAddress);
        //    AddAssociation(clAddress, clRegion, EJunctionCapStyle.Straight, EJunctionCapStyle.FullArrow, "in", "0..*", "1");
        //    AddAssociation(clRegion, acRegion);
        //    AddAssociation(clPurchase, asc2);
        //    AddAssociation(asc2, clShop, EJunctionCapStyle.Straight, EJunctionCapStyle.FullArrow, "from shop", "0..*", "1");
        //    AddAssociation(asc2, clDealer, EJunctionCapStyle.Straight, EJunctionCapStyle.FullArrow, "from dealer", "0..*", "1");
        //    AddAssociation(clPurchase, ascoItems);
        //    AddAssociation(ascoItems, clItem, EJunctionCapStyle.Straight, EJunctionCapStyle.FullArrow, "<<ordered>>\ncontained in", "1", "1..*");
        //    AddAssociation(clItem, clProduct, EJunctionCapStyle.Straight, EJunctionCapStyle.FullArrow, "purchases", "0..*", "1");
        //    AddAssociation(clProduct, acProduct);
        //    AddAssociation(clItem, acItem);
        //}

        #endregion

        public void DrawPIMPSMExample()
        {
            // prepare simple PIM diagram to start with
            RepresentationCollection ModelViewMap = xCaseDrawComponent.Canvas.ElementRepresentations;
            CreationResult <Class, ClassViewHelper> classCreationResult = DiagramController.NewClass("Region", 100, 10);
            Class     clRegion     = classCreationResult.ModelElement;
            PIM_Class clRegionView = (PIM_Class)ModelViewMap[clRegion];

            classCreationResult = DiagramController.NewClass("Address", 35, 189);
            Class     clAddress     = classCreationResult.ModelElement;
            PIM_Class clAddressView = (PIM_Class)ModelViewMap[classCreationResult.ModelElement];

            Dictionary <PIM_Class, List <string> > properties = new Dictionary <PIM_Class, List <string> >();

            properties[clRegionView] = new List <string> {
                "name", "code"
            };
            properties[clAddressView] = new List <string> {
                "street", "postcode", "city"
            };

            foreach (KeyValuePair <PIM_Class, List <string> > keyValuePair in properties)
            {
                foreach (string attribute in keyValuePair.Value)
                {
                    keyValuePair.Key.ClassController.AddNewAttribute(attribute);
                }
            }

            CreationResult <Association, AssociationViewHelper> associationCreationResult = DiagramController.NewAssociation("in", (Class)clRegionView.ModelElement, (Class)clAddressView.ModelElement);
            PIM_Association aRegionAdress = (PIM_Association)ModelViewMap[associationCreationResult.ModelElement];

            aRegionAdress.Controller.ChangeMultiplicity(aRegionAdress.Ends[0], "1");
            aRegionAdress.Controller.ChangeMultiplicity(aRegionAdress.Ends[1], "0..*");

            // derive PSM diagram
            PSMClass psmRegion = clRegionView.ClassController.DerivePSMClassToNewDiagram();

            PanelWindow p = (PanelWindow)Manager.Documents.Last();
            XCaseCanvas psmDiagramView = p.xCaseDrawComponent.Canvas;
            //ManageAttributesMacroCommand c = (ManageAttributesMacroCommand)ManageAttributesMacroCommandFactory.Factory().Create(psmDiagramView.Controller);
            PSM_Class psmRegionView = (PSM_Class)psmDiagramView.ElementRepresentations[psmRegion];

            //((PSM_ClassController)psmRegionView.Controller).IncludeAttributes(new Dictionary<Property, string> { {clRegion.Attributes[0], "RegionName"}, {clRegion.Attributes[1], "RegionCode"} });

            ViewController.MoveElement(200, 20, psmRegionView.ViewHelper, DiagramController);

            // add an attribute container

            NewPSMAttributeContainerCommand attrib = (NewPSMAttributeContainerCommand)NewPSMAttributeContainerCommandFactory.Factory().Create(psmDiagramView.Controller);

            attrib.PSMAttributes.Add(psmRegion.PSMAttributes[0]);
            attrib.PSMClass   = psmRegion;
            attrib.ViewHelper = new PSMElementViewHelper(Diagram)
            {
                X = 100, Y = 100
            };
            attrib.Execute();

            NewPSMAttributeContainerCommand attrib2 = (NewPSMAttributeContainerCommand)NewPSMAttributeContainerCommandFactory.Factory().Create(psmDiagramView.Controller);

            attrib2.PSMAttributes.Add(psmRegion.PSMAttributes[0]);
            attrib2.PSMClass   = psmRegion;
            attrib2.ViewHelper = new PSMElementViewHelper(Diagram)
            {
                X = 280, Y = 100
            };
            attrib2.Execute();

            AddPSMChildrenMacroCommand command = (AddPSMChildrenMacroCommand)AddPSMChildrenMacroCommandFactory.Factory().Create(psmDiagramView.Controller);

            command.Set(psmRegion);
            command.Execute();
        }
コード例 #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);
                }
            }
        }