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.cerebro.provevaadin.Game.java

public Game() {

    Subject currentUser = SecurityUtils.getSubject();

    this.addComponent(new Label("Area di gioco"));

    Button logout = new Button("Esci");
    this.addComponent(logout);
    logout.addClickListener((Button.ClickEvent e) -> {
        logger.info("Esco dall'applicazione");
        logger.info("Pulsante: " + e.toString());
        SecurityUtils.getSubject().logout();
        UI.getCurrent().getSession().close();
        UI.getCurrent().getPage().setLocation("");
    });/*from w  w  w .  j  a  va 2 s  . co m*/
}

From source file:com.cerebro.provevaadin.Secure.java

public Secure() {

    HorizontalLayout top = new HorizontalLayout();
    this.addComponent(top);
    top.addComponent(new Label("Area sicura"));

    VerticalLayout content = new VerticalLayout();
    this.addComponent(content);

    Navigator nav = new Navigator(UI.getCurrent(), content);
    nav.setErrorView(new ErrorView());
    nav.addView("", new HomeView());
    nav.navigateTo("");

    Button logout = new Button("Logout");
    logout.addClickListener((Button.ClickEvent event) -> {
        System.out.println("Esco dalla sessione");
        SecurityUtils.getSubject().logout();
        UI.getCurrent().getSession().close();
        UI.getCurrent().getPage().setLocation("");
    });//from  w  w  w.  j  av a 2  s . c o m
    top.addComponent(logout);
}

From source file:com.cerebro.provevaadin.SendConfEmail.java

public SendConfEmail() {
    Button send = new Button("Spedisci");
    send.addClickListener((Button.ClickEvent event) -> {
        try {//from  w w w . j  a  v a2  s  .  c  o  m
            client = new MailjetClient("328cd563c1977097c524f1981f92c8b5", "896ed8a77847d131bffd62668edea39c");
            request = new MailjetRequest(Email.resource)
                    .property(Email.FROMEMAIL, "info@ambulatorio-vet-athena.it")
                    .property(Email.FROMNAME, "Matteo Casagrande").property(Email.SUBJECT, "Email di prova")
                    .property(Email.TEXTPART, "Testo semplice di prova")
                    .property(Email.HTMLPART, "<h1>Testo in html</h1>")
                    .property(Email.RECIPIENTS, new JSONArray()
                            .put(new JSONObject().put("Email", "dottmatteocasagrande@gmail.com")));
            response = client.post(request);
            System.out.println(response.getData());
        } catch (MailjetException ex) {
            Logger.getLogger(SendConfEmail.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MailjetSocketTimeoutException ex) {
            Logger.getLogger(SendConfEmail.class.getName()).log(Level.SEVERE, null, ex);
        }
    });
    this.addComponent(send);
}

From source file:com.cerebro.provevaadin.SignIn.java

private VerticalLayout setFirstStep() {
    VerticalLayout firstStep = new VerticalLayout();
    CssLayout header = new CssLayout();
    Label title = new Label("Benvenuto " + u.getNomeUtente() + "!");
    Label istructions = new Label("Crea il tuo personaggio");
    Label step = new Label("1/*");
    header.addComponents(title, istructions, step);
    HorizontalLayout body = new HorizontalLayout();
    FormLayout datiIniziali = new FormLayout();
    TextField nomePG = new TextField("Nome del Personaggio");
    TextField cognomePG = new TextField("Cognome del Personaggio");
    OptionGroup sessoPG = new OptionGroup("Sesso del Personaggio");
    sessoPG.addItems("Maschio", "Femmina");
    ComboBox razzaPG = new ComboBox("Razza");
    datiIniziali.addComponents(nomePG, cognomePG, sessoPG, razzaPG);
    HorizontalLayout descrizioneRazza = new HorizontalLayout();
    descrizioneRazza.setWidth(datiIniziali.getWidth(), datiIniziali.getWidthUnits());
    //        Dettagli di popolazione e comportamento ComboBox
    razzaPG.addItem("Essere umano");
    body.addComponents(datiIniziali, descrizioneRazza);
    CssLayout footer = new CssLayout();
    Button next = new Button("Avanti ->");
    next.addClickListener((Button.ClickEvent event) -> {
        u.setNomePG(nomePG.getValue());//from   ww  w.  j  av a 2  s .  com
        u.setCognomePG(cognomePG.getValue());
        u.setSessoPG(sessoPG.getValue().toString());
        u.setRazzaPG(razzaPG.getValue().toString());
        this.setContent(setSecondStep());
    });
    footer.addComponents(next, createCancelButton());

    firstStep.addComponents(header, body, footer);
    return firstStep;
}

From source file:com.cerebro.provevaadin.SignIn.java

private VerticalLayout setSecondStep() {
    VerticalLayout secondStep = new VerticalLayout();
    CssLayout header = new CssLayout();
    Label title = new Label("Benvenuto " + u.getNomeUtente() + "!");
    Label istructions = new Label("Crea il tuo personaggio");
    Label step = new Label("2/*");
    header.addComponents(title, istructions, step);
    VerticalLayout body = new VerticalLayout();
    Label ageIstruction = new Label("Indica l'et del tuo personaggio in anni");
    // Cambiare i parametri in base alla razza
    Slider age = new Slider(1, 150);
    age.setImmediate(true);//  www.j av  a  2 s  . c o m
    age.setSizeFull();
    HorizontalLayout ageDescription = new HorizontalLayout();
    ageDescription.setHeight("250px");
    Label ageText = new Label("Valore dell'et: ");
    Label ageValue = new Label(age.getValue().toString());
    Label periodoVita = new Label("");
    ageDescription.addComponents(ageText, ageValue, periodoVita);
    age.addValueChangeListener((Property.ValueChangeEvent event) -> {
        System.out.println("Valore: " + age.getValue().toString());
        ageValue.setValue(age.getValue().toString());
        Double value = (100 * (age.getValue()) / (age.getMax()));
        if (value < 14) {
            periodoVita.setValue("Bambino");
        } else if (value > 14 && value < 24) {
            periodoVita.setValue("Adolescenza");
        } else if (value > 24 && value < 73) {
            periodoVita.setValue("Et adulta");
        } else if (value > 73) {
            periodoVita.setValue("Et anziana");
        }
    });
    body.addComponents(ageIstruction, age, ageDescription);
    CssLayout footer = new CssLayout();
    Button next = new Button("Avanti ->");
    next.addClickListener((Button.ClickEvent event) -> {
        u.setEtaPG(age.getValue().toString());
        this.setContent(setThirdStep());
    });
    footer.addComponents(next, createCancelButton());

    secondStep.addComponents(header, body, footer);
    return secondStep;
}

From source file:com.cerebro.provevaadin.SignIn.java

private Component setThirdStep() {
    VerticalLayout thirdStep = new VerticalLayout();
    CssLayout header = new CssLayout();
    Label title = new Label("Benvenuto " + u.getNomeUtente() + "!");
    Label istructions = new Label("Crea il tuo personaggio");
    Label step = new Label("3/*");
    header.addComponents(title, istructions, step);
    HorizontalLayout body = new HorizontalLayout();
    VerticalLayout carrieraPanel = new VerticalLayout();
    ComboBox carriera = new ComboBox("Scegli la tua carriera:");
    carriera.addItem("Guerriero");
    HorizontalLayout descrizioneCarriera = new HorizontalLayout();
    // Comportamento ComboBox
    carrieraPanel.addComponents(carriera, descrizioneCarriera);
    VerticalLayout orientamentoPanel = new VerticalLayout();
    ComboBox orientamento = new ComboBox("Scegli il tuo orientamento");
    orientamento.addItem("Buono Ordine");
    HorizontalLayout descrizioneOrientamento = new HorizontalLayout();
    // Comportamento ComboBox
    orientamentoPanel.addComponents(orientamento, descrizioneOrientamento);
    body.addComponents(carrieraPanel, orientamentoPanel);
    CssLayout footer = new CssLayout();
    Button next = new Button("Avanti ->");
    next.addClickListener((Button.ClickEvent event) -> {
        u.setCarrieraPG(carriera.getValue().toString());
        u.setOrientamentoPG(orientamento.getValue().toString());
        this.setContent(setFourthStep());
    });//from   ww w  . j a v a 2 s . c  om
    footer.addComponents(next, createCancelButton());
    thirdStep.addComponents(header, body, footer);
    return thirdStep;
}

From source file:com.cerebro.provevaadin.SignIn.java

private Component setFourthStep() {
    VerticalLayout fourthStep = new VerticalLayout();
    CssLayout header = new CssLayout();
    Label title = new Label("Benvenuto " + u.getNomeUtente() + "!");
    Label istructions = new Label("Crea il tuo personaggio");
    Label step = new Label("3/*");
    header.addComponents(title, istructions, step);
    CssLayout body = new CssLayout();
    Label resoconto = new Label("Stai per registrare il seguente personaggio: ");
    Label nomePG = new Label(u.getNomePG());
    CssLayout footer = new CssLayout();
    Button next = new Button("Fine");
    next.addClickListener((Button.ClickEvent event) -> {
        // Salvare i dati nel database, inviare la mail, rimandare all'ultima pagina
        this.setContent(setFourthStep());
    });/*from  w  ww  .  j a v  a2  s .co m*/
    footer.addComponents(next, createCancelButton());
    fourthStep.addComponents(header, body, footer);
    return fourthStep;
}

From source file:com.cerebro.provevaadin.smtp.ConfigurazioneSMTP.java

public ConfigurazioneSMTP() {

    this.setMargin(true);

    TextField smtpHost = new TextField("SMTP Host Server");
    smtpHost.setRequired(true);//from w w  w.j  a v a2  s .c  o  m
    TextField smtpPort = new TextField("SMTP Port");
    smtpPort.setRequired(true);
    TextField smtpUser = new TextField("SMTP Username");
    smtpUser.setRequired(true);
    TextField smtpPwd = new TextField("SMTP Password");
    smtpPwd.setRequired(true);
    TextField pwdConf = new TextField("Conferma la Password");
    pwdConf.setRequired(true);
    CheckBox security = new CheckBox("Sicurezza del server");

    Properties props = new Properties();
    InputStream config = VaadinServlet.getCurrent().getServletContext()
            .getResourceAsStream("/WEB-INF/config.properties");
    if (config != null) {
        System.out.println("Carico file di configurazione");
        try {
            props.load(config);
        } catch (IOException ex) {
            Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
    smtpHost.setValue(props.getProperty("smtp_host"));
    smtpUser.setValue(props.getProperty("smtp_user"));
    security.setValue(Boolean.parseBoolean(props.getProperty("smtp_sec")));

    Button salva = new Button("Salva i parametri");
    salva.addClickListener((Button.ClickEvent event) -> {
        System.out.println("Salvo i parametri SMTP");
        if (smtpHost.isValid() && smtpPort.isValid() && smtpUser.isValid() && smtpPwd.isValid()
                && smtpPwd.getValue().equals(pwdConf.getValue())) {
            props.setProperty("smtp_host", smtpHost.getValue());
            props.setProperty("smtp_port", smtpPort.getValue());
            props.setProperty("smtp_user", smtpUser.getValue());
            props.setProperty("smtp_pwd", smtpPwd.getValue());
            props.setProperty("smtp_sec", security.getValue().toString());
            String webInfPath = VaadinServlet.getCurrent().getServletConfig().getServletContext()
                    .getRealPath("WEB-INF");
            File f = new File(webInfPath + "/config.properties");
            try {
                OutputStream o = new FileOutputStream(f);
                try {
                    props.store(o, "Prova");
                } catch (IOException ex) {
                    Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex);
            }
            Notification.show("Parametri salvati");
        } else {
            Notification.show("Ricontrolla i parametri");
        }

    });

    TextField emailTest = new TextField("Destinatario Mail di Prova");
    emailTest.setImmediate(true);
    emailTest.addValidator(new EmailValidator("Mail non valida"));

    Button test = new Button("Invia una mail di prova");
    test.addClickListener((Button.ClickEvent event) -> {
        System.out.println("Invio della mail di prova");
        if (emailTest.isValid()) {
            try {
                System.out.println("Invio mail di prova a " + emailTest.getValue());
                HtmlEmail email = new HtmlEmail();
                email.setHostName(props.getProperty("smtp_host"));
                email.setSmtpPort(Integer.parseInt(props.getProperty("smtp_port")));
                email.setSSLOnConnect(Boolean.parseBoolean(props.getProperty("smtp_sec")));
                email.setAuthentication(props.getProperty("smtp_user"), props.getProperty("smtp_pwd"));
                email.setFrom("prova@prova.it");
                email.setSubject("Mail di prova");
                email.addTo(emailTest.getValue());
                email.setHtmlMsg("This is the message");
                email.send();
            } catch (EmailException ex) {
                Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex);
            }

        } else {
            Notification.show("Controlla l'indirizzo mail del destinatario");
        }
    });

    this.addComponents(smtpHost, smtpPort, smtpUser, smtpPwd, pwdConf, security, salva, emailTest, test);

}

From source file:com.cerebro.provevaadin.smtp.ConfigurazioneSMTPSpring.java

public ConfigurazioneSMTPSpring() {

    TextField smtpHost = new TextField("SMTP Host Server");
    smtpHost.setRequired(true);/*from  w  ww. java2 s. com*/
    TextField smtpPort = new TextField("SMTP Port");
    smtpPort.setRequired(true);
    TextField smtpUser = new TextField("SMTP Username");
    smtpUser.setRequired(true);
    PasswordField smtpPwd = new PasswordField("SMTP Password");
    smtpPwd.setRequired(true);
    PasswordField pwdConf = new PasswordField("Conferma la Password");
    pwdConf.setRequired(true);
    CheckBox security = new CheckBox("Sicurezza del server");

    Properties props = new Properties();
    InputStream config = VaadinServlet.getCurrent().getServletContext()
            .getResourceAsStream("/WEB-INF/config.properties");
    if (config != null) {
        System.out.println("Carico file di configurazione");
        try {
            props.load(config);
        } catch (IOException ex) {
            Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
    smtpHost.setValue(props.getProperty("mail.smtp.host"));
    smtpUser.setValue(props.getProperty("smtp_user"));
    security.setValue(Boolean.parseBoolean(props.getProperty("smtp_sec")));

    Button salva = new Button("Salva i parametri");
    salva.addClickListener((Button.ClickEvent event) -> {
        System.out.println("Salvo i parametri SMTP");
        if (smtpHost.isValid() && smtpPort.isValid() && smtpUser.isValid() && smtpPwd.isValid()
                && smtpPwd.getValue().equals(pwdConf.getValue())) {
            System.out.println(smtpHost.getValue() + smtpPort.getValue() + smtpUser.getValue()
                    + smtpPwd.getValue() + security.getValue().toString());
            props.setProperty("mail.smtp.host", smtpHost.getValue());
            props.setProperty("mail.smtp.port", smtpPort.getValue());
            props.setProperty("smtp_user", smtpUser.getValue());
            props.setProperty("smtp_pwd", smtpPwd.getValue());
            props.setProperty("mail.smtp.ssl.enable", security.getValue().toString());
            String webInfPath = VaadinServlet.getCurrent().getServletConfig().getServletContext()
                    .getRealPath("WEB-INF");
            File f = new File(webInfPath + "/config.properties");
            try {
                OutputStream o = new FileOutputStream(f);
                try {
                    props.store(o, "Prova");
                } catch (IOException ex) {
                    Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex);
            }
            Notification.show("Parametri salvati");
        } else {
            Notification.show("Ricontrolla i parametri");
        }

    });

    TextField emailTest = new TextField("Destinatario Mail di Prova");
    emailTest.setImmediate(true);
    emailTest.addValidator(new EmailValidator("Mail non valida"));

    Button test = new Button("Invia una mail di prova");
    test.addClickListener((Button.ClickEvent event) -> {
        System.out.println("Invio della mail di prova");
        if (emailTest.isValid() && !emailTest.isEmpty()) {
            System.out.println("Invio mail di prova a " + emailTest.getValue());
            JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
            mailSender.setJavaMailProperties(props);
            mailSender.setUsername(props.getProperty("smtp_user"));
            mailSender.setPassword(props.getProperty("smtp_pwd"));
            MimeMessage message = mailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(message);
            try {
                helper.setFrom("dottmatteocasagrande@gmail.com");
                helper.setSubject("Subject");
                helper.setText("It works!");
                helper.addTo(emailTest.getValue());
                mailSender.send(message);
            } catch (MessagingException ex) {
                Logger.getLogger(ConfigurazioneSMTPSpring.class.getName()).log(Level.SEVERE, null, ex);
            }

        } else {
            Notification.show("Controlla l'indirizzo mail del destinatario");
        }
    });

    this.addComponents(smtpHost, smtpPort, smtpUser, smtpPwd, pwdConf, security, salva, emailTest, test);

}

From source file:com.cms.utils.CommonUtils.java

public static GridManyButton getCommonButtonDialog(final CommonDialog dialog) {
    String[] commonBtn = new String[] { BundleUtils.getString("common.button.save"),
            BundleUtils.getString("common.button.cancel") };
    GridManyButton gridManyButton = new GridManyButton(commonBtn);
    Button btnCancel = gridManyButton.getBtnCommon().get(1);
    btnCancel.addClickListener(new Button.ClickListener() {

        @Override/*from  w  ww. j  av a  2  s  .c  om*/
        public void buttonClick(Button.ClickEvent event) {
            dialog.close();
        }
    });
    return gridManyButton;
}