Exemple #1
0
 /// <summary>
 /// Handles diagram removing event invoked by Projects window
 /// </summary>
 internal void DiagramRemoveHandler(object sender, DiagramDClickArgs arg)
 {
     if (arg.Diagram is PIMDiagram)
     {
         RemoveDiagramCommand removeDiagramCommand = (RemoveDiagramCommand)RemoveDiagramCommandFactory.Factory().Create(arg.Diagram.Project.GetModelController());
         removeDiagramCommand.Set(arg.Diagram.Project, arg.Diagram);
         removeDiagramCommand.Execute();
     }
     else if (arg.Diagram is PSMDiagram)
     {
         PanelWindow Tab = FindTab(arg.Diagram);
         if (Tab != null)
         {
             RemovePSMDiagramMacroCommand c = (RemovePSMDiagramMacroCommand)RemovePSMDiagramMacroCommandFactory.Factory().Create(arg.Diagram.Project.GetModelController());
             c.Set(arg.Diagram.Project, arg.Diagram as PSMDiagram, Tab.xCaseDrawComponent.Canvas.Controller);
             if (c.Commands.Count > 0)
             {
                 c.Execute();
             }
         }
         else
         {
             RemovePSMDiagramMacroCommand c = (RemovePSMDiagramMacroCommand)RemovePSMDiagramMacroCommandFactory.Factory().Create(MainWindow.CurrentProject.GetModelController());
             c.Set(arg.Diagram.Project, arg.Diagram as PSMDiagram, new DiagramController(arg.Diagram as PSMDiagram, MainWindow.CurrentProject.GetModelController()));
             if (c.Commands.Count > 0)
             {
                 c.Execute();
             }
         }
     }
     else
     {
         throw new NotImplementedException("Unknown diagram type");
     }
 }
Exemple #2
0
        /// <summary>
        /// Adds a new tab to the tab panel, associated with given <paramref name="diagram"/>
        /// <param name="diagram">Diagram to which the new tab should be bound</param>
        /// </summary>
        internal PanelWindow AddTab(Diagram diagram)
        {
            PanelWindow newTab = new PanelWindow();

            if (diagram is PIMDiagram)
            {
                newTab.xCaseDrawComponent.Canvas.InitializeRegistrationSet(MainWindow.PIMRepresentantsSet);
            }
            if (diagram is PSMDiagram)
            {
                newTab.xCaseDrawComponent.Canvas.InitializeRegistrationSet(MainWindow.PSMRepresentantsSet);
            }

            newTab.BindToDiagram(diagram, diagram.Project.GetModelController());
            newTab.xCaseDrawComponent.Canvas.SelectedItems.CollectionChanged += SelectedItems_CollectionChanged;

            ActivePane.Items.Add(newTab);
            ActivePane.UpdateLayout();
            //ActivePane.BringHeaderToFront(newTab);
            dockManager.ActiveDocument = newTab;
            #if DEBUG
            newTab.BindToLogWIndow(MainWindow.logWindow);
            #endif
            return(newTab);
        }
Exemple #3
0
        internal void project_DiagramRemoved(object sender, DiagramEventArgs e)
        {
            PanelWindow tab = FindTab(e.Diagram);

            if (tab != null)
            {
                RemoveTab(tab);
            }
        }
Exemple #4
0
        /// <summary>
        /// Invokes <see cref="ActiveDiagramChanged"/> event.
        /// </summary>
        /// <param name="panelWindow">New active panel window</param>
        internal void InvokeActiveDiagramChanged(PanelWindow panelWindow)
        {
            ActiveDiagramChangedEventHandler temp = ActiveDiagramChanged;

            if (temp != null)
            {
                temp(panelWindow);
            }
        }
Exemple #5
0
        public XCaseCanvas GetDiagramView(Diagram diag)
        {
            PanelWindow w = FindTab(diag);

            if (w != null)
            {
                return(w.xCaseDrawComponent.Canvas);
            }
            return(null);
        }
Exemple #6
0
        private void OnActiveDiagramChanged(PanelWindow panelWindow)
        {
            if (panelWindow != null)
            {
                Project diagramProject = panelWindow.xCaseDrawComponent.Canvas.Diagram.Project;
                if (diagramProject != CurrentProject)
                {
                    CurrentProject = diagramProject;
                }
            }

            if (panelWindow != null && panelWindow.xCaseDrawComponent.Canvas.Diagram != null)
            {
                //if (panelWindow.xCaseDrawComponent.Canvas.Diagram is PSMDiagram)
                //    View.TreeLayout.SwitchOff();
                ActiveDiagram = panelWindow.xCaseDrawComponent.Canvas;
                Debug.WriteLine("ActiveDiagramChanged (" + ActiveDiagram.Diagram.Caption + ")");
            }
            else
            {
                ActiveDiagram = null;
                Debug.WriteLine("ActiveDiagramChanged (null)");
            }

            navigatorWindow.ActiveDiagram  = ActiveDiagram;
            propertiesWindow.ActiveDiagram = ActiveDiagram;

            InvokeDiagramSelectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));

            UIElement[] pimMenus = new UIElement[] { PIMmenu, AlignmentMenu, PIMDeleteMenu, DeriveMenu };
            UIElement[] psmMenus = new UIElement[] { PSMmenuClass, PSMmenuElements, OrderingMenu, PSMDeleteMenu, bXMLSchema, bSampleDocument, ReverseMenu };

            bool showPIMMenus = ActiveDiagram != null && ActiveDiagram.Diagram != null && ActiveDiagram.Diagram is PIMDiagram;
            bool showPSMMenus = ActiveDiagram != null && ActiveDiagram.Diagram != null && ActiveDiagram.Diagram is PSMDiagram;

            foreach (UIElement menu in pimMenus)
            {
                menu.Visibility = showPIMMenus ? Visibility.Visible : Visibility.Collapsed;
            }
            foreach (UIElement menu in psmMenus)
            {
                menu.Visibility = showPSMMenus ? Visibility.Visible : Visibility.Collapsed;
            }

            if (ActiveDiagram != null)
            {
                ActiveDiagram.SelectedItems.CollectionChanged += navigatorWindow.SelectedItems_CollectionChanged;
            }

            // I am hiding the reverse menu in release versions for now
            #if DEBUG
            #else
            ReverseMenu.Visibility = Visibility.Collapsed;
            #endif
        }
 /// <summary>
 /// Closes given PanelWindow
 /// </summary>
 /// <param name="tab">PanelWindow to be closed</param>
 internal void RemoveTab(PanelWindow tab)
 {
     if (dockManager.ActiveDocument == tab)
     {
         MainWindow.ActiveDiagram.Unbind();
     }
     tab.Close();
     if (dockManager.ActiveDocument == null && dockManager.Documents.Count() > 0)
     {
         dockManager.ActiveDocument = dockManager.Documents.Last();
     }
     //InvokeActiveDiagramChanged(dockManager.ActiveDocument as PanelWindow);
 }
Exemple #8
0
 /// <summary>
 /// Closes active PanelWindow
 /// </summary>
 internal void RemoveActiveTab()
 {
     if (dockManager.ActiveDocument != null)
     {
         int         index = dockManager.MainDocumentPane.Items.IndexOf(dockManager.ActiveDocument);
         PanelWindow pw    = dockManager.ActiveDocument as PanelWindow;
         if (pw != null)
         {
             RemoveTab(pw);
         }
         else
         {
             (dockManager.ActiveDocument as DocumentContent).Close();
         }
     }
 }
Exemple #9
0
        /// <summary>
        /// Activates given diagram and selects given element on it (used from Properties window)
        /// </summary>
        /// <param name="diagram"></param>
        /// <param name="selectedElement"></param>
        public void ActivateDiagramWithElement(Diagram diagram, Element selectedElement)
        {
            PanelWindow tab = ActivateDiagram(diagram);

            tab.xCaseDrawComponent.Canvas.SelectedItems.SetSelection();

            if (selectedElement != null)
            {
                IModelElementRepresentant r = tab.xCaseDrawComponent.Canvas.ElementRepresentations[selectedElement];
                if (r != null && r is ISelectable)
                {
                    tab.xCaseDrawComponent.Canvas.SelectedItems.SetSelection((ISelectable)r);
                }
            }

            MainWindow.InvokeActiveDiagramChanged(tab);
        }
Exemple #10
0
        /// <summary>
        /// Activates a diagram
        /// </summary>
        /// <param name="diagram">Diagram to be activated</param>
        public PanelWindow ActivateDiagram(Diagram diagram)
        {
            PanelWindow Tab = FindTab(diagram);

            if (Tab == null)
            {
                if (diagram is PSMDiagram)
                {
                    View.TreeLayout.SwitchOff();
                }
                Tab = AddTab(diagram);
                MainWindow.propertiesWindow.BindDiagram(ref MainWindow.dockManager);
            }
            else
            {
                dockManager.ActiveDocument = Tab;
                Tab.xCaseDrawComponent.Canvas.SelectedItems.CollectionChanged += SelectedItems_CollectionChanged;
            }

            Tab.BringDocumentHeaderToView();
            return(Tab);
        }
Exemple #11
0
        //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();
        }
Exemple #12
0
        /// <summary>
        /// Handles diagram renaming event invoked by Projects window
        /// </summary>
        internal void DiagramRenameHandler(object sender, DiagramRenameArgs arg)
        {
            PanelWindow tab = FindTab(arg.Diagram);

            tab.RenameDiagram(arg.NewCaption);
        }