Example usage for com.vaadin.ui Button addListener

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

Introduction

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

Prototype

@Override
    public Registration addListener(Component.Listener listener) 

Source Link

Usage

From source file:ccm.CCM1.ColorPickerApplication.java

License:Apache License

@Override
public void init() {
    setMainWindow(main);//from ww w.ja  v  a 2  s.  c  o  m

    // Listen for value change events in the custom component,
    // triggered when user clicks a button to select another color.
    colorselector.addListener(new ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            // Provide some server-side feedback
            colorname.setValue("Selected color: " + colorselector.getColor());
        }
    });
    main.addComponent(colorselector);

    // Add another component to give feedback from server-side code
    colorname = new Label("Selected color: " + colorselector.getColor());
    main.addComponent(colorname);

    // Server-side manipulation of the component state
    final Button button = new Button("Set to white");
    button.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            colorselector.setColor("white");
        }
    });
    main.addComponent(button);

    setTheme("mytheme");
}

From source file:cib.ladnyik.MyVaadinApplication.java

License:Apache License

@Override
public void init() {
    Workbook wb = new XSSFWorkbook();
    window = new Window("My Vaadin Application");
    setMainWindow(window);/*from w w  w.java 2s .co m*/
    Button button = new Button("Click Me Two Times Three Times XXX");
    button.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            window.addComponent(new Label("Thank you for clicking"));
            System.out.println("Thank you for clicking");
        }
    });
    window.addComponent(button);

}

From source file:com.bellkenz.modules.PersonalInformation.java

public ComponentContainer personalInformation() {
    employeeInformationDAO = new EmployeeInformationDAO(getEmployeeId());
    employeePersonalInformation = new EmployeePersonalInformation();

    GridLayout glayout = new GridLayout(5, 9);
    glayout.setSpacing(true);//  w w  w  .jav a 2 s.  c om
    glayout.setMargin(true);

    final Panel imagePanel = new Panel();
    imagePanel.setStyleName("light");
    AbstractLayout panelLayout = (AbstractLayout) imagePanel.getContent();
    panelLayout.setMargin(false);
    imagePanel.setSizeFull();

    employeeImage = new Embedded(null, new ThemeResource("../myTheme/images/ronnie.jpg"));
    employeeImage.setImmediate(true);
    employeeImage.setWidth(90, Sizeable.UNITS_PIXELS);
    employeeImage.setHeight(90, Sizeable.UNITS_PIXELS);
    employeeImage.setStyleName("logo-img");
    imagePanel.addComponent(employeeImage);
    glayout.addComponent(employeeImage, 0, 0, 0, 1);
    glayout.setComponentAlignment(imagePanel, Alignment.MIDDLE_CENTER);

    firstname = createTextField("Firstname: ");
    glayout.addComponent(firstname, 1, 0, 2, 0);

    final TextField middlename = createTextField("Middlename: ");
    glayout.addComponent(middlename, 3, 0);

    final TextField lastname = createTextField("Lastname: ");
    glayout.addComponent(lastname, 4, 0);

    final TextField houseNo = createTextField("No: ");
    houseNo.setWidth("40px");
    glayout.addComponent(houseNo, 1, 1);

    final TextField street = createTextField("Street: ");
    street.setWidth("118");
    glayout.addComponent(street, 2, 1);

    final TextField city = createTextField("City: ");
    glayout.addComponent(city, 3, 1);

    final TextField zipCode = createTextField("Zip Code:");
    glayout.addComponent(zipCode, 4, 1);

    final TextField nickname = createTextField("Nickname: ");
    nickname.setWidth("90px");
    glayout.addComponent(nickname, 0, 2);

    final TextField permanentAddress = createTextField("Permanent/Provincial Address: ");
    permanentAddress.setWidth("533px");
    glayout.addComponent(permanentAddress, 1, 2, 4, 2);

    Button uploadPicture = new Button("Upload...");
    uploadPicture.setWidth("100%");
    uploadPicture.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (employeeId == null) {
                getWindow().showNotification("You did not select and Employee!",
                        Window.Notification.TYPE_WARNING_MESSAGE);
                return;
            }

            Window uploadImage = new UploadImage(imagePanel, employeeImage, employeeId);
            uploadImage.setWidth("450px");
            if (uploadImage.getParent() == null) {
                getWindow().addWindow(uploadImage);
            }
            uploadImage.setModal(true);
            uploadImage.center();
        }
    });
    glayout.addComponent(uploadPicture, 0, 3);

    final TextField landline = createTextField("Landline #: ");
    glayout.addComponent(landline, 1, 3, 2, 3);

    final TextField mobileNo = createTextField("Mobile #: ");
    glayout.addComponent(mobileNo, 3, 3);

    final TextField age = createTextField("Age: ");
    glayout.addComponent(age, 4, 3);

    final TextField emailAddress = createTextField("Email Address: ");
    glayout.addComponent(emailAddress, 1, 4, 2, 4);

    final PopupDateField dob = (PopupDateField) createDateField("Date of Birth: ");
    glayout.addComponent(dob, 3, 4);

    final TextField height = createTextField("Height: ");
    glayout.addComponent(height, 4, 4);

    final ComboBox civilStatus = new ComboBox("Civil Status: ");
    civilStatus.setWidth("100%");
    dropDownBoxList.populateCivilStatusList(civilStatus);
    glayout.addComponent(civilStatus, 1, 5, 2, 5);

    final ComboBox gender = new ComboBox("Gender: ");
    gender.setWidth("100%");
    dropDownBoxList.populateGenderList(gender);
    glayout.addComponent(gender, 3, 5);

    final TextField weight = createTextField("Weigth: ");
    glayout.addComponent(weight, 4, 5);

    final TextField driversLicenseNo = createTextField("Drivers License: ");
    glayout.addComponent(driversLicenseNo, 1, 6, 2, 6);

    final TextField restrictionCode = createTextField("Restriction Code: ");
    glayout.addComponent(restrictionCode, 3, 6);

    final TextField religion = createTextField("Religion: ");
    glayout.addComponent(religion, 4, 6);

    final ComboBox division = new ComboBox("Division: ");
    division.setWidth("100%");
    dropDownBoxList.populateBranchComboBox(division);
    glayout.addComponent(division, 1, 7, 2, 7);

    final ComboBox department = dropDownBoxList.populateDepartment(new ComboBox());
    department.setWidth("100%");
    division.addListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            if (division.getValue() == null) {
            } else {
                divisionId = branchDAO.getBranchId(division.getValue().toString());
            }
        }

    });
    glayout.addComponent(department, 3, 7);

    final TextField position = createTextField("Position: ");
    glayout.addComponent(position, 4, 7);
    //glayout.setComponentAlignment(position, Alignment.BOTTOM_LEFT);

    Button transferButton = new Button("Transfer Employee");
    transferButton.setWidth("100%");
    transferButton.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (getEmployeeId() == null) {
                getWindow().showNotification("You did not select an Employee!",
                        Window.Notification.TYPE_WARNING_MESSAGE);
                return;
            }

            Window subWindow = transferEmployee(getEmployeeId(), division, department, position);
            if (subWindow.getParent() == null) {
                getWindow().addWindow(subWindow);
            }
            subWindow.setModal(true);
            subWindow.center();
        }
    });
    glayout.addComponent(transferButton, 1, 8, 2, 8);
    glayout.setComponentAlignment(transferButton, Alignment.BOTTOM_CENTER);

    if (employeeId != null) {
        epiList = employeeInformationDAO.employeePersonalInformation();
        for (EmployeePersonalInformation epi : epiList) {
            final byte[] image = epi.getImage();
            if (image != null) {
                StreamResource.StreamSource imageSource = new StreamResource.StreamSource() {

                    @Override
                    public InputStream getStream() {
                        return new ByteArrayInputStream(image);
                    }

                };

                StreamResource imageResource = new StreamResource(imageSource, epi.getFirstname() + ".jpg",
                        getApplication());
                imageResource.setCacheTime(0);
                employeeImage.setSource(imageResource);
            }
            firstname.setValue(epi.getFirstname());
            middlename.setValue(epi.getMiddlename());
            lastname.setValue(epi.getLastname());
            houseNo.setValue(epi.getHouseNumber());

            street.setValue(epi.getStreet());
            city.setValue(epi.getStreet());
            zipCode.setValue(epi.getZipCode());
            nickname.setValue(epi.getNickname());
            permanentAddress.setValue(epi.getPermanentAddress());
            landline.setValue(epi.getLandlineNumber());
            mobileNo.setValue(epi.getMobileNumber());
            age.setValue(epi.getAge());
            emailAddress.setValue(epi.getEmailAddress());

            if (epi.getDob() != null) {
                dob.setValue(conUtil.parsingDate(epi.getDob()));
            } else {
                dob.setValue(null);
            }

            height.setValue(epi.getHeight());

            if (epi.getCivilStatus() != null) {
                Object civilStatusId = civilStatus.addItem();
                civilStatus.setItemCaption(civilStatusId, epi.getCivilStatus());
                civilStatus.setValue(civilStatusId);
            }

            if (epi.getGender() != null) {
                Object genderId = gender.addItem();
                gender.setItemCaption(genderId, epi.getGender());
                gender.setValue(genderId);
            }

            weight.setValue(epi.getWeight());
            driversLicenseNo.setValue(epi.getDriversLicense());
            restrictionCode.setValue(epi.getRestrictionCode());
            religion.setValue(epi.getReligion());
            position.setValue(epi.getPosition());

            Object divisionObjectId = division.addItem();
            division.setItemCaption(divisionObjectId, epi.getDivision());
            division.setValue(divisionObjectId);

            Object departmentObjectId = department.addItem();
            department.setItemCaption(departmentObjectId, epi.getDepartment());
            department.setValue(departmentObjectId);
        }
    }

    firstname.addListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            employeePersonalInformation.setFirstname(event.getProperty().getValue().toString());
        }
    });
    firstname.setImmediate(true);
    setInformation(employeePersonalInformation);

    return glayout;
}

From source file:com.bellkenz.modules.PersonalInformation.java

public Window transferEmployee(final String employeeId, final ComboBox div, final ComboBox dept,
        final TextField post) {
    VerticalLayout vlayout = new VerticalLayout();
    vlayout.setMargin(true);//from   ww w. j  a v a 2s  . co m
    vlayout.setSpacing(true);

    final Window subWindow = new Window("Transfer Employee", vlayout);
    subWindow.setWidth("200px");

    final ComboBox division = new ComboBox("Division: ");
    division.setWidth("100%");
    dropDownBoxList.populateBranchComboBox(division);
    subWindow.addComponent(division);

    final ComboBox department = dropDownBoxList.populateDepartment(new ComboBox());
    department.setWidth("100%");
    division.addListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            if (division.getValue() == null) {
            } else {
                divisionId = branchDAO.getBranchId(division.getValue().toString());
            }
        }

    });
    subWindow.addComponent(department);

    final TextField position = createTextField("Position: ");
    position.setWidth("100%");
    subWindow.addComponent(position);

    final PopupDateField entryDate = (PopupDateField) createDateField("Date of Entry: ");
    subWindow.addComponent(entryDate);

    Button updateButton = new Button("UPDATE");
    updateButton.setWidth("100%");
    updateButton.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (division.getValue() == null) {
                getWindow().showNotification("Select Division!", Window.Notification.TYPE_WARNING_MESSAGE);
                return;
            }

            if (department.getValue() == null) {
                getWindow().showNotification("Select Department!", Window.Notification.TYPE_WARNING_MESSAGE);
                return;
            }

            if (position.getValue() == null || position.getValue().toString().trim().isEmpty()) {
                getWindow().showNotification("Enter Position!", Window.Notification.TYPE_WARNING_MESSAGE);
                return;
            }

            if (entryDate.getValue() == null) {
                getWindow().showNotification("Select Entry Date!", Window.Notification.TYPE_WARNING_MESSAGE);
                return;
            }

            List<EmployeePositionHistory> ephList = new ArrayList<EmployeePositionHistory>();
            EmployeePositionHistory eph = new EmployeePositionHistory();
            eph.setBranch(division.getValue().toString());
            eph.setDepartment(department.getValue().toString());
            eph.setPosition(position.getValue().toString().trim().toLowerCase());
            eph.setEntryDate(conUtil.convertDateFormat(entryDate.getValue().toString()));
            ephList.add(eph);
            Integer deptId = departmentDAO.getDepartmentId(divisionId, department.getValue().toString());
            Boolean result = employeeInformationDAO.transferEmployee(ephList, deptId);
            if (result) {
                Object divObjectId = div.addItem();
                div.setItemCaption(divObjectId, division.getValue().toString());
                div.setValue(divObjectId);

                Object deptObjectId = dept.addItem();
                dept.setItemCaption(deptObjectId, department.getValue().toString());
                dept.setValue(deptObjectId);

                post.setValue(position.getValue().toString().trim().toLowerCase());

                (subWindow.getParent()).removeWindow(subWindow);
            } else {
                getWindow().showNotification("Cannot Transfer employee",
                        Window.Notification.TYPE_ERROR_MESSAGE);
            }
        }
    });
    subWindow.addComponent(updateButton);

    return subWindow;
}

From source file:com.bsb.common.vaadin.embed.component.DevApplicationHeader.java

License:Apache License

/**
 * Creates an new instance with the specified {@link EmbedVaadinServer}
 * to manage.//  w  w  w .  ja  va  2 s  .com
 *
 * @param server the server to manage
 */
public DevApplicationHeader(final EmbedVaadinServer server) {
    final Button shutdown = new Button("shutdown");
    shutdown.setStyleName(BaseTheme.BUTTON_LINK);
    shutdown.setDescription("Shutdown the embed server and close this tab");
    addComponent(shutdown);
    setComponentAlignment(shutdown, Alignment.MIDDLE_CENTER);

    shutdown.addListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            // Stop the server in a separate thread.
            final Thread thread = new Thread(new Runnable() {
                public void run() {
                    server.stop();
                }
            });
            // avoid that catalina's WebappClassLoader.clearReferencesThreads warns about the thread because it is
            // part of the web application being stopped.
            thread.setContextClassLoader(null);

            thread.start();

            // Close the browser tab
            getWindow().executeJavaScript("close();");
        }
    });
}

From source file:com.compomics.sigpep.webapp.MyVaadinApplication.java

License:Apache License

@Override
public void init() {
    iApplication = this;
    iSigPepSessionFactory = ApplicationLocator.getInstance().getApplication().getSigPepSessionFactory();

    //add theme/*from w ww  .j a  v  a2 s.c om*/
    setTheme("sigpep");

    //add main window
    Window lMainwindow = new Window("Sigpep Application");
    setMainWindow(lMainwindow);
    lMainwindow.addStyleName("v-app-my");

    //add notification component
    iNotifique = new Notifique(Boolean.FALSE);
    CustomOverlay lCustomOverlay = new CustomOverlay(iNotifique, getMainWindow());
    getMainWindow().addComponent(lCustomOverlay);

    //add form help
    iFormHelp = new FormHelp();
    iFormHelp.setFollowFocus(Boolean.TRUE);
    this.getMainWindow().getContent().addComponent(iFormHelp);

    //add panels
    iCenterLeft = new Panel();
    iCenterLeft.addStyleName(Reindeer.PANEL_LIGHT);
    iCenterLeft.setHeight("400px");
    iCenterLeft.setWidth("100%");

    iCenterRight = new Panel();
    iCenterRight.addStyleName(Reindeer.PANEL_LIGHT);
    iCenterRight.setHeight("400px");
    iCenterRight.setWidth("75%");

    //add form tabs
    iFormTabSheet = new FormTabSheet(this);
    iCenterLeft.addComponent(iFormTabSheet);

    iBottomLayoutResults = new VerticalLayout();

    if (PropertiesConfigurationHolder.showTestDemoFolder()) {
        Button lButton = new Button("load test data");
        lButton.addListener(new Button.ClickListener() {
            public void buttonClick(Button.ClickEvent event) {
                new BackgroundThread().run();
            }
        });
        iBottomLayoutResults.addComponent(lButton);
    }

    // Add the selector component
    iSelectionComponent = new TransitionSelectionComponent(MyVaadinApplication.this);
    iCenterRight.addComponent(iSelectionComponent);

    iHeaderLayout = new HorizontalLayout();
    iHeaderLayout.setSizeFull();
    iHeaderLayout.setHeight("100px");
    iHeaderLayout.addStyleName("v-header");

    VerticalLayout lVerticalLayout = new VerticalLayout();

    GridLayout lGridLayout = new GridLayout(2, 1);
    lGridLayout.setSpacing(true);
    lGridLayout.setSizeFull();

    lGridLayout.addComponent(iCenterLeft, 0, 0);
    lGridLayout.setComponentAlignment(iCenterLeft, Alignment.TOP_LEFT);

    lGridLayout.addComponent(iCenterRight, 1, 0);
    lGridLayout.setComponentAlignment(iCenterRight, Alignment.TOP_CENTER);

    lVerticalLayout.addComponent(iHeaderLayout);
    lVerticalLayout.addComponent(lGridLayout);
    lVerticalLayout.addComponent(iBottomLayoutResults);

    lVerticalLayout.setComponentAlignment(iHeaderLayout, Alignment.MIDDLE_CENTER);
    lVerticalLayout.setComponentAlignment(lGridLayout, Alignment.MIDDLE_CENTER);
    lVerticalLayout.setComponentAlignment(iBottomLayoutResults, Alignment.MIDDLE_CENTER);

    lMainwindow.addComponent(lVerticalLayout);
    lMainwindow.addComponent(pusher);

    // Create a tracker for vaadin.com domain.
    String lDomainName = PropertiesConfigurationHolder.getInstance().getString("analytics.domain");
    String lPageId = PropertiesConfigurationHolder.getInstance().getString("analytics.page");

    GoogleAnalyticsTracker tracker = new GoogleAnalyticsTracker("UA-26252212-1", lDomainName);
    lMainwindow.addComponent(tracker);
    tracker.trackPageview(lPageId);

    /**
     * Sets an UncaughtExceptionHandler and executes the thread by the ExecutorsService
     */
    Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler());

    parseSessionId();
}

From source file:com.concur.ui.WebApp.java

License:Apache License

private Window createWindow() {
    FormLayout fl = new FormLayout();

    //        final SessionGuard sg = new SessionGuard();
    //        sg.setKeepalive(true);
    //        fl.addComponent(sg);

    fl.setSizeFull();/*  w  w  w  .  j  a  v  a2s  .  c  om*/
    fl.setMargin(true);
    fl.addComponent(new Label("<h2>ATS Tuple Store -- Demo App<h2/>", Label.CONTENT_XML));

    actionField = new NativeSelect("Action:");
    actionField.addItem("Authenticate");
    actionField.addItem("GetTuple");
    actionField.addItem("PutTuple");
    actionField.addItem("GetConfigurations");
    actionField.select("Authenticate");
    fl.addComponent(actionField);

    tokenField = new TextField("Authentication Token:");
    tokenField.setColumns(40);
    fl.addComponent(tokenField);

    tupleKeyField = new TextField("TupleKey:");
    tupleKeyField.setColumns(40);
    fl.addComponent(tupleKeyField);

    tupleDataArea = new TextArea("TupleData:");
    tupleDataArea.setColumns(40);
    tupleDataArea.setRows(5);
    fl.addComponent(tupleDataArea);

    Button b = new Button("Send Request");
    b.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            submit();
        }
    });

    fl.addComponent(b);

    final Window w = new Window("ATS Tuple Store -- DEMO");
    w.setContent(fl);
    return w;
}

From source file:com.conx.logistics.kernel.ui.editors.vaadin.tests.MyVaadinApplication.java

License:Apache License

@Override
public void init() {
    window = new Window("My Vaadin Application");
    setMainWindow(window);//from w w  w.  ja v  a  2s  . c  o  m
    Button button = new Button("Click Me!");
    button.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            window.addComponent(new Label("Thank you for clicking!!!"));
        }
    });
    window.addComponent(button);

}

From source file:com.digitallabs.demos.Vaadin6BootstrapThemeDemo.java

License:Apache License

@Override
public void init() {
    setTheme("bootstrap");

    window = new Window("My Vaadin Application");
    setMainWindow(window);/* w  w  w. j  a v  a  2 s .  com*/
    Button button = new Button("Click Me");
    button.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            window.addComponent(new Label("Thank you for clicking"));
        }
    });

    CssLayout container = new CssLayout();
    container.setWidth("100%");
    container.addStyleName("container");

    typography(container);
    tables(container);
    forms(container);
    buttons(container);

    window.setContent(container);

}

From source file:com.fatminds.vaadin.cmis.components.CmisList.java

License:Apache License

public void addDeleteButtonColumn() {
    this.addGeneratedColumn("Delete", new Table.ColumnGenerator() {
        public Component generateCell(Table source, Object itemId, Object columnId) {
            CmisItem item = (CmisItem) getItem(itemId);
            // the Link -component:
            Button itemsButton = new Button("X");
            itemsButton.setData(item);/*from   w  w  w. j  a v  a2s.c  om*/
            itemsButton.addListener(new Button.ClickListener() {

                public void buttonClick(ClickEvent event) {
                    final CmisItem item = (CmisItem) event.getButton().getData();
                    setSelectedItem(item);
                    getContainerDataSource().removeItem(item.getItemId());

                    /**
                     * In practice, you'll want to confirm before deleting...
                     * 
                     * 
                                       ConfirmDialog.show(CatalogManagerApplication.getCurrentNavigableAppLevelWindow(), "Please Confirm:", "Are you sure you want to delete this item.?",
                       "Yes", "No", new ConfirmDialog.Listener() {
                            
                           public void onClose(ConfirmDialog dialog) {
                               if (dialog.isConfirmed()) {
                                   // Confirmed to continue
                                  container.removeItem(item.getItemId());
                               } 
                           }
                       });
                    **/
                }

            });

            return itemsButton;
        }

    });
}