aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/ui/RefreshUI.java
blob: 997d33ff6582f866f7f21b34a970f1505df495cb (plain)
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
package com.vaadin.tests.components.ui;

import com.vaadin.annotations.PreserveOnRefresh;
import com.vaadin.navigator.Navigator;
import com.vaadin.navigator.View;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@PreserveOnRefresh
public class RefreshUI extends AbstractTestUI {

    @Override
    protected void setup(VaadinRequest request) {
        final Navigator navigator = new Navigator(this, this);
        navigator.addView("", MyView.class);
        navigator.addView("otherview", OtherView.class);
        setNavigator(navigator);
        MyView.instanceNumber = 0;
        OtherView.instanceNumber = 0;
    }

    public static class MyView extends VerticalLayout implements View {
        private static int instanceNumber = 0;

        public MyView() {
            instanceNumber++;
            addComponent(new Label("This is instance no " + instanceNumber));
            addComponent(new Button("Navigate to otherview", e -> UI
                    .getCurrent().getNavigator().navigateTo("otherview")));
        }
    }

    public static class OtherView extends VerticalLayout implements View {
        private static int instanceNumber = 0;

        public OtherView() {
            instanceNumber++;
            addComponent(new Label(
                    "This is otherview instance no " + instanceNumber));
        }
    }
}