コード例 #1
0
  public SimpleLoginView() {
    setSizeFull();

    // Create the user input field
    userTextField = new TextField("User name: ");
    userTextField.setWidth("300px");
    userTextField.setRequired(true);
    userTextField.setInputPrompt("Your username (eg. user1)");
    userTextField.addValidator(new LoginValidator());
    userTextField.setInvalidAllowed(false);

    // Create the password input field
    passwordField = new PasswordField("Password:"******"300px");
    passwordField.setRequired(true);
    passwordField.addValidator(new PasswordValidator());
    passwordField.setValue("");
    passwordField.setNullRepresentation("");

    // Create login button
    loginButton = new Button("Login", this);

    // Add all to a panel
    VerticalLayout fields = new VerticalLayout(userTextField, passwordField, loginButton);
    fields.setCaption("Please login to access the application. (user1/password)");
    fields.setSpacing(true);
    fields.setMargin(new MarginInfo(true, true, true, false));
    fields.setSizeUndefined();

    // The view root layout
    VerticalLayout viewLayout = new VerticalLayout(fields);
    viewLayout.setSizeFull();
    viewLayout.setComponentAlignment(fields, Alignment.MIDDLE_CENTER);
    viewLayout.setStyleName(Reindeer.LAYOUT_BLUE);
    setCompositionRoot(viewLayout);
  }
コード例 #2
0
  protected Panel createPasswordFieldPanel(ConfigurationParameter parameter, Validator validator) {
    Panel paramPanel = new Panel();
    paramPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    paramPanel.setWidth("100%");

    GridLayout paramLayout = new GridLayout(2, 3);
    paramLayout.setSpacing(true);
    paramLayout.setSizeFull();
    paramLayout.setMargin(true);
    paramLayout.setColumnExpandRatio(0, .25f);
    paramLayout.setColumnExpandRatio(1, .75f);

    Label label = new Label(parameter.getName());
    label.setIcon(VaadinIcons.COG);
    label.addStyleName(ValoTheme.LABEL_LARGE);
    label.addStyleName(ValoTheme.LABEL_BOLD);
    label.setSizeUndefined();
    paramLayout.addComponent(label, 0, 0, 1, 0);
    paramLayout.setComponentAlignment(label, Alignment.TOP_LEFT);

    logger.info(parameter.getName() + " " + parameter.getValue());
    Label valueLabel = new Label("Value:");
    valueLabel.setSizeUndefined();
    passwordField = new PasswordField();
    passwordField.addValidator(validator);
    passwordField.setNullSettingAllowed(true);
    passwordField.setNullRepresentation("");
    passwordField.setValidationVisible(false);
    passwordField.setWidth("80%");
    passwordField.setId(parameter.getName());

    if (parameter instanceof ConfigurationParameterIntegerImpl) {
      StringToIntegerConverter plainIntegerConverter =
          new StringToIntegerConverter() {
            protected java.text.NumberFormat getFormat(Locale locale) {
              NumberFormat format = super.getFormat(locale);
              format.setGroupingUsed(false);
              return format;
            };
          };

      // either set for the field or in your field factory for multiple fields
      passwordField.setConverter(plainIntegerConverter);
    } else if (parameter instanceof ConfigurationParameterLongImpl) {
      StringToLongConverter plainLongConverter =
          new StringToLongConverter() {
            protected java.text.NumberFormat getFormat(Locale locale) {
              NumberFormat format = super.getFormat(locale);
              format.setGroupingUsed(false);
              return format;
            };
          };

      // either set for the field or in your field factory for multiple fields
      passwordField.setConverter(plainLongConverter);
    }

    BeanItem<ConfigurationParameter> parameterItem =
        new BeanItem<ConfigurationParameter>(parameter);

    if (parameter.getValue() != null) {
      passwordField.setPropertyDataSource(parameterItem.getItemProperty("value"));
    }

    paramLayout.addComponent(valueLabel, 0, 1);
    paramLayout.addComponent(passwordField, 1, 1);
    paramLayout.setComponentAlignment(valueLabel, Alignment.TOP_RIGHT);

    paramPanel.setContent(paramLayout);

    return paramPanel;
  }