kids.add(new Kid("Lia", 2, new DateWrapper(2005, 1, 1).asDate()));
kids.add(new Kid("Andrew", 1, new DateWrapper(2007, 1, 1).asDate()));
person.setKids(kids);
VerticalPanel vp = new VerticalPanel();
vp.setSpacing(10);
final ContentPanel panel = new ContentPanel();
panel.setHeading("Basic Template");
panel.setWidth(300);
panel.setBodyStyleName("pad-text");
ToolBar toolbar = new ToolBar();
Button apply = new Button("Apply Template");
apply.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
Template template = new Template(getBasicTemplate());
template.overwrite(panel.getBody().dom, Util.getJsObject(person));
}
});
toolbar.add(apply);
panel.setTopComponent(toolbar);
final ContentPanel xpanel = new ContentPanel();
xpanel.setHeading("XTemplate Playground");
xpanel.setWidth(300);
xpanel.setBodyStyleName("pad-text");
ToolBar toolBar = new ToolBar();
toolBar.add(new Button("Apply Template", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
XTemplate tpl = XTemplate.create(getTemplate());
xpanel.removeAll();
xpanel.addText(tpl.applyTemplate(Util.getJsObject(person, 3)));
xpanel.layout();
}
}));
xpanel.setTopComponent(toolBar);
final ContentPanel cpanel = new ContentPanel();
cpanel.setHeading("XTemplate Test");
cpanel.setWidth(500);
cpanel.setBodyStyleName("pad-text");
final Html html = new Html();
html.setStyleName("pad-text");
final TextArea area = new TextArea();
area.setSize(485, 150);
toolBar = new ToolBar();
toolBar.add(new Button("Apply Template", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
String template = area.getValue();
XTemplate tpl = XTemplate.create(template);
tpl.overwrite(html.getElement(), Util.getJsObject(person, 3));
}
}));
cpanel.setTopComponent(toolBar);
StringBuilder sb = new StringBuilder();
sb.append("<p>Name: {name}</p>\r\n");
sb.append("<p>Company: {company}</p>\r\n");
sb.append("<p>Location: {location}</p>\r\n");
sb.append("<p>Salary: {income:currency}</p>\r\n");
sb.append("<p>Kids:</p>\r\n");
sb.append("<tpl for=\"kids\" if=\"name==\'Darrell Meyer\'\">\r\n");
sb.append("<tpl if=\"age > 1\"><p>{#}. {parent.name}\'s kid - {name} - {bday:date(\"M/d/yyyy\")}</p></tpl>");
sb.append("</tpl>\r\n");
area.setValue(sb.toString());
cpanel.add(area);
cpanel.add(html);
vp.add(panel);
vp.add(xpanel);
vp.add(cpanel);
add(vp);
}