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
.occurrence
;
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
.persistence
.dao
.common
.Restriction
;
25 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.Restriction
.Operator
;
26 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
27 import eu
.etaxonomy
.cdm
.service
.CdmFilterablePagingProvider
;
28 import eu
.etaxonomy
.cdm
.service
.UserHelperAccess
;
29 import eu
.etaxonomy
.cdm
.vaadin
.event
.CollectionEditorAction
;
30 import eu
.etaxonomy
.cdm
.vaadin
.event
.EditorActionTypeFilter
;
31 import eu
.etaxonomy
.cdm
.vaadin
.event
.EntityChangeEvent
;
32 import eu
.etaxonomy
.cdm
.vaadin
.event
.InstitutionEditorAction
;
33 import eu
.etaxonomy
.cdm
.vaadin
.event
.ToOneRelatedEntityReloader
;
34 import eu
.etaxonomy
.cdm
.vaadin
.view
.common
.InstitutionPopupEditor
;
35 import eu
.etaxonomy
.vaadin
.mvp
.AbstractCdmEditorPresenter
;
36 import eu
.etaxonomy
.vaadin
.mvp
.BeanInstantiator
;
37 import eu
.etaxonomy
.vaadin
.mvp
.BoundField
;
38 import eu
.etaxonomy
.vaadin
.ui
.view
.PopupView
;
41 * @author a.kohlbecker
47 public class CollectionEditorPresenter
extends AbstractCdmEditorPresenter
<Collection
, CollectionPopupEditorView
> {
49 private static final long serialVersionUID
= -1996365248431425021L;
51 protected static BeanInstantiator
<Collection
> defaultBeanInstantiator
= new BeanInstantiator
<Collection
>() {
54 public Collection
createNewBean() {
55 return Collection
.NewInstance();
61 protected BeanInstantiator
<Collection
> defaultBeanInstantiator(){
62 return defaultBeanInstantiator
;
69 protected Collection
loadCdmEntity(UUID identifier
) {
71 List
<String
> initStrategy
= Arrays
.asList(new String
[]{
80 if(identifier
!= null){
81 bean
= getRepo().getCollectionService().load(identifier
, initStrategy
);
83 bean
= createNewBean();
92 protected void guaranteePerEntityCRUDPermissions(UUID identifier
) {
94 newAuthorityCreated
= UserHelperAccess
.userHelper().createAuthorityForCurrentUser(Collection
.class, identifier
, crud
, null);
103 protected void guaranteePerEntityCRUDPermissions(Collection bean
) {
105 newAuthorityCreated
= UserHelperAccess
.userHelper().createAuthorityForCurrentUser(bean
, crud
, null);
114 protected IService
<Collection
> getService() {
115 // TODO Auto-generated method stub
123 public void handleViewEntered() {
124 super.handleViewEntered();
126 CdmFilterablePagingProvider
<Collection
, Collection
> collectionPagingProvider
= new CdmFilterablePagingProvider
<Collection
, Collection
>(getRepo().getCollectionService());
127 collectionPagingProvider
.getRestrictions().add(new Restriction
<String
>("institute.titleCache", Operator
.OR
, MatchMode
.ANYWHERE
, CdmFilterablePagingProvider
.QUERY_STRING_PLACEHOLDER
));
128 getView().getSuperCollectionCombobox().getSelect().loadFrom(collectionPagingProvider
, collectionPagingProvider
, collectionPagingProvider
.getPageSize());
129 getView().getSuperCollectionCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader
<Collection
>(getView().getSuperCollectionCombobox(), this));
131 CdmFilterablePagingProvider
<AgentBase
, Institution
> institutionPagingProvider
= new CdmFilterablePagingProvider
<AgentBase
, Institution
>(getRepo().getAgentService(), Institution
.class);
132 getView().getInstitutionCombobox().getSelect().loadFrom(institutionPagingProvider
, institutionPagingProvider
, institutionPagingProvider
.getPageSize());
133 getView().getInstitutionCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader
<Institution
>(getView().getInstitutionCombobox(), this));
136 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Add
.class)
137 public void onCollectionEditorActionAdd(CollectionEditorAction event
) {
139 if(!checkFromOwnView(event
)){
143 CollectionPopupEditor collectionPopuEditor
= openPopupEditor(CollectionPopupEditor
.class, event
);
145 collectionPopuEditor
.grantToCurrentUser(this.crud
);
146 collectionPopuEditor
.withDeleteButton(true);
147 collectionPopuEditor
.loadInEditor(null);
150 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Edit
.class)
151 public void onCollectionEditorActionEdit(CollectionEditorAction event
) {
153 if(!checkFromOwnView(event
)){
157 CollectionPopupEditor collectionPopuEditor
= openPopupEditor(CollectionPopupEditor
.class, event
);
159 collectionPopuEditor
.grantToCurrentUser(this.crud
);
160 collectionPopuEditor
.withDeleteButton(true);
161 collectionPopuEditor
.loadInEditor(event
.getEntityUuid());
164 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Edit
.class)
165 public void onInstitutionEditorActionEdit(InstitutionEditorAction event
) {
167 if(!checkFromOwnView(event
)){
171 InstitutionPopupEditor institutionPopuEditor
= openPopupEditor(InstitutionPopupEditor
.class, event
);
173 institutionPopuEditor
.grantToCurrentUser(this.crud
);
174 institutionPopuEditor
.withDeleteButton(true);
175 institutionPopuEditor
.loadInEditor(event
.getEntityUuid());
178 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Add
.class)
179 public void onInstitutionEditorActionAdd(InstitutionEditorAction event
) {
181 if(!checkFromOwnView(event
)){
185 InstitutionPopupEditor institutionPopuEditor
= openPopupEditor(InstitutionPopupEditor
.class, event
);
187 institutionPopuEditor
.grantToCurrentUser(this.crud
);
188 institutionPopuEditor
.withDeleteButton(false);
189 institutionPopuEditor
.loadInEditor(null);
192 @EventBusListenerMethod()
193 public void onEntityChangeEvent(EntityChangeEvent
<?
> event
){
195 BoundField boundTargetField
= boundTargetField((PopupView
) event
.getSourceView());
197 if(boundTargetField
!= null){
198 if(boundTargetField
.matchesPropertyIdPath("superCollection")){
199 if(event
.isCreateOrModifiedType()){
201 Collection newCollection
= (Collection
) event
.getEntity();
202 getCache().load(newCollection
);
203 if(event
.isCreatedType()){
204 getView().getSuperCollectionCombobox().setValue(newCollection
);
206 getView().getSuperCollectionCombobox().reload();
210 } else if(boundTargetField
.matchesPropertyIdPath("institute")){
211 if(event
.isCreateOrModifiedType()){
213 Institution newInstitution
= (Institution
) event
.getEntity();
214 getCache().load(newInstitution
);
215 if(event
.isCreatedType()){
216 getView().getInstitutionCombobox().setValue(newInstitution
);
218 getView().getInstitutionCombobox().reload();