Pandaman
8 Jul 2009, 1:36 PM
The following code demonstrates an issue with GridCellRenderer and gwt Hyperlink objects. It loads a TreeGrid and a standard Grid, with one cell each (a link to a blank page). The issue is that when one clicks anywhere in the cell other than the link, the blank page is launched. Only clicking the link should launch the window instead of the white space in the cell.
public void onModuleLoad() {
final VerticalPanel vertPanel = new VerticalPanel();
final ArrayList<ColumnConfig> treeGridColumnList = new ArrayList<ColumnConfig>();
final ColumnConfig nameColumn = new ColumnConfig("name", 200);
nameColumn.setRenderer(new GridCellRenderer<BaseModel>() {
public Object render(BaseModel model, String property,
ColumnData config, int rowIndex, int colIndex,
ListStore<BaseModel> store, Grid<BaseModel> grid) {
final String value = model.get(property);
final Hyperlink link = new Hyperlink(value, true, "");
link.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
Window.open("", "window", "location=1,status=1,scrollbars=1,width=100,height=100");
}
});
return link;
}
});
treeGridColumnList.add(nameColumn);
final ColumnModel treeGridCM = new ColumnModel(treeGridColumnList);
final TreeStore<BaseModel> treeGridData = new TreeStore<BaseModel>();
final BaseModel baseModel = new BaseModel();
baseModel.set("name", "Test");
treeGridData.add(baseModel, false);
final TreeGrid<BaseModel> treeGrid = new TreeGrid<BaseModel>(treeGridData, treeGridCM);
vertPanel.add(treeGrid);
final ArrayList<ColumnConfig> gridColumnList = new ArrayList<ColumnConfig>();
gridColumnList.add(nameColumn);
final ColumnModel gridCM = new ColumnModel(gridColumnList);
final ListStore<BaseModel> gridData = new ListStore<BaseModel>();
gridData.add(baseModel);
final Grid<BaseModel> grid = new Grid<BaseModel>(gridData, gridCM);
vertPanel.add(grid);
RootPanel.get().add(vertPanel);
}
public void onModuleLoad() {
final VerticalPanel vertPanel = new VerticalPanel();
final ArrayList<ColumnConfig> treeGridColumnList = new ArrayList<ColumnConfig>();
final ColumnConfig nameColumn = new ColumnConfig("name", 200);
nameColumn.setRenderer(new GridCellRenderer<BaseModel>() {
public Object render(BaseModel model, String property,
ColumnData config, int rowIndex, int colIndex,
ListStore<BaseModel> store, Grid<BaseModel> grid) {
final String value = model.get(property);
final Hyperlink link = new Hyperlink(value, true, "");
link.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
Window.open("", "window", "location=1,status=1,scrollbars=1,width=100,height=100");
}
});
return link;
}
});
treeGridColumnList.add(nameColumn);
final ColumnModel treeGridCM = new ColumnModel(treeGridColumnList);
final TreeStore<BaseModel> treeGridData = new TreeStore<BaseModel>();
final BaseModel baseModel = new BaseModel();
baseModel.set("name", "Test");
treeGridData.add(baseModel, false);
final TreeGrid<BaseModel> treeGrid = new TreeGrid<BaseModel>(treeGridData, treeGridCM);
vertPanel.add(treeGrid);
final ArrayList<ColumnConfig> gridColumnList = new ArrayList<ColumnConfig>();
gridColumnList.add(nameColumn);
final ColumnModel gridCM = new ColumnModel(gridColumnList);
final ListStore<BaseModel> gridData = new ListStore<BaseModel>();
gridData.add(baseModel);
final Grid<BaseModel> grid = new Grid<BaseModel>(gridData, gridCM);
vertPanel.add(grid);
RootPanel.get().add(vertPanel);
}