Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Problems with TreeItem.getItems()
Problems with TreeItem.getItems() [message #280079] Fri, 28 January 2005 14:02
Eclipse UserFriend
Originally posted by: devin_steffler.ca.ibm.com

I'm having problems with TreeItem.getItems() and was told that I should seek
help on this newsgroup. Please point me in the appropriate direction if
this is not the case.

Example problem:
-------------------------------------------------
TreeViewer with a Tree that has the following structure:
TreeItem[0] {IASTTranslationUnit} // there are supposed to be more TreeItems
underneath this TreeItem that I want to access via TreeItem[0].getItems()
TreeItem[1] {} // object with ID 1234 (arbitrary ID)

When I invoke TreeItem[0].getItems() I get a TreeItem array that contains
one element. That element is the TreeItem[1] {} with object ID 1234 above
(which doesn't make sense to me).

When the view is displayed in Eclipse there are several items that appear as
children to TreeItem[0] however I can't seem to access those TreeItems
programatically from the Tree.
-------------------------------------------------

Here's the problematic code:
-------------------------------------------------
public void run() {
// take a snapshot of the current tree expansion
Object[] expandedElements = viewer.getExpandedElements();

// set the new content provider
viewer.setContentProvider(new ViewContentProvider(file));

viewer.refresh(); // suggested to help fix the problem, didn't work

// set the expansion of the new view based on the original snapshot
Tree tree = viewer.getTree();
if (expandedElements.length > 0) {
expandTreeIfNecessary(tree.getItems(), expandedElements);
}

viewer.refresh();

}


private void expandTreeIfNecessary(TreeItem[] treeItems, Object[]
expandedElements) {
for (int i=0; i<treeItems.length; i++) {
for (int j=0; j<expandedElements.length; j++) {

// if the items are a "close enough" match then expand the new TreeItem
if (treeItems[i].getData() instanceof TreeObject &&
expandedElements[j] instanceof TreeObject &&

((TreeObject)treeItems[i].getData()).getFilename().equals((( TreeObject)expan
dedElements[j]).getFilename()) &&

((TreeObject)treeItems[i].getData()).toString().equals(((Tre eObject)expanded
Elements[j]).toString())) {
treeItems[i].setExpanded(true);

// determine if children need to be expanded or not
expandTreeIfNecessary(treeItems[i].getItems(), expandedElements);
// the treeItems[i].getItems() seems problematic as it returns a TreeItem[1]
with a null data object
}
}
}
}
-------------------------------------------------

Thanks for your help,
Devin Steffler
IBM's Eclipse CDT
Ottawa (Palladium), Ontario, Canada
Previous Topic:How to Browse Remote Folder?
Next Topic:Retarget actions more documentation
Goto Forum:
  


Current Time: Tue Apr 23 17:48:28 GMT 2024

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

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

Back to the top