Improvements in Modules architecture in Sitefinity SP2

August 14, 2007 Digital Experience
For you that have been creating your own modules or simply just playing around with them, here are some good news. It has been a bit awkward in the past when you have tried to get a reference from CommandPanel to ControlPanel and vice versa. Another problematic area used to be notifying one control that other one has done something. Then you needed to created different events and all in all, it was more of a mental exercise than it should of.

So here are the good news. With Service Pack 2 we have introduced two new classes and a slight change in logic that will make all these problems I've mentioned in first paragraph go away. The old way of doing things is however still supported. The two new classes I'm talking about are :
  1. Telerik.Web.ControlPanelBase and
  2. Telerik.Web.CommandPanelBase
Take a look at the following diagram to get a general idea of these new improvements. Later I will explain this in a bit more detail :




So instead of implementing the IControlPanel interface on your ControlPanel classes, you should make that class inherit Telerik.Web.ControlPanelBase and in same way instead of implementing IControlPanelCommand interface on your CommandPanel classes, you should make that class inherit Telerik.Web.CommandPanelBase class.

In addition to that you'll also need to add constructors for ControlPanel and CommandPanel classes.
Here is the constructor for CommandPanel :
public CommandPanel(ControlPanel controlPanel) 
            : base(controlPanel) 
        { 
        } 

and here is the constructor for ControlPanel :
public ControlPanel() 
   base.commandPnls = new ICommandPanel[] { new CommandPanel(this) }; 


notice how the ControlPanel constructor actually creates a new instance of CommandPanel class.

Now in case you are wondering why would you go through all this trouble, here are the reasons.
First of all you'll have a direct access from CommandPanel to ControlPanel and vice versa (this.ControlPanel and this.CommandPanel). Also lets say you do something in CommandPanel (delete something) and you want to refresh the ControlPanel. You don't need to create events for that anymore. All you have to do is call this.ControlPanel.Refresh() from CommandPanel instance. CommandPanel also has the Refresh() method.

I will update the Contacts module in the next post so you can see this new improvements in action.

The Progress Team