Example usage for com.vaadin.event Action getCaption

List of usage examples for com.vaadin.event Action getCaption

Introduction

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

Prototype

public String getCaption() 

Source Link

Document

Returns the action's caption.

Usage

From source file:com.garyclayburg.vconsole.VConsole.java

License:Open Source License

private Table createUserTable(BeanContainer<String, User> userBeanContainer) {
    final Collection[] selectedRows = new Collection[1];
    final Table userTable = new Table();
    userTable.setSizeFull();//from  ww w  .j ava  2s.  c om
    userTable.setSelectable(true);
    userTable.setMultiSelect(false);
    userTable.setImmediate(true);
    userTable.setContainerDataSource(userBeanContainer);
    userTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {
        @Override
        public void itemClick(ItemClickEvent event) {
            Collection<?> itemPropertyIds = event.getItem().getItemPropertyIds();
            log.info("properties clicked: " + itemPropertyIds);
            log.info("multiple select? " + selectedRows[0]);
        }
    });
    userTable.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            //                selectedRows[0] = (Collection) userTable.getValue();
            log.info("selected: " + userTable.getValue());
        }
    });

    userTable.addActionHandler(new Action.Handler() {
        @Override
        public Action[] getActions(Object target, Object sender) {
            Table selectedUserTable = (Table) sender;
            Item item = selectedUserTable.getItem(selectedUserTable.getValue());
            Action[] actions = new Action[0];
            if (item instanceof BeanItem) {
                log.debug("create right-click menu items");
                //                    if (target == null){ //create actions for item user clicked on
                Item targetItem = selectedUserTable.getItem(target);
                if (targetItem != null) {
                    User targetUser = (User) ((BeanItem) targetItem).getBean();

                    if (targetUser != null) {
                        Set<String> allEntitledTargets = attributeService.getEntitledTargets(targetUser);
                        Set<Action> entitledTargetActions = new HashSet<>();

                        for (String targetName : allEntitledTargets) {
                            final Action action = new Action(targetName);
                            entitledTargetActions.add(action);
                        }
                        actions = entitledTargetActions.toArray(new Action[entitledTargetActions.size()]);
                        log.debug("right-click actions for user {}: {}", target, entitledTargetActions);
                    }
                }
            } else {
                log.debug("Cannot create right-click menu items");
            }

            return actions;
        }

        @Override
        public void handleAction(Action action, Object sender, Object target) {
            if (action != null) {
                Table selectedUserTable = (Table) sender;
                selectedUserTable.getValue();
                Item item = selectedUserTable.getItem(selectedUserTable.getValue());

                if (item instanceof BeanItem) {
                    log.debug("create target window");
                    User user = (User) ((BeanItem) item).getBean();
                    targetWindows.showTargetWindow(user, action.getCaption());
                } else {
                    log.debug("Cannot create window");
                }
            } else {
                Window multiWindow = new Window("multi-user myAD attributes");
                UI.getCurrent().addWindow(multiWindow);
                Label stuff = new Label("2 users here " + selectedRows[0] + " ");
                multiWindow.setContent(stuff);
            }
        }
    });
    userTable.setVisibleColumns("firstname", "lastname");
    return userTable;
}

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

License:Apache License

public static com.vaadin.event.ShortcutAction createShortcutAction(
        com.haulmont.cuba.gui.components.Action action) {
    KeyCombination keyCombination = action.getShortcutCombination();
    if (keyCombination != null) {
        return new com.vaadin.event.ShortcutAction(action.getCaption(), keyCombination.getKey().getCode(),
                KeyCombination.Modifier.codes(keyCombination.getModifiers()));
    } else {/*from w w  w  .  ja  v a 2 s  . c o m*/
        return null;
    }
}

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

License:Apache License

@Override
public void addAction(Action action, int index) {
    checkNotNullArgument(action, "Action must be non null");

    int oldIndex = findActionById(actionList, action.getId());
    if (oldIndex >= 0) {
        removeAction(actionList.get(oldIndex));
        if (index > oldIndex) {
            index--;/*from  w  ww.j  a  v a  2 s. c om*/
        }
    }

    if (StringUtils.isNotEmpty(action.getCaption())) {
        ActionMenuItemWrapper menuItemWrapper = createContextMenuItem(action);
        menuItemWrapper.setAction(action);
        contextMenuItems.add(menuItemWrapper);
    }

    actionList.add(index, action);
    shortcutsDelegate.addAction(null, action);
    attachAction(action);
    actionsPermissions.apply(action);
}

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

License:Apache License

protected ActionMenuItemWrapper createContextMenuItem(Action action) {
    MenuItem menuItem = contextMenu.addItem(action.getCaption(), null);
    menuItem.setStyleName("c-cm-item");

    return new ActionMenuItemWrapper(menuItem, showIconsForPopupMenuActions) {
        @Override/*from   www.ja  v a  2 s.com*/
        public void performAction(Action action) {
            action.actionPerform(WebDataGrid.this);
        }
    };
}

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 .  j a  v  a2s  . com*/

    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  va  2  s . co m

    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.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();/*from  w w w. j a v  a 2  s .  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:me.uni.emuseo.view.categories.CategoryTable.java

License:Open Source License

public CategoryTable() {

    setSortEnabled(false);//from w  w w.  j  a va2 s.c om
    addActionHandler(new Handler() {

        private static final long serialVersionUID = -1458601748782504737L;

        @Override
        public void handleAction(Action action, Object sender, Object target) {
            if (target == null) {
                return;
            }
            switch (action.getCaption()) {
            case "Edytuj":
                onEdit((CategoryDTO) target);
                break;
            case "Usu":
                onDelete((CategoryDTO) target);
                break;
            default:
                break;
            }
        }

        @Override
        public Action[] getActions(Object target, Object sender) {

            Action actionEdit = new Action("Edytuj", FontAwesome.EDIT);
            Action actionDelete = new Action("Usu", FontAwesome.TRASH_O);
            return new Action[] { actionEdit, actionDelete };
        }
    });
    setItemDescriptionGenerator(new CategoryDescriptionGenerator());

    beans = new BeanItemContainer<CategoryDTO>(CategoryDTO.class);
    setContainerDataSource(beans);
    setVisibleColumns(new Object[] { "name", "exhibitsCount" });
    setColumnHeaders("Nazwa", "Ilo eksponatw");

}

From source file:me.uni.emuseo.view.exhibits.ExhibitTable.java

License:Open Source License

public ExhibitTable() {

    setSortEnabled(false);/*from  w ww.  ja v  a  2  s.com*/
    addActionHandler(new Handler() {

        private static final long serialVersionUID = -1458601748782504737L;

        @Override
        public void handleAction(Action action, Object sender, Object target) {
            if (target == null) {
                return;
            }
            switch (action.getCaption()) {
            case "Edytuj":
                onEdit((ExhibitDTO) target);
                break;
            case "Usu":
                onDelete((ExhibitDTO) target);
                break;
            case EDIT_IMAGE_CAPTION:
                onImageEdit((ExhibitDTO) target);
                break;
            case SHOW_CAPTION:
                onShow((ExhibitDTO) target);
                break;
            default:
                break;
            }
        }

        @Override
        public Action[] getActions(Object target, Object sender) {

            Action actionEdit = new Action("Edytuj", FontAwesome.EDIT);
            Action actionDelete = new Action("Usu", FontAwesome.TRASH_O);
            Action actionEditImage = new Action(EDIT_IMAGE_CAPTION, FontAwesome.FILE_IMAGE_O);
            Action actionShow = new Action(SHOW_CAPTION, FontAwesome.EYE);
            return new Action[] { actionEdit, actionDelete, actionEditImage, actionShow };
        }
    });
    setItemDescriptionGenerator(new ExhibitDescriptionGenerator());

    beans = new BeanItemContainer<ExhibitDTO>(ExhibitDTO.class);
    setContainerDataSource(beans);
    beans.addNestedContainerBean("exhibitCategory");
    setVisibleColumns(new Object[] { "exhibitName", "exhibitNo", "genericYear", "exhibitCategory.name",
            "exhibitLocation" });
    setColumnHeaders("Nazwa", "Numer kat.", "Wiek w latach", "Kategoria", "Lokalizacja");

}

From source file:me.uni.emuseo.view.resources.ResourceTable.java

License:Open Source License

public ResourceTable() {

    setSortEnabled(false);//from  www  .j a v a2  s  . co  m
    addActionHandler(new Handler() {

        private static final long serialVersionUID = -1458601748782504737L;

        @Override
        public void handleAction(Action action, Object sender, Object target) {
            if (target == null) {
                return;
            }
            switch (action.getCaption()) {
            case "Edytuj":
                onEdit((ResourceDTO) target);
                break;
            case "Usu":
                onDelete((ResourceDTO) target);
                break;
            case "Poka":
                onShow((ResourceDTO) target);
            default:
                break;
            }
        }

        @Override
        public Action[] getActions(Object target, Object sender) {

            // Action actionEdit = new Action("Edytuj", FontAwesome.EDIT);
            // Action actionDelete = new Action("Usu",
            // FontAwesome.TRASH_O);
            Action actionShow = new Action("Poka", FontAwesome.EYE);
            return new Action[] { /* actionEdit, actionDelete, */actionShow };
        }
    });
    // setItemDescriptionGenerator(new ResourceDescriptionGenerator());

    beans = new BeanItemContainer<ResourceDTO>(ResourceDTO.class);
    setContainerDataSource(beans);
    setVisibleColumns("code", "fileName", "mimeType", "fileSize");
    setColumnHeaders("Kod", "Nazwa pliku", "Typ Mime", "Rozmiar");

}