Revision 98c2f401
Added by Andreas Kohlbecker over 5 years ago
src/main/java/eu/etaxonomy/cdm/service/FilterableStringRepresentationPagingProvider.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
public IDTYPE idFor(String stringRepresentation); |
21 | 21 |
|
22 |
/** |
|
23 |
* |
|
24 |
*/ |
|
25 |
public void clearIdCache(); |
|
26 |
|
|
22 | 27 |
|
23 | 28 |
} |
src/main/java/eu/etaxonomy/cdm/service/TaxonNameStringFilterablePagingProvider.java | ||
---|---|---|
254 | 254 |
} |
255 | 255 |
return lastPagedEntityUUIDs.get(stringRepresentation); |
256 | 256 |
} |
257 |
|
|
258 |
/** |
|
259 |
* {@inheritDoc} |
|
260 |
*/ |
|
261 |
@Override |
|
262 |
public void clearIdCache() { |
|
263 |
lastPagedEntityUUIDs = null; |
|
264 |
} |
|
257 | 265 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/event/TaxonNameEditorActionStrRep.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2017 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.cdm.vaadin.event; |
|
10 |
|
|
11 |
import java.util.Stack; |
|
12 |
import java.util.UUID; |
|
13 |
|
|
14 |
import com.vaadin.ui.Button; |
|
15 |
import com.vaadin.ui.Field; |
|
16 |
|
|
17 |
import eu.etaxonomy.vaadin.event.EditorActionType; |
|
18 |
import eu.etaxonomy.vaadin.mvp.AbstractView; |
|
19 |
|
|
20 |
/** |
|
21 |
* Variant of the TaxonNameEditorAction with to be published from fields like the {@link eu.etaxonomy.vaadin.component.WeaklyRelatedEntityCombobox} which |
|
22 |
* contain string representations of an entity instead of the whole entit.y |
|
23 |
* |
|
24 |
* @author a.kohlbecker |
|
25 |
* @since Mar 22, 2017 |
|
26 |
* |
|
27 |
*/ |
|
28 |
public class TaxonNameEditorActionStrRep extends AbstractEditorAction<String> { |
|
29 |
|
|
30 |
|
|
31 |
public TaxonNameEditorActionStrRep(EditorActionType eventType) { |
|
32 |
super(eventType); |
|
33 |
} |
|
34 |
|
|
35 |
/** |
|
36 |
* @param action |
|
37 |
* @param source |
|
38 |
*/ |
|
39 |
public TaxonNameEditorActionStrRep(EditorActionType action, Button source, Field<String> target, AbstractView sourceView) { |
|
40 |
super(action, source, target, sourceView); |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* @param action |
|
45 |
* @param entityId |
|
46 |
* @param source |
|
47 |
* @param sourceView |
|
48 |
*/ |
|
49 |
public TaxonNameEditorActionStrRep(EditorActionType action, UUID entityUuid, Button source, Field<String> target, AbstractView sourceView) { |
|
50 |
super(action, entityUuid, source, target, sourceView); |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* @param action |
|
55 |
* @param entityId |
|
56 |
* @param source |
|
57 |
* @param sourceView |
|
58 |
* @param context |
|
59 |
*/ |
|
60 |
public TaxonNameEditorActionStrRep(EditorActionType action, UUID entityUuid, Button source, Field<String> target, AbstractView sourceView, |
|
61 |
Stack<EditorActionContext> context) { |
|
62 |
super(action, entityUuid, source, target, sourceView, context); |
|
63 |
} |
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNameEditorPresenter.java | ||
---|---|---|
13 | 13 |
import java.util.List; |
14 | 14 |
import java.util.UUID; |
15 | 15 |
|
16 |
import org.apache.commons.lang.StringUtils; |
|
16 | 17 |
import org.apache.log4j.Logger; |
17 | 18 |
import org.hibernate.criterion.Restrictions; |
18 | 19 |
import org.springframework.context.annotation.Scope; |
... | ... | |
46 | 47 |
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent; |
47 | 48 |
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction; |
48 | 49 |
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction; |
50 |
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorActionStrRep; |
|
49 | 51 |
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityButtonUpdater; |
50 | 52 |
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader; |
51 | 53 |
import eu.etaxonomy.cdm.vaadin.model.name.TaxonNameDTO; |
... | ... | |
362 | 364 |
getView().getInfraSpecificEpithetField() |
363 | 365 |
); |
364 | 366 |
WeaklyRelatedEntityCombobox<TaxonName> genusOrUninomialField = (WeaklyRelatedEntityCombobox<TaxonName>)event.getNewField(); |
365 |
// FIXME genusOrUninomialField.setNestedButtonStateUpdater(new ToOneRelatedEntityButtonUpdater<TaxonName>(genusOrUninomialField)); |
|
366 | 367 |
genusOrUninomialField.loadFrom(genusOrUninomialPartPagingProvider, genusOrUninomialPartPagingProvider, genusOrUninomialPartPagingProvider.getPageSize()); |
367 | 368 |
genusOrUninomialField.setValue(event.getOldField().getValue()); |
368 | 369 |
}else { |
... | ... | |
384 | 385 |
BoundField boundTargetField = boundTargetField((PopupView) event.getSourceView()); |
385 | 386 |
|
386 | 387 |
if(boundTargetField != null){ |
387 |
if(boundTargetField.matchesPropertyIdPath("nomenclaturalReference")){ |
|
388 |
if(boundTargetField.matchesPropertyIdPath("genusOrUninomial")){ |
|
389 |
if(event.isCreateOrModifiedType()){ |
|
390 |
getCache().load(event.getEntity()); |
|
391 |
if(getView().getGenusOrUninomialField() instanceof WeaklyRelatedEntityCombobox){ |
|
392 |
WeaklyRelatedEntityCombobox<TaxonName> weaklyRelatedEntityCombobox = (WeaklyRelatedEntityCombobox<TaxonName>)getView().getGenusOrUninomialField(); |
|
393 |
if(event.isCreatedType()){ |
|
394 |
weaklyRelatedEntityCombobox.setValue(((TaxonName)event.getEntity()).getGenusOrUninomial()); |
|
395 |
weaklyRelatedEntityCombobox.reload(); |
|
396 |
} else { |
|
397 |
weaklyRelatedEntityCombobox.reload(); |
|
398 |
} |
|
399 |
// NOTE: in constrast to the ToOneRelatedEntityCombobox the .discard() does not |
|
400 |
// work here since no datasource is bound to the field, see weaklyRelatedEntityCombobox.reload() |
|
401 |
weaklyRelatedEntityCombobox.updateButtons(); |
|
402 |
} |
|
403 |
} |
|
404 |
} else |
|
405 |
if(boundTargetField.matchesPropertyIdPath("specificEpithet")){ |
|
388 | 406 |
if(event.isCreateOrModifiedType()){ |
407 |
getCache().load(event.getEntity()); |
|
389 | 408 |
|
409 |
if(getView().getSpecificEpithetField() instanceof WeaklyRelatedEntityCombobox){ |
|
410 |
WeaklyRelatedEntityCombobox weaklyRelatedEntityCombobox = (WeaklyRelatedEntityCombobox)getView().getSpecificEpithetField(); |
|
411 |
if(event.isCreatedType()){ |
|
412 |
getView().getSpecificEpithetField().setValue(((TaxonName)event.getEntity()).getSpecificEpithet()); |
|
413 |
weaklyRelatedEntityCombobox.reload(); |
|
414 |
} else { |
|
415 |
weaklyRelatedEntityCombobox.reload(); |
|
416 |
} |
|
417 |
// NOTE: in constrast to the ToOneRelatedEntityCombobox the .discard() does not |
|
418 |
// work here since no datasource is bound to the field, see weaklyRelatedEntityCombobox.reload() |
|
419 |
weaklyRelatedEntityCombobox.updateButtons(); |
|
420 |
} |
|
421 |
} |
|
422 |
} else |
|
423 |
if(boundTargetField.matchesPropertyIdPath("nomenclaturalReference")){ |
|
424 |
if(event.isCreateOrModifiedType()){ |
|
390 | 425 |
getCache().load(event.getEntity()); |
391 | 426 |
if(event.isCreatedType()){ |
392 | 427 |
getView().getNomReferenceCombobox().setValue((Reference) event.getEntity()); |
... | ... | |
396 | 431 |
getView().getCombinationAuthorshipField().discard(); //refresh from the datasource |
397 | 432 |
getView().updateAuthorshipFields(); |
398 | 433 |
} |
399 |
} |
|
434 |
} else
|
|
400 | 435 |
if(boundTargetField.matchesPropertyIdPath("validationFor.otherName")){ |
401 | 436 |
ReloadableLazyComboBox<TaxonName> otherNameField = asReloadableLazyComboBox(boundTargetField.getField(TaxonName.class)); |
402 | 437 |
if(event.isCreateOrModifiedType()){ |
... | ... | |
472 | 507 |
|
473 | 508 |
if(boundPropertyId != null){ |
474 | 509 |
if(boundPropertyId.matches("validationFor.otherName") || boundPropertyId.matches("basionyms") || boundPropertyId.matches("replacedSynonyms")){ |
475 |
TaxonNamePopupEditor validatedNamePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
|
|
476 |
validatedNamePopup.withDeleteButton(true);
|
|
510 |
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
|
|
511 |
namePopup.withDeleteButton(true);
|
|
477 | 512 |
getView().getModesActive().stream() |
478 | 513 |
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m)) |
479 |
.forEach(m -> validatedNamePopup.enableMode(m));
|
|
480 |
validatedNamePopup.loadInEditor(event.getEntityUuid());
|
|
514 |
.forEach(m -> namePopup.enableMode(m));
|
|
515 |
namePopup.loadInEditor(event.getEntityUuid());
|
|
481 | 516 |
} |
482 | 517 |
} |
518 |
} |
|
519 |
|
|
520 |
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class) |
|
521 |
public void onTaxonNameEditorActionStrRepEdit(TaxonNameEditorActionStrRep event) { |
|
522 |
|
|
523 |
if(getView() == null || event.getSourceView() != getView() ){ |
|
524 |
return; |
|
525 |
} |
|
526 |
|
|
527 |
PropertyIdPath boundPropertyId = boundPropertyIdPath(event.getTarget()); |
|
483 | 528 |
|
529 |
if(boundPropertyId != null){ |
|
530 |
if(boundPropertyId.matches("genusOrUninomial") || boundPropertyId.matches("specificEpithet")){ |
|
531 |
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event); |
|
532 |
namePopup.withDeleteButton(true); |
|
533 |
getView().getModesActive().stream() |
|
534 |
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m)) |
|
535 |
.forEach(m -> namePopup.enableMode(m)); |
|
536 |
namePopup.loadInEditor(event.getEntityUuid()); |
|
537 |
} |
|
538 |
} |
|
484 | 539 |
} |
485 | 540 |
|
486 | 541 |
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class) |
... | ... | |
494 | 549 |
|
495 | 550 |
if(boundPropertyId != null){ |
496 | 551 |
if(boundPropertyId.matches("validationFor.otherName") || boundPropertyId.matches("basionyms") || boundPropertyId.matches("replacedSynonyms")){ |
497 |
TaxonNamePopupEditor validatedNamePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
|
|
498 |
validatedNamePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
|
499 |
validatedNamePopup.withDeleteButton(true);
|
|
552 |
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
|
|
553 |
namePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
|
554 |
namePopup.withDeleteButton(true);
|
|
500 | 555 |
getView().getModesActive().stream() |
501 | 556 |
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m)) |
502 |
.forEach(m -> validatedNamePopup.enableMode(m)); |
|
503 |
validatedNamePopup.loadInEditor(null); |
|
557 |
.forEach(m -> namePopup.enableMode(m)); |
|
558 |
namePopup.loadInEditor(null); |
|
559 |
} |
|
560 |
} |
|
561 |
} |
|
562 |
|
|
563 |
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class) |
|
564 |
public void onTaxonNameEditorActionStrRepAdd(TaxonNameEditorActionStrRep event) { |
|
565 |
|
|
566 |
if(getView() == null || event.getSourceView() != getView() ){ |
|
567 |
return; |
|
568 |
} |
|
569 |
|
|
570 |
PropertyIdPath boundPropertyId = boundPropertyIdPath(event.getTarget()); |
|
571 |
|
|
572 |
if(boundPropertyId != null){ |
|
573 |
if(boundPropertyId.matches("genusOrUninomial") || boundPropertyId.matches("specificEpithet")){ |
|
574 |
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event); |
|
575 |
namePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE)); |
|
576 |
namePopup.withDeleteButton(true); |
|
577 |
String nameString = event.getTarget().getValue(); |
|
578 |
getView().getModesActive().stream() |
|
579 |
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m)) |
|
580 |
.forEach(m -> namePopup.enableMode(m)); |
|
581 |
namePopup.loadInEditor(null); |
|
582 |
if(StringUtils.isNotEmpty(nameString)){ |
|
583 |
if(boundPropertyId.matches("genusOrUninomial")){ |
|
584 |
namePopup.getGenusOrUninomialField().setValue(nameString); |
|
585 |
namePopup.getRankSelect().setValue(Rank.GENUS()); |
|
586 |
} |
|
587 |
if(boundPropertyId.matches("specificEpithet")){ |
|
588 |
namePopup.getSpecificEpithetField().setValue(nameString); |
|
589 |
namePopup.getGenusOrUninomialField().setValue(getView().getGenusOrUninomialField().getValue()); |
|
590 |
namePopup.getRankSelect().setValue(Rank.SPECIES()); |
|
591 |
} |
|
592 |
} |
|
504 | 593 |
} |
505 | 594 |
} |
506 | 595 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditor.java | ||
---|---|---|
44 | 44 |
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField; |
45 | 45 |
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction; |
46 | 46 |
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction; |
47 |
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorActionStrRep; |
|
47 | 48 |
import eu.etaxonomy.cdm.vaadin.model.name.NameRelationshipDTO; |
48 | 49 |
import eu.etaxonomy.cdm.vaadin.model.name.TaxonNameDTO; |
49 | 50 |
import eu.etaxonomy.cdm.vaadin.permission.AccessRestrictedView; |
... | ... | |
705 | 706 |
if(isModeEnabled(TaxonNamePopupEditorMode.VALIDATE_AGAINST_HIGHER_NAME_PART)){ |
706 | 707 |
if(isSpeciesOrBelow) { |
707 | 708 |
if(TextField.class.isAssignableFrom(genusOrUninomialField.getClass())){ |
708 |
WeaklyRelatedEntityCombobox<TaxonName> combobox = new WeaklyRelatedEntityCombobox<TaxonName>("-> this caption will be relpaced <-", TaxonName.class); |
|
709 |
WeaklyRelatedEntityCombobox<TaxonName> combobox = new WeaklyRelatedEntityCombobox<TaxonName>("-> this caption will be replaced <-", TaxonName.class); |
|
710 |
combobox.addClickListenerAddEntity(e -> getViewEventBus().publish( |
|
711 |
this, |
|
712 |
new TaxonNameEditorActionStrRep(EditorActionType.ADD, e.getButton(), combobox, this) |
|
713 |
)); |
|
714 |
combobox.addClickListenerEditEntity(e -> { |
|
715 |
if(combobox.getValue() != null){ |
|
716 |
getViewEventBus().publish(this, |
|
717 |
new TaxonNameEditorActionStrRep( |
|
718 |
EditorActionType.EDIT, |
|
719 |
combobox.getIdForValue(), |
|
720 |
e.getButton(), |
|
721 |
combobox, |
|
722 |
this) |
|
723 |
); |
|
724 |
} |
|
725 |
}); |
|
709 | 726 |
genusOrUninomialField = replaceComponent("genusOrUninomial", genusOrUninomialField, combobox, 0, genusOrUninomialRow, 1, genusOrUninomialRow); |
710 | 727 |
} |
711 | 728 |
} else { |
... | ... | |
718 | 735 |
if(isModeEnabled(TaxonNamePopupEditorMode.VALIDATE_AGAINST_HIGHER_NAME_PART)){ |
719 | 736 |
if(rank.isInfraSpecific()) { |
720 | 737 |
if(TextField.class.isAssignableFrom(specificEpithetField.getClass())) { |
721 |
WeaklyRelatedEntityCombobox<TaxonName> combobox = new WeaklyRelatedEntityCombobox<TaxonName>("-> this caption will be relpaced <-", TaxonName.class);
|
|
738 |
WeaklyRelatedEntityCombobox<TaxonName> combobox = new WeaklyRelatedEntityCombobox<TaxonName>("-> this caption will be replaced <-", TaxonName.class);
|
|
722 | 739 |
specificEpithetField = replaceComponent("specificEpithet", specificEpithetField, combobox, 0, specificEpithetFieldRow, 1, specificEpithetFieldRow); |
740 |
combobox.addClickListenerAddEntity(e -> getViewEventBus().publish( |
|
741 |
this, |
|
742 |
new TaxonNameEditorActionStrRep(EditorActionType.ADD, e.getButton(), combobox, this) |
|
743 |
)); |
|
744 |
combobox.addClickListenerEditEntity(e -> { |
|
745 |
if(combobox.getValue() != null){ |
|
746 |
getViewEventBus().publish(this, |
|
747 |
new TaxonNameEditorActionStrRep( |
|
748 |
EditorActionType.EDIT, |
|
749 |
combobox.getIdForValue(), |
|
750 |
e.getButton(), |
|
751 |
combobox, |
|
752 |
this) |
|
753 |
); |
|
754 |
} |
|
755 |
}); |
|
723 | 756 |
} |
724 | 757 |
} else { |
725 | 758 |
if(ToOneRelatedEntityCombobox.class.isAssignableFrom(specificEpithetField.getClass())) { |
src/main/java/eu/etaxonomy/vaadin/component/WeaklyRelatedEntityCombobox.java | ||
---|---|---|
61 | 61 |
lazySelect = new ReloadableLazyComboBox<String>(String.class); |
62 | 62 |
addStyledComponents(lazySelect, addButton, editButton); |
63 | 63 |
addSizedComponents(lazySelect, container); |
64 |
buttonUpdater = new WeaklyRelatedEntityButtonUpdater(this, type);
|
|
64 |
buttonUpdater = new WeaklyRelatedEntityButtonUpdater(this); |
|
65 | 65 |
lazySelect.addValueChangeListener(buttonUpdater); |
66 | 66 |
lazySelect.addValueChangeListener(e -> { |
67 | 67 |
// update the itemContainer immediately so that the edit button acts on the chosen item |
... | ... | |
128 | 128 |
*/ |
129 | 129 |
@Override |
130 | 130 |
public void reload() { |
131 |
filterablePagingProvider.clearIdCache(); |
|
131 | 132 |
getSelect().reload(); |
132 | 133 |
} |
133 | 134 |
|
135 |
|
|
134 | 136 |
/** |
135 | 137 |
* {@inheritDoc} |
136 | 138 |
*/ |
... | ... | |
181 | 183 |
return lazySelect.getValue(); |
182 | 184 |
} |
183 | 185 |
|
186 |
public UUID getIdForValue(){ |
|
187 |
return filterablePagingProvider.idFor(getValue()); |
|
188 |
} |
|
189 |
|
|
184 | 190 |
|
185 | 191 |
/** |
186 | 192 |
* {@inheritDoc} |
... | ... | |
220 | 226 |
} |
221 | 227 |
} |
222 | 228 |
|
229 |
@Override |
|
230 |
public void updateButtons(){ |
|
231 |
buttonUpdater.updateButtons(getValue()); |
|
232 |
} |
|
233 |
|
|
223 | 234 |
/** |
224 | 235 |
* {@inheritDoc} |
225 | 236 |
* @deprecated NestedButtonStateUpdater should rather be instantiated in the RelatedEntityField instead of passing it as property |
... | ... | |
236 | 247 |
|
237 | 248 |
WeaklyRelatedEntityCombobox<V> toOneRelatedEntityField; |
238 | 249 |
|
239 |
private Class<V> type; |
|
240 |
|
|
241 |
|
|
242 |
public WeaklyRelatedEntityButtonUpdater(WeaklyRelatedEntityCombobox<V> toOneRelatedEntityField, Class<V> type){ |
|
250 |
public WeaklyRelatedEntityButtonUpdater(WeaklyRelatedEntityCombobox<V> toOneRelatedEntityField){ |
|
243 | 251 |
this.toOneRelatedEntityField = toOneRelatedEntityField; |
244 |
this.type = type; |
|
245 | 252 |
String stringValue = toOneRelatedEntityField.getValue(); |
246 | 253 |
updateButtons(toOneRelatedEntityField.getValue()); |
247 | 254 |
toOneRelatedEntityField.setEditButtonEnabled(false); |
src/main/java/eu/etaxonomy/vaadin/component/WeaklyRelatedEntityField.java | ||
---|---|---|
56 | 56 |
|
57 | 57 |
public Class<String> getType(); |
58 | 58 |
|
59 |
/** |
|
60 |
* Update the enabled state of the add and edit buttons |
|
61 |
*/ |
|
62 |
public void updateButtons(); |
|
63 |
|
|
59 | 64 |
} |
Also available in: Unified diff
ref #7783 using WeaklyRelatedEntityCombobox in TaxonNameEditor: add, edit buttons working and enabled state updating ok