Project

General

Profile

Download (1.32 KB) Statistics
| Branch: | Tag: | Revision:
1
package com.vaadin.devday.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.devday.ui.NavigationManager;
10
import com.vaadin.navigator.View;
11
import com.vaadin.navigator.ViewChangeListener;
12
import com.vaadin.spring.annotation.SpringComponent;
13
import com.vaadin.spring.annotation.UIScope;
14

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

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

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

    
27
	@Autowired
28
    ApplicationEventPublisher eventBus;
29

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

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

    
50
}
(6-6/6)