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:com.fatminds.vaadin.cmis.components.CmisList.java

License:Apache License

public void addAssociationButtonColumn(final String headerText, final String buttonTextAdd,
        final String buttonTextRemove, final String dialogTextConfirmAdd, final String dialogTextConfirmRemove,
        final CmisAssociationContainer assocContainer, final CmisObject associationSource) {
    this.addGeneratedColumn(headerText, new Table.ColumnGenerator() {
        public Component generateCell(Table source, final Object itemId, final Object columnId) {
            CmisItem item = (CmisItem) getItem(itemId);
            // Find out if this item is already in the association
            boolean isAssociated = assocContainer.containsId(itemId);
            // the Link -component:
            final Button itemsButton = new Button(isAssociated ? buttonTextRemove : buttonTextAdd);
            itemsButton.setData(item);//from ww w .j  ava2  s .  c  o  m
            itemsButton.addListener(new Button.ClickListener() {

                public void buttonClick(ClickEvent event) {
                    final CmisItem item = (CmisItem) event.getButton().getData();
                    setSelectedItem(item);
                    boolean exists = assocContainer.containsId(itemId);
                    if (assocContainer.containsId(itemId)) {
                        assocContainer.removeItem(itemId);
                        itemsButton.setCaption(buttonTextAdd);
                    } else {
                        assocContainer.addItem(item);
                        itemsButton.setCaption(buttonTextRemove);
                    }
                    /**
                     * Preferred impl needs an app-level window to display its confirmation dialog; replace with your favorite flavor 
                     * (we use an adaptation of navigator7)
                     * 
                     *                       ConfirmDialog.show(CatalogManagerApplication.getCurrentNavigableAppLevelWindow(), 
                     "Please Confirm", 
                     (exists ? dialogTextConfirmRemove : dialogTextConfirmAdd),
                       "Yes", 
                       "No", 
                       new ConfirmDialog.Listener() {
                            
                           public void onClose(ConfirmDialog dialog) {
                               if (dialog.isConfirmed()) {
                                   // Confirmed to continue
                                  if (assocContainer.containsId(itemId)) {
                                     assocContainer.removeItem(itemId);
                                     itemsButton.setCaption(buttonTextAdd);
                                  }
                                  else {
                                      assocContainer.addItem(item);
                                      itemsButton.setCaption(buttonTextRemove);
                                  }
                               } 
                           }
                       });
                    **/
                }

            });

            return itemsButton;
        }
    });
}

From source file:com.foo.AwesomeTestApplication.java

License:Apache License

@Override
public void init() {
    final Window window = new Window("Awesome application to test AwesomeRichTextArea");
    setMainWindow(window);//  ww  w  .  j  a va2s  .  c o  m

    final AwesomeRichTextArea awesomeRichTextArea = new AwesomeRichTextArea();
    window.addComponent(awesomeRichTextArea);

    Button button = new Button("Show me what is selected");
    button.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            window.showNotification("Selected text is: " + awesomeRichTextArea.getSelectedText());
        }
    });

    window.addComponent(button);

}

From source file:com.github.peholmst.mvp4vaadin.navigation.ui.Breadcrumbs.java

License:Apache License

protected void addBreadcrumbForView(final View view) {
    addSeparatorForView(view);//  w w w.  ja  v  a2s  . co m
    final Button btn = getButtonFactory().createButton(view);
    final NavigationRequest navigationRequest = NavigationRequestBuilder.newInstance()
            .startWithPathToView(getController(), view).buildRequest();
    btn.addListener(new Button.ClickListener() {

        private static final long serialVersionUID = 5199653237630939848L;

        @Override
        public void buttonClick(ClickEvent event) {
            getController().navigate(navigationRequest);
        }
    });
    viewButtonMap.put(view, btn);
    view.addListener(this);
    addComponent(btn);
    setComponentAlignment(btn, Alignment.MIDDLE_LEFT);
}

From source file:com.github.peholmst.mvp4vaadin.navigation.ui.NavigationBar.java

License:Apache License

/**
 * Adds a breadcrumb to the navigation bar for the specified view. If there
 * already is one or more breadcrumbs in the bar, a separator will be added
 * before the actual navigation button://ww w .  j a v a2 s . co  m
 * 
 * <pre>
 * First view >> Second view >> Third view
 * </pre>
 * 
 * A click on the navigation button will result in a request to the view
 * controller to navigate to that particular view.
 * 
 * @see #addViewButton(String)
 * @see #addViewSeparator()
 * 
 * @param view
 *            the view to add (must not be <code>null</code>).
 */
protected void addBreadcrumbForView(final ControllableView view) {
    if (getViewController().getTrail().size() > 1) {
        Label separator = addViewSeparator();
        separator.setData(view);
    }

    final Button btn = addViewButton(view.getDisplayName());
    btn.setDescription(view.getViewDescription());
    btn.addListener(new Button.ClickListener() {

        private static final long serialVersionUID = -2163467482631873920L;

        @Override
        public void buttonClick(ClickEvent event) {
            getViewController().goToView(view);
        }
    });
    btn.setData(view);
}

From source file:com.github.peholmst.springsecuritydemo.ui.LoginView.java

License:Apache License

@SuppressWarnings("serial")
protected void init() {
    final Panel loginPanel = new Panel();
    loginPanel.setCaption(getApplication().getMessage("login.title"));
    ((VerticalLayout) loginPanel.getContent()).setSpacing(true);

    final TextField username = new TextField(getApplication().getMessage("login.username"));
    username.setWidth("100%");
    loginPanel.addComponent(username);/*  w  ww  .j a v  a 2  s .c om*/

    final TextField password = new TextField(getApplication().getMessage("login.password"));
    password.setSecret(true);
    password.setWidth("100%");
    loginPanel.addComponent(password);

    final Button loginButton = new Button(getApplication().getMessage("login.button"));
    loginButton.setStyleName("primary");
    // TODO Make it possible to submit the form by pressing <Enter> in any
    // of the text fields
    loginPanel.addComponent(loginButton);
    ((VerticalLayout) loginPanel.getContent()).setComponentAlignment(loginButton, Alignment.MIDDLE_RIGHT);
    loginButton.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            final Authentication auth = new UsernamePasswordAuthenticationToken(username.getValue(),
                    password.getValue());
            try {
                if (logger.isDebugEnabled()) {
                    logger.debug("Attempting authentication for user '" + auth.getName() + "'");
                }
                Authentication returned = getAuthenticationManager().authenticate(auth);
                if (logger.isDebugEnabled()) {
                    logger.debug("Authentication for user '" + auth.getName() + "' succeeded");
                }
                fireEvent(new LoginEvent(LoginView.this, returned));
            } catch (BadCredentialsException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Bad credentials for user '" + auth.getName() + "'", e);
                }
                getWindow().showNotification(getApplication().getMessage("login.badCredentials.title"),
                        getApplication().getMessage("login.badCredentials.descr"),
                        Notification.TYPE_WARNING_MESSAGE);
            } catch (DisabledException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Account disabled for user '" + auth.getName() + "'", e);
                }
                getWindow().showNotification(getApplication().getMessage("login.disabled.title"),
                        getApplication().getMessage("login.disabled.descr"), Notification.TYPE_WARNING_MESSAGE);
            } catch (LockedException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Account locked for user '" + auth.getName() + "'", e);
                }
                getWindow().showNotification(getApplication().getMessage("login.locked.title"),
                        getApplication().getMessage("login.locked.descr"), Notification.TYPE_WARNING_MESSAGE);
            } catch (Exception e) {
                if (logger.isErrorEnabled()) {
                    logger.error("Error while attempting authentication for user '" + auth.getName() + "'");
                }
                ExceptionUtils.handleException(getWindow(), e);
            }
        }
    });

    HorizontalLayout languages = new HorizontalLayout();
    languages.setSpacing(true);
    final Button.ClickListener languageListener = new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Locale locale = (Locale) event.getButton().getData();
            if (logger.isDebugEnabled()) {
                logger.debug("Changing locale to [" + locale + "] and restarting the application");
            }
            getApplication().setLocale(locale);
            getApplication().close();
        }
    };
    for (Locale locale : getApplication().getSupportedLocales()) {
        if (!getLocale().equals(locale)) {
            final Button languageButton = new Button(getApplication().getLocaleDisplayName(locale));
            languageButton.setStyleName(Button.STYLE_LINK);
            languageButton.setData(locale);
            languageButton.addListener(languageListener);
            languages.addComponent(languageButton);
        }
    }
    loginPanel.addComponent(languages);

    loginPanel.setWidth("300px");

    final HorizontalLayout viewLayout = new HorizontalLayout();
    viewLayout.addComponent(loginPanel);
    viewLayout.setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER);
    viewLayout.setSizeFull();
    viewLayout.setMargin(true);

    setCompositionRoot(viewLayout);
    setSizeFull();
}

From source file:com.hopcroft.vaadin.vaadin_ex.MyVaadinApplication.java

License:Apache License

@Override
public void init() {
    window = new Window("My Vaadin Application");
    setMainWindow(window);/* w ww  .ja v a 2  s . c o m*/
    Button button = new Button("Click Me pl");
    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.invient.vaadin.InvientChartsDemoWin.java

License:Apache License

private void registerSVGAndPrintEvent(final InvientCharts chart) {
    GridLayout gridLayout = new GridLayout(2, 1);
    gridLayout.setWidth("100%");
    gridLayout.setSpacing(true);/* w  w w .  j  a  va2s  . c om*/
    Button svgBtn;
    gridLayout.addComponent(svgBtn = new Button("Get SVG"));
    gridLayout.setComponentAlignment(svgBtn, Alignment.MIDDLE_RIGHT);
    Button printBtn;
    gridLayout.addComponent(printBtn = new Button("Print"));
    gridLayout.setComponentAlignment(printBtn, Alignment.MIDDLE_LEFT);
    rightLayout.addComponent(gridLayout);
    svgBtn.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            chart.addListener(new InvientCharts.ChartSVGAvailableListener() {

                @Override
                public void svgAvailable(ChartSVGAvailableEvent chartSVGAvailableEvent) {
                    logEventInfo("[svgAvailable]" + " svg -> " + chartSVGAvailableEvent.getSVG());
                }
            });
        }
    });
    printBtn.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            chart.print();
        }
    });
}

From source file:com.iton.gittest.HelloGit.MyVaadinApplication.java

License:Apache License

@Override
public void init() {
    window = new Window("My Vaadin Application");
    setMainWindow(window);/*  w w  w  .j  a v a 2  s.  co  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 two"));
        }
    });
    window.addComponent(button);

}

From source file:com.iton.gittest.HelloWorld.MyVaadinApplication.java

License:Apache License

@Override
public void init() {
    window = new Window("My Vaadin Application");
    setMainWindow(window);/*from   ww  w.j  a v a2  s  . com*/
    Button button = new Button("Click Me");
    button.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            Window win = new Window("PopUp Form");
            win.setModal(true);
            win.setScrollable(false);
            win.setDraggable(false);
            win.setResizable(false);
            win.center();
            win.setWidth("350px");
            win.addComponent(new Form());
            window.addWindow(win);
        }
    });
    window.addComponent(button);

}

From source file:com.jiangyifen.ec2.ui.mgr.system.tabsheet.SystemLicence.java

/**
 * added by chb 20140520/*from  w ww . j a v a 2 s .  c om*/
 * @return
 */
private VerticalLayout updateLicenseComponent() {
    VerticalLayout licenseUpdateLayout = new VerticalLayout();
    final VerticalLayout textAreaPlaceHolder = new VerticalLayout();
    final HorizontalLayout buttonPlaceHolder = new HorizontalLayout();
    buttonPlaceHolder.setSpacing(true);

    //
    final Button updateButton = new Button("License");
    updateButton.setData("show");

    //
    final Button cancelButton = new Button("?");

    //
    final TextArea licenseTextArea = new TextArea();
    licenseTextArea.setColumns(30);
    licenseTextArea.setRows(5);
    licenseTextArea.setWordwrap(true);
    licenseTextArea.setInputPrompt("??");

    //Layout
    buttonPlaceHolder.addComponent(updateButton);
    licenseUpdateLayout.addComponent(textAreaPlaceHolder);
    licenseUpdateLayout.addComponent(buttonPlaceHolder);

    //
    cancelButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            textAreaPlaceHolder.removeAllComponents();
            buttonPlaceHolder.removeComponent(cancelButton);
            updateButton.setData("show");
            updateButton.setCaption("License");
        }
    });

    updateButton.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            if (((String) event.getButton().getData()).equals("show")) {
                textAreaPlaceHolder.removeAllComponents();
                textAreaPlaceHolder.addComponent(licenseTextArea);
                buttonPlaceHolder.addComponent(cancelButton);
                event.getButton().setData("updateAndHide");
                event.getButton().setCaption("??");
            } else if (((String) event.getButton().getData()).equals("updateAndHide")) {
                StringReader stringReader = new StringReader(
                        StringUtils.trimToEmpty((String) licenseTextArea.getValue()));
                Properties props = new Properties();
                try {
                    props.load(stringReader);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                stringReader.close();
                //               Boolean isValidvalidateLicense(licenseTextArea.getValue());
                String license_date = props.getProperty(LicenseManager.LICENSE_DATE);
                String license_count = props.getProperty(LicenseManager.LICENSE_COUNT);
                String license_localmd5 = props.getProperty(LicenseManager.LICENSE_LOCALMD5);
                //
                Boolean isMatch = regexMatchCheck(license_date, license_count, license_localmd5);
                if (isMatch) {

                    Map<String, String> licenseMap = new HashMap<String, String>();
                    //??
                    //                  String license_count = (String)props.get(LicenseManager.LICENSE_COUNT);
                    license_count = license_count == null ? "" : license_count;
                    licenseMap.put(LicenseManager.LICENSE_COUNT, license_count);

                    //?
                    //                  String license_date = (String)props.get(LicenseManager.LICENSE_DATE);
                    license_date = license_date == null ? "" : license_date;
                    licenseMap.put(LicenseManager.LICENSE_DATE, license_date);

                    //???
                    //                  String license_localmd5 = (String)props.get(LicenseManager.LICENSE_LOCALMD5);
                    license_localmd5 = license_localmd5 == null ? "" : license_localmd5;
                    licenseMap.put(LicenseManager.LICENSE_LOCALMD5, license_localmd5);

                    //?License
                    Map<String, String> resultMap = LicenseManager.licenseValidate(licenseMap);

                    String validateResult = resultMap.get(LicenseManager.LICENSE_VALIDATE_RESULT);
                    if (LicenseManager.LICENSE_VALID.equals(validateResult)) {
                        //continue
                    } else {
                        NotificationUtil.showWarningNotification(SystemLicence.this,
                                "License ?License");
                        return;
                    }

                    try {
                        URL resourceurl = SystemLicence.class.getResource(LicenseManager.LICENSE_FILE);
                        //System.err.println("chb: SystemLicense"+resourceurl.getPath());
                        OutputStream fos = new FileOutputStream(resourceurl.getPath());
                        props.store(fos, "license");
                    } catch (Exception e) {
                        e.printStackTrace();
                        NotificationUtil.showWarningNotification(SystemLicence.this, "License ");
                        return;
                    }
                    textAreaPlaceHolder.removeAllComponents();
                    buttonPlaceHolder.removeComponent(cancelButton);
                    updateButton.setData("show");
                    updateButton.setCaption("License");
                    LicenseManager.loadLicenseFile(LicenseManager.LICENSE_FILE.substring(1));
                    //                  LicenseManager.loadLicenseFile(licenseFilename)
                    refreshLicenseInfo();
                    NotificationUtil.showWarningNotification(SystemLicence.this,
                            "License ?,?");
                } else {
                    NotificationUtil.showWarningNotification(SystemLicence.this,
                            "License ??");
                }
            }
        }

        /**
         * license ?
         * @param license_date
         * @param license_count
         * @param license_localmd5
         * @return
         */
        private Boolean regexMatchCheck(String license_date, String license_count, String license_localmd5) {
            if (StringUtils.isEmpty(license_date) || StringUtils.isEmpty(license_count)
                    || StringUtils.isEmpty(license_localmd5)) {
                return false;
            }
            String date_regex = "^\\d{4}-\\d{2}-\\d{2}\\s\\d{2}:\\d{2}:\\d{2}$"; //?
            String count_regex = "^\\d+$"; //?
            String md5_32_regex = "^\\w{32}$"; //?
            return license_localmd5.matches(md5_32_regex) && license_date.matches(date_regex)
                    && license_count.matches(count_regex);
        }
    });

    return licenseUpdateLayout;
}