Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsQuestion regarding TreeViewer
https://www.eclipse.org/forums/index.php/mv/msg/146948/462610/#msg_462610
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]]>Andre Pareis2005-10-15T00:11:15-00:00Re: Question regarding TreeViewer
https://www.eclipse.org/forums/index.php/mv/msg/146948/462628/#msg_462628
> 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?]]>Fabian Wolf2005-10-15T08:16:20-00:00Re: Question regarding TreeViewer
https://www.eclipse.org/forums/index.php/mv/msg/146948/462636/#msg_462636
>
> 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]]>Andre Pareis2005-10-15T19:43:41-00:00Re: Question regarding TreeViewer
https://www.eclipse.org/forums/index.php/mv/msg/146948/462704/#msg_462704
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
>]]>Grant Gayed2005-10-17T14:45:57-00:00Re: Question regarding TreeViewer
https://www.eclipse.org/forums/index.php/mv/msg/146948/462711/#msg_462711
> 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]]>Andre Pareis2005-10-17T20:50:47-00:00Re: Question regarding TreeViewer
https://www.eclipse.org/forums/index.php/mv/msg/146948/462731/#msg_462731
"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]]>Grant Gayed2005-10-18T13:57:28-00:00Re: Question regarding TreeViewer
https://www.eclipse.org/forums/index.php/mv/msg/146948/462787/#msg_462787
> 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:
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]]>Andre Pareis2005-10-19T12:43:33-00:00Re: Question regarding TreeViewer
https://www.eclipse.org/forums/index.php/mv/msg/146948/462791/#msg_462791
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]]>Grant Gayed2005-10-19T13:56:01-00:00Re: Question regarding TreeViewer
https://www.eclipse.org/forums/index.php/mv/msg/146948/462805/#msg_462805
> 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