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