1
|
package eu.etaxonomy.vaadin.mvp;
|
2
|
|
3
|
import org.apache.log4j.Logger;
|
4
|
import org.springframework.beans.factory.annotation.Autowired;
|
5
|
import org.springframework.beans.factory.annotation.Qualifier;
|
6
|
|
7
|
import com.vaadin.spring.annotation.SpringComponent;
|
8
|
import com.vaadin.spring.annotation.ViewScope;
|
9
|
|
10
|
import eu.etaxonomy.cdm.api.application.CdmRepository;
|
11
|
import eu.etaxonomy.vaadin.ui.navigation.NavigationManager;
|
12
|
|
13
|
/**
|
14
|
* AbstractPresenter is the base class of all presenter components. Presenter's
|
15
|
* role is to govern the view and control the complex UI logic based on
|
16
|
* notifications presenter receives from its view.
|
17
|
*
|
18
|
* @author Peter / Vaadin
|
19
|
*
|
20
|
* @param <V>
|
21
|
* type of the view this presenter governs
|
22
|
*/
|
23
|
@SpringComponent
|
24
|
@ViewScope
|
25
|
public abstract class AbstractPresenter<V extends ApplicationView> {
|
26
|
|
27
|
public static final Logger logger = Logger.getLogger(AbstractPresenter.class);
|
28
|
|
29
|
private V view;
|
30
|
|
31
|
|
32
|
protected V getView() {
|
33
|
return view;
|
34
|
}
|
35
|
|
36
|
@Autowired
|
37
|
@Qualifier("cdmRepository")
|
38
|
private CdmRepository repo;
|
39
|
|
40
|
@Autowired
|
41
|
private NavigationManager navigationManager;
|
42
|
|
43
|
/**
|
44
|
* @return the repo
|
45
|
*/
|
46
|
public CdmRepository getRepo() {
|
47
|
return repo;
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* Notifies the presenter that its view is initialized so that presenter can
|
52
|
* start its own initialization if required.
|
53
|
*
|
54
|
* @param view
|
55
|
*/
|
56
|
protected final void init(V view) {
|
57
|
logger.trace("Presenter init");
|
58
|
this.view = view;
|
59
|
onPresenterReady();
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* Extending classes should overwrite this method in order to perform logic
|
64
|
* after presenter has finished initializing.
|
65
|
*/
|
66
|
protected void onPresenterReady() {
|
67
|
logger.trace("Presenter ready");
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* Extending classes should overwrite this method to react to the event when
|
72
|
* user has navigated into the view that this presenter governs.
|
73
|
*/
|
74
|
public void onViewEnter() {
|
75
|
logger.trace("View entered");
|
76
|
}
|
77
|
|
78
|
public void onViewExit() {
|
79
|
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* @return the navigationManager
|
84
|
*/
|
85
|
public NavigationManager getNavigationManager() {
|
86
|
return navigationManager;
|
87
|
}
|
88
|
|
89
|
}
|