PDA

View Full Version : [FNR] Grid.setEnabled(false)



DarekKay
28 Nov 2011, 8:41 AM
Just found a bug while trying to disable a grid. Here a simple example:


private static final StockProperties props = GWT.create(StockProperties.class);

public void onModuleLoad()
{
ColumnConfig<Stock, String> nameCol =
new ColumnConfig<Stock, String>(props.name(), 200, "Name");

ListStore<Stock> store = new ListStore<Stock>(props.key());
store.add(new Stock("myKey", "myName"));

ContentPanel cp = new ContentPanel();
cp.setPixelSize(600, 300);

List<ColumnConfig<Stock, ?>> l = new ArrayList<ColumnConfig<Stock, ?>>();
l.add(nameCol);
ColumnModel<Stock> cm = new ColumnModel<Stock>(l);

final Grid<Stock> grid = new Grid<Stock>(store, cm);
grid.getView().setAutoExpandColumn(nameCol);
grid.setBorders(false);
grid.setStripeRows(true);
grid.setColumnLines(true);

VerticalLayoutContainer con = new VerticalLayoutContainer();
cp.setWidget(con);

con.add(grid, new VerticalLayoutData(1, 1));

grid.setEnabled(false); // NULLPOINTEREXCEPTION
RootLayoutPanel.get().add(cp);
}

interface StockProperties extends PropertyAccess<Stock>
{
ModelKeyProvider<Stock> key();
ValueProvider<Stock, String> name();
}

class Stock
{
public Stock(String key, String name)
{
this.key = key;
this.name = name;
}

String key = "";
String name = "";

public String getKey()
{
return key;
}

public void setKey(String key)
{
this.key = key;
}

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}
}

And the error message (my package = nope.client):


java.lang.NullPointerException: null
at com.google.gwt.user.client.ui.UIObject.setStyleName(UIObject.java:296)
at com.google.gwt.user.client.ui.UIObject.setStyleName(UIObject.java:688)
at com.google.gwt.user.client.ui.UIObject.addStyleName(UIObject.java:469)
at com.sencha.gxt.widget.core.client.Component.onDisable(Component.java:1298)
at com.sencha.gxt.widget.core.client.grid.Grid.onDisable(Grid.java:842)
at com.sencha.gxt.widget.core.client.Component.disable(Component.java:259)
at com.sencha.gxt.widget.core.client.Component.setEnabled(Component.java:699)
at nope.client.GXT_3_0.onModuleLoad(GXT_3_0.java:54)

sven
28 Nov 2011, 8:48 AM
Fixed in SVN

DarekKay
20 Dec 2011, 6:17 AM
The exception is gone, but the grid doesn't (always) get disabled. In my main application, the default "gray disabled" style is applied only sometimes. I couldn't find the exact test case when it works, so here a code where it doesn't work. It seems, like the "enabled" variable gets updated (since grid.isEnabled() returns false), but the style doesn't get changed and I can still select and change everything (cell and header):


public void onModuleLoad()
{
ColumnConfig<Stock, String> nameCol = new ColumnConfig<Stock, String>(props.name(), 200, "Name");

ListStore<Stock> store = new ListStore<Stock>(props.key());
store.add(new Stock("myKey", "myName", 1));

ContentPanel cp = new ContentPanel();
cp.setPixelSize(600, 300);

List<ColumnConfig<Stock, ?>> l = new ArrayList<ColumnConfig<Stock, ?>>();
l.add(nameCol);
ColumnModel<Stock> cm = new ColumnModel<Stock>(l);

final Grid<Stock> grid = new Grid<Stock>(store, cm);
grid.getView().setAutoExpandColumn(nameCol);
grid.setBorders(false);
grid.setStripeRows(true);
grid.setColumnLines(true);

GridInlineEditing<Stock> editing = new GridInlineEditing<Stock>(grid);
editing.addEditor(nameCol, new TextField());

VerticalLayoutContainer con = new VerticalLayoutContainer();
cp.setWidget(con);

TextButton button = new TextButton("disable");
button.addSelectHandler(new SelectHandler()
{

@Override
public void onSelect(SelectEvent event)
{
grid.setEnabled(false); // does nothing!
System.out.println(grid.isEnabled()); // = "false"
}
});

con.add(grid, new VerticalLayoutData(1, 0.9));
con.add(button, new VerticalLayoutData(1, 0.1));

grid.setEnabled(false); // does nothing!
System.out.println(grid.isEnabled()); // = "false"
RootLayoutPanel.get().add(cp);
}

(utility classes are the same as in my first post)