Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » To sub-class or not to sub-class
To sub-class or not to sub-class [message #436897] Tue, 25 May 2004 23:04 Go to next message
Mark Freiheit is currently offline Mark FreiheitFriend
Messages: 30
Registered: July 2009
Member
I wish to create a Table (or a TableTree) that has alternating rows
colored.
The code to do this is fairly straight forward...

private static final Color oddRowBkgnd =
new Color(Display.getCurrent(), 187, 221, 238);
private static final Color evenRowBkgnd =
new Color(Display.getCurrent(), 255, 255, 255);

private static Color[] rowBkgnd = new Color[] { evenRowBkgnd,
oddRowBkgnd };

public static void colorTable (Table table) {

TableItem[] items = table.getItems();
for (int i = 0; i < items.length; i++) {
items[i].setBackground(rowBkgnd[i % rowBkgnd.length]);
}
}

But if I implement this in a TableTree, then I have to call this code from
each
event handler that alters the input to the table, including Filters and
expand/contract
events.

Is there a "pre-draw" event that I can listen for and call this code in
one place?

Am I better served sub-classing a TableTree (as say a StripedTableTree)?
If so,
what methods would I overload to accomplish the drawing?

Thanks in advance for any advice you can give me -- Mark
Re: To sub-class or not to sub-class [message #436898 is a reply to message #436897] Wed, 26 May 2004 00:11 Go to previous messageGo to next message
Phil Williams is currently offline Phil WilliamsFriend
Messages: 22
Registered: July 2009
Junior Member
Why not just use a ColorProvider for your Table?

Mark wrote:

>I wish to create a Table (or a TableTree) that has alternating rows
>colored.
>The code to do this is fairly straight forward...
>
> private static final Color oddRowBkgnd =
> new Color(Display.getCurrent(), 187, 221, 238);
> private static final Color evenRowBkgnd =
> new Color(Display.getCurrent(), 255, 255, 255);
>
> private static Color[] rowBkgnd = new Color[] { evenRowBkgnd,
>oddRowBkgnd };
>
> public static void colorTable (Table table) {
>
> TableItem[] items = table.getItems();
> for (int i = 0; i < items.length; i++) {
> items[i].setBackground(rowBkgnd[i % rowBkgnd.length]);
> }
> }
>
>But if I implement this in a TableTree, then I have to call this code from
>each
>event handler that alters the input to the table, including Filters and
>expand/contract
>events.
>
>Is there a "pre-draw" event that I can listen for and call this code in
>one place?
>
>Am I better served sub-classing a TableTree (as say a StripedTableTree)?
>If so,
>what methods would I overload to accomplish the drawing?
>
>Thanks in advance for any advice you can give me -- Mark
>
>
>
Re: To sub-class or not to sub-class [message #436998 is a reply to message #436898] Thu, 27 May 2004 19:47 Go to previous messageGo to next message
Mark Freiheit is currently offline Mark FreiheitFriend
Messages: 30
Registered: July 2009
Member
Sorry... I cannot find any references to ColorProvider in SWT APIs (or
Java).
Could you please elaborate a little, or provide me a link to more info?

Thanks -- Mark

Phil Williams wrote:

> Why not just use a ColorProvider for your Table?

> Mark wrote:

> >I wish to create a Table (or a TableTree) that has alternating rows
> >colored.
> >The code to do this is fairly straight forward...
> >
> > private static final Color oddRowBkgnd =
> > new Color(Display.getCurrent(), 187, 221, 238);
> > private static final Color evenRowBkgnd =
> > new Color(Display.getCurrent(), 255, 255, 255);
> >
> > private static Color[] rowBkgnd = new Color[] { evenRowBkgnd,
> >oddRowBkgnd };
> >
> > public static void colorTable (Table table) {
> >
> > TableItem[] items = table.getItems();
> > for (int i = 0; i < items.length; i++) {
> > items[i].setBackground(rowBkgnd[i % rowBkgnd.length]);
> > }
> > }
> >
> >But if I implement this in a TableTree, then I have to call this code from
> >each
> >event handler that alters the input to the table, including Filters and
> >expand/contract
> >events.
> >
> >Is there a "pre-draw" event that I can listen for and call this code in
> >one place?
> >
> >Am I better served sub-classing a TableTree (as say a StripedTableTree)?
> >If so,
> >what methods would I overload to accomplish the drawing?
> >
> >Thanks in advance for any advice you can give me -- Mark
> >
> >
> >
Re: To sub-class or not to sub-class [message #437156 is a reply to message #436998] Sat, 29 May 2004 10:03 Go to previous message
Eclipse UserFriend
Originally posted by: v.j.b

"Mark" <freiheit@speakeasy.net> wrote in message
news:c95gkl$j8s$1@eclipse.org...
> Sorry... I cannot find any references to ColorProvider in SWT APIs (or
> Java).
> Could you please elaborate a little, or provide me a link to more info?

ColorProvider is part of the JFace package that comes with eclipse.
Previous Topic:wiki updates
Next Topic:Linux/Windows SWT issues
Goto Forum:
  


Current Time: Fri Apr 26 14:02:43 GMT 2024

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

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

Back to the top