-
Notifications
You must be signed in to change notification settings - Fork 8
/
MyUI.java
83 lines (72 loc) · 2.74 KB
/
MyUI.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package org.vaadin.mprdemo;
import com.vaadin.annotations.Push;
import com.vaadin.flow.component.AttachEvent;
import com.vaadin.flow.component.HasElement;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.applayout.AppLayout;
import com.vaadin.flow.component.applayout.DrawerToggle;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.icon.Icon;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.FlexLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouterLayout;
import com.vaadin.flow.router.RouterLink;
import com.vaadin.mpr.core.LegacyUI;
import com.vaadin.mpr.core.MprTheme;
import com.vaadin.server.VaadinSession;
@Push
@Route("")
@MprTheme("mytheme")
@CssImport("custom.css")
@LegacyUI(OldUI.class)
public class MyUI extends AppLayout implements RouterLayout {
private static final String VAADIN_THEMES = "/VAADIN/themes/";
private FlexLayout childWrapper = new FlexLayout();
private String css;
@SuppressWarnings("deprecation")
public MyUI() {
DrawerToggle toggle = new DrawerToggle();
addToNavbar(toggle);
VerticalLayout layout = new VerticalLayout();
layout.add(new RouterLink(SpreadsheetView.TITLE, SpreadsheetView.class));
layout.add(new RouterLink(TreeView.TITLE, TreeView.class));
layout.add(new RouterLink(VideoView.TITLE, VideoView.class));
layout.add(new RouterLink(LegacyRoute.TITLE, LegacyRoute.class));
Icon button = VaadinIcon.USER.create();
button.addClickListener(event -> {
getUI().ifPresent(ui -> {
ui.getSession().getSession().invalidate();
ui.getPage().setLocation("http://localhost:8080/");
});
});
layout.add(button);
addToDrawer(layout);
if (VaadinSession.getCurrent().getService().getDeploymentConfiguration().isProductionMode()) {
Notification.show("Vaadin 8 runs in prod mode");
}
childWrapper.setSizeFull();
setContent(childWrapper);
OldUI ui = (OldUI) OldUI.getCurrent();
Notification.show(ui.getHello());
ui.getPage().addUriFragmentChangedListener(event -> {
String uriFragment = event.getUriFragment().substring(1);
System.out.println("URI:" + uriFragment);
UI.getCurrent().navigate(uriFragment);
});
}
@Override
public void onAttach(AttachEvent event) {
if (event.getSession().getService().getDeploymentConfiguration().isProductionMode()) {
event.getUI().getPage().executeJs("window.vaadin.debug=false;");
}
}
@Override
public void showRouterLayoutContent(HasElement content) {
childWrapper.removeAll();
childWrapper.getElement().appendChild(content.getElement());
}
}