| Summary: | [Viewers] infinite tree when returning inputElement in getElements of a TreeViewers ContentProvider | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Christian Köstlin <christian.koestlin> | ||||
| Component: | UI | Assignee: | 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
Christian Köstlin
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
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.
|