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]
Print
Author Topic: TreeItemRenderer - Mediators.  (Read 4015 times)
yeremy
Jr. Member
**
Posts: 11


View Profile Email
« on: September 04, 2008, 10:46:13 »

Hi All!

i've been working with a Tree Control. now i need to add some funtionallity to each item of the tree, to do this is necesary to integrate with the rest of the application, send notifications, get the proxies, etc.

i've created  a itemRenderer and a mediator for this.

:
public class TreeItemFormRenderer extends TreeItemRenderer
{
...
}

it is called from the itemRenderer property :

:
//TreeContainer.mxml

<mx:Tree id="treeForm" left="0" top="0" width="100%" height="100%"
change="handleTreeChange(event);"
defaultLeafIcon="{SetNullLeafIcon}"
itemRenderer="com.dhManager.view.components.util.TreeItemFormRenderer">
</mx:Tree>

and i setup the Tree in the Mediator for treeConteiner.

:

//TreeContainerMediator.as
private function fillTreeView():void
{
treeContainer.treeForm.labelField = "@name";
treeContainer.treeForm.data = "@id";
treeContainer.treeForm.showRoot = false;
treeContainer.treeForm.dragEnabled = true;
treeContainer.treeForm.dataProvider = formProxy.getXMLListCollectionFoms();
}

I need to integrate each TreeItemRenderer to the rest of the application. my question is :
Where i can put the called to the notification which call to "Create Mediator Command" ?

this is the notification :

:
sendNotification( ApplicationFacade.MEDIATOR_CREATE, [ TreeItemFormRendererMediator.NAME, this  ] );
//this : TreeItemFormRenderern Object.

Any Help is good received!!

thanks!

yeremy.
« Last Edit: September 04, 2008, 09:28:11 by yeremy » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: September 05, 2008, 04:03:14 »

Hi yeremy,

You want to send the notification from the TreeContainerMediator not from the actual tree item renderer. Use a bubbling event at the end of the renderer's constructor to notify the TreeContainerMediator that the notification should be sent.

in TreeItemFormRenderer:
:
public class TreeItemFormRenderer extends TreeItemRenderer
{
   import flash.events.Event;
   public static const RENDERER_CREATED:String = "rendererCreated";
   
   public function TreeItemFormRenderer ()
   {
      super();
      ...
      dispatchEvent(new Event( RENDERER_CREATED, true )); // bubbling event
   }
 ...
}

in TreeContainerMediator:
:
import flash.events.Event;

override public function onRegister():void
{
   treeContainer.addEventListener( TreeItemFormRenderer.RENDERER_CREATED, onRendererCreated );
}

override private function onRendererCreated ( event:Event ):void
{
    var renderer:TreeItemFormRenderer = event.target as TreeItemFormRenderer;
    sendNotification( ApplicationFacade.MEDIATOR_CREATE, [ TreeItemFormRendererMediator.NAME, renderer ] );
}

I assume you have a command listening for that MEDIATOR_CREATE that is a factory for creating and registering any type of mediator based on the name.

However If you're only doing this one registration, you could skip the external command and just register the mediator from within the  TreeContainerMediator:

:
override private function onRendererCreated ( event:Event ):void
{
    var renderer:TreeItemFormRenderer = event.target as TreeItemFormRenderer;
    var mediator:TreeItemFormRendererMediator = new TreeItemFormRendererMediator( renderer );
    facade.registerMediator(TreeItemFormRendererMediator);
}

-=Cliff>
Logged
yeremy
Jr. Member
**
Posts: 11


View Profile Email
« Reply #2 on: September 06, 2008, 08:33:37 »

hey Cliff!

Thanks for your help!...i tried to do that you recommended me. but for some reason, it doesn't work correctly.

in TreeItemFormRenderer.
:
    public class TreeItemFormRenderer extends TreeItemRenderer
    {
/* Constants */
public static const EVENT_ITEM_RENDERER_CREATED : String = "eventItemRendererCreated";

                          public function TreeItemFormRenderer():void
{
super();
this.addEventListener( MouseEvent.ROLL_OUT, onRollOut );
this.addEventListener( MouseEvent.ROLL_OVER, onRollOver );

this.dispatchEvent( new Event( EVENT_ITEM_RENDERER_CREATED, true ) ); // bubbling event
//this.dispatchEvent(new Event( "testEvent", true ));
}
                          ...
             {


in TreeContainerMediator
:
override public function onRegister():void
{
   treeContainer.addEventListener( TreeItemFormRenderer.EVENT_ITEM_RENDERER_CREATED, onRendererCreated );
}

private function onRendererCreated ( event:Event ):void
{
    var renderer : TreeItemFormRenderer = event.target as TreeItemFormRenderer;
    var mediator : TreeItemFormRendererMediator = new TreeItemFormRendererMediator( renderer );
    facade.registerMediator( mediator );
}

i did exactly that you told me. it seems like onRendererCreated  is not being called when the event is sent.

do you know what is wrong in this?

Thanks in Advance!

yeremy.
Logged
yeremy
Jr. Member
**
Posts: 11


View Profile Email
« Reply #3 on: September 06, 2008, 11:15:05 »

it is working now!!!

i moved the call to the dispatchEvent from the constructor method to initializationComplete method.

in TreeItemFormRenderer
:
public class TreeItemFormRenderer extends TreeItemRenderer
{
/* Constants */
public static const EVENT_ITEM_RENDERER_CREATED : String = "eventItemRendererCreated";
public static const EVENT_PRIORITY_CHANGE : String = "eventPriorityChange";

...

public function TreeItemFormRenderer():void
{
super();
this.addEventListener( MouseEvent.ROLL_OUT, onRollOut );
this.addEventListener( MouseEvent.ROLL_OVER, onRollOver );

}

override protected function initializationComplete():void
{
super.initializationComplete();
this.dispatchEvent( new Event( EVENT_ITEM_RENDERER_CREATED, true ) );
}

...
}

Thanks for your help Cliff!!!

yeremy.
Logged
Pages: [1]
Print