PDA

View Full Version : Stateful TreeGrid Bug



support_csd_kz
10 Feb 2011, 2:50 AM
GXT version: 2.2.1
GWT version: 2.2.1

Bug with Tree state Restore mechanism. After state restore a simple not Async tree, expand all nodes correctly, except for top node.

Test case:
-0- Run the code below.
-1- Expand all nodes.
-2- Press refresh button.

All nodes will be expanded except the top node.

EntryPoint:


public class Empty implements EntryPoint {
private final GreetingServiceAsync greetingService = GWT
.create(GreetingService.class);
private TreeStore<TreeModel> store;

public void onModuleLoad() {
store = new TreeStore<TreeModel>();

ColumnConfig name = new ColumnConfig("id", "id", 100);
name.setRenderer(new TreeGridCellRenderer<TreeModel>());

ColumnConfig date = new ColumnConfig("name", "Name", 100);

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

ContentPanel cp = new ContentPanel();
cp.setBodyBorder(false);
cp.setHeading("Async TreeGrid");
cp.setButtonAlign(HorizontalAlignment.CENTER);
cp.setLayout(new FitLayout());
cp.setFrame(true);
cp.setSize(600, 300);

TreeGrid<TreeModel> tree = new TreeGrid<TreeModel>(store, cm);
tree.setStateful(true);
tree.setId("statefullasynctreegrid1111");
store.setKeyProvider(new ModelKeyProvider<TreeModel>() {

public String getKey(TreeModel model) {
return model.get("id").toString();
}

});
tree.setBorders(true);
tree.getStyle().setLeafIcon(IconHelper.createStyle("icon-page"));
tree.setSize(400, 400);
tree.setTrackMouseOver(false);
cp.add(tree);

RootPanel.get().add(cp);

reload();

Button button = new Button();
button.setText("Refresh");
button.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
reload();
}
});
RootPanel.get().add(button);

}

public void reload() {
greetingService.getFolderChildren(new AsyncCallback<List<TreeModel>>() {

@Override
public void onFailure(Throwable caught) {

}

@Override
public void onSuccess(List<TreeModel> result) {
store.removeAll();
store.add(result, true);
}
});
}
}


GreetingServiceImpl:


public class GreetingServiceImpl extends RemoteServiceServlet implements
GreetingService {

public String greetServer(String input) throws IllegalArgumentException {

return "Hello, ";
}

@Override
public List<TreeModel> getFolderChildren() {
System.out.println("getFolderChildren");
List<TreeModel> l = new ArrayList<TreeModel>();
TreeModel tm = new BaseTreeModel();
tm.set("id", 0);
tm.set("name", "test" + 0);
l.add(tm);

TreeModel tm1 = new BaseTreeModel();
tm1.set("id", 1);
tm1.set("name", "test" + 1);
tm.add(tm1);
// l.add(tm);

TreeModel tm2 = new BaseTreeModel();
tm2.set("id", 2);
tm2.set("name", "test" + 2);
tm1.add(tm2);
// l.add(tm);

TreeModel tm3 = new BaseTreeModel();
tm3.set("id", 3);
tm3.set("name", "test" + 3);
tm2.add(tm3);
// l.add(tm);

return l;
}

}