View Full Version : Where should we listen for application wide event in the MVC? A "MasterController"?

13 Dec 2011, 7:33 AM

I have a viewport set up like that:

North: Application header with a few link like Help and Logout
West: Accordion panel that acts as a menu
Center: A tab panel that act as the main container, may contain any kind of stuff
South: Application footer

Right now, I added a tab in the center tab panel and that has a "ProcessGroupMasterPanel" in it. This panel is configured like that:
Center: a grid displaying data
South: a Detail pane that display the currently selected item in more detail

In the detail pane, I have a toolbar with a "Open in new tab", so the user can open the selected item in its own tab.

Where should the event listener be, with respect to the MVC framework. The data are about "Process group".
I created a ProcessGroup controller that listen to the grid selected row event and update the detail pane, and the itemdoubleclick event to open up an edit window, but these are all events that can/should be managed for the "ProcessGroupMasterPanel", so it makes sense.

But now I want to open new tabs and all, that are outside the ProcessGroupMasterPanel, I think it would make sense to have some sort of MasterController that would listen for application wide event and act appropriately, what do you think?

That way, my widget/component could fire event such as "OpenTab" with parameter saying what should be in that tab and that MasterController, which would have references to the main tab panel could listen to that and create the tab.

I inspired all this by the "FeedViewer" demo, but this demo is not using the MVC framework... So I adjusted mine to work like that and came up with this question!


13 Dec 2011, 8:44 AM
I often use an App controller for commonly used actions. I do see a need for multiple controllers listening for the same event. For that, you can have one controller that can fire an event on the applications (this.application) and then you can use this.application.on() in the controllers.

13 Dec 2011, 9:54 AM
in other words: the application itself is a controller as well (an extension of it), so it perfectly fits your needs as a "MasterController".

13 Dec 2011, 11:26 AM

So when developing a custom widget, should I encapsulate the event listening into the widget itself, or should the widget include its own controller?

For example, with many different types of items, I want to use the same visual as the feed viewer demo (a grid and a detail panel below it).

So I thought of encapsulating this into a component called "MasterPanel".
This MasterPanel use a border layout with a grid (top) and a panel (bottom) along with a toolbar to toggle the detail panel (bottom vs left vs hidden) and to toggle summary. this tool bar is in MasterPanel's dockedItems since it's for interacting with both sub-component (grid and detail panel).

The Detail panel has its own toolbar with 'Open in a new tab', and a few other buttons since it has to do with the selected item only, though, by writing this, I realize that it could all go in the same upper toolbar, but I think it's easier for the end user to realize that the bottom toolbar is for the item displayed in that detail panel.

So I thought of doing this:
In the Grid, define the following 2 events:
itemSoftSelect - It would be fired when a user select an item by either single-clicking it or using the keyboard to move to an item.
itemHardSelect - It would be fired when a user double-click an item or press 'Enter' when already on an item.

In the MasterPanel, I would define this event:
openTab - It would be fired when the master panel detect it needs to open a new tab for a specific item.

So MasterPanel would listen for the itemHardSelect event and fire an openTab event.
It would also listen for itemSoftSelect and update the DetailPanel accordingly (it already does that, but it uses one of the grid's predefined event).

Also, in the DetailPanel, when the user click the 'Open in new tab', this could fire a itemHardSelect event as well, which would be catched by the MasterPanel and would therefore achieve the same desired effect (fireing a openTab event).

So far so good... What I'm wondering here, is where should all the event listening be defined? Does my custom component/widget have to encapsulate this in its definition file (like in the initComponent or something similar), or should my component include a definition file and a controller that glue all this together?

I think that by doing this, regardless of where the event listening will be written, the application's controller should listen to the openTab event and act accordingly, if I understood both your comment, I'm I right?

I'm not sure if this post is clear.. I rewrote it 3 times to make it easier to follow...

14 Dec 2011, 6:43 AM
Any thoughts about my last reply, before I go ahead and mark this post as answered..