Get the book!
The best Java IDE

Tip of the week: Associations Made Easy

Posted by Eitan Suez Fri, 07 Jul 2006 20:28:00 GMT

NakedObjects originally introduced a terrific way to establish associations between objects in a user interface. It automatically enabled this via drag and drop.

For some reason, dnd in many ways is not used as much as it used to be. Having to take the hand off the keyboard is admittedly a "productivity mark deduction."

So, in JMatter, I set out to enable associations in more than one way. For starters, dnd works out of the box. But one can also click a "pick" button that will display a listing of entries of the type for a given association, that the user simply picks from.

To make the example concrete, let's say we're working with the Symposium manager demo application in JMatter. And let's further say that we're defining a new talk to be given. Talks have a many-to-one association to the speaker (or presenter) giving the talk.

My favorite way of establishing that association is with the in-place associator widget that's built-in to JMatter. The way it works is that you simply start typing and the list of entries automatically filters out entries that do not match. It's that sort of dynamic JComboBox that web browsers popularized, I suppose. Except that the data comes straight from the database.

Here's a snapshot of me trying to define a new talk, In Action, as it were:

Eitan Associating a Speaker to a talk

(Please pardon the humour if you find it in ill taste :-) )

The only detail to tend to is to specify which field of Speaker are we searching by. That's what that little 'magnifying glass' icon to the left of the text field is for. It's a drop-down combobox that dynamically lists the various fields you might want to search by.

Here's how you control the default field that JMatter should use:

static
{
   ComplexType type = ComplexType.forClass(Speaker.class);
   type.setDefaultSearchField(type.field("name").field("first"));

}

And that's the tip of the week.

no comments

Comments

Comments are disabled

Powered