@Override
protected void setup() {
VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
final Window window = new Window("Focus test window", layout);
layout.setSizeUndefined();
layout.addComponent(new TextField());
window.addListener(new FocusListener() {
@Override
public void focus(FocusEvent event) {
Notification.show("Focused window");
}
});
window.addListener(new BlurListener() {
@Override
public void blur(BlurEvent event) {
Notification.show("Blurred window");
}
});
window.addActionHandler(new Handler() {
private Action[] s = new Action[] { new ShortcutAction("^Save") };
@Override
public Action[] getActions(Object target, Object sender) {
return s;
}
@Override
public void handleAction(Action action, Object sender, Object target) {
Notification.show("Action!");
}
});
UI main = getLayout().getUI();
main.addWindow(window);
((ComponentContainer) main.getContent()).addComponent(new TextField());
Button button = new Button("Bring to front (should focus too)",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
window.bringToFront();
}
});
((ComponentContainer) main.getContent()).addComponent(button);
Window window2 = new Window("Another window for testing");
main.addWindow(window2);
window2.setPositionX(50);
}