Revision 4e19a89d
Added by Andreas Kohlbecker over 5 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/event/AbstractEditorAction.java | ||
---|---|---|
21 | 21 |
* Base implementation for an event which represents the request to start |
22 | 22 |
* an editor to enable the user to perform the <code>action</code> transported |
23 | 23 |
* with this event. |
24 |
* <p> |
|
25 |
* Which the {@link #context) stack the action can keep track of the chain of editors which where opened before and which lead |
|
26 |
* to this action. This is important information when working with popup editors for which EntitySave events etc |
|
27 |
* need to be also handled by the base view (e.g. see {@link eu.etaxonomy.cdm.vaadin.view.registration.RegistrationWorkingsetPresenter} |
|
28 |
* from which the the first popup editor of the chain has been opened. So the {@link #context) stack is just like a breadcrumbs information. |
|
24 | 29 |
* |
25 | 30 |
* @author a.kohlbecker |
26 | 31 |
* @since Mar 22, 2017 |
... | ... | |
42 | 47 |
this(action, null, source, target, sourceView); |
43 | 48 |
} |
44 | 49 |
|
50 |
/** |
|
51 |
* |
|
52 |
* @deprecated Consider using the constructor with Stack<EditorActionContext> context, so that the context is set for all popupeditors!!! |
|
53 |
*/ |
|
54 |
@Deprecated |
|
45 | 55 |
public AbstractEditorAction(EditorActionType action, UUID entityUuid, Button source, Field<V> target, AbstractView sourceView) { |
46 | 56 |
this(action, entityUuid, source, target, sourceView, null); |
47 | 57 |
} |
... | ... | |
97 | 107 |
} |
98 | 108 |
|
99 | 109 |
/** |
110 |
* Which the {@link #context) stack the action can keep track of the chain of editors |
|
111 |
* which where opened before and which lead |
|
112 |
* to this action. |
|
113 |
* |
|
100 | 114 |
* @return the context |
101 | 115 |
*/ |
102 | 116 |
public Stack<EditorActionContext> getContext() { |
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNameEditorPresenter.java | ||
---|---|---|
225 | 225 |
} |
226 | 226 |
|
227 | 227 |
if(getView().isModeEnabled(TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY)){ |
228 |
if(taxonName.getNomenclaturalReference() != null){ |
|
229 |
Reference nomRef = taxonName.getNomenclaturalReference(); |
|
230 |
//getView().getNomReferenceCombobox().setEnabled(nomRef.isOfType(ReferenceType.Section)); |
|
231 |
publishedUnit = nomRef; |
|
232 |
while(publishedUnit.isOfType(ReferenceType.Section) && publishedUnit.getInReference() != null){ |
|
233 |
publishedUnit = nomRef.getInReference(); |
|
234 |
} |
|
235 |
// reduce available references to those which are sections of the publishedUnit and the publishedUnit itself |
|
236 |
// nomReferencePagingProvider |
|
237 |
nomReferencePagingProvider.getCriteria().add(Restrictions.or( |
|
238 |
Restrictions.and(Restrictions.eq("inReference", publishedUnit), Restrictions.eq("type", ReferenceType.Section)), |
|
239 |
Restrictions.idEq(publishedUnit.getId()) |
|
240 |
) |
|
241 |
); |
|
242 |
// and remove the empty option |
|
243 |
getView().getNomReferenceCombobox().getSelect().setNullSelectionAllowed(false); |
|
244 |
|
|
245 |
// new Reference only a sub sections of the publishedUnit |
|
246 |
newReferenceInstantiator = new BeanInstantiator<Reference>() { |
|
247 |
@Override |
|
248 |
public Reference createNewBean() { |
|
249 |
Reference newRef = ReferenceFactory.newSection(); |
|
250 |
newRef.setInReference(publishedUnit); |
|
251 |
return newRef; |
|
252 |
} |
|
253 |
}; |
|
228 |
Reference nomRef = taxonName.getNomenclaturalReference(); |
|
254 | 229 |
|
230 |
//getView().getNomReferenceCombobox().setEnabled(nomRef.isOfType(ReferenceType.Section)); |
|
231 |
publishedUnit = nomRef; |
|
232 |
while(publishedUnit.isOfType(ReferenceType.Section) && publishedUnit.getInReference() != null){ |
|
233 |
publishedUnit = nomRef.getInReference(); |
|
255 | 234 |
} |
235 |
// reduce available references to those which are sections of the publishedUnit and the publishedUnit itself |
|
236 |
// nomReferencePagingProvider |
|
237 |
nomReferencePagingProvider.getCriteria().add(Restrictions.or( |
|
238 |
Restrictions.and(Restrictions.eq("inReference", publishedUnit), Restrictions.eq("type", ReferenceType.Section)), |
|
239 |
Restrictions.idEq(publishedUnit.getId()) |
|
240 |
) |
|
241 |
); |
|
242 |
// and remove the empty option |
|
243 |
getView().getNomReferenceCombobox().getSelect().setNullSelectionAllowed(false); |
|
244 |
|
|
245 |
// new Reference only a sub sections of the publishedUnit |
|
246 |
newReferenceInstantiator = new BeanInstantiator<Reference>() { |
|
247 |
@Override |
|
248 |
public Reference createNewBean() { |
|
249 |
Reference newRef = ReferenceFactory.newSection(); |
|
250 |
newRef.setInReference(publishedUnit); |
|
251 |
return newRef; |
|
252 |
} |
|
253 |
}; |
|
254 |
|
|
256 | 255 |
} |
257 | 256 |
return taxonName; |
258 | 257 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java | ||
---|---|---|
134 | 134 |
|
135 | 135 |
private RegistrationWorkingSet workingset; |
136 | 136 |
|
137 |
private TaxonName newTaxonNameForRegistration = null; |
|
138 |
|
|
137 |
private TaxonNamePopupEditor newNameForRegistrationPopupEditor = null; |
|
139 | 138 |
|
140 | 139 |
private Map<NameTypeDesignationPopupEditor, UUID> nameTypeDesignationPopupEditorRegistrationUUIDMap = new HashMap<>(); |
141 | 140 |
|
... | ... | |
436 | 435 |
} |
437 | 436 |
|
438 | 437 |
getView().getAddNewNameRegistrationButton().setEnabled(false); |
439 |
newTaxonNameForRegistration = TaxonNameFactory.NewNameInstance(RegistrationUIDefaults.NOMENCLATURAL_CODE, Rank.SPECIES()); |
|
440 |
newTaxonNameForRegistration.setNomenclaturalReference(getRepo().getReferenceService().find(workingset.getCitationUuid())); |
|
441 |
EntityChangeEvent nameSaveEvent = getTaxonNameStore().saveBean(newTaxonNameForRegistration, (AbstractView) getView()); |
|
442 |
newTaxonNameForRegistration = getRepo().getNameService().find(nameSaveEvent.getEntityUuid()); |
|
443 |
TaxonNamePopupEditor popup = openPopupEditor(TaxonNamePopupEditor.class, event); |
|
444 |
popup.setParentEditorActionContext(event.getContext()); |
|
445 |
popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE,CRUD.DELETE)); |
|
446 |
popup.withDeleteButton(true); |
|
447 |
TaxonNamePopupEditorConfig.configureForNomenclaturalAct(popup); |
|
448 |
popup.loadInEditor(newTaxonNameForRegistration.getUuid()); |
|
438 |
if(newNameForRegistrationPopupEditor == null){ |
|
439 |
TaxonNamePopupEditor popup = openPopupEditor(TaxonNamePopupEditor.class, event); |
|
440 |
popup.setParentEditorActionContext(event.getContext()); |
|
441 |
popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE,CRUD.DELETE)); |
|
442 |
popup.withDeleteButton(true); |
|
443 |
popup.setCdmEntityInstantiator(new BeanInstantiator<TaxonName>() { |
|
444 |
|
|
445 |
@Override |
|
446 |
public TaxonName createNewBean() { |
|
447 |
TaxonName newTaxonName = TaxonNameFactory.NewNameInstance(RegistrationUIDefaults.NOMENCLATURAL_CODE, Rank.SPECIES()); |
|
448 |
newTaxonName.setNomenclaturalReference(getRepo().getReferenceService().load(workingset.getCitationUuid())); |
|
449 |
return newTaxonName; |
|
450 |
} |
|
451 |
}); |
|
452 |
TaxonNamePopupEditorConfig.configureForNomenclaturalAct(popup); |
|
453 |
popup.loadInEditor(null); |
|
454 |
} |
|
449 | 455 |
} |
450 | 456 |
|
451 | 457 |
/** |
... | ... | |
463 | 469 |
public void onDoneWithTaxonnameEditor(DoneWithPopupEvent event) throws RegistrationValidationException{ |
464 | 470 |
if(event.getPopup() instanceof TaxonNamePopupEditor){ |
465 | 471 |
try { |
466 |
TransactionStatus txStatus = getRepo().startTransaction(); |
|
467 | 472 |
if(event.getReason().equals(Reason.SAVE)){ |
468 |
if(newTaxonNameForRegistration != null){ |
|
469 |
UUID taxonNameUuid = newTaxonNameForRegistration.getUuid(); |
|
470 |
getRepo().getSession().refresh(newTaxonNameForRegistration); |
|
473 |
TransactionStatus txStatus = getRepo().startTransaction(); |
|
474 |
if(newNameForRegistrationPopupEditor != null){ |
|
475 |
UUID taxonNameUuid = newNameForRegistrationPopupEditor.getBean().getUuid(); |
|
476 |
getRepo().getSession().refresh(newNameForRegistrationPopupEditor.getBean().cdmEntity()); |
|
471 | 477 |
Registration reg = getRepo().getRegistrationService().createRegistrationForName(taxonNameUuid); |
472 | 478 |
// reload workingset into current session |
473 | 479 |
loadWorkingSet(workingset.getCitationUuid()); |
474 | 480 |
workingset.add(reg); |
475 | 481 |
} |
476 | 482 |
refreshView(true); |
477 |
} else if(event.getReason().equals(Reason.CANCEL)){ |
|
478 |
if(newTaxonNameForRegistration != null){ |
|
479 |
// clean up |
|
480 |
getTaxonNameStore().deleteBean(newTaxonNameForRegistration, (AbstractView) getView()); |
|
481 |
} |
|
483 |
getRepo().commitTransaction(txStatus); |
|
482 | 484 |
} |
483 |
getRepo().commitTransaction(txStatus); |
|
484 | 485 |
} finally { |
485 | 486 |
getRepo().getSession().clear(); // #7702 |
486 | 487 |
} |
487 |
newTaxonNameForRegistration = null;
|
|
488 |
newNameForRegistrationPopupEditor = null;
|
|
488 | 489 |
getView().getAddNewNameRegistrationButton().setEnabled(true); |
489 | 490 |
} |
490 | 491 |
} |
... | ... | |
716 | 717 |
} else |
717 | 718 |
if(TaxonName.class.isAssignableFrom(event.getEntityType())){ |
718 | 719 |
if(event.getType().equals(EntityChangeEvent.Type.CREATED)){ |
719 |
// new name! create a blocking registration |
|
720 | 720 |
Stack<EditorActionContext>context = ((AbstractPopupEditor)event.getSourceView()).getEditorActionContext(); |
721 | 721 |
EditorActionContext rootContext = context.get(0); |
722 | 722 |
if(rootContext.getParentView().equals(getView())){ |
723 |
Registration blockingRegistration = getRepo().getRegistrationService().createRegistrationForName(event.getEntityUuid()); |
|
723 |
// new name! create a blocking registration |
|
724 |
UUID taxonNameUUID = event.getEntityUuid(); |
|
725 |
Registration blockingRegistration = getRepo().getRegistrationService().createRegistrationForName(taxonNameUUID); |
|
724 | 726 |
TypedEntityReference<Registration> regReference = (TypedEntityReference<Registration>)rootContext.getParentEntity(); |
725 | 727 |
Registration registration = null; |
726 | 728 |
for(int i = context.size()-1; i>0; i--){ |
... | ... | |
737 | 739 |
getRepo().getRegistrationService().saveOrUpdate(registration); |
738 | 740 |
logger.debug("Blocking registration created"); |
739 | 741 |
} else { |
742 |
// in case of creating a new name for a registration the parent view is the TaxonNamePopupEditor |
|
743 |
// this is set |
|
740 | 744 |
logger.debug("Non blocking registration, since a new name for a new registration has been created"); |
741 | 745 |
} |
742 | 746 |
} |
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractCdmDTOPopupEditor.java | ||
---|---|---|
40 | 40 |
getPresenter().setGrantsForCurrentUser(crud); |
41 | 41 |
} |
42 | 42 |
|
43 |
public void setCdmEntityInstantiator(BeanInstantiator<CDM> cdmEntityInstantiator) { |
|
44 |
((AbstractCdmDTOEditorPresenter)getPresenter()).setCdmEntityInstantiator(cdmEntityInstantiator); |
|
45 |
} |
|
46 |
|
|
43 | 47 |
|
44 | 48 |
|
45 | 49 |
} |
Also available in: Unified diff
ref #7648 using CdmEntityInstantiator to disentangle the handling the creation of new taxon names for registrations