Revision d13ec7ca
Added by Andreas Kohlbecker about 6 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditor.java | ||
---|---|---|
11 | 11 |
import java.util.Collection; |
12 | 12 |
import java.util.EnumSet; |
13 | 13 |
|
14 |
import org.apache.commons.lang3.BooleanUtils; |
|
14 | 15 |
import org.springframework.security.core.GrantedAuthority; |
15 | 16 |
|
16 | 17 |
import com.vaadin.shared.ui.label.ContentMode; |
... | ... | |
111 | 112 |
*/ |
112 | 113 |
@Override |
113 | 114 |
public int getWindowPixelWidth() { |
114 |
return 700;
|
|
115 |
return 800;
|
|
115 | 116 |
} |
116 | 117 |
|
117 | 118 |
/** |
... | ... | |
202 | 203 |
rankSelect.setNullSelectionAllowed(false); |
203 | 204 |
rankSelect.setRows(1); |
204 | 205 |
rankSelect.setWidth(100, Unit.PERCENTAGE); |
205 |
rankSelect.addValueChangeListener(e -> updateFieldVisibility((Rank)e.getProperty().getValue()));
|
|
206 |
rankSelect.addValueChangeListener(e -> updateFieldVisibility()); |
|
206 | 207 |
addField(rankSelect, "rank", 0, row, 1, row); |
207 | 208 |
grid.setComponentAlignment(rankSelect, Alignment.TOP_RIGHT); |
208 | 209 |
|
209 | 210 |
basionymToggle = new CheckBox("With basionym"); |
210 | 211 |
basionymToggle.setValue(HAS_BASIONYM_DEFAULT); |
211 | 212 |
basionymToggle.addValueChangeListener(e -> { |
212 |
boolean enable = e.getProperty().getValue() != null && (Boolean)e.getProperty().getValue(); |
|
213 |
enableBasionymFields(enable); |
|
213 |
updateFieldVisibility(); |
|
214 | 214 |
}); |
215 | 215 |
basionymToggle.setStyleName(getDefaultComponentStyles()); |
216 | 216 |
grid.addComponent(basionymToggle, 2, row, 3, row); |
... | ... | |
315 | 315 |
|
316 | 316 |
|
317 | 317 |
setAdvancedModeEnabled(true); |
318 |
enableBasionymFields(HAS_BASIONYM_DEFAULT); |
|
319 | 318 |
registerAdvancedModeComponents(fullTitleCacheFiled, protectedNameCacheField); |
320 | 319 |
registerAdvancedModeComponents(basionymAuthorshipField.getCachFields()); |
321 | 320 |
registerAdvancedModeComponents(exBasionymAuthorshipField.getCachFields()); |
... | ... | |
326 | 325 |
} |
327 | 326 |
|
328 | 327 |
/** |
329 |
* @param value
|
|
328 |
* @param rank
|
|
330 | 329 |
* @return |
331 | 330 |
*/ |
332 |
private void enableBasionymFields(boolean enable) {
|
|
331 |
private void updateFieldVisibility() {
|
|
333 | 332 |
|
333 |
// TODO use getField() instead and remove field references |
|
334 | 334 |
|
335 |
basionymAuthorshipField.setVisible(enable); |
|
336 |
exBasionymAuthorshipField.setVisible(enable); |
|
337 |
basionymsComboboxSelect.setVisible(enable); |
|
338 | 335 |
TaxonName taxonName = getBean(); |
336 |
Rank rank = taxonName.getRank(); |
|
337 |
|
|
338 |
boolean isSpeciesOrBelow = !rank.isHigher(Rank.SPECIES()); |
|
339 |
Boolean withBasionym = BooleanUtils.isTrue(basionymToggle.getValue()); |
|
340 |
Boolean withValidation = BooleanUtils.isTrue(validationToggle.getValue()); |
|
341 |
|
|
342 |
basionymAuthorshipField.setVisible(withBasionym != null && withBasionym); |
|
343 |
exBasionymAuthorshipField.setVisible(withBasionym); |
|
344 |
basionymsComboboxSelect.setVisible(withBasionym); |
|
339 | 345 |
|
340 | 346 |
if(taxonName != null){ |
341 | 347 |
if(modesActive.contains(TaxonNamePopupEditorMode.suppressReplacementAuthorshipData)){ |
342 | 348 |
basionymAuthorshipField.setVisible(taxonName.getBasionymAuthorship() != null); |
343 | 349 |
exBasionymAuthorshipField.setVisible(taxonName.getExBasionymAuthorship() != null); |
344 | 350 |
} |
345 |
updateFieldVisibility(taxonName.getRank()); |
|
346 | 351 |
} |
347 |
} |
|
348 | 352 |
|
349 |
/** |
|
350 |
* @param rank |
|
351 |
* @return |
|
352 |
*/ |
|
353 |
private void updateFieldVisibility(Rank rank) { |
|
354 |
boolean isSpeciesOrBelow = !rank.isHigher(Rank.SPECIES()); |
|
355 |
// TODO use getField() instead and remove field references |
|
356 | 353 |
infraSpecificEpithetField.setVisible(rank.isInfraSpecific()); |
357 | 354 |
specificEpithetField.setVisible(isSpeciesOrBelow); |
358 | 355 |
infraGenericEpithetField.setVisible(rank.isInfraGenericButNotSpeciesGroup()); |
359 | 356 |
genusOrUninomialField.setCaption(isSpeciesOrBelow ? "Genus" : "Uninomial"); |
360 |
exCombinationAuthorshipField.setVisible(isSpeciesOrBelow); |
|
357 |
exCombinationAuthorshipField.setVisible(isSpeciesOrBelow && withValidation);
|
|
361 | 358 |
} |
362 | 359 |
|
363 | 360 |
@Override |
... | ... | |
372 | 369 |
boolean showExAuthors = taxonName.getExCombinationAuthorship() != null; |
373 | 370 |
validationToggle.setValue(showExAuthors); |
374 | 371 |
validationToggle.setReadOnly(showExAuthors); |
372 |
exCombinationAuthorshipField.setVisible(showExAuthors); |
|
375 | 373 |
|
376 | 374 |
if(isModeEnabled(TaxonNamePopupEditorMode.suppressReplacementAuthorshipData)){ |
377 | 375 |
combinationAuthorshipField.setVisible(taxonName.getCombinationAuthorship() != null); |
Also available in: Unified diff
TaxonNameEditor fixing field visibility issues