1
|
package eu.etaxonomy.vaadin.ui.navigation;
|
2
|
|
3
|
import org.springframework.beans.factory.annotation.Autowired;
|
4
|
import org.vaadin.dialogs.ConfirmDialog;
|
5
|
import org.vaadin.spring.events.EventBus.UIEventBus;
|
6
|
|
7
|
import com.vaadin.navigator.Navigator.UriFragmentManager;
|
8
|
import com.vaadin.server.Page;
|
9
|
import com.vaadin.server.Page.UriFragmentChangedEvent;
|
10
|
import com.vaadin.spring.annotation.SpringComponent;
|
11
|
import com.vaadin.spring.annotation.UIScope;
|
12
|
import com.vaadin.ui.UI;
|
13
|
import com.vaadin.ui.Window;
|
14
|
|
15
|
@SpringComponent
|
16
|
@UIScope
|
17
|
public class NavigationUriFragmentManager extends UriFragmentManager {
|
18
|
|
19
|
private static final long serialVersionUID = -2033745435437337863L;
|
20
|
|
21
|
@Autowired
|
22
|
UIEventBus uiEventBus;
|
23
|
|
24
|
public NavigationUriFragmentManager() {
|
25
|
super(Page.getCurrent());
|
26
|
}
|
27
|
|
28
|
@Override
|
29
|
public void uriFragmentChanged(UriFragmentChangedEvent event) {
|
30
|
|
31
|
if(!isModalWindowShown()){
|
32
|
uiEventBus.publish(this, new NavigationEvent(getState()));
|
33
|
} else {
|
34
|
ConfirmDialog confirm = ConfirmDialog.getFactory().create(
|
35
|
"Notification",
|
36
|
"You can't leave this page as long as modal popup editors are open.",
|
37
|
"Ok", null, null);
|
38
|
confirm.getCancelButton().setVisible(false);
|
39
|
confirm.show(UI.getCurrent(), null, true);
|
40
|
}
|
41
|
|
42
|
}
|
43
|
|
44
|
/**
|
45
|
*
|
46
|
*/
|
47
|
protected boolean isModalWindowShown() {
|
48
|
return UI.getCurrent().getWindows().stream().anyMatch(Window::isModal);
|
49
|
}
|
50
|
}
|