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.module.project.view.bug.BugChartComponent.java

License:Open Source License

private void initUI() {
    final PopupButton bugChartPopup = new PopupButton("");
    bugChartPopup.addStyleName("popuplistindicator");

    final MVerticalLayout filterBtnLayout = new MVerticalLayout().withWidth("200px");

    final Button btnBugByPriority = new Button("Bugs By Priority", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override/*from   www .  ja  v a  2s .  c om*/
        public void buttonClick(final ClickEvent event) {
            bugChartPopup.setPopupVisible(false);
            currentReportIndex = 0;
            displayReport();
        }
    });
    btnBugByPriority.setStyleName("link");
    filterBtnLayout.addComponent(btnBugByPriority);

    final Button btnBugByStatus = new Button("Bugs By Status", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            bugChartPopup.setPopupVisible(false);
            currentReportIndex = 1;
            displayReport();
        }
    });
    btnBugByStatus.setStyleName("link");
    filterBtnLayout.addComponent(btnBugByStatus);

    final Button btnBugByResolution = new Button("Bugs By Resolution", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            bugChartPopup.setPopupVisible(false);
            currentReportIndex = 2;
            displayReport();
        }
    });
    btnBugByResolution.setStyleName("link");
    filterBtnLayout.addComponent(btnBugByResolution);

    displayReport();

    bugChartPopup.setContent(filterBtnLayout);
    this.addHeaderElement(bugChartPopup);
    this.setHeaderColor(true);
}

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

License:Open Source License

private void initHeader() {
    final Label title = new ProjectViewHeader(ProjectTypeConstants.BUG,
            AppContext.getMessage(BugI18nEnum.VIEW_BUG_DASHBOARD_TITLE));
    header.with(title).withAlign(title, Alignment.MIDDLE_LEFT).expand(title);

    final Button createBugBtn = new Button(AppContext.getMessage(BugI18nEnum.BUTTON_NEW_BUG),
            new Button.ClickListener() {
                @Override/*  w  w  w.j a  v a  2  s  .  c om*/
                public void buttonClick(final ClickEvent event) {
                    EventBusFactory.getInstance().post(new BugEvent.GotoAdd(this, null));
                }
            });
    createBugBtn.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.BUGS));
    createBugBtn.setIcon(FontAwesome.PLUS);
    final SplitButton controlsBtn = new SplitButton(createBugBtn);
    controlsBtn.addStyleName(UIConstants.THEME_GREEN_LINK);
    controlsBtn.setWidthUndefined();

    final VerticalLayout btnControlsLayout = new VerticalLayout();
    final Button createComponentBtn = new Button(AppContext.getMessage(BugI18nEnum.BUTTON_NEW_COMPONENT),
            new Button.ClickListener() {
                @Override
                public void buttonClick(final ClickEvent event) {
                    controlsBtn.setPopupVisible(false);
                    EventBusFactory.getInstance().post(new BugComponentEvent.GotoAdd(this, null));
                }
            });
    createComponentBtn.setStyleName("link");
    createComponentBtn
            .setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.COMPONENTS));
    btnControlsLayout.addComponent(createComponentBtn);

    final Button createVersionBtn = new Button(AppContext.getMessage(BugI18nEnum.BUTTON_NEW_VERSION),
            new Button.ClickListener() {
                @Override
                public void buttonClick(final ClickEvent event) {
                    controlsBtn.setPopupVisible(false);
                    EventBusFactory.getInstance().post(new BugVersionEvent.GotoAdd(this, null));
                }
            });
    createVersionBtn.setStyleName("link");
    createVersionBtn.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.VERSIONS));
    btnControlsLayout.addComponent(createVersionBtn);

    controlsBtn.setContent(btnControlsLayout);
    header.addComponent(controlsBtn);
}

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

License:Open Source License

public void setSearchCriteria(final BugSearchCriteria searchCriteria) {
    this.searchCriteria = searchCriteria;
    if (isDisplayTotalCount) {
        int totalCount = dataList.getTotalCount(searchCriteria);
        String depotTitle = String.format("%s (%d)", title, totalCount);
        this.setTitle(depotTitle);
    }//from   w  ww .jav a 2s.  c  om
    final SearchRequest<BugSearchCriteria> searchRequest = new SearchRequest<>(searchCriteria, 0,
            BugDisplayWidget.MAX_ITEM_DISPLAY);
    final int displayItemsCount = dataList.setSearchRequest(searchRequest);
    if (displayItemsCount == BugDisplayWidget.MAX_ITEM_DISPLAY) {
        Button moreBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_MORE),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        EventBusFactory.getInstance().post(new BugEvent.GotoList(BugDisplayWidget.this,
                                new BugScreenData.Search(constructMoreDisplayFilter())));
                    }
                });
        moreBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
        final MVerticalLayout widgetFooter = new MVerticalLayout().withSpacing(false).withWidth("100%");
        widgetFooter.addStyleName("widget-footer");
        widgetFooter.with(moreBtn).withAlign(moreBtn, Alignment.TOP_RIGHT);
        bodyContent.addComponent(widgetFooter);
    }
}

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

License:Open Source License

public BugKanbanViewImpl() {
    this.setSizeFull();
    this.withSpacing(true).withMargin(new MarginInfo(false, true, true, true));

    searchPanel = new BugSearchPanel();
    MHorizontalLayout groupWrapLayout = new MHorizontalLayout();
    groupWrapLayout.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);

    searchPanel.addHeaderRight(groupWrapLayout);

    Button advanceDisplayBtn = new Button("List", new Button.ClickListener() {
        @Override/*from www . j a va  2 s  . c  om*/
        public void buttonClick(Button.ClickEvent clickEvent) {
            EventBusFactory.getInstance().post(new BugEvent.GotoList(BugKanbanViewImpl.this, null));
        }
    });
    advanceDisplayBtn.setWidth("100px");
    advanceDisplayBtn.setIcon(FontAwesome.SITEMAP);
    advanceDisplayBtn.setDescription("Detail");

    Button kanbanBtn = new Button("Kanban");
    kanbanBtn.setWidth("100px");
    kanbanBtn.setDescription("Kanban View");
    kanbanBtn.setIcon(FontAwesome.TH);

    ToggleButtonGroup viewButtons = new ToggleButtonGroup();
    viewButtons.addButton(advanceDisplayBtn);
    viewButtons.addButton(kanbanBtn);
    viewButtons.withDefaultButton(kanbanBtn);
    groupWrapLayout.addComponent(viewButtons);

    kanbanLayout = new MHorizontalLayout().withMargin(new MarginInfo(true, false, true, false))
            .withFullHeight();
    kanbanLayout.addStyleName("kanban-layout");
    this.with(searchPanel, kanbanLayout).expand(kanbanLayout);
}

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

License:Open Source License

private ComponentContainer constructTableActionControls() {
    final MHorizontalLayout layout = new MHorizontalLayout().withWidth("100%");

    final Label lbEmpty = new Label("");
    layout.with(lbEmpty).expand(lbEmpty);

    MHorizontalLayout buttonControls = new MHorizontalLayout();
    layout.addComponent(buttonControls);

    Button customizeViewBtn = new Button("", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override//from w  w w.  j  a  v  a 2 s  .c  o  m
        public void buttonClick(ClickEvent event) {
            UI.getCurrent().addWindow(new BugListCustomizeWindow(BugListView.VIEW_DEF_ID, tableItem));

        }
    });
    customizeViewBtn.setIcon(FontAwesome.COG);
    customizeViewBtn.setDescription("Layout Options");
    customizeViewBtn.setStyleName(UIConstants.THEME_GRAY_LINK);
    buttonControls.addComponent(customizeViewBtn);

    PopupButton exportButtonControl = new PopupButton();
    exportButtonControl.addStyleName(UIConstants.THEME_GRAY_LINK);
    exportButtonControl.setIcon(FontAwesome.EXTERNAL_LINK);
    exportButtonControl.setDescription(AppContext.getMessage(FileI18nEnum.EXPORT_FILE));

    VerticalLayout popupButtonsControl = new VerticalLayout();
    exportButtonControl.setContent(popupButtonsControl);

    Button exportPdfBtn = new Button(AppContext.getMessage(FileI18nEnum.PDF));

    StreamWrapperFileDownloader fileDownloader = new StreamWrapperFileDownloader(new StreamResourceFactory() {

        @Override
        public StreamResource getStreamResource() {
            String title = "Bugs of Project " + ((CurrentProjectVariables.getProject() != null
                    && CurrentProjectVariables.getProject().getName() != null)
                            ? CurrentProjectVariables.getProject().getName()
                            : "");
            BugSearchCriteria searchCriteria = new BugSearchCriteria();
            searchCriteria.setProjectId(
                    new NumberSearchField(SearchField.AND, CurrentProjectVariables.getProject().getId()));

            return new StreamResource(new SimpleGridExportItemsStreamResource.AllItems<>(title,
                    new RpParameterBuilder(tableItem.getDisplayColumns()), ReportExportType.PDF,
                    ApplicationContextUtil.getSpringBean(BugService.class), searchCriteria, SimpleBug.class),
                    "export.pdf");
        }

    });
    fileDownloader.extend(exportPdfBtn);
    exportPdfBtn.setIcon(FontAwesome.FILE_PDF_O);
    exportPdfBtn.setStyleName("link");
    popupButtonsControl.addComponent(exportPdfBtn);

    Button exportExcelBtn = new Button(AppContext.getMessage(FileI18nEnum.EXCEL));
    StreamWrapperFileDownloader excelDownloader = new StreamWrapperFileDownloader(new StreamResourceFactory() {

        @Override
        public StreamResource getStreamResource() {
            String title = "Bugs of Project " + ((CurrentProjectVariables.getProject() != null
                    && CurrentProjectVariables.getProject().getName() != null)
                            ? CurrentProjectVariables.getProject().getName()
                            : "");
            BugSearchCriteria searchCriteria = new BugSearchCriteria();
            searchCriteria.setProjectId(
                    new NumberSearchField(SearchField.AND, CurrentProjectVariables.getProject().getId()));

            return new StreamResource(new SimpleGridExportItemsStreamResource.AllItems<>(title,
                    new RpParameterBuilder(tableItem.getDisplayColumns()), ReportExportType.EXCEL,
                    ApplicationContextUtil.getSpringBean(BugService.class), searchCriteria, SimpleBug.class),
                    "export.xlsx");
        }
    });
    excelDownloader.extend(exportExcelBtn);
    exportExcelBtn.setIcon(FontAwesome.FILE_EXCEL_O);
    exportExcelBtn.setStyleName("link");
    popupButtonsControl.addComponent(exportExcelBtn);

    Button exportCsvBtn = new Button(AppContext.getMessage(FileI18nEnum.CSV));

    StreamWrapperFileDownloader csvFileDownloader = new StreamWrapperFileDownloader(
            new StreamResourceFactory() {

                @Override
                public StreamResource getStreamResource() {
                    String title = "Bugs of Project " + ((CurrentProjectVariables.getProject() != null
                            && CurrentProjectVariables.getProject().getName() != null)
                                    ? CurrentProjectVariables.getProject().getName()
                                    : "");
                    BugSearchCriteria searchCriteria = new BugSearchCriteria();
                    searchCriteria.setProjectId(new NumberSearchField(SearchField.AND,
                            CurrentProjectVariables.getProject().getId()));

                    return new StreamResource(new SimpleGridExportItemsStreamResource.AllItems<>(title,
                            new RpParameterBuilder(tableItem.getDisplayColumns()), ReportExportType.CSV,
                            ApplicationContextUtil.getSpringBean(BugService.class), searchCriteria,
                            SimpleBug.class), "export.csv");
                }
            });
    csvFileDownloader.extend(exportCsvBtn);

    exportCsvBtn.setIcon(FontAwesome.FILE_TEXT_O);
    exportCsvBtn.setStyleName("link");
    popupButtonsControl.addComponent(exportCsvBtn);

    buttonControls.addComponent(exportButtonControl);
    return layout;
}

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

License:Open Source License

public BugListWidget(final String title, final String backBtnLabel, final BugSearchCriteria bugSearchCriteria,
        final IBugReportDisplayContainer bugReportDisplayContainer) {
    super(title, new VerticalLayout());

    final VerticalLayout contentLayout = (VerticalLayout) this.bodyContent;
    contentLayout.setSpacing(true);//from w w w.  ja v a 2  s  . c  o  m
    contentLayout.setWidth("100%");

    final Button backToBugReportsBtn = new Button(backBtnLabel, new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            bugReportDisplayContainer.displayBugReports();
        }
    });
    // contentLayout.addComponent(backToBugReportsBtn);
    final VerticalLayout backBtnWrapper = new VerticalLayout();
    backBtnWrapper.setMargin(new MarginInfo(false, false, true, false));

    backToBugReportsBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    backBtnWrapper.addComponent(backToBugReportsBtn);

    this.addComponentAsFirst(backBtnWrapper);

    this.tableItem = new BugTableDisplay(BugTableFieldDef.action,
            Arrays.asList(BugTableFieldDef.summary, BugTableFieldDef.assignUser, BugTableFieldDef.severity,
                    BugTableFieldDef.resolution, BugTableFieldDef.duedate));

    this.tableItem.addTableListener(new TableClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void itemClick(final TableClickEvent event) {
            final SimpleBug bug = (SimpleBug) event.getData();
            if ("summary".equals(event.getFieldName())) {
                EventBusFactory.getInstance().post(new BugEvent.GotoRead(BugListWidget.this, bug.getId()));
            }
        }
    });

    this.tableItem.setWidth("100%");
    contentLayout.addComponent(this.tableItem);

    this.setSearchCriteria(bugSearchCriteria);
}

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

License:Open Source License

private void displayWorkflowControl() {
    if (BugStatus.Open.name().equals(this.beanItem.getStatus())
            || BugStatus.ReOpened.name().equals(this.beanItem.getStatus())) {
        this.bugWorkflowControl.removeAllComponents();
        final ButtonGroup navButton = new ButtonGroup();
        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.ja 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();
                    }
                });
        startProgressBtn.addStyleName(UIConstants.THEME_BROWN_LINK);
        navButton.addButton(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) {
                        UI.getCurrent().addWindow(new ResolvedInputWindow(BugReadViewImpl.this, beanItem));
                    }
                });
        resolveBtn.addStyleName(UIConstants.THEME_BROWN_LINK);
        navButton.addButton(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) {
                        UI.getCurrent().addWindow(new WontFixExplainWindow(BugReadViewImpl.this, beanItem));
                    }
                });
        wontFixBtn.addStyleName(UIConstants.THEME_BROWN_LINK);
        navButton.addButton(wontFixBtn);
        this.bugWorkflowControl.addComponent(navButton);
    } else if (BugStatus.InProgress.name().equals(this.beanItem.getStatus())) {
        this.bugWorkflowControl.removeAllComponents();
        final ButtonGroup navButton = new ButtonGroup();
        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();
                    }
                });
        stopProgressBtn.addStyleName(UIConstants.THEME_BROWN_LINK);
        navButton.addButton(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) {
                        UI.getCurrent().addWindow(new ResolvedInputWindow(BugReadViewImpl.this, beanItem));
                    }
                });
        resolveBtn.addStyleName(UIConstants.THEME_BROWN_LINK);
        navButton.addButton(resolveBtn);
        this.bugWorkflowControl.addComponent(navButton);
    } else if (BugStatus.Verified.name().equals(this.beanItem.getStatus())) {
        this.bugWorkflowControl.removeAllComponents();
        final ButtonGroup navButton = new ButtonGroup();
        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) {
                        UI.getCurrent().addWindow(new ReOpenWindow(BugReadViewImpl.this, beanItem));
                    }
                });
        reopenBtn.addStyleName(UIConstants.THEME_BROWN_LINK);
        navButton.addButton(reopenBtn);

        this.bugWorkflowControl.addComponent(navButton);
    } else if (BugStatus.Resolved.name().equals(this.beanItem.getStatus())) {
        this.bugWorkflowControl.removeAllComponents();
        final ButtonGroup navButton = new ButtonGroup();
        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) {
                        UI.getCurrent().addWindow(new ReOpenWindow(BugReadViewImpl.this, beanItem));
                    }
                });
        reopenBtn.addStyleName(UIConstants.THEME_BROWN_LINK);
        navButton.addButton(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) {
                        UI.getCurrent().addWindow(new ApproveInputWindow(BugReadViewImpl.this, beanItem));
                    }
                });
        approveNCloseBtn.addStyleName(UIConstants.THEME_BROWN_LINK);
        navButton.addButton(approveNCloseBtn);
        this.bugWorkflowControl.addComponent(navButton);
    } else if (BugStatus.Resolved.name().equals(this.beanItem.getStatus())) {
        this.bugWorkflowControl.removeAllComponents();
        final ButtonGroup navButton = new ButtonGroup();
        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) {
                        UI.getCurrent().addWindow(new ReOpenWindow(BugReadViewImpl.this, beanItem));
                    }
                });
        reopenBtn.setStyleName(UIConstants.THEME_BROWN_LINK);
        navButton.addButton(reopenBtn);

        this.bugWorkflowControl.addComponent(navButton);
    }
    this.bugWorkflowControl.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.BUGS));
}

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

License:Open Source License

@Override
protected ComponentContainer createButtonControls() {
    ProjectPreviewFormControlsGenerator<SimpleBug> bugPreviewFormControls = new ProjectPreviewFormControlsGenerator<>(
            previewForm);/*  w ww.  j  a v a 2 s  .c o m*/
    MButton linkBtn = new MButton("Link", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            UI.getCurrent().addWindow(new LinkIssueWindow(beanItem));
        }
    }).withIcon(FontAwesome.LINK);
    linkBtn.addStyleName("black");
    bugPreviewFormControls.addOptionButton(linkBtn);

    final HorizontalLayout topPanel = bugPreviewFormControls.createButtonControls(
            ProjectPreviewFormControlsGenerator.ADD_BTN_PRESENTED
                    | ProjectPreviewFormControlsGenerator.DELETE_BTN_PRESENTED
                    | ProjectPreviewFormControlsGenerator.EDIT_BTN_PRESENTED
                    | ProjectPreviewFormControlsGenerator.CLONE_BTN_PRESENTED,
            ProjectRolePermissionCollections.BUGS);

    final Button assignBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_ASSIGN),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(final ClickEvent event) {
                    UI.getCurrent().addWindow(new AssignBugWindow(BugReadViewImpl.this, beanItem));
                }
            });
    assignBtn.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.BUGS));
    assignBtn.setIcon(FontAwesome.SHARE);

    assignBtn.setStyleName(UIConstants.THEME_GREEN_LINK);

    this.bugWorkflowControl = new HorizontalLayout();
    this.bugWorkflowControl.setMargin(false);
    this.bugWorkflowControl.addStyleName("workflow-controls");

    bugPreviewFormControls.insertToControlBlock(bugWorkflowControl);
    bugPreviewFormControls.insertToControlBlock(assignBtn);
    topPanel.setSizeUndefined();

    return topPanel;
}

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

License:Open Source License

public void displayRelatedBugs(final SimpleBug bug) {
    this.bug = bug;
    VerticalLayout mainLayout = new VerticalLayout();
    mainLayout.setWidth("100%");
    mainLayout.setMargin(true);//from  w  ww .j  av a2 s  .c  om
    mainLayout.setSpacing(true);

    HorizontalLayout layoutAdd = new HorizontalLayout();
    layoutAdd.setSpacing(true);

    Label lbBug = new Label("Bug:");
    lbBug.setWidth("70px");
    layoutAdd.addComponent(lbBug);
    layoutAdd.setComponentAlignment(lbBug, Alignment.MIDDLE_LEFT);

    itemField = new TextField();
    itemField.setWidth("300px");
    itemField.setNullRepresentation("");
    itemField.setReadOnly(true);
    itemField.setEnabled(true);
    layoutAdd.addComponent(itemField);
    layoutAdd.setComponentAlignment(itemField, Alignment.MIDDLE_LEFT);

    browseBtn = new Button("", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
            callItemSelectionWindow();

        }
    });
    browseBtn.setIcon(MyCollabResource.newResource(WebResourceIds._16_browseItem));
    browseBtn.setStyleName("link");

    layoutAdd.addComponent(browseBtn);
    layoutAdd.setComponentAlignment(browseBtn, Alignment.MIDDLE_LEFT);

    clearBtn = new Button("", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
            setItemFieldValue("");
        }
    });
    clearBtn.setIcon(MyCollabResource.newResource("icons/16/clearItem.png"));
    clearBtn.setStyleName("link");

    layoutAdd.addComponent(clearBtn);
    layoutAdd.setComponentAlignment(clearBtn, Alignment.MIDDLE_LEFT);

    Label lbIs = new Label("is");
    layoutAdd.addComponent(lbIs);
    layoutAdd.setComponentAlignment(lbIs, Alignment.MIDDLE_LEFT);

    comboRelation = new BugRelationComboBox();
    comboRelation.setWidth("200px");
    layoutAdd.addComponent(comboRelation);
    layoutAdd.setComponentAlignment(comboRelation, Alignment.MIDDLE_LEFT);

    btnRelate = new Button("Relate");
    btnRelate.setStyleName(UIConstants.THEME_GREEN_LINK);
    btnRelate.setIcon(MyCollabResource.newResource(WebResourceIds._16_addRecord));

    ProjectMemberService memberService = ApplicationContextUtil.getSpringBean(ProjectMemberService.class);
    SimpleProjectMember member = memberService.findMemberByUsername(AppContext.getUsername(),
            CurrentProjectVariables.getProjectId(), AppContext.getAccountId());

    if (member != null) {
        btnRelate.setEnabled((member.getIsadmin() || (AppContext.getUsername().equals(bug.getAssignuser()))
                || (AppContext.getUsername().equals(bug.getLogby())))
                && CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.BUGS));
    }

    btnRelate.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
            if (!itemField.getValue().toString().trim().equals("") && relatedBean != null
                    && !relatedBean.getSummary().equals(bug.getSummary())) {
                SimpleRelatedBug relatedBug = new SimpleRelatedBug();
                relatedBug.setBugid(bug.getId());
                relatedBug.setRelatedid(relatedBean.getId());
                relatedBug.setRelatetype((String) comboRelation.getValue());
                relatedBug.setComment(txtComment.getValue().toString());
                relatedBugService.saveWithSession(relatedBug, AppContext.getUsername());

                SimpleRelatedBug oppositeRelation = new SimpleRelatedBug();
                oppositeRelation.setBugid(relatedBean.getId());
                oppositeRelation.setRelatedid(bug.getId());
                oppositeRelation.setComment(txtComment.getValue().toString());

                if (comboRelation.getValue().toString().equals(BugRelationConstants.PARENT)) {
                    oppositeRelation.setRelatetype(BugRelationConstants.CHILD);
                } else if (comboRelation.getValue().toString().equals(BugRelationConstants.CHILD)) {
                    oppositeRelation.setRelatetype(BugRelationConstants.PARENT);
                } else if (comboRelation.getValue().toString().equals(BugRelationConstants.RELATED)) {
                    oppositeRelation.setRelatetype(BugRelationConstants.RELATED);
                } else if (comboRelation.getValue().toString().equals(BugRelationConstants.BEFORE)) {
                    oppositeRelation.setRelatetype(BugRelationConstants.AFTER);
                } else if (comboRelation.getValue().toString().equals(BugRelationConstants.AFTER)) {
                    oppositeRelation.setRelatetype(BugRelationConstants.BEFORE);
                } else if (comboRelation.getValue().toString().equals(BugRelationConstants.DUPLICATED)) {
                    oppositeRelation.setRelatetype(BugRelationConstants.DUPLICATED);
                    BugService bugService = ApplicationContextUtil.getSpringBean(BugService.class);
                    bug.setStatus(BugStatus.Resolved.name());
                    bug.setResolution(BugResolution.Duplicate.name());
                    bugService.updateWithSession(bug, AppContext.getUsername());
                }
                relatedBugService.saveWithSession(oppositeRelation, AppContext.getUsername());

                setCriteria();

                setItemFieldValue("");
                txtComment.setValue("");
                relatedBean = null;
            }
        }
    });
    layoutAdd.addComponent(btnRelate);
    layoutAdd.setComponentAlignment(btnRelate, Alignment.MIDDLE_LEFT);

    Label lbInstruction = new Label("<strong>Relate to an existing ticket</strong>", ContentMode.HTML);
    mainLayout.addComponent(lbInstruction);

    mainLayout.addComponent(layoutAdd);

    HorizontalLayout layoutComment = new HorizontalLayout();
    layoutComment.setSpacing(true);
    Label lbComment = new Label("Comment:");
    lbComment.setWidth("70px");
    layoutComment.addComponent(lbComment);
    layoutComment.setComponentAlignment(lbComment, Alignment.TOP_LEFT);
    txtComment = new RichTextArea();
    txtComment.setHeight("130px");
    txtComment.setWidth("565px");
    layoutComment.addComponent(txtComment);
    layoutComment.setComponentAlignment(txtComment, Alignment.MIDDLE_LEFT);
    mainLayout.addComponent(layoutComment);

    tableItem = new DefaultPagedBeanTable<RelatedBugService, BugRelatedSearchCriteria, SimpleRelatedBug>(
            ApplicationContextUtil.getSpringBean(RelatedBugService.class), SimpleRelatedBug.class,
            Arrays.asList(
                    new TableViewField(BugI18nEnum.RELATED_BUG_NAME, "bugName",
                            UIConstants.TABLE_EX_LABEL_WIDTH),
                    new TableViewField(BugI18nEnum.RELATED_BUG_TYPE, "relatetype",
                            UIConstants.TABLE_S_LABEL_WIDTH),
                    new TableViewField(BugI18nEnum.RELATED_BUG_COMMENT, "comment",
                            UIConstants.TABLE_EX_LABEL_WIDTH),
                    new TableViewField(null, "id", UIConstants.TABLE_CONTROL_WIDTH)));

    tableItem.addGeneratedColumn("bugName", new Table.ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleRelatedBug relatedItem = tableItem.getBeanByIndex(itemId);
            String bugname = "[%s-%s] %s";
            bugname = String.format(bugname, CurrentProjectVariables.getProject().getShortname(),
                    relatedItem.getRelatedid(), relatedItem.getBugName());

            BugService bugService = ApplicationContextUtil.getSpringBean(BugService.class);
            final SimpleBug bug = bugService.findById(relatedItem.getRelatedid(), AppContext.getAccountId());

            LabelLink b = new LabelLink(bugname,
                    ProjectLinkBuilder.generateBugPreviewFullLink(bug.getBugkey(), bug.getProjectShortName()));

            if (StringUtils.isNotBlank(bug.getPriority())) {
                String iconPriority = ProjectResources.getIconResourceLink12ByBugPriority(bug.getPriority());

                b.setIconLink(iconPriority);
            }

            if (BugStatus.Verified.name().equals(bug.getStatus())) {
                b.addStyleName(UIConstants.LINK_COMPLETED);
            } else if (bug.getDuedate() != null
                    && (bug.getDuedate().before(new GregorianCalendar().getTime()))) {
                b.addStyleName(UIConstants.LINK_OVERDUE);
            }
            b.setWidth("100%");
            return b;

        }
    });

    tableItem.addGeneratedColumn("id", new ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            final SimpleRelatedBug relatedItem = tableItem.getBeanByIndex(itemId);

            Button deleteBtn = new Button(null, new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
                    BugRelatedSearchCriteria relateBugIdCriteria = new BugRelatedSearchCriteria();
                    relateBugIdCriteria.setBugId(new NumberSearchField(relatedItem.getBugid()));
                    relateBugIdCriteria.setRelatedId(new NumberSearchField(relatedItem.getRelatedid()));

                    relatedBugService.removeByCriteria(relateBugIdCriteria, AppContext.getAccountId());

                    BugRelatedSearchCriteria relateIdCriteria = new BugRelatedSearchCriteria();
                    relateIdCriteria.setBugId(new NumberSearchField(relatedItem.getRelatedid()));
                    relateIdCriteria.setRelatedId(new NumberSearchField(relatedItem.getBugid()));

                    relatedBugService.removeByCriteria(relateIdCriteria, AppContext.getAccountId());

                    BugRelatedField.this.setCriteria();
                }
            });
            deleteBtn.setStyleName("link");
            deleteBtn.setIcon(MyCollabResource.newResource("icons/16/delete.png"));
            relatedItem.setExtraData(deleteBtn);

            ProjectMemberService memberService = ApplicationContextUtil
                    .getSpringBean(ProjectMemberService.class);
            SimpleProjectMember member = memberService.findMemberByUsername(AppContext.getUsername(),
                    CurrentProjectVariables.getProjectId(), AppContext.getAccountId());

            if (member != null) {
                deleteBtn.setEnabled(
                        member.getIsadmin() || (AppContext.getUsername().equals(bug.getAssignuser()))
                                || (AppContext.getUsername().equals(bug.getLogby())));
            }
            return deleteBtn;
        }
    });

    mainLayout.addComponent(tableItem);

    setCriteria();

    this.setCompositionRoot(mainLayout);
}

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

License:Open Source License

private ComponentContainer constructHeader() {
    Label headerText = new ProjectViewHeader(ProjectTypeConstants.BUG,
            AppContext.getMessage(BugI18nEnum.VIEW_LIST_TITLE));

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

                @Override/*from  w ww  .  j a v a 2 s.c  o  m*/
                public void buttonClick(final ClickEvent event) {
                    EventBusFactory.getInstance().post(new BugEvent.GotoAdd(this, null));
                }
            });
    createBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    createBtn.setIcon(FontAwesome.PLUS);
    createBtn.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.BUGS));

    headerText.setStyleName(UIConstants.HEADER_TEXT);

    rightComponent = new MHorizontalLayout();

    MHorizontalLayout header = new MHorizontalLayout().withStyleName(UIConstants.HEADER_VIEW).withWidth("100%")
            .withSpacing(true).withMargin(new MarginInfo(true, false, true, false));

    header.with(headerText, createBtn, rightComponent).withAlign(headerText, Alignment.MIDDLE_LEFT)
            .withAlign(createBtn, Alignment.MIDDLE_RIGHT).withAlign(rightComponent, Alignment.MIDDLE_RIGHT)
            .expand(headerText);

    return header;
}