本文整理汇总了Java中com.vaadin.data.HasValue类的典型用法代码示例。如果您正苦于以下问题:Java HasValue类的具体用法?Java HasValue怎么用?Java HasValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HasValue类属于com.vaadin.data包,在下文中一共展示了HasValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bind
import com.vaadin.data.HasValue; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public <PRESENTATION, MODEL> EasyBinding<BEAN, PRESENTATION, MODEL> bind(HasValue<PRESENTATION> field,
String propertyName, Converter<PRESENTATION, ?> converter, boolean readOnly) {
Objects.requireNonNull(converter);
Objects.requireNonNull(propertyName, "Property name cannot be null");
// checkUnbound();
PropertyDefinition<BEAN, ?> definition = propertySet.getProperty(propertyName)
.orElseThrow(() -> new IllegalArgumentException(
"Could not resolve property name " + propertyName + " from " + propertySet));
ValueProvider<BEAN, ?> getter = definition.getGetter();
Setter<BEAN, ?> setter = readOnly ? null : definition.getSetter().orElse(null);
EasyBinding<BEAN, PRESENTATION, MODEL> binding = bind(field, (ValueProvider) getter, (Setter) setter,
propertyName, (Converter) converter);
boundProperties.put(propertyName, binding);
Optional<Field> modelField = getDeclaredFieldByName(definition.getPropertyHolderType(), definition.getName());
if (Arrays.asList(modelField.get().getAnnotations()).stream().anyMatch(requiredConfigurator)) {
field.setRequiredIndicatorVisible(true);
}
return binding;
}
示例2: EasyBinding
import com.vaadin.data.HasValue; //导入依赖的package包/类
public EasyBinding(BasicBinder<BEAN> binder, HasValue<FIELDVALUE> field, ValueProvider<BEAN, TARGET> getter,
Setter<BEAN, TARGET> setter, String property,
Converter<FIELDVALUE, TARGET> converterValidatorChain) {
this.field = field;
this.getter = getter;
this.setter = setter;
this.property = property;
this.converterValidatorChain = converterValidatorChain;
registration = field.addValueChangeListener(e -> {
if (binder.getBean() != null) {
if (binder.fieldToBean(this)) {
binder.fireValueChangeEvent(e);
}
}
});
if (setter == null) {
field.setReadOnly(true);
}
}
示例3: DatePickerHeader
import com.vaadin.data.HasValue; //导入依赖的package包/类
public DatePickerHeader(InlineDateField field, boolean lightTheme) {
setFlexDirection(FlexDirection.COLUMN);
setJustifyContent(JustifyContent.CENTER);
addStyleName(Paddings.Horizontal.LARGE);
addStyleName(FlexItem.FlexShrink.SHRINK_0);
this.field = field;
field.addValueChangeListener((HasValue.ValueChangeListener<LocalDate>) event -> {
year.setValue(field.getValue().format(DateTimeFormatter.ofPattern("yyyy")));
date.setValue(field.getValue().format(DateTimeFormatter.ofPattern("EEE, MMM d")));
});
setHeight(Metrics.DatePicker.HEADER_HEIGHT, Unit.PIXELS);
addStyleName(lightTheme ? MaterialColor.BLUE_500.getBackgroundColorStyle() : MaterialColor.GREY_700.getBackgroundColorStyle());
year.setPrimaryStyleName(Typography.Light.Body2.SECONDARY);
date.setPrimaryStyleName(Typography.Light.DatePicker.Title.PRIMARY);
addComponents(year, date);
}
示例4: setEditorBinding
import com.vaadin.data.HasValue; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private void setEditorBinding(P property, Column column, HasValue editor, boolean readOnly,
PropertyColumn<?, ?> pc) {
BindingBuilder builder = getGrid().getEditor().getBinder().forField(editor);
if (pc.isRequired()) {
final Localizable requiredMessage = (pc.getRequiredMessage() != null) ? pc.getRequiredMessage()
: RequiredInputValidator.DEFAULT_REQUIRED_ERROR;
builder.asRequired(context -> {
return LocalizationContext.translate(requiredMessage, true);
});
}
// default validators
getDefaultPropertyValidators(property).forEach(v -> builder.withValidator(new ValidatorWrapper<>(v)));
// validators
pc.getValidators().forEach(v -> builder.withValidator(v));
// bind
column.setEditorBinding(builder.bind(getColumnId(property)));
// set editable if not read-only
column.setEditable(!readOnly);
}
示例5: valueChange
import com.vaadin.data.HasValue; //导入依赖的package包/类
@Override
public void valueChange(HasValue.ValueChangeEvent<V> event) {
if (Objects.equals(event.getOldValue(), event.getValue())) {
// no change, no need to update the mode.
return;
}
if (FormGroupDefaults.BOOTSTRAP_MODE.equals(formGroup.getMode())) {
// mode is already updated, don't change it again.
return;
}
// value is changed, update the mode
formGroup.removeMode();
// value is changed, remove feedback if you are allowed to do it.
if (this.removeFeedback) {
formGroup.removeFeedback();
}
}
示例6: refreshLevelBonusVisibility
import com.vaadin.data.HasValue; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private void refreshLevelBonusVisibility(boolean visible, int... columns) {
final int nbRows = gridLayout.getRows();
final int nbColumns = gridLayout.getColumns();
for (int row = 0; row < nbRows; row++) {
for (int column = 0; column < nbColumns; column++) {
Component c = gridLayout.getComponent(column, row);
if (c != null) {
final int visibleColumn = column;
boolean match = IntStream.of(columns).anyMatch(x -> x == visibleColumn);
if (match) {
if (c instanceof HasValue && !visible) {
((HasValue) c).setValue(((HasValue) c).getEmptyValue());
}
c.setVisible(visible);
}
}
}
}
}
示例7: bind
import com.vaadin.data.HasValue; //导入依赖的package包/类
@Override
public <FIELDVALUE> Binding<BEAN, FIELDVALUE> bind(HasValue<FIELDVALUE> field, String propertyName) {
if (binder instanceof ReflectionBinder) {
return ((ReflectionBinder<BEAN>) binder).bind(field, propertyName);
} else {
throw new UnsupportedOperationException("Not supported");
}
}
示例8: bindProperty
import com.vaadin.data.HasValue; //导入依赖的package包/类
/**
* Binds {@code property} with {@code propertyType} to the field in the
* {@code objectWithMemberFields} instance using {@code memberField} as a
* reference to a member.
*
* @param objectWithMemberFields
* the object that contains (Java) member fields to build and bind
* @param memberField
* reference to a member field to bind
* @param propertyName
* property name to bind
* @param propertyType
* type of the property
* @return {@code true} if property is successfully bound
*/
protected boolean bindProperty(Object objectWithMemberFields, Field memberField, String propertyName,
Class<?> propertyType) {
log.log(Level.INFO, "Binding property, field={0}, property={1}",
new Object[] { memberField.getName(), propertyName });
Type valueType = GenericTypeReflector.getTypeParameter(memberField.getGenericType(),
HasValue.class.getTypeParameters()[0]);
if (valueType == null) {
throw new IllegalStateException(
String.format("Unable to detect value type for the member '%s' in the " + "class '%s'.",
memberField.getName(), objectWithMemberFields.getClass().getName()));
}
HasValue<?> field;
// Get the field from the object
try {
field = (HasValue<?>) ReflectTools.getJavaFieldValue(objectWithMemberFields, memberField, HasValue.class);
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
log.log(Level.INFO, "Not able to determine type of field");
// If we cannot determine the value, just skip the field
return false;
}
bind(field, propertyName);
return true;
}
示例9: isFieldBound
import com.vaadin.data.HasValue; //导入依赖的package包/类
protected boolean isFieldBound(Field memberField, Object objectWithMemberFields) {
try {
HasValue<?> field = (HasValue<?>) getMemberFieldValue(memberField, objectWithMemberFields);
return bindings.stream().anyMatch(binding -> binding.getField() == field);
} catch (Exception e) {
return false;
}
}
示例10: createAndBind
import com.vaadin.data.HasValue; //导入依赖的package包/类
protected Component createAndBind(Field f, String path) {
Optional<Component> c = ComponentFactoryRegistry.getInstance().createComponent(f);
if (!c.isPresent()) {
throw new RuntimeException("No Component factory matches field, field=<" + f + ">");
}
if (c.get() instanceof HasValue<?>) {
HasValue<?> h = (HasValue<?>) c.get();
bind(h, path + f.getName());
}
return c.get();
}
示例11: bind
import com.vaadin.data.HasValue; //导入依赖的package包/类
public <FIELDVALUE, TARGET> EasyBinding<BEAN, FIELDVALUE, TARGET> bind(HasValue<FIELDVALUE> field,
ValueProvider<BEAN, TARGET> getter, Setter<BEAN, TARGET> setter, String property,
Converter<FIELDVALUE, TARGET> converter) {
Objects.requireNonNull(field);
Objects.requireNonNull(getter);
Objects.requireNonNull(converter);
// Register as binding
EasyBinding<BEAN, FIELDVALUE, TARGET> binding = new EasyBinding<BEAN, FIELDVALUE, TARGET>(this, field, getter,
setter, property, converter);
// TODO: remove from binding
/*
* binding.registration = field.addValueChangeListener(e -> { if (getBean() !=
* null) { if(fieldToBean(binding)) { fireValueChangeEvent(e); } } });
*/
bindings.add(binding);
// Add property to validation error map
if (property != null) {
propertyToBindingMap.put(property, binding);
}
if (getBean() != null) {
if (fieldToBean(binding)) {
// TODO: should this be fired?
// fireValueChangeEvent(e);
}
} else {
fireStatusChangeEvent();
}
return binding;
}
示例12: EGTypeComponentAdapter
import com.vaadin.data.HasValue; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public EGTypeComponentAdapter(Class<T> genericType, Component adaptee) {
this.genericType = genericType;
this.component = adaptee;
hasValue = (HasValue<T>) adaptee;
hasValue.addValueChangeListener(e -> setValue(e.getValue()));
}
示例13: testGetFieldTypeForGenericFieldWithEmptyValue
import com.vaadin.data.HasValue; //导入依赖的package包/类
@Test
public void testGetFieldTypeForGenericFieldWithEmptyValue() {
@SuppressWarnings("unchecked")
HasValue<TestEnum> r = mock(HasValue.class);
when(r.getEmptyValue()).thenReturn(TestEnum.Test1);
assertTrue(binder.getPresentationTypeForField(r).isPresent());
assertEquals(TestEnum.class, binder.getPresentationTypeForField(r).get());
}
示例14: testGetFieldTypeForFieldWithNoInfo
import com.vaadin.data.HasValue; //导入依赖的package包/类
@Test
public void testGetFieldTypeForFieldWithNoInfo() {
@SuppressWarnings("unchecked")
HasValue<TestEnum> r = mock(HasValue.class);
// We don't expect any more than an empty optional
assertNotNull(binder.getPresentationTypeForField(r));
}
示例15: testBuildAndBind
import com.vaadin.data.HasValue; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testBuildAndBind() {
AutoBinder<MyEntity> binder = new AutoBinder<>(MyEntity.class);
binder.buildAndBind("car", "car.frontLeft", "car.frontLeft.tire", "spare", "spare.tire");
MyEntity entity = new MyEntity();
binder.setBean(entity);
assertTrue(binder.getFieldForProperty("street").isPresent());
assertTrue(binder.getFieldForProperty("number").isPresent());
assertTrue(binder.getFieldForProperty("number2").isPresent());
assertTrue(binder.getFieldForProperty("car.frontLeft.tire.type").isPresent());
assertTrue(binder.getFieldForProperty("spare.tire.type").isPresent());
assertTrue(binder.getFieldForProperty("unknown").isPresent());
AbstractField<String> numberField = (AbstractField<String>) binder.getFieldForProperty("number").get();
AbstractField<String> numberField2 = (AbstractField<String>) binder.getFieldForProperty("number2").get();
((HasValue<String>) binder.getFieldForProperty("street").get()).setValue("mystreet");
assertEquals("mystreet", entity.getStreet());
numberField.setValue("100");
assertEquals(new Integer(100), entity.getNumber());
assertNull(numberField.getComponentError());
numberField.setValue("0");
assertNotNull(numberField.getComponentError());
numberField.setValue("");
assertEquals(null, entity.getNumber());
assertNull(numberField.getComponentError());
numberField2.setValue("");
assertNotNull(numberField2.getComponentError());
}