PDA

View Full Version : [FIXED] [2.0m2] Grid cell render with button (BeanModel)



Webflash
29 May 2009, 4:14 AM
publicclass BugGxt implements EntryPoint {

publicvoid onModuleLoad() {

ListStore<BeanModel> store = new ListStore<BeanModel>();

store.setMonitorChanges(true);

List<ColumnConfig> columns = new ArrayList<ColumnConfig>();

CheckBoxSelectionModel<BeanModel> sm = new CheckBoxSelectionModel<BeanModel>();

columns.add(sm.getColumn());

columns.add(new ColumnConfig("name", "name", 150));

{

ColumnConfig column = new ColumnConfig("published", "published", 90);

column.setAlignment(HorizontalAlignment.CENTER);

column.setRenderer(new GridCellRenderer<BeanModel>() {

@Override

public Object render(BeanModel model, String property, ColumnData config, int rowIndex, int colIndex,

ListStore<BeanModel> store, Grid<BeanModel> grid) {

Product product = model.getBean();

if (product.isPublished()) {

return"published";

} else {

return"not published";

}

}

});

columns.add(column);

}

{

ColumnConfig column = new ColumnConfig();

column.setDataIndex("");

column.setRenderer(new GridCellRenderer<BeanModel>() {

@Override

public Object render(BeanModel model, String property, ColumnData config, int rowIndex,

int colIndex, ListStore<BeanModel> store, Grid<BeanModel> grid) {

Button editButton = new Button(null, "icon-edit", new SelectionListener<ButtonEvent>() {

@Override

publicvoid componentSelected(ButtonEvent ce) {

}

});

return editButton;

}

});

columns.add(column);

}

Grid<BeanModel> productGrid = new Grid<BeanModel>(store, new ColumnModel(columns));

productGrid.setLoadMask(true);

productGrid.setAutoExpandColumn("name");

productGrid.setSelectionModel(sm);

productGrid.addPlugin(sm);

store.add(BeanModelLookup.get().getFactory(Product.class).createModel(generateProductList()));

Viewport viewPort = new Viewport();
viewPort.setLayout(new FitLayout());
viewPort.add(productGrid);
RootPanel.get().add(viewPort);

}

protected List<Product> generateProductList() {
List<Product> result = new ArrayList<Product>();
for (int i = 0; i < 5; i++) {
Product p = new Product();
p.setName("product " + i);
p.setId(i);
result.add(p);
}
return result;
}

}


publicclass Product implements BeanModelTag {

privateintid;
private String name;

privatebooleanpublished;

publicboolean isPublished() {

returnpublished;

}

publicvoid setPublished(boolean published) {

this.published = published;

}

publicvoid setName(String name) {

this.name = name;

}

public String getName() {

returnname;

}

publicint getId() {
returnid;
}

publicvoid setId(int id) {
this.id = id;
}

@Override

publicboolean equals(Object obj) {
if (obj != null && obj instanceof Product) {
returnid == ((Product) obj).getId();
}
returnfalse;
}

@Override

publicint hashCode() {
returnid;
}

}

throw Exeption

at com.extjs.gxt.ui.client.store.Store.update(Store.java:513)
at com.extjs.gxt.ui.client.store.Store.onModelChange(Store.java:575)
at com.extjs.gxt.ui.client.store.Store$1.modelChanged(Store.java:481)
at com.extjs.gxt.ui.client.data.ChangeEventSupport.notify(ChangeEventSupport.java:33)
at com.extjs.gxt.ui.client.data.BaseModel.notify(BaseModel.java:103)
at com.extjs.gxt.ui.client.data.BaseModel.notifyPropertyChanged(BaseModel.java:152)
at com.extjs.gxt.ui.client.data.BaseModel.set(BaseModel.java:133)
at buggxt.client.BeanModel_buggxt_client_Product.set(transient source for buggxt.client.BeanModel_buggxt_client_Product:59)
at com.extjs.gxt.ui.client.widget.grid.GridView.getRenderedValue(GridView.java:997)
at com.extjs.gxt.ui.client.widget.grid.GridView.doRender(GridView.java:743)
at com.extjs.gxt.ui.client.widget.grid.GridView.renderRows(GridView.java:1507)
at com.extjs.gxt.ui.client.widget.grid.GridView.insertRows(GridView.java:1244)
at com.extjs.gxt.ui.client.widget.grid.GridView.refreshRow(GridView.java:1432)
at com.extjs.gxt.ui.client.widget.grid.GridView.onUpdate(GridView.java:1398)
at com.extjs.gxt.ui.client.widget.grid.GridView$5.storeUpdate(GridView.java:1172)
at com.extjs.gxt.ui.client.store.StoreListener.handleEvent(StoreListener.java:36)
at com.extjs.gxt.ui.client.store.StoreListener.handleEvent(StoreListener.java:1)
at com.extjs.gxt.ui.client.event.BaseObservable.callListener(BaseObservable.java:181)
at com.extjs.gxt.ui.client.event.BaseObservable.fireEvent(BaseObservable.java:98)
..... and repeat

sven
29 May 2009, 4:49 AM
This is already fixed in SVN