|
|
|
Re: problems with TableViewer [message #409981 is a reply to message #406106] |
Thu, 15 January 2004 06:38 |
Brian Fernandes 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 |
Eclipse User |
|
|
|
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...
|
|
|
Powered by
FUDForum. Page generated in 0.02553 seconds