PureMVC Architects Lounge

Announcements and General Discussion => Getting Started => Topic started by: MatFromBordeaux on May 24, 2008, 05:37:07



Title: Flex Tree control, Proxy and VOs
Post by: MatFromBordeaux on May 24, 2008, 05:37:07
Hi,

I am building my first Flex/PureMVC application to get a nice picture of the framework.

I don't find simple information about how I could represent a tree structure in my model...

I found examples of proxies manipulating simple VO as their "data", or ArrayCollection, but how could I manipulate (in proxy I suppose) and store (in proxy's data) a tree of objects.

My sample is quite simple: represent a shop, with products arranged in categories.
The tree is a set of categories, each category can contain subcategories and/or products.

[DVD]
  [Drama]
    .National treasure
    .The walker
  [Animation]
    .Toy story
[Books]
  .Learning AS3
  .Design Patterns

I suppose my Proxy would expose methods like getCategories, getProductsForCategory, etc... These methods returning stuff from the data var of the proxy.

Last but not least, I have a Tree control in my view component. How can I use Bindable to fill my Tree control with the data retreived by the mediator (through a notification sent by my proxy) ?


(don't forget I am not yet familiar with the framework)

Thanks for any response,

--
Mathieu


Title: Re: Flex Tree control, Proxy and VOs
Post by: puremvc on May 24, 2008, 06:53:14
Hi Matthew,

Sounds like you might be better off using an XMLListCollection. Queries to the Proxy like getMoviesByCategory would be a snap to pull off with E4X.

Also, if I'm not mistaken, the CodePeek demo uses a Tree control to display your searches by language, so you might want to look at that demo.

-=Cliff>


Title: Re: Flex Tree control, Proxy and VOs
Post by: MatFromBordeaux on May 24, 2008, 07:45:43
Hi Cliff,

I just downloaded CodePeek source code. I'm sure I'll find everything I need.
Thanks a lot for you answer.


--
Mat


Title: Re: Flex Tree control, Proxy and VOs
Post by: MatFromBordeaux on May 26, 2008, 02:37:33
Following this post about Tree control, I have a question.

Here is a piece of code from CodePeek AIR app.
Mediator method triggered when the user clicks on any item of the search Tree :

:
protected function onTreeItemSelect( event:Event ):void
{
    if ( app.tree.selectedItem.@url == undefined ) {   
      sendNotification( ApplicationFacade.SEARCH_TYPE_SELECTED, app.tree.selectedItem );
    } else {
      sendNotification( ApplicationFacade.SEARCH_SELECTED,[ app.tree.getParentItem( app.tree.selectedItem ), app.tree.selectedItem ] );
      app.browser.location = app.tree.selectedItem.@url;
    }
}

To know if the user clicked (in the search tree) on a Language or a Search keyword, CodePeek looks for a "url" attribute in the item : if no url attribute is found, it means that a Language (folder) was clicked...

Is there another way of doing this ?

How can I know the name of the XML tag of the clicked item ?

thanks in advance,

--
Mat


Title: Re: Flex Tree control, Proxy and VOs
Post by: puremvc on May 26, 2008, 08:38:24
Well app.tree.selectedItem would be an XMLList. I'm not at the computer right now, but if you look at the doc for XMLList, you'll find it.

Also, note CodePeek was the first PureMVC demo and all the best practices for view separation hadn't yet been sorted out. We'd today want to expose app.tree.selectedItem as a top level var in the app component.

-=Cliff>