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
.reference
;
11 import java
.util
.Arrays
;
12 import java
.util
.List
;
13 import java
.util
.UUID
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.springframework
.context
.annotation
.Scope
;
17 import org
.vaadin
.spring
.events
.annotation
.EventBusListenerMethod
;
18 import org
.vaadin
.viritin
.fields
.CaptionGenerator
;
20 import com
.vaadin
.spring
.annotation
.SpringComponent
;
22 import eu
.etaxonomy
.cdm
.api
.service
.IService
;
23 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
24 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
25 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
26 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
27 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
28 import eu
.etaxonomy
.cdm
.service
.CdmFilterablePagingProvider
;
29 import eu
.etaxonomy
.cdm
.service
.UserHelperAccess
;
30 import eu
.etaxonomy
.cdm
.vaadin
.event
.EntityChangeEvent
;
31 import eu
.etaxonomy
.cdm
.vaadin
.event
.ReferenceEditorAction
;
32 import eu
.etaxonomy
.cdm
.vaadin
.event
.ToOneRelatedEntityButtonUpdater
;
33 import eu
.etaxonomy
.cdm
.vaadin
.event
.ToOneRelatedEntityReloader
;
34 import eu
.etaxonomy
.vaadin
.component
.ToOneRelatedEntityField
;
35 import eu
.etaxonomy
.vaadin
.mvp
.AbstractCdmEditorPresenter
;
38 * @author a.kohlbecker
44 public class ReferenceEditorPresenter
extends AbstractCdmEditorPresenter
<Reference
, ReferencePopupEditorView
> {
46 private static final long serialVersionUID
= -7926116447719010837L;
48 private static final Logger logger
= Logger
.getLogger(ReferenceEditorPresenter
.class);
50 ReferencePopupEditor inReferencePopup
= null;
52 public ReferenceEditorPresenter() {
61 public void handleViewEntered() {
62 super.handleViewEntered();
64 getView().getInReferenceCombobox().getSelect().setCaptionGenerator(new CaptionGenerator
<Reference
>(){
67 public String
getCaption(Reference option
) {
68 return option
.getTitleCache();
73 CdmFilterablePagingProvider
<Reference
, Reference
> collectionPagingProvider
= pagingProviderFactory
.referencePagingProvider();
74 getView().getInReferenceCombobox().loadFrom(collectionPagingProvider
, collectionPagingProvider
, collectionPagingProvider
.getPageSize());
75 getView().getInReferenceCombobox().setNestedButtonStateUpdater(new ToOneRelatedEntityButtonUpdater
<Reference
>(getView().getInReferenceCombobox()));
76 getView().getInReferenceCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader
<Reference
>(getView().getInReferenceCombobox(),this));
78 CdmFilterablePagingProvider
<AgentBase
, TeamOrPersonBase
> teamOrPersonPagingProvider
= new CdmFilterablePagingProvider
<AgentBase
, TeamOrPersonBase
>(getRepo().getAgentService(), TeamOrPersonBase
.class);
79 CdmFilterablePagingProvider
<AgentBase
, Person
> personPagingProvider
= new CdmFilterablePagingProvider
<AgentBase
, Person
>(getRepo().getAgentService(), Person
.class);
80 getView().getAuthorshipField().setFilterableTeamPagingProvider(teamOrPersonPagingProvider
, this);
81 getView().getAuthorshipField().setFilterablePersonPagingProvider(personPagingProvider
, this);
88 protected Reference
loadCdmEntity(UUID identifier
) {
90 List
<String
> initStrategy
= Arrays
.asList(new String
[]{
97 if(identifier
!= null){
98 reference
= getRepo().getReferenceService().load(identifier
, initStrategy
);
100 reference
= createNewReference();
106 * TODO this should better go into {@link AbstractCdmEditorPresenter}
110 protected Reference
createNewReference() {
111 if(this.beanInstantiator
!= null){
112 return beanInstantiator
.createNewBean();
114 return ReferenceFactory
.newGeneric();
121 protected void guaranteePerEntityCRUDPermissions(UUID identifier
) {
123 newAuthorityCreated
= UserHelperAccess
.userHelper().createAuthorityForCurrentUser(Reference
.class, identifier
, crud
, null);
132 protected void guaranteePerEntityCRUDPermissions(Reference bean
) {
134 newAuthorityCreated
= UserHelperAccess
.userHelper().createAuthorityForCurrentUser(bean
, crud
, null);
140 * @param editorAction
141 * @throws EditorEntityBeanException
143 @EventBusListenerMethod
144 public void onReferenceEditorAction(ReferenceEditorAction editorAction
) {
146 if(!isFromOwnView(editorAction
) || editorAction
.getTarget() == null){
150 if(ToOneRelatedEntityField
.class.isAssignableFrom(editorAction
.getTarget().getClass())){
151 if(editorAction
.isAddAction()){
152 inReferencePopup
= openPopupEditor(ReferencePopupEditor
.class, editorAction
);
153 inReferencePopup
.loadInEditor(null);
155 if(editorAction
.isEditAction()){
156 inReferencePopup
= openPopupEditor(ReferencePopupEditor
.class, editorAction
);
157 inReferencePopup
.withDeleteButton(true);
158 inReferencePopup
.loadInEditor(editorAction
.getEntityUuid());
163 @EventBusListenerMethod
164 public void onEntityChangeEvent(EntityChangeEvent
<?
> event
){
166 if(event
.getSourceView() == inReferencePopup
){
167 if(event
.isCreateOrModifiedType()){
168 getCache().load(event
.getEntity());
169 getView().getInReferenceCombobox().reload();
171 if(event
.isRemovedType()){
172 getView().getInReferenceCombobox().selectNewItem(null);
174 inReferencePopup
= null;
183 protected IService
<Reference
> getService() {
184 return getRepo().getReferenceService();