summaryrefslogtreecommitdiffstats
path: root/java-vaadin/src/ch/asynk/helloworld/MainLayout.java
blob: d4481c14a934ad4c8c80219a4f4c31bb8f930f3b (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
package ch.asynk.helloworld;

import java.util.Date;

import com.vaadin.terminal.UserError;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Label;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Window.Notification;

public class MainLayout extends VerticalLayout {
    //
    private static final long serialVersionUID = 1L;
    //
    private Context ctx = null;

    public MainLayout(Context context) {
        ctx = context;
        //
        final AbstractComponent pa = buildPanel();
        pa.setWidth(250,UNITS_PIXELS);
        pa.setHeight(300,UNITS_PIXELS);
        addComponent(pa);
        setComponentAlignment(pa, Alignment.MIDDLE_CENTER);
        //
    }

    private AbstractComponent buildPanel() {
        Panel panel = new Panel("Main Layout");
        VerticalLayout layout = (VerticalLayout) panel.getContent();
        layout.setMargin(true);
        layout.setSpacing(true);
        layout.setHeight(100,UNITS_PERCENTAGE);
        //
        Label label = new Label("Hello world");
        layout.addComponent(label);
        //
        Button clockBtn = new Button("What is the time?");
        layout.addComponent( clockBtn );
        clockBtn.setIcon(Resources.clockIcon);
        clockBtn.addListener( new Button.ClickListener() {
            private static final long serialVersionUID = 1L;
            @Override
            public void buttonClick(ClickEvent event) {
                ctx.getApp().notifyError("The time is " + new Date(), "<i>italic</i> <b>bold</b> description");
                event.getButton().setComponentError( new UserError("Stop pressing this button !!") );
            }
        });
        ///
        layout.addComponent( new Button("throw an exception", new Button.ClickListener() {
            private static final long serialVersionUID = 1L;
            @Override
            public void buttonClick(ClickEvent event) {
                throw new RuntimeException("Wahou !! : exception");
            }
        }));
        //
        Button nextButton = new Button("next layout");
        nextButton.setDescription("Go to next layout");
        layout.addComponent(nextButton );
        nextButton.addListener( new Button.ClickListener() {
            private static final long serialVersionUID = 1L;
            @Override
            public void buttonClick(ClickEvent event) {
                ctx.getApp().getMainWindow().setContent( new DataMappingLayout(ctx) );
            }
        });
        //
        return panel;
    }
}