summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/fieldgroup/AbstractBeanFieldGroupTest.java
blob: 894944d1861b43a22cf1a902337a829b17b1f76b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.vaadin.tests.fieldgroup;

import com.vaadin.data.fieldgroup.BeanFieldGroup;
import com.vaadin.data.fieldgroup.FieldGroup.CommitException;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.util.Log;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Notification;

public abstract class AbstractBeanFieldGroupTest extends TestBase {

    private Button commitButton;
    protected Log log = new Log(5);

    private Button discardButton;
    private Button showBeanButton;
    private BeanFieldGroup fieldBinder;

    @Override
    protected void setup() {
        addComponent(log);
    }

    protected Button getDiscardButton() {
        if (discardButton == null) {
            discardButton = new Button("Discard", new Button.ClickListener() {

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

                }
            });
        }
        return discardButton;
    }

    protected Button getShowBeanButton() {
        if (showBeanButton == null) {
            showBeanButton = new Button("Show bean values",
                    new Button.ClickListener() {

                        @Override
                        public void buttonClick(ClickEvent event) {
                            log.log(getFieldBinder().getItemDataSource()
                                    .getBean().toString());

                        }
                    });
        }
        return showBeanButton;
    }

    protected Button getCommitButton() {
        if (commitButton == null) {
            commitButton = new Button("Commit");
            commitButton.addListener(new ClickListener() {

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

                }
            });
        }
        return commitButton;
    }

    protected BeanFieldGroup getFieldBinder() {
        return fieldBinder;
    }

    protected void setFieldBinder(BeanFieldGroup beanFieldBinder) {
        fieldBinder = beanFieldBinder;
    }

    @Override
    protected String getDescription() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    protected Integer getTicketNumber() {
        // TODO Auto-generated method stub
        return null;
    }

}