Java Code Examples for org.vaadin.viritin.button.MButton#addClickListener()

The following examples show how to use org.vaadin.viritin.button.MButton#addClickListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MButtonClickListeners.java    From viritin with Apache License 2.0 6 votes vote down vote up
@Override
public Component getTestComponent() {
    
    MButton b = new MButton("Say hola");
    
    // And the same without lambdas as the project is 1.6 compatible
    b.addClickListener(new MClickListener() {

        @Override
        public void onClick() {
            sayHola();
        }
    });
    b.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 5019806363620874205L;
        
        @Override
        public void buttonClick(ClickEvent event) {
            sayHolaOldSchool(event);
        }
    });
    
    return new MVerticalLayout(b);
}
 
Example 2
Source File: ProjectMembersWidget.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
ProjectMembersWidget() {
    super("", new CssLayout());
    MButton sortBtn = new MButton().withIcon(VaadinIcons.CARET_UP).withStyleName(WebThemes.BUTTON_ICON_ONLY);
    sortBtn.addClickListener(clickEvent -> {
        sortAsc = !sortAsc;
        if (sortAsc) {
            sortBtn.setIcon(VaadinIcons.CARET_UP);
            searchCriteria.setOrderFields(Collections.singletonList(new SearchCriteria.OrderField("memberFullName", SearchCriteria.ASC)));
        } else {
            sortBtn.setIcon(VaadinIcons.CARET_DOWN);
            searchCriteria.setOrderFields(Collections.singletonList(new SearchCriteria.OrderField("memberFullName",
                    SearchCriteria.DESC)));
        }
        memberList.setSearchCriteria(searchCriteria);
        setTitle(UserUIContext.getMessage(ProjectCommonI18nEnum.WIDGET_MEMBERS_TITLE, memberList.getTotalCount()));
    });
    addHeaderElement(sortBtn);

    final SearchTextField searchTextField = new SearchTextField() {
        @Override
        public void doSearch(String value) {
            searchCriteria.setMemberFullName(StringSearchField.and(value));
            showMembers();
        }

        @Override
        public void emptySearch() {
            searchCriteria.setMemberFullName(null);
            showMembers();
        }
    };
    searchTextField.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    addHeaderElement(searchTextField);

    memberList = new DefaultBeanPagedList<>(AppContextUtil.getSpringBean(ProjectMemberService.class),
            new MemberRowDisplayHandler(), 7);
    bodyContent.addComponent(memberList);
}
 
Example 3
Source File: TagViewComponent.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
private Button createAddTagBtn() {
    MButton addTagBtn = new MButton(UserUIContext.getMessage(TagI18nEnum.ACTION_ADD))
            .withIcon(VaadinIcons.PLUS_CIRCLE).withStyleName(WebThemes.BUTTON_LINK);
    addTagBtn.addClickListener(clickEvent -> {
        removeComponent(addTagBtn);
        addComponent(createSaveTagComp());
    });
    return addTagBtn;
}
 
Example 4
Source File: EmailTokenField.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
private Component generateToken(final String email) {
    MButton btn = new MButton(email).withIcon(VaadinIcons.CLOSE_SMALL).withStyleName("token-field");
    btn.addClickListener(clickEvent -> {
        EmailTokenField.this.removeComponent(btn);
        inviteEmails.remove(email);
    });
    return btn;
}
 
Example 5
Source File: MilestoneRoadmapViewImpl.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
MilestoneBlock(SimpleMilestone milestone) {
    this.withMargin(new MarginInfo(true, false, true, false)).withStyleName("roadmap-block");

    VaadinIcons statusIcon = ProjectAssetsUtil.getPhaseIcon(milestone.getStatus());
    ELabel statusLbl = ELabel.html(statusIcon.getHtml() + " " + UserUIContext.getMessage(MilestoneStatus.class,
            milestone.getStatus())).withStyleName(WebThemes.BLOCK).withUndefinedWidth();
    ToggleMilestoneSummaryField toggleMilestoneSummaryField = new ToggleMilestoneSummaryField(milestone, false, true);
    MHorizontalLayout headerLayout = new MHorizontalLayout(statusLbl, toggleMilestoneSummaryField).expand
            (toggleMilestoneSummaryField).withFullWidth();
    this.with(headerLayout);

    CssLayout metaBlock = new CssLayout();
    MilestoneComponentFactory popupFieldFactory = AppContextUtil.getSpringBean(MilestoneComponentFactory.class);
    metaBlock.addComponent(popupFieldFactory.createMilestoneAssigneePopupField(milestone, true));
    metaBlock.addComponent(popupFieldFactory.createStartDatePopupField(milestone));
    metaBlock.addComponent(popupFieldFactory.createEndDatePopupField(milestone));
    if (!SiteConfiguration.isCommunityEdition()) {
        metaBlock.addComponent(popupFieldFactory.createBillableHoursPopupField(milestone));
        metaBlock.addComponent(popupFieldFactory.createNonBillableHoursPopupField(milestone));
    }

    this.with(metaBlock);

    if (StringUtils.isNotBlank(milestone.getDescription())) {
        this.addComponent(ELabel.html(StringUtils.formatRichText(milestone.getDescription())));
    }

    MHorizontalLayout progressLayout = new MHorizontalLayout();
    progressLayout.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    int openAssignments = milestone.getNumOpenBugs() + milestone.getNumOpenTasks() + milestone.getNumOpenRisks();
    int totalAssignments = milestone.getNumBugs() + milestone.getNumTasks() + milestone.getNumRisks();
    ELabel progressInfoLbl;
    if (totalAssignments > 0) {
        progressInfoLbl = new ELabel(UserUIContext.getMessage(ProjectI18nEnum.OPT_PROJECT_TICKET,
                (totalAssignments - openAssignments), totalAssignments, (totalAssignments - openAssignments)
                        * 100 / totalAssignments)).withStyleName(WebThemes.META_INFO);
    } else {
        progressInfoLbl = new ELabel(UserUIContext.getMessage(ProjectI18nEnum.OPT_NO_TICKET))
                .withStyleName(WebThemes.META_INFO);
    }

    final MVerticalLayout issueLayout = new MVerticalLayout().withMargin(new MarginInfo(false, true, false, true));
    issueLayout.setVisible(false);

    progressLayout.with(progressInfoLbl);

    if (totalAssignments > 0) {
        MButton viewIssuesBtn = new MButton(UserUIContext.getMessage(ProjectI18nEnum.ACTION_VIEW_TICKETS))
                .withStyleName(WebThemes.BUTTON_LINK);
        viewIssuesBtn.addClickListener(clickEvent -> {
            showIssues = !showIssues;
            if (showIssues) {
                issueLayout.setVisible(true);
                viewIssuesBtn.setCaption(UserUIContext.getMessage(ProjectI18nEnum.ACTION_HIDE_TICKETS));
                ProjectTicketSearchCriteria searchCriteria = new ProjectTicketSearchCriteria();
                searchCriteria.setProjectIds(new SetSearchField<>(CurrentProjectVariables.getProjectId()));
                searchCriteria.setTypes(CurrentProjectVariables.getRestrictedTicketTypes());
                searchCriteria.setMilestoneId(new NumberSearchField(milestone.getId()));
                ProjectTicketService genericTaskService = AppContextUtil.getSpringBean(ProjectTicketService.class);
                List<ProjectTicket> tickets = (List<ProjectTicket>) genericTaskService.findPageableListByCriteria(new BasicSearchRequest<>(searchCriteria));
                for (ProjectTicket ticket : tickets) {
                    ToggleTicketSummaryField toggleTicketSummaryField = new ToggleTicketSummaryField(ticket);
                    MHorizontalLayout rowComp = new MHorizontalLayout(ELabel.EMPTY_SPACE());
                    rowComp.setDefaultComponentAlignment(Alignment.TOP_LEFT);
                    rowComp.with(ELabel.fontIcon(ProjectAssetsManager.getAsset(ticket.getType())).withUndefinedWidth());
                    String status = "";
                    if (ticket.isMilestone()) {
                        status = UserUIContext.getMessage(MilestoneStatus.class, ticket.getStatus());
                    } else {
                        status = UserUIContext.getMessage(StatusI18nEnum.class, ticket.getStatus());
                    }
                    rowComp.with(new ELabel(status).withStyleName(WebThemes.BLOCK).withUndefinedWidth());
                    String avatarLink = StorageUtils.getAvatarPath(ticket.getAssignUserAvatarId(), 16);
                    Img img = new Img(ticket.getAssignUserFullName(), avatarLink).setCSSClass(WebThemes.CIRCLE_BOX)
                            .setTitle(ticket.getAssignUserFullName());
                    rowComp.with(ELabel.html(img.write()).withUndefinedWidth());

                    rowComp.with(toggleTicketSummaryField).expand(toggleTicketSummaryField);
                    issueLayout.addComponent(rowComp);
                }
            } else {
                viewIssuesBtn.setCaption(UserUIContext.getMessage(ProjectI18nEnum.ACTION_VIEW_TICKETS));
                issueLayout.removeAllComponents();
                issueLayout.setVisible(false);
            }
        });
        progressLayout.with(viewIssuesBtn);
    }

    this.with(progressLayout, issueLayout);
}
 
Example 6
Source File: ProjectMemberListViewImpl.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
public ProjectMemberListViewImpl() {
    this.setMargin(new MarginInfo(false, true, true, true));

    responsiveLayout = new ResponsiveLayout(ResponsiveLayout.ContainerType.FIXED);
    responsiveLayout.setWidth("100%");
    this.add(responsiveLayout);

    MHorizontalLayout viewHeader = new MHorizontalLayout().withMargin(new MarginInfo(true, false, true, false)).withFullWidth();
    viewHeader.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);

    headerText = ComponentUtils.headerH2(ProjectTypeConstants.MEMBER, UserUIContext.getMessage(ProjectMemberI18nEnum.LIST));
    viewHeader.with(headerText).expand(headerText);

    final MButton sortBtn = new MButton().withIcon(VaadinIcons.CARET_UP).withStyleName(WebThemes.BUTTON_ICON_ONLY);
    sortBtn.addClickListener(clickEvent -> {
        sortAsc = !sortAsc;
        if (sortAsc) {
            sortBtn.setIcon(VaadinIcons.CARET_UP);
            displayMembers();
        } else {
            sortBtn.setIcon(VaadinIcons.CARET_DOWN);
            displayMembers();
        }
    });
    viewHeader.addComponent(sortBtn);

    final SearchTextField searchTextField = new SearchTextField() {
        @Override
        public void doSearch(String value) {
            searchCriteria.setMemberFullName(StringSearchField.and(value));
            displayMembers();
        }

        @Override
        public void emptySearch() {
            searchCriteria.setMemberFullName(null);
            displayMembers();
        }
    };
    searchTextField.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    viewHeader.addComponent(searchTextField);

    MButton printBtn = new MButton("", clickEvent -> UI.getCurrent().addWindow(new ProjectMemberCustomizeReportOutputWindow(new LazyValueInjector() {
        @Override
        protected Object doEval() {
            return searchCriteria;
        }
    }))).withIcon(VaadinIcons.PRINT).withStyleName(WebThemes.BUTTON_OPTION).withDescription(UserUIContext.getMessage(GenericI18Enum.ACTION_EXPORT));
    viewHeader.addComponent(printBtn);

    MButton createBtn = new MButton(UserUIContext.getMessage(ProjectMemberI18nEnum.BUTTON_NEW_INVITEES),
            clickEvent -> EventBusFactory.getInstance().post(new ProjectMemberEvent.GotoInviteMembers(this, null)))
            .withStyleName(WebThemes.BUTTON_ACTION).withIcon(VaadinIcons.PAPERPLANE);
    createBtn.setVisible(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.USERS));
    viewHeader.addComponent(createBtn);

    ResponsiveRow row = responsiveLayout.addRow();

    ResponsiveColumn column1 = new ResponsiveColumn(12, 12, 12, 12);
    column1.setContent(viewHeader);
    row.addColumn(column1);

    contentLayout = new MCssLayout().withFullWidth();
    row.addComponent(contentLayout);
}
 
Example 7
Source File: UserListViewImpl.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
public UserListViewImpl() {
    this.setMargin(new MarginInfo(false, true, false, true));
    MHorizontalLayout header = new MHorizontalLayout().withMargin(new MarginInfo(true, false, true, false))
            .withFullWidth();
    MButton createBtn = new MButton(UserUIContext.getMessage(UserI18nEnum.NEW),
            clickEvent -> EventBusFactory.getInstance().post(new UserEvent.GotoAdd(this, null)))
            .withIcon(VaadinIcons.PLUS).withStyleName(WebThemes.BUTTON_ACTION)
            .withVisible(UserUIContext.canWrite(RolePermissionCollections.ACCOUNT_USER));

    MButton bulkInviteBtn = new MButton(UserUIContext.getMessage(UserI18nEnum.BULK_INVITE),
            clickEvent -> EventBusFactory.getInstance().post(new UserEvent.GotoBulkInvite(this, null)))
            .withIcon(VaadinIcons.PLUS).withStyleName(WebThemes.BUTTON_ACTION)
            .withVisible(UserUIContext.canWrite(RolePermissionCollections.ACCOUNT_USER));

    headerText = HeaderWithIcon.h2(VaadinIcons.USERS, UserUIContext.getMessage(UserI18nEnum.LIST) + " " +
            UserUIContext.getMessage(GenericI18Enum.OPT_TOTAL_VALUE, 0));

    MButton sortBtn = new MButton().withIcon(VaadinIcons.CARET_UP).withStyleName(WebThemes.BUTTON_ICON_ONLY);
    sortBtn.addClickListener(clickEvent -> {
        sortAsc = !sortAsc;
        if (sortAsc) {
            sortBtn.setIcon(VaadinIcons.CARET_UP);
            displayUsers();
        } else {
            sortBtn.setIcon(VaadinIcons.CARET_DOWN);
            displayUsers();
        }
    });
    header.addComponent(sortBtn);

    SearchTextField searchTextField = new SearchTextField() {
        @Override
        public void doSearch(String value) {
            searchCriteria.setDisplayName(StringSearchField.and(value));
            displayUsers();
        }

        @Override
        public void emptySearch() {
            searchCriteria.setDisplayName(null);
            displayUsers();
        }
    };
    searchTextField.addStyleName(ValoTheme.TEXTFIELD_SMALL);

    MButton printBtn = new MButton("", clickEvent -> UI.getCurrent().addWindow(new UserCustomizeReportOutputWindow(
            new LazyValueInjector() {
                @Override
                protected Object doEval() {
                    return searchCriteria;
                }
            }))).withIcon(VaadinIcons.PRINT).withStyleName(WebThemes.BUTTON_OPTION)
            .withDescription(UserUIContext.getMessage(GenericI18Enum.ACTION_EXPORT));

    header.with(headerText, sortBtn, searchTextField, printBtn, createBtn, bulkInviteBtn).alignAll(Alignment.MIDDLE_LEFT).expand(headerText);
    this.addComponent(header);

    contentLayout = new CssLayout();
    contentLayout.setWidth("100%");
    this.addComponent(contentLayout);
}