Example usage for com.vaadin.ui Button addListener

List of usage examples for com.vaadin.ui Button addListener

Introduction

In this page you can find the example usage for com.vaadin.ui Button addListener.

Prototype

@Override
    public Registration addListener(Component.Listener listener) 

Source Link

Usage

From source file:org.activiti.explorer.ui.task.HistoricTaskDetailPanel.java

License:Apache License

protected void populateSubTasks(List<HistoricTaskInstance> subTasks) {
    for (final HistoricTaskInstance subTask : subTasks) {
        // icon// ww w  .j a  va  2s .c  o m
        Embedded icon = new Embedded(null, Images.TASK_22);
        icon.setWidth(22, UNITS_PIXELS);
        icon.setWidth(22, UNITS_PIXELS);
        subTaskGrid.addComponent(icon);

        // Link to subtask
        Button subTaskLink = new Button(subTask.getName());
        subTaskLink.addStyleName(Reindeer.BUTTON_LINK);
        subTaskLink.addListener(new ClickListener() {
            public void buttonClick(ClickEvent event) {
                ExplorerApp.get().getViewManager().showTaskPage(subTask.getId());
            }
        });
        subTaskGrid.addComponent(subTaskLink);
        subTaskGrid.setComponentAlignment(subTaskLink, Alignment.MIDDLE_LEFT);
    }
}

From source file:org.activiti.explorer.ui.task.SubTaskComponent.java

License:Apache License

protected void populateSubTasks(List<HistoricTaskInstance> subTasks) {
    if (!subTasks.isEmpty()) {
        for (final HistoricTaskInstance subTask : subTasks) {
            // icon
            Embedded icon = null;/*w w w  . j a v  a2s  .  c  o  m*/

            if (subTask.getEndTime() != null) {
                icon = new Embedded(null, Images.TASK_FINISHED_22);
            } else {
                icon = new Embedded(null, Images.TASK_22);
            }
            icon.setWidth(22, UNITS_PIXELS);
            icon.setWidth(22, UNITS_PIXELS);
            subTaskLayout.addComponent(icon);

            // Link to subtask
            Button subTaskLink = new Button(subTask.getName());
            subTaskLink.addStyleName(Reindeer.BUTTON_LINK);
            subTaskLink.addListener(new ClickListener() {
                public void buttonClick(ClickEvent event) {
                    ExplorerApp.get().getViewManager().showTaskPage(subTask.getId());
                }
            });
            subTaskLayout.addComponent(subTaskLink);
            subTaskLayout.setComponentAlignment(subTaskLink, Alignment.MIDDLE_LEFT);

            if (subTask.getEndTime() == null) {
                // Delete icon only appears when task is not finished yet
                Embedded deleteIcon = new Embedded(null, Images.DELETE);
                deleteIcon.addStyleName(ExplorerLayout.STYLE_CLICKABLE);
                deleteIcon.addListener(new DeleteSubTaskClickListener(subTask, this));
                subTaskLayout.addComponent(deleteIcon);
                subTaskLayout.setComponentAlignment(deleteIcon, Alignment.MIDDLE_RIGHT);
            } else {
                // Next line of grid
                subTaskLayout.newLine();
            }
        }
    } else {
        Label noSubTasksLabel = new Label(i18nManager.getMessage(Messages.TASK_NO_SUBTASKS));
        noSubTasksLabel.setSizeUndefined();
        noSubTasksLabel.addStyleName(Reindeer.LABEL_SMALL);
        subTaskLayout.addComponent(noSubTasksLabel);
    }

}

From source file:org.activiti.explorer.ui.task.TaskDetailPanel.java

License:Apache License

protected void initDescription(HorizontalLayout layout) {
    final CssLayout descriptionLayout = new CssLayout();
    descriptionLayout.setWidth(100, UNITS_PERCENTAGE);
    layout.addComponent(descriptionLayout);
    layout.setExpandRatio(descriptionLayout, 1.0f);
    layout.setComponentAlignment(descriptionLayout, Alignment.MIDDLE_LEFT);

    String descriptionText = null;
    if (task.getDescription() != null && !"".equals(task.getDescription())) {
        descriptionText = task.getDescription();
    } else {//from   w w w  .  j  a va  2s  .co  m
        descriptionText = i18nManager.getMessage(Messages.TASK_NO_DESCRIPTION);
    }
    final Label descriptionLabel = new Label(descriptionText);
    descriptionLabel.addStyleName(ExplorerLayout.STYLE_CLICKABLE);
    descriptionLayout.addComponent(descriptionLabel);

    descriptionLayout.addListener(new LayoutClickListener() {
        public void layoutClick(LayoutClickEvent event) {
            if (event.getClickedComponent() != null && event.getClickedComponent().equals(descriptionLabel)) {
                // layout for textarea + ok button
                final VerticalLayout editLayout = new VerticalLayout();
                editLayout.setSpacing(true);

                // textarea
                final TextArea descriptionTextArea = new TextArea();
                descriptionTextArea.setNullRepresentation("");
                descriptionTextArea.setWidth(100, UNITS_PERCENTAGE);
                descriptionTextArea.setValue(task.getDescription());
                editLayout.addComponent(descriptionTextArea);

                // ok button
                Button okButton = new Button(i18nManager.getMessage(Messages.BUTTON_OK));
                editLayout.addComponent(okButton);
                editLayout.setComponentAlignment(okButton, Alignment.BOTTOM_RIGHT);

                // replace
                descriptionLayout.replaceComponent(descriptionLabel, editLayout);

                // When OK is clicked -> update task data + ui
                okButton.addListener(new ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        // Update data
                        task.setDescription(descriptionTextArea.getValue().toString());
                        taskService.saveTask(task);

                        // Update UI
                        descriptionLabel.setValue(task.getDescription());
                        descriptionLayout.replaceComponent(editLayout, descriptionLabel);
                    }
                });
            }
        }
    });
}

From source file:org.activiti.explorer.ui.task.TaskDetailPanel.java

License:Apache License

protected void initProcessLink() {
    if (task.getProcessInstanceId() != null) {
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
                .processDefinitionId(task.getProcessDefinitionId()).singleResult();

        Button showProcessInstanceButton = new Button(i18nManager.getMessage(Messages.TASK_PART_OF_PROCESS,
                getProcessDisplayName(processDefinition)));
        showProcessInstanceButton.addStyleName(Reindeer.BUTTON_LINK);
        showProcessInstanceButton.addListener(new ClickListener() {
            public void buttonClick(ClickEvent event) {
                viewManager.showMyProcessInstancesPage(task.getProcessInstanceId());
            }/*from   w w  w.j  a  va2s  . c  om*/
        });

        centralLayout.addComponent(showProcessInstanceButton);
        addEmptySpace(centralLayout);
    }
}

From source file:org.activiti.explorer.ui.task.TaskDetailPanel.java

License:Apache License

protected void initParentTaskLink() {
    if (task.getParentTaskId() != null) {
        final Task parentTask = taskService.createTaskQuery().taskId(task.getParentTaskId()).singleResult();

        Button showParentTaskButton = new Button(
                i18nManager.getMessage(Messages.TASK_SUBTASK_OF_PARENT_TASK, parentTask.getName()));
        showParentTaskButton.addStyleName(Reindeer.BUTTON_LINK);
        showParentTaskButton.addListener(new ClickListener() {
            public void buttonClick(ClickEvent event) {
                viewManager.showTaskPage(parentTask.getId());
            }//  w  w  w.  j  a  v  a 2  s . c o m
        });

        centralLayout.addComponent(showParentTaskButton);
        addEmptySpace(centralLayout);
    }
}

From source file:org.activiti.explorer.ui.task.TaskEventsPanel.java

License:Apache License

protected void addInputField() {
    HorizontalLayout layout = new HorizontalLayout();
    layout.setSpacing(true);/* w ww.  j a  v a2  s.  c  o m*/
    layout.setWidth(100, UNITS_PERCENTAGE);
    addComponent(layout);

    Panel textFieldPanel = new Panel(); // Hack: actionHandlers can only be attached to panels or windows
    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) };
        }
    });

    Button 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());
        }
    });
}

From source file:org.activiti.explorer.ui.task.TaskMenuBar.java

License:Apache License

protected void initActions() {
    Button newCaseButton = new Button();
    newCaseButton.setCaption(i18nManager.getMessage(Messages.TASK_NEW));
    newCaseButton.setIcon(Images.TASK_16);
    addButton(newCaseButton);//from  w w w.jav a2 s  . co m

    newCaseButton.addListener(new ClickListener() {
        public void buttonClick(ClickEvent event) {
            NewCasePopupWindow newTaskPopupWindow = new NewCasePopupWindow();
            viewManager.showPopupWindow(newTaskPopupWindow);
        }
    });
}

From source file:org.activiti.explorer.ui.task.TaskRelatedContentComponent.java

License:Apache License

protected void initActions() {
    HorizontalLayout actionsContainer = new HorizontalLayout();
    actionsContainer.setSizeFull();/*ww  w . j  a  v  a2s .com*/

    // Title
    Label processTitle = new Label(i18nManager.getMessage(Messages.TASK_RELATED_CONTENT));
    processTitle.addStyleName(ExplorerLayout.STYLE_H3);
    processTitle.setSizeFull();
    actionsContainer.addComponent(processTitle);
    actionsContainer.setComponentAlignment(processTitle, Alignment.MIDDLE_LEFT);
    actionsContainer.setExpandRatio(processTitle, 1.0f);

    // Add content button
    Button addRelatedContentButton = new Button();
    addRelatedContentButton.addStyleName(ExplorerLayout.STYLE_ADD);
    addRelatedContentButton.addListener(new com.vaadin.ui.Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
            CreateAttachmentPopupWindow popup = new CreateAttachmentPopupWindow();

            if (task.getProcessInstanceId() != null) {
                popup.setProcessInstanceId(task.getProcessInstanceId());
            } else {
                popup.setTaskId(task.getId());
            }

            // Add listener to update attachments when added
            popup.addListener(new SubmitEventListener() {

                private static final long serialVersionUID = 1L;

                @Override
                protected void submitted(SubmitEvent event) {
                    taskDetailPanel.notifyRelatedContentChanged();
                }

                @Override
                protected void cancelled(SubmitEvent event) {
                    // No attachment was added so updating UI isn't needed.
                }
            });

            ExplorerApp.get().getViewManager().showPopupWindow(popup);
        }
    });

    actionsContainer.addComponent(addRelatedContentButton);
    actionsContainer.setComponentAlignment(processTitle, Alignment.MIDDLE_RIGHT);

    addComponent(actionsContainer);
}

From source file:org.activiti.explorer.ui.task.UserDetailsComponent.java

License:Apache License

protected void addUserDetails() {
    VerticalLayout detailsLayout = new VerticalLayout();
    addComponent(detailsLayout);/*from  www . j  a v a2s .  c om*/

    // Layout for name + skype
    HorizontalLayout nameLayout = new HorizontalLayout();
    nameLayout.setSpacing(true);
    detailsLayout.addComponent(nameLayout);

    // Name 
    Label nameLabel = null;
    if (user != null) {
        nameLabel = new Label(user.getFirstName() + " " + user.getLastName());
        nameLabel.addStyleName(ExplorerLayout.STYLE_LABEL_BOLD);
    } else {
        nameLabel = new Label("&nbsp;", Label.CONTENT_XHTML);
    }
    nameLayout.addComponent(nameLabel);

    // Layout for lower details
    HorizontalLayout actionsLayout = new HorizontalLayout();
    actionsLayout.setSpacing(true);
    detailsLayout.addComponent(actionsLayout);

    // Role
    Label roleLabel = new Label(role);
    actionsLayout.addComponent(roleLabel);

    // Action button
    if (clickListener != null) {
        Button button = new Button(buttonCaption);
        button.addStyleName(Reindeer.BUTTON_SMALL);
        button.addListener(clickListener);
        actionsLayout.addComponent(button);
    }
}

From source file:org.activiti.kickstart.ui.MainMenuBar.java

License:Apache License

protected void initButtons() {
    Button taskButton = addMenuButton("Create", Images.MAIN_MENU_CREATE_WORKFLOW, false, 80);
    taskButton.addListener(new CreateWorkflowButtonClickListener());
    menuItemButtons.put(MENU_ITEM_CREATE_WORKFLOW, taskButton);

    Button processButton = addMenuButton("Edit", Images.MAIN_MENU_EDIT_WORKFLOW, false, 80);
    processButton.addListener(new EditWorkflowButtonClickListener());
    menuItemButtons.put(MENU_ITEM_EDIT_WORKFLOW, processButton);

    Button manageButton = addMenuButton("Settings", Images.MAIN_MENU_SETTINGS, false, 90);
    manageButton.addListener(new SettingsClickListener());
    menuItemButtons.put(MENU_ITEM_SETTINGS, manageButton);

    // To center the buttons
    Label invisibleLabel = new Label();
    addComponent(invisibleLabel);/*w  w w  . j  a v  a 2 s  .c  o m*/
    setExpandRatio(invisibleLabel, 0.5f);
}