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 ctrlPanel = buildListsPanel();
ctrlPanel.setWidth(500,UNITS_PIXELS);
ctrlPanel.setHeight(400,UNITS_PIXELS);
addComponent(ctrlPanel);
setComponentAlignment(ctrlPanel, Alignment.MIDDLE_CENTER);
//
}
private AbstractComponent buildListsPanel() {
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);
//
layout.addComponent( new Button("What is the time?", new Button.ClickListener() {
private static final long serialVersionUID = 1L;
@Override
public void buttonClick(ClickEvent event) {
ctx.getApp().notifyError("The time is " + new Date(), "italic bold description");
event.getButton().setComponentError( new UserError("Stop pressing this button !!") );
}
}));
///
Button exceptionButton = new Button("throw an exception");
layout.addComponent(exceptionButton );
exceptionButton.addListener( 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;
}
}