Project

General

Profile

Download (2.29 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.vaadin.mvp;
2

    
3
import java.io.Serializable;
4

    
5
import org.apache.log4j.Logger;
6
import org.springframework.beans.factory.annotation.Autowired;
7
import org.springframework.beans.factory.annotation.Qualifier;
8

    
9
import com.vaadin.spring.annotation.SpringComponent;
10
import com.vaadin.spring.annotation.ViewScope;
11

    
12
import eu.etaxonomy.cdm.api.application.CdmRepository;
13
import eu.etaxonomy.vaadin.ui.navigation.NavigationManager;
14

    
15
/**
16
 * AbstractPresenter is the base class of all presenter components. Presenter's
17
 * role is to govern the view and control the complex UI logic based on
18
 * notifications presenter receives from its view.
19
 *
20
 * @author Peter / Vaadin
21
 *
22
 * @param <V>
23
 *            type of the view this presenter governs
24
 */
25
@SpringComponent
26
@ViewScope
27
public abstract class AbstractPresenter<V extends ApplicationView> implements Serializable {
28

    
29

    
30
    private static final long serialVersionUID = 5260910510283481832L;
31

    
32
    public static final Logger logger = Logger.getLogger(AbstractPresenter.class);
33

    
34
	private V view;
35

    
36

    
37
	protected V getView() {
38
	    if(view == null){
39
            Logger.getLogger(this.getClass()).warn("CDM-VAADIN#6562: presenter " + toString() + " without view.");
40
        }
41
		return view;
42
	}
43

    
44
	@Autowired
45
	@Qualifier("cdmRepository")
46
	private CdmRepository repo;
47

    
48
	@Autowired
49
	private NavigationManager navigationManager;
50

    
51
	/**
52
	 * @return the repo
53
	 */
54
	public CdmRepository getRepo() {
55
	    return repo;
56
	}
57

    
58
	/**
59
	 * Notifies the presenter that its view is initialized so that presenter can
60
	 * start its own initialization if required.
61
	 *
62
	 * @param view
63
	 */
64
	protected final void init(V view) {
65
	    logger.trace("Presenter init");
66
		this.view = view;
67
		onPresenterReady();
68
	}
69

    
70
	/**
71
	 * Extending classes should overwrite this method in order to perform logic
72
	 * after presenter has finished initializing.
73
	 */
74
	protected void onPresenterReady() {
75
	    logger.trace("Presenter ready");
76
	}
77

    
78
	/**
79
	 * Extending classes should overwrite this method to react to the event when
80
	 * user has navigated into the view that this presenter governs.
81
	 */
82
	public void onViewEnter() {
83
	    logger.trace("View entered");
84
	}
85

    
86
	public void onViewExit() {
87

    
88
	}
89

    
90
    /**
91
     * @return the navigationManager
92
     */
93
    public NavigationManager getNavigationManager() {
94
        return navigationManager;
95
    }
96

    
97
}
(4-4/7)