How Tree fits into MVC pattern
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
a node for Manage Flight, Manage Customer. Each would be added to the tree
a the task was selected from a Toolbar. As a sub-node of these was double
clicked a Panel would open to the right of the tree. I just wondered how this would be handled in an MVC environment.
Thanks.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
One believes what happens in Vegas stays in Vegas. I mean the UI. Getting from tree selection to the detail panel refresh event doesn't involve any model data or fancy logic.
Two uses the Window as a mini-controller within the GUI. It decouples the tree panel from the detail panel. One could argue the window is a legit controller in a nested or recursive MVC design. I'm not sure.
Three takes the controller role of interpreting user gestures seriously so all clicks and such go through the controller. This might be overkill or it might be just right if something more complicated was going to happen, like opening a whole new window.
Do any of those sound useful or horrible or whatever?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
So in terms of the Model View Controller (MVC) pattern you have two separate models:
- tree model
- panel model.
Both apply the MVC pattern separately. For instance if the panel model state (values) survives clicking other tree nodes then your two models are totally independent from each other except that the panel model creation is triggered by the tree model on behalf of the tree controller.
Is MVC overkill here?
a) If you now or probabely in the future need to have N controllers and / or N views per model then MVC shurely is the right choise.
b) If you are sure that only one controller and only one view is needed per model then you could choose a simpler solution not keeping clear the roles of model, view and controller.
I allways model MVC (for Java/Swing). The initial additional effort usually is compensated soon.
Thomas.
www.classic-and-class.com - www.evalulearn.com
Interfaces are the glue of OO.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by Stan James:
Now you're into the recursive MVC nature of Swing. The "business model" held in a back-end server ...
The MVC pattern may be applied to the system having the model in the backend, as you described, then the client and/or presentation tiers act as Controller and View. This is like the "macro cosmos".
The MVC pattern may and should also be applied to the "micro cosmos" splitting the client itself into Model (fed by the server's model), View and Controller roles. That is, what I described, because of the initial topic:
Originally posted by Barry Brashear:
... an application that has a tree on the left. When an item of the tree is double clicked it opens a panel on the right ...
Swing components implement the Controller and View roles (in an uggly mix ...) and mostly come with a specialized J*Model to be used with the J*-UI-component.
So at the end we have at least three models (not only for Java / Swing):
- the server-side model, usually connected to a persistent storage like a database (recursively; server's Controller&View having client's models).
- the client-side tree model
- the client side panel model (not recursive to but in sequence with the tree model)
Thomas.
[ August 21, 2005: Message edited by: Thomas Taeger ]
www.classic-and-class.com - www.evalulearn.com
Interfaces are the glue of OO.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
For your application you will need a controller to respond to the tree events, and a controller to respond to panel events. The way that I might structure this could be :
When the user double clicks on the TreeView component, the TreeController updates the TreeModel if necessary and calls a method in PanelController (passing a reference to the node/leaf that was called perhaps). The panel controller sets up the PanelModel object (if needed) and displays the appropriate panel. If a user makes changes in the panel the PanelController is responsible for pushing those changes to the PanelModel.
This would be the simplest way to implement MVC for this setup.
HTH,
Fintan
| PI day is 3.14 (march 14th) and is also einstein's birthday. And this is merely a tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |







