Package com.vaadin.data.fieldgroup

Examples of com.vaadin.data.fieldgroup.FieldGroup


        item.addItemProperty("date", new ObjectProperty<Date>(getDefaultDate()));

        FormLayout form = new FormLayout();
        form.setMargin(false);

        FieldGroup binder = new FieldGroup(item);
        form.addComponent(binder.buildAndBind(
                "Picker in read-only field group", "date"));
        binder.setReadOnly(true);

        row.addComponent(form);
    }
View Full Code Here


    }

    private void updateCalendarEventForm(CalendarEvent event) {
        BeanItem<CalendarEvent> item = new BeanItem<CalendarEvent>(event);
        scheduleEventFieldLayout.removeAllComponents();
        scheduleEventFieldGroup = new FieldGroup();
        initFormFields(scheduleEventFieldLayout, event.getClass());
        scheduleEventFieldGroup.setBuffered(true);
        scheduleEventFieldGroup.setItemDataSource(item);
    }
View Full Code Here

    public void fieldGroupBindAndUnbind() {
        item.addItemProperty("name", new TestingProperty<String>(
                "Just some text"));
        item.addItemProperty("age", new TestingProperty<String>("42"));

        final FieldGroup binder = new FieldGroup(item);
        binder.setBuffered(false);

        for (int i = 0; i < 2; ++i) {
            binder.bind(nameField, "name");
            binder.bind(ageField, "age");
            unboundField.setPropertyDataSource(unboundProp);

            assertTrue("No listeners in Properties", fieldsHaveListeners(true));

            binder.unbind(nameField);
            binder.unbind(ageField);
            unboundField.setPropertyDataSource(null);

            assertTrue("Listeners in Properties after unbinding",
                    fieldsHaveListeners(false));
        }
View Full Code Here

    @PropertyId("address.streetAddress")
    private TextField streetAddress;

    @Override
    protected void setup() {
        FieldGroup fieldGroup = new BeanFieldGroup<Person>(Person.class);
        fieldGroup.buildAndBindMemberFields(this);

        addComponent(firstName);
        addComponent(lastName);
        addComponent(streetAddress);

        fieldGroup.setItemDataSource(new BeanItem<Person>(new Person("Who",
                "me?", "email", 1, Sex.MALE, new Address("street name", 202020,
                        "City", Country.FINLAND))));
    }
View Full Code Here

    protected void setup() {
        addComponent(log);
        Panel confPanel = new ConfigurationPanel();
        addComponent(confPanel);

        final FieldGroup fieldGroup = new BeanFieldGroup<Person>(Person.class);
        fieldGroup.addCommitHandler(new CommitHandler() {

            @Override
            public void preCommit(CommitEvent commitEvent)
                    throws CommitException {
                if (configuration.preCommitFails) {
                    throw new CommitException(
                            "Error in preCommit because first name is "
                                    + getPerson(commitEvent.getFieldBinder())
                                            .getFirstName());
                }

            }

            @Override
            public void postCommit(CommitEvent commitEvent)
                    throws CommitException {
                if (configuration.postCommitFails) {
                    throw new CommitException(
                            "Error in postCommit because first name is "
                                    + getPerson(commitEvent.getFieldBinder())
                                            .getFirstName());
                }
            }
        });

        fieldGroup.setBuffered(true);

        fieldGroup.buildAndBindMemberFields(this);
        addComponent(firstName);
        addComponent(lastName);
        addComponent(email);
        addComponent(age);
        addComponent(sex);
        addComponent(deceased);

        Button commitButton = new Button("Commit", new Button.ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                String msg = "Commit succesful";
                try {
                    fieldGroup.commit();
                } catch (CommitException e) {
                    msg = "Commit failed: " + e.getMessage();
                }
                Notification.show(msg);
                log.log(msg);

            }
        });
        Button discardButton = new Button("Discard",
                new Button.ClickListener() {

                    @Override
                    public void buttonClick(ClickEvent event) {
                        fieldGroup.discard();
                        log.log("Discarded changes");

                    }
                });
        Button showBean = new Button("Show bean values",
                new Button.ClickListener() {

                    @Override
                    public void buttonClick(ClickEvent event) {
                        log.log(getPerson(fieldGroup).toString());

                    }
                });
        addComponent(commitButton);
        addComponent(discardButton);
        addComponent(showBean);
        email.addValidator(new EmailValidator("Must be a valid address"));
        lastName.addValidator(new StringLengthValidator("Must be min 5 chars",
                5, null, true));

        age.addValidator(new IntegerRangeValidator(
                "Must be between 0 and 150, {0} is not", 0, 150));
        sex.setPageLength(0);
        deceased.setConverter(new StringToBooleanConverter() {
            @Override
            protected String getTrueString() {
                return "YAY!";
            }

            @Override
            protected String getFalseString() {
                return "NAAAAAH";
            }
        });
        Person p = new Person("John", "Doe", "john@doe.com", 64, Sex.MALE,
                new Address("John street", 11223, "John's town", Country.USA));
        fieldGroup.setItemDataSource(new BeanItem<Person>(p));
    }
View Full Code Here

        public ConfigurationPanel() {
            super("Configuration", new VerticalLayout());
            ((VerticalLayout) getContent()).setMargin(true);
            BeanItem<Configuration> bi = new BeanItem<BasicPersonForm.Configuration>(
                    configuration);
            FieldGroup confFieldGroup = new FieldGroup(bi);
            confFieldGroup.setItemDataSource(bi);
            confFieldGroup.setBuffered(false);

            for (Object propertyId : bi.getItemPropertyIds()) {
                ((ComponentContainer) getContent()).addComponent(confFieldGroup
                        .buildAndBind(propertyId));
            }

        }
View Full Code Here

        BeanWithReadOnlyField bean = new BeanWithReadOnlyField();
        BeanItem<BeanWithReadOnlyField> beanItem = new BeanItem<BeanWithReadOnlyField>(
                bean);
        beanItem.getItemProperty("readOnlyField").setReadOnly(true);

        FieldGroup fieldGroup = new FieldGroup(beanItem);
        fieldGroup.bindMemberFields(this);

        assertTrue(readOnlyField.isReadOnly());
        assertFalse(writableField.isReadOnly());
    }
View Full Code Here

        BeanWithReadOnlyField bean = new BeanWithReadOnlyField();
        BeanItem<BeanWithReadOnlyField> beanItem = new BeanItem<BeanWithReadOnlyField>(
                bean);
        beanItem.getItemProperty("readOnlyField").setReadOnly(true);

        FieldGroup fieldGroup = new FieldGroup(beanItem);
        fieldGroup.bindMemberFields(this);

        fieldGroup.setReadOnly(true);
        assertTrue(readOnlyField.isReadOnly());
        assertTrue(writableField.isReadOnly());

        fieldGroup.setReadOnly(false);
        assertTrue(readOnlyField.isReadOnly());
        assertFalse(writableField.isReadOnly());
    }
View Full Code Here

        item.addItemProperty("testProperty", new ObjectProperty<String>(
                "Value of testProperty"));

        MySubClass form = new MySubClass();

        FieldGroup binder = new FieldGroup(item);
        binder.bindMemberFields(form);

        assertTrue("Value of testProperty".equals(form.test.getValue()));
    }
View Full Code Here

    @Override
    protected void setup() {
        getMainWindow().setLocale(Locale.US);
        addComponent(log);
        final FieldGroup fieldGroup = new BeanFieldGroup<DateObject>(
                DateObject.class);
        fieldGroup.setBuffered(true);

        fieldGroup.buildAndBindMemberFields(this);
        textField.setWidth("20em");
        addComponent(dateField);
        addComponent(popupDateField);
        addComponent(inlineDateField);
        addComponent(textField);

        Button commitButton = new Button("Commit", new Button.ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                String msg = "Commit succesful";
                try {
                    fieldGroup.commit();
                } catch (CommitException e) {
                    msg = "Commit failed: " + e.getMessage();
                }
                Notification.show(msg);
                log.log(msg);

            }
        });
        Button discardButton = new Button("Discard",
                new Button.ClickListener() {

                    @Override
                    public void buttonClick(ClickEvent event) {
                        fieldGroup.discard();
                        log.log("Discarded changes");

                    }
                });
        Button showBean = new Button("Show bean values",
                new Button.ClickListener() {

                    @Override
                    public void buttonClick(ClickEvent event) {
                        log.log(getPerson(fieldGroup).toString());

                    }
                });
        addComponent(commitButton);
        addComponent(discardButton);
        addComponent(showBean);

        DateObject d = new DateObject(new Date(443457289789L), new Date(
                443457289789L), new Date(443457289789L),
                new Date(443457289789L));
        fieldGroup.setItemDataSource(new BeanItem<DateObject>(d));
    }
View Full Code Here

TOP

Related Classes of com.vaadin.data.fieldgroup.FieldGroup

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.