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.occurrence;
|
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.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;
|
39
|
|
40
|
/**
|
41
|
* @author a.kohlbecker
|
42
|
* @since Dec 21, 2017
|
43
|
*
|
44
|
*/
|
45
|
@SpringComponent
|
46
|
@Scope("prototype")
|
47
|
public class CollectionEditorPresenter extends AbstractCdmEditorPresenter<Collection, CollectionPopupEditorView> {
|
48
|
|
49
|
private static final long serialVersionUID = -1996365248431425021L;
|
50
|
|
51
|
protected static BeanInstantiator<Collection> defaultBeanInstantiator = new BeanInstantiator<Collection>() {
|
52
|
|
53
|
@Override
|
54
|
public Collection createNewBean() {
|
55
|
return Collection.NewInstance();
|
56
|
}
|
57
|
};
|
58
|
|
59
|
|
60
|
@Override
|
61
|
protected BeanInstantiator<Collection> defaultBeanInstantiator(){
|
62
|
return defaultBeanInstantiator;
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* {@inheritDoc}
|
67
|
*/
|
68
|
@Override
|
69
|
protected Collection loadCdmEntity(UUID identifier) {
|
70
|
|
71
|
List<String> initStrategy = Arrays.asList(new String []{
|
72
|
|
73
|
"$",
|
74
|
"institute.$",
|
75
|
"superCollection.$",
|
76
|
}
|
77
|
);
|
78
|
|
79
|
Collection bean;
|
80
|
if(identifier != null){
|
81
|
bean = getRepo().getCollectionService().load(identifier, initStrategy);
|
82
|
} else {
|
83
|
bean = createNewBean();
|
84
|
}
|
85
|
return bean;
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* {@inheritDoc}
|
90
|
*/
|
91
|
@Override
|
92
|
protected void guaranteePerEntityCRUDPermissions(UUID identifier) {
|
93
|
if(crud != null){
|
94
|
newAuthorityCreated = UserHelperAccess.userHelper().createAuthorityForCurrentUser(Collection.class, identifier, crud, null);
|
95
|
}
|
96
|
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* {@inheritDoc}
|
101
|
*/
|
102
|
@Override
|
103
|
protected void guaranteePerEntityCRUDPermissions(Collection bean) {
|
104
|
if(crud != null){
|
105
|
newAuthorityCreated = UserHelperAccess.userHelper().createAuthorityForCurrentUser(bean, crud, null);
|
106
|
}
|
107
|
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* {@inheritDoc}
|
112
|
*/
|
113
|
@Override
|
114
|
protected IService<Collection> getService() {
|
115
|
// TODO Auto-generated method stub
|
116
|
return null;
|
117
|
}
|
118
|
|
119
|
/**
|
120
|
* {@inheritDoc}
|
121
|
*/
|
122
|
@Override
|
123
|
public void handleViewEntered() {
|
124
|
super.handleViewEntered();
|
125
|
|
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));
|
130
|
|
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));
|
134
|
}
|
135
|
|
136
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
137
|
public void onCollectionEditorActionAdd(CollectionEditorAction event) {
|
138
|
|
139
|
if(!checkFromOwnView(event)){
|
140
|
return;
|
141
|
}
|
142
|
|
143
|
CollectionPopupEditor collectionPopuEditor = openPopupEditor(CollectionPopupEditor.class, event);
|
144
|
|
145
|
collectionPopuEditor.grantToCurrentUser(this.crud);
|
146
|
collectionPopuEditor.withDeleteButton(true);
|
147
|
collectionPopuEditor.loadInEditor(null);
|
148
|
}
|
149
|
|
150
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
151
|
public void onCollectionEditorActionEdit(CollectionEditorAction event) {
|
152
|
|
153
|
if(!checkFromOwnView(event)){
|
154
|
return;
|
155
|
}
|
156
|
|
157
|
CollectionPopupEditor collectionPopuEditor = openPopupEditor(CollectionPopupEditor.class, event);
|
158
|
|
159
|
collectionPopuEditor.grantToCurrentUser(this.crud);
|
160
|
collectionPopuEditor.withDeleteButton(true);
|
161
|
collectionPopuEditor.loadInEditor(event.getEntityUuid());
|
162
|
}
|
163
|
|
164
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
165
|
public void onInstitutionEditorActionEdit(InstitutionEditorAction event) {
|
166
|
|
167
|
if(!checkFromOwnView(event)){
|
168
|
return;
|
169
|
}
|
170
|
|
171
|
InstitutionPopupEditor institutionPopuEditor = openPopupEditor(InstitutionPopupEditor.class, event);
|
172
|
|
173
|
institutionPopuEditor.grantToCurrentUser(this.crud);
|
174
|
institutionPopuEditor.withDeleteButton(true);
|
175
|
institutionPopuEditor.loadInEditor(event.getEntityUuid());
|
176
|
}
|
177
|
|
178
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
179
|
public void onInstitutionEditorActionAdd(InstitutionEditorAction event) {
|
180
|
|
181
|
if(!checkFromOwnView(event)){
|
182
|
return;
|
183
|
}
|
184
|
|
185
|
InstitutionPopupEditor institutionPopuEditor = openPopupEditor(InstitutionPopupEditor.class, event);
|
186
|
|
187
|
institutionPopuEditor.grantToCurrentUser(this.crud);
|
188
|
institutionPopuEditor.withDeleteButton(true);
|
189
|
institutionPopuEditor.loadInEditor(null);
|
190
|
}
|
191
|
|
192
|
@EventBusListenerMethod()
|
193
|
public void onEntityChangeEvent(EntityChangeEvent<?> event){
|
194
|
|
195
|
BoundField boundTargetField = boundTargetField((PopupView) event.getSourceView());
|
196
|
|
197
|
if(boundTargetField != null){
|
198
|
if(boundTargetField.matchesPropertyIdPath("superCollection")){
|
199
|
if(event.isCreateOrModifiedType()){
|
200
|
|
201
|
Collection newCollection = (Collection) event.getEntity();
|
202
|
getCache().load(newCollection);
|
203
|
if(event.isCreatedType()){
|
204
|
getView().getSuperCollectionCombobox().setValue(newCollection);
|
205
|
} else {
|
206
|
getView().getSuperCollectionCombobox().reload();
|
207
|
}
|
208
|
}
|
209
|
|
210
|
} else if(boundTargetField.matchesPropertyIdPath("institute")){
|
211
|
if(event.isCreateOrModifiedType()){
|
212
|
|
213
|
Institution newInstitution = (Institution) event.getEntity();
|
214
|
getCache().load(newInstitution);
|
215
|
if(event.isCreatedType()){
|
216
|
getView().getInstitutionCombobox().setValue(newInstitution);
|
217
|
} else {
|
218
|
getView().getInstitutionCombobox().reload();
|
219
|
}
|
220
|
}
|
221
|
|
222
|
}
|
223
|
}
|
224
|
}
|
225
|
|
226
|
|
227
|
|
228
|
}
|