Properties displayers descriptors
Description
Goal
We need generic displayer descriptors to indicate how some properties should be viewed/edited.
This could be used for:
- XClass (wiki objects)
- Properties (bean descriptors like macros parameters)
Need
Currently for xwiki-properties we are using the property java type to determine how to edit it but it' not enough we need to be able to add some custom constraints, proposed values, etc.
As generic as possible, these descriptors should contains only what is really necessary and let presentation layer handle the rest.
Proposed design
Keep using the property java type and only use displayer descriptor to provide informations that the type can't provide itself.
Property descriptor
A base descriptor with some information valid for all types:
class DisplayerDescriptor<T>
{
/* Suggest possible value for the property. */
List<T> getPossibleValues();
/* Indicate if the editor aceept custom value or only the one coming from #getPossibleValues. */
boolean onlyPossibleValues();
}Then for each type a custom displayer can be provided (the client have to know that that Number type is related to NumberType so theses displayer are well known displayers). Here some examples:
class NumberDisplayerDescriptor<T extends Number> extends DisplayerDescriptor<T>
{
T getMaximumValue();
T getMinimumValue();
}
class ListDisplayerDescriptor extends DisplayerDescriptor<List>
{
Class<V> getType();
}
class MapDisplayerDescriptor extends DisplayerDescriptor<Map>
{
Class<K> getKeyType();
Class<V> getValueType();
}
class StringDisplayerDescriptor extends DisplayerDescriptor<String>
{
boolean isMultiline();
}Bean property annotation
- JSR 303 constraints are already support in bean populate apis of xwiki-properties, just need to generate descriptors using them
- provide possible values related annotations
@PropertyPossibelValues(String providerRoleHint, boolean onlyPossibleValues)@PropertyPossibelValues(Object[] possibleValues, boolean onlyPossibleValues), generally better to use an enum as property type instead if onlyPossibleValues is true
- provide displayer related annotations
@PropertyDisplayer(Class<T extends DisplayerDescriptor> displayerClass, Object[] displayerParameters)- ...
class CodeMacroParameters
{
@PropertyPossibelValues("highlight", true)
String setLanguage();
[...]
}
Thomas Mortagne