PDA

View Full Version : TreePanelSelectionModel.setSelection is causing problem



sunnyuser
25 Aug 2010, 4:41 AM
In my application, I'm showing TreePanel at LHS and whenever user saves any data through the RHS form then I need to add that value or ModelData in the LHS TreePanel. I achieved that functionality with the help of treeStore.insert but with this I also need to highlight the newly added value in the TreePanel.

Is there any way to highlight that value. I tried many things but not able to do that.

I tried to with following code in overriding update method of TreePanel but not able to achieve my motive. I write code like as :

treePanel = new TreePanel<ModelData>(store) {

@Override
protected void update() {
super.update();
if (addedUnit != null) {
TreeNode treeNode = (TreeNode) findNode(addedUnit);
treePanel.getView().onSelectChange(addedUnit, true);
List<ModelData> selectionModelList = new ArrayList<ModelData>(1);
selectionModelList.add(addedUnit);
treePanel.getSelectionModel().setSelection(selectionModelList);
addedUnit = null;
}
}

};
treePanel.setDisplayProperty("unitName");
treePanel.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);

So, please if you have any suggestion or solution to achieve this then tell me.

sven
25 Aug 2010, 7:39 AM
treePanel.getView().onSelectChange(addedUnit, true);

You should not call this by hand. When selecting that model, it should be called already.

Have you set a brakepoint to this line


treePanel.getSelectionModel().setSelection(selectionModelList);

And tried to step through the code to see why it is not working?

Can you try to post a fully working testcase that implements EntryPoint?

sunnyuser
26 Aug 2010, 3:58 AM
Thanks Sven for your response.

I tried to debug the problem. I found, NewAdded is not coming as selected only when rootNode is collapsed and when I first expanded rootNode and after that add new TreeNode then it's working properly i.e. it's coming as selected Node.

I checked with this code :

treePanel = new TreePanel<ModelData>(store) {

@Override
protected void update() {
super.update();
if (addedUnit != null) {
TreeNode treeNode = (TreeNode) findNode(addedUnit);
List<ModelData> selectionModelList = new ArrayList<ModelData>(1);
selectionModelList.add(addedUnit);
treePanel.getSelectionModel().setSelection(selectionModelList);
addedUnit = null;

}
}
};
treePanel.setDisplayProperty("name");
treePanel.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);

Please tell me what should I do to make this functionality oK?

sven
26 Aug 2010, 4:01 AM
Can you please post some fully working testcase of your code, so that everybody fully understand what you are doing? It is hard to figure out what you are doing exactly if you dont know your code.

sunnyuser
26 Aug 2010, 4:07 AM
As I told u guys earlier that In my application, I'm showing TreePanel at LHS and whenever user saves any data through the RHS form then I need to add that value or ModelData in the LHS TreePanel. I achieved that functionality with the help of treeStore.insert but with this I also need to highlight the newly added value in the TreePanel.

I tried to with following code in overriding update method of TreePanel but not able to achieve my motive. I write code like as :

treePanel = new TreePanel<ModelData>(store) {

@Override
protected void update() {
super.update();
if (addedUnit != null) {
TreeNode treeNode = (TreeNode) findNode(addedUnit);
List<ModelData> selectionModelList = new ArrayList<ModelData>(1);
selectionModelList.add(addedUnit);
treePanel.getSelectionModel().setSelection(selectionModelList);
addedUnit = null;

}
}
};
treePanel.setDisplayProperty("name");
treePanel.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);

But main problem Now I am facing is when My rootNode is collapsed then TreePanel is expanded but Newly Added TreeNode is coming as HIghlighted but when rootNode is already expanded then Newly Added TreeNode is coming as Highlighted.

So please tell me where I'm dng mistake.

sven
26 Aug 2010, 4:19 AM
I really cannot help you with this code snippet. I dont even understand why you override the update method.

You should really take some minutes and put together an example that simple shows what you are doing.