Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 78359

Summary: [Viewers] infinite tree when returning inputElement in getElements of a TreeViewers ContentProvider
Product: [Eclipse Project] Platform Reporter: Christian Köstlin <christian.koestlin>
Component: UIAssignee: Boris Bokowski <bokowski>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P4 CC: eclipse-bug, markus.kell.r
Version: 3.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
example project that demonstrates the described behavior none

Description Christian Köstlin CLA 2004-11-10 18:40:01 EST
sometimes i want to populate a TreeViewer with objects that have all the needed
tree information. so i want to write a simply delegating treecontentprovider.
see attached plugin-project.
whats happening is that in AbstractTreeViewer.getRawChildren a check is made
that leads to the evaluation of StructuredTreeViewer.getRawChildren (if the root
and the parent are the same object (same by equals)) and this implementation
always calls getElements of the content provider ...
this leads to an infinite loop calling getElements ... 

is this a desired behavior and why is this desired?
Comment 1 Christian Köstlin CLA 2004-11-10 18:43:06 EST
Created attachment 15788 [details]
example project that demonstrates the described behavior

Steps to reproduce:
- unzip the project
- import the project into eclipse
- start a runtime workbench with this plugin enabled (in debug mode)
- open the view strangeview
- open the root node
you see that the only child of the root node is again the root node.

- close the view
- edit getElements so that the commented out code is used
- reopen the view in the runtime-workbench
- thats teh desired behavior
Comment 2 Tod Creasey CLA 2004-11-18 08:27:56 EST
We have to do a getElements so that we know what the raw children are. Tree 
viewers are designed so that all nodes are unique - you cannot have two 
different nodes representing the same object in the viewer.
Comment 3 Christian Köstlin CLA 2004-12-16 09:11:26 EST
i dont understand your answer.
the call to getelements is ok for me, and all my nodes are unique.
the problem i have is the following:
we pass a business object to the setinputmethod of the treeviewer,
the treeviewer calls getElements on the contentprovider which in our case
returns an array with exactly this business object. we want to have this
business object as the single root of the treeviewer. this seems not to be
possible, just have a look at our attached example.
Comment 4 Tod Creasey CLA 2004-12-16 09:22:24 EST
I see your issue. You are making the root and elements the same thing which is 
causing you this problem.

getRoot() returns getInput().
getElements(Object parent) passes in the root as the parent. 

Is the issue that you want a single root element as the top of the tree? If so 
then make a different object your root and have getElements() return a one 
element array of your top node.
Comment 5 Christian Köstlin CLA 2004-12-16 09:52:27 EST
i still dont get your point.
i want my business object to be the root of the tree.
so i set it as input to the treeviewer.
my contentprovider.getelements returns exactly this object wrapped into a new
array of size 1.
i know that i can make a workaround and wrap the business object, but i dont
understand why i have to.
Comment 6 Tod Creasey CLA 2004-12-16 10:42:23 EST
Do you want it to be the top visible element? The root is not visible - it is 
the element that generates the top visible elements in tree.

What I am saying is that if you want tree to look like

MyBusinessElement
   MySubElement1
   MySubElement2

MyBusinessElement cannot be the root. You need a model that looks like

MyInputElement
   MyBusinessElement
      MySubElement1
      MySubElement2

because you element is showing up twice - i.e. once as the root and once in an 
element. Your structure ends up looking to the viewer like

MyBusinessElement
    MyBusinessElement
       MyBusinessElement
          MyBusinessElement

Comment 7 Markus Keller CLA 2005-07-25 01:37:53 EDT
I'd say this is a dup of bug 9262.
Comment 8 Boris Bokowski CLA 2005-11-08 17:22:10 EST
Yes, I agree.

*** This bug has been marked as a duplicate of 9262 ***
Comment 9 Boris Bokowski CLA 2005-11-08 17:28:38 EST
Christian,

a simple workaround would be to do the following:

viewer.setInput(new TreeObject(new Object[] {root}));

and implement your content provider's getElements() method by downcasting the
input element to TreeObject and returning its children.

That way, you would not be restricted to trees with a single root element.