This could be handled in a more elegant fashion, if you used a
presentation model and injection.  But, a simple way to solve this is to
create a selectedRooms ArrayCollection in the model.  This collection
would hold references to the roomVO's that are in the rooms collection;
that is bound to the DataGrid.  When the user selects a room, dispatch
an event that contains the selectedItem (RoomVO).  In the command, add
the selectedItem to the selectedRooms collection.  In the view that
contains the TabNavigator, add an event listener for the
CollectionEvent.COLLECTION_CHANGE event; on the selectedRooms collection
in the model.  In the eventHandler function for the collection change
event, manually update the TabNavigator; based on the items in the
selectedRooms collection.  If you look at the CollectionEventKind of the
CollectionEvent, you can branch for add or remove.  For each RoomVO in
the selectedRooms collection, you can loop through the children of the
TabNavigator; to determine if the room component exists already (compare
to the component's roomVO).  If not, create an instance of the room
component , set the component's roomVO, and add the component, as a
child, to the TabNavigator.  If you're allowing removes as well, you'll
have to loop through the TabNavigator children first and see if they
exist in the selectedRooms collection.  Except for the first child, if a
component's roomVO doesn't exist in the collection, remove the child
component from the TabNavigator.

Another alternative would be to make a component out of the
TabNavigator's parent.  Use binding to the selectedRooms model
collection on the component's tag, and use a public getter/setter for
the dataProvider collection in the component.  In the setter, mark a
dataProviderChanged Boolean to true and invalidateProperties.   In
commitProperties, add or remove the room components to/from the
TabNavigator, and invalidateDisplayList.  This eliminates the collection
change event listener, but is a bit more complicated.

Good luck!

-TH

--- In [email protected], "Paul Andrews" <p...@...> wrote:
>
> ----- Original Message -----
> From: "someguy7_7" mus...@...
> To: [email protected]
> Sent: Sunday, January 04, 2009 8:23 PM
> Subject: [flexcoders] Re: Cairngorm proper usage
>
>
> > Can you give me some ideas on how I should setup the model? Have a
> > property called tabs that just has a list of view components that I
> > bind to the tabnavigator? Come to think of it I am not sure where I
> > would bind that to the tabnavigator.
>
> On reflection, your tabnavigator is doing two things - the first tab
is
> displaying all the rooms, then you have additional tabs that show
opened
> rooms.
>
> Essentially, your tab navigator is driven by the content of the room
list
> shown in the first tab. You can't bind a tabnavigator directly to the
model
> automatically, since you need to create containers to represent each
opened
> room and add them to the tab navigator and presumably remove them when
the
> room is closed. Essentially, you need to listen for changes in the
room
> model. You should be able to drive this from the same part of the
model you
> are binding your datagrid from on the first tab.
>
> Your view is going to need a method (function) to respond to changes
in the
> room data (specifically the field that says whether a room is open or
> closed) and I thing the view can do this using BindingUtils and the
> bindSetter() method to invoke a function to manipulate that
Tabnavigator
> child containers according to changes in the model.
>
> It is going to require some work.
>
> Paul
>
> >
> > Thanks
> >
> > --- In [email protected], "Paul Andrews" paul@ wrote:
> >>
> >>
> >> ----- Original Message -----
> >> From: "someguy7_7" muswei@
> >> To: [email protected]
> >> Sent: Sunday, January 04, 2009 6:23 PM
> >> Subject: [flexcoders] Re: Cairngorm proper usage
> >>
> >>
> >> > But how would I setup the binding in the tabnavigator so that the
> >> > first tab the list of rooms never goes away? I can't just set it
to a
> >> > arraycollection of the rooms in the model since that will wipe
out my
> >> > room list that I always want to be there. The only solution I can
> >> > think of is to implement a viewcontroller that listens for a an
event
> >> > that is fired from the command that the model has been updated
with
> >> > the new room which then tells the view to run through the room
list
> >> > and add any rooms that don't already exist. This seems like a lot
of
> >> > extra work. Anyone have a cleaner method?
> >>
> >> Your view should always reflect the model. If the view should
always
> > display
> >> a room list make sure the model always has the list in place. Your
> > problem
> >> is a problem of maintaining an appropriate model, not an
appropriate
> > view.
> >>
> >> Paul
> >>
> >> > Thanks
> >> >
> >> > --- In [email protected], "Ralf Bokelberg"
> >> > <ralf.bokelberg@> wrote:
> >> >>
> >> >> It would be in the spirit of Cairngorm to fire off a EnterRoom
event,
> >> >> which triggers a EnterRoom command. The command calls a
enterRoom
> >> >> method in some model. The TabNavigator binds to this model and
> >> >> updates itself, whenever the model changes
> >> >>
> >> >> With kind regards,
> >> >> Ralf.
> >> >>
> >> >> On Sun, Jan 4, 2009 at 7:49 AM, someguy7_7 <muswei@> wrote:
> >> >> > I am trying to determine the best way to use cairngorm for the
> >> >> > following use case. I want to display a tabnavigator that only
> > has 1
> >> >> > child which is a component that has a list of rooms in a
datagrid.
> >> >> > When one of the rooms is clicked a instance of the room
> > component is
> >> >> > added to the tabnavigator as a child. The room component just
has a
> >> >> > label that says "You are in room xxxxxx". Can I just fire off
a
> >> >> > regular event from the room list component that the main view
is
> >> >> > listening for so it can add the new child to the tabnav or do
I
> > need
> >> >> > to fire off a cairngorm event that goes through a command
which
> >> >> > somehow gets back to the view and tells it to add a new child
> > to the
> >> >> > tabnav?
> >> >> >
> >> >> > Any ideas on the best way to set this up so it does not
violate the
> >> >> > spirit/laws of cairngorm?
> >> >> >
> >> >> > Thanks
> >> >> >
> >> >> >
> >> >>
> >> >
> >> >
> >> >
> >> > ------------------------------------
> >> >
> >> > --
> >> > Flexcoders Mailing List
> >> > FAQ:
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> >> > Alternative FAQ location:
> >> >
> >
https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-\
1e62079f6847
> >> > Search Archives:
> >> > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo!
Groups
> >> > Links
> >> >
> >> >
> >> >
> >>
> >
> >
> >
> > ------------------------------------
> >
> > --
> > Flexcoders Mailing List
> > FAQ:
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > Alternative FAQ location:
> >
https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-\
1e62079f6847
> > Search Archives:
> > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo!
Groups
> > Links
> >
> >
> >
>


Reply via email to