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() 

Source Link

Document

Constructs an empty PasswordField.

Usage

From source file:org.ikasan.dashboard.ui.framework.window.LoginDialog.java

License:BSD License

/**
 * Helper method to initialise this object.
 * /* ww  w. ja  v a2  s  .co  m*/
 * @param userService
 * @param authProvider
 * @param visibilityGroup
 * @param userDetailsHelper
 * @param commitHandler
 */
protected void init(AuthenticationService authenticationService, VisibilityGroup visibilityGroup,
        final NavigationPanel commitHandler) {
    super.setModal(true);
    super.setResizable(false);
    super.center();
    this.setWidth(300, Unit.PIXELS);
    this.setHeight(200, Unit.PIXELS);

    PropertysetItem item = new PropertysetItem();
    item.addItemProperty(LoginFieldGroup.USERNAME, new ObjectProperty<String>(""));
    item.addItemProperty(LoginFieldGroup.PASSWORD, new ObjectProperty<String>(""));

    GridLayout form = new GridLayout(2, 4);
    form.setColumnExpandRatio(0, .15f);
    form.setColumnExpandRatio(1, .85f);
    form.setWidth(100, Unit.PERCENTAGE);
    form.setMargin(true);
    form.setSpacing(true);

    Label newTypeLabel = new Label("Login");
    newTypeLabel.setStyleName(ValoTheme.LABEL_HUGE);
    form.addComponent(newTypeLabel, 0, 0, 1, 0);

    Label usernameLabel = new Label("Username:");
    usernameLabel.setSizeUndefined();
    form.addComponent(usernameLabel, 0, 1);
    form.setComponentAlignment(usernameLabel, Alignment.MIDDLE_RIGHT);

    final TextField userNameField = new TextField();
    userNameField.addValidator(new StringLengthValidator("The username must not be empty", 1, null, true));
    userNameField.setValidationVisible(false);
    userNameField.setStyleName("ikasan");
    form.addComponent(userNameField, 1, 1);

    Label passwordLabel = new Label("Password:");
    passwordLabel.setSizeUndefined();
    form.addComponent(passwordLabel, 0, 2);
    form.setComponentAlignment(passwordLabel, Alignment.MIDDLE_RIGHT);

    final PasswordField passwordField = new PasswordField();
    passwordField.setStyleName("ikasan");
    passwordField.addValidator(new StringLengthValidator("The password must not be empty", 1, null, true));
    passwordField.setValidationVisible(false);
    form.addComponent(passwordField, 1, 2);

    final LoginFieldGroup binder = new LoginFieldGroup(item, visibilityGroup, authenticationService);
    binder.bind(userNameField, LoginFieldGroup.USERNAME);
    binder.bind(passwordField, LoginFieldGroup.PASSWORD);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);

    Button loginButton = new Button("Login");
    loginButton.addStyleName(ValoTheme.BUTTON_SMALL);
    loginButton.setClickShortcut(KeyCode.ENTER);

    loginButton.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            try {
                userNameField.validate();
                passwordField.validate();
            } catch (InvalidValueException e) {
                userNameField.setValidationVisible(true);
                passwordField.setValidationVisible(true);
                return;
            }

            try {
                binder.commit();
                userNameField.setValue("");
                passwordField.setValue("");
                close();
                commitHandler.postCommit();
            } catch (CommitException e) {
                Notification.show(e.getMessage(), Notification.Type.ERROR_MESSAGE);
            }
        }
    });
    buttons.addComponent(loginButton);

    Button cancelButton = new Button("Cancel");
    cancelButton.setStyleName(ValoTheme.BUTTON_SMALL);
    cancelButton.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            close();
            binder.discard();
        }
    });
    buttons.addComponent(cancelButton);

    form.addComponent(buttons, 0, 3, 1, 3);
    form.setComponentAlignment(buttons, Alignment.MIDDLE_CENTER);

    this.setContent(form);
}

From source file:org.jdal.vaadin.ui.FormUtils.java

License:Apache License

/**
 * Create a new {@link PasswordField}//from w w  w.  j  a  v  a  2 s .com
 * @return new PasswordField with null representation set to emptry string.
 */
public static PasswordField newPasswordField() {
    PasswordField pf = new PasswordField();
    pf.setNullRepresentation("");

    return pf;
}

From source file:org.jpos.qi.login.LoginView.java

License:Open Source License

private FormLayout createForm() {
    FormLayout formLayout = new FormLayout();
    formLayout.setMargin(false);/*from w w  w  .  jav  a2  s.  c o m*/
    formLayout.setSizeUndefined();

    binder = new Binder<>(String.class);
    username = new TextField(app.getMessage("login.username"));
    username.setMaxLength(60);

    binder.forField(username)
            .withValidator(new RegexpValidator(
                    app.getMessage("errorMessage.invalidField", username.getCaption()), USERNAME_PATTERN))
            .bind(string -> string, null);
    binder.setBean("");
    username.focus();
    username.setReadOnly(false);
    password = new PasswordField();
    password.setCaption(app.getMessage("login.password"));
    password.setMaxLength(64);
    binder.forField(password).asRequired(app.getMessage("errorMessage.req", password.getCaption()))
            .withValidator(new RegexpValidator(
                    app.getMessage("errorMessage.invalidField", password.getCaption()), PASSWORD_PATTERN))
            .bind(string -> string, null);
    password.setReadOnly(false);

    rememberMe = new CheckBox(app.getMessage("login.remember"));
    rememberMe.setDescription(app.getMessage("login.rememberDesc"));

    formLayout.addComponent(username);
    formLayout.addComponent(password);
    if (helper.isRememberEnabled())
        formLayout.addComponent(rememberMe);
    return formLayout;
}

From source file:org.metawidget.vaadin.ui.widgetbuilder.VaadinWidgetBuilder.java

License:LGPL

public Component buildWidget(String elementName, Map<String, String> attributes, VaadinMetawidget metawidget) {

    // Hidden//from   w w w. j  a v a 2s .  c  o  m

    if (TRUE.equals(attributes.get(HIDDEN))) {
        return new Stub();
    }

    // Action

    if (ACTION.equals(elementName)) {
        return new Button();
    }

    // Lookup the Class

    Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, String.class);

    // Support mandatory Booleans (can be rendered as a checkbox, even
    // though they have a Lookup)

    if (Boolean.class.equals(clazz) && TRUE.equals(attributes.get(REQUIRED))) {
        return new CheckBox();
    }

    // Lookups

    String lookup = attributes.get(LOOKUP);

    if (lookup != null && !"".equals(lookup)) {
        return createSelectComponent(attributes, lookup, metawidget);
    }

    if (clazz != null) {

        // Primitives

        if (clazz.isPrimitive()) {
            // booleans

            if (boolean.class.equals(clazz)) {
                return new CheckBox();
            }

            // chars

            if (char.class.equals(clazz)) {
                TextField textField = new TextField();
                textField.setMaxLength(1);

                return textField;
            }

            // Ranged

            String minimumValue = attributes.get(MINIMUM_VALUE);
            String maximumValue = attributes.get(MAXIMUM_VALUE);

            if (minimumValue != null && !"".equals(minimumValue) && maximumValue != null
                    && !"".equals(maximumValue)) {
                Slider slider = new Slider();
                slider.setMin(Double.parseDouble(minimumValue));
                try {
                    // Use big 'D' Double for Vaadin 6/7 compatibility
                    slider.setValue(Double.valueOf(slider.getMin()));
                } catch (ValueOutOfBoundsException e) {
                    throw WidgetBuilderException.newException(e);
                }
                slider.setMax(Double.parseDouble(maximumValue));

                return slider;
            }

            // Not-ranged

            return createTextField(attributes);
        }

        // Strings

        if (String.class.equals(clazz)) {
            if (TRUE.equals(attributes.get(MASKED))) {
                return new PasswordField();
            }

            if (TRUE.equals(attributes.get(LARGE))) {
                return new TextArea();
            }

            return createTextField(attributes);
        }

        // Characters

        if (Character.class.isAssignableFrom(clazz)) {
            TextField textField = new TextField();
            textField.setMaxLength(1);

            return textField;
        }

        // Dates

        if (Date.class.equals(clazz)) {
            return new PopupDateField();
        }

        // Numbers
        //
        // Note: we use a text field, not a JSpinner or JSlider, because
        // BeansBinding gets upset at doing 'setValue( null )' if the Integer
        // is null. We can still use JSpinner/JSliders for primitives, though.

        if (Number.class.isAssignableFrom(clazz)) {
            return createTextField(attributes);
        }

        // Collections

        if (Collection.class.isAssignableFrom(clazz)) {
            return new Stub();
        }
    }

    // Not simple, but don't expand

    if (TRUE.equals(attributes.get(DONT_EXPAND))) {
        return createTextField(attributes);
    }

    return null;
}

From source file:org.opennms.features.jmxconfiggenerator.webui.ui.ConfigForm.java

License:Open Source License

public ConfigForm(JmxConfigGeneratorApplication app) {
    this.app = app;
    setImmediate(true);/*from  www .  j a va 2  s.c o m*/
    setDescription(UIHelper.loadContentFromFile(getClass(), "/descriptions/ServiceConfiguration.html"));
    setFormFieldFactory(new com.vaadin.ui.DefaultFieldFactory() {

        @Override
        public Field<?> createField(Item item, Object propertyId, Component uiContext) {
            if (MetaConfigModel.PASSWORD.equals(propertyId)) {
                PasswordField field = new PasswordField();
                field.setNullRepresentation("");
                field.setCaption(createCaptionByPropertyId(propertyId));
                return field;
            }
            return super.createField(item, propertyId, uiContext);
        }
    });
    setBuffered(false);
    setFooter(buttonPanel);
}

From source file:org.opennms.features.topology.ssh.internal.AuthWindow.java

License:Open Source License

/**
 * This constructor method spawns a window to authorize the
 * username and password input by the user. If the authroization
 * is sucessful, the user will be connected to the host at the 
 * given port through SSH, and the terminal emulator this window
 * will be replaced by a terminal emulator. 
 * //w  ww .j av a  2 s . c  o  m
 * @param host - The host name to connect to
 * @param port - The port number to connect to
 */
public AuthWindow(String host, int port) {
    super("Login");
    m_host = host;
    m_port = port;
    if ("".equals(m_host) || m_port == 0) {
        showOptions = true;
    }
    setCaption("Auth Window");
    setModal(true);
    setWidth("260px");
    setHeight("190px");
    if (showOptions)
        setHeight("260px");
    setResizable(false);

    Label hostLabel = new Label("Host: ");
    hostField = new TextField();
    //        hostField.setMaxLength(FIELD_BUFFER);

    Label portLabel = new Label("Port: ");
    portField = new TextField();
    //        portField.setMaxLength(FIELD_BUFFER);

    Label usernameLabel = new Label("Username: ");
    usernameField = new TextField();
    //        usernameField.setMaxLength(FIELD_BUFFER);

    Label passwordLabel = new Label("Password: ");
    passwordField = new PasswordField();
    passwordField.setMaxLength(FIELD_BUFFER);

    final Button loginButton = new Button("Login");
    loginButton.setClickShortcut(KeyCode.ENTER);
    client = SshClient.setUpDefaultClient();
    client.start();
    loginButton.addClickListener(this);
    GridLayout grid = new GridLayout(2, 2);
    if (showOptions) {
        grid = new GridLayout(2, 4);
        grid.addComponent(hostLabel);
        grid.addComponent(hostField);
        grid.addComponent(portLabel);
        grid.addComponent(portField);
    }
    grid.addComponent(usernameLabel);
    grid.addComponent(usernameField);
    grid.addComponent(passwordLabel);
    grid.addComponent(passwordField);
    grid.setSpacing(true);
    grid.setMargin(new MarginInfo(false, false, true, false));
    VerticalLayout layout = new VerticalLayout();
    layout.addComponent(grid);
    layout.addComponent(loginButton);
    layout.setComponentAlignment(loginButton, Alignment.BOTTOM_RIGHT);
    setContent(layout);
}

From source file:org.ripla.web.demo.widgets.views.InputWidgetsView.java

License:Open Source License

public InputWidgetsView() {
    super();/*from w  ww .  j ava 2s. c o  m*/

    final IMessages lMessages = Activator.getMessages();
    final VerticalLayout lLayout = initLayout(lMessages, "widgets.title.page.input"); //$NON-NLS-1$

    final HorizontalLayout lColumns = new HorizontalLayout();
    lColumns.setSpacing(true);
    lLayout.addComponent(lColumns);

    final VerticalLayout lCol1 = new VerticalLayout();
    lCol1.setSizeUndefined();
    lColumns.addComponent(lCol1);
    final VerticalLayout lCol2 = new VerticalLayout();
    lCol2.setSizeUndefined();
    lColumns.addComponent(lCol2);
    final VerticalLayout lCol3 = new VerticalLayout();
    lCol3.setSizeUndefined();
    lColumns.addComponent(lCol3);
    lColumns.setExpandRatio(lCol3, 1);

    // classic input fields
    lCol1.addComponent(getSubtitle(lMessages.getMessage("widgets.input.subtitle.input.normal"))); //$NON-NLS-1$
    final TextField lTextField = new TextField();
    lTextField.setColumns(WIDTH_FIELD);
    lCol1.addComponent(lTextField);

    lCol1.addComponent(getSubtitle(lMessages.getMessage("widgets.input.subtitle.input.prompt"))); //$NON-NLS-1$
    final TextField lTextField2 = new TextField();
    lTextField2.setInputPrompt(lMessages.getMessage("widgets.input.input.prompt")); //$NON-NLS-1$
    lTextField2.setColumns(WIDTH_FIELD);
    lCol1.addComponent(lTextField2);

    lCol1.addComponent(getSubtitle(lMessages.getMessage("widgets.input.subtitle.input.password"))); //$NON-NLS-1$
    final PasswordField lPassword = new PasswordField();
    lPassword.setColumns(WIDTH_FIELD);
    lCol1.addComponent(lPassword);

    lCol1.addComponent(getSubtitle(lMessages.getMessage("widgets.input.subtitle.date"))); //$NON-NLS-1$
    final PopupDateField lDate1 = new PopupDateField(lMessages.getMessage("widgets.input.popup.date")); //$NON-NLS-1$
    lDate1.setResolution(Resolution.DAY);
    lDate1.setDateFormat("dd. MMMM yyyy"); //$NON-NLS-1$
    lDate1.setWidth(160, Unit.PIXELS);
    lDate1.setValue(new java.util.Date());
    lCol1.addComponent(lDate1);

    // text areas
    lCol2.addComponent(getSubtitle(lMessages.getMessage("widgets.input.subtitle.text.area"))); //$NON-NLS-1$
    final TextArea lArea = new TextArea();
    lArea.setColumns(WIDTH_AREA);
    lArea.setRows(7);
    lCol2.addComponent(lArea);

    lCol2.addComponent(getSubtitle(lMessages.getMessage("widgets.input.subtitle.rich.text"))); //$NON-NLS-1$
    final RichTextArea lRichText = new RichTextArea();
    lRichText.setWidth(WIDTH_AREA, Unit.EM);
    lRichText.setHeight(15, Unit.EM);
    lCol2.addComponent(lRichText);

    // text input with filter
    final CountryContainer lCountries = new CountryContainer();
    lCol3.addComponent(getSubtitle(lMessages.getMessage("widgets.input.subtitle.input.filter"))); //$NON-NLS-1$
    final TextField lFilter = new TextField();
    lFilter.setTextChangeEventMode(TextChangeEventMode.LAZY);
    lFilter.setTextChangeTimeout(200);
    lFilter.addTextChangeListener(new FieldEvents.TextChangeListener() {
        @Override
        public void textChange(final TextChangeEvent inEvent) {
            lCountries.removeAllContainerFilters();
            lCountries.addContainerFilter(
                    new SimpleStringFilter(CountryContainer.PROPERTY_NAME, inEvent.getText(), true, true));
        }
    });
    lFilter.setWidth(FILTER_WIDTH, Unit.PIXELS);

    final Table lTable = new Table(null, lCountries);
    lTable.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
    lTable.setWidth(FILTER_WIDTH, Unit.PIXELS);
    lTable.setPageLength(18);

    lCol3.addComponent(lFilter);
    lCol3.addComponent(lTable);
}

From source file:rs.pupin.jpo.validation.gui.ValidationSettingsWindow.java

@Override
public void attach() {
    // add endpoint field
    Label lbl = new Label("Endpoint:");
    lbl.setSizeUndefined();//  ww  w.  j  a va  2  s .  c o  m
    settingsLayout.addComponent(lbl, 0, 0, 0, 0);
    settingsLayout.setComponentAlignment(lbl, Alignment.MIDDLE_LEFT);
    endpointInput = new TextField();
    endpointInput.setValue(state.endpoint);
    endpointInput.setWidth("100%");
    settingsLayout.addComponent(endpointInput, 1, 0, 1, 0);

    // add graph field
    lbl = new Label("Graph:");
    lbl.setSizeUndefined();
    settingsLayout.addComponent(lbl, 0, 1, 0, 1);
    settingsLayout.setComponentAlignment(lbl, Alignment.MIDDLE_LEFT);
    graphInput = new TextField();
    graphInput.setValue(state.graph);
    graphInput.setWidth("100%");
    settingsLayout.addComponent(graphInput, 1, 1, 1, 1);

    lbl = new Label("");
    lbl.setHeight("30px");
    settingsLayout.addComponent(lbl, 0, 2, 1, 2);

    // add basic authentication check box
    authCheckBox = new CheckBox("Use basic authentication");
    authCheckBox.setSizeUndefined();
    settingsLayout.addComponent(authCheckBox, 0, 3, 1, 3);
    settingsLayout.setComponentAlignment(authCheckBox, Alignment.MIDDLE_LEFT);

    // add username field
    lbl = new Label("Username:");
    lbl.setSizeUndefined();
    settingsLayout.addComponent(lbl, 0, 4);
    settingsLayout.setComponentAlignment(lbl, Alignment.MIDDLE_LEFT);
    usernameInput = new TextField();
    usernameInput.setWidth("100%");
    usernameInput.setEnabled(false);
    settingsLayout.addComponent(usernameInput, 1, 4);
    settingsLayout.setComponentAlignment(usernameInput, Alignment.MIDDLE_LEFT);

    // add password field
    lbl = new Label("Password:");
    lbl.setSizeUndefined();
    settingsLayout.addComponent(lbl, 0, 5);
    settingsLayout.setComponentAlignment(lbl, Alignment.MIDDLE_LEFT);
    passwordInput = new PasswordField();
    passwordInput.setWidth("100%");
    passwordInput.setEnabled(false);
    settingsLayout.addComponent(passwordInput, 1, 5);

    lbl = new Label("");
    lbl.setHeight("30px");
    settingsLayout.addComponent(lbl, 0, 6, 1, 6);

    // add OntoWiki check box
    owCheckBox = new CheckBox("Use OntoWiki instance");
    owCheckBox.setSizeUndefined();
    if (state.owUrl != null)
        owCheckBox.setValue(true);
    else
        owCheckBox.setValue(false);
    settingsLayout.addComponent(owCheckBox, 0, 7, 1, 7);
    settingsLayout.setComponentAlignment(owCheckBox, Alignment.MIDDLE_LEFT);

    // add OntoWiki field
    lbl = new Label("OntoWiki URL:");
    lbl.setSizeUndefined();
    settingsLayout.addComponent(lbl, 0, 8);
    settingsLayout.setComponentAlignment(lbl, Alignment.MIDDLE_LEFT);
    owInput = new TextField();
    owInput.setWidth("100%");
    if (state.owUrl != null) {
        owInput.setEnabled(true);
        owInput.setValue(state.owUrl);
    } else
        owInput.setEnabled(false);
    settingsLayout.addComponent(owInput, 1, 8);
    settingsLayout.setComponentAlignment(owInput, Alignment.MIDDLE_LEFT);

    lbl = new Label("");
    lbl.setHeight("30px");
    settingsLayout.addComponent(lbl, 0, 9, 1, 9);

    // add buttons
    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);
    hl.setSizeUndefined();
    btnOK = new Button("OK");
    btnCancel = new Button("Cancel");
    hl.addComponent(btnOK);
    hl.addComponent(btnCancel);
    settingsLayout.addComponent(hl, 1, 10);
    settingsLayout.setComponentAlignment(hl, Alignment.MIDDLE_RIGHT);

    createListeners();
    center();
}

From source file:ru.codeinside.adm.ui.employee.TableEmployee.java

License:Mozilla Public License

public static PasswordField addPasswordField(AbstractComponentContainer container, String widthColumn,
        String content) {//from   w ww .  j  a va 2s .  c o  m
    HorizontalLayout l;
    l = new HorizontalLayout();
    Label label = new Label(content);
    label.setWidth(widthColumn);
    l.addComponent(label);
    l.setComponentAlignment(label, Alignment.MIDDLE_LEFT);
    final PasswordField field = new PasswordField();
    l.addComponent(field);
    container.addComponent(l);
    return field;
}

From source file:songstock.web.extensions.login.basic.BasicLoginForm.java

License:Open Source License

@AutoGenerated
private AbsoluteLayout buildMainLayout() {
    // common part: create layout
    mainLayout = new AbsoluteLayout();
    mainLayout.setImmediate(false);/*from   w w w.  ja  va 2s.com*/
    mainLayout.setWidth("340px");
    mainLayout.setHeight("180px");

    // top-level component properties
    setWidth("340px");
    setHeight("180px");

    // labelTitle
    labelTitle = new Label();
    labelTitle.setImmediate(false);
    labelTitle.setWidth("-1px");
    labelTitle.setHeight("-1px");
    labelTitle.setValue("<b>Login Form</b>");
    labelTitle.setContentMode(com.vaadin.shared.ui.label.ContentMode.HTML);
    mainLayout.addComponent(labelTitle, "top:20.0px;left:20.0px;");

    // labelEmail
    labelEmail = new Label();
    labelEmail.setImmediate(false);
    labelEmail.setWidth("-1px");
    labelEmail.setHeight("-1px");
    labelEmail.setValue("Email:");
    mainLayout.addComponent(labelEmail, "top:60.0px;left:20.0px;");

    // labelPassword
    labelPassword = new Label();
    labelPassword.setImmediate(false);
    labelPassword.setWidth("-1px");
    labelPassword.setHeight("-1px");
    labelPassword.setValue("Password:");
    mainLayout.addComponent(labelPassword, "top:102.0px;left:20.0px;");

    // textFieldEmail
    textFieldEmail = new TextField();
    textFieldEmail.setImmediate(false);
    textFieldEmail.setWidth("220px");
    textFieldEmail.setHeight("-1px");
    mainLayout.addComponent(textFieldEmail, "top:60.0px;left:100.0px;");

    // passwordField
    passwordField = new PasswordField();
    passwordField.setImmediate(false);
    passwordField.setWidth("220px");
    passwordField.setHeight("-1px");
    mainLayout.addComponent(passwordField, "top:100.0px;left:100.0px;");

    // buttonLogin
    buttonLogin = new Button();
    buttonLogin.setCaption("Login");
    buttonLogin.setImmediate(true);
    buttonLogin.setWidth("61px");
    buttonLogin.setHeight("-1px");
    mainLayout.addComponent(buttonLogin, "top:140.0px;right:19.0px;");

    // labelError
    labelError = new Label();
    labelError.setImmediate(false);
    labelError.setWidth("-1px");
    labelError.setHeight("-1px");
    labelError.setValue("<i>Label</i>");
    labelError.setContentMode(com.vaadin.shared.ui.label.ContentMode.HTML);
    mainLayout.addComponent(labelError, "top:142.0px;left:20.0px;");

    return mainLayout;
}