Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Build an AJAX Content Management System with Visual WebGUI: Creating a Framework

Flexible software systems require a foundation that supplies the basic system services that's easy for developers to use, yet powerful enough to support complex and flexible systems—in other words, a framework.


advertisement

he Mini CMS system begun in the first article in this series needs to have some base components that represent the actual workplace. These will support loading and showing modules inside the workplace, passing control between modules, and unloading them when their tasks are complete. Modules should be able to call other modules and pass some parameters. The called module should be able to return control back to the calling module and also return an exit status (if the user saved changes or canceled), so the calling module can update itself accordingly.

To make the framework flexible, it's best to define its components through interfaces. That will prevent binding the implementation to specific existing controls and allow future enhancements or implementation changes.

The Workplace and Module Components

 
Figure 1. IWTWorkplace and IWTModule Interfaces: These two core framework interfaces support loading, unloading, and showing modules.

The Workplace and Module components are the foundational bricks for the application. The Workplace is actually a container, which can load functional modules. Those loaded modules handle the real work of the application.



The Workplace and the Module expose the following interfaces:

  • IWTWorkplace: Defines the interface for a Workplace component, as shown in Figure 1. Components implementing this interface implement an actual workplace, and allow loading and showing modules, check if an existing module is loaded, hide all modules, removing a module. Table 1 shows its properties and methods.
  • IWTModule: Defines the interface for a Module component (see Figure 1). All modules must implement this interface. The properties and methods are described in Table 2.
Table 1. IWTWorkplace Interface: This table shows the properties and methods exposed by the IWTWorkplace interface.
Property Description
Control BodyPanel{ get; } Returns a reference to a control that act as a workplace container. In Visual WebGUI, all components derived from Control expose a Controls property (a ControlsCollection), which keeps track of all the contained controls.
string Caption
  { get; set;}
Sets or gets the caption value for the container. By implementing the IWTWorkplace as a HeaderedPanel or GroupBox, you can set the title label of the GroupBox or the header of the HeaderedPanel.
Method Description
IWTModule LoadModule(
IWTModule module,
IWTModule parentModule)
Loads a module as the active module and returns a reference to it. The second parameter, parentModule, is a reference to the parent IWTModule (the module this one was started from). The parentModule parameter lets you control which module will became active after the newly loaded module is closed. parentModule can be null, in which case the current module has no parent. This is useful for the very first module in IWTWorkplace, or when there are no dependencies on any other previously loaded module.
IWTModule LoadModule(
  IWTModule module,
  IWTModule parentModule,
  bool loadVisible);
Same as previous method, except that it supports loading hidden modules—which is useful when the program needs to perform additional tasks on a loaded module before showing it.
void ShowModule(
  IWTModule module);
Activates a loaded module.
bool CheckModuleExists(
  IWTModule module);
Check whether the specified module has been loaded into the IWTWorkplace.
void RemoveModule(
  IWTModule module);
Removes the specified module from the IWTWorkplace.
void HideAllModules(); Hides all modules.

Table 2. IWTModule Interface Properties and Methods: Each Module component must implement this interface.
Properties Description
IWTModule CallerModule
  { get; set; }
Gets or sets a reference to the calling module. Can be used to access properties or methods of the calling module.
IWTWorkplace HostWorkplace
  { get; set; }
Reference to workplace component where the module is loaded.
Method Description
void Refresh(
  WTCancelGenericEventArgs e)
This method should be called by the IWTWorkplace component when a module is closed and control should pass back to the calling module. The closing module raises the Close event, which receives arguments of type WTCancelGenericEventArgs. The workplace passes these to the calling module, by calling the Refresh method.
event WTCancelGenericEventHandler Close; The IWTModule fires this event when it closes.

The interaction between IWTModule and IWTWorkplace is driven by the WTWorkplaceController class. This class contains only static methods (see Table 3), which handle the plumbing between modules and workplaces.

Table 3. WTWorkplaceController Static Methods: The WtWorkplaceController exposes only static methods.
Method Description
public static
 IWTModule LoadModule(
   IWTWorkplace workplace,
   IWTModule module,
   IWTModule parentModule,
   bool loadVisible)
Loads a module into a workplace, and lets you specify a parent module (the module that launched the current module) and whether the new module will be loaded as visible or hidden.
public static
 void ShowModule(
   IWTWorkplace workplace,
   IWTModule module)
Shows a module already loaded into a workplace.
public static
 void RemoveModule(
   IWTWorkplace workplace,
   IWTModule module)
Removes a module from the workplace.
public static
 void HideAllModules(
   IWTWorkplace workplace)
Hides all modules from a workplace.
public static
 bool CheckModuleExists(
   IWTWorkplace workplace,
   IWTModule module);
Checks whether a module is loaded into a workplace.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap