In Search of the Holy Grail of Swing MVC (Part 2)

After describing the basic design idea in Part 1 now let’s get some meat on the design:

May look complicated but the application developer only deals with two interfaces (Controller and View) and two implementations (Controller1 and View1) as you can see here:

The ControllerQueue will also be used for parent to child controller communication:

In the next part I’ll create some code examples to demonstrate the above design idea.

And Now for Something Completely Different 🙂

ARTHUR: “Please go and tell your master that we have been charged by God with a sacred quest,  and if he will give us food and shelter for this night he can join us in our quest for the Holy Grail.”
MAN: “Well, I’ll ask him, but I don’t think he’ll be very keen. He’s already got one, you see?”
ARTHUR: “What?”
GALAHAD: “He says they’ve already got one!” (They are stunned.)
ARTHUR: “Are you sure he’s got one?”
MAN: “Oh yes.  It’s very nice”

In Search of the Holy Grail of Swing MVC (Part 1)

One of the greatest challenges for those developing with the Swing framework is that few instructions from Sun are currently available that explain the most expeditious ways of developing more comprehensive projects with Swing. The JFC (Java Foundation Classes) Library is, fundamentally, a gigantic – very powerful and highly flexible – tool box that makes it possible to implement virtually all client developments. Unfortunately, one is also compelled to do so on a relatively low abstraction level.

The term Model-View-Controller (MVC) as it relates to Swing, for instance, refers only to the interplay between data and graphical components (UI Controls). A structure that would meet the standards of a higher level MVC model, such as the one we are familiar with from the development of client server applications, is not available.

Currently, new attempts are underway to establish a Swing Application Framework in conjunction with the JSR-296, which aims to eliminate some of these weaknesses. The processing of prolonged duration function requests is accordingly going to be handled via so-called Tasks based on the familiar SwingWorker method.

One of the disadvantages of the SwingWorker pattern is the fact that the controller function is not clearly separated from the Surface, which results in the functions being scattered all across the entire UI code. This makes the creation of unit tests for the controller code more complicated or even impossible.

In Search of the Holy Grail of Swing MVC I think the following structure would be a good starting point for a common Swing Application Framework:

In Part 2 I’ll try to create a Real World implementation using the above basic design.

And Now for Something Completely Different 🙂

 “That is your purpose Arthur … the Quest for the Holy Grail … It is gone.”  All the KNIGHTS are left gasping in awe and wonderment. They all turn and look at ARTHUR.

Maven + WTP + Eclipse

If you want to run a Maven Java Web Project inside Eclipse you may use the WTP support from the Maven Eclipse Plugin. It configures your Maven Web Project for use with servers like Tomcat inside Eclipse:

  • Add the plugin to your web project’s “pom.xml”:
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-eclipse-plugin</artifactId>
      <inherited>true</inherited>
      <configuration>
        <wtpversion>2.0</wtpversion>
        <downloadSources>2.0</downloadSources>
      </configuration>
    </plugin>
  • Right click the project’s “pom.xml” and “Run as / Maven build…” (Goal “eclipse:eclipse”):
  • Refresh you project

Voilà – You have a ready configured web project you can simply add to your integrated server.