Project

General

Profile

Download (5.07 KB) Statistics
| Branch: | Tag: | Revision:
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.occurrence.Collection;
22
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
23
import eu.etaxonomy.cdm.vaadin.event.CollectionEditorAction;
24
import eu.etaxonomy.cdm.vaadin.event.EditorActionTypeFilter;
25
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
26
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader;
27
import eu.etaxonomy.cdm.vaadin.permission.VaadinUserHelper;
28
import eu.etaxonomy.vaadin.mvp.AbstractCdmEditorPresenter;
29
import eu.etaxonomy.vaadin.mvp.BoundField;
30
import eu.etaxonomy.vaadin.ui.view.PopupView;
31

    
32
/**
33
 * @author a.kohlbecker
34
 * @since Dec 21, 2017
35
 *
36
 */
37
@SpringComponent
38
@Scope("prototype")
39
public class CollectionEditorPresenter extends AbstractCdmEditorPresenter<Collection, CollectionPopupEditorView> {
40

    
41
    private static final long serialVersionUID = -1996365248431425021L;
42

    
43

    
44
    /**
45
     * {@inheritDoc}
46
     */
47
    @Override
48
    protected Collection loadCdmEntity(UUID identifier) {
49

    
50
        List<String> initStrategy = Arrays.asList(new String []{
51

    
52
                "$",
53
                "institute.$",
54
                "superCollection.$",
55
                }
56
        );
57

    
58
        Collection bean;
59
        if(identifier != null){
60
            bean = getRepo().getCollectionService().load(identifier, initStrategy);
61
        } else {
62
            bean = Collection.NewInstance();
63
        }
64
        return bean;
65
    }
66

    
67
    /**
68
     * {@inheritDoc}
69
     */
70
    @Override
71
    protected void guaranteePerEntityCRUDPermissions(UUID identifier) {
72
        if(crud != null){
73
            newAuthorityCreated = VaadinUserHelper.fromSession().createAuthorityForCurrentUser(Collection.class, identifier, crud, null);
74
        }
75

    
76
    }
77

    
78
    /**
79
     * {@inheritDoc}
80
     */
81
    @Override
82
    protected void guaranteePerEntityCRUDPermissions(Collection bean) {
83
        if(crud != null){
84
            newAuthorityCreated = VaadinUserHelper.fromSession().createAuthorityForCurrentUser(bean, crud, null);
85
        }
86

    
87
    }
88

    
89
    /**
90
     * {@inheritDoc}
91
     */
92
    @Override
93
    protected IService<Collection> getService() {
94
        // TODO Auto-generated method stub
95
        return null;
96
    }
97

    
98
    /**
99
     * {@inheritDoc}
100
     */
101
    @Override
102
    public void handleViewEntered() {
103
        super.handleViewEntered();
104

    
105
        CdmFilterablePagingProvider<Collection, Collection> collectionPagingProvider = new CdmFilterablePagingProvider<Collection, Collection>(getRepo().getCollectionService());
106
        getView().getSuperCollectionCombobox().getSelect().loadFrom(collectionPagingProvider, collectionPagingProvider, collectionPagingProvider.getPageSize());
107
        getView().getSuperCollectionCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Collection>(getView().getSuperCollectionCombobox(),this));
108
    }
109

    
110
    @EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
111
    public void onCollectionEditorActionAdd(CollectionEditorAction event) {
112

    
113
        if(!checkFromOwnView(event)){
114
            return;
115
        }
116

    
117
        CollectionPopupEditor collectionPopuEditor = openPopupEditor(CollectionPopupEditor.class, event);
118

    
119
        collectionPopuEditor.grantToCurrentUser(this.crud);
120
        collectionPopuEditor.withDeleteButton(true);
121
        collectionPopuEditor.loadInEditor(null);
122
    }
123

    
124
    @EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
125
    public void onCollectionEditorActionEdit(CollectionEditorAction event) {
126

    
127
        if(!checkFromOwnView(event)){
128
            return;
129
        }
130

    
131
        CollectionPopupEditor collectionPopuEditor = openPopupEditor(CollectionPopupEditor.class, event);
132

    
133
        collectionPopuEditor.grantToCurrentUser(this.crud);
134
        collectionPopuEditor.withDeleteButton(true);
135
        collectionPopuEditor.loadInEditor(event.getEntityUuid());
136
    }
137

    
138
    @EventBusListenerMethod()
139
    public void onEntityChangeEvent(EntityChangeEvent<?> event){
140

    
141
        BoundField boundTargetField = boundTargetField((PopupView) event.getSourceView());
142

    
143
        if(boundTargetField != null){
144
            if(boundTargetField.matchesPropertyIdPath("superCollection")){
145
                if(event.isCreateOrModifiedType()){
146

    
147
                    Collection newCollection = (Collection) event.getEntity();
148
                    getCache().load(newCollection);
149
                    if(event.isCreatedType()){
150
                        getView().getSuperCollectionCombobox().setValue(newCollection);
151
                    } else {
152
                        getView().getSuperCollectionCombobox().reload();
153
                    }
154
                }
155

    
156
            }
157
        }
158
    }
159

    
160

    
161

    
162
}
(1-1/3)