PDA

View Full Version : NullPointerException when adding cell renderer to EditorTreeGrid



shroom
9 Sep 2009, 5:50 AM
I get a NullPointerException when I try to add any kind of TreeGridCellRenderer to EditorTreeGrid. My EditorTreeGrid is initially empty and when I drag & drop items to it I want a "remove" button to appear in last column.


TreeGridCellRenderer<UserProjectDTO> buttonRenderer = new TreeGridCellRenderer<UserProjectDTO>() {

public Object render(UserProjectDTO model, String property, com.extjs.gxt.ui.client.widget.grid.ColumnData config, int rowIndex, int colIndex, ListStore<UserProjectDTO> store, Grid<UserProjectDTO> grid) {
IconButton buttonRemove = new IconButton("icon-delete");
buttonRemove.addSelectionListener(new SelectionListener<IconButtonEvent>() {
@Override
public void componentSelected(IconButtonEvent ce) {
System.out.println("button clicked");
}
});

LayoutContainer buttonContainer = new LayoutContainer();
buttonContainer.setSize(20, 14);
buttonContainer.add(buttonRemove);
buttonContainer.layout();
return buttonContainer;
}

};

ColumnConfig button = new ColumnConfig("x", "", 20);
name.setRenderer(new TreeGridCellRenderer<ModelData>());
position.setEditor(new CellEditor(comboPosition));
button.setRenderer(buttonRenderer);
ColumnModel cm = new ColumnModel(Arrays.asList(name, position, button));

tree = new EditorTreeGrid<ModelData>(treeStore, cm) {
@Override
protected boolean hasChildren(ModelData model) {
return true;
}
};
tree.setBorders(false);
tree.setSize(400, 400);
tree.setAutoExpandColumn("displayName");
tree.setTrackMouseOver(false);
tree.getView().setShowDirtyCells(false);
tree.setClicksToEdit(EditorGrid.ClicksToEdit.TWO);

LayoutContainer in renderer in unnecessary. I just wanted to be sure whether anything will be rendered into that column so I've tried multiple widgets and none seems to work. You can find full stack trace below:


java.lang.NullPointerException
at com.extjs.gxt.ui.client.widget.treegrid.TreeGridView.getWidgetCell(TreeGridView.java:308)
at com.extjs.gxt.ui.client.widget.treegrid.TreeGridView.getWidgetCell(TreeGridView.java:1)
at com.extjs.gxt.ui.client.widget.grid.GridView.renderWidgets(GridView.java:1600)
at com.extjs.gxt.ui.client.widget.grid.GridView.onAdd(GridView.java:1294)
at com.extjs.gxt.ui.client.widget.grid.GridView$5.storeAdd(GridView.java:1179)
at com.extjs.gxt.ui.client.store.StoreListener.handleEvent(StoreListener.java:22)
at com.extjs.gxt.ui.client.store.StoreListener.handleEvent(StoreListener.java:1)
at com.extjs.gxt.ui.client.event.BaseObservable.callListener(BaseObservable.java:176)
at com.extjs.gxt.ui.client.event.BaseObservable.fireEvent(BaseObservable.java:96)
at com.extjs.gxt.ui.client.store.ListStore.insert(ListStore.java:467)
at com.extjs.gxt.ui.client.store.ListStore.insert(ListStore.java:266)
at com.extjs.gxt.ui.client.widget.treegrid.TreeGridView.expand(TreeGridView.java:72)
at com.extjs.gxt.ui.client.widget.treegrid.TreeGrid.setExpanded(TreeGrid.java:301)
at com.extjs.gxt.ui.client.widget.treegrid.TreeGrid.setExpanded(TreeGrid.java:267)
at com.extjs.gxt.ui.client.widget.treegrid.TreeGrid$TreeNode.setExpanded(TreeGrid.java:105)
at com.extjs.gxt.ui.client.dnd.TreeGridDropTarget$1.run(TreeGridDropTarget.java:182)
at com.google.gwt.user.client.Timer.fireImpl(Timer.java:160)
at com.google.gwt.user.client.Timer.fireAndCatch(Timer.java:146)
at com.google.gwt.user.client.Timer.fire(Timer.java:138)
at sun.reflect.GeneratedMethodAccessor113.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.mac.MethodDispatch.invoke(MethodDispatch.java:71)
at org.eclipse.swt.internal.carbon.OS.ReceiveNextEvent(Native Method)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2909)
at com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:235)
at com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:558)
at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)

And this is the line that throws the exception:

cell = El.fly(cell).selectNode(".x-tree3-node-text").dom;

Thanks for your help.

sven
9 Sep 2009, 5:53 AM
Moving this to the help forum. The renderer you use it not for widgets.

shroom
9 Sep 2009, 5:55 AM
The renderer you use it not for widgets.

Thanks, but what kind of renderer should I use if I want to display an IconButton in EditorTreeGrid?

shroom
9 Sep 2009, 1:09 PM
My bad, when I looked into source code of TreeGridCellRenderer I realized that I should have used GridCellRenderer instead. Now everything works fine.