Package com.vaadin.ui

Examples of com.vaadin.ui.Form


        setMainWindow(new Window(this.title, layout));
       
        final BeanContainer<String, Task> beans = new BeanContainer<String, Task>(Task.class);
        beans.setBeanIdProperty("id");

        final Form form = new Form();
        form.setLocale(Locale.GERMAN);
        final Table table = new Table(this.title, beans);
        MenuBar menu = createMenuBar(beans, table);
        layout.addComponent(menu);
       
        table.setSelectable(true);
        table.setImmediate(true);
        table.setVisibleColumns(VISIBLE_COLUMNS);
        table.addListener(new Property.ValueChangeListener() {
            public void valueChange(ValueChangeEvent event) {
                Object selectedId = table.getValue();
                @SuppressWarnings("unchecked")
                BeanItem<Task> item = (BeanItem<Task>) table.getItem(selectedId);
                form.setItemDataSource(item);
                form.setVisibleItemProperties(VISIBLE_COLUMNS);
           }
        });
        update(beans);
        layout.addComponent(table);

        Object first = table.getItemIds().iterator().next();
        Item item = table.getItem(first);
        form.setItemDataSource(item);

        form.setCaption("Edit Task");
        form.setVisibleItemProperties(VISIBLE_COLUMNS);
        form.setImmediate(true);
        form.addListener(new Property.ValueChangeListener() {
            public void valueChange(ValueChangeEvent event) {
                @SuppressWarnings("unchecked")
                BeanItem<Task> item = (BeanItem<Task>) form.getItemDataSource();
                taskService.updateTask(item.getBean());
            }
        });
        layout.addComponent(form);
    }
View Full Code Here


        GridLayout gl = new GridLayout(3, 3);
        gl.setSpacing(true);
        gl.addComponent(new Label("Before form"));
        gl.newLine();

        form = new Form(gl);
        form.setItemDataSource(new BeanItem<MyBean>(new MyBean()));

        gl.addComponent(new Label("After form"));

        w.addComponent(form);
View Full Code Here

        tf = new TextField("Disabled");
        tf.setImmediate(true);
        tf.setEnabled(false);
        twoLayout.addComponent(tf);

        form = new Form();
        form.setCaption("Enabled");
        form.setFormFieldFactory(new DefaultFieldFactory() {

            @Override
            public Field<?> createField(Item item, Object propertyId,
View Full Code Here

            // l.setCaption("Filler label");
            // cc.addComponent(l);
        }

        if (c == Form.class) {
            Form f = (Form) cc;
            f.setFormFieldFactory(new FormFieldFactory() {

                @Override
                public Field<?> createField(Item item, Object propertyId,
                        Component uiContext) {
                    formTextArea = new RichTextArea();
                    formTextArea.setVisible(false);
                    return formTextArea;
                }

            });
            f.setItemDataSource(new BeanItem<Object>(new Object() {
                private int a;

                @SuppressWarnings("unused")
                public int getA() {
                    return a;
View Full Code Here

        RegexpValidator validator2 = serializeAndDeserialize(validator);
        validator2.validate("aaa");
    }

    public void testForm() throws Exception {
        Form f = new Form();
        String propertyId = "My property";
        f.addItemProperty(propertyId, new MethodProperty<Object>(new Data(),
                "dummyGetterAndSetter"));
        f.replaceWithSelect(propertyId, new Object[] { "a", "b", null },
                new String[] { "Item a", "ITem b", "Null item" });

        serializeAndDeserialize(f);

    }
View Full Code Here

    }

    private Layout createForms() {
        GridLayout layout = new GridLayout(1, 5);
        Form form;

        Random r = new Random();
        GridLayout l1 = new GridLayout(1, 3);
        form = createForm(l1, "200px", "500px");
        BeanItem<FormObject> item = new BeanItem<FormObject>(new FormObject());
        form.setItemDataSource(item);
        for (Iterator<?> i = item.getItemPropertyIds().iterator(); i.hasNext();) {
            Object property = i.next();
            Field<?> f = form.getField(property);

            f.setRequired(r.nextBoolean());
            if (r.nextBoolean()) {
                f.setIcon(new ThemeResource("icons/16/document-add.png"));
            }
View Full Code Here

        return layout;
    }

    private Form createForm(GridLayout parentLayout, String w, String h) {
        FormLayout formLayout = new FormLayout();
        Form form = new Form(formLayout);

        VerticalLayout vl = new VerticalLayout();
        vl.setMargin(true);
        vl.setSizeFull();
        Panel p = new Panel("Form " + w + "x" + h, vl);
View Full Code Here

        subWindow.setModal(true);
        VerticalLayout layout = new VerticalLayout();
        layout.setWidth("100%");
        subWindow.setContent(layout);

        final Form form = new Form();
        form.setFooter(null);
        form.setImmediate(true);
        form.setValidationVisible(true);
        form.setCaption("This is a form");
        form.setDescription("How do you do?");
        final TextField field1 = new TextField("Write here");
        field1.setImmediate(true);
        field1.addValidator(new Validator() {

            @Override
            public void validate(Object value) throws InvalidValueException {
                if (!isValid(value)) {
                    throw new InvalidValueException("FAIL!");
                }
            }

            public boolean isValid(Object value) {
                return field1.getValue().equals("valid");
            }
        });
        form.addField("Field 1", field1);
        layout.addComponent(form);

        getMainWindow().addWindow(subWindow);
        subWindow.bringToFront();
    }
View Full Code Here

    @Override
    public void init() {

        LegacyWindow main = new LegacyWindow("The Main Window!!!");
        setMainWindow(main);
        Form form = new Form();
        VerticalLayout formLayout = new VerticalLayout();
        form.setLayout(formLayout);
        Select formSelect = new Select("hello");
        Select select = new Select("hello");
        form.setEnabled(false);
        select.setEnabled(false);
        formLayout.addComponent(formSelect);

        VerticalLayout l2 = new VerticalLayout();
        l2.addComponent(new Select("hello"));
        l2.setEnabled(false);

        form.setCaption("Form");
        main.addComponent(form);
        l2.setCaption("VerticalLayout");
        main.addComponent(l2);
        main.addComponent(select);
        main.addComponent(new Select("Enabled=true select"));
View Full Code Here

*/
public class FormTest {

    @Test
    public void testFocus() {
        Form form = new Form();
        final boolean firstFieldIsFocused[] = new boolean[1];
        TextField field1 = new TextField() {
            @Override
            public boolean isConnectorEnabled() {
                return false;
            }

            @Override
            public void focus() {
                firstFieldIsFocused[0] = true;
            }
        };

        final boolean secondFieldIsFocused[] = new boolean[1];
        TextField field2 = new TextField() {
            @Override
            public boolean isConnectorEnabled() {
                return true;
            }

            @Override
            public void focus() {
                secondFieldIsFocused[0] = true;
            }
        };
        form.addField("a", field1);
        form.addField("b", field2);
        form.focus();

        Assert.assertTrue("Field with enabled connector is not focused",
                secondFieldIsFocused[0]);
        Assert.assertFalse("Field with disabled connector is focused",
                firstFieldIsFocused[0]);
View Full Code Here

TOP

Related Classes of com.vaadin.ui.Form

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.