2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.vaadin
.view
.name
;
11 import java
.util
.Arrays
;
12 import java
.util
.HashSet
;
13 import java
.util
.List
;
15 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
16 import org
.springframework
.context
.annotation
.Scope
;
18 import com
.vaadin
.spring
.annotation
.SpringComponent
;
20 import eu
.etaxonomy
.cdm
.api
.service
.IService
;
21 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignation
;
22 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignationStatus
;
23 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
24 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
25 import eu
.etaxonomy
.cdm
.service
.CdmFilterablePagingProvider
;
26 import eu
.etaxonomy
.cdm
.service
.IRegistrationWorkingSetService
;
27 import eu
.etaxonomy
.cdm
.vaadin
.component
.CdmBeanItemContainerFactory
;
28 import eu
.etaxonomy
.cdm
.vaadin
.event
.ToOneRelatedEntityButtonUpdater
;
29 import eu
.etaxonomy
.cdm
.vaadin
.event
.ToOneRelatedEntityReloader
;
30 import eu
.etaxonomy
.cdm
.vaadin
.security
.UserHelper
;
31 import eu
.etaxonomy
.cdm
.vaadin
.util
.CdmTitleCacheCaptionGenerator
;
32 import eu
.etaxonomy
.cdm
.vaadin
.util
.converter
.TypeDesignationSetManager
.TypeDesignationWorkingSet
;
33 import eu
.etaxonomy
.cdm
.vaadin
.view
.registration
.RegistrationDTO
;
34 import eu
.etaxonomy
.vaadin
.mvp
.AbstractCdmEditorPresenter
;
37 * @author a.kohlbecker
43 public class NameTypeDesignationPresenter
44 extends AbstractCdmEditorPresenter
<NameTypeDesignation
, NameTypeDesignationEditorView
> {
47 private IRegistrationWorkingSetService registrationWorkingSetService
;
49 HashSet
<TaxonName
> typifiedNamesAsLoaded
;
56 protected NameTypeDesignation
loadBeanById(Object identifier
) {
57 if(identifier
instanceof Integer
|| identifier
== null){
58 return super.loadBeanById(identifier
);
60 TypeDesignationWorkingsetEditorIdSet idset
= (TypeDesignationWorkingsetEditorIdSet
)identifier
;
61 RegistrationDTO regDTO
= registrationWorkingSetService
.loadDtoById(idset
.registrationId
);
62 // find the working set
63 TypeDesignationWorkingSet typeDesignationWorkingSet
= regDTO
.getTypeDesignationWorkingSet(idset
.baseEntityRef
);
65 // NameTypeDesignation bameTypeDesignation = regDTO.getNameTypeDesignation(typeDesignationWorkingSet.getBaseEntityReference());
66 if(!typeDesignationWorkingSet
.getBaseEntityReference().getType().equals(TaxonName
.class)){
67 throw new RuntimeException("TypeDesignationWorkingsetEditorIdSet references not a NameTypeDesignation");
69 // TypeDesignationWorkingSet for NameTyped only contain one item!!!
70 int nameTypeDesignationId
= typeDesignationWorkingSet
.getTypeDesignations().get(0).getId();
71 return super.loadBeanById(nameTypeDesignationId
);
80 protected NameTypeDesignation
loadCdmEntityById(Integer identifier
) {
81 List
<String
> initStrategy
= Arrays
.asList(new String
[]{
83 "typifiedNames.typeDesignations", // important !!
85 "citation.authorship.$",
89 NameTypeDesignation typeDesignation
;
90 if(identifier
!= null){
91 typeDesignation
= (NameTypeDesignation
) getRepo().getNameService().loadTypeDesignation(identifier
, initStrategy
);
93 if(beanInstantiator
!= null){
94 typeDesignation
= beanInstantiator
.createNewBean();
96 typeDesignation
= NameTypeDesignation
.NewInstance();
100 typifiedNamesAsLoaded
= new HashSet
<>(typeDesignation
.getTypifiedNames());
102 return typeDesignation
;
112 public void handleViewEntered() {
114 CdmBeanItemContainerFactory selectFactory
= new CdmBeanItemContainerFactory(getRepo());
115 getView().getTypeStatusSelect().setContainerDataSource(selectFactory
.buildBeanItemContainer(NameTypeDesignationStatus
.class));
116 getView().getTypeStatusSelect().setItemCaptionPropertyId("description");
118 getView().getCitationCombobox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator
<Reference
>());
119 CdmFilterablePagingProvider
<Reference
,Reference
> referencePagingProvider
= new CdmFilterablePagingProvider
<Reference
, Reference
>(getRepo().getReferenceService());
120 getView().getCitationCombobox().loadFrom(referencePagingProvider
, referencePagingProvider
, referencePagingProvider
.getPageSize());
121 getView().getCitationCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityButtonUpdater
<Reference
>(getView().getCitationCombobox()));
122 getView().getCitationCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader
<>(getView().getCitationCombobox(), this));
124 CdmFilterablePagingProvider
<TaxonName
,TaxonName
> namePagingProvider
= new CdmFilterablePagingProvider
<TaxonName
, TaxonName
>(getRepo().getNameService());
125 getView().getTypeNameField().loadFrom(namePagingProvider
, namePagingProvider
, namePagingProvider
.getPageSize());
126 getView().getTypeNameField().getSelect().addValueChangeListener(new ToOneRelatedEntityButtonUpdater
<TaxonName
>(getView().getTypeNameField()));
127 getView().getTypeNameField().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader
<>(getView().getTypeNameField(), this));
129 getView().getTypifiedNamesComboboxSelect().setPagingProviders(namePagingProvider
, namePagingProvider
, namePagingProvider
.getPageSize(), this);
138 protected void guaranteePerEntityCRUDPermissions(Integer identifier
) {
140 newAuthorityCreated
= UserHelper
.fromSession().createAuthorityForCurrentUser(NameTypeDesignation
.class, identifier
, crud
, null);
148 protected void guaranteePerEntityCRUDPermissions(NameTypeDesignation bean
) {
149 // TODO Auto-generated method stub
157 protected IService
<NameTypeDesignation
> getService() {
158 // TODO Auto-generated method stub
167 protected NameTypeDesignation
handleTransientProperties(NameTypeDesignation bean
) {
169 // the typifiedNames can only be set on the name side, so we need to
170 // handle changes explicitly here
171 HashSet
<TaxonName
> typifiedNames
= new HashSet
<>(bean
.getTypifiedNames());
174 for(TaxonName name
: typifiedNames
){
175 if(!name
.getTypeDesignations().contains(bean
)){
176 name
.addTypeDesignation(bean
, false);
180 for(TaxonName name
: typifiedNamesAsLoaded
){
181 if(!typifiedNames
.contains(name
)){
182 name
.removeTypeDesignation(bean
);
184 // FIXME do we need to save the names here or is the delete cascaded from the typedesignation to the name?