Project

General

Profile

Download (2.56 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.vaadin.mvp;
10

    
11
import org.hibernate.FlushMode;
12
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
13

    
14
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction;
15
import eu.etaxonomy.vaadin.mvp.event.EditorDeleteEvent;
16
import eu.etaxonomy.vaadin.mvp.event.EditorPreSaveEvent;
17
import eu.etaxonomy.vaadin.mvp.event.EditorSaveEvent;
18
import eu.etaxonomy.vaadin.mvp.event.EditorViewEvent;
19

    
20
/**
21
 *
22
 * @author a.kohlbecker
23
 * @since Apr 5, 2017
24
 *
25
 */
26
public abstract class AbstractEditorPresenter<DTO extends Object, V extends ApplicationView<?>> extends AbstractPresenter<V> {
27

    
28

    
29
    private static final long serialVersionUID = -6677074110764145236L;
30

    
31
    FlushMode previousPreSaveEvenFlushMode = null;
32

    
33
    protected BeanInstantiator<DTO> beanInstantiator = null;
34

    
35
    /**
36
     * Load the bean to be edited in the editor freshly from the persistent storage.
37
     * Ore create an new empty instance in case the supplied <code>identifier</code> is <code>null</code>.
38
     *
39
     * @param identifier
40
     * @return
41
     */
42
    protected abstract DTO loadBeanById(Object identifier);
43

    
44
    /**
45
     * @param beanInstantiator the beanInstantiator to set
46
     */
47
    public void setBeanInstantiator(BeanInstantiator<DTO> beanInstantiator) {
48
        this.beanInstantiator = beanInstantiator;
49
    }
50

    
51
    @EventBusListenerMethod
52
    public void onEditorPreSaveEvent(EditorPreSaveEvent<DTO> preSaveEvent){
53
    }
54

    
55
    @EventBusListenerMethod
56
    public void onEditorSaveEvent(EditorSaveEvent<DTO> saveEvent){
57

    
58
        DTO bean = saveEvent.getBean();
59
        saveBean(bean);
60
    }
61

    
62
   /**
63
    * @param saveEvent
64
    */
65
   @EventBusListenerMethod
66
   public void onEditorDeleteEvent(EditorDeleteEvent<DTO> deleteEvent){
67

    
68
       deleteBean(deleteEvent.getBean());
69
   }
70

    
71
    /**
72
     * @param saveEvent
73
     * @return
74
     */
75
    protected boolean isFromOwnView(EditorViewEvent saveEvent) {
76
        return saveEvent.getView().equals(getView());
77
    }
78

    
79
    protected Class<V> getViewType() {
80
        return (Class<V>) super.getView().getClass();
81
    }
82

    
83
    protected boolean isFromOwnView(AbstractEditorAction action){
84
        return action.getSourceView() != null && getView().equals(action.getSourceView());
85
    }
86

    
87

    
88
    protected abstract void saveBean(DTO bean);
89

    
90
    /**
91
     * @param bean
92
     */
93
    protected abstract void deleteBean(DTO bean);
94

    
95
}
(3-3/9)