Java 类com.vaadin.ui.TextField 实例源码

项目:easybinder    文件:ComponentFactoryRegistry.java   
public Optional<Component> createComponent(Field field) {
    Class<?> classToTest = field.getType();
    while (classToTest != null) {
        List<Pair<Predicate<Field>, Function<Field, Component>>> candidates = builders.get(classToTest);
        if (candidates != null) {
            Optional<Pair<Predicate<Field>, Function<Field, Component>>> match = candidates.stream()
                    .filter(e -> e.getFirst().test(field)).findFirst();
            if (match.isPresent()) {
                log.log(Level.INFO, "Fould build rule for field=<{0}> using type={1}",
                        new Object[] { field, classToTest });
                return Optional.of(match.get().getSecond().apply(field));
            }
        }

        log.log(Level.INFO, "No build rule for field=<{0}> with type=<{1}>", new Object[] { field, classToTest });
        classToTest = classToTest.getSuperclass();
    }

    log.log(Level.INFO, "No match for field=<{1}> with type=<{2}>, generating a text field",
            new Object[] { field, field.getType() });
    return Optional.of(new TextField(SharedUtil.camelCaseToHumanFriendly(field.getName())));
}
项目:easybinder    文件:BinderAdapterTest.java   
@Test
public void testReadWriteBeanEmptySetter() throws ValidationException {
    @SuppressWarnings("unchecked")
    BasicBinder<TestEntity> binder = mock(BasicBinder.class);
    BinderAdapter<TestEntity> binderAdapter = new BinderAdapter<TestEntity>(binder, TestEntity.class);

    when(binder.getBean()).thenReturn(new TestEntity());
    when(binder.isValid()).thenReturn(true);

    EasyBinding<TestEntity, String, Integer> binding = new EasyBinding<>(
            binder,
            new TextField(),
            TestEntity::getTest,
            null,
            "test",
            new StringToIntegerConverter(""));

    when(binder.getBindings()).thenReturn(Arrays.asList(binding));

    TestEntity testEntity = new TestEntity();

    // Just verify that no null pointer exception is thrown
    binderAdapter.readBean(testEntity);
    binderAdapter.writeBean(testEntity);
}
项目:easybinder    文件:BasicBinderStringTest.java   
@Test
public void testValid() {
    TextField text = new TextField();

    binder.bind(text, d -> d.getText() == null ? "" : d.getText(), (e, f) -> e.setText("".equals(f) ? null : f),
            "text");

    MyEntity t = new MyEntity();

    t.setText("bla");
    binder.setBean(t);

    assertTrue(binder.isValid());

    text.setValue("");
    assertNull(t.getText());
}
项目:easybinder    文件:BeanValidationBinderStringTest.java   
@Test
public void testNullRepresentation() {
    TextField field = new TextField();

    // Bind with null representation
    Binder<MyEntity> binder = new BeanValidationBinder<>(MyEntity.class);
    binder.forField(field).withNullRepresentation("").bind("text");

    MyEntity bean = new MyEntity();

    assertTrue(validator.validate(bean).isEmpty());
    assertTrue(binder.validate().isOk());

    binder.setBean(bean);

    field.setValue("test");
    assertEquals("test", bean.getText());

    field.setValue("");
    assertNull(bean.getText());

    assertTrue(validator.validate(bean).isEmpty());
    assertTrue(binder.validate().isOk());
}
项目:easybinder    文件:BeanValidationBinderStringTest.java   
@Test
public void testNullRepresentationSizeMin1() {
    TextField field = new TextField();

    // Bind with null representation
    Binder<MyEntitySizeMin1> binder = new BeanValidationBinder<>(MyEntitySizeMin1.class);
    binder.forField(field).withNullRepresentation("").bind("text");

    MyEntitySizeMin1 bean = new MyEntitySizeMin1();

    assertTrue(validator.validate(bean).isEmpty());
    assertTrue(binder.validate().isOk());

    binder.setBean(bean);

    field.setValue("test");
    assertEquals("test", bean.getText());

    field.setValue("");
    assertNull(bean.getText());

    assertTrue(validator.validate(bean).isEmpty());
    assertTrue(binder.validate().isOk());
}
项目:easybinder    文件:BeanValidationBinderBeanLevelTest.java   
@Test
public void testBeanClassLevelValidation() {
    TextField field1 = new TextField();
    TextField field2 = new TextField();
    Label statusLabel = new Label();

    Binder<MyEntity> binder = new BeanValidationBinder<>(MyEntity.class);
    binder.forField(field1).withNullRepresentation("").bind("s1");
    binder.forField(field2).withNullRepresentation("").bind("s2");

    binder.setStatusLabel(statusLabel);

    MyEntity bean = new MyEntity();

    binder.setBean(bean);

    assertFalse(validator.validate(bean).isEmpty());
    assertTrue(binder.validate().isOk());

    // JSR303 bean level validation still missing:
    // https://github.com/vaadin/framework/issues/8498
    // assertFalse(binder.validate().isOk());
}
项目:easybinder    文件:BuildAndBindTest.java   
@SuppressWarnings("unchecked")
@BeforeClass
public static void setup() {
    binder.buildAndBind("flightId");

    form.airline = (TextField) binder.getFieldForProperty("flightId.airline").get();
    form.flightNumber = (TextField) binder.getFieldForProperty("flightId.flightNumber").get();
    form.flightSuffix = (TextField) binder.getFieldForProperty("flightId.flightSuffix").get();
    form.date = (DateField) binder.getFieldForProperty("flightId.date").get();
    form.legType = (AbstractSingleSelect<LegType>) binder.getFieldForProperty("flightId.legType").get();
    form.sbt = (DateTimeField) binder.getFieldForProperty("sbt").get();
    form.ebt = (DateTimeField) binder.getFieldForProperty("ebt").get();
    form.abt = (DateTimeField) binder.getFieldForProperty("abt").get();
    form.gate = (TextField) binder.getFieldForProperty("gate").get();
    form.canceled = (CheckBox) binder.getFieldForProperty("canceled").get();
}
项目:esup-ecandidat    文件:SearchAnneeUnivApoField.java   
/**
 * Constructeur, initialisation du champs
 * @param libelleBtnFind 
 */
public SearchAnneeUnivApoField(String libelleBtnFind) {
    super();
    layout = new HorizontalLayout();
    layout.setSpacing(true);
    anneeField = new TextField();
    anneeField.addValueChangeListener(e->showOrHideError());
    anneeField.setNullRepresentation("");
    anneeField.setReadOnly(true);
    btnSearch = new OneClickButton(libelleBtnFind,FontAwesome.SEARCH);
    btnSearch.addClickListener(e->{
        SearchAnneeUnivApoWindow window = new SearchAnneeUnivApoWindow();
        window.addAnneeUniListener(a->changeFieldValue(a));
        UI.getCurrent().addWindow(window);
    });
    layout.addComponent(anneeField);
    layout.addComponent(btnSearch);
}
项目:esup-ecandidat    文件:I18nField.java   
/** Colore les champs en rouge si erreur
 * @param validate
 */
@SuppressWarnings("unchecked")
private void validateFields(Boolean validate){
    listLayoutTraductions.forEach(e -> {        
        AbstractField<String> tf;           
        if (e.getComponent(0) instanceof TextField || e.getComponent(0) instanceof RichTextArea){
            tf = (AbstractField<String>) e.getComponent(0);             
        }else if (e.getComponent(0) instanceof HorizontalLayout){               
            tf = (AbstractField<String>) e.getComponent(1);
        }else{
            tf = (AbstractField<String>) e.getComponent(1);
        }
        /* Ajout du style*/
        if (validate){
            tf.removeStyleName(StyleConstants.FIELD_ERROR_COMPLETE);
        }else{
            tf.addStyleName(StyleConstants.FIELD_ERROR_COMPLETE);
        }
    });
}
项目:esup-ecandidat    文件:GridFormatting.java   
/**
 * Ajoute un filtre en TextField sur une liste de colonnes
 * 
 * @param filterRow
 * @param container
 * @param propertys
 */
private void addStringFilters(String... propertys) {
    for (String property : propertys) {
        HeaderCell cell = getFilterCell(property);
        TextField filterField = new TextField();
        filterField.setImmediate(true);
        filterField.setWidth(100, Unit.PERCENTAGE);
        filterField.addStyleName(ValoTheme.TEXTFIELD_TINY);
        filterField.setInputPrompt(applicationContext.getMessage("filter.all", null, UI.getCurrent().getLocale()));
        filterField.addTextChangeListener(change -> {
            // Can't modify filters so need to replace
            container.removeContainerFilters(property);
            // (Re)create the filter if necessary
            if (!change.getText().isEmpty()) {
                container.addContainerFilter(new InsensitiveStringFilter(property, change.getText()));
            }
            fireFilterListener();
        });
        cell.setComponent(filterField);
    }
}
项目:osc-core    文件:SetNATSettingsWindow.java   
@Override
public void populateForm() {
    this.ipAddress = new TextField("IPv4 Address");
    this.ipAddress.setImmediate(true);

    // filling form with existing data
    if (this.networkLayout.natTable.getItem(1).getItemProperty("Value").getValue() != null) {
        this.ipAddress.setValue(this.networkLayout.natTable.getItem(1).getItemProperty("Value").getValue()
                .toString());
    }

    // adding not null constraint
    this.ipAddress.setRequired(true);
    this.ipAddress.setRequiredError("IPv4 Address cannot be empty");

    this.form.addComponent(this.ipAddress);
    this.ipAddress.focus();

}
项目:tinypounder    文件:TinyPounderMainUI.java   
private void updateOffHeapGrid() {
  int nRows = offheaps.getValue().intValue() + 1;
  // removes rows
  for (int r = offheapGrid.getRows(); r > nRows; r--) {
    offheapGrid.removeRow(r - 1);
  }
  // set new row limit
  offheapGrid.setRows(nRows);
  // add new rows
  for (int r = 1; r < nRows; r++) {
    if (offheapGrid.getComponent(0, r) == null) {
      TextField name = new TextField();
      name.setPlaceholder("Name");
      name.setValue("offheap-" + r);
      TextField memory = new TextField();
      memory.setPlaceholder("Size (MB)");
      memory.setValue("256");
      offheapGrid.addComponent(name, 0, r);
      offheapGrid.addComponent(memory, 1, r);
    }
  }
}
项目:tinypounder    文件:TinyPounderMainUI.java   
private void updateDataRootGrid() {
  int header = getDataRootFirstRow();
  int nRows = dataRoots.getValue().intValue() + header;
  // removes rows
  for (int r = dataRootGrid.getRows(); r > nRows; r--) {
    dataRootGrid.removeRow(r - 1);
  }
  // set new row limit
  dataRootGrid.setRows(nRows);
  // add new rows
  for (int r = header; r < nRows; r++) {
    if (dataRootGrid.getComponent(0, r) == null) {
      TextField id = new TextField();
      id.setPlaceholder("ID");
      id.setValue("dataroot-" + (r - header + 1));
      TextField path = new TextField();
      path.setPlaceholder("Location");
      path.setValue(new File(baseLocation.getValue(), "data/dataroot-" + (r - header + 1)).getAbsolutePath());
      path.setEnabled(false);
      id.addValueChangeListener(event -> path.setValue(new File(baseLocation.getValue(), "data/" + event.getValue()).getAbsolutePath()));
      path.setWidth(100, Unit.PERCENTAGE);
      dataRootGrid.addComponent(id, 0, r, 1, r);
      dataRootGrid.addComponent(path, DATAROOT_PATH_COLUMN, r);
    }
  }
}
项目:tinypounder    文件:TinyPounderMainUI.java   
private void platformBackupWanted(boolean wanted) {
  int row = getBackupRow();
  if (wanted) {
    dataRootGrid.insertRow(row);
    TextField id = new TextField();
    id.setPlaceholder("ID");
    id.setValue("BACKUP");
    id.setReadOnly(true);
    TextField path = new TextField();
    path.setPlaceholder("Location");
    path.setValue(new File(baseLocation.getValue(), "data/backup").getAbsolutePath());
    path.setEnabled(false);
    path.setWidth(100, Unit.PERCENTAGE);
    dataRootGrid.addComponent(id, 0, row, 1, row);
    dataRootGrid.addComponent(path, DATAROOT_PATH_COLUMN, row);
  } else {
    dataRootGrid.removeRow(row);
  }
}
项目:tinypounder    文件:TinyPounderMainUI.java   
private void platformPersistenceWanted(boolean wanted) {
  int row = getPersistenceRow();
  if (wanted) {
    dataRootGrid.insertRow(row);
    TextField id = new TextField();
    id.setPlaceholder("ID");
    id.setValue("PLATFORM");
    id.setReadOnly(true);
    TextField path = new TextField();
    path.setPlaceholder("Location");
    path.setValue(new File(baseLocation.getValue(), "data/platform").getAbsolutePath());
    path.setEnabled(false);
    path.setWidth(100, Unit.PERCENTAGE);
    dataRootGrid.addComponent(id, 0, row, 1, row);
    dataRootGrid.addComponent(path, DATAROOT_PATH_COLUMN, row);
  } else {
    dataRootGrid.removeRow(row);
  }
}
项目:holon-vaadin    文件:ExampleInput.java   
public void input7() {
    // tag::input7[]
    Input<Integer> integerInput = Components.input.number(Integer.class).build();

    Input<Boolean> booleanInput = Input.from(integerInput, // <1>
            Converter.from(value -> Result.ok((value == null) ? null : (value ? 1 : 0)),
                    value -> (value == null) ? Boolean.FALSE : (value.intValue() > 0)));

    Boolean boolValue = booleanInput.getValue();

    final Property<Boolean> BOOL_PROPERTY = PathProperty.create("bool", Boolean.class);
    booleanInput = Input.from(integerInput, BOOL_PROPERTY, PropertyValueConverter.numericBoolean(Integer.class)); // <2>

    Input<Long> longInput = Input.from(new TextField(), // <3>
            Converter.from(value -> Result.ok((value == null) ? null : value.toString()),
                    value -> (value == null || value.trim().isEmpty()) ? null : Long.parseLong(value)));
    // end::input7[]
}
项目:vaadin-karaf    文件:MyUI.java   
@Override
protected void init(VaadinRequest vaadinRequest) {
    final VerticalLayout layout = new VerticalLayout();

    final TextField name = new TextField();
    name.setCaption("Type your name here:");

    Button button = new Button("Click Me");
    button.addClickListener(e -> {
        layout.addComponent(new Label("Thanks " + name.getValue() + ", it works!"));
    });

    layout.addComponents(name, button);

    setContent(layout);
}
项目:dungeonstory-java    文件:UserGrid.java   
public UserGrid() {
    super(User.class);

    removeAllColumns();

    Binder<User> binder = new BeanValidationBinder<>(User.class);

    getEditor().setEnabled(true);
    getEditor().setBinder(binder);
    getEditor().setCancelCaption(Messages.getInstance().getMessage("button.cancel"));
    getEditor().setSaveCaption(Messages.getInstance().getMessage("button.save"));

    EnumComboBox<AccessRole> roleEditor = new EnumComboBox<>(AccessRole.class);
    binder.forField(roleEditor).bind(User::getRole, User::setRole);

    addColumn(User::getUsername).setCaption("Utilisateur").setId("username");
    addColumn(User::getRole).setCaption("Role").setId("role").setEditorComponent(roleEditor, User::setRole);
    addColumn(User::getName).setCaption("Nom").setId("name");
    addColumn("email").setCaption("Courriel").setEditorComponent(new TextField());

    setRowHeight(40);
}
项目:vaadin-stackpanel    文件:DemoUI.java   
public SectionPanel(String caption) {
    setCaption(caption);
    setContent(new HorizontalLayout() {

        {
            setSizeFull();
            setMargin(true);
            setSpacing(true);
            setDefaultComponentAlignment(Alignment.BOTTOM_LEFT);
            addComponents(
                    new TextField("First Name"),
                    new TextField("Last Name"),
                    new TextField("Phone"),
                    new Button("Save"));
        }
    });
}
项目:cherry-web    文件:SimpleEditor.java   
@Override
public void initUi() {

    title = new TextField("Title");
    title.setValue(data.getString("title", ""));
    title.setWidth("100%");
    addComponent(title);

    textUi = new CherryRichTextArea();
    text = textUi.createEditor();
    textUi.setComponentEditor(text);

    try {
        textUi.setValue(data.getString("text", ""));
    } catch (MException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    text.setSizeFull();
    addComponent(text);

}
项目:hawkbit    文件:UploadConfirmationWindow.java   
private void addFileNameLayout(final Item newItem, final String baseSoftwareModuleNameVersion,
        final String customFileName, final String itemId) {
    final HorizontalLayout horizontalLayout = new HorizontalLayout();
    final TextField fileNameTextField = createTextField(
            baseSoftwareModuleNameVersion + "/" + customFileName + "/customFileName");
    fileNameTextField.setData(baseSoftwareModuleNameVersion + "/" + customFileName);
    fileNameTextField.setValue(customFileName);

    newItem.getItemProperty(FILE_NAME).setValue(fileNameTextField.getValue());

    final Label warningIconLabel = getWarningLabel();
    warningIconLabel.setId(baseSoftwareModuleNameVersion + "/" + customFileName + "/icon");
    setWarningIcon(warningIconLabel, fileNameTextField.getValue(), itemId);
    newItem.getItemProperty(WARNING_ICON).setValue(warningIconLabel);

    horizontalLayout.addComponent(fileNameTextField);
    horizontalLayout.setComponentAlignment(fileNameTextField, Alignment.MIDDLE_LEFT);
    horizontalLayout.addComponent(warningIconLabel);
    horizontalLayout.setComponentAlignment(warningIconLabel, Alignment.MIDDLE_RIGHT);
    newItem.getItemProperty(FILE_NAME_LAYOUT).setValue(horizontalLayout);

    fileNameTextField.addTextChangeListener(event -> onFileNameChange(event, warningIconLabel, newItem));
}
项目:hawkbit    文件:UploadConfirmationWindow.java   
private void onFileNameChange(final TextChangeEvent event, final Label warningIconLabel, final Item newItem) {

        final String itemId = (String) ((TextField) event.getComponent()).getData();
        final String fileName = event.getText();

        final Boolean isWarningIconDisplayed = isWarningIcon(warningIconLabel);
        setWarningIcon(warningIconLabel, fileName, itemId);

        final Long currentSwId = (Long) newItem.getItemProperty(BASE_SOFTWARE_ID).getValue();
        final String oldFileName = (String) newItem.getItemProperty(FILE_NAME).getValue();
        newItem.getItemProperty(FILE_NAME).setValue(event.getText());

        // if warning was displayed prior and not displayed currently
        if (isWarningIconDisplayed && !warningIconLabel.isVisible()) {
            modifyIconOfSameSwId(itemId, currentSwId, oldFileName);
        }
        checkDuplicateEntry(itemId, currentSwId, event.getText(), oldFileName);
        enableOrDisableUploadBtn();
    }
项目:hawkbit    文件:TargetDetails.java   
private HorizontalLayout getSecurityTokenLayout(final String securityToken) {
    final HorizontalLayout securityTokenLayout = new HorizontalLayout();

    final Label securityTableLbl = new Label(
            SPUIComponentProvider.getBoldHTMLText(getI18n().getMessage("label.target.security.token")),
            ContentMode.HTML);
    securityTableLbl.addStyleName(SPUIDefinitions.TEXT_STYLE);
    securityTableLbl.addStyleName("label-style");

    final TextField securityTokentxt = new TextField();
    securityTokentxt.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS);
    securityTokentxt.addStyleName(ValoTheme.TEXTFIELD_TINY);
    securityTokentxt.addStyleName("targetDtls-securityToken");
    securityTokentxt.addStyleName(SPUIDefinitions.TEXT_STYLE);
    securityTokentxt.setCaption(null);
    securityTokentxt.setNullRepresentation("");
    securityTokentxt.setValue(securityToken);
    securityTokentxt.setReadOnly(true);

    securityTokenLayout.addComponent(securityTableLbl);
    securityTokenLayout.addComponent(securityTokentxt);
    return securityTokenLayout;
}
项目:cherry-web    文件:ActionDialog.java   
@Override
protected void initContent(VerticalLayout layout) throws Exception {
    setCaption(operation.getDescription().getCaption());
    {
        TextField label = new TextField();
        label.setEnabled(false);
        label.setValue(nodePaths());
        label.setWidth("100%");
        layout.addComponent(label);
    }
    editor = operation.createEditor(editorProperties, this);
    if (editor != null) {
        layout.addComponent(editor);
        layout.setExpandRatio(editor, 1);
    }
}
项目:Vaadin-Prime-Count    文件:EnvironmentStatusbar.java   
protected static void amendHeapStatusField(final TextField txtfHeapSttus, final String formatter)
{
    if (UI.getCurrent().isAttached())
    {
        UI.getCurrent().access( //NOPMD
                () -> {
                    if (null == formatter || null == txtfHeapSttus)
                    {
                        LoggerFactory.getLogger(EnvironmentStatusbar.class).warn( //NOPMD
                                "'formatter' and 'txtfHeapStts' of method 'amendHeapStatusField' both must no be null");
                        return;
                    }
                    txtfHeapSttus.setValue(formatter);
                }); //NOPMD
    }
}
项目:SecureBPMN    文件:LongFormPropertyRenderer.java   
@Override
public Field getPropertyField(FormProperty formProperty) {
  final TextField textField = new TextField(getPropertyLabel(formProperty));
  textField.setRequired(formProperty.isRequired());
  textField.setEnabled(formProperty.isWritable());
  textField.setRequiredError(getMessage(Messages.FORM_FIELD_REQUIRED, getPropertyLabel(formProperty)));

  if (formProperty.getValue() != null) {
    textField.setValue(formProperty.getValue());
  }

  // Add validation of numeric value
  textField.addValidator(new LongValidator("Value must be a long"));
  textField.setImmediate(true);

  return textField;
}
项目:SecureBPMN    文件:AccountSelectionPopup.java   
protected void initAlfrescoComponent() {
  alfrescoForm = new Form();
  alfrescoForm.setDescription(i18nManager.getMessage(Messages.ALFRESCO_DESCRIPTION));

  final TextField alfrescoServer = new TextField(i18nManager.getMessage(Messages.ALFRESCO_SERVER));
  alfrescoForm.getLayout().addComponent(alfrescoServer);

  final TextField alfrescoUserName = new TextField(i18nManager.getMessage(Messages.ALFRESCO_USERNAME));
  alfrescoForm.getLayout().addComponent(alfrescoUserName);

  final PasswordField alfrescoPassword = new PasswordField(i18nManager.getMessage(Messages.ALFRESCO_PASSWORD));
  alfrescoForm.getLayout().addComponent(alfrescoPassword);

  // Matching listener
  alfrescoClickListener = new ClickListener() {
    public void buttonClick(ClickEvent event) {
      Map<String, Object> accountDetails = createAccountDetails(
              "alfresco", 
              alfrescoUserName.getValue().toString(), 
              alfrescoPassword.getValue().toString(),
              "server", alfrescoServer.getValue().toString()
              ); 
      fireEvent(new SubmitEvent(AccountSelectionPopup.this, SubmitEvent.SUBMITTED, accountDetails));
    }
  };
}
项目:SecureBPMN    文件:TaskListHeader.java   
protected void initInputField() {
  // Csslayout is used to style inputtext as rounded
  CssLayout csslayout = new CssLayout();
  csslayout.setHeight(24, UNITS_PIXELS);
  csslayout.setWidth(100, UNITS_PERCENTAGE);
  layout.addComponent(csslayout);

  inputField = new TextField();
  inputField.setWidth(100, UNITS_PERCENTAGE);
  inputField.addStyleName(ExplorerLayout.STYLE_SEARCHBOX);
  inputField.setInputPrompt(i18nManager.getMessage(Messages.TASK_CREATE_NEW));
  inputField.focus();
  csslayout.addComponent(inputField);

  layout.setComponentAlignment(csslayout, Alignment.MIDDLE_LEFT);
  layout.setExpandRatio(csslayout, 1.0f);
}
项目:SecureBPMN    文件:SelectUsersPopupWindow.java   
protected void initSearchField() {
  HorizontalLayout searchLayout = new HorizontalLayout();
  searchLayout.setSpacing(true);
  addComponent(searchLayout);

  // textfield
  searchField = new TextField();
  searchField.setInputPrompt(i18nManager.getMessage(Messages.PEOPLE_SEARCH));
  searchField.setWidth(180, UNITS_PIXELS);
  searchField.focus();
  searchLayout.addComponent(searchField);

  // Logic to change table according to input
  searchField.addListener(new TextChangeListener() {
    public void textChange(TextChangeEvent event) {
      searchPeople(event.getText());
    }
  });

  initSelectMyselfButton(searchLayout);
}
项目:vaadin-grid-util    文件:FieldFactory.java   
public static <T> TextField genNumberField(Binder<T> binder, String propertyId, Converter converter, String inputPrompt) {
    final TextField field = new TextField();
    field.setWidth("100%");
    field.addStyleName(STYLENAME_GRIDCELLFILTER);
    field.addStyleName(ValoTheme.TEXTFIELD_TINY);
    field.addValueChangeListener(e -> {
        if (binder.isValid()) {
            field.setComponentError(null);
        }
    });
    binder.forField(field)
            .withNullRepresentation("")
            // .withValidator(text -> text != null && text.length() > 0, "invalid")
            .withConverter(converter)
            .bind(propertyId);
    field.setPlaceholder(inputPrompt);
    return field;
}
项目:SecureBPMN    文件:SubTaskComponent.java   
protected void initAddButton() {
  addSubTaskButton = new Button();
  addSubTaskButton.addStyleName(ExplorerLayout.STYLE_ADD);
  addSubTaskPanel.addComponent(addSubTaskButton);
  addSubTaskButton.addListener(new ClickListener() {
    public void buttonClick(ClickEvent event) {
      // Remove button
      addSubTaskPanel.removeAllComponents();

      // And add textfield
      Label createSubTaskLabel = new Label("Create new subtask:");
      createSubTaskLabel.addStyleName(Reindeer.LABEL_SMALL);
      addSubTaskPanel.addComponent(createSubTaskLabel);
      newTaskTextField = new TextField();
      newTaskTextField.focus();
      addSubTaskPanel.addComponent(newTaskTextField);
    }
  });
}
项目:minimal-j    文件:Vaadin.java   
private TextField createSearchField() {
TextField textFieldSearch = new TextField();
      textFieldSearch.setWidth("30ex");
      textFieldSearch.addShortcutListener(new ShortcutListener("Search", ShortcutAction.KeyCode.ENTER, null) {
    private static final long serialVersionUID = 1L;

    @Override
    public void handleAction(Object sender, Object target) {
        if (target == textFieldSearch) {
            String query = textFieldSearch.getValue();
            Page page = Application.getInstance().createSearchPage(query);
            show(page);
        }
    }
});

      return textFieldSearch;
  }
项目:holon-vaadin7    文件:ExampleListing.java   
public void listing12() {
    // tag::listing12[]
    PropertyListing listing = Components.listing.properties(PROPERTIES) //
            .editable(true) // <1>
            .editorSaveCaption("Save item") // <2>
            .editorCancelCaption("Discard") // <3>
            .editable(ID, false) // <4>
            .editor(DESCRIPTION, new TextField()) // <5>
            .withValidator(DESCRIPTION, Validator.max(100)) // <6>
            .required(ID) // <7>
            .build();
    // end::listing12[]
}
项目:holon-vaadin7    文件:ExampleInput.java   
public void input6() {
    // tag::input6[]
    ValidatableInput<String> validatableInput = ValidatableInput.from(Components.input.string().build()); // <1>

    validatableInput = ValidatableInput.from(new TextField()); // <2>

    validatableInput = Components.input.string().validatable() // <3>
            .required("Value is required") // <4>
            .withValidator(Validator.max(100)).build(); // <5>
    // end::input6[]
}
项目:easybinder    文件:ReflectionBinderTest.java   
@Test
public void testRequiredIndicatorVisible() {
    AbstractField<String> field = mock(TextField.class);
    EasyBinding<?,?,?> binding = binder.bind(field, "testIntMin1", new StringToIntegerConverter(""));
    assertNotNull(binding);
    verify(field, times(1)).setRequiredIndicatorVisible(true);
}
项目:easybinder    文件:ReflectionBinderTest.java   
@Test
public void testRequiredIndicatorNotVisible() {
    AbstractField<String> field = mock(TextField.class);
    EasyBinding<?,?,?> binding = binder.bind(field, "testIntMin0", new StringToIntegerConverter(""));
    assertNotNull(binding);
    verify(field, never()).setRequiredIndicatorVisible(true);
}
项目:easybinder    文件:ReflectionBinderTest.java   
@Test
public void testRequiredIndicatorNotVisibleNoAnnotation() {
    AbstractField<String> field = mock(TextField.class);
    EasyBinding<?,?,?> binding = binder.bind(field, "testInt", new StringToIntegerConverter(""));
    assertNotNull(binding);
    verify(field, never()).setRequiredIndicatorVisible(true);
}
项目:easybinder    文件:ReflectionBinderTest.java   
@Test
public void testRequiredIndicatorVisibleCustomIndicator() {
    AbstractField<String> field = mock(TextField.class);
    binder.setRequiredConfigurator(e -> true);
    assertNotNull(binder.getRequiredConfigurator());
    EasyBinding<?,?,?> binding = binder.bind(field, "testIntMin0", new StringToIntegerConverter(""));
    assertNotNull(binding);
    verify(field, times(1)).setRequiredIndicatorVisible(true);
}
项目:easybinder    文件:ComponentFactoryRegistryTest.java   
@Test
public void testNoMatch() throws NoSuchFieldException, SecurityException {
    cfr.addBuildPattern(MyNewType.class, e -> false, e -> mock(Component.class));
    Optional<Component> c = cfr.createComponent(this.getClass().getDeclaredField("newTypeField"));
    assertTrue(c.isPresent());
    assertTrue(c.get() instanceof TextField);
}
项目:easybinder    文件:BasicBinderNumberTest.java   
@Test
public void testValid() {
    TextField number = new TextField();

    BasicBinder<MyEntity> binder = new BasicBinder<>();
    binder.bind(number, d -> d.getNumber() == null ? "" : Integer.toString(d.getNumber()),
            (e, f) -> e.setNumber("".equals(f) ? null : Integer.parseInt(f)), "number");
    /*
     * binder.forField(number) .withNullRepresentation("") .withConverter(new
     * StringToIntegerConverter("Must be a number")) .bind("number");
     */
    MyEntity t = new MyEntity();

    // valid
    t.setNumber(1);
    binder.setBean(t);

    assertTrue(binder.isValid());

    // invalid
    t.setNumber(0);
    binder.setBean(t);
    assertFalse(binder.isValid());

    t.setNumber(null);
    binder.setBean(t);
    assertFalse(binder.isValid());

    assertEquals("", number.getValue());
    number.setValue("1");
    assertEquals(new Integer(1), t.getNumber());
    number.setValue("");

    assertEquals(null, t.getNumber());
}