in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

How to customize standard controllers

Last post 8/10/2007 9:03 AM by Vedat Nommaz. 3 replies.
Page 1 of 1 (4 items)
Sort Posts:
Previous Next
  • 10/25/2006 12:47 PM

    How to customize standard controllers

    Hello everybody,
    
        The usability of code reuse and the customization of its behaviour is
    one of the most significant goals of a developer when designing and
    creating components, controls, classes or even frameworks.
    
        For this, the virtual methods and events are a common technique in the
    Object Oriented Programming.
    
        The virtual methods are more preferrable when the behaviour change is
    clear, strict and there will be no other adjustments. For example, you want
    to unconditionally close the object editing window after a user saves the
    changes in addition to the default implementation (which only saves the
    changes). This means that this is the only adjustment of the "Save" action
    in this application. Generally the virtual methods are used at the end-user
    applications development.
    
        The events should be used when there may be introduced a couple of
    independed adjustments of the implemented behaviour. For example, two
    different pluggable application modules deslare objects which require
    additional initialization when creating. In this case both these modules
    will extend the "New" action behaviour independently,  and for this, using
    the events is the most appropriated decision (actually, there will be the
    chain of handlers for a single event). This approach can be used at the
    end-user applications development as well as at the extentions development
    for the existing components or controls.
    
        Of course both these design decisions can be implemented simultaneously.
    
        The above is the common theses and the reused elements should provide
    the virtual methods and events. What does the XAF propose for using these
    techniques?
    
        XAF is a configurable system which has all the functionality within the
    Controllers. This design allows plugging a new functionality (as
    controllers) into the application or totally replacing a feature by removing
    the appropriate controllers and introducing a couple of new ones. This
    concerns code reuse because most of the application functionality remains
    untouched, though it is inexpediently to drop a significant block
    (controller) when only a bit of customizations is necessary. Controller
    should have virtual methods and events for such little adjustments.
    
        For example the "WebDetailViewController" class declares several
    actions: "Cancel", "Save", "SaveAndClose" and "Edit". Each action has an
    appropriate virtual method called ExecuteXXX: "ExecuteCancel",
    "ExecuteSave", "ExecuteSaveAndClose" and "ExecuteEdit". So a developer can
    make his own controller and override any of these virtual methods. In this
    case all the UI settings of actions (category, caption, image, shortcut,
    tool tip, localizations and so on) and the action state management (Active
    and Enabled) will be reused. All the WebDetailViewController's actions are
    very simple so there is only a single virtual method per each action. If an
    action implementation is complex enough then there may be a couple of
    virtual methods. This is the best practice for the design of controllers
    which will be used by other developers.
    
        All the XAF controllers are collected on the application startup (or
    when a ModelEditor loads the application model). You can find all of them in
    the Model Editor within the 'Actions' node. If you inherite your own
    controller from the "WebDetailViewController" class you will see there both
    your controller and the "WebDetailViewController". The main difference
    between them is that all the WebDetailViewController's actions will be shown
    within the WebDetailViewController's node, while your controller's node will
    contain no actions: your controller will contain all the inherited actions
    at run-time but it doesn't declare them, so the actions are shown once
    within their container's node and are not duplicated into the descendant's
    nodes. At run-time XAF doesn't create controllers if there is an inherited
    controller, all the base controllers are not working in the application.
    
        Another sample is the "NewObjectViewController" which declares the "New"
    action and a couple of events in addition to the virtual methods:
    CollectDescendats, CollectRoot, QueryNewObject and ObjectCreated. You can
    add a handler to one of these events to customize the list of objects
    available for creation, to create object manually, to customize the just
    created object and to specify whether it will be shown in a new DetailView
    or not. These events allow introducing several handlers for different
    objects and primarily they are oriented to the module developers.
    
    In the attached file I have demonstrated the above techniques.
    
    -- 
    Thanks, Dan
    R&D, .NET Team Developer Express Inc.
    
    PS. Please don't reply to me directly by email unless it is specifically
    requested. If you wish to receive direct assistance from our Support Team,
    use Support Center at http://www.devexpress.com/Support/Center
    
    Please take a look at our Knowledge Base at: http://www.devexpress.com/kb.
    It contains useful information on our products that may save you time.
  • 11/14/2006 4:02 PM In reply to

    • Robert Anderson

    Re: How to customize standard controllers

    Hi Dan,
    
    The example shows the subclassing of the WebDetailViewController.  What 
    about the WinDetailViewController?  It is a sealed class at the moment so I 
    cannot override it...
    
    Also, how would I do the same for Delete?  I don't find a protected 
    ExecuteDelete() on the DeleteObjectsViewController.
    
    Thanks,
    
    Rob
  • 11/15/2006 11:34 AM In reply to

    Re: How to customize standard controllers

    Hello Robert,
    
    > The example shows the subclassing of the WebDetailViewController.  What
    > about the WinDetailViewController?  It is a sealed class at the moment so
    > I cannot override it...
    >
    > Also, how would I do the same for Delete?  I don't find a protected
    > ExecuteDelete() on the DeleteObjectsViewController.
    
    In the next release, all the standard controllers (at least most of them)
    will be designed the way I described in my previous post.
    In the XAF CTP2, there is a couple of design mistakes, and you have pointed
    to one of them.
    
    With such a design, it is impossible to change the behavior of a standard
    controller, and the only way to do this is to disable the standard
    controller and make a new one with the necessary functionality.
    
    -- 
    Thanks, Dan
    
    R&D, .NET Team Developer Express Inc.
    
    PS. Please don't reply to me directly by email unless it is specifically
    requested. If you wish to receive direct assistance from our Support Team,
    use Support Center at http://www.devexpress.com/Support/Center
    
    Please take a look at our Knowledge Base at: http://www.devexpress.com/kb.
    It contains useful information on our products that may save you time.
    "Robert Anderson" <newsreplies2@yahoo.com> wrote in message
    news:4559f4fc$1@news.devexpress.com...
    > Hi Dan,
    >
    > The example shows the subclassing of the WebDetailViewController.  What
    > about the WinDetailViewController?  It is a sealed class at the moment so
    > I cannot override it...
    >
    > Also, how would I do the same for Delete?  I don't find a protected
    > ExecuteDelete() on the DeleteObjectsViewController.
    >
    > Thanks,
    >
    > Rob
    >
    >
  • 8/10/2007 9:03 AM In reply to

    Re: How to customize standard controllers

    I was very excited when I found this post as it seemed to answer our two bottlenecks w xaf

    1) How to take over new object creation so we have complete control of the winapp form

    2) How to take over object edit screen so we can control layout of the form, placement of fields, types of controls to be used for objects, use of tabs to seperate controls in different areas, etc.. 

    However sounds like the examples are already obsolete - could not get them to compile on latest xaf anyways.

    we need more flexibility to make the new/edit screens more user friendly. I can provide detailed examples of what we are trying to accomplish upon request.

    What is the best solution with the current release candidate?  

    Filed under:
Page 1 of 1 (4 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED