public void AddCommandItem(IControllerCommandItem CommandItem)
            {
                SetCommandItemAvaialble(CommandItem);

                SetCommandItemEnabled(CommandItem, false);

                _items.Add(CommandItem);

                CommandItem.Execute += new ControllerCommandItemExecuteHandler(CommandItem_Execute);
            }
            private bool IsCommandAvailable(IControllerCommandItem CommandItem)
            {
                IControllerCommand command = _commands.FirstOrDefault(p => p.CommandName == CommandItem.CommandName);

                if (command != null)
                {
                    return command.Available ? CheckFkCommandEnabled(CommandItem, false) : false;
                }
                else
                {
                    return false;
                }
            }
            private bool IsCommandEnabled(IControllerCommandItem CommandItem, bool KeyCommand)
            {
                IControllerCommand command = GetCommand(CommandItem);//_commands.FirstOrDefault(p => p.CommandName == CommandItem.CommandName);

                if (command != null)
                {
                    return command.Enabled ? CheckFkCommandEnabled(CommandItem, KeyCommand) : false;
                }
                else
                {
                    return false;
                }
            }
 private IControllerCommand GetCommand(IControllerCommandItem CommandItem)
 {
     return _commands.FirstOrDefault(p => p.CommandName == CommandItem.CommandName);
 }
 private void SetCommandItemEnabled(IControllerCommandItem CommandItem, bool KeyCommand)
 {
     CommandItem.Enabled = IsCommandEnabled(CommandItem, KeyCommand);
 }
 private void SetCommandItemAvaialble(IControllerCommandItem CommandItem)
 {
     CommandItem.Available = IsCommandAvailable(CommandItem);
 }
            private bool CheckFkCommandEnabled(IControllerCommandItem CommandItem, bool IsKeyCommand)
            {
                if (Controller.TableContext.ActiveType == XOTableContextActiveType.Item)
                {
                    if (CommandItem.CommandName == ControllerCommandTypes.SelectFkItem.ToString())
                    {
                        return
                            DataAvail.Utils.EnumFlags.IsContain(((DataAvail.Controllers.Commands.UICommandItems.FKCommandItemContext)CommandItem.Context).fieldContext.FkInterfaceType,
                            IsKeyCommand ? XWPFieldFkInterfaceType.SelectItemKey : XWPFieldFkInterfaceType.SelectItemButton);
                    }
                    else if (CommandItem.CommandName == ControllerCommandTypes.AddFkItem.ToString())
                    {
                        return
                            DataAvail.Utils.EnumFlags.IsContain(((DataAvail.Controllers.Commands.UICommandItems.FKCommandItemContext)CommandItem.Context).fieldContext.FkInterfaceType,
                              IsKeyCommand ? XWPFieldFkInterfaceType.AddItemKey : XWPFieldFkInterfaceType.AddItemButton);
                    }
                }
                else
                {
                    if (CommandItem.CommandName == ControllerCommandTypes.SelectFkItem.ToString())
                    {
                        return
                            DataAvail.Utils.EnumFlags.IsContain(((DataAvail.Controllers.Commands.UICommandItems.FKCommandItemContext)CommandItem.Context).fieldContext.FkInterfaceType,
                            IsKeyCommand ? XWPFieldFkInterfaceType.SelectItemKeySearch : XWPFieldFkInterfaceType.SelectItemButtonSearch);
                    }
                    else if (CommandItem.CommandName == ControllerCommandTypes.AddFkItem.ToString())
                    {
                        return false;
                    }
                }

                return true;
            }