Java Code Examples for com.vaadin.ui.TextField

The following are top voted examples for showing how to use com.vaadin.ui.TextField. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: easybinder   File: ComponentFactoryRegistry.java   Source Code and License 6 votes vote down vote up
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())));
}
 
Example 2
Project: easybinder   File: BinderAdapterTest.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 3
Project: easybinder   File: BasicBinderStringTest.java   Source Code and License 6 votes vote down vote up
@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());
}
 
Example 4
Project: easybinder   File: BeanValidationBinderStringTest.java   Source Code and License 6 votes vote down vote up
@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());
}
 
Example 5
Project: easybinder   File: BeanValidationBinderStringTest.java   Source Code and License 6 votes vote down vote up
@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());
}
 
Example 6
Project: easybinder   File: BeanValidationBinderBeanLevelTest.java   Source Code and License 6 votes vote down vote up
@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());
}
 
Example 7
Project: easybinder   File: BuildAndBindTest.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 8
Project: esup-ecandidat   File: SearchAnneeUnivApoField.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 9
Project: esup-ecandidat   File: I18nField.java   Source Code and License 6 votes vote down vote up
/** 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);
		}
	});
}
 
Example 10
Project: esup-ecandidat   File: GridFormatting.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 11
Project: osc-core   File: SetNATSettingsWindow.java   Source Code and License 6 votes vote down vote up
@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();

}
 
Example 12
Project: tinypounder   File: TinyPounderMainUI.java   Source Code and License 6 votes vote down vote up
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);
    }
  }
}
 
Example 13
Project: tinypounder   File: TinyPounderMainUI.java   Source Code and License 6 votes vote down vote up
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);
    }
  }
}
 
Example 14
Project: tinypounder   File: TinyPounderMainUI.java   Source Code and License 6 votes vote down vote up
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);
  }
}
 
Example 15
Project: tinypounder   File: TinyPounderMainUI.java   Source Code and License 6 votes vote down vote up
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);
  }
}
 
Example 16
Project: holon-vaadin   File: ExampleInput.java   Source Code and License 6 votes vote down vote up
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[]
}
 
Example 17
Project: vaadin-karaf   File: MyUI.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 18
Project: dungeonstory-java   File: UserGrid.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 19
Project: vaadin-stackpanel   File: DemoUI.java   Source Code and License 6 votes vote down vote up
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"));
        }
    });
}
 
Example 20
Project: cherry-web   File: SimpleEditor.java   Source Code and License 6 votes vote down vote up
@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);

}
 
Example 21
Project: hawkbit   File: UploadConfirmationWindow.java   Source Code and License 6 votes vote down vote up
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));
}
 
Example 22
Project: hawkbit   File: UploadConfirmationWindow.java   Source Code and License 6 votes vote down vote up
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();
    }
 
Example 23
Project: hawkbit   File: TargetDetails.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 24
Project: cherry-web   File: ActionDialog.java   Source Code and License 6 votes vote down vote up
@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);
	}
}
 
Example 25
Project: Vaadin-Prime-Count   File: EnvironmentStatusbar.java   Source Code and License 6 votes vote down vote up
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
    }
}
 
Example 26
Project: SecureBPMN   File: LongFormPropertyRenderer.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 27
Project: SecureBPMN   File: AccountSelectionPopup.java   Source Code and License 6 votes vote down vote up
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));
    }
  };
}
 
Example 28
Project: SecureBPMN   File: TaskListHeader.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 29
Project: SecureBPMN   File: SelectUsersPopupWindow.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 30
Project: vaadin-grid-util   File: FieldFactory.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 31
Project: SecureBPMN   File: SubTaskComponent.java   Source Code and License 6 votes vote down vote up
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);
    }
  });
}
 
Example 32
Project: minimal-j   File: Vaadin.java   Source Code and License 6 votes vote down vote up
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;
  }
 
Example 33
Project: holon-vaadin7   File: ExampleListing.java   Source Code and License 5 votes vote down vote up
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[]
}
 
Example 34
Project: holon-vaadin7   File: ExampleInput.java   Source Code and License 5 votes vote down vote up
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[]
}
 
Example 35
Project: easybinder   File: ReflectionBinderTest.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 36
Project: easybinder   File: ReflectionBinderTest.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 37
Project: easybinder   File: ReflectionBinderTest.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 38
Project: easybinder   File: ReflectionBinderTest.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 39
Project: easybinder   File: ComponentFactoryRegistryTest.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 40
Project: easybinder   File: BasicBinderNumberTest.java   Source Code and License 5 votes vote down vote up
@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());
}