2 * Copyright (C) 2017 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
.common
;
11 import java
.util
.Arrays
;
12 import java
.util
.List
;
13 import java
.util
.UUID
;
15 import org
.springframework
.context
.annotation
.Scope
;
16 import org
.vaadin
.spring
.events
.annotation
.EventBusListenerMethod
;
18 import com
.vaadin
.spring
.annotation
.SpringComponent
;
20 import eu
.etaxonomy
.cdm
.api
.service
.IService
;
21 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
22 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
23 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
24 import eu
.etaxonomy
.cdm
.service
.CdmFilterablePagingProvider
;
25 import eu
.etaxonomy
.cdm
.service
.UserHelperAccess
;
26 import eu
.etaxonomy
.cdm
.vaadin
.event
.EditorActionTypeFilter
;
27 import eu
.etaxonomy
.cdm
.vaadin
.event
.EntityChangeEvent
;
28 import eu
.etaxonomy
.cdm
.vaadin
.event
.InstitutionEditorAction
;
29 import eu
.etaxonomy
.cdm
.vaadin
.event
.ToOneRelatedEntityReloader
;
30 import eu
.etaxonomy
.cdm
.vaadin
.model
.common
.InstitutionDTO
;
31 import eu
.etaxonomy
.vaadin
.mvp
.AbstractCdmDTOEditorPresenter
;
32 import eu
.etaxonomy
.vaadin
.mvp
.BoundField
;
33 import eu
.etaxonomy
.vaadin
.ui
.view
.PopupView
;
36 * @author a.kohlbecker
42 public class InstitutionEditorPresenter
extends AbstractCdmDTOEditorPresenter
<InstitutionDTO
, Institution
, InstitutionPopupEditorView
> {
44 private static final long serialVersionUID
= -1996365248431425021L;
51 protected Institution
loadCdmEntity(UUID identifier
) {
53 List
<String
> initStrategy
= Arrays
.asList(new String
[]{
62 if(identifier
!= null){
63 bean
= (Institution
) getRepo().getAgentService().load(identifier
, initStrategy
);
65 bean
= Institution
.NewInstance();
74 protected void guaranteePerEntityCRUDPermissions(UUID identifier
) {
76 newAuthorityCreated
= UserHelperAccess
.userHelper().createAuthorityForCurrentUser(Collection
.class, identifier
, crud
, null);
85 protected void guaranteePerEntityCRUDPermissions(Institution bean
) {
87 newAuthorityCreated
= UserHelperAccess
.userHelper().createAuthorityForCurrentUser(bean
, crud
, null);
96 protected IService
<Institution
> getService() {
97 // TODO Auto-generated method stub
105 public void handleViewEntered() {
106 super.handleViewEntered();
108 CdmFilterablePagingProvider
<AgentBase
, Institution
> collectionPagingProvider
= new CdmFilterablePagingProvider
<AgentBase
, Institution
>(getRepo().getAgentService(), Institution
.class);
109 getView().getPartOfCombobox().getSelect().loadFrom(collectionPagingProvider
, collectionPagingProvider
, collectionPagingProvider
.getPageSize());
110 getView().getPartOfCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader
<Institution
>(getView().getPartOfCombobox(), this));
114 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Add
.class)
115 public void onInstitutionEditorActionAdd(InstitutionEditorAction event
) {
117 if(!checkFromOwnView(event
)){
121 InstitutionPopupEditor intitutionPopuEditor
= openPopupEditor(InstitutionPopupEditor
.class, event
);
123 intitutionPopuEditor
.grantToCurrentUser(this.crud
);
124 intitutionPopuEditor
.withDeleteButton(true);
125 intitutionPopuEditor
.loadInEditor(null);
128 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Edit
.class)
129 public void onCollectionEditorActionEdit(InstitutionEditorAction event
) {
131 if(!checkFromOwnView(event
)){
135 InstitutionPopupEditor intitutionPopuEditor
= openPopupEditor(InstitutionPopupEditor
.class, event
);
137 intitutionPopuEditor
.grantToCurrentUser(this.crud
);
138 intitutionPopuEditor
.withDeleteButton(true);
139 intitutionPopuEditor
.loadInEditor(event
.getEntityUuid());
142 @EventBusListenerMethod()
143 public void onEntityChangeEvent(EntityChangeEvent
<?
> event
){
145 BoundField boundTargetField
= boundTargetField((PopupView
) event
.getSourceView());
147 if(boundTargetField
!= null){
148 if(boundTargetField
.matchesPropertyIdPath("isPartOf")){
149 if(event
.isCreateOrModifiedType()){
151 Institution newInstitution
= (Institution
) event
.getEntity();
152 getCache().load(newInstitution
);
153 if(event
.isCreatedType()){
154 getView().getPartOfCombobox().setValue(newInstitution
);
156 getView().getPartOfCombobox().reload();
168 protected InstitutionDTO
createDTODecorator(Institution cdmEntitiy
) {
169 return new InstitutionDTO(cdmEntitiy
);