Models (ModelData <- Model <- etc...) support a form of "instrospection" as property names (String) and values can be retrieved at runtime. I guess this is great at least for internal use.
But when it comes to write some models for ComboBox, Tree, etc, I don't see how it is useful.
I mean : to tell the component which text it must displays, the model must set a property (name/value) and the model user must tell the component what is the name of the property (by default it is "text" for ComboBox, for example). IMHO it is not a good constraint because :
- it is not type-safe
- it can easily cause typo errors
- it introduces coupling (the model user must know the internal behaviour of the model : what is the name of the display property)
I think it would be nice to have something like
in a Model interface, a
public String getDisplayText();
in a SortableModel sub-interface, etc...
public Object getSortValue();
Other possibility would be that model-based components rely on a ModelDisplayProvider class with a
Would it be possible to slightly reconsider/enhance the Model API ? Thoughts ?
public String getDisplayText(M model);