Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.squadd.UI; import com.squadd.entities.Contacts; import com.squadd.entities.UserInfo; import com.vaadin.data.Property; import com.vaadin.data.Property.ValueChangeListener; import com.vaadin.server.UserError; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.Component; import com.vaadin.ui.FormLayout; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Layout; import com.vaadin.ui.Notification; import com.vaadin.ui.PasswordField; import com.vaadin.ui.TextField; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * * @author SharkNado */ public class MainInformationLayout extends FormLayout { private TextField login; private boolean inUse = true; private PasswordField password; private PasswordField confirmed; public void setLogin(TextField login) { this.login = login; } public void setPassword(PasswordField password) { this.password = password; } public void setConfirmed(PasswordField confirmed) { this.confirmed = confirmed; } public TextField getLogin() { return login; } public PasswordField getPassword() { return password; } public PasswordField getConfirmed() { return confirmed; } public MainInformationLayout() { configureComponents(); buildLayout(); configureActions(); } private void configureComponents() { login = new TextField("Login"); password = new PasswordField("Password"); confirmed = new PasswordField("Confirm Password"); } private void buildLayout() { HorizontalLayout emailLayout = new HorizontalLayout(login); centerAligningComponent(emailLayout, login); HorizontalLayout passwordLayout = new HorizontalLayout(password); centerAligningComponent(passwordLayout, password); HorizontalLayout confirmLayout = new HorizontalLayout(confirmed); centerAligningComponent(confirmLayout, confirmed); addComponents(emailLayout, passwordLayout, confirmLayout); } private void centerAligningComponent(HorizontalLayout where, Component what) { where.setSizeFull(); where.setComponentAlignment(what, Alignment.TOP_CENTER); } private void configureActions() { configureFieldActions(); } private void configureFieldActions() { ValueChangeListener clearErrorTextFields = new ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { TextField curr = (TextField) event.getProperty(); curr.setComponentError(null); } }; ValueChangeListener clearErrorPassFields = new ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { PasswordField curr = (PasswordField) event.getProperty(); curr.setComponentError(null); } }; login.addValueChangeListener(clearErrorTextFields); password.addValueChangeListener(clearErrorPassFields); confirmed.addValueChangeListener(clearErrorPassFields); } public boolean isInUse() { return inUse; } public void setInUse(boolean inUse) { this.inUse = inUse; } }