1

我们有一个 Vaadin 7 应用程序,它可以有多个 Vaadin 窗口对象。为了帮助用户管理这些窗口,我想要一个按钮来调整窗口大小/重新定位窗口,例如平铺窗口。我的代码是这样的:

for (Window window : ui.getWindows()) {
    window.setHeight(...);
    window.setWidth(...);
    window.setPositionX(...);
    window.setPositionY(....);
}
  1. 窗口被添加到 UI 中,用户与之交互,按下运行上述伪代码的按钮,窗口响应。(好的)。

  2. 如果用户现在再次移动/调整窗口大小,则相同的按钮无效。(坏的)

知道为什么在上述情况 2 中调整大小/重新定位不能继续工作吗?

我创建了一个测试程序来澄清我的问题:

package com.example.tilewindow;

import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

@SuppressWarnings("serial")
@Theme("tilewindow")
public class TilewindowUI extends UI {

@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = TilewindowUI.class)
public static class Servlet extends VaadinServlet {
}
static int counter = 1;


@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    setContent(layout);
    addWindow(createWindow(0, 0, 300, 300));
    addWindow(createWindow(500, 0, 300, 300));
    addWindow(createWindow(0, 500, 300, 300));

    Button newWindowButton = new Button("New Window 2");
    newWindowButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            addWindow(createWindow(0, 0, 500, 500));
        }
    });
    Button tileWindowsButton = new Button("Tile");
    tileWindowsButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            Collection<Window> temp = getWindows();
            Collection<Window> windows = new ArrayList<Window>(temp);
            System.out.println("windows count = " + windows.size());
            int offset = 20;
            for (Window window : windows) {
                window.setHeight(200, Unit.PIXELS);
                window.setWidth(200, Unit.PIXELS);
                window.setPositionX(offset);
                window.setPositionY(offset);
                offset += 20;
                window.markAsDirty();
                System.out.println("   Found window, offset = ." + offset);
            }
            windows.clear();
            markAsDirty();
        }
    });
    layout.addComponent(newWindowButton);
    layout.addComponent(tileWindowsButton);
}
private Window createWindow(int xIn, int yIn, int heightIn, int widthIn) {
    Window returnValue = new Window();
    returnValue.setPositionX(xIn);
    returnValue.setPositionY(yIn);
    returnValue.setHeight(heightIn, Unit.PIXELS);
    returnValue.setWidth(widthIn, Unit.PIXELS);
    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.addComponent(new Label("Window #" + counter++));
    verticalLayout.addComponent(new TextField());
    returnValue.setContent(verticalLayout);
    return (returnValue);
}

}
4

1 回答 1

1

vaadin 承认这是一个错误。将在未来的版本中修复。

http://dev.vaadin.com/ticket/12885

于 2013-11-14T16:34:57.190 回答