SectionStack sectionStack = new SectionStack();
sectionStack.setWidth(550);
sectionStack.setHeight(230);
String title = Canvas.imgHTML("silk/world.png") + " Countries Visited";
SectionStackSection section = new SectionStackSection(title);
section.setCanCollapse(false);
section.setExpanded(true);
final ListGrid countryGrid = new ListGrid();
countryGrid.setWidth(550);
countryGrid.setHeight(224);
countryGrid.setShowAllRecords(true);
countryGrid.setCellHeight(22);
countryGrid.setDataSource(CountryXmlDS.getInstance());
ListGridField countryCodeField = new ListGridField("countryCode", "Flag", 40);
countryCodeField.setAlign(Alignment.CENTER);
countryCodeField.setType(ListGridFieldType.IMAGE);
countryCodeField.setImageURLPrefix("flags/16/");
countryCodeField.setImageURLSuffix(".png");
countryCodeField.setCanEdit(false);
ListGridField nameField = new ListGridField("countryName", "Country");
ListGridField continentField = new ListGridField("continent", "Continent");
ListGridField memberG8Field = new ListGridField("member_g8", "Member G8");
ListGridField populationField = new ListGridField("population", "Population");
populationField.setType(ListGridFieldType.INTEGER);
populationField.setCellFormatter(new CellFormatter() {
public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
if(value == null) return null;
NumberFormat nf = NumberFormat.getFormat("0,000");
try {
return nf.format(((Number) value).longValue());
} catch (Exception e) {
return value.toString();
}
}
});
ListGridField independenceField = new ListGridField("independence", "Independence");
countryGrid.setFields(countryCodeField, nameField,continentField, memberG8Field, populationField, independenceField);
countryGrid.setAutoFetchData(true);
countryGrid.setCanEdit(true);
countryGrid.setEditEvent(ListGridEditEvent.CLICK);
section.setItems(countryGrid);
sectionStack.setSections(section);
return sectionStack;
}