Example usage for com.vaadin.ui PasswordField PasswordField

List of usage examples for com.vaadin.ui PasswordField PasswordField

Introduction

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

Prototype

public PasswordField(ValueChangeListener<String> valueChangeListener) 

Source Link

Document

Constructs a new PasswordField with a value change listener.

Usage

From source file:annis.gui.admin.NewPasswordWindow.java

License:Apache License

public NewPasswordWindow(final String userName, final List<UserListView.Listener> listeners) {
    setCaption("Set new password for user \"" + userName + "\"");
    setModal(true);/*from w  w  w.ja  v a 2 s.  c  om*/

    FormLayout layout = new FormLayout();
    setContent(layout);

    final PasswordField txtPassword1 = new PasswordField("Enter new password");
    final PasswordField txtPassword2 = new PasswordField("Repeat new password");

    txtPassword1.setValidationVisible(true);
    txtPassword1.setRequired(true);

    txtPassword2.addValidator(new Validator() {

        @Override
        public void validate(Object value) throws Validator.InvalidValueException {
            String asString = (String) value;
            if (asString != null && !asString.equals(txtPassword1.getValue())) {
                throw new InvalidValueException("Passwords are not the same");
            }
        }
    });
    txtPassword2.setRequired(true);
    txtPassword2.setValidationVisible(true);

    Button btOk = new Button("Ok");
    btOk.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    btOk.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            try {
                txtPassword1.validate();
                txtPassword2.validate();

                if (txtPassword1.isValid() && txtPassword2.isValid()) {
                    for (UserListView.Listener l : listeners) {
                        l.passwordChanged(userName, txtPassword1.getValue());
                    }
                    UI.getCurrent().removeWindow(NewPasswordWindow.this);
                    Notification.show("Password for user \"" + userName + "\" was changed");
                } else {

                }
            } catch (Validator.InvalidValueException ex) {
                Notification n = new Notification("Validation failed", ex.getHtmlMessage(), Type.ERROR_MESSAGE,
                        true);
                n.show(Page.getCurrent());
            }
        }
    });

    Button btCancel = new Button("Cancel");
    btCancel.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            UI.getCurrent().removeWindow(NewPasswordWindow.this);
        }
    });

    HorizontalLayout actionLayout = new HorizontalLayout(btOk, btCancel);

    layout.addComponent(txtPassword1);
    layout.addComponent(txtPassword2);
    layout.addComponent(actionLayout);
}

From source file:ar.com.zir.cipres.ui.forms.CipresSystemUserForm.java

@Override
protected void bindAdditionalFields(FieldGroup binder) {
    super.bindAdditionalFields(binder);
    PasswordField pwd = new PasswordField("Contrasea");
    pwd.setRequired(true);//from  w w  w  .  ja  va  2s .  com
    pwd.setImmediate(true);
    pwd.setReadOnly(true);
    pwd.addValueChangeListener((Property.ValueChangeEvent event) -> {
        //            if (isEditing() && getFieldValue("password") != null && getFieldValue("password").equals("000000")) {
        //                Notification.show("Password invlido", Notification.Type.ERROR_MESSAGE);
        //                setFieldValue("password", null);
        //            }
        updateUiPersistence(action, getBeanItem().getBean(), true);
    });
    pwd.addTextChangeListener((TextChangeEvent event) -> {
        if (event.getText().equals("000000")) {
            Notification.show("Password invlido", Notification.Type.ERROR_MESSAGE);
            setFieldValue("password", null);
        }
    });
    pwd.setTextChangeEventMode(AbstractTextField.TextChangeEventMode.EAGER);
    pwd.addStyleName("visible");
    pwd.setNullRepresentation("");
    registerField("password", pwd);
    binder.bind(pwd, "password");
    grid.addComponent(pwd);
    grid.setRows(2);
    grid.addComponent(getTwinCol(binder), 0, 1, 1, 1);
}

From source file:at.peppol.webgui.app.LoginWindow.java

License:Mozilla Public License

private void init() {

    HorizontalLayout h1 = new HorizontalLayout();
    h1.setSizeFull();// ww w  .  j  a  v a  2  s. c  o m

    FormLayout fl = new FormLayout();
    fl.setSizeUndefined();
    usernameField = new TextField("Username:");
    usernameField.setImmediate(true);
    fl.addComponent(usernameField);
    passwordField = new PasswordField("Password:");
    passwordField.setImmediate(true);
    fl.addComponent(passwordField);

    Button loginButton = new Button("Login");
    loginButton.addStyleName("default");
    loginButton.addListener(this);
    fl.addComponent(loginButton);
    loginButton.setClickShortcut(KeyCode.ENTER);

    h1.addComponent(fl);
    h1.setComponentAlignment(fl, Alignment.MIDDLE_CENTER);
    addComponent(h1);

}

From source file:by.bigvova.LoginUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    getPage().setTitle("Vaadin Shared Security Demo Login");

    FormLayout loginForm = new FormLayout();
    loginForm.setSizeUndefined();/*from  w w w  .j av  a2s .  co m*/

    userName = new TextField("Username");
    passwordField = new PasswordField("Password");
    rememberMe = new CheckBox("Remember me");
    login = new Button("Login");
    Label label = new Label("Name: User / Password: password");
    loginForm.addComponent(userName);
    loginForm.addComponent(passwordField);
    loginForm.addComponent(rememberMe);
    loginForm.addComponent(login);
    login.addStyleName(ValoTheme.BUTTON_PRIMARY);
    login.setDisableOnClick(true);
    login.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    login.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            login();
        }
    });

    VerticalLayout loginLayout = new VerticalLayout();
    loginLayout.setSpacing(true);
    loginLayout.setSizeUndefined();

    if (request.getParameter("logout") != null) {
        loggedOutLabel = new Label("You have been logged out!");
        loggedOutLabel.addStyleName(ValoTheme.LABEL_SUCCESS);
        loggedOutLabel.setSizeUndefined();
        loginLayout.addComponent(loggedOutLabel);
        loginLayout.setComponentAlignment(loggedOutLabel, Alignment.BOTTOM_CENTER);
    }

    loginLayout.addComponent(loginFailedLabel = new Label());
    loginLayout.setComponentAlignment(loginFailedLabel, Alignment.BOTTOM_CENTER);
    loginFailedLabel.setSizeUndefined();
    loginFailedLabel.addStyleName(ValoTheme.LABEL_FAILURE);
    loginFailedLabel.setVisible(false);

    loginLayout.addComponent(label);
    loginLayout.addComponent(loginForm);
    loginLayout.setComponentAlignment(loginForm, Alignment.TOP_CENTER);

    VerticalLayout rootLayout = new VerticalLayout(loginLayout);
    rootLayout.setSizeFull();
    rootLayout.setComponentAlignment(loginLayout, Alignment.MIDDLE_CENTER);
    setContent(rootLayout);
    setSizeFull();
}

From source file:by.bigvova.ui.LoginUI.java

License:Apache License

private Component buildFields() {
    final VerticalLayout layout = new VerticalLayout();
    HorizontalLayout fields = new HorizontalLayout();
    fields.setSpacing(true);//from w  w  w  .  j  av a 2  s  .c  o m
    fields.addStyleName("fields");

    final TextField username = new TextField("Username");
    username.setIcon(FontAwesome.USER);
    username.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);

    final PasswordField password = new PasswordField("Password");
    password.setIcon(FontAwesome.LOCK);
    password.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);

    final Button signin = new Button("Sign In");
    signin.addStyleName(ValoTheme.BUTTON_PRIMARY);
    signin.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    signin.focus();

    final CheckBox checkBox = new CheckBox("Remember me", true);

    signin.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final Button.ClickEvent event) {
            login(username.getValue(), password.getValue(), checkBox.getValue());
        }
    });

    fields.addComponents(username, password, signin);
    fields.setComponentAlignment(signin, Alignment.BOTTOM_LEFT);

    layout.setSpacing(true);
    layout.addComponent(fields);
    layout.addComponent(checkBox);
    return layout;
}

From source file:ch.bfh.ti.soed.hs16.srs.black.view.loginView.LoginView.java

License:Open Source License

public LoginView() {
    usernameField = new TextField("Username");
    usernameField.setIcon(FontAwesome.USER);
    usernameField.setWidth(12, Unit.EM);
    passwordField = new PasswordField("Password");
    passwordField.setIcon(FontAwesome.KEY);
    passwordField.setWidth(12, Unit.EM);
    loginButton = new Button("Login");
    loginButton.setWidth(5, Unit.EM);/*from w  w w .j a  v  a  2 s  .co  m*/
    loginButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
    signUpButton = new Button("Sign Up");
    signUpButton.setWidth(6, Unit.EM);

    VerticalLayout layout = new VerticalLayout();
    HorizontalLayout layoutButtons = new HorizontalLayout(loginButton, signUpButton);
    layoutButtons.setSpacing(true);
    Panel panel = new Panel("Login - Smart ReservationEntity System");
    panel.setSizeUndefined();
    layout.addComponent(panel);

    FormLayout content = new FormLayout();
    content.addComponents(usernameField, passwordField, layoutButtons);
    content.setSizeFull();
    content.setMargin(true);
    panel.setContent(content);

    setCompositionRoot(layout);

    layout.setComponentAlignment(panel, Alignment.MIDDLE_CENTER);
    layout.setMargin(new MarginInfo(true, false, false, false));
}

From source file:ch.bfh.ti.soed.hs16.srs.black.view.signUpView.SignUpView.java

License:Open Source License

public SignUpView() {
    usernameField = new TextField("Username");
    usernameField.setIcon(FontAwesome.USER);
    usernameField.setWidth(12, Unit.EM);
    passwordField = new PasswordField("Password");
    passwordField.setIcon(FontAwesome.KEY);
    passwordField.setWidth(12, Unit.EM);
    passwordFieldRepeat = new PasswordField("Repeat Password");
    passwordFieldRepeat.setIcon(FontAwesome.KEY);
    passwordFieldRepeat.setWidth(12, Unit.EM);
    addUserButton = new Button("Add New User");
    addUserButton.setWidth(12, Unit.EM);
    goBackButton = new Button("Back");

    VerticalLayout layout = new VerticalLayout();
    Panel panel = new Panel("Sign Up - Smart ReservationEntity System");
    panel.setSizeUndefined();/*from w w w  . j  a va2s.c  o m*/
    layout.addComponent(panel);

    FormLayout content = new FormLayout();
    content.addComponents(usernameField, passwordField, passwordFieldRepeat, addUserButton);
    content.setSizeUndefined();
    content.setMargin(true);
    VerticalLayout formAndBack = new VerticalLayout(content, goBackButton);
    formAndBack.setMargin(true);
    panel.setContent(formAndBack);

    setCompositionRoot(layout);

    layout.setComponentAlignment(panel, Alignment.MIDDLE_CENTER);
    layout.setMargin(new MarginInfo(true, false, false, false));
}

From source file:ch.bfh.ti.soed.hs16.srs.green.view.MyUI.java

License:Open Source License

/**
 * Method which actually creates the whole UI.
 *///www .j a  va  2 s  . co  m
@Override
protected void init(VaadinRequest vaadinRequest) {

    VerticalLayout layout = new VerticalLayout();

    Panel panel = new Panel("Login");
    panel.setSizeUndefined();

    FormLayout content = new FormLayout();
    userName = new TextField("Username");
    content.addComponent(userName);

    PasswordField password = new PasswordField("Password");
    content.addComponent(password);

    Button login = new Button("Login");
    register = new Button("Register");
    CheckBox askBox = new CheckBox("Are you a Roommanager?");

    login.setStyleName(Reindeer.BUTTON_SMALL);
    login.setWidth("86px");

    register.setStyleName(Reindeer.BUTTON_SMALL);
    register.setWidth("86px");
    askBox.setStyleName(Reindeer.BUTTON_SMALL);

    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);
    hl.addComponent(login);
    hl.addComponent(register);
    hl.addComponent(askBox);

    content.addComponent(hl);
    content.setSizeUndefined();
    content.setMargin(true);

    panel.setContent(content);

    login.addClickListener(e -> {
        System.out.println(userName.getValue());
        System.out.println(password.getValue());
        try {
            if (controller.login(userName.getValue(), password.getValue())
                    || userName.equals(userName.getValue()) && password.equals(password.getValue())) {
                setContent(new ReservationUI());
            }
        } catch (Throwable e1) {
            e1.printStackTrace();
        }
    });

    register.addClickListener(e -> {
        try {
            Role x = askBox.getValue() ? Role.ROOMMANAGER : Role.CUSTOMER;
            controller.register(userName.getValue(), password.getValue(), x);
        } catch (Throwable e1) {
            e1.printStackTrace();
        }
    });

    layout.setMargin(true);
    layout.setSpacing(true);
    layout.addComponent(panel);
    setContent(layout);
}

From source file:ch.bfh.ti.soed.hs16.srs.red.ui.views.LoginView.java

License:Open Source License

public LoginView(Navigator nav) {

    try {//from  w ww .jav  a 2  s.  c  om
        // @TODO remove before release
        DevDemo devdemo = new DevDemo();
    } catch (Exception ex) {
        Notification.show("Demo Entries failed to initialize.", ex.getMessage(),
                Notification.Type.ERROR_MESSAGE);
    }
    /*---------------------------------
    initialize Objects
    ---------------------------------*/
    this.nav = nav;
    this.vertical = new VerticalLayout();
    this.loginName = new TextField("username");
    this.passwordField = new PasswordField("password");
    this.loginButton = new Button("Login", this);

    /*-------------------------------
    add to css
    -------------------------------*/
    vertical.setPrimaryStyleName("rootLogin");
    loginButton.setStyleName("buttonLogin");

    /*-------------------------------
    add Components to Layout
    --------------------------------*/
    vertical.addComponents(loginName, passwordField, loginButton);
    setCompositionRoot(vertical);
}

From source file:ch.bfh.ti.soed.hs16.srs.view.views.LoginView.java

License:Open Source License

public LoginView(Navigator nav) {

    /* init objects */
    this.layout = new VerticalLayout();
    this.btn = new Button("Login");
    this.loginFld = new TextField("username");
    this.pwFld = new PasswordField("password");
    this.header = new Header();
    this.footer = new Footer("BFH", "Biel-Bienne", "Schweiz");

    /* add to css */
    this.layout.setPrimaryStyleName("rootLogin");
    this.btn.setStyleName("buttonLogin");

    /* add components to layout */
    this.layout.addComponent(this.header.getHeaderLayout());
    this.layout.addComponents(this.loginFld, this.pwFld, this.btn);
    this.layout.addComponent(this.footer.getFooterLayout());
    setCompositionRoot(layout);/*w w w .  j  av a2s. com*/

    /* event handling */
    this.btn.addClickListener((Button.ClickListener) clickEvent -> {
        // handle userlogin
        nav.navigateTo("RoomView");
    });
}