Example usage for com.vaadin.event ShortcutAction ShortcutAction

List of usage examples for com.vaadin.event ShortcutAction ShortcutAction

Introduction

In this page you can find the example usage for com.vaadin.event ShortcutAction ShortcutAction.

Prototype

public ShortcutAction(String caption, int kc, int... m) 

Source Link

Document

Creates a shortcut that reacts to the given KeyCode and (optionally) ModifierKey s.

Usage

From source file:ac.uk.icl.dell.vaadin.glycanbuilder.GlycanBuilder.java

License:Open Source License

private void initToolBars() {
    theToolBarPanel = new Panel();
    theToolBarPanel.setContent(new HorizontalLayout());

    NavigableApplication.getCurrentNavigableAppLevelWindow().addActionHandler(new Handler() {
        private static final long serialVersionUID = 1735392108529734256L;

        Action actionDelete = new ShortcutAction("Delete", ShortcutAction.KeyCode.DELETE, null);
        Action actionCopy = new ShortcutAction("Copy", ShortcutAction.KeyCode.C,
                new int[] { ShortcutAction.ModifierKey.CTRL });
        Action actionPaste = new ShortcutAction("Paste", ShortcutAction.KeyCode.V,
                new int[] { ShortcutAction.ModifierKey.CTRL });
        Action actionCut = new ShortcutAction("Cut", ShortcutAction.KeyCode.X,
                new int[] { ShortcutAction.ModifierKey.CTRL });
        Action actionSelectAll = new ShortcutAction("Select all", ShortcutAction.KeyCode.A,
                new int[] { ShortcutAction.ModifierKey.CTRL });
        Action actionUnSelectAll = new ShortcutAction("UnSelect all", ShortcutAction.KeyCode.A,
                new int[] { ShortcutAction.ModifierKey.CTRL, ShortcutAction.ModifierKey.SHIFT });

        @Override/*from   w  ww .  j  av  a2s  .  c  o  m*/
        public Action[] getActions(Object target, Object sender) {
            return new Action[] { actionDelete, actionCopy, actionPaste, actionCut, actionSelectAll,
                    actionUnSelectAll };
        }

        @Override
        public void handleAction(Action action, Object sender, Object target) {

            GlycanCanvas canvas = theCanvas.theCanvas;
            if (theCanvas.theCanvas.hasSelected()) {
                if (action == actionDelete) {
                    canvas.delete();
                } else if (action == actionCopy) {
                    canvas.copy();
                } else if (action == actionCut) {
                    canvas.cut();
                }
            }

            if (action == actionSelectAll) {
                canvas.selectAll();
                canvas.documentUpdated();
            } else if (action == actionUnSelectAll) {
                canvas.resetSelection();
                canvas.documentUpdated();
            } else if (action == actionPaste) {
                System.err.println("Paste picked up!");
                canvas.paste();
            }
        }
    });

    theCanvas.appendGeneralToolBar(theToolBarPanel);

    //theToolBarPanel.setScrollable(true);

    mainLayout.addComponent(theToolBarPanel);

    Panel theLinkageToolBarPanel = new Panel();
    theLinkageToolBarPanel.setContent(new HorizontalLayout());
    theLinkageToolBarPanel.setWidth("100%");
    //theLinkageToolBarPanel.setScrollable(true);

    theCanvas.appendLinkageToolBar(theLinkageToolBarPanel);

    //theLinkageToolBarPanel.setScrollable(false);

    mainLayout.addComponent(theLinkageToolBarPanel);

    theResidueCanvas = new VaadinGlycanCanvas();
    theResidueCanvas.setBackgroundColor("#CCF");
    theResidueCanvas.setName("residueCanvas");

    theResidueCanvas.setHeight("25px");
    theResidueCanvas.setWidth("100%");

    theResidueCanvas.enableMouseSelectionRectangle(false);
    theResidueCanvas.theCanvas.theGlycanRenderer.getGraphicOptions().MARGIN_TOP = 2;

    mainLayout.addComponent(theResidueCanvas);
    //mainLayout.setExpandRatio(theResidueCanvas, 1);

    final VaadinGlycanCanvas finalCanvas = theResidueCanvas;
    finalCanvas.enableResidueToolBarMode();

    theResidueCanvas.theCanvas.addGlycanCanvasUpdateListener(new GlycanCanvasUpdateListener() {
        @Override
        public void glycanCanvasUpdated() {
            Residue selectedResidues[] = theResidueCanvas.theCanvas.selectedResidues.toArray(new Residue[0]);

            theResidueCanvas.theCanvas.selectedResidues.clear();

            theCanvas.theCanvas.setDocumentChangedEventFiring(false);

            for (Residue toinsert : selectedResidues) {
                System.err.println("Selected residue: " + toinsert.getTypeName());
                theCanvas.theCanvas.addResidueByNameToSelected(toinsert.getTypeName());
            }

            theCanvas.theCanvas.setDocumentChangedEventFiring(true);
            theCanvas.theCanvas.documentUpdated();
        }
    });
}

From source file:com.haulmont.cuba.web.gui.components.WebPickerFieldActionHandler.java

License:Apache License

public void addAction(com.haulmont.cuba.gui.components.Action action, int index) {
    actionList.add(index, action);// w  w w . jav  a  2 s  .co  m

    updateOrderedShortcuts();

    KeyCombination combination = action.getShortcutCombination();
    if (combination != null) {
        int key = combination.getKey().getCode();
        int[] modifiers = KeyCombination.Modifier.codes(combination.getModifiers());
        ShortcutAction providedShortcut = new ShortcutAction(action.getCaption(), key, modifiers);
        shortcuts.add(providedShortcut);
        actionsMap.put(providedShortcut, action);
    }
}

From source file:com.haulmont.cuba.web.gui.components.WebPickerFieldActionHandler.java

License:Apache License

protected void updateOrderedShortcuts() {
    shortcuts.removeAll(orderedShortcuts);
    for (ShortcutAction orderedShortcut : orderedShortcuts) {
        actionsMap.remove(orderedShortcut);
    }//from w  w  w.j a  v a 2s .  c  om

    for (int i = 0; i < actionList.size(); i++) {
        int keyCode = ShortcutAction.KeyCode.NUM1 + i;

        com.haulmont.cuba.gui.components.Action orderedAction = actionList.get(i);

        ShortcutAction orderedShortcut = new ShortcutAction(orderedAction.getCaption(), keyCode, modifiers);
        shortcuts.add(orderedShortcut);
        orderedShortcuts.add(orderedShortcut);
        actionsMap.put(orderedShortcut, orderedAction);
    }
}

From source file:com.haulmont.cuba.web.WebWindowManager.java

License:Apache License

protected Component showWindowDialog(Window window, OpenType openType, boolean forciblyDialog) {
    final CubaWindow vWindow = createDialogWindow(window);
    vWindow.setStyleName("c-app-dialog-window");
    if (ui.isTestMode()) {
        vWindow.setCubaId("dialog_" + window.getId());
        vWindow.setId(ui.getTestIdManager().getTestId("dialog_" + window.getId()));
    }/*from   ww  w . j a v a 2s.c o  m*/

    Layout layout = (Layout) WebComponentsHelper.getComposition(window);
    vWindow.setContent(layout);

    vWindow.addPreCloseListener(event -> {
        event.setPreventClose(true);
        if (!isCloseWithCloseButtonPrevented(window)) {
            // user has clicked on X
            window.close(Window.CLOSE_ACTION_ID);
        }
    });

    String closeShortcut = clientConfig.getCloseShortcut();
    KeyCombination closeCombination = KeyCombination.create(closeShortcut);

    ShortcutAction exitAction = new ShortcutAction("closeShortcutAction", closeCombination.getKey().getCode(),
            KeyCombination.Modifier.codes(closeCombination.getModifiers()));

    Map<com.vaadin.event.Action, Runnable> actions = singletonMap(exitAction, () -> {
        if (openType.getOpenMode() != OpenMode.DIALOG
                || BooleanUtils.isNotFalse(window.getDialogOptions().getCloseable())) {
            if (isCloseWithShortcutPrevented(window)) {
                return;
            }
            window.close(Window.CLOSE_ACTION_ID);
        }
    });

    WebComponentsHelper.setActions(vWindow, actions);

    boolean dialogParamsSizeUndefined = openType.getHeight() == null && openType.getWidth() == null;

    ThemeConstants theme = app.getThemeConstants();

    if (forciblyDialog && dialogParamsSizeUndefined) {
        layout.setHeight(100, Unit.PERCENTAGE);

        vWindow.setWidth(theme.getInt("cuba.web.WebWindowManager.forciblyDialog.width"), Unit.PIXELS);
        vWindow.setHeight(theme.getInt("cuba.web.WebWindowManager.forciblyDialog.height"), Unit.PIXELS);

        // resizable by default, but may be overridden in dialog params
        vWindow.setResizable(BooleanUtils.isNotFalse(openType.getResizable()));

        window.setHeightFull();
    } else {
        if (openType.getWidth() == null) {
            vWindow.setWidth(theme.getInt("cuba.web.WebWindowManager.dialog.width"), Unit.PIXELS);
        } else if (openType.getWidth() == AUTO_SIZE_PX) {
            vWindow.setWidthUndefined();
            layout.setWidthUndefined();
            window.setWidthAuto();
        } else {
            vWindow.setWidth(openType.getWidth(),
                    openType.getWidthUnit() != null ? WebWrapperUtils.toVaadinUnit(openType.getWidthUnit())
                            : Unit.PIXELS);
        }

        if (openType.getHeight() != null && openType.getHeight() != AUTO_SIZE_PX) {
            vWindow.setHeight(openType.getHeight(),
                    openType.getHeightUnit() != null ? WebWrapperUtils.toVaadinUnit(openType.getHeightUnit())
                            : Unit.PIXELS);
            layout.setHeight("100%");
            window.setHeightFull();
        } else {
            window.setHeightAuto();
        }

        // non resizable by default
        vWindow.setResizable(BooleanUtils.isTrue(openType.getResizable()));
    }

    if (openType.getCloseable() != null) {
        vWindow.setClosable(openType.getCloseable());
    }

    boolean modal = true;
    if (!hasModalWindow() && openType.getModal() != null) {
        modal = openType.getModal();
    }
    vWindow.setModal(modal);

    if (vWindow.isModal()) {
        boolean informationDialog = false;
        if (openType.getCloseOnClickOutside() != null) {
            informationDialog = openType.getCloseOnClickOutside();
        }
        vWindow.setCloseOnClickOutside(informationDialog);
    }

    if (openType.getMaximized() != null) {
        if (openType.getMaximized()) {
            vWindow.setWindowMode(WindowMode.MAXIMIZED);
        } else {
            vWindow.setWindowMode(WindowMode.NORMAL);
        }
    }

    if (openType.getPositionX() == null && openType.getPositionY() == null) {
        vWindow.center();
    } else {
        if (openType.getPositionX() != null) {
            vWindow.setPositionX(openType.getPositionX());
        }
        if (openType.getPositionY() != null) {
            vWindow.setPositionY(openType.getPositionY());
        }
    }

    getDialogParams().reset();

    ui.addWindow(vWindow);

    return vWindow;
}

From source file:com.klwork.explorer.project.ProjectSearchPanel.java

License:Apache License

protected void initKeyboardListener() {
    addActionHandler(new Handler() {
        public void handleAction(Action action, Object sender, Object target) {
            if (inputField.getValue() != null && !"".equals(inputField.getValue().toString())) {

                /*// Create task
                Task task = taskService.newTask();
                task.setName(inputField.getValue().toString());
                task.setOwner(LoginHandler.getLoggedInUser().getId());
                taskService.saveTask(task);
                        /*from   www. j a  v  a  2 s  .  c  o  m*/
                // Switch to the new task
                //ViewToolManager.getMainView().showTasksPage(task.getId());
                */ }
        }

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

From source file:com.klwork.explorer.ui.custom.TaskListHeader.java

License:Apache License

protected void initKeyboardListener() {
    addActionHandler(new Handler() {
        public void handleAction(Action action, Object sender, Object target) {
            if (inputField.getValue() != null && !"".equals(inputField.getValue().toString())) {

                // Create task
                Task task = taskService.newTask();
                task.setName(inputField.getValue().toString());
                task.setOwner(LoginHandler.getLoggedInUser().getId());
                taskService.saveTask(task);

                // Switch to the new task
                ViewToolManager.getMainView().showTasksPage(task.getId());
            }/*from w  w  w . j  a  v  a 2s.co  m*/
        }

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

From source file:com.klwork.explorer.ui.task.NewTaskPopupWindow.java

License:Apache License

protected void initEnterKeyListener() {
    addActionHandler(new Handler() {
        public void handleAction(Action action, Object sender, Object target) {
            handleFormSubmit();// www. ja  v  a 2 s .co  m
        }

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

From source file:com.klwork.explorer.ui.task.ProcessInstanceEventsPanel.java

License:Apache License

public void initAddEventInput(HorizontalLayout hLayout) {
    Panel textFieldPanel = new Panel(); // Hack: actionHandlers can only be
    // attached to panels or windows
    textFieldPanel.addStyleName(Reindeer.PANEL_LIGHT);
    VerticalLayout textFieldPanelLayout = new VerticalLayout();
    textFieldPanel.setContent(textFieldPanelLayout);

    textFieldPanel.setWidth(100, Unit.PERCENTAGE);
    hLayout.addComponent(textFieldPanel);
    hLayout.setExpandRatio(textFieldPanel, 1.0f);

    commentInputField = new TextField();
    commentInputField.setWidth(100, Unit.PERCENTAGE);
    textFieldPanelLayout.addComponent(commentInputField);

    // Hack to catch keyboard 'enter'
    textFieldPanel.addActionHandler(new Handler() {
        public void handleAction(Action action, Object sender, Object target) {
            addNewComment(commentInputField.getValue().toString());
        }/*w w  w . j  ava  2 s. c o  m*/

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

From source file:com.klwork.explorer.ui.task.SubTaskComponent.java

License:Apache License

protected void initAddSubTaskPanelKeyboardActions() {
    addSubTaskPanel.addActionHandler(new Handler() {
        public void handleAction(Action action, Object sender, Object target) {
            if ("escape".equals(action.getCaption())) {
                resetAddButton();/*ww  w . j  a v  a  2s  .  c o m*/
            } else if ("enter".equals(action.getCaption())) {//lllll
                if (newTaskTextField != null && newTaskTextField.getValue() != null
                        && !"".equals(newTaskTextField.getValue().toString())) {

                    LoggedInUser loggedInUser = LoginHandler.getLoggedInUser();

                    // save task
                    Task newTask = taskService.newTask();
                    newTask.setParentTaskId(parentTask.getId());
                    if (parentTask.getAssignee() != null) {
                        newTask.setAssignee(parentTask.getAssignee());
                    } else {
                        newTask.setAssignee(loggedInUser.getId());
                    }
                    if (parentTask.getOwner() != null) {
                        newTask.setOwner(parentTask.getOwner());
                    } else {
                        newTask.setOwner(loggedInUser.getId());
                    }
                    newTask.setName(newTaskTextField.getValue().toString());
                    taskService.saveTask(newTask);

                    // Reset the add button to its original state
                    resetAddButton();

                    // refresh sub tasks section
                    refreshSubTasks();
                }
            }
        }

        public Action[] getActions(Object target, Object sender) {
            return new Action[] { new ShortcutAction("enter", ShortcutAction.KeyCode.ENTER, null),
                    new ShortcutAction("escape", ShortcutAction.KeyCode.ESCAPE, null) };
        }
    });
}

From source file:com.klwork.explorer.ui.task.TaskEventsPanel.java

License:Apache License

public void initAddEventInput(HorizontalLayout hLayout) {
    Panel textFieldPanel = new Panel(); // Hack: actionHandlers can only be attached to panels or windows
    textFieldPanel.addStyleName(Reindeer.PANEL_LIGHT);
    VerticalLayout textFieldPanelLayout = new VerticalLayout();
    textFieldPanel.setContent(textFieldPanelLayout);

    textFieldPanel.setWidth(100, Unit.PERCENTAGE);
    hLayout.addComponent(textFieldPanel);
    hLayout.setExpandRatio(textFieldPanel, 1.0f);

    commentInputField = new TextField();
    commentInputField.setWidth(100, Unit.PERCENTAGE);
    textFieldPanelLayout.addComponent(commentInputField);

    // Hack to catch keyboard 'enter'
    textFieldPanel.addActionHandler(new Handler() {
        public void handleAction(Action action, Object sender, Object target) {
            addNewComment(commentInputField.getValue().toString());
        }/*from   w w w  .  ja va 2  s. c  o  m*/

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