1 package eu
.etaxonomy
.vaadin
.mvp
;
3 import javax
.annotation
.PostConstruct
;
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
;
12 import com
.vaadin
.ui
.CustomComponent
;
15 * AbstractView is the base class of all MVP views. It takes care of finding
16 * appropriate presenter component for the view.
20 * type of the presenter this view uses.
22 * @author Peter / Vaadin
25 public abstract class AbstractView
<P
extends AbstractPresenter
> extends CustomComponent
26 implements ApplicationContextAware
{
29 public static final Logger logger
= Logger
.getLogger(AbstractView
.class);
33 private ApplicationContext applicationContext
;
36 protected ApplicationEventPublisher eventBus
;
38 @SuppressWarnings("unchecked")
40 protected final void init() {
41 Logger
.getLogger(getClass().getSimpleName()).info("View init");
42 if(!ApplicationView
.class.isAssignableFrom(this.getClass())){
43 throw new RuntimeException("Any view bean must implement the ApplicationView interface: ViewBean ---> ViewInterface ---> ApplicationView");
48 presenter
.init((ApplicationView
<P
>) this);
53 protected void setPresenter(P presenter
) {
54 this.presenter
= presenter
;
58 protected final void injectPresenter(P presenter
){
59 logger
.trace(this.toString() + " injecting presenter " + presenter
.toString());
60 setPresenter(presenter
);
64 public void detach() {
65 getPresenter().onViewExit();
70 * Initialize the Components of the View
72 protected abstract void initContent();
75 * This method is called after the content of the view and the presenter
76 * are initialized and ready.
78 protected void onViewReady() {
79 logger
.trace("View ready");
82 protected P
getPresenter() {
87 public void setApplicationContext(ApplicationContext applicationContext
) throws BeansException
{
88 this.applicationContext
= applicationContext
;
91 public ApplicationEventPublisher
getEventBus(){