printStack.setVisibilityMode(VisibilityMode.MULTIPLE);
printStack.setWidth(400);
printStack.setHeight(455);
final DetailViewer printViewer = new DetailViewer();
printViewer.setDataSource(countryDS);
printViewer.setWidth100();
printViewer.setMargin(15);
printViewer.setEmptyMessage("Select a country to view its details");
final ListGrid printGrid = new ListGrid();
printGrid.setHeight(150);
printGrid.setDataSource(countryDS);
ListGridField countryCode = new ListGridField("countryCode", "Code", 50);
ListGridField countryName = new ListGridField("countryName", "Country");
ListGridField capital = new ListGridField("capital", "Capital");
ListGridField continent = new ListGridField("continent", "Continent");
printGrid.setFields(countryCode, countryName, capital, continent);
printGrid.addRecordClickHandler(new RecordClickHandler() {
public void onRecordClick(RecordClickEvent event) {
printViewer.setData(new Record[]{event.getRecord()});
}
});
SectionStackSection countriesSection = new SectionStackSection("Countries");
countriesSection.setExpanded(true);
countriesSection.addItem(printGrid);
printStack.addSection(countriesSection);
SectionStackSection detailsSection = new SectionStackSection("Country Details");
detailsSection.setExpanded(true);
detailsSection.addItem(printViewer);
printStack.addSection(detailsSection);
final VLayout printContainer = new VLayout(10);
HLayout printButtonLayout = new HLayout(5);
IButton newButton = new IButton("New");
newButton.setDisabled(true);
IButton changeButton = new IButton("Change");
changeButton.setDisabled(true);
IButton printPreviewButton = new IButton("Print Preview");
printPreviewButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
Canvas.showPrintPreview(printContainer);
}
});
printButtonLayout.addMember(newButton);
printButtonLayout.addMember(changeButton);
printButtonLayout.addMember(printPreviewButton);
printContainer.addMember(printStack);
printContainer.addMember(printButtonLayout);
// The filter is just to limit the number of records in the ListGrid - we don't want to print them all
printGrid.filterData(new Criteria("CountryName", "land"), new DSCallback() {
public void execute(DSResponse response, Object rawData, DSRequest request) {
printGrid.selectRecord(0);
printViewer.setData(new Record[]{printGrid.getSelectedRecord()});
}
});
return printContainer;
}