1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.ui.field;
35
36 import info.magnolia.ui.editor.ComplexPropertyDefinition;
37 import info.magnolia.ui.editor.EditorDefinition;
38 import info.magnolia.ui.ConfiguredViewDefinition;
39 import info.magnolia.ui.editor.ItemProviderDefinition;
40 import info.magnolia.ui.editor.ItemProviderStrategy;
41 import info.magnolia.ui.editor.EditorView;
42 import info.magnolia.ui.editor.FormView;
43
44 import java.util.Optional;
45
46 import lombok.Data;
47 import lombok.EqualsAndHashCode;
48
49
50
51
52
53 @EqualsAndHashCode(callSuper = true)
54 @Data
55 public class ConfiguredComplexPropertyDefinition<T> extends ConfiguredViewDefinition<EditorView<T>> implements ComplexPropertyDefinition<T> {
56 private String name;
57 private String label;
58 private String description;
59 private boolean i18n;
60 private String styleName;
61 private ItemProviderDefinition<T, T> itemProvider;
62
63 public ConfiguredComplexPropertyDefinition() {
64 setImplementationClass((Class) FormView.class);
65 }
66
67 @Override
68 public EditorDefinition<T> getEditorDefinition() {
69 if (this instanceof EditorDefinition) {
70 return (EditorDefinition<T>) this;
71 }
72 throw new IllegalStateException("Attempted to cast a non-editor property definition to EditorDefinition");
73 }
74
75
76
77
78
79
80
81
82 public static class Wrapper<T> extends ConfiguredComplexPropertyDefinition<T> {
83
84 private final EditorDefinition<T> delegate;
85
86 public Wrapper(EditorDefinition<T> delegate) {
87 this.delegate = delegate;
88 }
89
90 @Override
91 public EditorDefinition<T> getEditorDefinition() {
92 return delegate;
93 }
94
95 @Override
96 public String getName() {
97 String name = super.getName();
98 if (name == null) {
99 name = delegate.getName();
100 }
101 return name;
102 }
103
104 @Override
105 public String getLabel() {
106 String label = super.getLabel();
107 if (label == null && delegate instanceof EditorPropertyDefinition) {
108 label = ((EditorPropertyDefinition) delegate).getLabel();
109 }
110 return label;
111 }
112
113 @Override
114 public String getDescription() {
115 String description = super.getDescription();
116 if (description == null && delegate instanceof EditorPropertyDefinition) {
117 description = ((EditorPropertyDefinition) delegate).getDescription();
118 }
119 return description;
120 }
121
122 @Override
123 public boolean isI18n() {
124 if (super.isI18n()) {
125 return true;
126 } else if (delegate instanceof EditorPropertyDefinition) {
127 return ((EditorPropertyDefinition) delegate).isI18n();
128 } else return false;
129 }
130
131 @Override
132 public String getStyleName() {
133 String styleName = super.getStyleName();
134 if (styleName == null && delegate instanceof EditorPropertyDefinition) {
135 styleName = ((EditorPropertyDefinition) delegate).getStyleName();
136 }
137 return styleName;
138 }
139 }
140 }