JFace and its model-view controller

As we saw in the SWT introduction, the Standard Widget Toolkit renders our data. It does not organize it, transform it, neither it helps us to handle it. And that’s correct. As the name says, it’s a widget toolkit, and it’s what we should expect.
But in our road to Eclipse RCP, here’s another vital friend: JFace.
JFace is a lot of things -maybe too many- but today we’ll be talking about its model-view controller.
Just a little preface for who never really faced theory behind model-view controllers.
In an application you usually have complex information and “views” on that information. When you display data, in fact, you transform tokens of data to make them coherent with the way you want the data displayed. A model-view controller is a formal way to do this, to replace long, hardly reusable, buggy code.
Think of it: once you have an algorithm to navigate information (as it could be a table, a tree, a chain of links…) and some rules to display the tokens of data properly, you just need to glue it all up. Debug and changes become simpler then ever. JFace will do this for us.
The main concept is that to handle structured data, you need a viewer, something that wraps the widget and learns from us how to render the complex data the application uses. If our application (or a portion) uses “Violin” objects, our TableViewer should not require “strings”, but violins and an interpretation key for violins
This is how a model-view controller works. Defined a structure to navigate data, defined a rendering method for one item of data, you have all you need to display automatically any type of information.

Read more of this post

Follow

Get every new post delivered to your Inbox.