Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 291245 - [Viewers] StyledCellLabelProvider.paint(...) does not respect column alignment
Summary: [Viewers] StyledCellLabelProvider.paint(...) does not respect column alignment
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 major with 2 votes (vote)
Target Milestone: 4.3 M7   Edit
Assignee: Michael Rennie CLA
QA Contact:
URL:
Whiteboard: patch
Keywords: contributed, helpwanted
: 270729 (view as bug list)
Depends on: 309785
Blocks: 308321
  Show dependency tree
 
Reported: 2009-10-02 16:01 EDT by Tonny Madsen CLA
Modified: 2018-08-08 04:11 EDT (History)
13 users (show)

See Also:


Attachments
Potential fix v01 (1.40 KB, patch)
2010-02-11 01:17 EST, Hitesh CLA
no flags Details | Diff
perf test (9.14 KB, patch)
2010-02-11 01:36 EST, Hitesh CLA
no flags Details | Diff
perf test (9.16 KB, patch)
2010-02-11 02:15 EST, Hitesh CLA
no flags Details | Diff
modified Snippet051 (5.05 KB, text/plain)
2010-04-14 07:24 EDT, Markus Keller CLA
no flags Details
Patch with fix. (1.04 KB, patch)
2012-10-29 18:13 EDT, Pawel Piech CLA
Michael_Rennie: iplog+
Michael_Rennie: review+
Details | Diff
Extension to the StyledCellLabelProviderTests. (3.77 KB, patch)
2012-10-29 18:14 EDT, Pawel Piech CLA
Michael_Rennie: iplog+
Michael_Rennie: review+
Details | Diff
Text Clipping Bug Demonstration (2.70 KB, text/plain)
2018-08-07 15:58 EDT, Matthew Janssen CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tonny Madsen CLA 2009-10-02 16:01:02 EDT
The current version of StyledCellLabelProvider.paint(...) does not respect the current alignment of the current column.

Unfortunately, this is rather difficult as a new version cannot be implemented outside the org.eclipse.jface.viewers package as vital interfaces are package local. Also the StyledCellLabelProvider.paint(...) cannot be overriden in a sub-classes as some of the needed methods are private to StyledCellLabelProvider (e.g. getViewerCell(...)).
Comment 1 Tonny Madsen CLA 2009-10-02 16:10:41 EDT
By the way: If you fix this, then please make sure that we can optionally have a different alignment for the column header and the column data. You often want to have center alignment for all headers, and yet have left and right alignment for text and number related columns.
Comment 2 Boris Bokowski CLA 2009-11-26 09:52:46 EST
Hitesh is now responsible for watching bugs in the [Viewers] component area.
Comment 3 Hitesh CLA 2010-02-11 01:17:35 EST
Created attachment 158821 [details]
Potential fix v01

Here is a possible patch.
Comment 4 Hitesh CLA 2010-02-11 01:36:10 EST
Created attachment 158822 [details]
perf test

The test is not very useful, but, strangely, I ended up writing a performance test for this.
Comment 5 Hitesh CLA 2010-02-11 01:39:24 EST
Although  the above patch is rather simple and I get an all UI test pass with the patch, it is likely that this must have been avoided for some reason. Adding Boris for comment.
Comment 6 Hitesh CLA 2010-02-11 02:15:34 EST
Created attachment 158825 [details]
perf test
Comment 7 Hitesh CLA 2010-02-11 04:56:42 EST
Just came across a few more related bugs. We should defer this until Bug 292198 is fixed.The layout should be updated completely during the measure event.
Comment 8 Curtis Windatt CLA 2010-04-07 11:16:52 EDT
Ankur and I just ran into this in PDE.  When we switch from a labelprovider to a styledcelllabelprovider the alignment of the other columns was removed.
Comment 9 Ankur Sharma CLA 2010-04-12 05:05:09 EDT
Any plans of this one making it for M7?
Comment 10 Boris Bokowski CLA 2010-04-12 13:41:27 EDT
(In reply to comment #7)
> Just came across a few more related bugs. We should defer this until Bug 292198
> is fixed.The layout should be updated completely during the measure event.

If we don't have the time to optimize, we should just apply the proposed patch, and add a comment on bug 292198 so that we can move the alignment logic when we do optimize.
Comment 11 Hitesh CLA 2010-04-13 06:42:59 EDT
Fix released to HEAD.
Comment 12 Dani Megert CLA 2010-04-14 07:14:40 EDT
Hitesh, I've reverted the fix in HEAD because it causes screen cheese and wrong label positioning.

Test Case:
1. start new workspace using HEAD or N20100413-2000
2. Window > Open Perspective > Java Browsing
3. create a Java project 'P'
4. create a new class 'C' (in default package)
==> observer the cheese in the Packages view
5. in the Projects view select the jsse.jar
==> no cheese but labels not centered in Packages view (if you don't see it immediately, then unselect and select the jsse.jar several times)


I didn't verify it but I suspect this fix might also affect performance.
Comment 13 Markus Keller CLA 2010-04-14 07:24:34 EDT
Created attachment 164816 [details]
modified Snippet051

Here's a modified Snippet051 I used to test this.

StyledCellLabelProvider#updateLayoutAlignment(TextLayout, ViewerCell) had several problems:
- cell.getTextBounds() is expensive and unnecessary, since the calling method already has the bounds (and checked for null)
- layout.setWidth(..) throws an IAE when I make the columns small
- when the columns are too small to show the entire text, they start wrapping. That's unwanted and causes information loss. Not even the tooltip shows the cut text any more.
Comment 14 Hitesh CLA 2010-04-14 07:34:20 EDT
(In reply to comment #12)
> Hitesh, I've reverted the fix in HEAD because it causes screen cheese and wrong
> label positioning.
Thanks
> 
> Test Case:
> 1. start new workspace using HEAD or N20100413-2000
> 2. Window > Open Perspective > Java Browsing
> 3. create a Java project 'P'
> 4. create a new class 'C' (in default package)
> ==> observer the cheese in the Packages view
> 5. in the Projects view select the jsse.jar
> ==> no cheese but labels not centered in Packages view (if you don't see it
> immediately, then unselect and select the jsse.jar several times)

Dani, I haven't been able to reproduce this yet. Will give it further try.

> I didn't verify it but I suspect this fix might also affect performance.

(In reply to comment #13)
> Created an attachment (id=164816) [details]
> modified Snippet051
> 
> Here's a modified Snippet051 I used to test this.
> 
Thanks for catching it early, I had doubts about the performance (Comment 4). Let me investigate and respin the patch if it makes sense.
Comment 15 Markus Keller CLA 2010-04-20 11:00:46 EDT
I'm not sure what you're trying to do with the MeasureItem event (bug 309785).

Can't you just implement this in StyledCellLabelProvider#paint(Event, Object), using layoutBounds and textBounds to calculate x such that end of the text is aligned to the right side of the textBounds? The GC should take care of the necessary clipping (and if it doesn't, you could maybe use GC#setClipping(..) in the meantime).
Comment 16 J. Alv CLA 2010-11-11 11:54:06 EST
Does anyone know if this bug is gonna be fix anytime soon?
Comment 17 Boris Bokowski CLA 2010-11-30 10:35:48 EST
(In reply to comment #16)
> Does anyone know if this bug is gonna be fix anytime soon?

Not sure if we'll be able to get to this soon. Help would be appreciated - see comment 15 for implementation ideas.
Comment 18 J. Alv CLA 2010-11-30 11:26:22 EST
We used Hitesh potential fix because we needed to deliver this to our client ASAP and move to the next module. The only Con we found was that it justifies the column text and creates new lines to fit the rest of it if any.
Comment 19 Dani Megert CLA 2010-11-30 11:28:58 EST
(In reply to comment #18)
> We used Hitesh potential fix because we needed to deliver this to our client
> ASAP and move to the next module. The only Con we found was that it justifies
> the column text and creates new lines to fit the rest of it if any.
See comment 12 and comment 13 for the issues it causes.
Comment 20 Thomas Singer CLA 2011-09-21 07:30:09 EDT
I'm also having this problem and wait for a fix.
Comment 21 Markus Keller CLA 2011-09-21 10:36:11 EDT
If you really need it, you can provide a patch along the lines of comment 15.
Comment 22 Thomas Singer CLA 2011-09-21 13:42:51 EDT
Do you mean I should patch the jface.jar myself? I've tried overriding StyledCellLabelProvider.paint but a lot of methods or variables are not accessible.
Comment 23 Markus Keller CLA 2011-09-21 14:00:55 EDT
No, I meant you could attach a patch here that correctly implements the column alignment right in StyledCellLabelProvider.java.

We don't intend to make the implementation details of that class accessible for overriding, but we would be glad to release a fix that solves the problem for everyone.
Comment 24 Philippe Coucaud CLA 2012-04-29 08:09:10 EDT
*** Bug 270729 has been marked as a duplicate of this bug. ***
Comment 25 Pawel Piech CLA 2012-10-29 18:13:44 EDT
Created attachment 222959 [details]
Patch with fix.

This patch implements the fix suggested in comment #15.  It's a rather small changes so I hope it's not too simplistic.  I had to set the clipping region to avoid painting over the cell's image.
Comment 26 Pawel Piech CLA 2012-10-29 18:14:58 EDT
Created attachment 222960 [details]
Extension to the  StyledCellLabelProviderTests.
Comment 27 Michael Rennie CLA 2013-04-10 11:58:20 EDT
Comment on attachment 222959 [details]
Patch with fix.

The patch works nicely *and* there is no cheese regardless of the size of the column (or during column resizing).

I tested this on Mac and Windows using Dani's test case, Markus' snippet and the PDE launch config / target platform page (both of which use the StyledCellLabelProvider)
Comment 28 Michael Rennie CLA 2013-04-10 12:06:35 EDT
Comment on attachment 222960 [details]
Extension to the  StyledCellLabelProviderTests.

The patch adds the ability to change the layout to confirm it is being respected.

I did have to add in a call to:  tableViewer.getTable().setHeaderVisible(true);
so that the column header would show up.
Comment 30 Matthew Janssen CLA 2018-08-07 15:58:56 EDT
Created attachment 275306 [details]
Text Clipping Bug Demonstration

I am pretty confident that the solution for this bug introduced another bug which has already been documented here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=414292. I have uploaded this attachment that can be run that demonstrates this bug. You will notice that the text in the first column is clipped a little bit and if you resize the column (make it smaller and then make it bigger) you should notice a lot of artifacting and weird behaviour. Mousing over the row after performing the above steps causes the cell to re-draw itself and the graphical glitches are fixed. I believe that this is probably due to the gc.setClipping() lines added in this commit.
Comment 31 Dani Megert CLA 2018-08-08 04:11:25 EDT
(In reply to Matthew Janssen from comment #30)
> Created attachment 275306 [details]
> Text Clipping Bug Demonstration
> 
> I am pretty confident that the solution for this bug introduced another bug
> which has already been documented here:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=414292. I have uploaded this
> attachment that can be run that demonstrates this bug. You will notice that
> the text in the first column is clipped a little bit and if you resize the
> column (make it smaller and then make it bigger) you should notice a lot of
> artifacting and weird behaviour. Mousing over the row after performing the
> above steps causes the cell to re-draw itself and the graphical glitches are
> fixed. I believe that this is probably due to the gc.setClipping() lines
> added in this commit.

Lets deal with this in bug 414292.