Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » problems with TableViewer
problems with TableViewer [message #406095] Tue, 06 January 2004 20:56 Go to next message
Brian Fernandes is currently offline Brian FernandesFriend
Messages: 68
Registered: July 2009
Member
Hi Guys,

I'm using a TableViewer for one of my views but I am unclear of how to
achieve the following.

I have 3 columns in my table. Consider a single row of the table. The color
of the cell in the first column must bet set corresponding to the text in
the cell in the second column. Currently I am using a ColorCellEditor in the
first column but the cell editor is displayed only when I click the cell
(obviously). When you use this cellEditor to pick a color, I also manage to
change the background color of the TableItem. - this has 2 issues

1) the color of the entire row is changed, not a single cell
2) the color can be set only you manually change the color.

I use a Label provider to set the text in the second column - this would be
a good time to set the color of the tables cells as well; but here I don't
have a TabelItem Reference - I only have the Object provided by the
ContentProvider and an index.

So in what method should I change the background color of the cells ? - so
that as soon as a row is populated with textual data, it's color is set
accordingly ?

I have also set the third column to be a CheckboxCellEditor but the checkbox
isn't being displayed. Any simple mistakes which I could have made ?

Thanks,
Brian.
Re: problems with TableViewer [message #406106 is a reply to message #406095] Wed, 07 January 2004 01:51 Go to previous messageGo to next message
Michael Xia is currently offline Michael XiaFriend
Messages: 119
Registered: July 2009
Senior Member
Brian,

Are you using 2.1? In 3.0, you could use TableItem.setBackground(int,
Color) to set individual cell's background color.

Michael

Brian Fernandes wrote:

> Hi Guys,

> I'm using a TableViewer for one of my views but I am unclear of how to
> achieve the following.

> I have 3 columns in my table. Consider a single row of the table. The color
> of the cell in the first column must bet set corresponding to the text in
> the cell in the second column. Currently I am using a ColorCellEditor in the
> first column but the cell editor is displayed only when I click the cell
> (obviously). When you use this cellEditor to pick a color, I also manage to
> change the background color of the TableItem. - this has 2 issues

> 1) the color of the entire row is changed, not a single cell
> 2) the color can be set only you manually change the color.

> I use a Label provider to set the text in the second column - this would be
> a good time to set the color of the tables cells as well; but here I don't
> have a TabelItem Reference - I only have the Object provided by the
> ContentProvider and an index.

> So in what method should I change the background color of the cells ? - so
> that as soon as a row is populated with textual data, it's color is set
> accordingly ?

> I have also set the third column to be a CheckboxCellEditor but the checkbox
> isn't being displayed. Any simple mistakes which I could have made ?

> Thanks,
> Brian.
Re: problems with TableViewer [message #406116 is a reply to message #406106] Wed, 07 January 2004 05:17 Go to previous messageGo to next message
Brian Fernandes is currently offline Brian FernandesFriend
Messages: 68
Registered: July 2009
Member
Great - I am using 3 so I can color individual cells.

But I still have a problem here ..
My view is linked to an editor and I am notified of editor changes with the
IPartListener Interface.
When my editor is activated, I call setInput which in turn calls
getElements[] and the LabelProvider provides the new labels for the table.
Now according to a label in a row, I have to set the color of a cell in that
row - where do I do this ?

Or do I use the list of tableItem list to getText and according set the
color ? In what method do I do this ?

Thanks again,
Brian.
Re: problems with TableViewer [message #409981 is a reply to message #406106] Thu, 15 January 2004 06:38 Go to previous messageGo to next message
Brian Fernandes is currently offline Brian FernandesFriend
Messages: 68
Registered: July 2009
Member
I managed to set the background color of the cell using the
ColorCellEditor - but I'm having the following issues with this.

If the table style is set to SWT.FULL_SELECTION, then if I click a row of
the table, the entire rows background color becomes the selection color, and
the color I set is not visible... this is not too big a deal, becuse the
selection is not shown if you deselect the view.

If I don't use SWT.FULL_SELECTION , then the color cell editor does not work
as expected. I have to first select the appropriate row of the table by
clicking a cell in the first column and then only can I click the
colorCellEditor.

SWT.HIDE_SELECTION does not have any effect when SWT.FULL_SELECTION is on.

Any thing I can do to disable the selection from changing the background
color ?

Thanks,
Brian.


"Michael Xia" <yun@rti.com> wrote in message
news:btfone$54k$1@eclipse.org...
> Brian,
>
> Are you using 2.1? In 3.0, you could use TableItem.setBackground(int,
> Color) to set individual cell's background color.
>
> Michael
>
> Brian Fernandes wrote:
>
> > Hi Guys,
>
> > I'm using a TableViewer for one of my views but I am unclear of how to
> > achieve the following.
>
> > I have 3 columns in my table. Consider a single row of the table. The
color
> > of the cell in the first column must bet set corresponding to the text
in
> > the cell in the second column. Currently I am using a ColorCellEditor in
the
> > first column but the cell editor is displayed only when I click the cell
> > (obviously). When you use this cellEditor to pick a color, I also manage
to
> > change the background color of the TableItem. - this has 2 issues
>
> > 1) the color of the entire row is changed, not a single cell
> > 2) the color can be set only you manually change the color.
>
> > I use a Label provider to set the text in the second column - this would
be
> > a good time to set the color of the tables cells as well; but here I
don't
> > have a TabelItem Reference - I only have the Object provided by the
> > ContentProvider and an index.
>
> > So in what method should I change the background color of the cells ? -
so
> > that as soon as a row is populated with textual data, it's color is set
> > accordingly ?
>
> > I have also set the third column to be a CheckboxCellEditor but the
checkbox
> > isn't being displayed. Any simple mistakes which I could have made ?
>
> > Thanks,
> > Brian.
>
>
Re: problems with TableViewer [message #449915 is a reply to message #406095] Mon, 31 January 2005 13:04 Go to previous message
Eclipse UserFriend
Originally posted by: hoeggerand.post.ch

Brian Fernandes schrieb:
> Hi Guys,
>
> I'm using a TableViewer for one of my views but I am unclear of how to
> achieve the following.
>
> I have 3 columns in my table. Consider a single row of the table. The color
> of the cell in the first column must bet set corresponding to the text in
> the cell in the second column. Currently I am using a ColorCellEditor in the
> first column but the cell editor is displayed only when I click the cell
> (obviously). When you use this cellEditor to pick a color, I also manage to
> change the background color of the TableItem. - this has 2 issues
>
> 1) the color of the entire row is changed, not a single cell
> 2) the color can be set only you manually change the color.
>
> I use a Label provider to set the text in the second column - this would be
> a good time to set the color of the tables cells as well; but here I don't
> have a TabelItem Reference - I only have the Object provided by the
> ContentProvider and an index.
>
> So in what method should I change the background color of the cells ? - so
> that as soon as a row is populated with textual data, it's color is set
> accordingly ?
>
> I have also set the third column to be a CheckboxCellEditor but the checkbox
> isn't being displayed. Any simple mistakes which I could have made ?
>
> Thanks,
> Brian.
>
>
Hi Brian
When you attach your own provider class implements ITableLabelProvider,
ITableColorProvider to a TableViewer. The methods Color
getForeground(Object element, int columnIndex); and
Color getBackground(Object element, int columnIndex);
are called for each cell in your table. Once you have had a look at the
implementation of the TableViewer you'll find this hack as internal
class TableColorAndFontCollector.

snipplet:
TableViewer tv = new TableViewer(new Table(parent),SWT.FULL_SELECTION);
tv.setLabelProvider(new P_NonSenseProvider());

// somewhere else

class P_NonSenseProvider implements ITableLabelProvider,
ITableColorProvider{
public Image getColumnImage(Object element, int columnIndex)
{ return null; }
public String getColumnText(Object element, int columnIndex)
{ return null; }
public void addListener(ILabelProviderListener listener)
{ }
public void dispose()
{ }
public boolean isLabelProperty(Object element, String property)
{ return false; }
public void removeListener(ILabelProviderListener listener)
{ }
// methods of the ColorProvider
public Color getBackground(Object element, int columnIndex)
{ return null; }
public Color getForeground(Object element, int columnIndex)
{ return null; }
}

Hope it helps...
Previous Topic:flexible space between menus
Next Topic:Cell editors not working.
Goto Forum:
  


Current Time: Fri Apr 26 08:33:17 GMT 2024

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

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

Back to the top