Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » CNF, tree refresh problem(Having problem while refreshing tree viewer in CNF)
CNF, tree refresh problem [message #891529] Mon, 25 June 2012 03:32 Go to next message
Girish Chandran is currently offline Girish Chandran
Messages: 24
Registered: June 2012
Junior Member
Hi all,

Iam having a project explorer view in my RCP application. Iam using CNF for the project explorer. Everything was working fine and i loved working with CNF. But,when i added context menu to the tree viewer for adding a new node, deleting a node etc..., the refresh action is not working fine. Iam having a listener, which notifies the viewer whenever a data change exist and the listener automatically triggers the refresh action of tree viewer. But when iam refreshing like treeviewer.refresh(), the refresh operation works fine but the tree gets collapsed to the root node of the tree. When iam calling treeviewer.refresh(node, true), the refresh operation does works.

Can anyone please help me out and provide a solution to the problem such that the refresh operation happens perfectly fine and the treeviewer should not collapse. It should in the same state as it was before.

Iam using eclipse 3.7 indigo.

Regards,
Girish
Re: CNF, tree refresh problem [message #891619 is a reply to message #891529] Mon, 25 June 2012 07:18 Go to previous messageGo to next message
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi Girish,

did you try to call getExpandedElements() to get the expanded elements before refresh and setExpandedElements(Object[] elements) after refresh?
Re: CNF, tree refresh problem [message #891643 is a reply to message #891619] Mon, 25 June 2012 08:00 Go to previous messageGo to next message
Girish Chandran is currently offline Girish Chandran
Messages: 24
Registered: June 2012
Junior Member
Hi Jan,

I tried calling calling setExpandedElements(object[] elements) after the refresh operation. But no effect on it.
I would like to show my code snippet of the content provider,

public Object[] getChildren(Object parentElement)
{
if (parentElement instanceof IProject)
{
resource.addDataChangeListener(this); // Notifies the viewer that a data change has been obtained. It is done by the
// emf notification.
return children(parentElement);
}
else
{
return children(parentElement);
}
}

// Listens to the data change
public void dataChanged(IChangedData object)
{
treeviewer.refresh(); or treeviewer.refresh(object,true);
}


I think, i have issues while calling the data change listener. Because after the treeviewer.refresh() operation, the control automatically goes to the getChildren() method and it returns the childrens under the project node.
But i would like to have a case such that, the tree should be refreshed and the tree needs to be expanded as it was earlier before the refresh operation.

I have already tried using setExpandedElements(Object[] elements), but was not able to get the desired result

Regards,
Girish

Re: CNF, tree refresh problem [message #891698 is a reply to message #891643] Mon, 25 June 2012 10:18 Go to previous messageGo to next message
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
And why you can't just call treeviewer.refresh(node, true)?
I suppose you can obtain the parent for the new added model elemet(s) from the IChangedData object.

Check this articlehttp://software-developer-struggles.blogspot.cz/2010/02/jface-treeviewer-collapses-after.html

[Updated on: Mon, 25 June 2012 10:21]

Report message to a moderator

Re: CNF, tree refresh problem [message #891700 is a reply to message #891698] Mon, 25 June 2012 10:21 Go to previous messageGo to next message
Girish Chandran is currently offline Girish Chandran
Messages: 24
Registered: June 2012
Junior Member
I did called treeviewer.refresh(node,true);
Iam very much able to obtain the parent node and i tried to refresh it. But the newly added node is not getting reflected in the tree viewer
Re: CNF, tree refresh problem [message #891702 is a reply to message #891700] Mon, 25 June 2012 10:23 Go to previous messageGo to next message
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Look at the article I posted to you in my previous post. Its hard to say when I can't debug your code.
Re: CNF, tree refresh problem [message #891800 is a reply to message #891702] Tue, 26 June 2012 01:02 Go to previous messageGo to next message
Girish Chandran is currently offline Girish Chandran
Messages: 24
Registered: June 2012
Junior Member
Hi Jan,

I tried and got it. I did collapsed my tree to one level of the data being changed and expanded the tree manually and then refreshed the node in a thread when the expansion reaches the changed node. Thanks Jan. Thanks for your support.

Iam having one more issues. I have an editor, which changes values according to the node being selected in the explorer. So when i change a value, the data change listener activates the tree refresh and i set the selection on the tree node as treeviewer.setselection(selection,true);

I works fine. But when it sets the selection , a flickering happens in the editor and we can be able to see the flickering effect. Is there any method by which this flickering can be stopped.

Regards,
Girish
Re: CNF, tree refresh problem [message #891839 is a reply to message #891800] Tue, 26 June 2012 05:01 Go to previous messageGo to next message
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Sorry but I don't understand you.

You have a CNF view containing a TreeViewer and you have an editor, right?. When the tree selection changes, the editor do something? What is flickering?
Re: CNF, tree refresh problem [message #891868 is a reply to message #891839] Tue, 26 June 2012 07:34 Go to previous message
Thorsten Schlathölter is currently offline Thorsten Schlathölter
Messages: 208
Registered: February 2012
Location: Düsseldorf
Senior Member
Hi Girish,
allthough you already have a solution, there is one thing that comes into my mind reading this. If get- and setExpandedElements does not work, the reason might be that your elements do not implement hashCode() and equals(). In that case the viewer might not be able to find the elements in the new model. Make sure that elements considered to be equal return the same hashCode and true upon a call to equals(otherObject).

Regards,
Thorsten
Previous Topic:[Databind] Decorate elements of a JFace viewer (table, tree, ...)
Next Topic:How to stop cell editing in ColumnViewer?
Goto Forum:
  


Current Time: Mon Jul 28 08:39:18 EDT 2014

Powered by FUDForum. Page generated in 0.02760 seconds