aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/elements/menubar/MenuBarUI.java
blob: 4ab4430ae628fe04dda392343b123e451d72ce3c (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
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
package com.vaadin.tests.elements.menubar;

import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.MenuBar.Command;
import com.vaadin.ui.MenuBar.MenuItem;

@SuppressWarnings("serial")
public class MenuBarUI extends AbstractTestUI {

    @Override
    protected void setup(VaadinRequest request) {
        addComponent(createDefaultMenuBar("", ""));
        addComponent(createDefaultMenuBar("2", ""));
        addComponent(createDefaultMenuBar("", "2"));
    }

    private MenuBar createDefaultMenuBar(String topLevelItemSuffix,
            String secondaryLevelItemSuffix) {
        MenuBar menuBar = new MenuBar();
        MenuItem file = menuBar.addItem("File" + topLevelItemSuffix, null);
        file.addItem("Open" + secondaryLevelItemSuffix, new MenuBarCommand())
                .setDescription("<b>Preformatted</b>\ndescription");
        file.addItem("Save" + secondaryLevelItemSuffix, new MenuBarCommand())
                .setDescription("plain description,\n <b>HTML</b> is visible",
                        ContentMode.TEXT);
        file.addItem("Save As.." + secondaryLevelItemSuffix,
                new MenuBarCommand());
        file.addSeparator();

        MenuItem export = file.addItem("Export.." + secondaryLevelItemSuffix,
                null);
        export.addItem("As PDF..." + secondaryLevelItemSuffix,
                new MenuBarCommand());
        export.addItem("As Doc..." + secondaryLevelItemSuffix,
                new MenuBarCommand());

        file.addSeparator();
        file.addItem("Exit" + secondaryLevelItemSuffix, new MenuBarCommand())
                .setDescription("<b>HTML</b><br/>description",
                        ContentMode.HTML);

        MenuItem edit = menuBar.addItem("Edit" + topLevelItemSuffix, null);
        edit.addItem("Copy" + secondaryLevelItemSuffix, new MenuBarCommand());
        edit.addItem("Cut" + secondaryLevelItemSuffix, new MenuBarCommand());
        edit.addItem("Paste" + secondaryLevelItemSuffix, new MenuBarCommand());

        menuBar.addItem("Help" + topLevelItemSuffix, new MenuBarCommand());
        return menuBar;
    }

    @Override
    protected String getTestDescription() {
        return "UI used to validate MenuBarElement API";
    }

    @Override
    protected Integer getTicketNumber() {
        return 13364;
    }

    private class MenuBarCommand implements Command {

        @Override
        public void menuSelected(MenuItem selectedItem) {
        }

    }
}