PDA

View Full Version : TreeGrid RpcProxy - delete last leaf problem



kosmo20
6 Nov 2009, 6:45 AM
Hi
I have a problem with refreshing parent node type, when I delete its last leaf - parent node type should be changed to leaf, but I still see node expand icon. I red this topic http://www.extjs.com/forum/showthread.php?t=72262. But I don't know how to fire TreeLoader event that checks if parent node still has a children

TreeLoader<LifeEventModel> loader = new BaseTreeLoader<LifeEventModel>(proxy){

@Override
public boolean hasChildren(LifeEventModel parent) {
return parent.isHasChildren();
}

};hasChildren method is fired only once when tree is building. I thought that changing
parent.setHasChildren(false) helps but I was wrong :(. Can anybody help me and write what should I do to update parent node. I Tried store.update(parent), store.getLoader().loadChildren() etc. All code looks like:

ContentPanel treePanel = new BaseContentPanel("Klasyfikacje Life Event");
treePanel.setLayout(new FitLayout());
treePanel.setFrame(true);
//treePanel.setSize(Constants.MAIN_PANEL_WIDTH - 5, Constants.TREE_PANEL_HEIGHT);

RpcProxy<List<LifeEventModel>> proxy = new RpcProxy<List<LifeEventModel>>() {
@Override
protected void load(Object loadConfig, AsyncCallback<List<LifeEventModel>> callback) {
service.getLifeEventChildren((LifeEventModel) loadConfig, callback);
}
};

TreeLoader<LifeEventModel> loader = new BaseTreeLoader<LifeEventModel>(proxy){

@Override
public boolean hasChildren(LifeEventModel parent) {
return parent.isHasChildren();
}

};

store = new TreeStore<LifeEventModel>(loader);

loader.load(null);

ColumnConfig name = new ColumnConfig(Constants.NAZWA, "Nazwa LE", 450);
name.setRenderer(new TreeGridCellRenderer<ModelData>());
ColumnConfig dotyczy = new ColumnConfig(Constants.DOTYCZY, "Dotyczy", 150);
ColumnConfig status = new ColumnConfig(Constants.STATUS_PELNA_NAZWA, "Status", 80);

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

tree = new TreeGrid<ModelData>(store, cm);
tree.setBorders(true);
tree.setHeight(Constants.TREE_PANEL_HEIGHT);
tree.setAutoExpandColumn("statusPelnaNazwa");
tree.setTrackMouseOver(false);
tree.setLoadMask(true);
treePanel.add(tree);

tree.getSelectionModel().addListener(Events.SelectionChange, new Listener<SelectionChangedEvent<ModelData>>(){

public void handleEvent(SelectionChangedEvent<ModelData> be) {
boolean enabled = false;
if(be.getSelection().size() == 1 ){
LifeEventModel lem = (LifeEventModel) be.getSelectedItem();
enabled = lem.getIdentyfikator() != 0;
}
addLEButton.setEnabled(enabled);
modifyLEButton.setEnabled(enabled);
deleteLEButton.setEnabled(enabled);
}

});

harun
2 Sep 2010, 12:57 AM
Hi kosmo20,

I had a same problem with you,but I solved it now, like this



if ( store.getChildCount( parent ) == 0 ) {
parent.setHaschild( false );
tree.setLeaf( parent, true );
}

sven
2 Sep 2010, 1:47 AM
You will need to override the TreePanel hasChildren method for this. Because once loaded, the loader haschildren method is not asked anymore.

harun
2 Sep 2010, 2:03 AM
You will need to override the TreePanel hasChildren method for this. Because once loaded, the loader haschildren method is not asked anymore.

Thank you very much Sven,

your solution is better than mine, I implemented it



tree = new TreePanel<GroupData>( store ) {
@Override
protected boolean hasChildren( GroupData model)
{

return model.isHaschild();

};
};