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