Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Question regarding TreeViewer
Question regarding TreeViewer [message #462610] Sat, 15 October 2005 00:11 Go to next message
Andre Pareis is currently offline Andre PareisFriend
Messages: 113
Registered: July 2009
Senior Member
Hi,

I am using a TreeViewer with additional columns.

Since such a tree with table columns right to the tree can be hard to
read once it get's larger and one adds more columns, I would like to
introduce a nice color banding for odd and even rows.

I have not found a solution to my problem yet. The only piece of code I
found was for a table, there it worked by setting the background of the
TableItems.


I tested to set the background of the root item and it worked partially
in the sense that the tree column was not completely background colored
with my color (only the label, not the space right to it up to the next
column). The subsequent columns to the right were correctly colored
though. Good.

The problems I have are firstly how to do it in a hierarchy of items and
secondly when to do it - perhaps in some listener?

In Swing I always used a renderer for such kind of stuff so I'm kind of
lost now.

Thanks
Andre
Re: Question regarding TreeViewer [message #462628 is a reply to message #462610] Sat, 15 October 2005 08:16 Go to previous messageGo to next message
Fabian Wolf is currently offline Fabian WolfFriend
Messages: 96
Registered: July 2009
Member
Andre R. Pareis wrote:
> Hi,
>
> I am using a TreeViewer with additional columns.
>
> Since such a tree with table columns right to the tree can be hard to
> read once it get's larger and one adds more columns, I would like to
> introduce a nice color banding for odd and even rows.

Is
treeviewer.getTree().setLinesVisible(true);
what you're looking for?
Re: Question regarding TreeViewer [message #462636 is a reply to message #462628] Sat, 15 October 2005 19:43 Go to previous messageGo to next message
Andre Pareis is currently offline Andre PareisFriend
Messages: 113
Registered: July 2009
Senior Member
Fabian Wolf schrieb:
>
> Is
> treeviewer.getTree().setLinesVisible(true);
> what you're looking for?
>

Unfortunately not. setLinesVisible draws only the grid lines IIRC.

What I mean with color banding is to have alternating background colors
for odd end even line numbers.

With a table it's pretty simple by just calling
table.getItem(i).setBackgroundColor(i%2==1 ? oddBackground : evenBackground)

I looking for something similar that works with a tree.

thanks
andre
Re: Question regarding TreeViewer [message #462704 is a reply to message #462636] Mon, 17 October 2005 14:45 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi Andre,

The approach that you're taking is correct. You can make the background
colour span the full width, excluding the expand/collapse box, by creating
your Tree with style SWT.FULL_SELECTION.

Ideally, style FULL_SELECTION should not be needed to make this work, but
this seems to be the case on win32. I'm not sure if this is a bug or native
platform behaviour, so I've logged
https://bugs.eclipse.org/bugs/show_bug.cgi?id=112791 to investigate.

Grant

"Andre R. Pareis" <andre.pareis@entura.ch> wrote in message
news:dirm5i$r7v$1@news.eclipse.org...
> Fabian Wolf schrieb:
> >
> > Is
> > treeviewer.getTree().setLinesVisible(true);
> > what you're looking for?
> >
>
> Unfortunately not. setLinesVisible draws only the grid lines IIRC.
>
> What I mean with color banding is to have alternating background colors
> for odd end even line numbers.
>
> With a table it's pretty simple by just calling
> table.getItem(i).setBackgroundColor(i%2==1 ? oddBackground :
evenBackground)
>
> I looking for something similar that works with a tree.
>
> thanks
> andre
>
Re: Question regarding TreeViewer [message #462711 is a reply to message #462704] Mon, 17 October 2005 20:50 Go to previous messageGo to next message
Andre Pareis is currently offline Andre PareisFriend
Messages: 113
Registered: July 2009
Senior Member
Grant Gayed schrieb:
> The approach that you're taking is correct. You can make the background
> colour span the full width, excluding the expand/collapse box, by creating
> your Tree with style SWT.FULL_SELECTION.
>
> Ideally, style FULL_SELECTION should not be needed to make this work, but
> this seems to be the case on win32. I'm not sure if this is a bug or native
> platform behaviour, so I've logged
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=112791 to investigate.
>
> Grant

Great - or not so great, but I can live with that small bug for the time
being. I added FULL_SELECTION, now the row is colored completely.

I still have no idea how to do the banding with alternating colors on a
tree correctly. The problem is that I just can't go through the
hierarchy and apply alternating background colors to the TreeItems on my
way, because I have to consider the expansion state of each node so that
no two rows will result in the same background color.

I'm sure this is FAQ, but I have no idea where to hook for listening to
expansion events - if there are such ???

Can somebody point me into the right direction?

andre
Re: Question regarding TreeViewer [message #462731 is a reply to message #462711] Tue, 18 October 2005 13:57 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Tree.addTreeListener() will let you listen for expands and collapses.

"Andre R. Pareis" <andre.pareis@entura.ch> wrote in message
news:dj12rd$n6e$1@news.eclipse.org...
> Grant Gayed schrieb:
> > The approach that you're taking is correct. You can make the background
> > colour span the full width, excluding the expand/collapse box, by
creating
> > your Tree with style SWT.FULL_SELECTION.
> >
> > Ideally, style FULL_SELECTION should not be needed to make this work,
but
> > this seems to be the case on win32. I'm not sure if this is a bug or
native
> > platform behaviour, so I've logged
> > https://bugs.eclipse.org/bugs/show_bug.cgi?id=112791 to investigate.
> >
> > Grant
>
> Great - or not so great, but I can live with that small bug for the time
> being. I added FULL_SELECTION, now the row is colored completely.
>
> I still have no idea how to do the banding with alternating colors on a
> tree correctly. The problem is that I just can't go through the
> hierarchy and apply alternating background colors to the TreeItems on my
> way, because I have to consider the expansion state of each node so that
> no two rows will result in the same background color.
>
> I'm sure this is FAQ, but I have no idea where to hook for listening to
> expansion events - if there are such ???
>
> Can somebody point me into the right direction?
>
> andre
Re: Question regarding TreeViewer [message #462787 is a reply to message #462731] Wed, 19 October 2005 12:43 Go to previous messageGo to next message
Andre Pareis is currently offline Andre PareisFriend
Messages: 113
Registered: July 2009
Senior Member
Grant Gayed schrieb:
> Tree.addTreeListener() will let you listen for expands and collapses.


Unfortunately the events are triggered when the tree item is about to
expand.

This made it necessary to invoke my banding method after the expansion
event, which I solved by calling Display.syncExec(...) from within a
temporary thread. This works fine now but looks weird. Here's the code:



treeViewerWithColumns.addTreeListener(new ITreeViewerListener() {

public void treeCollapsed(TreeExpansionEvent event) {
applyBanding();
}


public void treeExpanded(TreeExpansionEvent event) {
applyBanding();
}


private void applyBanding() {
new Thread(new Runnable() {
public void run() {
treeViewerWithColumns.getTree().getDisplay().syncExec(new Runnable() {
public void run() {
applyBandingOnTree(treeViewerWithColumns.getTree().getItem(0 ), 0);
}
});
}
}).start();
}
});




private int applyBandingOnTree(TreeItem ti, int n) {

ti.setBackground((n++&1)==1 ? oddBG : evenBG);

if(ti.getExpanded()) {
TreeItem[] subitems = ti.getItems();
for (TreeItem item : subitems) {
n = applyBandingOnTree(item, n);
}
}

return n;
}



thanks
andre
Re: Question regarding TreeViewer [message #462791 is a reply to message #462787] Wed, 19 October 2005 13:56 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
A slightly less hacky approach to deferring the banding is to do it in an
asyncExec. This would make your applyBanding method look like:

private void applyBanding() {
final Tree tree = treeViewerWithColumns.getTree();
tree.getDisplay().asyncExec(new Runnable() {
public void run() {
if (!tree.isDisposed()) {
applyBandingOnTree(tree.getItem(0), 0);
}
}
});
}

Grant

"Andre R. Pareis" <andre.pareis@entura.ch> wrote in message
news:dj5f1o$4qr$1@news.eclipse.org...
> Grant Gayed schrieb:
> > Tree.addTreeListener() will let you listen for expands and collapses.
>
>
> Unfortunately the events are triggered when the tree item is about to
> expand.
>
> This made it necessary to invoke my banding method after the expansion
> event, which I solved by calling Display.syncExec(...) from within a
> temporary thread. This works fine now but looks weird. Here's the code:
>
>
>
> treeViewerWithColumns.addTreeListener(new ITreeViewerListener() {
>
> public void treeCollapsed(TreeExpansionEvent event) {
> applyBanding();
> }
>
>
> public void treeExpanded(TreeExpansionEvent event) {
> applyBanding();
> }
>
>
> private void applyBanding() {
> new Thread(new Runnable() {
> public void run() {
> treeViewerWithColumns.getTree().getDisplay().syncExec(new Runnable() {
> public void run() {
> applyBandingOnTree(treeViewerWithColumns.getTree().getItem(0 ), 0);
> }
> });
> }
> }).start();
> }
> });
>
>
>
>
> private int applyBandingOnTree(TreeItem ti, int n) {
>
> ti.setBackground((n++&1)==1 ? oddBG : evenBG);
>
> if(ti.getExpanded()) {
> TreeItem[] subitems = ti.getItems();
> for (TreeItem item : subitems) {
> n = applyBandingOnTree(item, n);
> }
> }
>
> return n;
> }
>
>
>
> thanks
> andre
Re: Question regarding TreeViewer [message #462805 is a reply to message #462791] Wed, 19 October 2005 20:00 Go to previous message
Andre Pareis is currently offline Andre PareisFriend
Messages: 113
Registered: July 2009
Senior Member
Grant Gayed wrote:
> A slightly less hacky approach to deferring the banding is to do it in an
> asyncExec. This would make your applyBanding method look like:
>
> private void applyBanding() {
> final Tree tree = treeViewerWithColumns.getTree();
> tree.getDisplay().asyncExec(new Runnable() {
> public void run() {
> if (!tree.isDisposed()) {
> applyBandingOnTree(tree.getItem(0), 0);
> }
> }
> });
> }


thanks Grant, workes fine and makes expansion visually a bit smoother

andre
Previous Topic:No SelectionEvent when right-clicking Tree
Next Topic:SWT Browser crash
Goto Forum:
  


Current Time: Thu Mar 28 15:43:08 GMT 2024

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

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

Back to the top