Project

General

Profile

Download (1.32 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.vaadin.ui.navigation;
2

    
3
import java.util.Collection;
4

    
5
import org.springframework.beans.factory.annotation.Autowired;
6
import org.springframework.context.ApplicationEventPublisher;
7
import org.springframework.context.annotation.Lazy;
8

    
9
import com.vaadin.navigator.View;
10
import com.vaadin.navigator.ViewChangeListener;
11
import com.vaadin.spring.annotation.SpringComponent;
12
import com.vaadin.spring.annotation.UIScope;
13

    
14
import eu.etaxonomy.vaadin.ui.NavigationManager;
15

    
16
@SpringComponent
17
@UIScope
18
class ViewChangeListenerBean implements ViewChangeListener {
19
	private static final long serialVersionUID = 1913421359807383L;
20

    
21
	@Autowired(required=false)
22
	private Collection<ViewChangeAllowedVerifier> verifiers = null;
23

    
24
	@Autowired
25
	@Lazy
26
	private NavigationManager navigationManager;
27

    
28
	@Autowired
29
    ApplicationEventPublisher eventBus;
30

    
31
	@Override
32
	public boolean beforeViewChange(ViewChangeEvent event) {
33
		View currentView = navigationManager.getCurrentView();
34
		if (currentView != null && verifiers != null) {
35
			for (ViewChangeAllowedVerifier verifier : verifiers) {
36
				if (currentView.equals(verifier)) {
37
					if (!verifier.isViewChangeAllowed()) {
38
						return false;
39
					}
40
				}
41
			}
42
		}
43
		return true;
44
	}
45

    
46
	@Override
47
	public void afterViewChange(ViewChangeEvent event) {
48
	    eventBus.publishEvent(new AfterViewChangeEvent());
49
	}
50

    
51
}
(6-6/6)