当前位置: 首页>>代码示例>>Java>>正文


Java Binder.Binding方法代码示例

本文整理汇总了Java中com.vaadin.data.Binder.Binding方法的典型用法代码示例。如果您正苦于以下问题:Java Binder.Binding方法的具体用法?Java Binder.Binding怎么用?Java Binder.Binding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.vaadin.data.Binder的用法示例。


在下文中一共展示了Binder.Binding方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getComponentFor

import com.vaadin.data.Binder; //导入方法依赖的package包/类
protected final Component getComponentFor(ET pojo, String property) {
    ElementEditor editorsstuff = pojoToEditor.get(pojo);
    if (editorsstuff == null) {
        editorsstuff = createBoundEditor(pojo);
    }
    Component c = null;
    Optional<Binder.Binding<ET, ?>> binding = editorsstuff.beanBinder.getBinding(property);
    if (binding.isPresent()) {
        c = (Component) binding.get().getField();
    } else {
        try {
            // property that is not a property editor field but custom UI "column"
            java.lang.reflect.Field f = editorType.getDeclaredField(property);
            f.setAccessible(true);
            c = (Component) f.get(editorsstuff.editor);
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
            Logger.getLogger(AbstractElementCollection.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (c == null) {
            c = new Label("");
        }
    }

    return c;
}
 
开发者ID:viydaag,项目名称:dungeonstory-java,代码行数:26,代码来源:AbstractElementCollection.java

示例2: afterSuccessfulFetch

import com.vaadin.data.Binder; //导入方法依赖的package包/类
public void afterSuccessfulFetch(Badge badge) {
        binder.setBean(badge);

        Binder<AgeRange> ageRangeBinder = ageRangeGrid.getEditor().getBinder();
        TextField ageRangeCost = new TextField();
        TextField stripeColor = new TextField();
        TextField stripeText = new TextField();


        Binder.Binding<AgeRange, BigDecimal> costBinding = ageRangeBinder.forField(ageRangeCost)
                .withConverter(value -> value.isEmpty() ? new BigDecimal("0.00") : new BigDecimal(value),
                        value -> value == null ? "" : value.toString(),
                        "Price must be in ##.## format")
                .bind(AgeRange::getCost, AgeRange::setCost);

        // Don't allow editing of name, minage, or maxage because there's no way to add/remove
        // age ranges at run time. Lots of things assume that there are four of them:
        // Adult, Youth, Child, 5 or Under
//        Binder.Binding<AgeRange, Integer> minAgeBinding = ageRangeBinder.forField(minAge)
//                .withConverter(value -> value.isEmpty() ? new Integer(0) : new Integer(value),
//                        value -> value == null ? "" : value.toString(),
//                        "Minimum Age must be an integer > 0")
//                .bind(AgeRange::getMinAge, AgeRange::setMinAge);
//
//        Binder.Binding<AgeRange, Integer> maxAgeBinding = ageRangeBinder.forField(maxAge)
//                .withConverter(value -> value.isEmpty() ? new Integer(0) : new Integer(value),
//                        value -> value == null ? "" : value.toString(),
//                        "Maxiumum Age must be an integer <= 255")
//                .bind(AgeRange::getMaxAge, AgeRange::setMaxAge);

        ageRangeGrid.setItems(badge.getAgeRanges());
        ageRangeGrid.addColumn(AgeRange::getName).setCaption("Age Range");
        ageRangeGrid.addColumn(AgeRange::getMinAge).setCaption("Minimum Age");
        ageRangeGrid.addColumn(AgeRange::getMaxAge).setCaption("Maximum Age");
        ageRangeGrid.addColumn(AgeRange::getCost).setCaption("Cost").setEditorBinding(costBinding);
        ageRangeGrid.addColumn(AgeRange::getStripeColor).setCaption("Stripe Color").setEditorComponent(stripeColor, AgeRange::setStripeColor);
        ageRangeGrid.addColumn(AgeRange::getStripeText).setCaption("Stripe Text").setEditorComponent(stripeText, AgeRange::setStripeText);

        name.focus();
    }
 
开发者ID:kumoregdev,项目名称:kumoreg,代码行数:41,代码来源:BadgeEditView.java

示例3: addInternalElement

import com.vaadin.data.Binder; //导入方法依赖的package包/类
@Override
public void addInternalElement(final ET v) {
    ensureInited();
    items.add(v);

    Binder<ET> beanBinder = getBinderFor(v);
    for (String property : getVisibleProperties()) {
        Optional<Binder.Binding<ET, ?>> binding = beanBinder.getBinding(property);
        Component c = null;
        if (!binding.isPresent()) {
            c = getComponentFor(v, property.toString());
            Logger.getLogger(ElementCollectionField.class.getName()).log(Level.WARNING, "No editor field for{0}", property);
        } else {
            c = (Component) binding.get().getField();
        }
        gridLayout.addComponent(c);
        gridLayout.setComponentAlignment(c, Alignment.MIDDLE_LEFT);
    }
    if (getPopupEditor() != null) {
        FButton b = new FButton(VaadinIcons.EDIT).withStyleName(ValoTheme.BUTTON_ICON_ONLY).withClickListener(event -> editInPopup(v));
        gridLayout.addComponent(b);
    }
    if (isAllowRemovingItems()) {
        gridLayout.addComponent(createRemoveButton(v));
    }
    if (!isAllowEditItems()) {
        beanBinder.setReadOnly(true);
    }
}
 
开发者ID:viydaag,项目名称:dungeonstory-java,代码行数:30,代码来源:ElementCollectionField.java

示例4: getComponentFor

import com.vaadin.data.Binder; //导入方法依赖的package包/类
protected final Component getComponentFor(ET pojo, String property) {
    EditorStuff editorsstuff = pojoToEditor.get(pojo);
    if (editorsstuff == null) {
        Object o = createEditorInstance(pojo);
        Binder<ET> binder = new BeanValidationBinder<>(elementType);
        binder.bindInstanceFields(o);
        binder.addStatusChangeListener(scl);
        editorsstuff = new EditorStuff(binder, o);
        // TODO listen for all changes for proper modified/validity changes
        pojoToEditor.put(pojo, editorsstuff);
    }
    Component c = null;
    Optional<Binder.Binding<ET, ?>> binding = editorsstuff.bfg.getBinding(property);
    if (binding.isPresent()) {
        c = (Component) binding.get().getField();
    } else {
        try {
            // property that is not a property editor field but custom UI "column"
            java.lang.reflect.Field f = editorType.getDeclaredField(property);
            f.setAccessible(true);
            c = (Component) f.get(editorsstuff.editor);
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
            Logger.getLogger(AbstractElementCollection.class.getName()).
                    log(Level.SEVERE, null, ex);
        }
        if (c == null) {
            c = new Label("");
        }
    }

    return c;
}
 
开发者ID:viritin,项目名称:viritin,代码行数:33,代码来源:AbstractElementCollection.java

示例5: addInternalElement

import com.vaadin.data.Binder; //导入方法依赖的package包/类
@Override
public void addInternalElement(final ET v) {
    ensureInited();
    items.add(v);
    Binder<ET> fg = getFieldGroupFor(v);
    for (Object property : getVisibleProperties()) {
        Optional<Binder.Binding<ET, ?>> binding = fg.getBinding(property.toString());
        Component c = null;
        if (!binding.isPresent()) {
            c = getComponentFor(v, property.toString());
            Logger.getLogger(ElementCollectionField.class.getName())
                    .log(Level.WARNING, "No editor field for{0}", property);
        } else {
            // TODO, should always use getComponentFor ??
            c = (Component) binding.get().getField();
        }
        layout.addComponent(c);
        layout.setComponentAlignment(c, Alignment.MIDDLE_LEFT);
    }
    if (getPopupEditor() != null) {
        MButton b = new MButton(VaadinIcons.PENCIL)
                .withStyleName(ValoTheme.BUTTON_ICON_ONLY)
                .withListener(new Button.ClickListener() {
            private static final long serialVersionUID = 5019806363620874205L;
            @Override
            public void buttonClick(Button.ClickEvent event) {
                editInPopup(v);
            }
        });
        layout.add(b);
    }
    if (isAllowRemovingItems()) {
        layout.add(createRemoveButton(v));
    }
    if (!isAllowEditItems()) {
        fg.setReadOnly(true);
    }
}
 
开发者ID:viritin,项目名称:viritin,代码行数:39,代码来源:ElementCollectionField.java

示例6: setup

import com.vaadin.data.Binder; //导入方法依赖的package包/类
@BeforeClass
public static void setup() {
	RequiredFieldConfigurator MIN = annotation -> annotation.annotationType().equals(Min.class)
			&& ((Min) annotation).value() > 0;

	binder.setRequiredConfigurator(MIN.chain(RequiredFieldConfigurator.DEFAULT));

	Converter<String, Integer> c = Converter.from(e -> {
		if (e.length() == 0) {
			return Result.error("Must be a number");
		}
		try {
			return Result.ok(Integer.parseInt(e));
		} catch (NumberFormatException ex) {
			return Result.error("Must be a number");
		}
	}, e -> Integer.toString(e));

	binder.forField(form.airline).bind("flightId.airline");
	binder.forField(form.flightNumber).withConverter(c).bind("flightId.flightNumber");
	binder.forField(form.flightSuffix)
			.withConverter(Converter.from(
					e -> e.length() == 0 ? Result.ok(null)
							: (e.length() == 1 ? Result.ok(e.charAt(0)) : Result.error("Must be 1 character")),
					f -> f == null ? "" : "" + f))
			.bind("flightId.flightSuffix");
	binder.forField(form.date).withConverter(new LocalDateToDateConverter()).bind("flightId.date");
	binder.forField(form.legType).bind("flightId.legType");
	binder.forField(form.sbt).withConverter(new LocalDateTimeToDateConverter(ZoneId.systemDefault())).bind("sbt");
	binder.forField(form.ebt).withConverter(new LocalDateTimeToDateConverter(ZoneId.systemDefault())).bind("ebt");
	binder.forField(form.abt).withConverter(new LocalDateTimeToDateConverter(ZoneId.systemDefault())).bind("abt");
	Binder.Binding<Flight, String> scheduledDependingBinding = binder.forField(form.gate).withNullRepresentation("")
			.withValidator(e -> form.sbt.getValue() == null ? true : e != null, "Gate should be set when scheduled")
			.bind(Flight::getGate, Flight::setGate);
	form.sbt.addValueChangeListener(e -> scheduledDependingBinding.validate());

	binder.bindInstanceFields(form);

	binder.withValidator(e -> new FlightValidator().isValid(e, null), FlightValid.MESSAGE);

	form.flightNumber.setRequiredIndicatorVisible(true);
}
 
开发者ID:ljessendk,项目名称:easybinder,代码行数:43,代码来源:VaadinBeanBinderTest.java


注:本文中的com.vaadin.data.Binder.Binding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。