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.annotation.Lazy;
|
7
|
import org.vaadin.spring.events.EventBus.UIEventBus;
|
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
|
@SpringComponent("viewChangeListenerBean")
|
15
|
@UIScope
|
16
|
class ViewChangeListenerBean implements ViewChangeListener {
|
17
|
private static final long serialVersionUID = 1913421359807383L;
|
18
|
|
19
|
@Autowired(required=false)
|
20
|
private Collection<ViewChangeAllowedVerifier> verifiers = null;
|
21
|
|
22
|
@Autowired
|
23
|
@Lazy
|
24
|
private NavigationManager navigationManager;
|
25
|
|
26
|
@Autowired
|
27
|
UIEventBus uiEventBus;
|
28
|
|
29
|
@Override
|
30
|
public boolean beforeViewChange(ViewChangeEvent event) {
|
31
|
View currentView = navigationManager.getCurrentView();
|
32
|
if (currentView != null && verifiers != null) {
|
33
|
for (ViewChangeAllowedVerifier verifier : verifiers) {
|
34
|
if (currentView.equals(verifier)) {
|
35
|
if (!verifier.isViewChangeAllowed()) {
|
36
|
return false;
|
37
|
}
|
38
|
}
|
39
|
}
|
40
|
}
|
41
|
return true;
|
42
|
}
|
43
|
|
44
|
@Override
|
45
|
public void afterViewChange(ViewChangeEvent event) {
|
46
|
uiEventBus.publish(this, new AfterViewChangeEvent());
|
47
|
}
|
48
|
|
49
|
}
|