Example usage for com.vaadin.ui Button addClickListener

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

Introduction

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

Prototype

public Registration addClickListener(ClickListener listener) 

Source Link

Document

Adds the button click listener.

Usage

From source file:com.mcparland.john.vaadin_cookbook.PriceList.java

License:Apache License

/**
 * Create a button to add products to the table.
 * //  w ww  . j  av a  2s.com
 * @return button to add products to the table.
 */
@SuppressWarnings("serial")
private Button createAddProductButton() {
    Button addProductButton = new Button("Add Product");
    addProductButton.addClickListener(new ClickListener() {
        /*
         * (non-Javadoc)
         * 
         * @see
         * com.vaadin.ui.Button.ClickListener#buttonClick(com.vaadin.ui.
         * Button.ClickEvent)
         */
        public void buttonClick(ClickEvent clickEvent) {
            container.addItem(new Product("", 0.0d));
        }
    });
    return addProductButton;
}

From source file:com.mcparland.john.WelcomeView.java

License:Apache License

public WelcomeView() {
    Label welcomeLabel = new Label("Welcome!");
    addComponent(welcomeLabel);/*from w  ww  .  jav  a 2 s  .c  om*/

    Button ordersButton = new Button("Open Orders");
    ordersButton.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            UI ui = UI.getCurrent();
            Navigator nav = ui.getNavigator();
            nav.navigateTo(OrdersView.VIEW_NAME);
        }
    });

    addComponent(ordersButton);
}

From source file:com.mechanicshop.components.MaintenanceLayout.java

private void buildLayout() {
    HorizontalLayout layoutTitle = new HorizontalLayout();
    layoutTitle.setSizeUndefined();//from  ww w  . j a va  2  s . c om
    layoutTitle.setWidth("100%");
    layoutTitle.setSpacing(false);
    layoutTitle.setMargin(false);
    titleLabel.addStyleName(ValoTheme.LABEL_H2);
    titleLabel.addStyleName(ValoTheme.LABEL_COLORED);
    titleLabel.addStyleName(ValoTheme.LABEL_NO_MARGIN);
    titleLabel.addStyleName(ValoTheme.LABEL_BOLD);
    titleLabel.setSizeUndefined();

    layoutTitle.addComponent(titleLabel);
    layoutTitle.setComponentAlignment(titleLabel, Alignment.MIDDLE_CENTER);

    VerticalLayout layoutTable = new VerticalLayout();

    layoutTable.setSizeFull();

    layoutTable.setSpacing(true);
    HorizontalLayout layoutButtons = new HorizontalLayout();
    layoutButtons.setMargin(false);
    layoutButtons.setSpacing(true);
    layoutButtons.setSizeUndefined();
    Button passwordBtn = new Button("Edit Password");
    passwordBtn.addClickListener(passwordListener);
    passwordBtn.setImmediate(true);
    passwordBtn.setIcon(FontAwesome.EDIT);
    passwordBtn.setStyleName(ValoTheme.BUTTON_TINY);
    Button media1Btn = new Button("Media 1 Default Text");
    media1Btn.setStyleName(ValoTheme.BUTTON_TINY);
    media1Btn.setImmediate(true);
    media1Btn.setIcon(FontAwesome.EDIT);
    media1Btn.addClickListener(media1Listener);
    Button media2Btn = new Button("Media 2 Default Text");
    media2Btn.setStyleName(ValoTheme.BUTTON_TINY);
    media2Btn.setImmediate(true);
    media2Btn.setIcon(FontAwesome.EDIT);
    media2Btn.addClickListener(media2Listener);
    layoutButtons.addComponents(passwordBtn, media1Btn, media2Btn);

    layoutButtons.setComponentAlignment(passwordBtn, Alignment.MIDDLE_LEFT);
    layoutButtons.setComponentAlignment(media1Btn, Alignment.MIDDLE_LEFT);
    layoutButtons.setComponentAlignment(media2Btn, Alignment.MIDDLE_LEFT);

    addComponent(layoutTitle);
    addComponent(layoutTable);
    layoutTable.addComponent(layoutButtons);
    layoutTable.addComponent(table);
    layoutTable.setComponentAlignment(table, Alignment.TOP_CENTER);
    layoutTable.setExpandRatio(table, 3);
    setComponentAlignment(layoutTitle, Alignment.TOP_CENTER);
    setComponentAlignment(layoutTable, Alignment.TOP_CENTER);
    setExpandRatio(layoutTable, 3);
    setSpacing(true);
    setMargin(true);

}

From source file:com.mechanicshop.components.MaintenanceLayout.java

private void customizeTable() {
    table.setSizeFull();// www. j  a v  a2  s . co m
    table.setSortEnabled(true);
    table.setStyleName(ValoTheme.TABLE_NO_HORIZONTAL_LINES);
    table.addStyleName(ValoTheme.TABLE_SMALL);
    table.setEditable(true);
    table.setImmediate(true);

    table.addGeneratedColumn(" ", new Table.ColumnGenerator() {

        @Override
        public Object generateCell(final Table source, final Object itemId, Object columnId) {
            Button icon = new Button();
            icon.setStyleName(ValoTheme.BUTTON_ICON_ONLY);
            icon.addStyleName(ValoTheme.BUTTON_TINY);
            icon.addStyleName(ValoTheme.BUTTON_BORDERLESS);
            icon.setVisible(true);
            icon.setImmediate(true);
            icon.setDescription("Details");
            icon.setIcon(FontAwesome.PENCIL);
            icon.addClickListener(new ClickListener() {

                @Override
                public void buttonClick(ClickEvent event) {
                    Item item = source.getItem(itemId);
                    showDataEntryWindow(item);
                }
            });
            return icon;
        }
    });

}

From source file:com.mechanicshop.components.TableLayout.java

private void buildLayout() {
    HorizontalLayout layoutTitle = new HorizontalLayout();
    layoutTitle.setSizeUndefined();//from   ww w.j a v  a2  s.  c  o  m
    layoutTitle.setWidth("100%");
    layoutTitle.setSpacing(false);
    layoutTitle.setMargin(false);
    titleLabel.addStyleName(ValoTheme.LABEL_H2);
    titleLabel.addStyleName(ValoTheme.LABEL_COLORED);
    titleLabel.addStyleName(ValoTheme.LABEL_NO_MARGIN);
    titleLabel.addStyleName(ValoTheme.LABEL_BOLD);
    titleLabel.setSizeUndefined();

    layoutTitle.addComponent(titleLabel);
    layoutTitle.setComponentAlignment(titleLabel, Alignment.MIDDLE_CENTER);

    VerticalLayout layoutTable = new VerticalLayout();

    layoutTable.addComponent(table);
    layoutTable.setComponentAlignment(table, Alignment.TOP_CENTER);
    layoutTable.setSizeFull();

    layoutTable.setSpacing(true);
    HorizontalLayout layoutButtons = new HorizontalLayout();
    layoutButtons.setMargin(false);
    layoutButtons.setSpacing(true);
    layoutButtons.setSizeUndefined();
    layoutButtons.setWidth("100%");
    Button addBtn = new Button("Add new Car");
    addBtn.addClickListener(addBtnListener);
    addBtn.setImmediate(true);
    addBtn.setStyleName(ValoTheme.BUTTON_TINY);
    addBtn.addStyleName(ValoTheme.BUTTON_FRIENDLY);
    Button deleteBtn = new Button("Delete Selected");
    deleteBtn.setStyleName(ValoTheme.BUTTON_TINY);
    deleteBtn.addStyleName(ValoTheme.BUTTON_DANGER);
    deleteBtn.setImmediate(true);
    deleteBtn.addClickListener(removeListener);

    btnSendSMS.setStyleName(ValoTheme.BUTTON_TINY);
    btnSendSMS.addStyleName(ValoTheme.BUTTON_FRIENDLY);
    btnSendSMS.setImmediate(true);
    btnSendSMS.addClickListener(sendSMSBtnListener);

    searchTextField.setImmediate(true);
    searchTextField.addStyleName(ValoTheme.TEXTFIELD_TINY);
    searchTextField.addTextChangeListener(filterChangeListener);
    Label lbSearch = new Label("Search");
    lbSearch.addStyleName(ValoTheme.LABEL_TINY);
    lbSearch.setSizeUndefined();
    layoutButtons.addComponents(lbSearch, searchTextField, addBtn, deleteBtn, btnSendSMS);

    layoutButtons.setComponentAlignment(lbSearch, Alignment.MIDDLE_LEFT);
    layoutButtons.setComponentAlignment(searchTextField, Alignment.BOTTOM_LEFT);
    layoutButtons.setComponentAlignment(addBtn, Alignment.BOTTOM_RIGHT);
    layoutButtons.setComponentAlignment(deleteBtn, Alignment.BOTTOM_RIGHT);
    layoutButtons.setComponentAlignment(btnSendSMS, Alignment.BOTTOM_RIGHT);
    layoutButtons.setExpandRatio(addBtn, 3);
    addComponent(layoutTitle);
    addComponent(layoutTable);
    layoutTable.addComponent(layoutButtons);
    layoutTable.setExpandRatio(table, 3);
    setComponentAlignment(layoutTitle, Alignment.TOP_CENTER);
    setComponentAlignment(layoutTable, Alignment.TOP_CENTER);
    setExpandRatio(layoutTable, 3);
    setSpacing(true);
    setMargin(true);

}

From source file:com.mechanicshop.components.TableLayout.java

private void customizeTable() {
    table.setSizeFull();/* w  ww .  j ava  2 s . co m*/
    table.setSortEnabled(true);
    table.setStyleName(ValoTheme.TABLE_NO_HORIZONTAL_LINES);
    table.addStyleName(ValoTheme.TABLE_SMALL);
    table.setEditable(true);
    table.setImmediate(true);
    table.setSizeFull();
    table.addGeneratedColumn("", new Table.ColumnGenerator() {

        @Override
        public Object generateCell(Table source, final Object itemId, Object columnId) {
            boolean selected = false;

            final CheckBox cb = new CheckBox("", selected);

            cb.addValueChangeListener(new Property.ValueChangeListener() {

                public void valueChange(ValueChangeEvent event) {
                    if (selectedItemIds.contains(itemId)) {
                        selectedItemIds.remove(itemId);
                    } else {
                        if (cb.getValue() != false) {
                            selectedItemIds.add(itemId);
                        }
                    }
                }
            });
            return cb;
        }
    });

    table.addGeneratedColumn(" ", new Table.ColumnGenerator() {

        @Override
        public Object generateCell(final Table source, final Object itemId, Object columnId) {
            Button icon = new Button();
            icon.setStyleName(ValoTheme.BUTTON_ICON_ONLY);
            icon.addStyleName(ValoTheme.BUTTON_TINY);
            icon.addStyleName(ValoTheme.BUTTON_BORDERLESS);
            icon.setVisible(true);
            icon.setImmediate(true);
            icon.setDescription("Details");
            icon.setIcon(FontAwesome.PENCIL);
            icon.addClickListener(new ClickListener() {

                @Override
                public void buttonClick(ClickEvent event) {
                    Item item = source.getItem(itemId);
                    dataEntryLayout.fillDataEntry(item, titleLabel.getValue());
                    getUI().addWindow(dataEntryLayout);

                }
            });
            return icon;
        }
    });

}

From source file:com.mechanicshop.components.TableLayout.java

public void createCustomMessage() {
    final TextArea textArea = new TextArea();
    textArea.setImmediate(true);//from   w w w  .ja va  2s .c  o m
    textArea.setColumns(30);
    textArea.setRows(10);
    textArea.addStyleName(ValoTheme.TEXTAREA_SMALL);
    textArea.setRequired(true);
    final Window subWindow = new Window();
    subWindow.setModal(true);
    subWindow.setHeight("350px");
    subWindow.setWidth("500px");
    subWindow.setCaption("Insert Message");
    subWindow.setStyleName(ValoTheme.WINDOW_TOP_TOOLBAR);
    subWindow.setClosable(false);
    subWindow.setResizable(false);

    HorizontalLayout layoutButtons = new HorizontalLayout();
    layoutButtons.setMargin(false);
    Button sendBtn = new Button("Send");
    sendBtn.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            try {
                textArea.validate();
                String message = textArea.getValue();
                smsSenderService.sendMessageMassive(message);
                subWindow.close();
                Notification.show("Message Sent");
            } catch (Exception e) {

            }
        }
    });
    sendBtn.setImmediate(true);
    sendBtn.setStyleName(ValoTheme.BUTTON_TINY);
    sendBtn.addStyleName(ValoTheme.BUTTON_FRIENDLY);
    Button cancelBtn = new Button("Cancel");
    cancelBtn.setStyleName(ValoTheme.BUTTON_TINY);
    cancelBtn.addStyleName(ValoTheme.BUTTON_DANGER);
    cancelBtn.setImmediate(true);
    cancelBtn.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            subWindow.close();

        }
    });

    layoutButtons.setSizeUndefined();
    layoutButtons.setSpacing(true);
    layoutButtons.addComponents(cancelBtn, sendBtn);

    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);
    layout.setMargin(true);
    layout.addComponent(textArea);
    layout.addComponent(layoutButtons);
    layout.setComponentAlignment(textArea, Alignment.MIDDLE_CENTER);
    layout.setComponentAlignment(layoutButtons, Alignment.MIDDLE_RIGHT);
    layout.setExpandRatio(textArea, 3);

    layout.setSizeFull();

    subWindow.setContent(layout);
    subWindow.center();

    getUI().addWindow(subWindow);
}

From source file:com.moscaville.ui.CsvVaadinUI.java

private void buildTemplateGridHeader() {
    HorizontalLayout templateGridHeaderLayout = new HorizontalLayout();
    templateGridHeaderLayout.setSpacing(true);
    templateGridHeaderLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);

    Button btnNew = new Button("New", FontAwesome.FILE);
    btnNew.setDescription("New template file");
    btnNew.addClickListener((Button.ClickEvent event) -> {
        templateManager.newTemplate();// w  w w  .j  a  v a  2  s. co m
    });
    templateGridHeaderLayout.addComponent(btnNew);

    Button btnOpen = new Button("Open", FontAwesome.FILE_O);
    btnOpen.setDescription("Open template file");
    btnOpen.addClickListener((Button.ClickEvent event) -> {
        fileChooser.setFileExtension(FileChooser.FILE_EXTENSION_TEMPLATE);
        addWindow(fileChooser);
    });
    templateGridHeaderLayout.addComponent(btnOpen);

    Button btnSave = new Button("Save", FontAwesome.SAVE);
    tfTemplateFileName = new TextField();
    tfTemplateFileName.setDescription("template file name");
    tfTemplateFileName.setInputPrompt("template file name");
    tfTemplateFileName.setImmediate(true);
    tfTemplateFileName.addValueChangeListener((Property.ValueChangeEvent event) -> {
        btnSave.setEnabled(tfTemplateFileName.getValue() != null && tfTemplateFileName.getValue().length() > 0);
    });
    templateGridHeaderLayout.addComponent(tfTemplateFileName);

    FieldGroup binder = new FieldGroup(templateManager.getTemplateBeanItem());
    binder.setBuffered(false);
    binder.bind(tfTemplateFileName, "templateFileName");

    btnSave.setDescription("Save template file");
    btnSave.setImmediate(true);
    btnSave.setEnabled(false);
    btnSave.addClickListener((Button.ClickEvent event) -> {
        templateManager.saveTemplate();
    });
    templateGridHeaderLayout.addComponent(btnSave);

    Button btnData = new Button("Data", FontAwesome.DATABASE);
    btnData.setDescription("Load data");
    btnData.addClickListener((Button.ClickEvent event) -> {
        fileChooser.setFileExtension(FileChooser.FILE_EXTENSION_CSV);
        addWindow(fileChooser);
    });
    templateGridHeaderLayout.addComponent(btnData);

    Button btnImport = new Button("Import", FontAwesome.DOWNLOAD);

    templateGridHeaderLayout.addComponent(btnImport);
    mainLayout.addComponent(templateGridHeaderLayout);
}

From source file:com.moscaville.ui.CsvVaadinUI.java

private void buildTemplateGrid() {
    VerticalLayout templateGridLayout = new VerticalLayout();
    templateGridLayout.setSpacing(true);
    templateGrid.setWidth("100%");
    templateGrid.setHeight("300px");
    templateGridLayout.addComponent(templateGrid);
    HorizontalLayout tgButtonLayout = new HorizontalLayout();
    tgButtonLayout.setSpacing(true);//from  w  w w . j a  va  2 s  .c om
    Button btnAddTemplate = new Button("Add", FontAwesome.PLUS_SQUARE);
    btnAddTemplate.setDescription("Add template");
    btnAddTemplate.addClickListener((Button.ClickEvent event) -> {
        templateManager.addProperty();
    });
    tgButtonLayout.addComponent(btnAddTemplate);
    Button btnDeleteTemplate = new Button("Delete", FontAwesome.MINUS_SQUARE);
    btnDeleteTemplate.setDescription("Delete template");
    btnDeleteTemplate.addClickListener((Button.ClickEvent event) -> {
        Object itemId = templateGrid.getSelectedRow();
        if (itemId != null) {
            templateManager.getContainer().removeItem(itemId);
        }
    });
    tgButtonLayout.addComponent(btnDeleteTemplate);
    templateGridLayout.addComponent(tgButtonLayout);
    mainLayout.addComponent(templateGridLayout);
}

From source file:com.mycollab.mobile.module.crm.view.account.AccountReadViewImpl.java

License:Open Source License

@Override
protected ComponentContainer createBottomPanel() {
    HorizontalLayout toolbarLayout = new HorizontalLayout();
    toolbarLayout.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    toolbarLayout.setSpacing(true);/* w  w  w. ja  va  2 s.c  o m*/

    Button relatedContacts = new Button();
    relatedContacts.setCaption("<span aria-hidden=\"true\" data-icon=\"" + IconConstants.CRM_CONTACT
            + "\"></span><div class=\"screen-reader-text\">" + UserUIContext.getMessage(ContactI18nEnum.LIST)
            + "</div>");
    relatedContacts.setHtmlContentAllowed(true);
    relatedContacts.addClickListener(clickEvent -> EventBusFactory.getInstance()
            .post(new AccountEvent.GoToRelatedItems(this, new CrmRelatedItemsScreenData(associateContacts))));
    toolbarLayout.addComponent(relatedContacts);

    Button relatedOpportunities = new Button();
    relatedOpportunities.setCaption("<span aria-hidden=\"true\" data-icon=\"" + IconConstants.CRM_OPPORTUNITY
            + "\"></span><div class=\"screen-reader-text\">"
            + UserUIContext.getMessage(OpportunityI18nEnum.LIST) + "</div>");
    relatedOpportunities.setHtmlContentAllowed(true);
    relatedOpportunities.addClickListener(clickEvent -> EventBusFactory.getInstance().post(
            new AccountEvent.GoToRelatedItems(this, new CrmRelatedItemsScreenData(associateOpportunities))));
    toolbarLayout.addComponent(relatedOpportunities);

    Button relatedLeads = new Button();
    relatedLeads.setCaption("<span aria-hidden=\"true\" data-icon=\"" + IconConstants.CRM_LEAD
            + "\"></span><div class=\"screen-reader-text\">" + UserUIContext.getMessage(LeadI18nEnum.LIST)
            + "</div>");
    relatedLeads.setHtmlContentAllowed(true);
    relatedLeads.addClickListener(clickEvent -> EventBusFactory.getInstance()
            .post(new AccountEvent.GoToRelatedItems(this, new CrmRelatedItemsScreenData(associateLeads))));
    toolbarLayout.addComponent(relatedLeads);

    Button relatedActivities = new Button();
    relatedActivities.setCaption("<span aria-hidden=\"true\" data-icon=\"" + IconConstants.CRM_ACTIVITY
            + "\"></span><div class=\"screen-reader-text\">"
            + UserUIContext.getMessage(CrmCommonI18nEnum.TAB_ACTIVITY) + "</div>");
    relatedActivities.setHtmlContentAllowed(true);
    relatedActivities.addClickListener(clickEvent -> EventBusFactory.getInstance()
            .post(new AccountEvent.GoToRelatedItems(this, new CrmRelatedItemsScreenData(associateActivities))));
    toolbarLayout.addComponent(relatedActivities);

    return toolbarLayout;
}