package com.nrusev.web.ui.mvp;

import com.google.common.eventbus.EventBus;
import com.vaadin.navigator.Navigator;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.ui.UI;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@SuppressWarnings("serial")
public abstract class MvpPresenter<T extends MvpView> implements View {
	
	private final T view;

	private final EventBus eventBus;

	public MvpPresenter(final T view, final EventBus eventBus) {
		this.view = view;
		this.eventBus = eventBus;
		this.eventBus.register(this);
	}
	
	public T getView() {
		return view;
	}

	public EventBus getEventBus(){
		return eventBus;
	}

	@PostConstruct
	private void init(){
	}

	@PreDestroy
	private void preDestroy(){
		this.eventBus.unregister(this);
		System.out.println("pre destroy on abstract class...");
	}

	@Override
	public void enter(ViewChangeListener.ViewChangeEvent viewChangeEvent) {
		if(viewChangeEvent.getNewView().equals(viewChangeEvent.getOldView())){
			this.getEventBus().unregister(viewChangeEvent.getOldView());
		}
	}
}

@@ -214,16 +214,79 @@
 n.ui.UI;
+%0Aimport org.springframework.beans.factory.annotation.Autowired;
 %0A%0Aimport
@@ -582,28 +582,8 @@
 ) %7B%0A
-%09%09this.view = view;%0A
 %09%09th
@@ -617,31 +617,19 @@
 his.
-eventBus.register(this)
+view = view
 ;%0A%09%7D
@@ -765,16 +765,48 @@
 init()%7B%0A
+%09%09this.eventBus.register(this);%0A
 %09%7D%0A%0A%09@Pr

revert previous