1 package fr.ifremer.dali.ui.swing.util.table;
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 import fr.ifremer.dali.decorator.DecoratorService;
27 import fr.ifremer.dali.dto.DaliBeans;
28 import fr.ifremer.dali.dto.referential.pmfm.PmfmDTO;
29 import fr.ifremer.dali.service.DaliServiceLocator;
30 import fr.ifremer.quadrige3.core.dao.technical.decorator.Decorator;
31
32
33
34
35
36
37
38 public class DaliColumnIdentifier<R extends AbstractDaliRowUIModel> extends fr.ifremer.quadrige3.ui.swing.table.ColumnIdentifier<R> {
39
40
41
42
43
44
45
46
47
48
49
50 protected DaliColumnIdentifier(String propertyName, String headerI18nKey, String headerTipI18nKey, Class propertyType, String decoratorName, boolean mandatory) {
51 super(propertyName, headerI18nKey, headerTipI18nKey, propertyType, decoratorName, mandatory);
52 }
53
54
55
56
57
58
59
60
61
62
63
64 public static <R extends AbstractDaliRowUIModel> DaliColumnIdentifier<R> newId(String propertyName, String headerI18nKey, String headerTipI18nKey, Class propertyType) {
65 return new DaliColumnIdentifier<>(propertyName, headerI18nKey, headerTipI18nKey, propertyType, null, false);
66 }
67
68
69
70
71
72
73
74
75
76
77
78
79 public static <R extends AbstractDaliRowUIModel> DaliColumnIdentifier<R> newId(String propertyName, String headerI18nKey, String headerTipI18nKey, Class propertyType,
80 String decoratorName) {
81 return new DaliColumnIdentifier<>(propertyName, headerI18nKey, headerTipI18nKey, propertyType, decoratorName, false);
82 }
83
84
85
86
87
88
89
90
91
92
93
94
95 public static <R extends AbstractDaliRowUIModel> DaliColumnIdentifier<R> newId(String propertyName, String headerI18nKey, String headerTipI18nKey, Class propertyType,
96 boolean mandatory) {
97 return new DaliColumnIdentifier<>(propertyName, headerI18nKey, headerTipI18nKey, propertyType, null, mandatory);
98 }
99
100
101
102
103
104
105
106
107
108
109
110
111
112 public static <R extends AbstractDaliRowUIModel> DaliColumnIdentifier<R> newId(String propertyName, String headerI18nKey, String headerTipI18nKey, Class propertyType,
113 String decoratorName, boolean mandatory) {
114 return new DaliColumnIdentifier<>(propertyName, headerI18nKey, headerTipI18nKey, propertyType, decoratorName, mandatory);
115 }
116
117
118
119
120
121
122
123
124
125
126
127 public static <R extends AbstractDaliRowUIModel> DaliColumnIdentifier<R> newReadOnlyId(String propertyName, String headerI18nKey, String headerTipI18nKey, Class propertyType) {
128
129 return newReadOnlyId(propertyName, headerI18nKey, headerTipI18nKey, propertyType, null);
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143 public static <R extends AbstractDaliRowUIModel> DaliColumnIdentifier<R> newReadOnlyId(String propertyName, String headerI18nKey, String headerTipI18nKey, Class propertyType,
144 String decoratorName) {
145 return new DaliColumnIdentifier<R>(propertyName, headerI18nKey, headerTipI18nKey, propertyType, decoratorName, false) {
146
147 private static final long serialVersionUID = 1L;
148
149 @Override
150 public void setValue(R entry, Object value) {
151
152 }
153 };
154 }
155
156
157
158
159
160
161
162
163
164 public static <R extends AbstractDaliRowUIModel> DaliColumnIdentifier<R> newPmfmNameId(String headerI18nKey, String headerTipI18nKey) {
165
166 return newPmfmNameId(null, headerI18nKey, headerTipI18nKey);
167 }
168
169
170
171
172
173
174
175
176
177
178 public static <R extends AbstractDaliRowUIModel> DaliColumnIdentifier<R> newPmfmNameId(final String parentPropertyName, String headerI18nKey, String headerTipI18nKey) {
179
180 final DecoratorService decoratorService = DaliServiceLocator.instance().getDecoratorService();
181
182 return new DaliColumnIdentifier<R>(PmfmDTO.PROPERTY_NAME, headerI18nKey, headerTipI18nKey, String.class, null, false) {
183
184 @Override
185 public Object getValue(R entry) {
186
187 PmfmDTO pmfm = null;
188 if (parentPropertyName != null) {
189 pmfm = DaliBeans.getProperty(entry, parentPropertyName);
190 } else if (entry instanceof PmfmDTO) {
191 pmfm = (PmfmDTO) entry;
192 }
193
194 if (pmfm != null) {
195
196 Decorator decorator = decoratorService.getDecoratorByType(PmfmDTO.class, DecoratorService.NAME);
197 if (decorator != null) {
198 return decorator.toString(pmfm);
199 }
200 }
201
202 return null;
203 }
204
205 @Override
206 public void setValue(R entry, Object value) {
207
208 }
209
210 };
211 }
212
213 }