Search in sources :

Example 1 with Handler

use of com.vaadin.event.Action.Handler in project Activiti by Activiti.

the class SubTaskComponent method initAddSubTaskPanelKeyboardActions.

protected void initAddSubTaskPanelKeyboardActions() {
    addSubTaskPanel.addActionHandler(new Handler() {

        public void handleAction(Action action, Object sender, Object target) {
            if ("escape".equals(action.getCaption())) {
                resetAddButton();
            } else if ("enter".equals(action.getCaption())) {
                if (newTaskTextField != null && newTaskTextField.getValue() != null && !"".equals(newTaskTextField.getValue().toString())) {
                    LoggedInUser loggedInUser = ExplorerApp.get().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) };
        }
    });
}
Also used : ShortcutAction(com.vaadin.event.ShortcutAction) Action(com.vaadin.event.Action) Task(org.activiti.engine.task.Task) Handler(com.vaadin.event.Action.Handler) LoggedInUser(org.activiti.explorer.identity.LoggedInUser) ShortcutAction(com.vaadin.event.ShortcutAction)

Example 2 with Handler

use of com.vaadin.event.Action.Handler in project Activiti by Activiti.

the class TaskEventsPanel method addInputField.

protected void addInputField() {
    HorizontalLayout layout = new HorizontalLayout();
    layout.setSpacing(true);
    layout.setWidth(100, UNITS_PERCENTAGE);
    addComponent(layout);
    // Hack: actionHandlers can only be attached to panels or windows
    Panel textFieldPanel = new Panel();
    textFieldPanel.addStyleName(Reindeer.PANEL_LIGHT);
    textFieldPanel.setContent(new VerticalLayout());
    textFieldPanel.setWidth(100, UNITS_PERCENTAGE);
    layout.addComponent(textFieldPanel);
    layout.setExpandRatio(textFieldPanel, 1.0f);
    commentInputField = new TextField();
    commentInputField.setWidth(100, UNITS_PERCENTAGE);
    textFieldPanel.addComponent(commentInputField);
    // Hack to catch keyboard 'enter'
    textFieldPanel.addActionHandler(new Handler() {

        public void handleAction(Action action, Object sender, Object target) {
            addNewComment(commentInputField.getValue().toString());
        }

        public Action[] getActions(Object target, Object sender) {
            return new Action[] { new ShortcutAction("enter", ShortcutAction.KeyCode.ENTER, null) };
        }
    });
    addCommentButton = new Button(i18nManager.getMessage(Messages.TASK_ADD_COMMENT));
    layout.addComponent(addCommentButton);
    layout.setComponentAlignment(addCommentButton, Alignment.MIDDLE_LEFT);
    addCommentButton.addListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {
            addNewComment(commentInputField.getValue().toString());
        }
    });
}
Also used : Panel(com.vaadin.ui.Panel) ShortcutAction(com.vaadin.event.ShortcutAction) Action(com.vaadin.event.Action) Button(com.vaadin.ui.Button) ClickEvent(com.vaadin.ui.Button.ClickEvent) VerticalLayout(com.vaadin.ui.VerticalLayout) TextField(com.vaadin.ui.TextField) Handler(com.vaadin.event.Action.Handler) ShortcutAction(com.vaadin.event.ShortcutAction) ClickListener(com.vaadin.ui.Button.ClickListener) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Aggregations

Action (com.vaadin.event.Action)2 Handler (com.vaadin.event.Action.Handler)2 ShortcutAction (com.vaadin.event.ShortcutAction)2 Button (com.vaadin.ui.Button)1 ClickEvent (com.vaadin.ui.Button.ClickEvent)1 ClickListener (com.vaadin.ui.Button.ClickListener)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Panel (com.vaadin.ui.Panel)1 TextField (com.vaadin.ui.TextField)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 Task (org.activiti.engine.task.Task)1 LoggedInUser (org.activiti.explorer.identity.LoggedInUser)1