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.anphat.list.controller.MapStaffCustomerController.java

/**
 * Khoi tao cac bang//w  w  w .  j  av a 2  s.  c om
 */
private void initTables() {
    tblUtils = new TableUtils();
    //Khoi tao bang khach hang
    panelTableCustomer = mapStaffCustomerDialog.getPanelTblCustomer();
    tblCustomer = panelTableCustomer.getMainTable();
    tblUtils.generateColumn(tblCustomer);
    containerCustomer = new BeanItemContainer(CustomerDTO.class);
    CommonFunctionTableFilter.initTable(panelTableCustomer, HEADER_CUSTOMER, containerCustomer,
            CAPTION_CUSTOMER, 5, "customer");

    //Khoi tao bang khach hang
    panelTableMapStaffCustomer = mapStaffCustomerDialog.getPanelTblCustomerStatus();
    tblStaffMapCustomer = panelTableMapStaffCustomer.getMainTable();
    tblUtils.generateColumn(tblStaffMapCustomer);
    containerMapStaffCustomer = new BeanItemContainer(StaffDTO.class);
    containerMapStaffCustomer.addAll(lstStaffs);
    //Them nut chi tiet
    tblStaffMapCustomer.addGeneratedColumn("detail", new CustomTable.ColumnGenerator() {
        @Override
        public Object generateCell(CustomTable source, Object itemId, Object columnId) {
            final StaffDTO staff = (StaffDTO) itemId;
            if (DataUtil.isListNullOrEmpty(staff.getLstCustomers())) {
                return "";
            } else {
                Button btnDetail = new Button(BundleUtils.getString("statistic.list.detail"));
                btnDetail.setDisableOnClick(true);
                btnDetail.addStyleName(Runo.BUTTON_LINK);
                btnDetail.addStyleName("v-link-button-left");
                btnDetail.addClickListener(new Button.ClickListener() {
                    @Override
                    public void buttonClick(Button.ClickEvent event) {
                        CustomerDialog customerDialog = new CustomerDialog(mapServices, mapCustServiceStatus);
                        customerDialog.setData2Table(staff.getLstCustomers());
                        UI.getCurrent().addWindow(customerDialog);
                        event.getButton().setEnabled(true);
                    }
                });
                return btnDetail;
            }

        }
    });
    //Them nut so luong
    tblStaffMapCustomer.addGeneratedColumn("quanlity", new CustomTable.ColumnGenerator() {
        @Override
        public Object generateCell(CustomTable source, Object itemId, Object columnId) {
            StaffDTO staff = (StaffDTO) itemId;
            if (DataUtil.isListNullOrEmpty(staff.getLstCustomers())) {
                return 0;
            } else {
                return staff.getLstCustomers().size();
            }
        }
    });
    CommonFunctionTableFilter.initTable(panelTableMapStaffCustomer, HEADER_MAP_STAFF_CUSTOMER,
            containerMapStaffCustomer, CAPTION_MAP_STAFF_CUSTOMER, 5, "customerStatusForm");
}

From source file:com.anphat.list.controller.MapStaffCustomerViewController.java

/**
 * Khoi tao cac bang//from   w  ww  . j av a  2  s.  c o  m
 */
private void initTables() {
    tblUtils = new TableUtils();
    //Khoi tao bang khach hang
    panelTableCustomer = mapStaffCustomerView.getPanelTblCustomer();
    tblCustomer = panelTableCustomer.getMainTable();
    tblUtils.generateColumn(tblCustomer);
    containerCustomer = new BeanItemContainer(CustomerDTO.class);
    CommonFunctionTableFilter.initTable(panelTableCustomer, HEADER_CUSTOMER, containerCustomer,
            CAPTION_CUSTOMER, 5, "customer");
    CommonUtils.convertFieldTable(tblCustomer, "taxAuthority", mapTaxAuthority);
    //        name#1,startTime#2,endTime#2,taxAuthority#1
    tblCustomer.setColumnExpandRatio("taxCode", 1);
    tblCustomer.setColumnExpandRatio("name", 2);
    tblCustomer.setColumnExpandRatio("startTime", 1);
    tblCustomer.setColumnExpandRatio("endTime", 1);
    tblCustomer.setColumnExpandRatio("taxAuthority", 1);
    //Khoi tao bang khach hang
    panelTableMapStaffCustomer = mapStaffCustomerView.getPanelTblCustomerStatus();
    tblStaffMapCustomer = panelTableMapStaffCustomer.getMainTable();
    tblUtils.generateColumn(tblStaffMapCustomer);
    containerMapStaffCustomer = new BeanItemContainer(StaffDTO.class);
    containerMapStaffCustomer.addAll(lstStaffs);
    //Them nut chi tiet
    tblStaffMapCustomer.addGeneratedColumn("detail", new CustomTable.ColumnGenerator() {
        @Override
        public Object generateCell(CustomTable source, Object itemId, Object columnId) {
            try {
                final StaffDTO staff = (StaffDTO) itemId;

                if (DataUtil.isStringNullOrEmpty(staff.getQuanlity()) || "0".equals(staff.getQuanlity())) {
                    return null;
                } else {
                    Button btnDetail = new Button(BundleUtils.getString("statistic.list.detail"));
                    btnDetail.setDisableOnClick(true);
                    btnDetail.addStyleName(Runo.BUTTON_LINK);
                    btnDetail.addStyleName("v-link-button-left");
                    btnDetail.addClickListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(Button.ClickEvent event) {
                            CustomerDialog customerDialog = new CustomerDialog(mapServices,
                                    mapCustServiceStatus);
                            customerDialog.setData2Table(staff.getLstCustomers());
                            UI.getCurrent().addWindow(customerDialog);
                            event.getButton().setEnabled(true);
                        }
                    });
                    return btnDetail;
                }
            } catch (NullValueInNestedPathException nvnpe) {
                return null;
            }
        }
    });
    //Them nut huy bo
    tblStaffMapCustomer.addGeneratedColumn("cancel", new CustomTable.ColumnGenerator() {
        @Override
        public Object generateCell(final CustomTable source, Object itemId, Object columnId) {
            try {
                final StaffDTO staff = (StaffDTO) itemId;
                if (DataUtil.isStringNullOrEmpty(staff.getQuanlity()) || "0".equals(staff.getQuanlity())) {
                    return null;
                } else {
                    Button btnDetail = new Button(BundleUtils.getString("statistic.list.cancel"));
                    btnDetail.setDisableOnClick(true);
                    btnDetail.addStyleName(Runo.BUTTON_LINK);
                    btnDetail.addStyleName("v-link-button-left");
                    btnDetail.addClickListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(Button.ClickEvent event) {
                            doReset(staff);
                        }
                    });
                    return btnDetail;
                }
            } catch (NullValueInNestedPathException nvnpe) {
                return null;
            }
        }
    });
    CommonFunctionTableFilter.initTable(panelTableMapStaffCustomer, HEADER_MAP_STAFF_CUSTOMER,
            containerMapStaffCustomer, CAPTION_MAP_STAFF_CUSTOMER, 5, "customerStatusForm");

}

From source file:com.arcusys.liferay.vaadinplugin.ControlPanelUI.java

License:Apache License

private Button createChangeVersionButton() {
    Button button = new Button("Change version");
    button.setStyleName(BaseTheme.BUTTON_LINK);
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            ChangeVersionWindow window = new ChangeVersionWindow();
            addWindow(window);//from   w  w w  .java2  s  .c o m
            window.initialize();
        }
    });
    return button;
}

From source file:com.arcusys.liferay.vaadinplugin.ControlPanelUI.java

License:Apache License

private Button createDetailsButton() {
    Button button = new Button("Details");
    button.setStyleName(BaseTheme.BUTTON_LINK);
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            addWindow(new DetailsWindow());
        }//w w w . j  a va  2  s  .co m
    });
    return button;
}

From source file:com.arcusys.liferay.vaadinplugin.ControlPanelUI.java

License:Apache License

private Button createUpdateVaadinVersionButton() {
    Button button = new Button("Upgrade");
    button.setImmediate(true);//w w  w  . ja v  a  2  s.co  m
    button.setStyleName(BaseTheme.BUTTON_LINK);
    button.addClickListener(new Button.ClickListener() {

        public void buttonClick(Button.ClickEvent event) {

            if (!newestDownloadInfo.isExists()) {
                Notification.show(WARNING_UPGRADE_VAADIN_VERSION_NOT_FOUND, Notification.Type.ERROR_MESSAGE);
                return;
            }

            outputLog.log("Location for download: " + newestDownloadInfo.getDownloadUrl());

            try {
                addWindow(new WarningWindow(newestDownloadInfo));
            } catch (Exception ex) {
                outputLog.log(ex.getMessage());
            }
        }
    });
    return button;
}

From source file:com.blogspot.markogronroos.MainUI.java

License:GNU General Public License

protected void jpaContTable(AbstractOrderedLayout main) {
    final VerticalLayout layout = new VerticalLayout();
    main.addComponent(layout);//from   www.ja v a2 s.  co  m
    show(layout, "Please notice table rows are selectable, column order movable, column sort order adjustable");

    // Create a persistent person container
    JPAContainer<Trip> trips = JPAContainerFactory.make(Trip.class, "source.jpa");
    // You can add entities to the container as well
    trips.addEntity(new Trip("Riga", "Brussels", 5.0F));
    trips.addEntity(new Trip("London", "Riga", 101.0F));

    // Bind it to a component
    Table personTable = new Table("Past Trips", trips);

    personTable.setSizeUndefined();
    personTable.setSelectable(true);
    personTable.setMultiSelect(false);
    personTable.setImmediate(true);
    personTable.setColumnReorderingAllowed(true);
    personTable.setColumnCollapsingAllowed(true);

    personTable.setVisibleColumns(new String[] { "id", "price", "startLocation", "finishLocation" });
    layout.addComponent(personTable);

    Button button = new Button("Clear");
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            //layout.addComponent(new Label("Thank you for clicking"));
            layout.removeAllComponents();
        }
    });
    layout.addComponent(button);
}

From source file:com.blogspot.markogronroos.MainUI.java

License:GNU General Public License

protected void jpaContTable2(AbstractOrderedLayout main) {
    final VerticalLayout layout = new VerticalLayout();
    main.addComponent(layout);/*w  w w  . j av a 2s  .c  o  m*/
    show(layout, "This is same as above but EntityManager is created explicitly");

    EntityManager em = JPAContainerFactory.createEntityManagerForPersistenceUnit("source.jpa");
    /*
            
       Notice that if you use update the persistent data with an entity manager outside a JPAContainer bound to the 
       data, you need to refresh the container as described in Section 19.4.2, Creating and Accessing Entities?.
            
    Refreshing JPAContainer
            
    In cases where you change JPAContainer items outside the container, for example by through an EntityManager, 
    or when they change in the database, you need to refresh the container.
    The EntityContainer interface implemented by JPAContainer provides two methods to refresh a container. The 
    refresh() discards all container caches and buffers and refreshes all loaded items in the container. All 
    changes made to items provided by the container are discarded. The refreshItem() refreshes a single item.
            
    */
    // Create a persistent person container
    JPAContainer<Trip> trips = JPAContainerFactory.make(Trip.class, em);

    // You can add entities to the container as well
    trips.addEntity(new Trip("Riga", "Brussels", 5.0F));
    trips.addEntity(new Trip("London", "Riga", 101.0F));

    // Bind it to a component
    Table personTable = new Table("Past Trips", trips);

    personTable.setSizeUndefined();
    personTable.setSelectable(true);
    personTable.setMultiSelect(false);
    personTable.setImmediate(true);
    personTable.setColumnReorderingAllowed(true);
    personTable.setColumnCollapsingAllowed(true);

    personTable.setVisibleColumns(new String[] { "id", "price", "startLocation", "finishLocation" });
    layout.addComponent(personTable);

    Button button = new Button("Clear");
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            //layout.addComponent(new Label("Thank you for clicking"));
            layout.removeAllComponents();
        }
    });
    layout.addComponent(button);
}

From source file:com.blogspot.markogronroos.MainUI.java

License:GNU General Public License

protected void jpaContForm1(AbstractOrderedLayout main) {
    final VerticalLayout layout = new VerticalLayout();
    main.addComponent(layout);/*  www. java 2 s. co m*/
    show(layout, "JPAContainer Form Example enterd!");

    // Have a persistent container
    final JPAContainer<Trip> trips = JPAContainerFactory.make(Trip.class, "source.jpa");
    // For selecting an item to edit
    // Country Editor
    final Form tripForm = new Form();
    tripForm.setCaption("Trip form");

    tripForm.setWidth("420px");
    tripForm.setBuffered(true);
    tripForm.setEnabled(false);
    Object itemId = trips.getIdByIndex(0);
    if (itemId == null)
        show(layout, "Sorry no item retrieved!");
    else {
        show(layout, " choosen item: " + itemId); //+" class: "+itemId.getClass().getName());
        Item tripItem = trips.getItem(itemId);
        show(layout, " Item found :" + tripItem);
        layout.addComponent(tripForm);

        // Use a JPAContainer field factory
        //  - no configuration is needed here
        final FieldFactory fieldFactory = new FieldFactory();
        //fieldFactory.
        tripForm.setFormFieldFactory(fieldFactory);
        // Edit the item in the form
        tripForm.setItemDataSource(tripItem);
        tripForm.setEnabled(true);

        tripForm.setVisibleItemProperties(new String[] { "startLocation", "finishLocation", "status" });
        //tripForm.getField("name").setCaption("name new caption");

        // Handle saves on the form
        final Button save = new Button("Save");
        tripForm.getFooter().addComponent(save);
        save.addClickListener(new ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                try {
                    tripForm.commit();
                    tripForm.setEnabled(false);
                } catch (InvalidValueException e) {
                    e.printStackTrace();
                }
            }
        });

    }

}

From source file:com.cavisson.gui.dashboard.components.calender.HiddenFwdBackButtons.java

License:Apache License

@SuppressWarnings("deprecation")
@Override//from   w w w.  j av a  2 s. c o  m
protected void init(VaadinRequest request) {
    GridLayout content = new GridLayout(1, 2);
    content.setSizeFull();
    setContent(content);

    final Calendar calendar = new Calendar();
    calendar.setLocale(new Locale("fi", "FI"));

    calendar.setSizeFull();
    calendar.setStartDate(new Date(100, 1, 1));
    calendar.setEndDate(new Date(100, 1, 7));
    content.addComponent(calendar);
    Button button = new Button("Hide forward and back buttons");
    button.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            // This should hide the forward and back navigation buttons
            calendar.setHandler((BackwardHandler) null);
            calendar.setHandler((ForwardHandler) null);
        }
    });
    content.addComponent(button);

    content.setRowExpandRatio(0, 1);

}

From source file:com.cavisson.gui.dashboard.components.charts.Impl.ResizeInsideVaadinComponent.java

@Override
protected Component getChart() {

    VerticalSplitPanel verticalSplitPanel = new VerticalSplitPanel();
    HorizontalSplitPanel horizontalSplitPanel = new HorizontalSplitPanel();
    horizontalSplitPanel.setSecondComponent(verticalSplitPanel);
    verticalSplitPanel.setFirstComponent(createChart());

    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setMargin(true);/*from   w ww  . ja v  a 2 s  . c o m*/
    verticalLayout.setSpacing(true);
    verticalLayout.addComponent(
            new Label("Relatively sized components resize themselves automatically when in Vaadin component."));

    Button button = new Button("Open in a window");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Window window = new Window("Chart windodw");
            window.setContent(createChart());
            window.setWidth("50%");
            window.setHeight("50%");

            getUI().addWindow(window);

        }
    });

    verticalLayout.addComponent(button);
    horizontalSplitPanel.setFirstComponent(verticalLayout);

    return horizontalSplitPanel;
}