Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: 1 [2]
Print
Author Topic: Popup Window  (Read 34077 times)
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« Reply #15 on: January 25, 2009, 11:55:44 »


Windows

For windows in AIR I have the same approach regarding a command to open one. I've had a real need for this since I have logic that has to figure out if the window for a VO is already open, if it is just activate it (bring it to the front and set focus) otherwise one needs to be created. In this case the command is called OpenIdeaEditorCommand and my mx:Window component is called IdeaEditor (think exactly like creating a new email with Apple Mail).

My case is that what makes the component unique is the IdeaVO. I use Flex's UIDUtil class and call the getUID(obj) method passing in an IdeaVO instance to make sure I have a unique id for each instance. This is how I register mediators since I use that UID as a name! I check if their is a mediator registered with that name and if there is I know a window is already open (in this case for an existing idea that is being edited) so I send a ACTIVATE_IDEA_EDITOR notification which that Mediator responds too by calling the viewComponent's activate() method.

If the mediator is not registered I know I need to create a new IdeaEditor so that is done in the command as well as creating and registering the new mediator. All event handlers are taken care of within the mediator, not the command! So if you close the window the mediator listens for a close event so it can remove itself from the Facade. Hot! :) Cliff, I showed this at the set of PureMVC presentations at MAX since it is an AIR client I built using PureMVC.

This is exactly how I handle Windows in AIR also. It works really well. I usually create AbstractIdeaWindow components as well to provide a similar interface across the related components - in addition to the AbstractIdeaWindowMediator (which extends my common AbstractMediator).

All of my VOs (and database tables) carry a UID property with the constructors passing a new UID (if it isn't already there). This is great because I don't have to wait for the object to come back from the service with an ID property and can track it instantly in my application for interface items (Windows) unique to the object.

This is the typical execute method in my OpenWindowCommand classes:

:
override public function execute(notification:INotification):void
{
var caseVO:CaseVO = notification.getBody() as CaseVO;
if(!caseVO)
return

var caseWindow:CaseMediaWindow;
var caseWindowMediator:CaseMediaWindowMediator;

if(facade.hasMediator(CaseMediaWindowMediator.NAME+caseVO.UID))
{
caseWindow = facade.retrieveMediator( CaseMediaWindowMediator.NAME+caseVO.UID ).getViewComponent() as CaseMediaWindow;
caseWindow.activate();
caseWindow.restore();
caseWindow.orderToFront();
}
else
{
caseWindow = new CaseMediaWindow()
caseWindow.open();
caseWindowMediator = new CaseMediaWindowMediator(caseWindow, caseVO);
facade.registerMediator(caseWindowMediator)
}
}
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
JJfutbol
Sr. Member
****
Posts: 53


View Profile WWW Email
« Reply #16 on: January 25, 2009, 08:50:57 »

Joel, have I ever told you have impeccable taste when it comes to applying solutions as yours with commands. :) If only other people had such great as us! I really want to share examples like these since I think most people don't really find much use for commands but they can prove to be quite helpful in encapsulating logic.
Logged
dierre
Jr. Member
**
Posts: 11


View Profile Email
« Reply #17 on: April 14, 2009, 03:11:05 »

Hi Daniele. I have a question. Your method is working but how can I load external information?
Logged
Pages: 1 [2]
Print