PDA

View Full Version : [FIXED] [2.0] CheckBoxSelectionModel select method does not work



micgala
13 Jul 2009, 2:03 AM
Hi.

For GXT 2.0 final, calling manually the select() method does not check the required row.

I have created a testcase for this issue. The first row should be presented selected, but it is not:



public void onModuleLoad() {

Window window = new Window();
window.setLayout(new FitLayout());
window.setSize(400, 300);

ListStore<BaseModel> store = new ListStore<BaseModel>();
BaseModel model1 = new BaseModel();
model1.set("name", "Name1");
store.add(model1);
BaseModel model2 = new BaseModel();
model2.set("name", "Name2");
store.add(model2);

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

ColumnConfig name = new ColumnConfig("name", "Name", 200);

ColumnModel cm = new ColumnModel(Arrays.asList(sm.getColumn(), name));

final Grid<BaseModel> grid = new Grid<BaseModel>(store, cm);
grid.setSelectionModel(sm);
grid.addPlugin(sm);

window.addListener(Events.Show, new Listener<ComponentEvent>() {
public void handleEvent(ComponentEvent be) {
grid.getSelectionModel().select(0, true);
}
});

window.add(grid);
window.show();
}
Thanks for verifying.

Regards,
Michel.

micgala
17 Jul 2009, 5:53 AM
hmm, some more information about this.

I have also tried the Render events, instead of the Show, and the same problem is still there: no selection is made.

But then, if you add a button, and that button selects the first item, then it almost work:

The first time you click, it selects the entry, but also selects the "all" check.
If you click again, then it keeps the entry selected, but the "all" check, is unchecked (which should be the desired behavior since the beginning).

Problems is that I want to display the window with the entry selected already... and this is still not working.

Follows the slightly modified version, for checking the info provided by me:



public void onModuleLoad() {

Window window = new Window();
window.setLayout(new FitLayout());
window.setSize(400, 300);

ListStore<BaseModel> store = new ListStore<BaseModel>();
BaseModel model1 = new BaseModel();
model1.set("name", "Name1");
store.add(model1);
BaseModel model2 = new BaseModel();
model2.set("name", "Name2");
store.add(model2);

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

ColumnConfig name = new ColumnConfig("name", "Name", 200);

ColumnModel cm = new ColumnModel(Arrays.asList(sm.getColumn(), name));

final Grid<BaseModel> grid = new Grid<BaseModel>(store, cm);
grid.setSelectionModel(sm);
grid.addPlugin(sm);

//window.addListener(eventType, listener)

window.addListener(Events.Render, new Listener<ComponentEvent>() {
public void handleEvent(ComponentEvent be) {
grid.getSelectionModel().select(0, true);
}
});

window.addButton(new Button("test", new SelectionListener<ButtonEvent>() {

@Override
public void componentSelected(ButtonEvent ce) {
grid.getSelectionModel().select(0, true);
}

}));

window.add(grid);
window.show();
}

sven
17 Jul 2009, 5:58 AM
We added a ViewReady event to grid. You need to listen to that event and than select the item. The change is already in SVN. Marking this thread as FNR.

micgala
17 Jul 2009, 6:04 AM
Tks for the info sven!

I hope you've added some info about this in the javadocs as well, so we can learn that this new Event should be listened to.

Regards,
Michel.

sven
17 Jul 2009, 6:05 AM
Yes we added the new ViewReady event to the javadocs.