> I am developing an application that displays a JTree and shows
> different options based on what the user clicks within the JTree. I
[quoted text clipped - 19 lines]
>
> Thanks
This is the job of your controller.
When the user selects a tree node, your controller should receive the
event and know, via it's configuration, which view to associate with the
resulting model object.
The configuration could be as simple as a properties file that looks
something like this...
com.myproject.model.ModelType1=com.myproject.view.ViewType1
com.myproject.model.ModelType2=com.myproject.view.ViewType2
At start up, this is parsed into a map that looks something like this..
Map<Class<? extends Model>, Class<? extends View>> viewMap;
When a node is selected you use a viewMap.get to pull the appropriate
view class out of the map and instansiate it reflectively.
The controller then passes the model to the view and displays it.
Beyond this you can get more sophisticated, with interfaces like
ViewFactory etc, but it is this basic mechanism that you should aim
towards. Let your controller integrate your models and views.
Jason Cavett - 01 Dec 2006 13:48 GMT
> > I am developing an application that displays a JTree and shows
> > different options based on what the user clicks within the JTree. I
[quoted text clipped - 42 lines]
> ViewFactory etc, but it is this basic mechanism that you should aim
> towards. Let your controller integrate your models and views.- Hide quoted text -- Show quoted text -
Okay, I didn't think of having a config file and using reflection.
Since you mentioned a factory, would it also be feasible (from a poor
design vs. good design standpoint) to use an overloaded factory class?
It's kind of the same idea, but instead of having a properties file, I
have the class enforce everything.
wesley.hall@gmail.com - 01 Dec 2006 14:41 GMT
> Since you mentioned a factory, would it also be feasible (from a poor
> design vs. good design standpoint) to use an overloaded factory class?
> It's kind of the same idea, but instead of having a properties file, I
> have the class enforce everything.
I am not exactly sure what you mean here, but it doesn't matter. As
long as it is your controller that is linking your model and views and
displaying the views based on user action, then how you inform your
controller of which views go with which models is entirely your choice.
The solution that I mentioned was not my idea of a perfect solution,
there are short comings in this approach too, but it is "on the right
track" in terms of MVC. I did not want to dilute that message with lots
of stylistic stuff and I certainly wouldn't want to deprive you of the
enjoyment (and wonderful learning experience) of designing your own
software. Good luck!