Using the MVC Pattern in Eclipse Applications
22. August 2006
When I made my first “Hello World” PlugIn I didn’t care about such things like Data-Workflow or Application Data Tree, I just tried the different features the framework provided. But as the applications became more and more complex and also the amount of different views, perspectives and editors increased I was forced to implement different mechanism to manage all the different data and their presentation. In this article I want to show how to install the Model-View-Controller in your RCP to make a clear software-archictcture and flexible ways for interacting between view and model.
A theoretic discourse
The Model-View-Controller is a paradigma that was developed in the 70s as a result of application-development. In this time the technique was ready for applications with a graphical-user-interface (gui) and a mechanism was needed for handling the new components in a clear way. The Norwegian Trygve Reenskaug developed a schema that is used until in our days and is the most known Design-Pattern. As the name implies the application is divided into three components which have defined communication paths.

The most important things are:
- Views don’t know each other
- The Controller references no views
- The Model references no views
- The View doesn’t manipulate the model
- Only the view knows how to react on which events
Matching the Pattern to RCP Elements
So far so good. But how to match this pattern to your RCP-Application? - Very easy. Just try to find Eclipse-Components that can be used for the special purposes.
- Views are all elements that represents data, e.g. ViewParts, EditorParts, Trees, Tables,…
- Controller can be very easy implemented with JFace Action. Here you have the advantage, that they can be embedded by the framework into views, like Coolbars, Toolbars, ContextMenus,… But they can be also called if a Selection-Event of a SWT-Button is triggered.
- The model is your Business-Model. You just have to add support for PropertyChange-Notfication.

Communication between different Views
An often question is how to communicate different different views? With the MVC no problem: The views are triggering events from the model, therefore its absolutely irrelevant from where the manipulation request came from.

A simple example
I’ve written a small example that should demonstrate in a very simple way the relationships between the different components.

Download
Download the MVC Example as RCP (Source included - 9,3 Mbyte)
CVS-Checkout (more info)



Great!! I really needed this clear overview. Keep it up.
Comment by Lager — 24. November 2007 @ 19:09
Thanks for the example. I am very glad I found your site.
I see that the java beans classes
java.beans.PropertyChangeEvent;
java.beans.PropertyChangeListener;
are used.
Eclipse provides IPropertyChangeListener other class and means for listening for bound changes. I am confused as to when to use them and when to tuse the java beans classes. Why not use the classes provided by Eclipse?
Thanks
Bill B
Comment by Bill Blalock — 28. November 2007 @ 21:42
Hi, i have some problems to dowload your sources, please help me!
Comment by papaetoo — 8. June 2009 @ 15:34
Same here I can only run the program and not see the source.
Comment by steve — 16. June 2009 @ 00:04
You’ll find the source in plugins/de.spiritlink.mvc_1.0.0.jar/src
CVS is currently down
Comment by Tom Seidel — 16. June 2009 @ 00:25
Hi, I have the same problem when i developped my rcp, i hope to implement the MVC pattern in my RCP application but i d’ont know how to implement it ?!, and your example is very clear to anderstand the MVC pattern in RCP and i use it. thank you very much. i visited regulary your web site for another matter.
Comment by Kheireddine MESSAI — 2. July 2009 @ 14:10
A very interesting web site consulting, specially to change experience.
Thanks.
Atman
Comment by Atman Haddj Elmrabet — 24. August 2009 @ 17:34
[…] rich client 2.0 » Using the MVC Pattern in Eclipse Applications – […]
Pingback by camestres.com » Links for 5/1/2010 — 5. January 2010 @ 17:27