1
|
package eu.etaxonomy.vaadin.mvp;
|
2
|
|
3
|
import java.util.logging.Logger;
|
4
|
|
5
|
import javax.annotation.PostConstruct;
|
6
|
|
7
|
import org.springframework.beans.BeansException;
|
8
|
import org.springframework.context.ApplicationContext;
|
9
|
import org.springframework.context.ApplicationContextAware;
|
10
|
|
11
|
import com.vaadin.ui.CustomComponent;
|
12
|
|
13
|
/**
|
14
|
* AbstractView is the base class of all MVP views. It takes care of finding
|
15
|
* appropriate presenter component for the view.
|
16
|
*
|
17
|
* @param
|
18
|
* <P>
|
19
|
* type of the presenter this view uses.
|
20
|
*
|
21
|
* @author Peter / Vaadin
|
22
|
*/
|
23
|
public abstract class AbstractView<P extends AbstractPresenter> extends CustomComponent
|
24
|
implements ApplicationContextAware {
|
25
|
|
26
|
private P presenter;
|
27
|
|
28
|
private ApplicationContext applicationContext;
|
29
|
|
30
|
@PostConstruct
|
31
|
protected final void init() {
|
32
|
Logger.getLogger(getClass().getSimpleName()).info("View init");
|
33
|
presenter.init((ApplicationView) this);
|
34
|
|
35
|
onViewReady();
|
36
|
}
|
37
|
|
38
|
protected void setPresenter(P presenter) {
|
39
|
this.presenter = presenter;
|
40
|
}
|
41
|
|
42
|
protected abstract void injectPresenter(P presenter);
|
43
|
|
44
|
@Override
|
45
|
public void detach() {
|
46
|
getPresenter().onViewExit();
|
47
|
super.detach();
|
48
|
}
|
49
|
|
50
|
protected void onViewReady() {
|
51
|
Logger.getLogger(getClass().getSimpleName()).info("View ready");
|
52
|
}
|
53
|
|
54
|
protected P getPresenter() {
|
55
|
return presenter;
|
56
|
}
|
57
|
|
58
|
@Override
|
59
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
60
|
this.applicationContext = applicationContext;
|
61
|
}
|
62
|
}
|