Multiple views populating a common display area

Columbus's Avatar

Columbus

04 Apr, 2012 12:52 PM

Hello all,

My application has multiple views (view1, view2, ..) that are required to populate a common tab navigator (tabnav). To accomplish this, I create a tabnavModel that holds the tab navigator and inject it as a singleton.

Each view creates a visual element (datagrid, chart, etc.) that needs to be added to the common tabnav as a new tab. Here is the approach I chose: I would need to inject the tabnavModel into each view mediator. Then, I would need to create the visual elements inside each view and then pass them in an event (addVisualElement) to the view mediator. The mediator would then call addElement() to add the visual element to the common tabnav. My problem is this: The onRegister method of the viewMediator is where I will register to listen to the addVisualElement event from the view. For the lack of a suitable trigger, I create the visual elements inside the creationCompleteHandler and fire an addVisualElement event. However, the mediator would not have registered to listen to the addVisualElement event until after the event is fired because the creationCompleteHandler in the view runs before the viewMediator's onRegister method. How do I add my visual elements to the common display area (tabnav)? Or may be I am on the wrong track and need to take a different approach. Please let me know what you think.

Thanks,
c

  1. Support Staff 1 Posted by Ondina D.F. on 04 Apr, 2012 03:38 PM

    Ondina D.F.'s Avatar

    Hi Columbus,

    However, the mediator would not have registered to listen to the addVisualElement event until after the event is fired because the creationCompleteHandler in the view runs before the viewMediator's onRegister method.

    You have to dispatch your AddVisualElementEvent after the new visual element has been added to the display list, in order for the Mediator to hear it.
    Just add an event handler for the visual element’s addedToStage event and dispatch your custom AddVisualElementEvent.

    But I think your approach isn’t quite right, or I didn’t understand the workflow.
    What do you mean by a “common tab navigator (tabnav)”.
    Is it a Flex ViewStack (containing View1, View2, View3) + ButtonBar ?
    Is it a mobile app using a ViewNavigator?

    Each view creates a visual element (datagrid, chart, etc.) that needs to be added to the common tabnav as a new tab.

    Does this mean you have a View2 in a ViewStack or something similar, and when you navigate to this view, you create a datagrid and you want to add the datagrid to the ViewStack as well?

    I create a tabnavModel that holds the tab navigator and inject it as a singleton.

    In my opinion the Model shouldn’t hold a display object.

    I would create a TabNavView paired to a TabNavMediator, and let the TabNavMediator listen for events from other parts of the app, and let TabNavView add or remove views.
    This way you wouldn’t have to inject the TabnavModel into your mediators.

    But, as I said, I’m afraid I didn’t understand your use case, so please try and explain again what you need to achieve :)

    Ondina

  2. 2 Posted by Columbus on 09 Apr, 2012 08:04 PM

    Columbus's Avatar

    Ondina - Thanks for your response. I went with your suggestion to create a view/mediator for tabnav - which is essentially a tabnavigator.

    c

  3. Support Staff 3 Posted by Ondina D.F. on 11 Apr, 2012 11:01 AM

    Ondina D.F.'s Avatar

    My pleasure!

  4. Ondina D.F. closed this discussion on 11 Apr, 2012 11:01 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac