Reputation: 77
We have a Vaadin 7 application which can have several Vaadin window objects. To aid the user in managing these windows, I want to have a button which will resize/reposition the windows such as tile the windows. The code I have goes something like this:
for (Window window : ui.getWindows()) {
window.setHeight(...);
window.setWidth(...);
window.setPositionX(...);
window.setPositionY(....);
}
The window is added to the UI, user interacts with it, presses the button which runs the above pseudo code, and the window responds. (good).
If the user now moves/resizes the windows again, the same button has no effect. (bad)
Any idea why the resizing/repositioning does not continue to work in case 2 above?
I created a test program to clarify my issue:
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);
}
}
Upvotes: 1
Views: 2311
Reputation: 77
vaadin has acknowledged this as a bug. Will fix in a future release.
http://dev.vaadin.com/ticket/12885
Upvotes: 1