单击MenuItem打开上传窗口

时间:2014-10-08 09:34:33

标签: java menu upload vaadin

我想通过点击MenuItem从Upload元素打开uploadwindow。这可能吗? 另一个想法是在MenuBar中添加上传元素,但我认为这是不可能的,对吗?

感谢您的帮助!

2 个答案:

答案 0 :(得分:2)

也许一点点javascript可以帮到你:

Upload upload = new Upload();
upload.setImmediate(true); // if you want to start upload after selection
upload.addStyleName("my-upload");
MenuBar menuBar = new MenuBar();
menuBar.addItem("Caption", new Command() {
    private static final long serialVersionUID = 1L;

    @Override
    public void menuSelected(MenuItem selectedItem) {
        JavaScript.getCurrent().execute(
            "document.getElementsByClassName('gwt-FileUpload')[0].click()");
    }
});
addComponent(upload);
addComponent(menuBar);

如果你想隐藏上传:

.v-slot-my-upload {
    display: none;
}

答案 1 :(得分:1)

最简单的MenuBar,MenuItem,Window和Upload用例,为您留下布局:

    MenuBar menuBar = new MenuBar();
    final Window window = new Window();
    window.setContent(new Upload());
    menuBar.addItem("Caption", new Command()
    {
        @Override
        public void menuSelected(MenuItem selectedItem)
        {
            UI.getCurrent().addWindow(window);
        }
    });