Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Expanding a TreeItem in swt.Tree
| |
Re: Expanding a TreeItem in swt.Tree [message #454107 is a reply to message #454104] |
Sun, 17 April 2005 23:44 |
Eclipse User |
|
|
|
Originally posted by: doug-list.threepenny.net
for(int i = 0; i < c; i++){
TreeItem s = p0.getItems()[0];
should be
[i] not [0]
Doug
Boris Munivrana wrote:
> Hi there,
>
> while coding a method which should expand a treebranch including all its
> subitems it appears that actually it's only working for a quite small
> amount / limited depth of TreeItems.
> Here are the 2 methods I wrote:
>
> a) implementation:
>
> public void expandTreeItem(Tree p0, TreeItem p1, boolean p2){
> p0.setRedraw(false);
> p1.setExpanded(p2);
> expandTreeItem(p1, p2);
> p0.setRedraw(true);
> p0.redraw();
> }
>
> b) helper method:
>
> private static void expandTreeItem(TreeItem p0, boolean p1){
> int c = p0.getItemCount();
> for(int i = 0; i < c; i++){
> TreeItem s = p0.getItems()[0];
> s.setExpanded(p1);
> if(s.getItemCount() > 0)
> expandTreeItem(s, p1);
> }
> }
>
> c:) usage:
>
> TreeItem[] selection = tree.getSelection();
> if(selection.length > 0){
> expandTreeItem(tree, selection[0],!selection[0].getExpanded());
> }
>
>
> What is wrong with my code? Any help would be appreciated.
>
> Kind regards
>
> Boris Munivrana
>
|
|
|
Re: Expanding a TreeItem in swt.Tree [message #454289 is a reply to message #454107] |
Tue, 19 April 2005 17:33 |
Boris Munivrana Messages: 23 Registered: July 2009 |
Junior Member |
|
|
Thanks, Doug.
BTW: Do you have any idea how to catch all children of a treebranch in a
fast way, since the swt.widgets.Tree / swt.widgets.TreeItem API does not
handle deep treestructure by default, like
javax.swing.tree.DefaultMutableTreeNode.
Backround: 2 years ago I wrote a swing-based application for my company
which breaks down variant parts lists from database source / Excel,
creates a hierarchic teestructure and with the combination of DND enabling
the user to change the structure (we're providing catalogs with part lists
for our end customers via docware, but our recource lists have to be
modified before they can be displayed, and docware doesn't provide any
functionality / software to do this).
This works quite well with swing, but focusing my interest on swt I now
would like to rewrite it, hoping for swt's capability of providing a more
native user experience, but somehow I haven't got around the tree problem
yet.
With kind regards
Boris Munivrana
Doug Pearson wrote:
> for(int i = 0; i < c; i++){
> TreeItem s = p0.getItems()[0];
> should be
> [i] not [0]
> Doug
> Boris Munivrana wrote:
>> Hi there,
>>
>> while coding a method which should expand a treebranch including all its
>> subitems it appears that actually it's only working for a quite small
>> amount / limited depth of TreeItems.
>> Here are the 2 methods I wrote:
>>
>> a) implementation:
>>
>> public void expandTreeItem(Tree p0, TreeItem p1, boolean p2){
>> p0.setRedraw(false);
>> p1.setExpanded(p2);
>> expandTreeItem(p1, p2);
>> p0.setRedraw(true);
>> p0.redraw();
>> }
>>
>> b) helper method:
>>
>> private static void expandTreeItem(TreeItem p0, boolean p1){
>> int c = p0.getItemCount();
>> for(int i = 0; i < c; i++){
>> TreeItem s = p0.getItems()[0];
>> s.setExpanded(p1);
>> if(s.getItemCount() > 0)
>> expandTreeItem(s, p1);
>> }
>> }
>>
>> c:) usage:
>>
>> TreeItem[] selection = tree.getSelection();
>> if(selection.length > 0){
>> expandTreeItem(tree, selection[0],!selection[0].getExpanded());
>> }
>>
>>
>> What is wrong with my code? Any help would be appreciated.
>>
>> Kind regards
>>
>> Boris Munivrana
>>
|
|
|
Re: Expanding a TreeItem in swt.Tree [message #454290 is a reply to message #454289] |
Tue, 19 April 2005 17:37 |
Emil Crumhorn Messages: 169 Registered: July 2009 |
Senior Member |
|
|
You should look into using a TreeViewer with a ContentProvider and a
LabelProvider if you want to do "detailed" operations on your tree, that way
you can do what you did in Swing, which is defining your own nodes. And if
you have those set up with the usual parent-child get/fetch/add methods,
it's easy to fetch all children starting at a certain leaf. TreeViewers also
allow you to filter and sort your trees, and if you have your LabelProvider
implement IFontProvider, IColorProvider then you have colors and fonts for
your tree too.
IBM has an example in their developerworks section if you want some code
samples: http://www-106.ibm.com/developerworks/java/library/os-ecgui1 /
Emil
"Boris Munivrana" <bmunivrana@web.de> wrote in message
news:cb3c3c02a4e35ef6bacadb1b2cf5a955$1@www.eclipse.org...
>
> Thanks, Doug.
>
> BTW: Do you have any idea how to catch all children of a treebranch in a
> fast way, since the swt.widgets.Tree / swt.widgets.TreeItem API does not
> handle deep treestructure by default, like
> javax.swing.tree.DefaultMutableTreeNode.
>
> Backround: 2 years ago I wrote a swing-based application for my company
> which breaks down variant parts lists from database source / Excel,
> creates a hierarchic teestructure and with the combination of DND enabling
> the user to change the structure (we're providing catalogs with part lists
> for our end customers via docware, but our recource lists have to be
> modified before they can be displayed, and docware doesn't provide any
> functionality / software to do this). This works quite well with swing,
> but focusing my interest on swt I now would like to rewrite it, hoping for
> swt's capability of providing a more native user experience, but somehow I
> haven't got around the tree problem yet.
>
> With kind regards
>
> Boris Munivrana
>
>
> Doug Pearson wrote:
>
>> for(int i = 0; i < c; i++){
>> TreeItem s = p0.getItems()[0];
>
>> should be
>> [i] not [0]
>
>> Doug
>
>> Boris Munivrana wrote:
>
>>> Hi there,
>>>
>>> while coding a method which should expand a treebranch including all its
>>> subitems it appears that actually it's only working for a quite small
>>> amount / limited depth of TreeItems.
>>> Here are the 2 methods I wrote:
>>>
>>> a) implementation:
>>>
>>> public void expandTreeItem(Tree p0, TreeItem p1, boolean p2){
>>> p0.setRedraw(false);
>>> p1.setExpanded(p2);
>>> expandTreeItem(p1, p2);
>>> p0.setRedraw(true);
>>> p0.redraw();
>>> }
>>>
>>> b) helper method:
>>>
>>> private static void expandTreeItem(TreeItem p0, boolean p1){
>>> int c = p0.getItemCount();
>>> for(int i = 0; i < c; i++){
>>> TreeItem s = p0.getItems()[0];
>>> s.setExpanded(p1);
>>> if(s.getItemCount() > 0)
>>> expandTreeItem(s, p1);
>>> }
>>> }
>>>
>>> c:) usage:
>>>
>>> TreeItem[] selection = tree.getSelection();
>>> if(selection.length > 0){
>>> expandTreeItem(tree, selection[0],!selection[0].getExpanded());
>>> }
>>>
>>>
>>> What is wrong with my code? Any help would be appreciated.
>>>
>>> Kind regards
>>>
>>> Boris Munivrana
>>>
>
|
|
|
Re: Expanding a TreeItem in swt.Tree [message #454292 is a reply to message #454290] |
Tue, 19 April 2005 18:46 |
Boris Munivrana Messages: 23 Registered: July 2009 |
Junior Member |
|
|
Hi, Emil,
Emil Crumhorn wrote:
> You should look into using a TreeViewer with a ContentProvider and a
> LabelProvider if you want to do "detailed" operations on your tree, that way
> you can do what you did in Swing, which is defining your own nodes. And if
> you have those set up with the usual parent-child get/fetch/add methods,
> it's easy to fetch all children starting at a certain leaf.
That sounds good, so far. But does all this perform decently? The parts
lists I'm dealing with may consist of a several hundred items. Swing does
this very fast, but, since I suggest that a TreeViewer encapsulates an SWT
Tree widget, I think I would only be facing the poor performance I
experienced with the SWT Tree?
> TreeViewers also allow you to filter and sort your trees, and if you have
Neat-
> your LabelProvider
> implement IFontProvider, IColorProvider then you have colors and fonts for
> your tree too.
I will definetly need these features to indicate dragged-/copied states
of treenodes -
> IBM has an example in their developerworks section if you want some code
> samples: http://www-106.ibm.com/developerworks/java/library/os-ecgui1 /
Thanks for the link and for your attention, it is appreciated deeply.
With kind regards,
Boris Munivrana
> Emil
> "Boris Munivrana" <bmunivrana@web.de> wrote in message
> news:cb3c3c02a4e35ef6bacadb1b2cf5a955$1@www.eclipse.org...
>>
>> Thanks, Doug.
>>
>> BTW: Do you have any idea how to catch all children of a treebranch in a
>> fast way, since the swt.widgets.Tree / swt.widgets.TreeItem API does not
>> handle deep treestructure by default, like
>> javax.swing.tree.DefaultMutableTreeNode.
>>
>> Backround: 2 years ago I wrote a swing-based application for my company
>> which breaks down variant parts lists from database source / Excel,
>> creates a hierarchic teestructure and with the combination of DND enabling
>> the user to change the structure (we're providing catalogs with part lists
>> for our end customers via docware, but our recource lists have to be
>> modified before they can be displayed, and docware doesn't provide any
>> functionality / software to do this). This works quite well with swing,
>> but focusing my interest on swt I now would like to rewrite it, hoping for
>> swt's capability of providing a more native user experience, but somehow I
>> haven't got around the tree problem yet.
>>
>> With kind regards
>>
>> Boris Munivrana
>>
>>
>> Doug Pearson wrote:
>>
>>> for(int i = 0; i < c; i++){
>>> TreeItem s = p0.getItems()[0];
>>
>>> should be
>>> [i] not [0]
>>
>>> Doug
>>
>>> Boris Munivrana wrote:
>>
>>>> Hi there,
>>>>
>>>> while coding a method which should expand a treebranch including all its
>>>> subitems it appears that actually it's only working for a quite small
>>>> amount / limited depth of TreeItems.
>>>> Here are the 2 methods I wrote:
>>>>
>>>> a) implementation:
>>>>
>>>> public void expandTreeItem(Tree p0, TreeItem p1, boolean p2){
>>>> p0.setRedraw(false);
>>>> p1.setExpanded(p2);
>>>> expandTreeItem(p1, p2);
>>>> p0.setRedraw(true);
>>>> p0.redraw();
>>>> }
>>>>
>>>> b) helper method:
>>>>
>>>> private static void expandTreeItem(TreeItem p0, boolean p1){
>>>> int c = p0.getItemCount();
>>>> for(int i = 0; i < c; i++){
>>>> TreeItem s = p0.getItems()[0];
>>>> s.setExpanded(p1);
>>>> if(s.getItemCount() > 0)
>>>> expandTreeItem(s, p1);
>>>> }
>>>> }
>>>>
>>>> c:) usage:
>>>>
>>>> TreeItem[] selection = tree.getSelection();
>>>> if(selection.length > 0){
>>>> expandTreeItem(tree, selection[0],!selection[0].getExpanded());
>>>> }
>>>>
>>>>
>>>> What is wrong with my code? Any help would be appreciated.
>>>>
>>>> Kind regards
>>>>
>>>> Boris Munivrana
>>>>
>>
|
|
|
Re: Expanding a TreeItem in swt.Tree [message #454336 is a reply to message #454289] |
Wed, 20 April 2005 16:49 |
Steve Northover Messages: 1636 Registered: July 2009 |
Senior Member |
|
|
For one thing, "getItems() [0]" is a bad thing to do. Call getItems() once,
store the result and then iterate through that. Even if the items were
stored in Java memory (they are not, they are stored in the operating
system), getItems() would need to return a copy of the array to avoid the
application modified the array directly. I hope this is enough to fix your
performance problem.
"Boris Munivrana" <bmunivrana@web.de> wrote in message
news:cb3c3c02a4e35ef6bacadb1b2cf5a955$1@www.eclipse.org...
>
> Thanks, Doug.
>
> BTW: Do you have any idea how to catch all children of a treebranch in a
> fast way, since the swt.widgets.Tree / swt.widgets.TreeItem API does not
> handle deep treestructure by default, like
> javax.swing.tree.DefaultMutableTreeNode.
>
> Backround: 2 years ago I wrote a swing-based application for my company
> which breaks down variant parts lists from database source / Excel,
> creates a hierarchic teestructure and with the combination of DND enabling
> the user to change the structure (we're providing catalogs with part lists
> for our end customers via docware, but our recource lists have to be
> modified before they can be displayed, and docware doesn't provide any
> functionality / software to do this).
> This works quite well with swing, but focusing my interest on swt I now
> would like to rewrite it, hoping for swt's capability of providing a more
> native user experience, but somehow I haven't got around the tree problem
> yet.
>
> With kind regards
>
> Boris Munivrana
>
>
> Doug Pearson wrote:
>
> > for(int i = 0; i < c; i++){
> > TreeItem s = p0.getItems()[0];
>
> > should be
> > [i] not [0]
>
> > Doug
>
> > Boris Munivrana wrote:
>
> >> Hi there,
> >>
> >> while coding a method which should expand a treebranch including all
its
> >> subitems it appears that actually it's only working for a quite small
> >> amount / limited depth of TreeItems.
> >> Here are the 2 methods I wrote:
> >>
> >> a) implementation:
> >>
> >> public void expandTreeItem(Tree p0, TreeItem p1, boolean p2){
> >> p0.setRedraw(false);
> >> p1.setExpanded(p2);
> >> expandTreeItem(p1, p2);
> >> p0.setRedraw(true);
> >> p0.redraw();
> >> }
> >>
> >> b) helper method:
> >>
> >> private static void expandTreeItem(TreeItem p0, boolean p1){
> >> int c = p0.getItemCount();
> >> for(int i = 0; i < c; i++){
> >> TreeItem s = p0.getItems()[0];
> >> s.setExpanded(p1);
> >> if(s.getItemCount() > 0)
> >> expandTreeItem(s, p1);
> >> }
> >> }
> >>
> >> c:) usage:
> >>
> >> TreeItem[] selection = tree.getSelection();
> >> if(selection.length > 0){
> >> expandTreeItem(tree, selection[0],!selection[0].getExpanded());
> >> }
> >>
> >>
> >> What is wrong with my code? Any help would be appreciated.
> >>
> >> Kind regards
> >>
> >> Boris Munivrana
> >>
>
|
|
|
Re: Expanding a TreeItem in swt.Tree [message #454445 is a reply to message #454336] |
Wed, 20 April 2005 21:31 |
Boris Munivrana Messages: 23 Registered: July 2009 |
Junior Member |
|
|
Hi Steve,
thanks for pointing this out.
With kind regards
Boris Munivrana
Steve Northover wrote:
> For one thing, "getItems() [0]" is a bad thing to do. Call getItems() once,
> store the result and then iterate through that. Even if the items were
> stored in Java memory (they are not, they are stored in the operating
> system), getItems() would need to return a copy of the array to avoid the
> application modified the array directly. I hope this is enough to fix your
> performance problem.
> "Boris Munivrana" <bmunivrana@web.de> wrote in message
> news:cb3c3c02a4e35ef6bacadb1b2cf5a955$1@www.eclipse.org...
>>
>> Thanks, Doug.
>>
>> BTW: Do you have any idea how to catch all children of a treebranch in a
>> fast way, since the swt.widgets.Tree / swt.widgets.TreeItem API does not
>> handle deep treestructure by default, like
>> javax.swing.tree.DefaultMutableTreeNode.
>>
>> Backround: 2 years ago I wrote a swing-based application for my company
>> which breaks down variant parts lists from database source / Excel,
>> creates a hierarchic teestructure and with the combination of DND enabling
>> the user to change the structure (we're providing catalogs with part lists
>> for our end customers via docware, but our recource lists have to be
>> modified before they can be displayed, and docware doesn't provide any
>> functionality / software to do this).
>> This works quite well with swing, but focusing my interest on swt I now
>> would like to rewrite it, hoping for swt's capability of providing a more
>> native user experience, but somehow I haven't got around the tree problem
>> yet.
>>
>> With kind regards
>>
>> Boris Munivrana
>>
>>
>> Doug Pearson wrote:
>>
>> > for(int i = 0; i < c; i++){
>> > TreeItem s = p0.getItems()[0];
>>
>> > should be
>> > [i] not [0]
>>
>> > Doug
>>
>> > Boris Munivrana wrote:
>>
>> >> Hi there,
>> >>
>> >> while coding a method which should expand a treebranch including all
> its
>> >> subitems it appears that actually it's only working for a quite small
>> >> amount / limited depth of TreeItems.
>> >> Here are the 2 methods I wrote:
>> >>
>> >> a) implementation:
>> >>
>> >> public void expandTreeItem(Tree p0, TreeItem p1, boolean p2){
>> >> p0.setRedraw(false);
>> >> p1.setExpanded(p2);
>> >> expandTreeItem(p1, p2);
>> >> p0.setRedraw(true);
>> >> p0.redraw();
>> >> }
>> >>
>> >> b) helper method:
>> >>
>> >> private static void expandTreeItem(TreeItem p0, boolean p1){
>> >> int c = p0.getItemCount();
>> >> for(int i = 0; i < c; i++){
>> >> TreeItem s = p0.getItems()[0];
>> >> s.setExpanded(p1);
>> >> if(s.getItemCount() > 0)
>> >> expandTreeItem(s, p1);
>> >> }
>> >> }
>> >>
>> >> c:) usage:
>> >>
>> >> TreeItem[] selection = tree.getSelection();
>> >> if(selection.length > 0){
>> >> expandTreeItem(tree, selection[0],!selection[0].getExpanded());
>> >> }
>> >>
>> >>
>> >> What is wrong with my code? Any help would be appreciated.
>> >>
>> >> Kind regards
>> >>
>> >> Boris Munivrana
>> >>
>>
|
|
|
Goto Forum:
Current Time: Sat Apr 27 02:35:16 GMT 2024
Powered by FUDForum. Page generated in 0.04066 seconds
|