eXpress App Framework Team

This Blog

News

You are welcome to test the new XAF features prior to the 17.2 release: one, two, three, four, five, five

July 2007 - Posts

  • Why is it disabled?

        I've been often asked: "Why is the XXX action not visible?" or "Why is it disabled?"
     
        Well, sometimes it's difficult to find the cause, and it can even require a thorough debugging. An action can be invisible or disabled due to several reasons: security rights, ReadOnly views, a 'get' only access to a property, the absence of a default constructor, and lots of other specific parameters.

        To avoid these difficulties, we have introduced a possibility to name each reason. The Active/Enabled properties of the ActionBase class are calculated from a list of 'Boolean' values:
     
          activeResult = true;
          foreach(string key in ActiveList.GetKeys()) {
            activeResult = activeResult && ActiveList[key];
          }
     
        This approach allows a number of controllers to control the Active property independent from each other. For example, by default the “New” action is controlled by:
          - SecuritySystem: the action should be disabled if the current user doesn’t have appropriate rights
          - The View’s ReadOnly property: if the entire View is marked as ReadOnly then the action should be disabled
          - The possibility to create an object: it’s simply impossible to create an object if the class declaration doesn’t have a default constructor, and the action should be disabled
          - Collection settings: the collection can restrict adding new entries, and in this case, the “New” action should be disabled
     
        The “New” action will be disabled if there is at least one reason for it.
     
        The above reasons are controlled by different code placed in the XAF core and in a number of standard controllers. In addition to this code, you may introduce your own controller, which will restrict the “New” action’s availability in specific scenarios. This specific reason will be added into the list together with all other reasons.
     
        At the same time this approach allows you to investigate all the reasons and to easily find out why the action is invisible or disabled:
     
          string activeReasons;
          foreach(string key in ActiveList.GetKeys()) {
               activeReasons = activeReasons + key + " = " + ActiveList[key] + "\n";
          }
     
        The most common format to show this information is Xml. For example, the "NavigateBack" action detailed information can be like this:
     
          <Action ID="NavigateBack" TypeName="SingleChoiceAction" Category="ViewsHistoryNavigation" Active="True" Enabled="True" AdditionalInfo="">
               <ActiveList>
                    <Item Key="EmptyItems" Value="True" />
                    <Item Key="Controller active" Value="True" />
                    <Item Key="HideActionsViewController" Value="True" />
                    <Item Key="Main window" Value="True" />
               </ActiveList>
               <EnabledList>
                    <Item Key="EmptyItems" Value="True" />
                    <Item Key="Can back" Value="True" />
               </EnabledList>
          </Action>
     
         - The "EmptyItems" entry informs that there is a restriction on the items count in the action's ItemList, and currently there is one or several items. This action is a SingleChoiceAction, and it requires an item to be executed
         - The "Controller active" entry informs that there is a restriction on the controller's Active property, and currently the controller is active
         - The "HideActionsViewController" entry informs that this action can be disabled by the HideActionsViewController class, and that currently it is not disabled
         - The "Main window" entry informs that the action can only work in the application’s main window, and currently it is working in that window
     
        The "EnabledList" section contains similar entries.
     
        Another interesting information is the set of available ActionContainer objects on the Window and the way actions were distributed along the ActionContainers:
     
     <Template Name="ApplicationWindowContext" TypeName="DevExpress.ExpressApp.Win.Templates.MainForm">
          <ActionContainers>

               <Container Name="About" />
               <Container Name="Tools">
                    <Actions>
                         <Action ID="EditModel" />
                         <Action ID="ChooseSkin" />
                         <Action ID="ChangePasswordByUser" />
                    </Actions>
               </Container>
               <Container Name="File" />
               <Container Name="ObjectsCreation">
                    <Actions>
                         <Action ID="New" />
                         <Action ID="AddFromFile" />
                         <Action ID="CloneObject" />
                    </Actions>
               </Container>
     
          </ActionContainers>
     
        All this information is collected by the "DiagnosticInfoController" class, which only contains the "Diagnostic Info" action. By default, this action is disabled. To show, add a special entry into the "app.config" or "web.config" file:
     
          <appSettings>
              <add key="EnableDiagnosticActions" value="True" />
          </appSettings>

     
        This action shows a popup window with a large edit box that shows the information in the Xml format.
     
        This action helped me solve a number of issues with ease and save a lot of time on developing XAF applications. Hope, it will help you as well.

     
    --
    Thanks, Dan
    R&D, .NET Team Developer Express Inc.
     
    PS. If you wish to receive direct assistance from our Support Team, use
    Support Center at http://www.devexpress.com/Support/Center
LIVE CHAT

Chat is one of the many ways you can contact members of the DevExpress Team.
We are available Monday-Friday between 7:30am and 4:30pm Pacific Time.

If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

FOLLOW US

DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

Copyright © 1998-2017 Developer Express Inc.
All trademarks or registered trademarks are property of their respective owners