Project

General

Profile

Download (2.08 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
    public static final Logger logger = Logger.getLogger(AbstractPresenter.class);
30

    
31
	private V view;
32

    
33

    
34
	protected V getView() {
35
		return view;
36
	}
37

    
38
	@Autowired
39
	@Qualifier("cdmRepository")
40
	private CdmRepository repo;
41

    
42
	@Autowired
43
	private NavigationManager navigationManager;
44

    
45
	/**
46
	 * @return the repo
47
	 */
48
	public CdmRepository getRepo() {
49
	    return repo;
50
	}
51

    
52
	/**
53
	 * Notifies the presenter that its view is initialized so that presenter can
54
	 * start its own initialization if required.
55
	 *
56
	 * @param view
57
	 */
58
	protected final void init(V view) {
59
	    logger.trace("Presenter init");
60
		this.view = view;
61
		onPresenterReady();
62
	}
63

    
64
	/**
65
	 * Extending classes should overwrite this method in order to perform logic
66
	 * after presenter has finished initializing.
67
	 */
68
	protected void onPresenterReady() {
69
	    logger.trace("Presenter ready");
70
	}
71

    
72
	/**
73
	 * Extending classes should overwrite this method to react to the event when
74
	 * user has navigated into the view that this presenter governs.
75
	 */
76
	public void onViewEnter() {
77
	    logger.trace("View entered");
78
	}
79

    
80
	public void onViewExit() {
81

    
82
	}
83

    
84
    /**
85
     * @return the navigationManager
86
     */
87
    public NavigationManager getNavigationManager() {
88
        return navigationManager;
89
    }
90

    
91
}
(4-4/7)