Last modified by Vincent Massol on 2024/11/19 16:12

Hide last authors
Thomas Mortagne 2.1 1 {{include document="XWiki.DesignClassSheet"/}}
Thomas Mortagne 1.1 2
Thomas Mortagne 2.1 3 = Goal =
Thomas Mortagne 1.1 4
5 We need generic displayer descriptors to indicate how some properties should be viewed/edited.
6
7 This could be used for:
Thomas Mortagne 2.1 8
Thomas Mortagne 1.1 9 * XClass (wiki objects)
10 * Properties (bean descriptors like macros parameters)
11
Thomas Mortagne 2.1 12 = Need =
Thomas Mortagne 1.1 13
14 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.
15
16 As generic as possible, these descriptors should contains only what is really necessary and let presentation layer handle the rest.
17
Thomas Mortagne 2.1 18 = Proposed design =
Thomas Mortagne 1.1 19
Thomas Mortagne 9.1 20 Keep using the property java type and only use displayer descriptor to provide informations that the type can't provide itself.
Thomas Mortagne 5.1 21
22 == Property descriptor ==
23
24 A base descriptor with some information valid for all types:
Thomas Mortagne 36.1 25
Ecaterina Moraru (Valica) 35.2 26 {{code language="java"}}class DisplayerDescriptor<T>
Thomas Mortagne 1.1 27 {
28 /* Suggest possible value for the property. */
29 List<T> getPossibleValues();
30
31 /* Indicate if the editor aceept custom value or only the one coming from #getPossibleValues. */
32 boolean onlyPossibleValues();
Ecaterina Moraru (Valica) 35.2 33 }{{/code}}
Thomas Mortagne 5.1 34
Thomas Mortagne 24.1 35 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:
Thomas Mortagne 36.1 36
Ecaterina Moraru (Valica) 35.2 37 {{code language="java"}}class NumberDisplayerDescriptor<T extends Number> extends DisplayerDescriptor<T>
Thomas Mortagne 1.1 38 {
Thomas Mortagne 21.1 39 T getMaximumValue();
40 T getMinimumValue();
Thomas Mortagne 1.1 41 }
Thomas Mortagne 22.1 42
Thomas Mortagne 26.1 43 class ListDisplayerDescriptor extends DisplayerDescriptor<List>
Thomas Mortagne 22.1 44 {
45 Class<V> getType();
46 }
47
Thomas Mortagne 26.1 48 class MapDisplayerDescriptor extends DisplayerDescriptor<Map>
Thomas Mortagne 22.1 49 {
Thomas Mortagne 23.1 50 Class<K> getKeyType();
51 Class<V> getValueType();
Thomas Mortagne 22.1 52 }
Thomas Mortagne 25.1 53
Thomas Mortagne 26.1 54 class StringDisplayerDescriptor extends DisplayerDescriptor<String>
Thomas Mortagne 25.1 55 {
56 boolean isMultiline();
Ecaterina Moraru (Valica) 35.2 57 }{{/code}}
Thomas Mortagne 5.1 58
Thomas Mortagne 11.1 59 == Bean property annotation ==
Thomas Mortagne 10.1 60
61 * JSR 303 constraints are already support in bean populate apis of xwiki-properties, just need to generate descriptors using them
62 * provide possible values related annotations
Thomas Mortagne 29.1 63 ** {{code language="java"}}@PropertyPossibelValues(String providerRoleHint, boolean onlyPossibleValues){{/code}}
Thomas Mortagne 33.1 64 ** {{code language="java"}}@PropertyPossibelValues(Object[] possibleValues, boolean onlyPossibleValues){{/code}}, generally better to use an enum as property type instead if ##onlyPossibleValues## is true
Thomas Mortagne 27.1 65 * provide displayer related annotations
Thomas Mortagne 28.1 66 ** {{code language="java"}}@PropertyDisplayer(Class<T extends DisplayerDescriptor> displayerClass, Object[] displayerParameters){{/code}}
Thomas Mortagne 25.1 67 ** ...
Thomas Mortagne 15.1 68
Thomas Mortagne 18.1 69 {{code language="java"}}
Thomas Mortagne 15.1 70 class CodeMacroParameters
71 {
72 @PropertyPossibelValues("highlight", true)
73 String setLanguage();
74
75 [...]
76 }
Thomas Mortagne 16.1 77 {{/code}}

Get Connected