Extending Value Models

I recently worked on a large scale Swing project where we made heavy use of value models in the UI. The requirements were complex as the interface designers were more interested in what was good rather than what was easy.

In our technology selection we examined various value model frameworks such as Spring Rich Client, JGoodies Binding and PGS Binding. Of all the frameworks we examined, none provided a simple mechanism for adding meta data to our value models.

Some of our meta data included the following properties:

  1. Obfuscated - some fields need to be be obfuscated from view (such as credit card numbers) based on the users profile.
  2. These fields also needed the ability to be un-obfuscated temporarily.
  3. Editable - Some fields needed to be displayed, but were only editable if the user had the required privileges. Non editable fields looked like labels and not like regular components.
  4. Enabled - Fields that were editable could be either enabled or disabled.
  5. Visible - Fields and forms needed to be shown and hidden.

Even if we could find a framework that could model these aspects it would be unlikely that it would match the exact look and feel requirements of our designers. So in the end, we decided to write our own.

Our approach was to use the ValueModel as both and Adapter and Decorator. As an adapter the value model was responsible for transfering the value to and from the source. As a decorator it provided additional information about the value that was relevant for the UI.

Binding Overview

The key to the design was that the infrastructure modeled our business requirements. In the end developers had very little code to write to create a whole dollar, obfuscated `JFormattedTextField`, and none of it was difficult or Swing-ish.

This entry was posted in Development, UIs and Swing. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *