Esempio n. 1
0
        /// <summary>
        /// Initializes PSM Classes Context Menus
        /// </summary>
        private void InitContextMenu()
        {
            //txtClassName.ResetContextMenu();
            txtClassName.ContextMenuOpening    += ContextMenu_ContextMenuOpening;
            txtRepresentedClassName.ContextMenu = null;
            ContextMenuItem miRemove = new ContextMenuItem("Remove");

            miRemove.Icon   = ContextMenuIcon.GetContextIcon("delete2");
            miRemove.Click += delegate { ClassController.Remove(); };
            txtClassName.ContextMenu.Items.Add(miRemove);
            txtClassName.ContextMenu.Items.Add(new Separator());

            ContextMenuItem miDeriveNew = new ContextMenuItem("Derive another class as root");

            miDeriveNew.Icon   = ContextMenuIcon.GetContextIcon("class");
            miDeriveNew.Click += delegate { ClassController.DeriveNewRootPSMClass(); };
            txtClassName.ContextMenu.Items.Add(miDeriveNew);

            ContextMenuItem miLocatePimClass = new ContextMenuItem("Find represented PIM class");

            miLocatePimClass.Icon   = ContextMenuIcon.GetContextIcon("magnifier");
            miLocatePimClass.Click += delegate {
                ClassController.FindRepresentedClass();
            };
            txtClassName.ContextMenu.Items.Add(miLocatePimClass);

            miLocateRepresentedPSMClass           = new ContextMenuItem("Find represented PSM class");
            miLocateRepresentedPSMClass.Icon      = ContextMenuIcon.GetContextIcon("magnifier");
            miLocateRepresentedPSMClass.IsEnabled = false;
            miLocateRepresentedPSMClass.Click    += delegate
            {
                if (PSMClass.IsStructuralRepresentative)
                {
                    if (PSMClass.RepresentedPSMClass.Diagram == PSMClass.Diagram)
                    {
                        XCaseCanvas.SelectElement(PSMClass.RepresentedPSMClass);
                    }
                    else
                    {
                        ClassController.FindRepresentedPSMClass();
                    }
                }
            };

            txtClassName.ContextMenu.Items.Add(miLocateRepresentedPSMClass);

            miFindStructuralRepresentatives           = new ContextMenuItem("Find Structural Representatives");
            miFindStructuralRepresentatives.Icon      = ContextMenuIcon.GetContextIcon("magnifier");
            miFindStructuralRepresentatives.IsEnabled = true;
            miFindStructuralRepresentatives.Click    += delegate
            {
                if (PSMClass.IsReferencedFromStructuralRepresentative())
                {
                    SelectItemsDialog d     = new SelectItemsDialog();
                    List <PSMClass>   items = new List <Model.PSMClass>();
                    foreach (PSMClass r in PSMClass.RepresentedClassRepresentants)
                    {
                        if (r.RepresentedPSMClass == PSMClass)
                        {
                            items.Add(r);
                        }
                    }
                    d.SetItems(items);
                    if (d.ShowDialog() == true && d.selectedObjects.Count > 0)
                    {
                        XCaseCanvas.SelectElement((PSMElement)d.selectedObjects.First());
                    }
                }
            };
            txtClassName.ContextMenu.Items.Add(miFindStructuralRepresentatives);

            miConvertToRegular        = new ContextMenuItem("Convert to regular PSM class");
            miConvertToRegular.Icon   = ContextMenuIcon.GetContextIcon("class");
            miConvertToRegular.Click +=
                delegate
            {
                SetRepresentedHighlight(false);
                ClassController.SetPSMRepresentedClass(true);
            };

            miConvertToRepresentant        = new ContextMenuItem("Convert to PSM Structural Representative");
            miConvertToRepresentant.Icon   = ContextMenuIcon.GetContextIcon("class");
            miConvertToRepresentant.Click += delegate { ClassController.SetPSMRepresentedClass(false); };

            txtClassName.ContextMenu.Items.Add(miConvertToRepresentant);
            txtClassName.ContextMenu.Items.Add(miConvertToRegular);

            txtClassName.ContextMenu.Items.Add(new Separator());

            miAbstract             = new ContextMenuItem("Abstract class");
            miAbstract.IsCheckable = true;
            miAbstract.Click      += delegate { ClassController.ChangeAbstract(!PSMClass.IsAbstract); };
            txtClassName.ContextMenu.Items.Add(miAbstract);

            miAllowAnyAttribute             = new ContextMenuItem("Allow any attribute");
            miAllowAnyAttribute.IsCheckable = true;
            miAllowAnyAttribute.Click      += delegate { ClassController.ChangeAllowAnyAttributeDefinition(!PSMClass.AllowAnyAttribute); };
            txtClassName.ContextMenu.Items.Add(miAllowAnyAttribute);

            ContextMenuItem miAutosize = new ContextMenuItem("Autosize");

            miAutosize.Click += delegate { ViewController.ResizeElement(double.NaN, double.NaN, ViewHelper, XCaseCanvas.Controller); };
            txtClassName.ContextMenu.Items.Add(miAutosize);
            txtClassName.ContextMenu.Items.Add(new Separator());

            miCollapseAttributes = new ContextMenuItem("Hide attributes")
            {
                IsCheckable = true
            };
            txtClassName.ContextMenu.Items.Add(miCollapseAttributes);
            miCollapseAttributes.Checked +=
                delegate
            {
                if (!AttributesCollapsed)
                {
                    ViewController.ChangeSectionVisibility(ViewHelper, SectionVisibilityCommand.ESectionVisibilityAction.CollapseAttributes, XCaseCanvas.Controller);
                }
            };
            miCollapseAttributes.Unchecked +=
                delegate
            {
                if (AttributesCollapsed)
                {
                    ViewController.ChangeSectionVisibility(ViewHelper, SectionVisibilityCommand.ESectionVisibilityAction.ShowAttributes, XCaseCanvas.Controller);
                }
            };

            miCollapseElementNameLabel = new ContextMenuItem("Hide element name")
            {
                IsCheckable = true
            };
            miCollapseElementNameLabel.Checked +=
                delegate
            {
                if (!ElementNameLabelCollapsed)
                {
                    ViewController.ChangeSectionVisibility(ViewHelper, SectionVisibilityCommand.ESectionVisibilityAction.CollapseElementNameLabel, XCaseCanvas.Controller);
                }
            };
            miCollapseElementNameLabel.Unchecked +=
                delegate
            {
                if (ElementNameLabelCollapsed)
                {
                    ViewController.ChangeSectionVisibility(ViewHelper, SectionVisibilityCommand.ESectionVisibilityAction.ShowElementNameLabel, XCaseCanvas.Controller);
                }
            };
            txtClassName.ContextMenu.Items.Add(miCollapseElementNameLabel);
            txtClassName.ContextMenu.Items.Add(new Separator());

            miElementNameLabelAlignRight = new ContextMenuItem("Aligned to right")
            {
                IsCheckable = true
            };
            miElementNameLabelAlignRight.Checked +=
                delegate
            {
                if (!ElementNameLabelAlignedRight)
                {
                    ViewController.ChangeElementNameLabelAlignment(ViewHelper, true, XCaseCanvas.Controller);
                }
            };

            miElementNameLabelAlignRight.Unchecked +=
                delegate
            {
                if (ElementNameLabelAlignedRight)
                {
                    ViewController.ChangeElementNameLabelAlignment(ViewHelper, false, XCaseCanvas.Controller);
                }
            };
            //txtElementNameLabel.ResetContextMenu();
            txtElementNameLabel.ContextMenu.Items.Add(miElementNameLabelAlignRight);

            txtElementNameLabel.mi_Rename.Header = "Change XML Element name...";

            ContextMenuItem miDeleteElementName = new ContextMenuItem("Delete element name");

            miDeleteElementName.Icon   = ContextMenuIcon.GetContextIcon("delete2");
            miDeleteElementName.Click += delegate { ClassController.ChangeElementName(string.Empty); };
            txtElementNameLabel.ContextMenu.Items.Add(miDeleteElementName);


            foreach (ContextMenuItem item in classAttributes.PropertiesMenuItems)
            {
                txtClassName.ContextMenu.Items.Add(item);
            }
            foreach (ContextMenuItem item in ContextMenuItems)
            {
                txtClassName.ContextMenu.Items.Add(item);
            }

            txtClassName.ContextMenu.Items.Add(new Separator());

            miGroupBy        = new ContextMenuItem("Group by...");
            miGroupBy.Click += delegate { ClassController.GroupBy(); };
            txtClassName.ContextMenu.Items.Add(miGroupBy);

            ContextMenuItem miAddChildren = new ContextMenuItem("Add children...");

            miAddChildren.Icon   = ContextMenuIcon.GetContextIcon("AddChildren");
            miAddChildren.Click += delegate { ClassController.AddChildren(); };
            txtClassName.ContextMenu.Items.Add(miAddChildren);

            ContextMenuItem miAddAttributes = new ContextMenuItem("Attributes...");

            miAddAttributes.Icon   = ContextMenuIcon.GetContextIcon("AddAttributes");
            miAddAttributes.Click += delegate { ClassController.ShowClassDialog(); };
            txtClassName.ContextMenu.Items.Add(miAddAttributes);

            txtClassName.ContextMenu.Items.Add(new Separator());

            ContextMenuItem miProperties = new ContextMenuItem("Properties...");

            miProperties.Icon   = ContextMenuIcon.GetContextIcon("props");
            miProperties.Click += delegate { ClassController.ShowClassDialog(); };
            txtClassName.ContextMenu.Items.Add(miProperties);
        }