/**
* create a grid with the appropriate structure.
* @return
*/
private Canvas createGridProducts() {
Canvas canvas = new Canvas();
productGrid.setWidth100();
productGrid.setHeight100();
productGrid.setEmptyCellValue("-");
GridFieldPrincipal aux = GridFieldPrincipal.getInstance();
aux.invalidateCache();
aux.destroy();
productGrid.setDataSource(aux);
//creates the columns
ListGridField nameField = new ListGridField("Name", constants.name());
ListGridField initialEstimationField = new ListGridField("InitialEstimation", constants.initialEstimation());
initialEstimationField.setWidth("10%");
ListGridField capitalField = new ListGridField("CurrentEstimation", constants.currentEstimation());
capitalField.setWidth("10%");
ListGridField descriptionField = new ListGridField("Description", constants.description());
productGrid.setFields(nameField, initialEstimationField, capitalField, descriptionField);
//configure the grid, by adding the context menu.
productGrid.setSortField(0);
productGrid.setDataPageSize(50);
productGrid.setAutoFetchData(true);
popupProduct();
productGrid.setContextMenu(menu);
//configure grid handlers.
productGrid.addRecordClickHandler(new RecordClickHandler() {
@Override
public void onRecordClick(RecordClickEvent event) {
ListGridRecord record = (ListGridRecord) event.getRecord();
idItemSelected = record.getAttribute("id");
popupProduct();
productGrid.setContextMenu(menu);
}
});
productGrid.addRowContextClickHandler( new RowContextClickHandler() {
@Override
public void onRowContextClick(RowContextClickEvent event) {
ListGridRecord record = (ListGridRecord) event.getRecord();
idItemSelected = record.getAttribute("id");
popupProduct();
productGrid.setContextMenu(menu);
}
});
productGrid.addRecordDoubleClickHandler(new RecordDoubleClickHandler() {
@Override
public void onRecordDoubleClick(RecordDoubleClickEvent event) {
ListGridRecord record = (ListGridRecord) event.getRecord();
idItemSelected = record.getAttribute("id");
popupProduct();
productGrid.setContextMenu(menu);
po.manageProducts(idItemSelected, SHOW);
}
});
canvas.addChild(productGrid);
return canvas;
}