Revision 51d6bc3c
Added by Andreas Kohlbecker about 6 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/NameTypeDesignationPopupEditor.java | ||
---|---|---|
132 | 132 |
typifiedNamesComboboxSelect = new ToManyRelatedEntitiesComboboxSelect<TaxonName>(TaxonName.class, "Typified names"); |
133 | 133 |
typifiedNamesComboboxSelect.setConverter(new SetToListConverter<TaxonName>()); |
134 | 134 |
addField(typifiedNamesComboboxSelect, "typifiedNames", 0, row, 3, row); |
135 |
typifiedNamesComboboxSelect.setReadOnly(false); // FIXME this does not help |
|
135 | 136 |
|
136 | 137 |
row++; |
137 | 138 |
citationCombobox = new ToOneRelatedEntityCombobox<Reference>("Citation", Reference.class); |
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/NameTypeDesignationPresenter.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.cdm.vaadin.view.name; |
10 | 10 |
|
11 | 11 |
import java.util.Arrays; |
12 |
import java.util.HashSet; |
|
12 | 13 |
import java.util.List; |
13 | 14 |
|
14 | 15 |
import eu.etaxonomy.cdm.api.service.IService; |
... | ... | |
21 | 22 |
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityButtonUpdater; |
22 | 23 |
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader; |
23 | 24 |
import eu.etaxonomy.cdm.vaadin.security.UserHelper; |
25 |
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator; |
|
24 | 26 |
import eu.etaxonomy.vaadin.mvp.AbstractCdmEditorPresenter; |
25 | 27 |
|
26 | 28 |
/** |
... | ... | |
31 | 33 |
public class NameTypeDesignationPresenter |
32 | 34 |
extends AbstractCdmEditorPresenter<NameTypeDesignation, NameTypeDesignationEditorView> { |
33 | 35 |
|
36 |
HashSet<TaxonName> typifiedNamesAsLoaded; |
|
37 |
|
|
34 | 38 |
/** |
35 | 39 |
* {@inheritDoc} |
36 | 40 |
*/ |
... | ... | |
54 | 58 |
typeDesignation = NameTypeDesignation.NewInstance(); |
55 | 59 |
} |
56 | 60 |
} |
61 |
|
|
62 |
typifiedNamesAsLoaded = new HashSet<>(typeDesignation.getTypifiedNames()); |
|
63 |
|
|
57 | 64 |
return typeDesignation; |
58 | 65 |
} |
59 | 66 |
|
... | ... | |
69 | 76 |
CdmBeanItemContainerFactory selectFactory = new CdmBeanItemContainerFactory(getRepo()); |
70 | 77 |
getView().getTypeStatusSelect().setContainerDataSource(selectFactory.buildBeanItemContainer(NameTypeDesignationStatus.class)); |
71 | 78 |
|
79 |
getView().getCitationCombobox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Reference>()); |
|
72 | 80 |
CdmFilterablePagingProvider<Reference,Reference> referencePagingProvider = new CdmFilterablePagingProvider<Reference, Reference>(getRepo().getReferenceService()); |
73 | 81 |
getView().getCitationCombobox().loadFrom(referencePagingProvider, referencePagingProvider, referencePagingProvider.getPageSize()); |
74 | 82 |
getView().getCitationCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityButtonUpdater<Reference>(getView().getCitationCombobox())); |
... | ... | |
112 | 120 |
return null; |
113 | 121 |
} |
114 | 122 |
|
123 |
|
|
124 |
/** |
|
125 |
* {@inheritDoc} |
|
126 |
*/ |
|
127 |
@Override |
|
128 |
protected NameTypeDesignation handleTransientProperties(NameTypeDesignation bean) { |
|
129 |
|
|
130 |
// the typifiedNames can only be set on the name side, so we need to |
|
131 |
// handle changes explicitly here |
|
132 |
HashSet<TaxonName> typifiedNames = new HashSet<>(bean.getTypifiedNames()); |
|
133 |
|
|
134 |
// handle adds |
|
135 |
for(TaxonName name : typifiedNames){ |
|
136 |
if(!name.getTypeDesignations().contains(bean)){ |
|
137 |
name.addTypeDesignation(bean, false); |
|
138 |
} |
|
139 |
} |
|
140 |
// handle removed |
|
141 |
for(TaxonName name : typifiedNamesAsLoaded){ |
|
142 |
if(!typifiedNames.contains(name)){ |
|
143 |
name.removeTypeDesignation(bean); |
|
144 |
} |
|
145 |
// FIXME do we need to save the names here or is the delete cascaded from the typedesignation to the name? |
|
146 |
} |
|
147 |
|
|
148 |
return bean; |
|
149 |
} |
|
150 |
|
|
151 |
|
|
152 |
|
|
115 | 153 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java | ||
---|---|---|
14 | 14 |
import java.util.List; |
15 | 15 |
import java.util.UUID; |
16 | 16 |
|
17 |
import org.hibernate.Session; |
|
18 |
import org.hibernate.Transaction; |
|
17 | 19 |
import org.springframework.beans.factory.annotation.Autowired; |
18 | 20 |
import org.springframework.context.event.EventListener; |
19 | 21 |
import org.springframework.security.core.Authentication; |
... | ... | |
31 | 33 |
import eu.etaxonomy.cdm.api.service.idminter.IdentifierMinter.Identifier; |
32 | 34 |
import eu.etaxonomy.cdm.api.service.idminter.RegistrationIdentifierMinter; |
33 | 35 |
import eu.etaxonomy.cdm.model.common.User; |
36 |
import eu.etaxonomy.cdm.model.name.NameTypeDesignation; |
|
34 | 37 |
import eu.etaxonomy.cdm.model.name.Rank; |
35 | 38 |
import eu.etaxonomy.cdm.model.name.Registration; |
36 | 39 |
import eu.etaxonomy.cdm.model.name.RegistrationStatus; |
... | ... | |
63 | 66 |
import eu.etaxonomy.cdm.vaadin.view.name.TypeDesignationWorkingsetEditorIdSet; |
64 | 67 |
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor; |
65 | 68 |
import eu.etaxonomy.vaadin.mvp.AbstractPresenter; |
69 |
import eu.etaxonomy.vaadin.mvp.BeanInstantiator; |
|
66 | 70 |
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent; |
67 | 71 |
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent.Reason; |
68 | 72 |
|
... | ... | |
386 | 390 |
popup.withDeleteButton(true); |
387 | 391 |
popup.loadInEditor(new TypeDesignationWorkingsetEditorIdSet(event.getRegistrationId(), event.getEntityId())); |
388 | 392 |
if(event.getSourceComponent() != null){ |
389 |
// TODO document this !!!!!!!!!!!
|
|
393 |
// propagate readonly state from source component to popup
|
|
390 | 394 |
popup.setReadOnly(event.getSourceComponent().isReadOnly()); |
391 | 395 |
} |
392 | 396 |
} else { |
393 | 397 |
NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class); |
394 | 398 |
popup.withDeleteButton(true); |
395 | 399 |
popup.loadInEditor(event.getEntityId()); |
400 |
|
|
401 |
popup.getCitationCombobox().setEnabled(false); |
|
402 |
popup.getTypifiedNamesComboboxSelect().setEnabled(false); |
|
403 |
|
|
396 | 404 |
if(event.getSourceComponent() != null){ |
405 |
// propagate readonly state from source component to popup |
|
397 | 406 |
popup.setReadOnly(event.getSourceComponent().isReadOnly()); |
398 | 407 |
} |
399 | 408 |
newNameTypeDesignationTarget = workingset.getRegistrationDTO(event.getRegistrationId()).get(); |
... | ... | |
428 | 437 |
popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE)); |
429 | 438 |
popup.loadInEditor(identifierSet); |
430 | 439 |
popup.withDeleteButton(true); |
440 |
if(event.getSourceComponent() != null){ |
|
441 |
// propagate readonly state from source component to popup |
|
442 |
popup.setReadOnly(event.getSourceComponent().isReadOnly()); |
|
443 |
} |
|
431 | 444 |
} else { |
432 | 445 |
NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class); |
433 | 446 |
popup.withDeleteButton(true); |
434 | 447 |
popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE)); |
448 |
newNameTypeDesignationTarget = workingset.getRegistrationDTO(event.getRegistrationId()).get(); |
|
449 |
popup.setBeanInstantiator(new BeanInstantiator<NameTypeDesignation>() { |
|
450 |
|
|
451 |
@Override |
|
452 |
public NameTypeDesignation createNewBean() { |
|
453 |
NameTypeDesignation nameTypeDesignation = NameTypeDesignation.NewInstance(); |
|
454 |
nameTypeDesignation.setCitation(newNameTypeDesignationTarget.getCitation()); |
|
455 |
nameTypeDesignation.getTypifiedNames().add(newNameTypeDesignationTarget.getTypifiedName()); |
|
456 |
return nameTypeDesignation; |
|
457 |
} |
|
458 |
}); |
|
435 | 459 |
popup.loadInEditor(null); |
460 |
popup.getCitationCombobox().setEnabled(false); |
|
461 |
popup.getTypifiedNamesComboboxSelect().setEnabled(false); |
|
436 | 462 |
if(event.getSourceComponent() != null){ |
463 |
// propagate readonly state from source component to popup |
|
437 | 464 |
popup.setReadOnly(event.getSourceComponent().isReadOnly()); |
438 | 465 |
} |
439 |
newNameTypeDesignationTarget = workingset.getRegistrationDTO(event.getRegistrationId()).get(); |
|
440 | 466 |
} |
441 | 467 |
} |
442 | 468 |
|
... | ... | |
469 | 495 |
} else if(event.getPopup() instanceof NameTypeDesignationPopupEditor){ |
470 | 496 |
if(event.getReason().equals(Reason.SAVE)){ |
471 | 497 |
UUID uuid = ((NameTypeDesignationPopupEditor)event.getPopup()).getBean().getUuid(); |
472 |
TypeDesignationBase<?> nameTypeDesignation = getRepo().getNameService().loadTypeDesignation(uuid, null); |
|
473 |
Registration registration = getRepo().getRegistrationService().load(newNameTypeDesignationTarget.getId(), Arrays.asList("$", "typeDesignations")); |
|
498 |
|
|
499 |
Session session = getRepo().getSessionFactory().openSession(); |
|
500 |
Transaction txstate = session.beginTransaction(); |
|
501 |
TypeDesignationBase<?> nameTypeDesignation = getRepo().getNameService().loadTypeDesignation(uuid, Arrays.asList("")); |
|
502 |
// only load the typeDesignations with the registration so that the typified name can not be twice in the session |
|
503 |
// otherwise multiple representation problems might occur |
|
504 |
Registration registration = getRepo().getRegistrationService().load(newNameTypeDesignationTarget.getUuid(), Arrays.asList("typeDesignations")); |
|
474 | 505 |
registration.getTypeDesignations().add(nameTypeDesignation); |
475 |
getRepo().getRegistrationService().saveOrUpdate(registration); |
|
506 |
session.merge(registration); |
|
507 |
txstate.commit(); |
|
508 |
session.close(); |
|
509 |
|
|
476 | 510 |
newNameTypeDesignationTarget = null; |
477 | 511 |
refreshView(true); |
478 | 512 |
} else if(event.getReason().equals(Reason.CANCEL)){ |
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPopupEditor.java | ||
---|---|---|
48 | 48 |
import eu.etaxonomy.cdm.vaadin.component.TextFieldNFix; |
49 | 49 |
import eu.etaxonomy.vaadin.component.NestedFieldGroup; |
50 | 50 |
import eu.etaxonomy.vaadin.component.SwitchableTextField; |
51 |
import eu.etaxonomy.vaadin.mvp.event.EditorCancelEvent; |
|
52 | 51 |
import eu.etaxonomy.vaadin.mvp.event.EditorDeleteEvent; |
53 | 52 |
import eu.etaxonomy.vaadin.mvp.event.EditorPreSaveEvent; |
54 | 53 |
import eu.etaxonomy.vaadin.mvp.event.EditorSaveEvent; |
... | ... | |
279 | 278 |
@Override |
280 | 279 |
public void cancel() { |
281 | 280 |
fieldGroup.discard(); |
282 |
eventBus.publishEvent(new EditorCancelEvent<DTO>(this, getBean())); |
|
283 | 281 |
eventBus.publishEvent(new DoneWithPopupEvent(this, Reason.CANCEL)); |
284 | 282 |
} |
285 | 283 |
|
... | ... | |
287 | 285 |
* @return |
288 | 286 |
*/ |
289 | 287 |
private void delete() { |
290 |
eventBus.publishEvent(new EditorDeleteEvent(this, fieldGroup.getItemDataSource().getBean())); |
|
288 |
eventBus.publishEvent(new EditorDeleteEvent<DTO>(this, fieldGroup.getItemDataSource().getBean()));
|
|
291 | 289 |
eventBus.publishEvent(new DoneWithPopupEvent(this, Reason.DELETE)); |
292 | 290 |
} |
293 | 291 |
|
Also available in: Unified diff
fix #6740 NameTypeDesignationEditor save operation working