Project

General

Profile

Download (4.99 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

    
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.ToOneRelatedEntityReloader;
25
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
26
import eu.etaxonomy.vaadin.mvp.AbstractCdmEditorPresenter;
27
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent;
28
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent.Reason;
29

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

    
39
    private static final long serialVersionUID = -1996365248431425021L;
40
    private CollectionPopupEditor collectionPopuEditor;
41

    
42

    
43
    /**
44
     * {@inheritDoc}
45
     */
46
    @Override
47
    protected Collection loadCdmEntityById(Integer identifier) {
48

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

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

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

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

    
75
    }
76

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

    
86
    }
87

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

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

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

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

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

    
116
        collectionPopuEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class);
117

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

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

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

    
130
        collectionPopuEditor = getNavigationManager().showInPopup(CollectionPopupEditor.class);
131

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

    
137
    @EventBusListenerMethod()
138
    public void onDoneWithPopupEvent(DoneWithPopupEvent event){
139
        if(event.getPopup() == collectionPopuEditor){
140
            if(event.getReason() == Reason.SAVE){
141

    
142
                Collection newCollection = collectionPopuEditor.getBean();
143

    
144
                // TODO the bean contained in the popup editor is not yet updated at this point.
145
                //      so re reload it using the uuid since new beans will not have an Id at this point.
146
                newCollection = getRepo().getCollectionService().find(newCollection.getUuid());
147
                getView().getSuperCollectionCombobox().getSelect().setValue(newCollection);
148
            }
149

    
150
            collectionPopuEditor = null;
151
        }
152
    }
153

    
154

    
155

    
156
}
(1-1/3)