title.addStyleName(Reindeer.LABEL_H1);
header.addComponent(title);
final CheckBox vertical = new CheckBox("Vertical", !horizontal);
vertical.setImmediate(true);
vertical.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
view.removeAllComponents();
view.addComponent(createControls(!vertical.getValue()
.booleanValue()));
view.addComponent(createTestLayout(!vertical.getValue()
.booleanValue()));
view.setExpandRatio(view.getComponent(1), 1);
}
});
header.addComponent(vertical);
Button addComponent = new Button("Add Component",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
GridLayout grid = new GridLayout(2, 2);
Button grow = new Button("Grow Me",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
if (event.getButton().getWidth() == -1) {
event.getButton().setHeight("50px");
event.getButton().setWidth("200px");
} else {
event.getButton()
.setSizeUndefined();
}
}
});
grid.addComponent(new Label("Grid cell 1"));
grid.addComponent(new Label("Grid cell 2"));
grid.addComponent(grow);
grid.addComponent(new Label("Grid cell 4"));
l.addComponent(grid);
// l.addComponent(new TextField("Some field"));
}
});
header.addComponent(addComponent);
Button removeComponent = new Button("Remove Component",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Component last = l.getComponent(l.getComponentCount() - 1);
l.removeComponent(last);
}
});
header.addComponent(removeComponent);
// Second row
HorizontalLayout controls = new HorizontalLayout();
controls.setSpacing(true);
root.addComponent(controls);
// Layout controls
HorizontalLayout layout = new HorizontalLayout();
layout.addStyleName("fieldset");
layout.setSpacing(true);
controls.addComponent(layout);
layout.addComponent(new Label("Layout"));
ArrayList<String> sizes = new ArrayList<String>();
sizes.addAll(Arrays.asList("100px", "30em", "100%"));
final NativeSelect width = new NativeSelect(null, sizes);
width.setImmediate(true);
width.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
if (width.getValue() != null) {
l.setWidth(width.getValue().toString());
} else {
l.setWidth(null);
}
}
});
layout.addComponent(width);
layout.addComponent(new Label("×", ContentMode.HTML));
final NativeSelect height = new NativeSelect(null, sizes);
height.setImmediate(true);
height.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
if (height.getValue() != null) {
l.setHeight(height.getValue().toString());
} else {
l.setHeight(null);
}
}
});
layout.addComponent(height);
final CheckBox margin = new CheckBox("Margin", false);
margin.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
l.setMargin(margin.getValue().booleanValue());
}
});
margin.setImmediate(true);
layout.addComponent(margin);
layout.addComponent(margin);
final CheckBox spacing = new CheckBox("Spacing", false);
spacing.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
l.setSpacing(spacing.getValue().booleanValue());
}
});
spacing.setImmediate(true);
layout.addComponent(spacing);
// Cell controls
HorizontalLayout cell = new HorizontalLayout();
cell.addStyleName("fieldset");
cell.setSpacing(true);
controls.addComponent(cell);
cell.addComponent(new Label("Cell"));
ArrayList<Alignment> alignments = new ArrayList<Alignment>();
alignments.addAll(Arrays.asList(Alignment.TOP_LEFT,
Alignment.MIDDLE_LEFT, Alignment.BOTTOM_LEFT,
Alignment.TOP_CENTER, Alignment.MIDDLE_CENTER,
Alignment.BOTTOM_CENTER, Alignment.TOP_RIGHT,
Alignment.MIDDLE_RIGHT, Alignment.BOTTOM_RIGHT));
align = new NativeSelect(null, alignments);
for (Alignment a : alignments) {
align.setItemCaption(a,
a.getVerticalAlignment() + "-" + a.getHorizontalAlignment());
}
align.setImmediate(true);
align.setEnabled(false);
align.setNullSelectionAllowed(false);
align.select(Alignment.TOP_LEFT);
align.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
if (target == null) {
return;
}
l.setComponentAlignment(target, ((Alignment) align.getValue()));
}
});
cell.addComponent(align);
expand = new CheckBox("Expand");
expand.setImmediate(true);
expand.setEnabled(false);
expand.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
if (target != null) {
l.setExpandRatio(target, expand.getValue() ? 1 : 0);
}
}
});
cell.addComponent(expand);
// Component controls
HorizontalLayout component = new HorizontalLayout();
component.addStyleName("fieldset");
component.setSpacing(true);
root.addComponent(component);
component.addComponent(new Label("Component"));
sizes = new ArrayList<String>();
sizes.addAll(Arrays.asList("50px", "200px", "10em", "50%", "100%"));
componentWidth = new NativeSelect(null, sizes);
componentWidth.setImmediate(true);
componentWidth.setEnabled(false);
componentWidth.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
if (target == null) {
return;
}
if (componentWidth.getValue() != null) {
target.setWidth(componentWidth.getValue().toString());
} else {
target.setWidth(null);
}
}
});
component.addComponent(componentWidth);
component.addComponent(new Label("×", ContentMode.HTML));
componentHeight = new NativeSelect(null, sizes);
componentHeight.setImmediate(true);
componentHeight.setEnabled(false);
componentHeight.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
if (componentHeight.getValue() != null) {
target.setHeight(componentHeight.getValue().toString());
} else {
target.setHeight(null);
}
}
});
component.addComponent(componentHeight);
componentCaption = new NativeSelect("Caption", Arrays.asList("Short",
"Slightly Longer Caption"));
componentCaption.setImmediate(true);
componentCaption.setEnabled(false);
componentCaption.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
if (componentCaption.getValue() != null) {
target.setCaption(componentCaption.getValue().toString());
} else {
target.setCaption(null);
}
}
});
component.addComponent(componentCaption);
componentIcon = new NativeSelect("Icon", Arrays.asList(
"../runo/icons/16/folder.png", "../runo/icons/32/document.png"));
componentIcon.setImmediate(true);
componentIcon.setEnabled(false);
componentIcon.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
if (componentIcon.getValue() != null) {
target.setIcon(new ThemeResource(componentIcon.getValue()
.toString()));
} else {
target.setIcon(null);
}
}
});
component.addComponent(componentIcon);
componentDescription = new TextField("Description");
componentDescription.setImmediate(true);
componentDescription.setEnabled(false);
componentDescription.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
target.setDescription(componentDescription.getValue());
}
});
component.addComponent(componentDescription);
componentError = new CheckBox("Error");
componentError.setImmediate(true);
componentError.setEnabled(false);
componentError.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
if (target != null) {
target.setComponentError(componentError.getValue() ? new UserError(
"Error message") : null);
}
}
});
component.addComponent(componentError);
componentRequired = new CheckBox("Required");
componentRequired.setImmediate(true);
componentRequired.setEnabled(false);
componentRequired.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
if (target != null && target instanceof AbstractField) {
((AbstractField<?>) target).setRequired(componentRequired
.getValue());