1
|
/**
|
2
|
* Copyright (C) 2017 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.vaadin.view.common;
|
10
|
|
11
|
import java.util.Arrays;
|
12
|
import java.util.List;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.springframework.context.annotation.Scope;
|
16
|
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
17
|
|
18
|
import com.vaadin.spring.annotation.SpringComponent;
|
19
|
|
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;
|
34
|
|
35
|
/**
|
36
|
* @author a.kohlbecker
|
37
|
* @since Dec 21, 2017
|
38
|
*
|
39
|
*/
|
40
|
@SpringComponent
|
41
|
@Scope("prototype")
|
42
|
public class InstitutionEditorPresenter extends AbstractCdmDTOEditorPresenter<InstitutionDTO, Institution, InstitutionPopupEditorView> {
|
43
|
|
44
|
private static final long serialVersionUID = -1996365248431425021L;
|
45
|
|
46
|
/**
|
47
|
* {@inheritDoc}
|
48
|
*/
|
49
|
@Override
|
50
|
protected Institution loadCdmEntity(UUID identifier) {
|
51
|
|
52
|
List<String> initStrategy = Arrays.asList(new String []{
|
53
|
|
54
|
"$",
|
55
|
"contact.$",
|
56
|
"isPartOf.$",
|
57
|
}
|
58
|
);
|
59
|
|
60
|
Institution bean;
|
61
|
if(identifier != null){
|
62
|
bean = (Institution) getRepo().getAgentService().load(identifier, initStrategy);
|
63
|
} else {
|
64
|
bean = cdmEntityInstantiator.createNewBean();
|
65
|
}
|
66
|
return bean;
|
67
|
}
|
68
|
|
69
|
/**
|
70
|
* {@inheritDoc}
|
71
|
*/
|
72
|
@Override
|
73
|
protected void guaranteePerEntityCRUDPermissions(UUID identifier) {
|
74
|
if(crud != null){
|
75
|
newAuthorityCreated = UserHelperAccess.userHelper().createAuthorityForCurrentUser(Collection.class, identifier, crud, null);
|
76
|
}
|
77
|
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* {@inheritDoc}
|
82
|
*/
|
83
|
@Override
|
84
|
protected void guaranteePerEntityCRUDPermissions(Institution bean) {
|
85
|
if(crud != null){
|
86
|
newAuthorityCreated = UserHelperAccess.userHelper().createAuthorityForCurrentUser(bean, crud, null);
|
87
|
}
|
88
|
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* {@inheritDoc}
|
93
|
*/
|
94
|
@Override
|
95
|
protected IService<Institution> getService() {
|
96
|
// TODO Auto-generated method stub
|
97
|
return null;
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
* {@inheritDoc}
|
102
|
*/
|
103
|
@Override
|
104
|
public void handleViewEntered() {
|
105
|
super.handleViewEntered();
|
106
|
|
107
|
CdmFilterablePagingProvider<AgentBase, Institution> collectionPagingProvider = new CdmFilterablePagingProvider<AgentBase, Institution>(getRepo().getAgentService(), Institution.class);
|
108
|
getView().getPartOfCombobox().getSelect().loadFrom(collectionPagingProvider, collectionPagingProvider, collectionPagingProvider.getPageSize());
|
109
|
getView().getPartOfCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Institution>(getView().getPartOfCombobox(), this));
|
110
|
|
111
|
}
|
112
|
|
113
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
114
|
public void onInstitutionEditorActionAdd(InstitutionEditorAction event) {
|
115
|
|
116
|
if(!checkFromOwnView(event)){
|
117
|
return;
|
118
|
}
|
119
|
|
120
|
InstitutionPopupEditor intitutionPopuEditor = openPopupEditor(InstitutionPopupEditor.class, event);
|
121
|
|
122
|
intitutionPopuEditor.grantToCurrentUser(this.crud);
|
123
|
intitutionPopuEditor.withDeleteButton(true);
|
124
|
intitutionPopuEditor.loadInEditor(null);
|
125
|
}
|
126
|
|
127
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
128
|
public void onCollectionEditorActionEdit(InstitutionEditorAction event) {
|
129
|
|
130
|
if(!checkFromOwnView(event)){
|
131
|
return;
|
132
|
}
|
133
|
|
134
|
InstitutionPopupEditor intitutionPopuEditor = openPopupEditor(InstitutionPopupEditor.class, event);
|
135
|
|
136
|
intitutionPopuEditor.grantToCurrentUser(this.crud);
|
137
|
intitutionPopuEditor.withDeleteButton(true);
|
138
|
intitutionPopuEditor.loadInEditor(event.getEntityUuid());
|
139
|
}
|
140
|
|
141
|
@EventBusListenerMethod()
|
142
|
public void onEntityChangeEvent(EntityChangeEvent<?> event){
|
143
|
|
144
|
BoundField boundTargetField = boundTargetField((PopupView) event.getSourceView());
|
145
|
|
146
|
if(boundTargetField != null){
|
147
|
if(boundTargetField.matchesPropertyIdPath("isPartOf")){
|
148
|
if(event.isCreateOrModifiedType()){
|
149
|
|
150
|
Institution newInstitution = (Institution) event.getEntity();
|
151
|
getCache().load(newInstitution);
|
152
|
if(event.isCreatedType()){
|
153
|
getView().getPartOfCombobox().setValue(newInstitution);
|
154
|
} else {
|
155
|
getView().getPartOfCombobox().reload();
|
156
|
}
|
157
|
}
|
158
|
|
159
|
}
|
160
|
}
|
161
|
}
|
162
|
|
163
|
/**
|
164
|
* {@inheritDoc}
|
165
|
*/
|
166
|
@Override
|
167
|
protected InstitutionDTO createDTODecorator(Institution cdmEntitiy) {
|
168
|
return new InstitutionDTO(cdmEntitiy);
|
169
|
}
|
170
|
|
171
|
|
172
|
|
173
|
}
|