Ejemplo n.º 1
0
        internal override bool Execute(TreeListNode senderNode)
        {
            BaseTreeListTag tag = senderNode.Tag as BaseTreeListTag;

            if (tag.GetDefaultParameterRow() != null)
            {
                return(parameterIDs.Contains(tag.GetDefaultParameterRow().ID));
            }
            if (tag.GetDefaultFunctionRow() != null)
            {
                return(functionIDs.Contains(tag.GetDefaultFunctionRow().ID));
            }
            return(policyIDs.Contains(tag.GetDefaultPolicyRow().ID));
        }
Ejemplo n.º 2
0
        internal static List <ExtensionOrGroup> GetLookGroupDrawInfo(string cc, TreeListNode node)
        {
            if (CountryAdministrator.IsAddOn(cc) || node.Tag == null || node.Tag as BaseTreeListTag == null)
            {
                return(new List <ExtensionOrGroup>());
            }
            BaseTreeListTag nodeTag = node.Tag as BaseTreeListTag;

            List <string> lookGroupIds = (from lgPol in GetCountryConfig(cc).LookGroup_Policy where lgPol.PolicyID == nodeTag.GetDefaultPolicyRow().ID select lgPol.LookGroupID).ToList();

            if (nodeTag.GetDefaultFunctionRow() != null)
            {
                lookGroupIds.AddRange((from lgFun in GetCountryConfig(cc).LookGroup_Function where lgFun.FunctionID == nodeTag.GetDefaultFunctionRow().ID select lgFun.LookGroupID));
            }
            if (nodeTag.GetDefaultParameterRow() != null)
            {
                lookGroupIds.AddRange((from lgPar in GetCountryConfig(cc).LookGroup_Parameter where lgPar.ParameterID == nodeTag.GetDefaultParameterRow().ID select lgPar.LookGroupID));
            }

            List <ExtensionOrGroup> lookGroups = new List <ExtensionOrGroup>();

            foreach (CountryConfig.LookGroupRow lg in GetCountryConfig(cc).LookGroup)
            {
                if (lookGroupIds.Contains(lg.ID))
                {
                    lookGroups.Add(new ExtensionOrGroup(lg));
                }
            }
            return(lookGroups);
        }
Ejemplo n.º 3
0
        internal static List <ExtensionOrGroup> GetExtensionDrawInfo(string cc, TreeListNode node)
        {
            if (CountryAdministrator.IsAddOn(cc) || node.Tag == null || node.Tag as BaseTreeListTag == null)
            {
                return(new List <ExtensionOrGroup>());
            }
            BaseTreeListTag nodeTag = node.Tag as BaseTreeListTag;

            Dictionary <string, LookDef.STYLE> extIdsAndStyles = new Dictionary <string, LookDef.STYLE>();

            foreach (CountryConfig.Extension_PolicyRow extPolRow in from ePol in GetCountryConfig(cc).Extension_Policy where ePol.PolicyID == nodeTag.GetDefaultPolicyRow().ID select ePol)
            {
                extIdsAndStyles.Add(extPolRow.ExtensionID, extPolRow.BaseOff ? LookDef.STYLE.EXTENSION_OFF : LookDef.STYLE.EXTENSION_ON);
            }
            if (nodeTag.GetDefaultFunctionRow() != null)
            {
                foreach (CountryConfig.Extension_FunctionRow extFunRow in from eFun in GetCountryConfig(cc).Extension_Function where eFun.FunctionID == nodeTag.GetDefaultFunctionRow().ID select eFun)
                { // function-setting with regard to BaseOff overwrites policy-setting (in fact only BaseOff=true may overwrite BaseOff=false, but this is not the point to check for observing this rule)
                    if (extIdsAndStyles.ContainsKey(extFunRow.ExtensionID))
                    {
                        extIdsAndStyles[extFunRow.ExtensionID] = extFunRow.BaseOff ? LookDef.STYLE.EXTENSION_OFF : LookDef.STYLE.EXTENSION_ON;
                    }
                    else
                    {
                        extIdsAndStyles.Add(extFunRow.ExtensionID, extFunRow.BaseOff ? LookDef.STYLE.EXTENSION_OFF : LookDef.STYLE.EXTENSION_ON);
                    }
                }
            }
            if (nodeTag.GetDefaultParameterRow() != null)
            {
                foreach (CountryConfig.Extension_ParameterRow extParRow in from ePar in GetCountryConfig(cc).Extension_Parameter where ePar.ParameterID == nodeTag.GetDefaultParameterRow().ID select ePar)
                { // see overwriting rule above
                    if (extIdsAndStyles.ContainsKey(extParRow.ExtensionID))
                    {
                        extIdsAndStyles[extParRow.ExtensionID] = extParRow.BaseOff ? LookDef.STYLE.EXTENSION_OFF : LookDef.STYLE.EXTENSION_ON;
                    }
                    else
                    {
                        extIdsAndStyles.Add(extParRow.ExtensionID, extParRow.BaseOff ? LookDef.STYLE.EXTENSION_OFF : LookDef.STYLE.EXTENSION_ON);
                    }
                }
            }

            List <ExtensionOrGroup> extensions = new List <ExtensionOrGroup>();

            foreach (GlobLocExtensionRow e in GetExtensions(cc))
            {
                if (extIdsAndStyles.ContainsKey(e.ID))
                {
                    extensions.Add(new ExtensionOrGroup(e, extIdsAndStyles[e.ID]));
                }
            }
            return(extensions);
        }
        TreeListNode GetFunctionNode(TreeListNode parameterOrFunctionNode)
        {   //get function node if menu was opened from a parameter node
            BaseTreeListTag treeListTag = parameterOrFunctionNode.Tag as BaseTreeListTag;

            if (treeListTag.GetDefaultParameterRow() == null)
            {
                return(parameterOrFunctionNode);
            }
            else
            {
                return(parameterOrFunctionNode.ParentNode);
            }
        }
        void GreyState(TreeListNode senderNode)
        {
            if (senderNode == null)
            {
                return;
            }

            BaseTreeListTag treeListTag     = _mainForm.treeList.FocusedNode.Tag as BaseTreeListTag;
            bool            isParameterNode = treeListTag.GetDefaultParameterRow() != null;

            mniDeleteParameter.Enabled      = isParameterNode;
            mniDeleteFunction.ShortcutKeys  = isParameterNode ? System.Windows.Forms.Keys.None : System.Windows.Forms.Keys.Delete;
            mniDeleteParameter.ShortcutKeys = isParameterNode ? System.Windows.Forms.Keys.Delete : System.Windows.Forms.Keys.None;
            mniMoveFunctionDown.Enabled     = senderNode.NextNode != null;
            mniMoveFunctionUp.Enabled       = senderNode.PrevNode != null;
            mniPasteFunctionAfter.Enabled   = mniPasteFunctionBefore.Enabled = EM_AppContext.Instance.GetPasteFunctionAction() != null;
            mniPrivate.Enabled = !_mainForm._isAddOn;
            //the following is in fact not really correct (a reasonable copy of the selection is only possible if the function-name-cell lies within the selection and the selection contains editable cells)
            //it's aim is just to indicate that it is not possible to copy the values of the function with this menu (unless they are selected)
            mniCopyValues.Enabled        = _mainForm.GetMultiCellSelector().HasSelection();
            toolStripSeparator10.Enabled = !MultiCellSelector.IsClipboardEmpty();
            mniGroups.Enabled            = !_mainForm._isAddOn;
            mniExtensions.Enabled        = !_mainForm._isAddOn;
        }
        void mniDescriptionAsComment_Click(object sender, EventArgs e)
        {
            //a(ny) system is necessary to find out which incomelists (via DefIL), constants (via DefConst) and variables (via DefVar) are defined and to gather their descriptions
            TreeListColumn anySystemColumn = null;

            foreach (TreeListColumn column in _mainForm.treeList.Columns)
            {
                if (TreeListBuilder.IsSystemColumn(column))
                {
                    anySystemColumn = column;
                    break;
                }
            }
            if (anySystemColumn == null || anySystemColumn.Tag == null)
            {
                return;
            }

            _mainForm.Cursor = Cursors.WaitCursor;

            Dictionary <string, string> descriptionsILVarConst = new Dictionary <string, string>(); //gather incomelists and their description in a dictionary to be applied below
            SystemTreeListTag           systemTag = anySystemColumn.Tag as SystemTreeListTag;

            foreach (DataSets.CountryConfig.ParameterRow ilParameterRow in systemTag.GetParameterRowsILs())
            {
                if (!descriptionsILVarConst.Keys.Contains(ilParameterRow.Value.ToLower()))
                {
                    descriptionsILVarConst.Add(ilParameterRow.Value.ToLower(), systemTag.GetILTUComment(ilParameterRow));
                }
            }
            foreach (DataSets.CountryConfig.ParameterRow parameterRow in systemTag.GetParameterRowsConstants())
            {
                if (!descriptionsILVarConst.Keys.Contains(parameterRow.Name.ToLower()))
                {
                    descriptionsILVarConst.Add(parameterRow.Name.ToLower(), parameterRow.Comment);
                }
            }
            foreach (DataSets.CountryConfig.ParameterRow parameterRow in systemTag.GetParameterRowsDefVariables())
            {
                if (!descriptionsILVarConst.Keys.Contains(parameterRow.Name.ToLower()))
                {
                    descriptionsILVarConst.Add(parameterRow.Name.ToLower(), parameterRow.Comment);
                }
            }

            //the necessary comment-changes must be gathered in an action-group (to allow for a common undo)
            ActionGroup actionGroup = new ActionGroup();

            //loop over the parameters of the DefIL-function to put the respective descriptions of its components in the comment column
            BaseTreeListTag treeListTag  = _mainForm.treeList.FocusedNode.Tag as BaseTreeListTag;
            TreeListNode    functionNode = treeListTag.GetDefaultParameterRow() != null ? _mainForm.treeList.FocusedNode.ParentNode : _mainForm.treeList.FocusedNode;

            foreach (TreeListNode parameterNode in functionNode.Nodes)
            {
                CountryConfig.ParameterRow parameterRow = (parameterNode.Tag as ParameterTreeListTag).GetDefaultParameterRow();
                string description = string.Empty;
                if (descriptionsILVarConst.Keys.Contains(parameterRow.Name.ToLower())) //component is an incomelist, variable or constant
                {
                    description = descriptionsILVarConst[parameterRow.Name.ToLower()];
                }
                else //component is a variable (defined in the variables description file)
                {
                    description = EM_AppContext.Instance.GetVarConfigFacade().GetDescriptionOfVariable(parameterRow.Name, _mainForm.GetCountryShortName());
                }
                if (description != string.Empty)
                {
                    actionGroup.AddAction(new ChangeParameterCommentAction(parameterNode, description, true, _mainForm.GetTreeListBuilder().GetCommentColumn()));
                }
                //else: 'name' parameter, no description or unknown component
            }

            if (actionGroup.GetActionsCount() > 0)
            {
                _mainForm.PerformAction(actionGroup, false);
            }

            _mainForm.Cursor = Cursors.Default;
        }
        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 }
            });
        }