Package com.vaadin.tests.components.button

Source Code of com.vaadin.tests.components.button.ButtonEnterWithWindowShortcut

package com.vaadin.tests.components.button;

import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.event.ShortcutAction;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.util.Log;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;

public class ButtonEnterWithWindowShortcut extends TestBase {
    Log log = new Log(5);

    @Override
    protected void setup() {
        getMainWindow().addActionHandler(new Handler() {
            private static final long serialVersionUID = -4976129418325394913L;

            @Override
            public void handleAction(Action action, Object sender, Object target) {
                log.log(action.getCaption() + " pressed in window");
            }

            @Override
            public Action[] getActions(Object target, Object sender) {
                ShortcutAction enter = new ShortcutAction("enter",
                        ShortcutAction.KeyCode.ENTER, null);
                ShortcutAction space = new ShortcutAction("space",
                        ShortcutAction.KeyCode.SPACEBAR, null);
                return new Action[] { enter, space };
            }
        });

        Button button = new Button("Focus me and press enter",
                new ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        log.log("button click listener fired");
                    }
                });
        button.focus();

        addComponent(log);
        addComponent(button);
    }

    @Override
    protected String getDescription() {
        return "Pressing enter or space with the button focused should trigger the button click listener and not the shortcut action on the window.";
    }

    @Override
    protected Integer getTicketNumber() {
        return Integer.valueOf(5433);
    }

}
TOP

Related Classes of com.vaadin.tests.components.button.ButtonEnterWithWindowShortcut

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.