tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/45-extend-mediators-for-rolandRobotlegs: Discussion 2018-10-18T16:35:09Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/10607962010-02-18T22:20:47Z2010-02-18T22:26:29ZExtend Mediators (for Roland)<div><p>Because the thread was closed, I am opening a new one.</p>
<p>I've done exactly what you are attempting to do. It's very
straightforward.</p>
<p>I have an abstract WindowMediator for my Window class (which
extends Sprite) and then I create concrete WindowMediators that
extend WindowMediator. The abstract has a protected var
window:Window and in the onRegister of the concrete mediator, I set
window = the injected concrete view.</p>
<p>public class WindowMediator extends Mediator implements
IMediator {</p>
<pre>
<code>protected var window:Window;
public function WindowMediator()
{
super();
}
override public function onRegister():void
{
eventMap.mapListener(window, Event.CLOSE, onWindowClose, Event);
eventMap.mapListener(window, Event.ACTIVATE, onWindowActivate, Event);
eventMap.mapListener(window, Event.DEACTIVATE, onWindowDeactivate, Event);
eventMap.mapListener(window, Event.ADDED_TO_STAGE, onAddedToStage, Event);
eventMap.mapListener(window, NativeWindowBoundsEvent.RESIZE, onWindowBounds, NativeWindowBoundsEvent);
eventMap.mapListener(window, NativeWindowBoundsEvent.MOVE, onWindowBounds, NativeWindowBoundsEvent);
eventMap.mapListener(window, SystemControlsEvent.CLOSE_WINDOW, onSystemControlClose, SystemControlsEvent);
eventMap.mapListener(window, SystemControlsEvent.MAXIMIZE_WINDOW, onSystemControlMaximize, SystemControlsEvent);
eventMap.mapListener(window, SystemControlsEvent.MINIMIZE_WINDOW, onSystemControlMinimize, SystemControlsEvent);
eventMap.mapListener(window, SystemControlsEvent.RESTORE_WINDOW, onSystemControlRestore, SystemControlsEvent);
super.onRegister();
}
protected function onAddedToStage(event:Event):void
{
// initialization
}
protected function onWindowClose(event:Event):void
{
var owner:Window = (window is ModalWindow) ? ModalWindow(window).owner : null;
dispatch(new WindowLifeEvent(WindowLifeEvent.DESTROY, null, window.uid, owner));
}
protected function onWindowActivate(event:Event):void
{
dispatch(new ApplicationWindowEvent(ApplicationWindowEvent.ACTIVATE, window.uid));
}
protected function onWindowDeactivate(event:Event):void
{
dispatch(new ApplicationWindowEvent(ApplicationWindowEvent.DEACTIVATE, window.uid));
}
protected function onWindowBounds(event:NativeWindowBoundsEvent):void
{
dispatch(new ApplicationWindowEvent(ApplicationWindowEvent.BOUNDS, window.uid, event.afterBounds));
}
protected function onSystemControlClose(event:SystemControlsEvent):void
{
window.nativeWindow.close();
}
protected function onSystemControlMaximize(event:SystemControlsEvent):void
{
window.nativeWindow.maximize();
}
protected function onSystemControlMinimize(event:SystemControlsEvent):void
{
window.nativeWindow.minimize();
}
protected function onSystemControlRestore(event:SystemControlsEvent):void
{
window.nativeWindow.restore();
}</code>
</pre>
<p>}</p>
<p>public class PanelWindowMediator extends WindowMediator
implements IMediator {</p>
<pre>
<code>[Inject]
public var model:PanelModel;
[Inject]
public var panelWindow:PanelWindow;
public function PanelWindowMediator()
{
super();
}
override public function onRegister():void
{
window = panelWindow;
panelWindow.panel = model.getPanel(window.uid);
super.onRegister();
}
override protected function onWindowClose(event:Event):void
{
model.closeWindow(panelWindow.panel);
super.onWindowClose(event);
}</code>
</pre>
<p>}</p></div>stevensackstag:robotlegs.tenderapp.com,2009-10-18:Comment/10607962010-02-19T09:24:09Z2010-02-19T09:24:09ZExtend Mediators (for Roland)<div><p>Hi Steven,</p>
<p>Which thread was closed? I thought that even if an issue was
"resolved" it could still be re-opened by anyone adding a new
comment. Also, as this thread is marked as private (I noticed that
on your last thread as well) I think it's only visible to yourself
and members of the Robotlegs support team (3 of us at the
moment).</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/10607962010-03-11T01:14:47Z2010-03-11T01:14:47ZExtend Mediators (for Roland)<div><p>I couldn't reopen it. It wouldn't let me. I didn't mean to make
this private, either.</p></div>stevensackstag:robotlegs.tenderapp.com,2009-10-18:Comment/10607962010-03-11T12:04:42Z2010-03-11T12:04:42ZExtend Mediators (for Roland)<div><p>Oh no! Perhaps closing issues is a bad idea then - I assumed
that anyone could re-open any issue by simply continuing the
conversation. Will have to look into that. This thread is now
public - not sure what's going on there either! Sorry for any
hassles.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/10607962010-03-12T01:15:22Z2010-03-12T01:15:22ZExtend Mediators (for Roland)<div><p>I made it public. The mystery is solved. ;)</p></div>stevensacks