Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » TreeViewer refresh() collapse problem-- SWT(TreeViewer tree getting collapsed on calling refresh() method)
TreeViewer refresh() collapse problem-- SWT [message #528054] Mon, 19 April 2010 06:49 Go to next message
Prasad  is currently offline Prasad Friend
Messages: 8
Registered: April 2010
Junior Member
Hi all,
I am calling refresh() method on SWT TreeViewer object..all the previously expanded items are getting collapsed..
I want to have the previous state of tree after i call refresh() method...

How to do this.. any suggestions please...

Thanks,
Prasad.
Re: TreeViewer refresh() collapse problem-- SWT [message #528066 is a reply to message #528054] Mon, 19 April 2010 07:57 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
You need to:
a) make your object implement equals/hashcode
b) implement an IElementComparer

Tom

Am 19.04.10 08:49, schrieb Prasad:
> Hi all,
> I am calling refresh() method on SWT TreeViewer object..all the
> previously expanded items are getting collapsed..
> I want to have the previous state of tree after i call refresh() method...
> How to do this.. any suggestions please...
>
> Thanks,
> Prasad.
Re: TreeViewer refresh() collapse problem-- SWT [message #528084 is a reply to message #528066] Mon, 19 April 2010 09:46 Go to previous messageGo to next message
Prasad  is currently offline Prasad Friend
Messages: 8
Registered: April 2010
Junior Member
Hi Tom,
I did not get you...

Can you please explain me in detail...


Thanks,
Prasad.
Re: TreeViewer refresh() collapse problem-- SWT [message #733541 is a reply to message #528084] Wed, 05 October 2011 01:28 Go to previous messageGo to next message
Phaedrus The Greek is currently offline Phaedrus The GreekFriend
Messages: 17
Registered: August 2011
Junior Member
The Treeviewer needs to be able to consider if your elements are equal to one another. You should implement hashcode() and equals() based on some field or method in your class that identifies it's uniqueness.

In Eclipse you can say : Source->Generate hashcode & equals. It will then ask you what fields you want to use to compare uniqueness, but I just replaced them with my toString() method.

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((toString() == null) ? 0 : toString().hashCode());
		return result;
	}



	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UConfiguration other = (UConfiguration) obj;
		if (toString() == null) {
			if (other.toString() != null)
				return false;
		} else if (!toString().equals(other.toString()))
			return false;
		return true;
	}
Re: TreeViewer refresh() collapse problem-- SWT [message #733578 is a reply to message #733541] Wed, 05 October 2011 06:12 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
it is much better to set an IElementComparer on to the viewer.

Tom
Am 05.10.11 03:28, schrieb Jay:
> The Treeviewer needs to be able to consider if your elements are equal
> to one another. You should implement hashcode() and equals() based on
> some field or method in your class that identifies it's uniqueness.
> In Eclipse you can say : Source->Generate hashcode & equals. It will
> then ask you what fields you want to use to compare uniqueness, but I
> just replaced them with my toString() method.
>
>
> @Override
> public int hashCode() {
> final int prime = 31;
> int result = 1;
> result = prime * result
> + ((toString() == null) ? 0 : toString().hashCode());
> return result;
> }
>
>
>
> @Override
> public boolean equals(Object obj) {
> if (this == obj)
> return true;
> if (obj == null)
> return false;
> if (getClass() != obj.getClass())
> return false;
> UConfiguration other = (UConfiguration) obj;
> if (toString() == null) {
> if (other.toString() != null)
> return false;
> } else if (!toString().equals(other.toString()))
> return false;
> return true;
> }
>
Re: TreeViewer refresh() collapse problem-- SWT [message #757743 is a reply to message #733578] Mon, 21 November 2011 13:01 Go to previous messageGo to next message
Dmitry Pryadkin is currently offline Dmitry PryadkinFriend
Messages: 146
Registered: July 2009
Senior Member
That won't help if you use DeferredTreeContentManager since it's responsible for collapsing the Tree. I have hit the same issue with it.
Re: TreeViewer refresh() collapse problem-- SWT [message #910714 is a reply to message #733541] Mon, 10 September 2012 09:08 Go to previous message
Ioanna L. is currently offline Ioanna L.Friend
Messages: 1
Registered: September 2012
Junior Member
Thank you very much! Your solution helped me to solve a problem I was struggling with for a long time!
Previous Topic:Table viewer & cell editor & input change listner
Next Topic:Set text color of Action
Goto Forum:
  


Current Time: Tue Apr 16 15:09:01 GMT 2024

Powered by FUDForum. Page generated in 1.00013 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top