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
|
|
14
|
import org.springframework.context.annotation.Scope;
|
15
|
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
16
|
|
17
|
import com.vaadin.spring.annotation.SpringComponent;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.service.IService;
|
20
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
21
|
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
|
22
|
import eu.etaxonomy.cdm.vaadin.event.CollectionEditorAction;
|
23
|
import eu.etaxonomy.cdm.vaadin.event.EditorActionTypeFilter;
|
24
|
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
|
25
|
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader;
|
26
|
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
|
27
|
import eu.etaxonomy.vaadin.mvp.AbstractCdmEditorPresenter;
|
28
|
|
29
|
/**
|
30
|
* @author a.kohlbecker
|
31
|
* @since Dec 21, 2017
|
32
|
*
|
33
|
*/
|
34
|
@SpringComponent
|
35
|
@Scope("prototype")
|
36
|
public class CollectionEditorPresenter extends AbstractCdmEditorPresenter<Collection, CollectionPopupEditorView> {
|
37
|
|
38
|
private static final long serialVersionUID = -1996365248431425021L;
|
39
|
private CollectionPopupEditor collectionPopuEditor;
|
40
|
|
41
|
|
42
|
/**
|
43
|
* {@inheritDoc}
|
44
|
*/
|
45
|
@Override
|
46
|
protected Collection loadCdmEntityById(Integer identifier) {
|
47
|
|
48
|
List<String> initStrategy = Arrays.asList(new String []{
|
49
|
|
50
|
"$",
|
51
|
"institute.$",
|
52
|
"superCollection.$",
|
53
|
}
|
54
|
);
|
55
|
|
56
|
Collection bean;
|
57
|
if(identifier != null){
|
58
|
bean = getRepo().getCollectionService().load(identifier, initStrategy);
|
59
|
} else {
|
60
|
bean = Collection.NewInstance();
|
61
|
}
|
62
|
return bean;
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* {@inheritDoc}
|
67
|
*/
|
68
|
@Override
|
69
|
protected void guaranteePerEntityCRUDPermissions(Integer identifier) {
|
70
|
if(crud != null){
|
71
|
newAuthorityCreated = UserHelper.fromSession().createAuthorityForCurrentUser(Collection.class, identifier, crud, null);
|
72
|
}
|
73
|
|
74
|
}
|
75
|
|
76
|
/**
|
77
|
* {@inheritDoc}
|
78
|
*/
|
79
|
@Override
|
80
|
protected void guaranteePerEntityCRUDPermissions(Collection bean) {
|
81
|
if(crud != null){
|
82
|
newAuthorityCreated = UserHelper.fromSession().createAuthorityForCurrentUser(bean, crud, null);
|
83
|
}
|
84
|
|
85
|
}
|
86
|
|
87
|
/**
|
88
|
* {@inheritDoc}
|
89
|
*/
|
90
|
@Override
|
91
|
protected IService<Collection> getService() {
|
92
|
// TODO Auto-generated method stub
|
93
|
return null;
|
94
|
}
|
95
|
|
96
|
/**
|
97
|
* {@inheritDoc}
|
98
|
*/
|
99
|
@Override
|
100
|
public void handleViewEntered() {
|
101
|
super.handleViewEntered();
|
102
|
|
103
|
CdmFilterablePagingProvider<Collection, Collection> collectionPagingProvider = new CdmFilterablePagingProvider<Collection, Collection>(getRepo().getCollectionService());
|
104
|
getView().getSuperCollectionCombobox().getSelect().loadFrom(collectionPagingProvider, collectionPagingProvider, collectionPagingProvider.getPageSize());
|
105
|
getView().getSuperCollectionCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Collection>(getView().getSuperCollectionCombobox(),this));
|
106
|
}
|
107
|
|
108
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
109
|
public void onCollectionEditorActionAdd(CollectionEditorAction event) {
|
110
|
|
111
|
if(!checkFromOwnView(event)){
|
112
|
return;
|
113
|
}
|
114
|
|
115
|
collectionPopuEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class, getView());
|
116
|
|
117
|
collectionPopuEditor.grantToCurrentUser(this.crud);
|
118
|
collectionPopuEditor.withDeleteButton(true);
|
119
|
collectionPopuEditor.loadInEditor(null);
|
120
|
}
|
121
|
|
122
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
123
|
public void onCollectionEditorActionEdit(CollectionEditorAction event) {
|
124
|
|
125
|
if(!checkFromOwnView(event)){
|
126
|
return;
|
127
|
}
|
128
|
|
129
|
collectionPopuEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class, getView());
|
130
|
|
131
|
collectionPopuEditor.grantToCurrentUser(this.crud);
|
132
|
collectionPopuEditor.withDeleteButton(true);
|
133
|
collectionPopuEditor.loadInEditor(event.getEntityId());
|
134
|
}
|
135
|
|
136
|
@EventBusListenerMethod()
|
137
|
public void onEntityChangeEvent(EntityChangeEvent<?> event){
|
138
|
if(event.getSourceView() == collectionPopuEditor){
|
139
|
if(event.isCreateOrModifiedType()){
|
140
|
|
141
|
Collection newCollection = (Collection) event.getEntity();
|
142
|
getCache().load(newCollection);
|
143
|
getView().getSuperCollectionCombobox().getSelect().setValue(newCollection);
|
144
|
}
|
145
|
|
146
|
collectionPopuEditor = null;
|
147
|
}
|
148
|
}
|
149
|
|
150
|
|
151
|
|
152
|
}
|