Example usage for com.vaadin.ui Button Button

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

Introduction

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

Prototype

public Button(Resource icon, ClickListener listener) 

Source Link

Document

Creates a new push button with a click listener.

Usage

From source file:com.esofthead.mycollab.mobile.module.crm.ui.AbstractRelatedItemSelectionView.java

License:Open Source License

public AbstractRelatedItemSelectionView(String title, final AbstractRelatedListView<T, S> relatedListView) {
    this.setCaption(title);
    this.relatedListView = relatedListView;
    // if (!relatedListView.getItemList().getCurrentDataList().isEmpty())
    // this.selections = new HashSet<T>(relatedListView.getItemList()
    // .getCurrentDataList());
    initUI();/*www.  ja va  2  s  .  co m*/
    this.setContent(itemList);
    Button doneBtn = new Button(AppContext.getMessage(GenericI18Enum.M_BUTTON_DONE),
            new Button.ClickListener() {
                private static final long serialVersionUID = -652476076947907047L;

                @Override
                public void buttonClick(Button.ClickEvent event) {
                    if (!selections.isEmpty()) {
                        relatedListView.fireSelectedRelatedItems(selections);
                    }
                }
            });
    doneBtn.setStyleName("save-btn");
    this.setRightComponent(doneBtn);
}

From source file:com.esofthead.mycollab.mobile.module.project.ui.form.field.ProjectFormAttachmentDisplayField.java

License:Open Source License

@Override
protected Component initContent() {
    ResourceService resourceService = ApplicationContextUtil.getSpringBean(ResourceService.class);
    List<Content> attachments = resourceService.getContents(
            AttachmentUtils.getProjectEntityAttachmentPath(AppContext.getAccountId(), projectid, type, typeid));
    if (CollectionUtils.isNotEmpty(attachments)) {
        VerticalLayout comp = new VerticalLayout();
        comp.setStyleName("attachment-view-panel");

        for (final Content attachment : attachments) {
            String docName = attachment.getPath();
            int lastIndex = docName.lastIndexOf("/");
            if (lastIndex != -1) {
                docName = docName.substring(lastIndex + 1, docName.length());
            }//from  ww  w .  j  av a  2  s .c o  m

            if (MimeTypesUtil.isImageType(docName)) {
                Button b = new Button(attachment.getTitle(), new Button.ClickListener() {

                    private static final long serialVersionUID = 293396615972447886L;

                    @Override
                    public void buttonClick(Button.ClickEvent event) {
                        AttachmentPreviewView previewView = new AttachmentPreviewView(
                                VaadinResourceManager.getResourceManager()
                                        .getImagePreviewResource(attachment.getPath(), DEFAULT_SOURCE));
                        EventBusFactory.getInstance().post(new ShellEvent.PushView(this, previewView));
                    }
                });
                b.setWidth("100%");
                comp.addComponent(b);
            } else {
                Label l = new Label(attachment.getTitle());
                l.setWidth("100%");
                comp.addComponent(l);
            }
        }

        return comp;
    }
    return new Label("&nbsp;", ContentMode.HTML);
}

From source file:com.esofthead.mycollab.mobile.module.project.ui.ProjectCommentInput.java

License:Open Source License

private Component createAttachmentRow(String fileName) {
    final HorizontalLayout uploadSucceedLayout = new HorizontalLayout();
    uploadSucceedLayout.setWidth("100%");
    Label uploadResult = new Label(fileName);
    uploadResult.setWidth("100%");
    uploadSucceedLayout.addComponent(uploadResult);
    uploadSucceedLayout.setExpandRatio(uploadResult, 1.0f);

    Button removeAttachment = new Button(
            "<span aria-hidden=\"true\" data-icon=\"" + IconConstants.DELETE + "\"></span>",
            new Button.ClickListener() {

                private static final long serialVersionUID = 1L;

                @Override//w  ww . jav  a2  s.c  o m
                public void buttonClick(ClickEvent event) {
                    statusWrapper.removeComponent(uploadSucceedLayout);
                }

            });
    removeAttachment.setHtmlContentAllowed(true);
    removeAttachment.setStyleName("link");
    uploadSucceedLayout.addComponent(removeAttachment);
    uploadSucceedLayout.setStyleName("upload-succeed-layout");
    uploadSucceedLayout.setSpacing(true);
    return uploadSucceedLayout;
}

From source file:com.esofthead.mycollab.mobile.module.project.ui.ProjectCommentInputView.java

License:Open Source License

public ProjectCommentInputView(String typeVal, String typeIdVal, Integer extraTypeIdVal) {
    this.setCaption("Add a comment");
    resourceService = AppContextUtil.getSpringBean(ResourceService.class);
    MVerticalLayout content = new MVerticalLayout().withFullWidth().withStyleName("comment-input");
    this.setContent(content);

    type = typeVal;//from w  w  w .j  ava2s .c  o  m
    typeId = typeIdVal;
    extraTypeId = extraTypeIdVal;

    prepareUploadField();

    commentInput = new TextArea();
    commentInput.setWidth("100%");
    commentInput.setInputPrompt(AppContext.getMessage(GenericI18Enum.M_NOTE_INPUT_PROMPT));

    Button postBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SAVE), new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            final CommentWithBLOBs comment = new CommentWithBLOBs();
            comment.setComment(commentInput.getValue());
            comment.setCreatedtime(new GregorianCalendar().getTime());
            comment.setCreateduser(AppContext.getUsername());
            comment.setSaccountid(AppContext.getAccountId());
            comment.setType(type);
            comment.setTypeid("" + typeId);
            comment.setExtratypeid(extraTypeId);

            final CommentService commentService = AppContextUtil.getSpringBean(CommentService.class);
            int commentId = commentService.saveWithSession(comment, AppContext.getUsername());

            String attachmentPath = AttachmentUtils.getCommentAttachmentPath(type, AppContext.getAccountId(),
                    CurrentProjectVariables.getProjectId(), typeId, commentId);
            if (!"".equals(attachmentPath)) {
                saveContentsToRepo(attachmentPath);
            }

            getNavigationManager().navigateBack();
        }
    });
    this.setRightComponent(postBtn);
    content.with(commentInput, ELabel.hr(), uploadField, statusWrapper);
}

From source file:com.esofthead.mycollab.mobile.module.project.ui.ProjectCommentInputView.java

License:Open Source License

private Component createAttachmentRow(String fileName) {
    final MHorizontalLayout uploadSucceedLayout = new MHorizontalLayout().withFullWidth();
    Label uploadResult = new Label(fileName);
    uploadSucceedLayout.with(uploadResult).expand(uploadResult);

    Button removeAttachment = new Button("", new Button.ClickListener() {
        @Override/*from  w ww . ja v  a  2 s.co m*/
        public void buttonClick(ClickEvent event) {
            statusWrapper.removeComponent(uploadSucceedLayout);
        }
    });
    removeAttachment.setIcon(FontAwesome.TRASH);
    removeAttachment.setHtmlContentAllowed(true);
    removeAttachment.setStyleName("link");
    uploadSucceedLayout.addComponent(removeAttachment);
    return uploadSucceedLayout;
}

From source file:com.esofthead.mycollab.mobile.module.project.ui.ProjectMobileMenuPageView.java

License:Open Source License

@Override
protected void buildNavigateMenu() {
    getMenu().setWidth("80%");
    addSection("Views:");

    Button prjButton = new Button("Projects", new Button.ClickListener() {
        @Override/*  ww w  .  jav a2s.c  o  m*/
        public void buttonClick(Button.ClickEvent clickEvent) {
            closeMenu();
            EventBusFactory.getInstance().post(new ProjectEvent.GotoProjectList(this, null));
        }
    });
    prjButton.setIcon(FontAwesome.BUILDING);
    addMenuItem(prjButton);

    // Buttons with styling (slightly smaller with left-aligned text)
    Button activityBtn = new Button("Activities", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            closeMenu();
            EventBusFactory.getInstance()
                    .post(new ProjectEvent.MyProjectActivities(this, CurrentProjectVariables.getProjectId()));
        }
    });
    activityBtn.setIcon(FontAwesome.INBOX);
    addMenuItem(activityBtn);

    // add more buttons for a more realistic look.
    Button messageBtn = new Button("Messages", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            closeMenu();
            EventBusFactory.getInstance().post(new MessageEvent.GotoList(this, null));
        }
    });
    messageBtn.setIcon(ProjectAssetsManager.getAsset(ProjectTypeConstants.MESSAGE));
    addMenuItem(messageBtn);

    Button phaseBtn = new Button("Phases", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            closeMenu();
            EventBusFactory.getInstance().post(new MilestoneEvent.GotoList(this, null));
        }
    });
    phaseBtn.setIcon(ProjectAssetsManager.getAsset(ProjectTypeConstants.MILESTONE));
    addMenuItem(phaseBtn);

    Button taskBtn = new Button("Tasks", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            closeMenu();
            EventBusFactory.getInstance().post(new TaskEvent.GotoList(this, null));
        }
    });
    taskBtn.setIcon(ProjectAssetsManager.getAsset(ProjectTypeConstants.TASK));
    addMenuItem(taskBtn);

    Button bugBtn = new Button("Bugs", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            closeMenu();
            EventBusFactory.getInstance().post(new BugEvent.GotoList(this, null));
        }
    });
    bugBtn.setIcon(ProjectAssetsManager.getAsset(ProjectTypeConstants.BUG));
    addMenuItem(bugBtn);

    Button userBtn = new Button("Users", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            closeMenu();
            EventBusFactory.getInstance().post(new ProjectMemberEvent.GotoList(this, null));
        }
    });
    userBtn.setIcon(ProjectAssetsManager.getAsset(ProjectTypeConstants.MEMBER));
    addMenuItem(userBtn);

    addSection("Settings:");

    Button logoutBtn = new Button("Logout", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            closeMenu();
            EventBusFactory.getInstance().post(new ShellEvent.LogOut(this));
        }
    });
    logoutBtn.setIcon(FontAwesome.SIGN_OUT);
    addMenuItem(logoutBtn);
}

From source file:com.esofthead.mycollab.mobile.module.project.ui.TimeLogComp.java

License:Open Source License

public void displayTime(final V bean) {
    this.removeAllComponents();

    HorizontalLayout header = new HorizontalLayout();
    header.setSpacing(true);//from w w  w.java2s. c om
    header.setStyleName("info-hdr");
    header.addStyleName("timelog-comp-hdr");
    header.setWidth("100%");
    Label dateInfoHeader = new Label(AppContext.getMessage(TimeTrackingI18nEnum.SUB_INFO_TIME));
    dateInfoHeader.setWidthUndefined();
    header.addComponent(dateInfoHeader);
    header.setExpandRatio(dateInfoHeader, 1.0f);

    if (hasEditPermission()) {
        Button editBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_EDIT),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(ClickEvent event) {
                        showEditTimeView(bean);

                    }
                });
        editBtn.setStyleName("link");
        editBtn.setHtmlContentAllowed(true);
        header.addComponent(editBtn);
        header.setComponentAlignment(editBtn, Alignment.BOTTOM_LEFT);
    }

    this.addComponent(header);

    GridFormLayoutHelper layout = new GridFormLayoutHelper(1, 3, "100%", "150px", Alignment.TOP_RIGHT);
    layout.getLayout().setWidth("100%");
    layout.getLayout().setMargin(false);

    double billableHours = getTotalBillableHours(bean);
    double nonBillableHours = getTotalNonBillableHours(bean);
    double remainHours = getRemainedHours(bean);
    layout.addComponent(new Label(billableHours + ""),
            AppContext.getMessage(TimeTrackingI18nEnum.M_FORM_BILLABLE_HOURS), 0, 0);
    layout.addComponent(new Label(nonBillableHours + ""),
            AppContext.getMessage(TimeTrackingI18nEnum.M_FORM_NON_BILLABLE_HOURS), 0, 1);
    layout.addComponent(new Label(remainHours + ""),
            AppContext.getMessage(TimeTrackingI18nEnum.M_FORM_REMAIN_HOURS), 0, 2);
    this.addComponent(layout.getLayout());
}

From source file:com.esofthead.mycollab.mobile.module.project.ui.TimeLogEditView.java

License:Open Source License

private void initUI() {
    headerPanel = new HorizontalLayout();
    headerPanel.setWidth("100%");
    headerPanel.setStyleName("summary-info-panel");
    headerPanel.setMargin(new MarginInfo(true, false, true, false));
    headerPanel.setHeightUndefined();//w  w w .  j  ava 2  s. c  om
    content.addComponent(headerPanel);
    constructSpentTimeEntryPanel();
    constructRemainTimeEntryPanel();

    this.tableItem = new DefaultPagedBeanList<ItemTimeLoggingService, ItemTimeLoggingSearchCriteria, SimpleItemTimeLogging>(
            ApplicationContextUtil.getSpringBean(ItemTimeLoggingService.class), new TimeLogRowHandler()) {

        private static final long serialVersionUID = -4549910960891655297L;

        @Override
        protected void renderRows() {
            int i = 0;
            Date currentDate = new GregorianCalendar(2100, 1, 1).getTime();
            for (final SimpleItemTimeLogging item : currentListData) {
                if (!DateUtils.isSameDay(item.getLogforday(), currentDate)) {
                    Label dateLbl = new Label(AppContext.formatDate(item.getLogforday()));
                    dateLbl.setStyleName("log-day");
                    listContainer.addComponent(dateLbl);
                    currentDate = item.getLogforday();
                }
                final Component row = getRowDisplayHandler().generateRow(item, i);
                listContainer.addComponent(row);
                i++;
            }
        }

    };

    this.tableItem.setWidth("100%");
    content.addComponent(tableItem);
    content.setExpandRatio(tableItem, 1.0f);

    VerticalLayout controlBtns = new VerticalLayout();
    controlBtns.setSpacing(true);
    controlBtns.setWidth("100%");
    controlBtns.setMargin(true);
    controlBtns.addStyleName("edit-btn-layout");
    controlBtns.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);

    Button addNewEntryBtn = new Button(AppContext.getMessage(TimeTrackingI18nEnum.M_DIALOG_ADD_TIME_LOG_ENTRY),
            new Button.ClickListener() {

                private static final long serialVersionUID = -2540265040691537699L;

                @Override
                public void buttonClick(Button.ClickEvent event) {
                    UI.getCurrent().addWindow(new NewTimeLogEntryWindow());
                }
            });
    addNewEntryBtn.setWidth("100%");
    controlBtns.addComponent(addNewEntryBtn);

    Button updateRemainTimeBtn = new Button(
            AppContext.getMessage(TimeTrackingI18nEnum.M_DIALOG_UPDATE_REMAIN_HOURS),
            new Button.ClickListener() {

                private static final long serialVersionUID = 9215577509351959739L;

                @Override
                public void buttonClick(Button.ClickEvent event) {
                    UI.getCurrent().addWindow(new UpdateRemainTimeWindow());
                }
            });
    updateRemainTimeBtn.setWidth("100%");
    controlBtns.addComponent(updateRemainTimeBtn);

    NavigationBarQuickMenu editBtn = new NavigationBarQuickMenu();
    editBtn.setButtonCaption(null);
    editBtn.setStyleName("edit-btn");
    editBtn.setContent(controlBtns);
    this.setRightComponent(editBtn);
}

From source file:com.esofthead.mycollab.mobile.module.project.view.bug.ApproveInputView.java

License:Open Source License

private void constructUI() {
    final Button approveBtn = new Button("Approve & Close", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override/* w  w  w  .  j av a 2s.  c om*/
        public void buttonClick(final Button.ClickEvent event) {

            if (editForm.validateForm()) {
                // Save bug status and assignee
                ApproveInputView.this.bug.setStatus(BugStatus.Verified.name());

                final BugService bugService = ApplicationContextUtil.getSpringBean(BugService.class);
                bugService.updateSelectiveWithSession(ApproveInputView.this.bug, AppContext.getUsername());

                // Save comment
                final String commentValue = editForm.commentArea.getValue();
                if (commentValue != null && !commentValue.trim().equals("")) {
                    final Comment comment = new Comment();
                    comment.setComment(editForm.commentArea.getValue());
                    comment.setCreatedtime(new GregorianCalendar().getTime());
                    comment.setCreateduser(AppContext.getUsername());
                    comment.setSaccountid(AppContext.getAccountId());
                    comment.setType(CommentType.PRJ_BUG.toString());
                    comment.setTypeid("" + ApproveInputView.this.bug.getId());
                    comment.setExtratypeid(CurrentProjectVariables.getProjectId());

                    final CommentService commentService = ApplicationContextUtil
                            .getSpringBean(CommentService.class);
                    commentService.saveWithSession(comment, AppContext.getUsername());
                }
                ApproveInputView.this.callbackForm.previewItem(bug);
                EventBusFactory.getInstance().post(new ShellEvent.NavigateBack(this, null));
            }
        }
    });
    approveBtn.setStyleName("save-btn");
    this.setRightComponent(approveBtn);

    this.setContent(this.editForm);
}

From source file:com.esofthead.mycollab.mobile.module.project.view.bug.BugReadViewImpl.java

License:Open Source License

private void displayWorkflowControl() {
    this.bugWorkFlowControl.removeAllComponents();
    if (BugStatus.Open.name().equals(this.beanItem.getStatus())
            || BugStatus.ReOpened.name().equals(this.beanItem.getStatus())) {
        final Button startProgressBtn = new Button(AppContext.getMessage(BugI18nEnum.BUTTON_START_PROGRESS),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override//from w w  w. j  a v  a  2  s.  com
                    public void buttonClick(final ClickEvent event) {
                        beanItem.setStatus(BugStatus.InProgress.name());
                        final BugService bugService = ApplicationContextUtil.getSpringBean(BugService.class);
                        bugService.updateSelectiveWithSession(beanItem, AppContext.getUsername());
                        displayWorkflowControl();
                    }
                });
        bugWorkFlowControl.addComponent(startProgressBtn);

        final Button resolveBtn = new Button(AppContext.getMessage(BugI18nEnum.BUTTON_RESOLVED),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        EventBusFactory.getInstance().post(new ShellEvent.PushView(this,
                                new ResolvedInputView(BugReadViewImpl.this, beanItem)));
                    }
                });
        bugWorkFlowControl.addComponent(resolveBtn);

        final Button wontFixBtn = new Button(AppContext.getMessage(BugI18nEnum.BUTTON_WONTFIX),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        EventBusFactory.getInstance().post(new ShellEvent.PushView(this,
                                new WontFixExplainView(BugReadViewImpl.this, beanItem)));
                    }
                });
        bugWorkFlowControl.addComponent(wontFixBtn);
    } else if (BugStatus.InProgress.name().equals(this.beanItem.getStatus())) {
        final Button stopProgressBtn = new Button(AppContext.getMessage(BugI18nEnum.BUTTON_STOP_PROGRESS),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        beanItem.setStatus(BugStatus.Open.name());
                        final BugService bugService = ApplicationContextUtil.getSpringBean(BugService.class);
                        bugService.updateSelectiveWithSession(beanItem, AppContext.getUsername());
                        displayWorkflowControl();
                    }
                });
        bugWorkFlowControl.addComponent(stopProgressBtn);

        final Button resolveBtn = new Button(AppContext.getMessage(BugI18nEnum.BUTTON_RESOLVED),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        EventBusFactory.getInstance().post(new ShellEvent.PushView(this,
                                new ResolvedInputView(BugReadViewImpl.this, beanItem)));
                    }
                });
        bugWorkFlowControl.addComponent(resolveBtn);
    } else if (BugStatus.Verified.name().equals(this.beanItem.getStatus())) {
        final Button reopenBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_REOPEN),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        EventBusFactory.getInstance().post(
                                new ShellEvent.PushView(this, new ReOpenView(BugReadViewImpl.this, beanItem)));
                    }
                });
        bugWorkFlowControl.addComponent(reopenBtn);
    } else if (BugStatus.Resolved.name().equals(this.beanItem.getStatus())) {
        final Button reopenBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_REOPEN),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        EventBusFactory.getInstance().post(
                                new ShellEvent.PushView(this, new ReOpenView(BugReadViewImpl.this, beanItem)));
                    }
                });
        bugWorkFlowControl.addComponent(reopenBtn);

        final Button approveNCloseBtn = new Button(AppContext.getMessage(BugI18nEnum.BUTTON_APPROVE_CLOSE),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        EventBusFactory.getInstance().post(new ShellEvent.PushView(this,
                                new ApproveInputView(BugReadViewImpl.this, beanItem)));
                    }
                });
        bugWorkFlowControl.addComponent(approveNCloseBtn);
    } else if (BugStatus.Resolved.name().equals(this.beanItem.getStatus())) {
        final Button reopenBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_REOPEN),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        EventBusFactory.getInstance().post(
                                new ShellEvent.PushView(this, new ReOpenView(BugReadViewImpl.this, beanItem)));
                    }
                });
        bugWorkFlowControl.addComponent(reopenBtn);
    }
    this.bugWorkFlowControl.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.BUGS));
}