Project

General

Profile

Download (1.61 KB) Statistics
| Branch: | Tag: | Revision:
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.beans.factory.annotation.Autowired;
9
import org.springframework.context.ApplicationContext;
10
import org.springframework.context.ApplicationContextAware;
11
import org.springframework.context.ApplicationEventPublisher;
12

    
13
import com.vaadin.ui.CustomComponent;
14

    
15
/**
16
 * AbstractView is the base class of all MVP views. It takes care of finding
17
 * appropriate presenter component for the view.
18
 *
19
 * @param
20
 * 			<P>
21
 *            type of the presenter this view uses.
22
 *
23
 * @author Peter / Vaadin
24
 */
25
public abstract class AbstractView<P extends AbstractPresenter> extends CustomComponent
26
		implements ApplicationContextAware {
27

    
28
	private P presenter;
29

    
30
	private ApplicationContext applicationContext;
31

    
32
    @Autowired
33
    ApplicationEventPublisher eventBus;
34

    
35
	@PostConstruct
36
	protected final void init() {
37
		Logger.getLogger(getClass().getSimpleName()).info("View init");
38
		presenter.init((ApplicationView) this);
39

    
40
		onViewReady();
41
	}
42

    
43
	protected void setPresenter(P presenter) {
44
		this.presenter = presenter;
45
	}
46

    
47
	protected abstract void injectPresenter(P presenter);
48

    
49
	@Override
50
	public void detach() {
51
		getPresenter().onViewExit();
52
		super.detach();
53
	}
54

    
55
	protected void onViewReady() {
56
		Logger.getLogger(getClass().getSimpleName()).info("View ready");
57
	}
58

    
59
	protected P getPresenter() {
60
		return presenter;
61
	}
62

    
63
	@Override
64
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
65
		this.applicationContext = applicationContext;
66
	}
67
}
(2-2/3)