コード例 #1
0
ファイル: M2MTransformer.cs プロジェクト: theedward/xisweb
        public static XisCollapsible CreateDetailOrRefManagerCollapsible(EA.Package package, EA.Diagram diagram, XisEntity entity,
            XisInteractionSpace parentIS, EA.Element useCase, bool isDetail, EA.Element be, string name, string searchBy = null, string orderBy = null)
        {
            XisCollapsible collapsible = new XisCollapsible(repository, diagram, parentIS, entity.Element.Name + "Collapsible");
            collapsible.SetEntityName(entity.Element.Name);

            XisCollapsibleItem collapsibleItem = new XisCollapsibleItem(repository, diagram, collapsible, collapsible.Element.Name + "Item");

            XisList list = new XisList(repository, diagram, collapsibleItem, entity.Element.Name + "List");
            list.SetEntityName(entity.Element.Name);

            XisListItem item = new XisListItem(repository, diagram, list, list.Element.Name + "Item");
            if (entity.Element.Attributes.Count > 1)
            {
                EA.Attribute first = entity.Element.Attributes.GetAt(0);
                EA.Attribute second = entity.Element.Attributes.GetAt(1);
                XisLabel lbl1 = new XisLabel(repository, item, diagram, first.Name + "Lbl");
                lbl1.SetEntityAttributeName(entity.Element.Name + "." + first.Name);
                XisLabel lbl2 = new XisLabel(repository, item, diagram, second.Name + "Lbl");
                lbl2.SetEntityAttributeName(entity.Element.Name + "." + second.Name);
            }
            else if (entity.Element.Attributes.Count == 1)
            {
                EA.Attribute attr = entity.Element.Attributes.GetAt(0);
                XisLabel lbl = new XisLabel(repository, item, diagram, attr.Name + "Lbl");
                lbl.SetEntityAttributeName(entity.Element.Name + "." + attr.Name);
            }

            if ((isDetail && ContainsUpdateDetail(useCase))
                    || (!isDetail && ContainsUpdateReference(useCase)))
            {
                string actionName = "edit" + entity.Element.Name;
                item.SetOnTapAction(actionName);
            }
            if ((isDetail && ContainsReadDetail(useCase))
                || (!isDetail && ContainsReadReference(useCase)))
            {
                string actionName = "view" + entity.Element.Name;
                item.SetOnTapAction(actionName);
            }

            Dictionary<ActionType, XisMenuItem> detailModes = new Dictionary<ActionType, XisMenuItem>();

            #region Create Context Menu
            if (isDetail && (ContainsReadDetail(useCase) || ContainsUpdateDetail(useCase) || ContainsDeleteDetail(useCase))
                || !isDetail && (ContainsReadReference(useCase) || ContainsUpdateReference(useCase) || ContainsDeleteReference(useCase)))
            {
                XisMenu context = new XisMenu(repository, diagram, package, list.Element.Name + "ContextMenu", MenuType.ContextMenu);

                if (isDetail && ContainsReadDetail(useCase)
                    || !isDetail && ContainsReadReference(useCase))
                {
                    context.SetEntityName(entity.Element.Name);
                    string actionName = "view" + entity.Element.Name;
                    XisMenuItem contextItem = new XisMenuItem(repository, diagram, context,
                        "View" + entity.Element.Name + "Item", actionName);
                    contextItem.SetValue("View " + entity.Element.Name);
                    detailModes.Add(ActionType.Read, contextItem);
                }

                if (isDetail && ContainsUpdateDetail(useCase)
                    || !isDetail && ContainsUpdateReference(useCase))
                {
                    context.SetEntityName(entity.Element.Name);
                    string actionName = "edit" + entity.Element.Name;
                    XisMenuItem contextItem = new XisMenuItem(repository, diagram, context,
                        "Edit" + entity.Element.Name + "Item", actionName);
                    contextItem.SetValue("Edit " + entity.Element.Name);
                    detailModes.Add(ActionType.Update, contextItem);
                }

                if (isDetail && ContainsUpdateDetail(useCase)
                    || !isDetail && ContainsUpdateReference(useCase))
                {
                    context.SetEntityName(entity.Element.Name);
                    string actionName = "delete" + entity.Element.Name;
                    XisMenuItem contextItem = new XisMenuItem(repository, diagram, context,
                        "Delete" + entity.Element.Name + "Item", actionName);
                    contextItem.SetValue("Delete " + entity.Element.Name);
                    XisWebHelper.CreateXisAction(repository, contextItem.Element, actionName, ActionType.Delete);
                }
                collapsible.ContextMenu = context;
            }
            #endregion

            #region Create Options Menu
            XisMenu menu = new XisMenu(repository, diagram, collapsibleItem, collapsibleItem.Element.Name + "Menu", MenuType.OptionsMenu);

            if ((isDetail && (ContainsCreateDetail(useCase) || ContainsDeleteDetail(useCase)))
                || (!isDetail && (ContainsCreateReference(useCase) || ContainsDeleteReference(useCase))))
            {
                menu.SetEntityName(entity.Element.Name);
                string actionName = "create" + entity.Element.Name;
                XisMenuItem menuItem = new XisMenuItem(repository, diagram, menu,
                    "Create" + entity.Element.Name + "Item", actionName);
                menuItem.SetValue("Create " + entity.Element.Name);
                detailModes.Add(ActionType.Create, menuItem);
            }

            if (isDetail && (ContainsDeleteDetail(useCase))
                || !isDetail && (ContainsDeleteReference(useCase)))
            {
                menu.SetEntityName(entity.Element.Name);
                string actionName = "deleteAll" + entity.Element.Name + "s";
                XisMenuItem menuItem = new XisMenuItem(repository, diagram, menu,
                    "DeleteAll" + entity.Element.Name + "Item", actionName);
                menuItem.SetValue("Delete all " + entity.Element.Name + "s");
                XisWebHelper.CreateXisAction(repository, menuItem.Element, actionName, ActionType.DeleteAll);
            }

            //No need for Close action in Collapsible since the panel closes itself
            /*string actionClose = "close" + entity.Element.Name;
            XisMenuItem backMenuItem = new XisMenuItem(repository, diagram, menu,
                "Close" + entity.Element.Name + "Item", actionClose);
            backMenuItem.SetValue("Close");
            XisWebHelper.CreateXisAction(repository, backMenuItem.Element, actionClose, ActionType.Cancel);*/

            collapsible.Menu = menu;
            #endregion

            if (detailModes.Count > 0 || !string.IsNullOrEmpty(item.GetOnTapAction()))
            {
                XisInteractionSpace detailIS = CreateDetailOrRefEditorIS(package, entity, parentIS, useCase, isDetail, be);
                foreach (ActionType key in detailModes.Keys)
                {
                    XisMenuItem mItem = detailModes[key];
                    XisWebHelper.CreateXisAction(repository, mItem.Element, mItem.GetOnTapAction(),
                        key, detailIS.Element.Name);
                    CreateXisInteractionSpaceAssociation(mItem.GetOnTapAction(), parentIS, detailIS);
                }

                if (!string.IsNullOrEmpty(item.GetOnTapAction()))
                {
                    XisWebHelper.CreateXisAction(repository, item.Element, item.GetOnTapAction(),
                        ActionType.Update, detailIS.Element.Name);
                    CreateXisInteractionSpaceAssociation(item.GetOnTapAction(), parentIS, detailIS);
                }
            }

            ComputePositions(collapsible, diagram, parentIS.GetDiagramObject(diagram), null);

            if (collapsible.ContextMenu != null)
            {
                EA.DiagramObject obj = collapsible.GetDiagramObject(diagram);
                int center = (obj.top + obj.bottom) / -2;
                collapsible.ContextMenu.SetPosition(diagram, obj.right + 50, obj.right + 330, -obj.top, -obj.top + 70);
                ComputePositions(collapsible.ContextMenu, diagram);

                // Create XisIS-MenuAssociation
                EA.DiagramObject sourceObj = item.GetDiagramObject(diagram);
                EA.Connector c = item.Element.Connectors.AddNew("", "Association");
                c.ClientID = item.Element.ElementID;
                c.SupplierID = collapsible.ContextMenu.Element.ElementID;
                c.Direction = "Source -> Destination";
                c.Stereotype = "XisIS-MenuAssociation";
                c.Update();
                item.Element.Update();
                item.Element.Connectors.Refresh();
            }

            return collapsible;
        }
コード例 #2
0
ファイル: M2MTransformer.cs プロジェクト: theedward/xisweb
        public static void ProcessManagerUseCase(EA.Package package, XisEntity master,
            EA.Element useCase, EA.Element be, bool isStartingUC, List<EA.Element> useCases = null, String patternType = null)
        {
            // Create IS Diagram
            EA.Diagram listDiagram = XisWebHelper.CreateDiagram(package, master.Element.Name + "ListIS Diagram",
                "XIS-Web_Diagrams::InteractionSpaceViewModel");
            XisInteractionSpace listIS = null;

            if (isStartingUC && patternType != null)
            {
                listIS = new XisInteractionSpace(repository, package, listDiagram,
                    master.Element.Name + "ListIS", "Manage " + master.Element.Name + "s", InteractionSpaceType.MasterEntityList);
            }
            else
            {
                listIS = new XisInteractionSpace(repository, package, listDiagram,
                    master.Element.Name + "ListIS", "Manage " + master.Element.Name + "s", InteractionSpaceType.MasterEntityList, isStartingUC, !isStartingUC);

                if (isStartingUC && patternType == null)
                {
                    homeIS = listIS;
                }
            }

            //Image & Sitemap Creation - Define a proper source path!
            XisImage img = new XisImage(repository, listIS, listDiagram, "../images/default.png");

            XisSiteMap siteMap = new XisSiteMap(repository, listIS, listDiagram);

            // List Creation
            XisList list = new XisList(repository, listDiagram, listIS, master.Element.Name + "List");
            list.SetEntityName(master.Element.Name);

            //if (ContainsSearch(operations))
            //{
            //    string searchBy = "";
            //    string tv = null;

            //    foreach (EA.Attribute attr in master.Element.Attributes)
            //    {
            //        tv = GetAttributeTag(attr.TaggedValues, "isKey").Value;
            //        if (!string.IsNullOrEmpty(tv) && tv.ToLower() == "true")
            //        {
            //            searchBy += master.Element.Name + "." + attr.Name + ";";
            //        }
            //    }

            //    if (string.IsNullOrEmpty(searchBy))
            //    {
            //        list.SetSearchBy(master.Element.Name + ".Id");
            //    }
            //    else
            //    {
            //        list.SetSearchBy(searchBy.Substring(0, searchBy.Length - 1));
            //    }
            //}

            XisListItem item = new XisListItem(repository, listDiagram, list, list.Element.Name + "Item");

            if (ContainsUpdateMaster(useCase))
            {
                string actionName = "edit" + master.Element.Name;
                item.SetOnTapAction(actionName);
            }
            else if (ContainsReadMaster(useCase))
            {
                string actionName = "view" + master.Element.Name;
                item.SetOnTapAction(actionName);
            }

            if (master.Element.Attributes.Count > 1)
            {
                EA.Attribute first = master.Element.Attributes.GetAt(0);
                EA.Attribute second = master.Element.Attributes.GetAt(1);
                XisLabel lbl1 = new XisLabel(repository, item, listDiagram, first.Name + "Lbl");
                lbl1.SetEntityAttributeName(master.Element.Name + "." + first.Name);
                XisLabel lbl2 = new XisLabel(repository, item, listDiagram, second.Name + "Lbl");
                lbl2.SetEntityAttributeName(master.Element.Name + "." + second.Name);
            }
            else if (master.Element.Attributes.Count == 1)
            {
                EA.Attribute attr = master.Element.Attributes.GetAt(0);
                item.SetValueFromExpression(master.Element.Name + "." + attr.Name);
            }

            // Read, Update, Create
            //Menu Creation
            #region Create Options Menu
            Dictionary<ActionType, XisMenuItem> detailModes = new Dictionary<ActionType, XisMenuItem>(3);

            if (ContainsCreateMaster(useCase) || ContainsDeleteMaster(useCase))
            {
                XisMenu menu = new XisMenu(repository, listDiagram, listIS, listIS.Element.Name + "Menu", MenuType.OptionsMenu);

                if (ContainsCreateMaster(useCase))
                {
                    menu.SetEntityName(master.Element.Name);
                    string actionName = "create" + master.Element.Name;
                    XisMenuItem menuItem = new XisMenuItem(repository, listDiagram, menu,
                        "Create" + master.Element.Name + "Item", actionName);
                    menuItem.SetValue("Create " + master.Element.Name);
                    detailModes.Add(ActionType.Create, menuItem);
                }

                if (ContainsDeleteMaster(useCase))
                {
                    menu.SetEntityName(master.Element.Name);
                    string actionName = "deleteAll" + master.Element.Name + "s";
                    XisMenuItem menuItem = new XisMenuItem(repository, listDiagram, menu,
                        "DeleteAll" + master.Element.Name + "Item", actionName);
                    menuItem.SetValue("Delete all " + master.Element.Name + "s");
                    XisWebHelper.CreateXisAction(repository, menuItem.Element, actionName, ActionType.DeleteAll);
                }
                listIS.Menu = menu;
            }
            #endregion
            #region Create Context Menu
            if (ContainsReadMaster(useCase) || ContainsUpdateMaster(useCase) || ContainsDeleteMaster(useCase))
            {
                XisMenu context = new XisMenu(repository, listDiagram, package, list.Element.Name + "ContextMenu", MenuType.ContextMenu);

                if (ContainsReadMaster(useCase))
                {
                    context.SetEntityName(master.Element.Name);
                    string actionName = "view" + master.Element.Name;
                    XisMenuItem contextItem = new XisMenuItem(repository, listDiagram, context,
                        "View" + master.Element.Name + "Item", actionName);
                    contextItem.SetValue("View " + master.Element.Name);
                    detailModes.Add(ActionType.Read, contextItem);
                }

                if (ContainsUpdateMaster(useCase))
                {
                    context.SetEntityName(master.Element.Name);
                    string actionName = "edit" + master.Element.Name;
                    XisMenuItem contextItem = new XisMenuItem(repository, listDiagram, context,
                        "Edit" + master.Element.Name + "Item", actionName);
                    contextItem.SetValue("Edit " + master.Element.Name);
                    detailModes.Add(ActionType.Update, contextItem);
                }

                //This action is passing to the Editor page
                /*if (ContainsDeleteMaster(useCase))
                {
                    context.SetEntityName(master.Element.Name);
                    string actionName = "delete" + master.Element.Name;
                    XisMenuItem contextItem = new XisMenuItem(repository, listDiagram, context,
                        "Delete" + master.Element.Name + "Item", actionName);
                    contextItem.SetValue("Delete " + master.Element.Name);
                    XisWebHelper.CreateXisAction(repository, contextItem.Element, actionName, ActionType.Delete);
                }*/
                listIS.ContextMenu = context;
            }
            #endregion

            // Navigation between home UC and the others
            if (patternType != null)
            {
                AddToHomeISByPattern(useCase, listIS, patternType);
            }
            else if (isStartingUC)
            {
                if (useCases != null)
                {
                    AssociateFirstSubSpaces(listDiagram, useCases, listIS, be.ElementID, master.Element.Name);
                }
            }

            #region Check ServiceUC Extensions
            Dictionary<List<EA.Element>, bool> services = new Dictionary<List<EA.Element>, bool>();

            if (useCase.Connectors.Count > 0)
            {
                List<EA.Element> extends = new List<EA.Element>();
                Dictionary<EA.Element, bool> providers = new Dictionary<EA.Element, bool>();

                foreach (EA.Connector conn in useCase.Connectors)
                {
                    if (conn.Stereotype == "extend")
                    {
                        EA.Element el = repository.GetElementByID(conn.ClientID);
                        extends.Add(el);
                    }
                }

                foreach (EA.Element e in extends)
                {
                    bool hasBE = false;
                    EA.Element provider = null;

                    foreach (EA.Connector conn in e.Connectors)
                    {
                        if (conn.Stereotype == "XisServiceUC-BEAssociation")
                        {
                            hasBE = true;
                        }
                        else if (conn.Stereotype == "XisServiceUC-ProviderAssociation")
                        {
                            provider = repository.GetElementByID(conn.SupplierID);
                            providers.Add(provider, false);
                        }
                    }

                    if (provider != null && hasBE)
                    {
                        providers[provider] = true;
                    }
                }

                foreach (EA.Element p in providers.Keys)
                {
                    List<EA.Element> lst = new List<EA.Element>();

                    foreach (EA.Connector c in p.Connectors)
                    {
                        if (c.Stereotype == "XisProvider-ServiceRealization")
                        {
                            EA.Element el = repository.GetElementByID(c.SupplierID);
                            lst.Add(el);
                        }
                    }

                    if (lst.Count > 0)
                    {
                        services.Add(lst, providers[p]);
                    }
                }

                if (services.Count > 0)
                {
                    if (services.Values.Contains(true))
                    {
                        if (listIS.ContextMenu == null)
                        {
                            listIS.ContextMenu = new XisMenu(repository, listDiagram, package, list.Element.Name + "ContextMenu",
                                MenuType.ContextMenu);
                        }

                        foreach (List<EA.Element> lst in services.Keys)
                        {
                            if (services[lst])
                            {
                                foreach (EA.Element serv in lst)
                                {
                                    foreach (EA.Method method in serv.Methods)
                                    {
                                        if (method.Stereotype == "XisServiceMethod")
                                        {
                                            XisMenuItem menuItem = new XisMenuItem(repository, listDiagram, listIS.ContextMenu,
                                                method.Name, serv.Name + "." + method.Name);
                                            menuItem.SetValue(method.Name);
                                            XisWebHelper.CreateXisAction(repository, menuItem.Element, menuItem.GetOnTapAction(),
                                                ActionType.WebService);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (services.Values.Contains(false))
                    {
                        if (listIS.Menu == null)
                        {
                            listIS.Menu = new XisMenu(repository, listDiagram, listIS, listIS.Element.Name + "Menu", MenuType.OptionsMenu);
                        }

                        foreach (List<EA.Element> lst in services.Keys)
                        {
                            if (!services[lst])
                            {
                                foreach (EA.Element serv in lst)
                                {
                                    foreach (EA.Method method in serv.Methods)
                                    {
                                        if (method.Stereotype == "XisServiceMethod")
                                        {
                                            XisMenuItem menuItem = new XisMenuItem(repository, listDiagram, listIS.Menu,
                                                method.Name, serv.Name + "." + method.Name);
                                            menuItem.SetValue(method.Name);
                                            XisWebHelper.CreateXisAction(repository, menuItem.Element, menuItem.GetOnTapAction(),
                                                ActionType.WebService);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            if (detailModes.Count > 0 || !string.IsNullOrEmpty(item.GetOnTapAction()))
            {
                XisInteractionSpace detailIS = CreateMasterEditorIS(package, master, listIS, useCase, be, services);

                foreach (ActionType key in detailModes.Keys)
                {
                    XisMenuItem mItem = detailModes[key];
                    XisWebHelper.CreateXisAction(repository, mItem.Element, mItem.GetOnTapAction(),
                        key, detailIS.Element.Name);
                    CreateXisInteractionSpaceAssociation(mItem.GetOnTapAction(), listIS, detailIS);
                }

                if (!string.IsNullOrEmpty(item.GetOnTapAction()))
                {
                    XisWebHelper.CreateXisAction(repository, item.Element, item.GetOnTapAction(),
                        ActionType.Update, detailIS.Element.Name);
                    CreateXisInteractionSpaceAssociation(item.GetOnTapAction(), listIS, detailIS);
                }
            }

            if (homeIS != listIS)
            {
                if (listIS.Menu == null)
                {
                    listIS.Menu = new XisMenu(repository, listDiagram, listIS, listIS.Element.Name + "Menu", MenuType.OptionsMenu);
                }

                string actionBack = "backTo" + homeIS.Element.Name;
                XisMenuItem backMenuItem = new XisMenuItem(repository, listDiagram, listIS.Menu,
                    "BackTo" + homeIS.Element.Name + "Item", actionBack);
                backMenuItem.SetValue("Go Back");
                XisWebHelper.CreateXisAction(repository, backMenuItem.Element, actionBack, ActionType.Cancel);
                CreateXisInteractionSpaceAssociation(actionBack, listIS, homeIS);
            }

            ComputePositions(listIS, listDiagram);

            if (listIS.ContextMenu != null)
            {
                EA.DiagramObject obj = listIS.GetDiagramObject(listDiagram);
                int center = (obj.top + obj.bottom) / -2;
                listIS.ContextMenu.SetPosition(listDiagram, obj.right + 50, obj.right + 330, -obj.top, -obj.top + 70);
                ComputePositions(listIS.ContextMenu, listDiagram);

                // Create XisIS-MenuAssociation
                EA.DiagramObject sourceObj = item.GetDiagramObject(listDiagram);
                EA.Connector c = item.Element.Connectors.AddNew("", "Association");
                c.ClientID = item.Element.ElementID;
                c.SupplierID = listIS.ContextMenu.Element.ElementID;
                c.Direction = "Source -> Destination";
                c.Stereotype = "XisIS-MenuAssociation";
                c.Update();
                item.Element.Update();
                item.Element.Connectors.Refresh();
            }

            // Associate BE
            AssociateBEtoIS(listDiagram, listIS, be);

            if (!isStartingUC)
            {
                // TODO: Link subspaces
                //CreateXisInteractionSpaceAssociation(repository, "goTo" + listIS.Element.Name, homeIS, listIS);
            }
        }