Facing an issue with positioning the Window, using keyboard shortcuts.

Hi

In my application i use two windows at a time. If one is maximized, other will be minimized. I have added custom buttons to maximize and minimize the windows. It is working absolutely fine if i use mouse click for resizing and repositiong the windows. But instead if i use keyboard shortcuts i’m facing an issue with positioning the window.

I have written a sample code demonstrating the problem with a single window.

package com.example.windowissue;

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.event.Action;
import com.vaadin.event.ShortcutAction;
import com.vaadin.event.Action.Handler;
import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.event.ShortcutAction.ModifierKey;
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.Notification;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

@SuppressWarnings("serial")
@Theme("windowissue")
public class WindowissueUI extends UI implements Handler {

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

    Window win = new Window("Window X");
    Action action1 = new ShortcutAction("Alt+W",ShortcutAction.KeyCode.W,new int[] { ShortcutAction.ModifierKey.ALT });
    Action action2 = new ShortcutAction("Alt+Q",ShortcutAction.KeyCode.Q,new int[] { ShortcutAction.ModifierKey.ALT });
    @Override
    protected void init(VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        layout.setSpacing(true);
        setContent(layout);
        addActionHandler(this);
        win.setWidth("150px");
        win.setHeight("150px");
        win.addActionHandler(this);
        TextField txtName = new TextField();
        txtName.setInputPrompt("Enter Text");
        win.setContent(txtName);

        Button button = new Button("Click Me to open a window");
        button.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                addWindow(win);
            }
        });
        
        button.setClickShortcut(KeyCode.D, ModifierKey.ALT);
        Label lbl1 = new Label("Try to resize and reposition by using Alt+W and Alt+Q...(works fine)");
        Label lbl2 = new Label("Enter some text in the TextField inside window and"
                + " try to resize and reposition by using Alt+W and Alt+Q...(getting issue)");
        layout.addComponent(button);
        layout.addComponent(lbl1);
        layout.addComponent(lbl2);
    }

    @Override
    public Action[] getActions(Object target, Object sender) {
        // TODO Auto-generated method stub
        return new Action[] {action1, action2};
    }

    @Override
    public void handleAction(Action action, Object sender, Object target) {
        // TODO Auto-generated method stub
        if (action == action1) {
            win.setPosition(40, 40);
            win.setWidth("300px");
            win.setHeight("300px");
        }

        if (action == action2) {
            win.setPosition(400, 400);
            win.setWidth("200px");
            win.setHeight("200px");
        }
    }

}

Run the above code and see, window gets resized but it is not repositioning.

Thanks
Mahmood.