Revision e8674a36
Added by Andreas Kohlbecker about 6 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java | ||
---|---|---|
12 | 12 |
import java.util.Arrays; |
13 | 13 |
import java.util.EnumSet; |
14 | 14 |
import java.util.List; |
15 |
import java.util.Stack; |
|
15 | 16 |
import java.util.UUID; |
16 | 17 |
|
17 | 18 |
import org.hibernate.Session; |
... | ... | |
46 | 47 |
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider; |
47 | 48 |
import eu.etaxonomy.cdm.service.CdmStore; |
48 | 49 |
import eu.etaxonomy.cdm.service.IRegistrationWorkingSetService; |
50 |
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.EditorActionContext; |
|
49 | 51 |
import eu.etaxonomy.cdm.vaadin.event.EditorActionTypeFilter; |
50 | 52 |
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent; |
51 | 53 |
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction; |
... | ... | |
56 | 58 |
import eu.etaxonomy.cdm.vaadin.event.TypeDesignationWorkingsetEditorAction; |
57 | 59 |
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkingsetAction; |
58 | 60 |
import eu.etaxonomy.cdm.vaadin.model.EntityReference; |
61 |
import eu.etaxonomy.cdm.vaadin.model.TypedEntityReference; |
|
59 | 62 |
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet; |
60 | 63 |
import eu.etaxonomy.cdm.vaadin.security.UserHelper; |
61 | 64 |
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults; |
... | ... | |
67 | 70 |
import eu.etaxonomy.cdm.vaadin.view.name.TaxonNamePopupEditorMode; |
68 | 71 |
import eu.etaxonomy.cdm.vaadin.view.name.TypeDesignationWorkingsetEditorIdSet; |
69 | 72 |
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor; |
73 |
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor; |
|
70 | 74 |
import eu.etaxonomy.vaadin.mvp.AbstractPresenter; |
75 |
import eu.etaxonomy.vaadin.mvp.AbstractView; |
|
71 | 76 |
import eu.etaxonomy.vaadin.mvp.BeanInstantiator; |
72 | 77 |
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent; |
73 | 78 |
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent.Reason; |
... | ... | |
151 | 156 |
null); |
152 | 157 |
Authentication authentication = currentSecurityContext().getAuthentication(); |
153 | 158 |
reg.setSubmitter((User)authentication.getPrincipal()); |
154 |
EntityChangeEvent event = getRegistrationStore().saveBean(reg); |
|
159 |
EntityChangeEvent event = getRegistrationStore().saveBean(reg, (AbstractView) getView());
|
|
155 | 160 |
UserHelper.fromSession().createAuthorityForCurrentUser(Registration.class, event.getEntityId(), Operation.UPDATE, RegistrationStatus.PREPARATION.name()); |
156 | 161 |
getRepo().commitTransaction(txStatus); |
157 | 162 |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
... | ... | |
223 | 228 |
return; |
224 | 229 |
} |
225 | 230 |
|
226 |
ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class); |
|
231 |
ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
|
|
227 | 232 |
popup.withReferenceTypes(RegistrationUIDefaults.PRINTPUB_REFERENCE_TYPES); |
228 | 233 |
popup.loadInEditor(null); |
229 | 234 |
} |
... | ... | |
234 | 239 |
if(!checkFromOwnView(event)){ |
235 | 240 |
return; |
236 | 241 |
} |
237 |
ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class); |
|
242 |
ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
|
|
238 | 243 |
popup.withReferenceTypes(RegistrationUIDefaults.PRINTPUB_REFERENCE_TYPES); |
239 | 244 |
popup.withDeleteButton(true); |
240 | 245 |
popup.loadInEditor(event.getEntityId()); |
241 | 246 |
} |
242 | 247 |
|
243 |
@EventBusListenerMethod
|
|
248 |
@EventBusListenerMethod |
|
244 | 249 |
public void onDoneWithReferencePopupEditor(DoneWithPopupEvent event) throws RegistrationValidationException{ |
245 | 250 |
if(event.getPopup() instanceof ReferencePopupEditor){ |
246 | 251 |
if(event.getReason().equals(Reason.SAVE)){ |
... | ... | |
265 | 270 |
return; |
266 | 271 |
} |
267 | 272 |
|
268 |
RegistrationPopupEditor popup = getNavigationManager().showInPopup(RegistrationPopupEditor.class); |
|
273 |
RegistrationPopupEditor popup = getNavigationManager().showInPopup(RegistrationPopupEditor.class, getView());
|
|
269 | 274 |
popup.loadInEditor(event.getEntityId()); |
270 | 275 |
} |
271 | 276 |
|
... | ... | |
276 | 281 |
return; |
277 | 282 |
} |
278 | 283 |
|
279 |
TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class); |
|
284 |
TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView()); |
|
285 |
popup.setParentEditorActionContext(event.getContext()); |
|
280 | 286 |
popup.withDeleteButton(true); |
281 | 287 |
configureTaxonNameEditor(popup); |
282 | 288 |
popup.loadInEditor(event.getEntityId()); |
... | ... | |
296 | 302 |
|
297 | 303 |
newTaxonNameForRegistration = TaxonNameFactory.NewNameInstance(RegistrationUIDefaults.NOMENCLATURAL_CODE, Rank.SPECIES()); |
298 | 304 |
newTaxonNameForRegistration.setNomenclaturalReference(getRepo().getReferenceService().find(workingset.getCitationId())); |
299 |
EntityChangeEvent nameSaveEvent = getTaxonNameStore().saveBean(newTaxonNameForRegistration); |
|
305 |
EntityChangeEvent nameSaveEvent = getTaxonNameStore().saveBean(newTaxonNameForRegistration, (AbstractView) getView());
|
|
300 | 306 |
newTaxonNameForRegistration = getRepo().getNameService().find(nameSaveEvent.getEntityId()); |
301 |
TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class); |
|
307 |
TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView()); |
|
308 |
popup.setParentEditorActionContext(event.getContext()); |
|
302 | 309 |
popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE,CRUD.DELETE)); |
303 | 310 |
popup.withDeleteButton(true); |
304 | 311 |
configureTaxonNameEditor(popup); |
... | ... | |
345 | 352 |
} else if(event.getReason().equals(Reason.CANCEL)){ |
346 | 353 |
if(newTaxonNameForRegistration != null){ |
347 | 354 |
// clean up |
348 |
getTaxonNameStore().deleteBean(newTaxonNameForRegistration); |
|
355 |
getTaxonNameStore().deleteBean(newTaxonNameForRegistration, (AbstractView) getView());
|
|
349 | 356 |
} |
350 | 357 |
} |
351 | 358 |
getRepo().commitTransaction(txStatus); |
... | ... | |
393 | 400 |
} |
394 | 401 |
|
395 | 402 |
if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET ){ |
396 |
SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class); |
|
403 |
SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class, getView()); |
|
404 |
popup.setParentEditorActionContext(event.getContext()); |
|
397 | 405 |
popup.withDeleteButton(true); |
398 | 406 |
popup.loadInEditor(new TypeDesignationWorkingsetEditorIdSet(event.getRegistrationId(), event.getBaseEntityRef())); |
399 | 407 |
if(event.getSourceComponent() != null){ |
... | ... | |
401 | 409 |
popup.setReadOnly(event.getSourceComponent().isReadOnly()); |
402 | 410 |
} |
403 | 411 |
} else { |
404 |
NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class); |
|
412 |
NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class, getView()); |
|
413 |
popup.setParentEditorActionContext(event.getContext()); |
|
405 | 414 |
popup.withDeleteButton(true); |
406 | 415 |
popup.loadInEditor(new TypeDesignationWorkingsetEditorIdSet(event.getRegistrationId(), event.getBaseEntityRef())); |
407 | 416 |
|
... | ... | |
424 | 433 |
} |
425 | 434 |
|
426 | 435 |
if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET){ |
427 |
SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class); |
|
436 |
SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class, getView()); |
|
437 |
popup.setParentEditorActionContext(event.getContext()); |
|
428 | 438 |
TypeDesignationWorkingsetEditorIdSet identifierSet; |
429 | 439 |
Integer typifiedNameId; |
430 | 440 |
if(newRegistrationDTOWithExistingName != null){ |
... | ... | |
453 | 463 |
popup.setReadOnly(event.getSourceComponent().isReadOnly()); |
454 | 464 |
} |
455 | 465 |
} else { |
456 |
NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class); |
|
466 |
NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class, getView()); |
|
467 |
popup.setParentEditorActionContext(event.getContext()); |
|
457 | 468 |
popup.withDeleteButton(true); |
458 | 469 |
popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE)); |
459 | 470 |
newNameTypeDesignationTarget = workingset.getRegistrationDTO(event.getRegistrationId()).get(); |
... | ... | |
498 | 509 |
} else if(event.getReason().equals(Reason.CANCEL)){ |
499 | 510 |
// clean up |
500 | 511 |
if(newRegistrationDTOWithExistingName != null){ |
501 |
getRegistrationStore().deleteBean(newRegistrationDTOWithExistingName.registration()); |
|
512 |
getRegistrationStore().deleteBean(newRegistrationDTOWithExistingName.registration(), (AbstractView) getView());
|
|
502 | 513 |
} |
503 | 514 |
} |
504 | 515 |
// set newRegistrationDTOWithExistingName NULL in any case |
... | ... | |
566 | 577 |
} |
567 | 578 |
} else |
568 | 579 |
if(TaxonName.class.isAssignableFrom(event.getEntityType())){ |
580 |
if(event.getType().equals(EntityChangeEvent.Type.CREATED)){ |
|
581 |
// new name! create a blocking registration |
|
582 |
Stack<EditorActionContext>context = ((AbstractPopupEditor)event.getSourceView()).getEditorActionContext(); |
|
583 |
EditorActionContext rootContext = context.get(0); |
|
584 |
if(rootContext.getParentView().equals(getView())){ |
|
585 |
TypedEntityReference<Registration> regReference = (TypedEntityReference<Registration>)rootContext.getParentEntity(); |
|
586 |
TaxonName newName = getRepo().getNameService().load(event.getEntityId(), Arrays.asList("$", "registrations")); |
|
587 |
Registration blockingRegistration = Registration.NewInstance(); |
|
588 |
blockingRegistration = getRepo().getRegistrationService().save(blockingRegistration); |
|
589 |
blockingRegistration.setName(newName); |
|
590 |
Registration registration = getRepo().getRegistrationService().load(regReference.getId(), Arrays.asList("$", "blockedBy")); |
|
591 |
registration.getBlockedBy().add(blockingRegistration); |
|
592 |
getRepo().getRegistrationService().saveOrUpdate(registration); |
|
593 |
logger.debug("Blocking registration created"); |
|
594 |
} else { |
|
595 |
throw new RuntimeException("huuu?"); |
|
596 |
} |
|
597 |
} |
|
569 | 598 |
if(workingset.getRegistrationDTOs().stream().anyMatch(reg -> |
570 | 599 |
reg.getTypifiedNameRef() != null |
571 | 600 |
&& reg.getTypifiedNameRef().getId() == event.getEntityId())){ |
Also available in: Unified diff
ref #7195 introducing the concept of EditorActionContext stacks to facilitate creating blocking relations