PDA

View Full Version : Grid mouse over bug



eugenparaschiv
15 Oct 2008, 11:36 PM
I have come across a bug in Grid. Perhaps I should include this in the Bug section of the forum, but I just want to confirm there is a bug and not just something I'm doing wrong. Anyways, I'm using a grid and each time I move my mouse over it, it throws the following exception:

[ERROR] Uncaught exception escaped
java.lang.NullPointerException: null
at com.extjs.gxt.ui.client.widget.grid.GridView.handleHdMove(GridView.java:1537)
at com.extjs.gxt.ui.client.widget.grid.GridView.access$6(GridView.java:1535)
at com.extjs.gxt.ui.client.widget.grid.GridView$5.onBrowserEvent(GridView.java:1014)
at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1308)
at com.google.gwt.user.client.DOM.dispatchEventAndCatch(DOM.java:1287)
at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1255)
at sun.reflect.GeneratedMethodAccessor88.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.moz.MethodDispatch.invoke(MethodDispatch.java:80)
at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event(Native Method)
at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event(OS.java:5273)
at org.eclipse.swt.widgets.Display.eventProc(Display.java:1135)
at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:1428)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2840)
at com.google.gwt.dev.GWTShell.pumpEventLoop(GWTShell.java:720)
at com.google.gwt.dev.GWTShell.run(GWTShell.java:593)
at com.google.gwt.dev.GWTShell.main(GWTShell.java:357)

The grid itself is nothing special. I will provide specific code if needed, but perhaps someone has already come across this exception before.
Cheers.
Eugen

gslender
15 Oct 2008, 11:42 PM
Eugen,

I've not seen this bug in the cases of Grid that I use. I'm guessing by the stack trace that this is on linux? - which isn't a supported platform, so perhaps the bug is related to that?

If you still feel a bug exists, post some code and provide clear steps to demonstrate the problem and I will confirm on Windows XP. :D

Cheers,
Grant

eugenparaschiv
16 Oct 2008, 12:07 AM
I have found what causes the problem, and I think it is a bug. Here is the test case:


package uk.net.doctors.main.client.service.testing;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;


public class Test implements EntryPoint {
public void onModuleLoad(){
final Viewport view = new Viewport();
final ContentPanel panel = new ContentPanel( new FitLayout() );
panel.setSize( 1024, 768 );

panel.add( this.createGrid() );

view.add( panel );
RootPanel.get().add( view );
}

private final Grid<SimpleModel> createGrid(){
final Grid<SimpleModel> postsGrid;
final List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
//COLUMN(S)
ColumnConfig column = null;

column = new ColumnConfig( "rating", "<b>Rating</b>", 100 );
configs.add(column);

column = new ColumnConfig( "title", "<b>Title</b>", 400 );
configs.add(column);

//COLUMN MODEL
final ColumnModel cm = new ColumnModel( configs );

//STORE
final List<SimpleModel> modelList = this.getModel();
final ListStore<SimpleModel> store = new ListStore<SimpleModel>();
store.add( modelList );

//THE GRID
postsGrid = new Grid<SimpleModel>( store, cm );
postsGrid.setEnableColumnResize( false ); //this causes all the problems

postsGrid.getSelectionModel().setLocked( true );
postsGrid.setTrackMouseOver( false );

return postsGrid;
}

private final List<SimpleModel> getModel(){
final List<SimpleModel> testModel = new ArrayList<SimpleModel>();

SimpleModel modelItem = null;

modelItem = new SimpleModel( 5, "Hello Glad to inform you all about our SMS ALERT is bogus. " );
testModel.add(modelItem) ;

modelItem = new SimpleModel( 12, "Aside from the fact that you can take action now and improve! " );
testModel.add(modelItem) ;

testModel.add(modelItem) ;

return testModel;
}
}

final class SimpleModel extends BaseModel {
public SimpleModel( final int ratingToSet, final String titleToUse ){
this.set( "title", titleToUse);
this.set("rating", ratingToSet);
}

}


Now try clicking on the header of the column, so that the Grid is sorted by that column and you will get a lot of exceptions like the one I posted.
The problem is cause by the line:
postsGrid.setEnableColumnResize( false ); //this causes all the problems

I will keep debugging to see why. Any ideas why this happens?
Thanks.
Eugen.

eugenparaschiv
16 Oct 2008, 12:17 AM
Got it. The bug is in GridView: the field bar gets initialized only if the column resize is enabled: (line 1308)
if (grid.isEnableColumnResize()) {
bar = new GridSplitBar();
bar.render(grid.getElement());
}

but then is used in (line 1537):
private void handleHdMove(Event e) {
if (activeHd != null && !headerDisabled) {
bar.onMouseMove(e);
}
}

So if the bar doesn't get initialized, it evidently throws a NullPointerException here.
The fix will probably be handling the ONMOUSEMOVE event differently, perhaps checking if the bar is initialized first, or even if the columns are resizable, before calling the handleHdMove method