com.vaadin.data.Binder Java Examples

The following examples show how to use com.vaadin.data.Binder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FormFactoryImpl.java    From cia with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the display property converters.
 *
 * @param                     <T> the generic type
 * @param displayProperties   the display properties
 * @param formContent         the form content
 * @param binder              the binder
 * @param propertyDescriptors the property descriptors
 */
private static <T extends Serializable> void createDisplayPropertyConverters(final List<String> displayProperties,
		final ComponentContainer formContent, final Binder<T> binder, final PropertyDescriptor[] propertyDescriptors) {
	for (final String property : displayProperties) {
		final Class<?> typeOfProperty = getTypeOfProperty(propertyDescriptors, property);

		if (typeOfProperty != null) {
			final AbstractField<?> field = new TextField();
			field.setReadOnly(true);
			field.setCaption(property);
			field.setWidth(ContentSize.FULL_SIZE);
			formContent.addComponent(field);
			final Converter converter = getConverterForType(typeOfProperty);

			if (converter != null) {
				binder.forField(field).withConverter(converter).bind(property);
			} else {
				binder.forField(field).bind(property);
			} 
		}
	}
}
 
Example #2
Source File: DemoUI.java    From gantt with Apache License 2.0 6 votes vote down vote up
private void commit(final Window win, final Binder<? extends AbstractStep> binder,
        final NativeSelect<Step> parentStepSelect) {
    AbstractStep step = binder.getBean();
    gantt.markStepDirty(step);
    if (parentStepSelect.isEnabled() && parentStepSelect.getValue() != null) {
        SubStep subStep = addSubStep(parentStepSelect, step);
        step = subStep;
    }
    if (step instanceof Step && !gantt.getSteps().contains(step)) {
        gantt.addStep((Step) step);
    }
    if (ganttListener != null && step instanceof Step) {
        ganttListener.stepModified((Step) step);
    }
    win.close();
}
 
Example #3
Source File: FieldFactory.java    From vaadin-grid-util with MIT 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 #4
Source File: FieldFactory.java    From vaadin-grid-util with MIT License 6 votes vote down vote up
public static <T> DateField genDateField(Binder<T> binder, String propertyId, final java.text.SimpleDateFormat dateFormat) {
    DateField dateField = new DateField();

    binder.bind(dateField, propertyId);
    if (dateFormat != null) {
        dateField.setDateFormat(dateFormat.toPattern());
    }
    dateField.setWidth("100%");

    dateField.setResolution(DateResolution.DAY);
    dateField.addStyleName(STYLENAME_GRIDCELLFILTER);
    dateField.addStyleName(ValoTheme.DATEFIELD_TINY);
    dateField.addValueChangeListener(e -> {
        if (binder.isValid()) {
            dateField.setComponentError(null);
        }
    });
    return dateField;
}
 
Example #5
Source File: AbstractElementCollection.java    From viritin with Apache License 2.0 6 votes vote down vote up
@Override
public void statusChange(StatusChangeEvent event) {
    ET bean = (ET) event.getBinder().getBean();
    if (bean == newInstance) {
        // God dammit, you can't rely on BeanValidationBinder.isValid !
        // Returns true here even if some notnull fields are not set :-(
        // Thus, check also with own BeanValidation logi, this should 
        // also give a bare bones cross field validation support for
        // elements
        final Binder<?> binder = event.getBinder();
        final boolean valid = binder.isValid();
        if (!valid || !isValidBean(bean)) {
            return;
        }
        getAndEnsureValue().add(newInstance);
        fireEvent(
                new ElementAddedEvent<>(AbstractElementCollection.this,
                newInstance));
        setPersisted(newInstance, true);
        onElementAdded();
    }
    // TODO
    fireValueChange();
}
 
Example #6
Source File: DemoUI.java    From gantt with Apache License 2.0 5 votes vote down vote up
private void delete(final Window win, final Binder<? extends AbstractStep> binder) {
    AbstractStep step = binder.getBean();
    if (step instanceof SubStep) {
        SubStep substep = (SubStep) step;
        substep.getOwner().removeSubStep(substep);
    } else {
        gantt.removeStep((Step) step);
        if (ganttListener != null) {
            ganttListener.stepDeleted((Step) step);
        }
    }
    win.close();
}
 
Example #7
Source File: AbstractElementCollection.java    From viritin with Apache License 2.0 5 votes vote down vote up
/**
 * Provides EditorStuff for pojo - creates a new one or reuses one from pojoToEditor map.
 * Returned EditorStuff is never null.
 * 
 * @param pojo the entity for which editor needs to be generated
 * @return editor stuff
 */
protected EditorStuff provideEditorStuff(ET pojo) {
	EditorStuff editorsstuff = pojoToEditor.get(pojo);
    if (editorsstuff == null) {
        Object o = createEditorInstance(pojo);
        Binder<ET> binder = instantiateBinder(elementType);
        binder.bindInstanceFields(o);
        binder.setBean(pojo);
        binder.addStatusChangeListener(scl);
        editorsstuff = new EditorStuff(binder, o);
        // TODO listen for all changes for proper modified/validity changes
        pojoToEditor.put(pojo, editorsstuff);
    }
    return editorsstuff;
}
 
Example #8
Source File: RangeCellFilterComponentTyped.java    From vaadin-grid-util with MIT License 5 votes vote down vote up
/**
 * create binder when not already done
 *
 * @return instance of binder
 */
public Binder<TwoValueObjectTyped<T>> getBinder() {
    if (this.binder == null) {
        this.binder = new Binder(TwoValueObjectTyped.class);
        this.binder.setBean(new TwoValueObjectTyped<>());
    }
    return this.binder;
}
 
Example #9
Source File: RangeCellFilterComponent.java    From vaadin-grid-util with MIT License 5 votes vote down vote up
/**
 * create binder when not already done
 *
 * @return instance of binder
 */
public Binder<TwoValueObject> getBinder() {
    if (this.binder == null) {
        this.binder = new Binder(TwoValueObject.class);
        this.binder.setBean(new TwoValueObject());
    }
    return this.binder;
}
 
Example #10
Source File: FormFactoryImpl.java    From cia with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends Serializable> void addFormPanelTextFields(final AbstractOrderedLayout panelContent, final T item,
		final Class<T> beanType, final List<String> displayProperties) {


	final Panel formPanel = new Panel();
	formPanel.setSizeFull();


	panelContent.addComponent(formPanel);
	if (displayProperties.size() > SIZE_FOR_GRID) {
		panelContent.setExpandRatio(formPanel, ContentRatio.GRID);
	}
	else {
		panelContent.setExpandRatio(formPanel, ContentRatio.SMALL_GRID);
	}


	final FormLayout formContent = new FormLayout();
	formPanel.setContent(formContent);
	formContent.setWidth(ContentSize.FULL_SIZE);

	final Binder<T> binder = new Binder<>(beanType);
	binder.setBean(item);
	binder.setReadOnly(true);

	PropertyDescriptor[] propertyDescriptors=null;
	try {
		final BeanInfo info = Introspector.getBeanInfo(item.getClass());
		propertyDescriptors = info.getPropertyDescriptors();
	} catch (final IntrospectionException exception) {
		LOGGER.error("No able to getfieldtypes for type:+ item.getClass()", exception);
	}

	createDisplayPropertyConverters(displayProperties, formContent, binder, propertyDescriptors);
}
 
Example #11
Source File: AbstractForm.java    From viritin with Apache License 2.0 4 votes vote down vote up
public Binder<T> getBinder() {
    return binder;
}
 
Example #12
Source File: AbstractForm.java    From viritin with Apache License 2.0 4 votes vote down vote up
public void setBinder(Binder<T> binder) {
    this.binder = binder;
}
 
Example #13
Source File: AbstractElementCollection.java    From viritin with Apache License 2.0 4 votes vote down vote up
private EditorStuff(Binder<ET> editor, Object o) {
    this.bfg = editor;
    this.editor = o;
}
 
Example #14
Source File: AbstractElementCollection.java    From viritin with Apache License 2.0 4 votes vote down vote up
protected Binder<ET> instantiateBinder(Class<ET> elementClass) {
	return new BeanValidationBinder<>(elementClass);
}
 
Example #15
Source File: AbstractElementCollection.java    From viritin with Apache License 2.0 4 votes vote down vote up
protected Binder<ET> getFieldGroupFor(ET pojo) {
    return provideEditorStuff(pojo).bfg;
}
 
Example #16
Source File: DemoUI.java    From gantt with Apache License 2.0 4 votes vote down vote up
private void cancel(final Window win, final Binder<? extends AbstractStep> binder) {
    win.close();
}
 
Example #17
Source File: CommitFormWrapperClickListener.java    From cia with Apache License 2.0 2 votes vote down vote up
/**
 * Instantiates a new commit form wrapper click listener.
 *
 * @param fieldGroup
 *            the field group
 * @param buttonListener
 *            the button listener
 */
public CommitFormWrapperClickListener(final Binder<?> fieldGroup, final ClickListener buttonListener) {
	this.binder = fieldGroup;
	this.buttonListener = buttonListener;
}