List of usage examples for com.vaadin.ui TextField setValue
@Override public void setValue(String value)
From source file:com.cerebro.provevaadin.ChatOffGame.java
public ChatOffGame() { Panel messagesPanel = new Panel(); messagesPanel.setSizeFull();/* w w w.j a v a2 s . c om*/ messagesPanel.setContent(messages); this.addComponent(messagesPanel); this.setExpandRatio(messagesPanel, 1.0f); HorizontalLayout sendBar = new HorizontalLayout(); sendBar.setWidth("100%"); final TextField input = new TextField(); input.setWidth("100%"); sendBar.addComponent(input); sendBar.setExpandRatio(input, 1.0f); Button send = new Button("Send"); send.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); send.addClickListener((Button.ClickEvent event) -> { BroadcasterOffGame.broadcast(input.getValue(), FROM); input.setValue(""); }); sendBar.addComponent(send); this.addComponent(sendBar); BroadcasterOffGame.register(this); }
From source file:com.cerebro.provevaadin.ChatOnGame.java
public ChatOnGame(User user) { if (user.getUltimoLuogoPG() != null) { logger.info("Luogo: " + user.getUltimoLuogoPG()); } else {/*from w w w .j a va 2 s. c o m*/ logger.info("Nessun luogo selezionato"); } Panel messagesPanel = new Panel(); messagesPanel.setSizeFull(); messagesPanel.setContent(messages); this.addComponent(messagesPanel); this.setExpandRatio(messagesPanel, 1.0f); HorizontalLayout sendBar = new HorizontalLayout(); sendBar.setWidth("100%"); final TextField input = new TextField(); input.setWidth("100%"); sendBar.addComponent(input); sendBar.setExpandRatio(input, 1.0f); Button send = new Button("Send"); send.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); send.addClickListener((Button.ClickEvent event) -> { logger.info("Invio del messaggio al server"); BroadcasterOnGame.broadcast(input.getValue(), FROM); input.setValue(""); }); sendBar.addComponent(send); this.addComponent(sendBar); BroadcasterOnGame.register(this); }
From source file:com.cerebro.provevaadin.database.Configurazione.java
public Configurazione() { System.out.println("Componente per la personalizzazione"); this.setMargin(true); TextField db_host = new TextField("Database Host Name"); db_host.isRequired();// w w w . j ava 2s . c o m TextField db_port = new TextField("Database Port"); db_port.isRequired(); TextField db_user = new TextField("Username"); db_user.isRequired(); PasswordField db_pwd = new PasswordField("Password"); db_pwd.isRequired(); PasswordField pwd_conf = new PasswordField("Conferma Password"); pwd_conf.setImmediate(true); 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(MySQLServer.class.getName()).log(Level.SEVERE, null, ex); } } db_host.setValue(props.getProperty("db_host")); db_user.setValue(props.getProperty("db_user")); Button salva = new Button("Salva"); salva.addClickListener((Button.ClickEvent event) -> { System.out.println("Salvo i parametri"); if (db_host.isValid() && db_port.isValid() && db_user.isValid() && db_pwd.isValid() && pwd_conf.getValue().equals(db_pwd.getValue())) { String dbHost = "jdbc:mysql://" + db_host.getValue() + ":" + db_port.getValue() + "/grizzly?useSSL=false&serverTimezone=UTC"; props.setProperty("db_host", dbHost); props.setProperty("db_user", db_user.getValue()); props.setProperty("db_pwd", db_pwd.getValue()); 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(Configurazione.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) { Logger.getLogger(Configurazione.class.getName()).log(Level.SEVERE, null, ex); } Notification.show("Parametri salvati"); } else { Notification.show("Ricontrolla i parametri"); } }); Button test = new Button("Test per i parametri salvati"); test.addClickListener((Button.ClickEvent event) -> { System.out.println("Testo i parametri"); MySQLServer mysql = new MySQLServer(); JDBCConnectionPool conn = mysql.getJDBCConnPool(); if (!mysql.testJDBCConnPool(conn)) { Notification.show("Errore nella connessione al database"); } else { Notification.show("Connessione avvenuta con successo"); } }); this.addComponents(db_host, db_port, db_user, db_pwd, pwd_conf, salva, test); }
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 ww w . ja va2s. co 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 ww w. j a v a 2 s.c o m*/ 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.component.CustomPageTable.java
public HorizontalLayout createControls(String pageSizeDefault) { this.pageSizeDefault = pageSizeDefault; separatorTotal.setImmediate(true);/* ww w . java 2s. co m*/ Label itemsPerPageLabel = new Label(BundleUtils.getString("common.table.numberRecord")); for (String numberSize : Constants.PAGE_SIZE_LIST) { itemsPerPageSelect.addItem(numberSize); } itemsPerPageSelect.setImmediate(true); itemsPerPageSelect.setNullSelectionAllowed(false); itemsPerPageSelect.setWidth("50px"); itemsPerPageSelect.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = -2255853716069800092L; @Override public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) { setPageLength(Integer.valueOf(String.valueOf(event.getProperty().getValue()))); firePagedChangedEvent(); } }); itemsPerPageSelect.select(pageSizeDefault); Label pageLabel = new Label(BundleUtils.getString("common.table.page"), ContentMode.HTML); final TextField currentPageTextField = new TextField(); currentPageTextField.setValue(String.valueOf(getCurrentPage())); currentPageTextField.setConverter(Integer.class); currentPageTextField .addValidator(new IntegerRangeValidator("Wrong page number", 1, getTotalAmountOfPages())); Label separatorLabel = new Label(" / ", ContentMode.HTML); final Label totalPagesLabel = new Label(String.valueOf(getTotalAmountOfPages()), ContentMode.HTML); currentPageTextField.setStyleName(Reindeer.TEXTFIELD_SMALL); currentPageTextField.setImmediate(true); currentPageTextField.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = -2255853716069800092L; @Override public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) { currentPageTextField.removeAllValidators(); currentPageTextField .addValidator(new IntegerRangeValidator("Wrong page number", 1, getTotalAmountOfPages())); if (Integer.valueOf(String.valueOf(currentPageTextField.getValue())) <= getTotalAmountOfPages()) { int page = Integer.valueOf(String.valueOf(currentPageTextField.getValue())); setCurrentPage(page); } } }); pageLabel.setWidth(null); currentPageTextField.setWidth("30px"); separatorLabel.setWidth(null); totalPagesLabel.setWidth(null); HorizontalLayout controlBar = new HorizontalLayout(); HorizontalLayout pageSize = new HorizontalLayout(); HorizontalLayout pageManagement = new HorizontalLayout(); final Button first = new Button("<<", new Button.ClickListener() { private static final long serialVersionUID = -355520120491283992L; @Override public void buttonClick(Button.ClickEvent event) { setCurrentPage(0); } }); previous = new Button("<", new Button.ClickListener() { private static final long serialVersionUID = -355520120491283992L; @Override public void buttonClick(Button.ClickEvent event) { previousPage(); } }); final Button next = new Button(">", new Button.ClickListener() { private static final long serialVersionUID = -1927138212640638452L; @Override public void buttonClick(Button.ClickEvent event) { nextPage(); } }); final Button last = new Button(">>", new Button.ClickListener() { private static final long serialVersionUID = -355520120491283992L; @Override public void buttonClick(Button.ClickEvent event) { setCurrentPage(getTotalAmountOfPages()); } }); first.setStyleName(Reindeer.BUTTON_LINK); previous.setStyleName(Reindeer.BUTTON_LINK); next.setStyleName(Reindeer.BUTTON_LINK); last.setStyleName(Reindeer.BUTTON_LINK); itemsPerPageLabel.addStyleName("pagedtable-itemsperpagecaption"); itemsPerPageSelect.addStyleName("pagedtable-itemsperpagecombobox"); pageLabel.addStyleName("pagedtable-pagecaption"); currentPageTextField.addStyleName("pagedtable-pagefield"); separatorLabel.addStyleName("pagedtable-separator"); separatorTotal.addStyleName("pagedtable-separator"); totalPagesLabel.addStyleName("pagedtable-total"); first.addStyleName("pagedtable-first"); previous.addStyleName("pagedtable-previous"); next.addStyleName("pagedtable-next"); last.addStyleName("pagedtable-last"); itemsPerPageLabel.addStyleName("pagedtable-label"); itemsPerPageSelect.addStyleName("pagedtable-combobox"); pageLabel.addStyleName("pagedtable-label"); currentPageTextField.addStyleName("pagedtable-label"); separatorLabel.addStyleName("pagedtable-label"); separatorTotal.addStyleName("pagedtable-label"); totalPagesLabel.addStyleName("pagedtable-label"); first.addStyleName("pagedtable-button"); previous.addStyleName("pagedtable-button"); next.addStyleName("pagedtable-button"); last.addStyleName("pagedtable-button"); pageSize.addComponent(itemsPerPageLabel); pageSize.addComponent(itemsPerPageSelect); Label separator = new Label(" / ", ContentMode.HTML); pageSize.addComponent(separator); pageSize.addComponent(separatorTotal); pageSize.setComponentAlignment(itemsPerPageLabel, Alignment.MIDDLE_LEFT); pageSize.setComponentAlignment(itemsPerPageSelect, Alignment.MIDDLE_LEFT); pageSize.setComponentAlignment(separator, Alignment.MIDDLE_LEFT); pageSize.setComponentAlignment(separatorTotal, Alignment.MIDDLE_LEFT); pageSize.setSpacing(true); pageManagement.addComponent(first); pageManagement.addComponent(previous); pageManagement.addComponent(pageLabel); pageManagement.addComponent(currentPageTextField); pageManagement.addComponent(separatorLabel); pageManagement.addComponent(totalPagesLabel); pageManagement.addComponent(next); pageManagement.addComponent(last); pageManagement.setComponentAlignment(first, Alignment.MIDDLE_LEFT); pageManagement.setComponentAlignment(previous, Alignment.MIDDLE_LEFT); pageManagement.setComponentAlignment(pageLabel, Alignment.MIDDLE_LEFT); pageManagement.setComponentAlignment(currentPageTextField, Alignment.MIDDLE_LEFT); pageManagement.setComponentAlignment(separatorLabel, Alignment.MIDDLE_LEFT); pageManagement.setComponentAlignment(totalPagesLabel, Alignment.MIDDLE_LEFT); pageManagement.setComponentAlignment(next, Alignment.MIDDLE_LEFT); pageManagement.setComponentAlignment(last, Alignment.MIDDLE_LEFT); pageManagement.setWidth(null); pageManagement.setSpacing(true); controlBar.addComponent(pageSize); controlBar.addComponent(pageManagement); controlBar.setComponentAlignment(pageManagement, Alignment.MIDDLE_CENTER); controlBar.setWidth("100%"); controlBar.setExpandRatio(pageSize, 1); addListener(new PageChangeListener() { @Override public void pageChanged(PagedTableChangeEvent event) { int abc = event.getCurrentPage(); first.setEnabled(container.getStartIndex() > 0); previous.setEnabled(container.getStartIndex() > 0); next.setEnabled(container.getStartIndex() < container.getRealSize() - getPageLength()); last.setEnabled(container.getStartIndex() < container.getRealSize() - getPageLength()); currentPageTextField.setValue(String.valueOf(getCurrentPage())); totalPagesLabel.setValue(String.valueOf(getTotalAmountOfPages())); if (resizePage) { int lenght = getPageLength(); int a = lenght % 5; int b = lenght / 5; if (a != 0) { int pageLenght = 5 * (b + 1); itemsPerPageSelect.setValue(pageLenght); } } separatorTotal.setValue(String.valueOf(container.getRealSize())); } }); return controlBar; }
From source file:com.cms.utils.ShortcutUtils.java
public static void doTextChangeUppercase(final TextField field) { field.addTextChangeListener(new FieldEvents.TextChangeListener() { @Override//from w ww. j a v a 2s. com public void textChange(FieldEvents.TextChangeEvent event) { try { field.setValue(event.getText().toUpperCase()); // workaround cursor position problem field.setCursorPosition(event.getCursorPosition()); field.validate(); } catch (InvalidValueException e) { e.printStackTrace(); } } }); }
From source file:com.cms.utils.ShortcutUtils.java
public static void doTextChangePhoneNumber(final TextField field) { field.addTextChangeListener(new FieldEvents.TextChangeListener() { @Override/* w w w. j a v a 2 s .c o m*/ public void textChange(FieldEvents.TextChangeEvent event) { try { String phone; if (field.getValue().length() < 10) { field.setBuffered(true); phone = event.getText(); field.setValue(phone); } if (field.getValue().length() >= 10) { field.setCursorPosition(event.getCursorPosition()); phone = convertText2PhoneFormat(event.getText()); field.setValue(phone); } if (field.getValue().length() == 11) { field.setCursorPosition(event.getCursorPosition()); phone = convertText2PhoneFormat(event.getText()); field.setValue(phone); } field.validate(); } catch (InvalidValueException e) { e.printStackTrace(); } } }); }
From source file:com.cms.utils.ShortcutUtils.java
public static void doTextTrim(final TextField field) { field.addTextChangeListener(new FieldEvents.TextChangeListener() { @Override//from ww w .j a va2 s .c o m public void textChange(FieldEvents.TextChangeEvent event) { try { field.setValue(event.getText().trim()); // workaround cursor position problem field.setCursorPosition(event.getCursorPosition()); field.validate(); } catch (InvalidValueException e) { e.printStackTrace(); } } }); }
From source file:com.coatl.vaadin.abc.ixDefinicionDeForma.java
void vaciarMapa(Map m) { Iterator<String> i = m.keySet().iterator(); while (i.hasNext()) { String nombre = i.next(); AbstractComponent cValor = componentes.get(nombre); Object valor = m.get(nombre); if (cValor instanceof TextField) { TextField tf = (TextField) cValor; boolean ro = tf.isReadOnly(); tf.setReadOnly(false);//from w w w . j a v a 2 s . c o m tf.setValue((String) valor); tf.setReadOnly(ro); } if (cValor instanceof CheckBox) { CheckBox tf = (CheckBox) cValor; boolean ro = tf.isReadOnly(); tf.setReadOnly(false); ((CheckBox) cValor).setValue((Boolean) valor); tf.setReadOnly(ro); } } }