Community
Participate
Working Groups
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?
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
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.
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.
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.
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.
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
I'd say this is a dup of bug 9262.
Yes, I agree. *** This bug has been marked as a duplicate of 9262 ***
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.