private static Dictionary <string, Image> GetRelevantGroupMenuItems(string cc, string menuItemName) { Dictionary <string, Image> relevantGroups = new Dictionary <string, Image>(); // (1) add to group: only show groups which still can be added, i.e. where not already all selected elements belong to if (menuItemName == MENU_GROUP_ADD) { foreach (CountryConfig.LookGroupRow groupRow in GetCountryConfig(cc).LookGroup) { bool canBeAdded = false; foreach (TreeListNode node in GetSelectedNodes(cc)) { if (CountryAdministrator.IsAddOn(cc) || node.Tag == null || node.Tag as BaseTreeListTag == null) { continue; } BaseTreeListTag nodeTag = node.Tag as BaseTreeListTag; if (nodeTag.GetDefaultParameterRow() != null) // means: if (isParameterRow) { if ((from lgPar in GetCountryConfig(cc).LookGroup_Parameter where lgPar.LookGroupID == groupRow.ID && lgPar.ParameterID == nodeTag.GetDefaultParameterRow().ID select lgPar).Any()) { continue; // node belongs to group } } if (nodeTag.GetDefaultFunctionRow() != null) // means: if (isFunctionRow || isParameterRow) { if ((from lgFun in GetCountryConfig(cc).LookGroup_Function where lgFun.LookGroupID == groupRow.ID && lgFun.FunctionID == nodeTag.GetDefaultFunctionRow().ID select lgFun).Any()) { continue; // node belongs to group } } // means: if (isPolicyRow || isFunctionRow || isParameterRow) if ((from lgPol in GetCountryConfig(cc).LookGroup_Policy where lgPol.LookGroupID == groupRow.ID && lgPol.PolicyID == nodeTag.GetDefaultPolicyRow().ID select lgPol).Any()) { continue; // node belongs to group } canBeAdded = true; break; // node, nor parent nodes, do belong to group: can be added } if (!canBeAdded) { continue; } ExtensionOrGroup eg = new ExtensionOrGroup(groupRow); relevantGroups.Add(eg.name, eg.look.GetMenuImage()); } } // (2) remove from group: only show groups which can be removed, i.e. where any of the selected elements belongs to else if (menuItemName == MENU_GROUP_REMOVE) { List <string> lookGroupIds = new List <string>(); foreach (TreeListNode node in GetSelectedNodes(cc)) { if (CountryAdministrator.IsAddOn(cc) || node.Tag == null || node.Tag as BaseTreeListTag == null) { continue; } BaseTreeListTag nodeTag = node.Tag as BaseTreeListTag; // "belongs to" means, that the function/parameter itself has to belong to the group, not only the parent if (nodeTag.GetDefaultParameterRow() != null) // means: if (isParameterRow) { lookGroupIds.AddRange(from lgPar in GetCountryConfig(cc).LookGroup_Parameter where lgPar.ParameterID == nodeTag.GetDefaultParameterRow().ID select lgPar.LookGroupID); } else if (nodeTag.GetDefaultFunctionRow() != null) // means: if (isFunctionRow) { lookGroupIds.AddRange(from lgFun in GetCountryConfig(cc).LookGroup_Function where lgFun.FunctionID == nodeTag.GetDefaultFunctionRow().ID select lgFun.LookGroupID); } else // means: if (isPolicyRow) { lookGroupIds.AddRange(from lgPol in GetCountryConfig(cc).LookGroup_Policy where lgPol.PolicyID == nodeTag.GetDefaultPolicyRow().ID select lgPol.LookGroupID); } } foreach (CountryConfig.LookGroupRow groupRow in from lg in GetCountryConfig(cc).LookGroup where lookGroupIds.Contains(lg.ID) select lg) { ExtensionOrGroup eg = new ExtensionOrGroup(groupRow); relevantGroups.Add(eg.name, eg.look.GetMenuImage()); } } // (3) all other menu items (Expand,etc.): show all groups else { foreach (CountryConfig.LookGroupRow groupRow in GetCountryConfig(cc).LookGroup) { ExtensionOrGroup eg = new ExtensionOrGroup(groupRow); relevantGroups.Add(eg.name, eg.look.GetMenuImage()); } } return(relevantGroups.Any() ? relevantGroups : new Dictionary <string, Image>() { { NO_ITEMS_DEFINED, null } }); }
private static Dictionary <string, Image> GetRelevantExtensionMenuItems(string cc, string menuItemName) { Dictionary <string, Image> relevantExtensions = new Dictionary <string, Image>(); bool globalOnly = menuItemName == MENU_EXTENSION_PRIVATE_ALL || menuItemName == MENU_EXTENSION_NOT_PRIVATE_ALL; // (1) add to extension: only show extensions which still can be added, i.e. where not already all selected elements belong to if (menuItemName == MENU_EXTENSION_ADDON || menuItemName == MENU_EXTENSION_ADDOFF) { foreach (GlobLocExtensionRow extRow in globalOnly ? ExtensionAndGroupManager.GetGlobalExtensions() : ExtensionAndGroupManager.GetExtensions(cc)) { bool canBeAdded = false; foreach (TreeListNode node in GetSelectedNodes(cc)) { if (CountryAdministrator.IsAddOn(cc) || node.Tag == null || node.Tag as BaseTreeListTag == null) { continue; } BaseTreeListTag nodeTag = node.Tag as BaseTreeListTag; if (nodeTag.GetDefaultParameterRow() != null) // means: if (isParameterRow) { if ((from ePar in GetCountryConfig(cc).Extension_Parameter where ePar.ExtensionID == extRow.ID && ePar.ParameterID == nodeTag.GetDefaultParameterRow().ID select ePar).Any()) { continue; // node belongs to extension } } if (nodeTag.GetDefaultFunctionRow() != null) // means: if (isFunctionRow || isParameterRow) { var ef = from eFun in GetCountryConfig(cc).Extension_Function where eFun.ExtensionID == extRow.ID && eFun.FunctionID == nodeTag.GetDefaultFunctionRow().ID select eFun; if (ef.Any()) { if (nodeTag.GetDefaultParameterRow() == null) { continue; // is actually function-node and belongs to extension } // a parameter-node can still be added as switch-off, if function-node is added as switch-on if (ef.First().BaseOff || menuItemName == MENU_EXTENSION_ADDON) { continue; } } } // means: if (isPolicyRow || isFunctionRow || isParameterRow) var ep = from ePol in GetCountryConfig(cc).Extension_Policy where ePol.ExtensionID == extRow.ID && ePol.PolicyID == nodeTag.GetDefaultPolicyRow().ID select ePol; if (ep.Any()) { if (nodeTag.GetDefaultParameterRow() == null && nodeTag.GetDefaultFunctionRow() == null) { continue; // is actually policy-node and belongs to extension } // a parameter- or function-node can still be added as switch-off, if policy-node is added as switch-on if (ep.First().BaseOff || menuItemName == MENU_EXTENSION_ADDON) { continue; } } canBeAdded = true; break; // node, nor parent nodes, do belong to extension: can be added } if (!canBeAdded) { continue; } ExtensionOrGroup eg = new ExtensionOrGroup(extRow); relevantExtensions.Add(eg.name, eg.look.GetMenuImage()); } } // (2) remove from extension: only show extensions which can be removed, i.e. where any of the selected elements belongs to else if (menuItemName == MENU_EXTENSION_REMOVE) { List <string> extIds = new List <string>(); foreach (TreeListNode node in GetSelectedNodes(cc)) { if (CountryAdministrator.IsAddOn(cc) || node.Tag == null || node.Tag as BaseTreeListTag == null) { continue; } BaseTreeListTag nodeTag = node.Tag as BaseTreeListTag; // "belongs to" means, that the function/parameter itself has to belong to the extension, not only the parent if (nodeTag.GetDefaultParameterRow() != null) // means: if (isParameterRow) { extIds.AddRange(from ePar in GetCountryConfig(cc).Extension_Parameter where ePar.ParameterID == nodeTag.GetDefaultParameterRow().ID select ePar.ExtensionID); } else if (nodeTag.GetDefaultFunctionRow() != null) // means: if (isFunctionRow) { extIds.AddRange(from eFun in GetCountryConfig(cc).Extension_Function where eFun.FunctionID == nodeTag.GetDefaultFunctionRow().ID select eFun.ExtensionID); } else // means: if (isPolicyRow) { extIds.AddRange(from ePol in GetCountryConfig(cc).Extension_Policy where ePol.PolicyID == nodeTag.GetDefaultPolicyRow().ID select ePol.ExtensionID); } } foreach (GlobLocExtensionRow gleRow in from e in globalOnly ? ExtensionAndGroupManager.GetGlobalExtensions() : ExtensionAndGroupManager.GetExtensions(cc) where extIds.Contains(e.ID) select e) { ExtensionOrGroup eg = new ExtensionOrGroup(gleRow); relevantExtensions.Add(eg.name, eg.look.GetMenuImage()); } } // (3) all other menu items (Expand,etc.): show all extensions else { foreach (GlobLocExtensionRow extRow in globalOnly ? ExtensionAndGroupManager.GetGlobalExtensions() : ExtensionAndGroupManager.GetExtensions(cc)) { ExtensionOrGroup eg = new ExtensionOrGroup(extRow); relevantExtensions.Add(eg.name, eg.look.GetMenuImage()); } } return(relevantExtensions.Any() ? relevantExtensions : new Dictionary <string, Image>() { { NO_ITEMS_DEFINED, null } }); }