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
|
import org.springframework.transaction.TransactionStatus;
|
9
|
|
10
|
import com.vaadin.spring.annotation.SpringComponent;
|
11
|
import com.vaadin.spring.annotation.ViewScope;
|
12
|
|
13
|
import eu.etaxonomy.cdm.api.application.CdmRepository;
|
14
|
import eu.etaxonomy.vaadin.ui.navigation.NavigationManager;
|
15
|
|
16
|
/**
|
17
|
* AbstractPresenter is the base class of all presenter components. Presenter's
|
18
|
* role is to govern the view and control the complex UI logic based on
|
19
|
* notifications presenter receives from its view.
|
20
|
*
|
21
|
* @author Peter / Vaadin
|
22
|
*
|
23
|
* @param <V>
|
24
|
* type of the view this presenter governs
|
25
|
*/
|
26
|
@SpringComponent
|
27
|
@ViewScope
|
28
|
public abstract class AbstractPresenter<V extends ApplicationView> implements Serializable {
|
29
|
|
30
|
|
31
|
private static final long serialVersionUID = 5260910510283481832L;
|
32
|
|
33
|
public static final Logger logger = Logger.getLogger(AbstractPresenter.class);
|
34
|
|
35
|
private V view;
|
36
|
|
37
|
|
38
|
protected V getView() {
|
39
|
if(view == null){
|
40
|
Logger.getLogger(this.getClass()).warn("CDM-VAADIN#6562: presenter " + toString() + " without view.");
|
41
|
}
|
42
|
return view;
|
43
|
}
|
44
|
|
45
|
@Autowired
|
46
|
@Qualifier("cdmRepository")
|
47
|
private CdmRepository repo;
|
48
|
|
49
|
@Autowired
|
50
|
private NavigationManager navigationManager;
|
51
|
|
52
|
/**
|
53
|
* @return the repo
|
54
|
*/
|
55
|
public CdmRepository getRepo() {
|
56
|
return repo;
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
* Notifies the presenter that its view is initialized so that presenter can
|
61
|
* start its own initialization if required.
|
62
|
*
|
63
|
* @param view
|
64
|
*/
|
65
|
protected final void init(V view) {
|
66
|
logger.trace("Presenter init");
|
67
|
this.view = view;
|
68
|
onPresenterReady();
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Extending classes should overwrite this method in order to perform logic
|
73
|
* after presenter has finished initializing.
|
74
|
*/
|
75
|
protected void onPresenterReady() {
|
76
|
logger.trace("Presenter ready");
|
77
|
}
|
78
|
|
79
|
public final void onViewEnter() {
|
80
|
logger.trace("View entered");
|
81
|
TransactionStatus tx = getRepo().startTransaction();
|
82
|
handleViewEntered();
|
83
|
getRepo().commitTransaction(tx);
|
84
|
}
|
85
|
|
86
|
public final void onViewExit() {
|
87
|
handleViewExit();
|
88
|
}
|
89
|
|
90
|
/**
|
91
|
* Extending classes should overwrite this method to react to the event when
|
92
|
* user has navigated into the view that this presenter governs.
|
93
|
*/
|
94
|
public void handleViewEntered() {
|
95
|
}
|
96
|
|
97
|
/**
|
98
|
* Extending classes may overwrite this method to react to
|
99
|
* the event when user leaves the view that this presenter
|
100
|
* governs.
|
101
|
*/
|
102
|
public void handleViewExit() {
|
103
|
}
|
104
|
|
105
|
/**
|
106
|
* @return the navigationManager
|
107
|
*/
|
108
|
public NavigationManager getNavigationManager() {
|
109
|
return navigationManager;
|
110
|
}
|
111
|
|
112
|
}
|