Revision e2da4a33
Added by Andreas Kohlbecker almost 6 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/view/reference/ReferencePopupEditor.java | ||
---|---|---|
11 | 11 |
import java.util.Collection; |
12 | 12 |
import java.util.EnumSet; |
13 | 13 |
import java.util.HashMap; |
14 |
import java.util.LinkedHashMap; |
|
14 | 15 |
import java.util.Map; |
16 |
import java.util.Set; |
|
15 | 17 |
|
16 | 18 |
import org.springframework.context.annotation.Scope; |
17 | 19 |
import org.springframework.security.core.GrantedAuthority; |
... | ... | |
41 | 43 |
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox; |
42 | 44 |
import eu.etaxonomy.vaadin.event.EditorActionType; |
43 | 45 |
import eu.etaxonomy.vaadin.mvp.AbstractCdmPopupEditor; |
46 |
import eu.etaxonomy.vaadin.util.PropertyIdPath; |
|
44 | 47 |
|
45 | 48 |
/** |
46 | 49 |
* @author a.kohlbecker |
... | ... | |
69 | 72 |
|
70 | 73 |
private static Map<String,String> propertyNameLabelMap = new HashMap<>(); |
71 | 74 |
|
75 |
private int variableGridStartRow; |
|
76 |
|
|
77 |
private int variableGridLastRow; |
|
78 |
|
|
79 |
/** |
|
80 |
* Used to record the fields from the variable grid part in their original order. |
|
81 |
*/ |
|
82 |
private LinkedHashMap<String, Field<?>> adaptiveFields = new LinkedHashMap<>(); |
|
83 |
|
|
72 | 84 |
static { |
73 | 85 |
propertyNameLabelMap.put("inReference", "In reference"); |
74 | 86 |
propertyNameLabelMap.put("inJournal", "In journal"); |
... | ... | |
167 | 179 |
addField(inReferenceCombobox, "inReference", 0, row, GRID_COLS -1, row); |
168 | 180 |
row++; |
169 | 181 |
|
182 |
variableGridStartRow = row; |
|
170 | 183 |
addTextField("Series", "seriesPart", 0, row).setWidth(100, Unit.PERCENTAGE); |
171 | 184 |
addTextField("Volume", "volume", 1, row).setWidth(100, Unit.PERCENTAGE); |
172 | 185 |
addTextField("Pages", "pages", 2, row).setWidth(100, Unit.PERCENTAGE); |
... | ... | |
190 | 203 |
uriField.setWidth(100, Unit.PERCENTAGE); |
191 | 204 |
addField(uriField, "uri", 3, row); |
192 | 205 |
|
206 |
|
|
207 |
variableGridLastRow = row; |
|
208 |
|
|
193 | 209 |
// titleField.setRequired(true); |
194 | 210 |
// publisherField.setRequired(true); |
195 | 211 |
|
... | ... | |
204 | 220 |
* @param value |
205 | 221 |
* @return |
206 | 222 |
*/ |
207 |
private Object updateFieldVisibility(ReferenceType value) {
|
|
223 |
private Object updateFieldVisibility(ReferenceType referenceType) {
|
|
208 | 224 |
|
209 |
try { |
|
210 |
Map<String, String> fieldPropertyDefinition = ReferencePropertyDefinitions.fieldPropertyDefinition(value); |
|
211 |
setAllFieldsVisible(false); |
|
212 |
for(String fieldName : fieldPropertyDefinition.keySet()){ |
|
213 |
Field<?> field = getField(fieldName); |
|
214 |
if(field == null){ |
|
215 |
continue; |
|
225 |
GridLayout grid = (GridLayout)getFieldLayout(); |
|
226 |
|
|
227 |
// initialize the map of adaptive fields |
|
228 |
if(adaptiveFields.isEmpty()){ |
|
229 |
try{ |
|
230 |
Map<String, String> fieldPropertyDefinition = ReferencePropertyDefinitions.fieldPropertyDefinition(null); |
|
231 |
Set<String> fieldNames = fieldPropertyDefinition.keySet(); |
|
232 |
for(int row = variableGridStartRow; row <= variableGridLastRow; row++){ |
|
233 |
for(int x=0; x < grid.getColumns(); x++){ |
|
234 |
Component c = grid.getComponent(x, row); |
|
235 |
if(c != null && c instanceof Field){ |
|
236 |
Field<?> field = (Field<?>)c; |
|
237 |
PropertyIdPath propertyIdPath = boundPropertyIdPath(field); |
|
238 |
if(propertyIdPath != null && fieldNames.contains(propertyIdPath.toString())){ |
|
239 |
adaptiveFields.put(propertyIdPath.toString(), field); |
|
240 |
} |
|
241 |
} |
|
242 |
} |
|
216 | 243 |
} |
217 |
field.setVisible(true); |
|
218 |
String propertyName = fieldPropertyDefinition.get(fieldName); |
|
219 |
if(propertyName != fieldName){ |
|
244 |
} catch (UnimplemetedCaseException e) { |
|
245 |
throw new RuntimeException(e); |
|
246 |
} |
|
247 |
} |
|
248 |
|
|
249 |
// clear the variable grid part |
|
250 |
for(int row = variableGridStartRow; row <= variableGridLastRow; row++){ |
|
251 |
for(int x=0; x < grid.getColumns(); x++){ |
|
252 |
grid.removeComponent(x, row); |
|
253 |
} |
|
254 |
} |
|
255 |
|
|
256 |
// set cursor at the beginning of the variable grid part |
|
257 |
grid.setCursorY(variableGridStartRow); |
|
258 |
grid.setCursorX(0); |
|
259 |
|
|
260 |
// place the fields which are required for the given referenceType in the variable grid part while |
|
261 |
// and retain the original order which is recorded in the adaptiveFields |
|
262 |
try { |
|
263 |
Map<String, String> fieldPropertyDefinition = ReferencePropertyDefinitions.fieldPropertyDefinition(referenceType); |
|
264 |
|
|
265 |
for(String fieldName : adaptiveFields.keySet()){ // iterate over the LinkedHashMap to retain the original order of the fields |
|
266 |
if(fieldPropertyDefinition.containsKey(fieldName)){ |
|
267 |
Field<?> field = adaptiveFields.get(fieldName); |
|
268 |
grid.addComponent(field); |
|
269 |
String propertyName = fieldPropertyDefinition.get(fieldName); |
|
270 |
if(propertyName != fieldName){ |
|
220 | 271 |
field.setCaption(propertyNameLabelMap.get(propertyName)); |
272 |
} |
|
221 | 273 |
} |
222 | 274 |
} |
223 | 275 |
} catch (UnimplemetedCaseException e) { |
... | ... | |
228 | 280 |
getField("inReference").setCaption(propertyNameLabelMap.get("inReference")); |
229 | 281 |
} |
230 | 282 |
|
231 |
|
|
232 |
|
|
233 | 283 |
EnumSet<ReferenceType> hideNomTitle = EnumSet.of(ReferenceType.Article, ReferenceType.Section, ReferenceType.BookSection, ReferenceType.InProceedings, ReferenceType.PrintSeries); |
234 | 284 |
EnumSet<ReferenceType> hideTitle = EnumSet.of(ReferenceType.Section, ReferenceType.BookSection); |
235 |
getField("abbrevTitle").setVisible(!hideNomTitle.contains(value));
|
|
236 |
getField("title").setVisible(!hideTitle.contains(value));
|
|
285 |
getField("abbrevTitle").setVisible(!hideNomTitle.contains(referenceType));
|
|
286 |
getField("title").setVisible(!hideTitle.contains(referenceType));
|
|
237 | 287 |
|
238 | 288 |
return null; |
239 | 289 |
} |
Also available in: Unified diff
ref #7223 improving the layout for all reference types by implemetning a real adaptive layout