Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 61869

Summary: [JFace] JFace does not reflect the new color options for SWT Table and tree
Product: [Eclipse Project] Platform Reporter: Gunnar Ahlberg <gunnar>
Component: UIAssignee: Tod Creasey <Tod_Creasey>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P2 CC: danjou, eclipse, jean-michel_lemieux, john.ruud, michaelvanmeekeren, n.a.edgar, patmc
Version: 3.0Keywords: helpwanted
Target Milestone: 3.1 M2   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 54534    
Attachments:
Description Flags
Patch for column based colors for TableViewers
none
Standalone class displaying the benefits of a ITableColorProvider
none
Testcase for ITableColorProvider none

Description Gunnar Ahlberg CLA 2004-05-12 05:32:59 EDT
The IColorProvider can be implemented by a label provider to provide 
background and foreground colors to a viewer.
This should be changed to set the colors for individual cells, as is possible 
with the new SWT functionality already implemented in SWT.

Changes:
1) IColorProvider - two supplementing methods
       Color getForeground(Object element, int index);
       Color getBackground(Object element, int index);

2) References to IColorProvider to the new methods
doUpdateItem(Item, Object) - org.eclipse.jface.viewers.TableTreeViewer (3 
matches)
doUpdateItem(Item, Object) - org.eclipse.jface.viewers.TreeViewer (3 matches)
doUpdateItem(Widget, Object, boolean) - org.eclipse.jface.viewers.TableViewer 
(3 matches)
Comment 1 Tod Creasey CLA 2004-05-12 08:05:50 EDT
This is unlikely for 3.0 as the API freeze occured 2 weeks ago. However we 
should look at this early in 3.0.1.
Comment 2 Tod Creasey CLA 2004-05-12 08:06:10 EDT
Marking later
Comment 3 Tod Creasey CLA 2004-06-28 11:28:10 EDT
Reopening now that 3.0 has shipped
Comment 4 Tod Creasey CLA 2004-07-05 09:31:12 EDT
Adding Nick to the list as he is the original author. I am not clear as to why 
this API would be required as you can already determine the color of an cell 
using the IColorProvider using getForeground(Object element) and getBackground
(Object element).

I am not sure why you need API that includes indices as well.
Comment 5 Gunnar Ahlberg CLA 2004-07-05 10:58:21 EDT
I need the viewer to call the IColorProvider per cell, not per row.
Example:

---------------------------------
| Column1 | Column 2 | Column 3 |
---------------------------------
| Blue    |  Red     | Green    |   
---------------------------------

SWT allows this with 3.0, but as long as the viewer is calling the
IColorProvider per row and not per cell, this is not possible (without modifying
the lowlevel widget)
Comment 6 Tod Creasey CLA 2004-07-05 11:04:41 EDT
Right - so an ITableColorProvider would be OK then? I don't think this API 
would be worth having on TreeViewers and so adding a second interface would 
allow us to do this in a non-breaking way.
Comment 7 Nick Edgar CLA 2004-07-05 11:52:50 EDT
That would be consistent with ITableLabelProvider.
Comment 8 Gunnar Ahlberg CLA 2004-07-06 03:43:24 EDT
Ah, yes, that would be the intellegent and elegant solution and would fit my needs.
Comment 9 Tod Creasey CLA 2004-07-06 07:53:38 EDT
Gunnar if this is important to you if you would like to submit a patch with 
your suggested changes we could review it and make sure that it satisifes 
everyone before we proceed.
Comment 10 Gunnar Ahlberg CLA 2004-07-06 09:18:09 EDT
Created attachment 12979 [details]
Patch for column based colors for TableViewers

Initial version, testcase comming
Comment 11 Gunnar Ahlberg CLA 2004-07-06 09:20:58 EDT
Created attachment 12980 [details]
Standalone class displaying the benefits of a ITableColorProvider

This is not a JUnit testcase but a standalone class. It will display a table
with two columns, first with red background and green foreground, and a second
column with green background and red foreground
Comment 12 Michael Van Meekeren CLA 2004-07-06 09:27:33 EDT
Would you be able to provide a JUnit test as well<grin>?
Comment 13 Gunnar Ahlberg CLA 2004-07-06 10:07:24 EDT
Created attachment 12981 [details]
Testcase for ITableColorProvider

This is a testcase that can be run in the org.eclipse.ui.tests project. 
Sourcefolder: Eclipse JFace Tests
Parent class: StructuredViewerTest
Not too sure about how valid or thorough the tests are, may need some
additional work (currently there are 4)
Comment 14 Tod Creasey CLA 2004-07-06 14:27:42 EDT
*** Bug 57154 has been marked as a duplicate of this bug. ***
Comment 15 Tod Creasey CLA 2004-07-06 14:28:37 EDT
*** Bug 52963 has been marked as a duplicate of this bug. ***
Comment 16 Tod Creasey CLA 2004-07-06 14:29:56 EDT
*** Bug 54982 has been marked as a duplicate of this bug. ***
Comment 17 Tod Creasey CLA 2004-07-06 14:56:26 EDT
The basic implementation iof ITableColorProvider looks fine - I will have to 
change to copyright to fit the format of the rest of Eclipse.

The only change to code I will make is that your patch would mean that 
TableViewer would no longer support IColorProvider - this would be a breaking 
API change which I don't think we want to make as it is still potentially 
useful to highlight an entire line.
Comment 18 Nick Edgar CLA 2004-07-06 15:15:15 EDT
As with ILabelProvider/ITableLabelProvider, the table viewers should still
handle the case where an IColorProvider is given instead of an
ITableColorProvider.  In this case, it should apply the color to all columns
(unlike ILabelProvider, which provides the text for the first column only).
Comment 19 Tod Creasey CLA 2004-07-06 15:51:33 EDT
Patch and test released. I have not removed the reference to IColorProvider as 
the patch does but otherwise the code is pretty much the same.

I changed the copyright to be consistent with our other contributor copyrights 
(with attributions of course).

I have also tidied up the test case and added it to our suites.

Thanks for all of the help Gunnar!

As this was a small change it may be worth putting into 3.0.1.
Comment 20 Nick Edgar CLA 2004-07-07 12:15:20 EDT
3.0.1 is for critical fixes only, not new features or enhancements.
Basically the same criteria as the 3.0 end-game.
Comment 21 John Ruud CLA 2004-07-19 16:43:05 EDT
Changes similar to following would make my property sheet life a lot easier:

The following viewers should support ITableColorProvider:
TableViewer
TableTreeViewer
PropertySheetViewer

They should also support something like an 'ITableFontProvider' (similar to 
ITableColorProvider, but for fonts).

A 'DecoratingLabelProvider' if often used for wrapping the real label 
providers, so the viewers would also need to take that into consideration.
Comment 22 John Ruud CLA 2004-07-19 16:50:54 EDT
'PropertySheetViewer' is different from the other viewers in that it is using 
an IPropertySheetEntry for rendering each item (but the entry will typically 
get the values from the entry's label provider).

PropertySheetViewer renders the following values (in column 0 and 1) using the 
IPropertySheetEntry:
Text: getDisplayName(), getValueAsString()
Image: NONE, getImage()
Font: NONE, NONE

The DEFAULT implementation (PropertySheetEntry) is using the entry's label 
provider:
Text: descriptor.getDisplayName(), descriptor.getLabelProvider().getText()
Image: NONE, descriptor.getLabelProvider().getImage()
Font: NONE, NONE

I believe 'IPropertySheetEntry' may have to be fattened up in order to provide 
the missing values (i.e. font for column 0). Alternatively, in our current 
implementation the viewer delegates the rendering of each item/widget to 
an 'item decorator' as follows:

PropertySheetEntry.updateEntry(IPropertySheetEntry entry, TableTreeItem item) {
  ...
  if (entry instanceof IItemDecorator)
    ((IItemDecorator) entry).decorate(entry, item);
  ...
}

public interface IItemDecorator {
  void decorate(Object object, Widget item);
}
Comment 23 Gunnar Ahlberg CLA 2004-08-24 07:58:13 EDT
Hi

I submitted the patch for ITableColorProvider. The only thing left to
touch is the contributor information.
Due to legal issues, please change the attached lines


Index: src/org/eclipse/jface/viewers/ITableColorProvider.java
===================================================================
RCS file:
/home/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/ITableColorProvider.java,v
retrieving revision 1.2
diff -u -r1.2 ITableColorProvider.java
--- src/org/eclipse/jface/viewers/ITableColorProvider.java 8 Jul 2004
20:07:08 -0000 1.2
+++ src/org/eclipse/jface/viewers/ITableColorProvider.java 24 Aug 2004
07:59:56 -0000
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
- * Initial implementation - Gunnar Ahlberg - www.gunnarahlberg.com
+ * Initial implementation - Gunnar Ahlberg - IBS AB, www.ibs.net
* IBM Corporation - further revisions
*******************************************************************************/



Index: Eclipse JFace
Tests/org/eclipse/jface/tests/viewers/TableColorProviderTest.java
===================================================================
RCS file: /home/eclipse/org.eclipse.ui.tests/Eclipse JFace
Tests/org/eclipse/jface/tests/viewers/TableColorProviderTest.java,v
retrieving revision 1.2
diff -u -r1.2 TableColorProviderTest.java
--- Eclipse JFace
Tests/org/eclipse/jface/tests/viewers/TableColorProviderTest.java 8 Jul
2004 20:03:53 -0000 1.2
+++ Eclipse JFace
Tests/org/eclipse/jface/tests/viewers/TableColorProviderTest.java 24 Aug
2004 08:01:59 -0000
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
- * Initial implementation - Gunnar Ahlberg - www.gunnarahlberg.com
+ * Initial implementation - Gunnar Ahlberg - IBS AB, www.ibs.net
* IBM Corporation - further revisions
*******************************************************************************/

Comment 24 Tod Creasey CLA 2004-08-24 07:59:33 EDT
Reopening to fix up comments.
Comment 25 Tod Creasey CLA 2004-08-25 12:04:06 EDT
I have released your requested updates for build >20040825
Comment 26 John Ruud CLA 2004-08-25 17:27:05 EDT
Several viewer-provider related bugs have been marked as dupes of this bug 
(and are therefore closed), including: 
https://bugs.eclipse.org/bugs/show_bug.cgi?id=52963

TableViewer now supports ITableColorProvider, but TableTreeViewer still 
doesn't (I think it should). 
Also, it would be very useful if table viewers were to support 
a 'ITableFontProvider', probably modeled after ITableColorProvider.

Should these be submitted as new bugs (since this one is now closed), or 
should discussion continue here?
Comment 27 Tod Creasey CLA 2004-08-26 07:35:03 EDT
Please do. It is much harder for us to track progress if there are multiple 
problems reported in the same bug. This is particulary timely as I am looking 
into all of the places that JFace does not adequately support the 3.0 SWT API 
now.

BTW I have logged a PR for and ITableFontProvider as well. See Bug 72615
Comment 28 John Ruud CLA 2004-08-26 15:17:39 EDT
Will do (I have entered BR# 72720)
Comment 29 Tod Creasey CLA 2004-09-21 11:36:52 EDT
Verified in 200409210800