Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Problems with TreeItem.getItems()
Problems with TreeItem.getItems() [message #449667] Thu, 27 January 2005 17:18 Go to next message
Devin Steffler is currently offline Devin StefflerFriend
Messages: 7
Registered: July 2009
Junior Member
I created a new view that uses a TreeViewer. I want to traverse through the
TreeItems in the Tree and programmatically setExpanded(true) for certain
TreeItems.

The Tree contains the items:
[0]= TreeItem {IASTTranslationUnit} // this should contain several more
TreeItems underneath it but I can't figure out how to get to them and
getItems() doesn't seem to work
[1]= TreeItem {}

The first TreeItem[0]#setExpanded(true) works fine, but then I want to
setExpanded(true) for some of the TreeItems underneath it. So I do the
following:
TreeItem[0].getItems() to get the TreeItems under that specific TreeItem
(assuming this is what is supposed to happen based on the spec). Here's
what the spec says:
--------------------------------------------------
TreeItem#getItems()
Returns an array of TreeItems which are the direct item children
of the receiver.
--------------------------------------------------

When I call this, getItems() returns an array of TreeItems that only has one
element (the TreeItem[1] above displayed as TreeItem{}).

Is the TreeItem.getItems() supposed to return the TreeItems that are
children to the TreeItem? Is this a bug? Are there alternatives that I
could use? I started looking at using the TableTreeViewer but saw that it
will be deprecated for Eclipse 3.1M5. Any suggestions?

Thanks,
Devin Steffler
IBM's Eclipse CDT
Ottawa (Palladium), Ontario, Canada
Re: Problems with TreeItem.getItems() [message #449670 is a reply to message #449667] Thu, 27 January 2005 17:54 Go to previous messageGo to next message
Devin Steffler is currently offline Devin StefflerFriend
Messages: 7
Registered: July 2009
Junior Member
This might be of some help (or part of the problem):

My view has a "refresh" button. When it is clicked, I create a new
ViewContentProvider (identical to the previous content provider, just a new
object) and update the viewer's content provider with it.

Then I want to traverse the TreeItems and set the expanded state based on
information from the previous expanded elements (retrieved via
viewer.getExpandedElements()).

Does setting the content provider to a new ViewContentProvider create any
problems with the TreeViewer, Tree, or the Tree's TreeItems?

Thanks,
Devin Steffler
IBM's Eclipse CDT
Ottawa (Palladium), Ontario, Canada

"Devin Steffler" <devin_steffler@ca.ibm.com> wrote in message
news:ctb7pd$31p$1@www.eclipse.org...
> I created a new view that uses a TreeViewer. I want to traverse through
the
> TreeItems in the Tree and programmatically setExpanded(true) for certain
> TreeItems.
>
> The Tree contains the items:
> [0]= TreeItem {IASTTranslationUnit} // this should contain several more
> TreeItems underneath it but I can't figure out how to get to them and
> getItems() doesn't seem to work
> [1]= TreeItem {}
>
> The first TreeItem[0]#setExpanded(true) works fine, but then I want to
> setExpanded(true) for some of the TreeItems underneath it. So I do the
> following:
> TreeItem[0].getItems() to get the TreeItems under that specific TreeItem
> (assuming this is what is supposed to happen based on the spec). Here's
> what the spec says:
> --------------------------------------------------
> TreeItem#getItems()
> Returns an array of TreeItems which are the direct item children
> of the receiver.
> --------------------------------------------------
>
> When I call this, getItems() returns an array of TreeItems that only has
one
> element (the TreeItem[1] above displayed as TreeItem{}).
>
> Is the TreeItem.getItems() supposed to return the TreeItems that are
> children to the TreeItem? Is this a bug? Are there alternatives that I
> could use? I started looking at using the TableTreeViewer but saw that it
> will be deprecated for Eclipse 3.1M5. Any suggestions?
>
> Thanks,
> Devin Steffler
> IBM's Eclipse CDT
> Ottawa (Palladium), Ontario, Canada
>
>
Re: Problems with TreeItem.getItems() [message #449680 is a reply to message #449670] Thu, 27 January 2005 21:06 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Your best source for answers about JFace is the eclipse.platform newsgroup:

news://news.eclipse.org/eclipse.platform

That being said, I think you might need to call the refresh method on the
TreeViewer after you have changed the content provider.


"Devin Steffler" <devin_steffler@ca.ibm.com> wrote in message
news:ctb9tj$hmn$1@www.eclipse.org...
> This might be of some help (or part of the problem):
>
> My view has a "refresh" button. When it is clicked, I create a new
> ViewContentProvider (identical to the previous content provider, just a
> new
> object) and update the viewer's content provider with it.
>
> Then I want to traverse the TreeItems and set the expanded state based on
> information from the previous expanded elements (retrieved via
> viewer.getExpandedElements()).
>
> Does setting the content provider to a new ViewContentProvider create any
> problems with the TreeViewer, Tree, or the Tree's TreeItems?
>
> Thanks,
> Devin Steffler
> IBM's Eclipse CDT
> Ottawa (Palladium), Ontario, Canada
>
> "Devin Steffler" <devin_steffler@ca.ibm.com> wrote in message
> news:ctb7pd$31p$1@www.eclipse.org...
>> I created a new view that uses a TreeViewer. I want to traverse through
> the
>> TreeItems in the Tree and programmatically setExpanded(true) for certain
>> TreeItems.
>>
>> The Tree contains the items:
>> [0]= TreeItem {IASTTranslationUnit} // this should contain several more
>> TreeItems underneath it but I can't figure out how to get to them and
>> getItems() doesn't seem to work
>> [1]= TreeItem {}
>>
>> The first TreeItem[0]#setExpanded(true) works fine, but then I want to
>> setExpanded(true) for some of the TreeItems underneath it. So I do the
>> following:
>> TreeItem[0].getItems() to get the TreeItems under that specific TreeItem
>> (assuming this is what is supposed to happen based on the spec). Here's
>> what the spec says:
>> --------------------------------------------------
>> TreeItem#getItems()
>> Returns an array of TreeItems which are the direct item
>> children
>> of the receiver.
>> --------------------------------------------------
>>
>> When I call this, getItems() returns an array of TreeItems that only has
> one
>> element (the TreeItem[1] above displayed as TreeItem{}).
>>
>> Is the TreeItem.getItems() supposed to return the TreeItems that are
>> children to the TreeItem? Is this a bug? Are there alternatives that I
>> could use? I started looking at using the TableTreeViewer but saw that
>> it
>> will be deprecated for Eclipse 3.1M5. Any suggestions?
>>
>> Thanks,
>> Devin Steffler
>> IBM's Eclipse CDT
>> Ottawa (Palladium), Ontario, Canada
>>
>>
>
>
Re: Problems with TreeItem.getItems() [message #449727 is a reply to message #449680] Fri, 28 January 2005 13:56 Go to previous message
Devin Steffler is currently offline Devin StefflerFriend
Messages: 7
Registered: July 2009
Junior Member
Thanks for your help Veronika. Your suggestion didn't seem to work though.
I'll try posting my problem to eclipse.platform and see what happens.

Here's a copy of the code I'm using (maybe something obvious will jump out
at you :)

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
}
}
}
}


"Veronika Irvine" <veronika_irvine@oti.com> wrote in message
news:ctbl6b$2lb$1@www.eclipse.org...
> Your best source for answers about JFace is the eclipse.platform
newsgroup:
>
> news://news.eclipse.org/eclipse.platform
>
> That being said, I think you might need to call the refresh method on the
> TreeViewer after you have changed the content provider.
>
>
> "Devin Steffler" <devin_steffler@ca.ibm.com> wrote in message
> news:ctb9tj$hmn$1@www.eclipse.org...
> > This might be of some help (or part of the problem):
> >
> > My view has a "refresh" button. When it is clicked, I create a new
> > ViewContentProvider (identical to the previous content provider, just a
> > new
> > object) and update the viewer's content provider with it.
> >
> > Then I want to traverse the TreeItems and set the expanded state based
on
> > information from the previous expanded elements (retrieved via
> > viewer.getExpandedElements()).
> >
> > Does setting the content provider to a new ViewContentProvider create
any
> > problems with the TreeViewer, Tree, or the Tree's TreeItems?
> >
> > Thanks,
> > Devin Steffler
> > IBM's Eclipse CDT
> > Ottawa (Palladium), Ontario, Canada
> >
> > "Devin Steffler" <devin_steffler@ca.ibm.com> wrote in message
> > news:ctb7pd$31p$1@www.eclipse.org...
> >> I created a new view that uses a TreeViewer. I want to traverse
through
> > the
> >> TreeItems in the Tree and programmatically setExpanded(true) for
certain
> >> TreeItems.
> >>
> >> The Tree contains the items:
> >> [0]= TreeItem {IASTTranslationUnit} // this should contain several more
> >> TreeItems underneath it but I can't figure out how to get to them and
> >> getItems() doesn't seem to work
> >> [1]= TreeItem {}
> >>
> >> The first TreeItem[0]#setExpanded(true) works fine, but then I want to
> >> setExpanded(true) for some of the TreeItems underneath it. So I do the
> >> following:
> >> TreeItem[0].getItems() to get the TreeItems under that specific
TreeItem
> >> (assuming this is what is supposed to happen based on the spec).
Here's
> >> what the spec says:
> >> --------------------------------------------------
> >> TreeItem#getItems()
> >> Returns an array of TreeItems which are the direct item
> >> children
> >> of the receiver.
> >> --------------------------------------------------
> >>
> >> When I call this, getItems() returns an array of TreeItems that only
has
> > one
> >> element (the TreeItem[1] above displayed as TreeItem{}).
> >>
> >> Is the TreeItem.getItems() supposed to return the TreeItems that are
> >> children to the TreeItem? Is this a bug? Are there alternatives that
I
> >> could use? I started looking at using the TableTreeViewer but saw that
> >> it
> >> will be deprecated for Eclipse 3.1M5. Any suggestions?
> >>
> >> Thanks,
> >> Devin Steffler
> >> IBM's Eclipse CDT
> >> Ottawa (Palladium), Ontario, Canada
> >>
> >>
> >
> >
>
>
Previous Topic:How to undo from a Text??
Next Topic:Is there a SWT list-like widget that displays items in two or more columns?
Goto Forum:
  


Current Time: Sat May 11 23:49:36 GMT 2024

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

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

Back to the top