Example usage for com.vaadin.ui Button setCaption

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

Introduction

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

Prototype

@Override
    public void setCaption(String caption) 

Source Link

Usage

From source file:uk.co.intec.keyDatesApp.components.Pager.java

License:Apache License

/**
 * Load pages buttons - Prev, page numbers, Next.<br/>
 * <br/>/*  w  w w  . j ava2  s . c o m*/
 * If current page is 3 or less, the first page number displayed will be 1.
 * Otherwise, if available page is less than current page + 2, the first
 * page number will be available pages - 4. Otherwise, the first page number
 * will be current page - 2.
 */
public void loadPagerPagesButtons() {
    getPagerPagesPanel().removeAllComponents();
    if (getWrappedView().getAvailablePages() > 1) {
        final Button pageLink = new Button();
        pageLink.setCaption("Prev");
        pageLink.addStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED);
        pageLink.addStyleName(ValoTheme.BUTTON_TINY);
        pageLink.setIcon(FontAwesome.ANGLE_LEFT);
        pageLink.addClickListener(new ClickListener() {
            private static final long serialVersionUID = 1L;

            /*
             * (non-Javadoc)
             *
             * @see
             * com.vaadin.ui.Button.ClickListener#buttonClick(com.vaadin.ui.
             * Button.ClickEvent)
             */
            @Override
            public void buttonClick(ClickEvent event) {
                getWrappedView().setCurrentPage(getWrappedView().getCurrentPage() - 1);
                getWrappedView().setStart(getWrappedView().getStart() - getWrappedView().getCount());
                getWrappedView().redrawContents();
            }
        });
        final Label spacer = new Label("|");
        getPagerPagesButtons().put("Prev", pageLink);
        getPagerPagesPanel().addComponents(pageLink, spacer);
    }

    // Buttons for all pages
    int startPageNo = 1;
    if (getWrappedView().getCurrentPage() > 3) {
        if (getWrappedView().getAvailablePages() < (getWrappedView().getCurrentPage() + 2)) {
            startPageNo = getWrappedView().getAvailablePages() - 4;
            if (startPageNo < 1) {
                startPageNo = 1;
            }
        } else {
            startPageNo = getWrappedView().getCurrentPage() - 2;
        }
    }
    for (int i = startPageNo; i <= getWrappedView().getAvailablePages(); i++) {
        final Button pageLink = new Button();
        final int newPageNo = i;
        pageLink.setCaption(Integer.toString(i));
        pageLink.addStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED);
        pageLink.addStyleName(ValoTheme.BUTTON_TINY);
        pageLink.addClickListener(new ClickListener() {
            private static final long serialVersionUID = 1L;

            /*
             * (non-Javadoc)
             *
             * @see
             * com.vaadin.ui.Button.ClickListener#buttonClick(com.vaadin.ui.
             * Button.ClickEvent)
             */
            @Override
            public void buttonClick(ClickEvent event) {
                getWrappedView().setStart(1 + ((newPageNo - 1) * getWrappedView().getCount()));
                getWrappedView().setCurrentPage(newPageNo);
                getWrappedView().redrawContents();
            }
        });
        getPagerPagesButtons().put(i, pageLink);
        getPagerPagesPanel().addComponent(pageLink);
        if (getWrappedView().getAvailablePages() > 1) {
            final Label spacer = new Label("|");
            getPagerPagesPanel().addComponent(spacer);
        }
    }

    if (getWrappedView().getAvailablePages() > 1) {
        final Button pageLink = new Button();
        pageLink.setCaption("Next");
        pageLink.addStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED);
        pageLink.addStyleName(ValoTheme.BUTTON_TINY);
        pageLink.addStyleName(ValoTheme.BUTTON_ICON_ALIGN_RIGHT);
        pageLink.setIcon(FontAwesome.ANGLE_RIGHT);
        pageLink.addClickListener(new ClickListener() {
            private static final long serialVersionUID = 1L;

            /*
             * (non-Javadoc)
             *
             * @see
             * com.vaadin.ui.Button.ClickListener#buttonClick(com.vaadin.ui.
             * Button.ClickEvent)
             */
            @Override
            public void buttonClick(ClickEvent event) {
                getWrappedView().setCurrentPage(getWrappedView().getCurrentPage() + 1);
                getWrappedView().setStart(getWrappedView().getStart() + getWrappedView().getCount());
                getWrappedView().redrawContents();
            }
        });
        getPagerPagesButtons().put("Next", pageLink);
        getPagerPagesPanel().addComponents(pageLink);
    }

    updatePagerPagesButtonStyles();
}