Wiki source code of Properties displayers descriptors
Last modified by Vincent Massol on 2024/11/19 16:12
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
![]() |
2.1 | 1 | {{include document="XWiki.DesignClassSheet"/}} |
![]() |
1.1 | 2 | |
![]() |
2.1 | 3 | = Goal = |
![]() |
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: | ||
![]() |
2.1 | 8 | |
![]() |
1.1 | 9 | * XClass (wiki objects) |
| 10 | * Properties (bean descriptors like macros parameters) | ||
| 11 | |||
![]() |
2.1 | 12 | = Need = |
![]() |
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 | |||
![]() |
2.1 | 18 | = Proposed design = |
![]() |
1.1 | 19 | |
![]() |
9.1 | 20 | Keep using the property java type and only use displayer descriptor to provide informations that the type can't provide itself. |
![]() |
5.1 | 21 | |
| 22 | == Property descriptor == | ||
| 23 | |||
| 24 | A base descriptor with some information valid for all types: | ||
![]() |
36.1 | 25 | |
| |
35.2 | 26 | {{code language="java"}}class DisplayerDescriptor<T> |
![]() |
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(); | ||
| |
35.2 | 33 | }{{/code}} |
![]() |
5.1 | 34 | |
![]() |
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: |
![]() |
36.1 | 36 | |
| |
35.2 | 37 | {{code language="java"}}class NumberDisplayerDescriptor<T extends Number> extends DisplayerDescriptor<T> |
![]() |
1.1 | 38 | { |
![]() |
21.1 | 39 | T getMaximumValue(); |
| 40 | T getMinimumValue(); | ||
![]() |
1.1 | 41 | } |
![]() |
22.1 | 42 | |
![]() |
26.1 | 43 | class ListDisplayerDescriptor extends DisplayerDescriptor<List> |
![]() |
22.1 | 44 | { |
| 45 | Class<V> getType(); | ||
| 46 | } | ||
| 47 | |||
![]() |
26.1 | 48 | class MapDisplayerDescriptor extends DisplayerDescriptor<Map> |
![]() |
22.1 | 49 | { |
![]() |
23.1 | 50 | Class<K> getKeyType(); |
| 51 | Class<V> getValueType(); | ||
![]() |
22.1 | 52 | } |
![]() |
25.1 | 53 | |
![]() |
26.1 | 54 | class StringDisplayerDescriptor extends DisplayerDescriptor<String> |
![]() |
25.1 | 55 | { |
| 56 | boolean isMultiline(); | ||
| |
35.2 | 57 | }{{/code}} |
![]() |
5.1 | 58 | |
![]() |
11.1 | 59 | == Bean property annotation == |
![]() |
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 | ||
![]() |
29.1 | 63 | ** {{code language="java"}}@PropertyPossibelValues(String providerRoleHint, boolean onlyPossibleValues){{/code}} |
![]() |
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 |
![]() |
27.1 | 65 | * provide displayer related annotations |
![]() |
28.1 | 66 | ** {{code language="java"}}@PropertyDisplayer(Class<T extends DisplayerDescriptor> displayerClass, Object[] displayerParameters){{/code}} |
![]() |
25.1 | 67 | ** ... |
![]() |
15.1 | 68 | |
![]() |
18.1 | 69 | {{code language="java"}} |
![]() |
15.1 | 70 | class CodeMacroParameters |
| 71 | { | ||
| 72 | @PropertyPossibelValues("highlight", true) | ||
| 73 | String setLanguage(); | ||
| 74 | |||
| 75 | [...] | ||
| 76 | } | ||
![]() |
16.1 | 77 | {{/code}} |
