Sunday, August 28, 2011

Why I love the DataBinding framework

I'm working on an enterprise client server application. In my domain model I use a generic ValueList/Value construction to map all kinds of simple selectable values. Think of it as a customizable enum thats stored in the database backend. It's been a while since I annotated the JPA model with the name of the ValueList wherever a value gets referenced, the main purpose of this was to be able to pre-populate the value fields with the default value from the corresponding list.

@JoinColumn(name = "origin_id")
@ValueListName(name = ValueListNames.PERSONORIGIN)
@ManyToOne(optional = true)
public Value getOrigin() {
return this.origin;
}


Yesterday I created a new feature that enables the user to edit the values of the list whenever he clicks on a Combo and then hits F1. The solution is quite straightforward.

In the Command Handler for the key

- I ask the display for the focus control
- I ask the active part for its DataBindingContext
- I search the Context for the proper binding of the focus control
- I ask the binding for its model element
- I ask the model element wether it has an annotated ValueList name
- if so, I open the Edit Dialog for the correct ValueList

That's true DRY I think.

Jupyter Kernel for Java9