Bug 107064 - [Preferences] PreferencePage.createNoteComposite does not wrap long notes
Summary: [Preferences] PreferencePage.createNoteComposite does not wrap long notes
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Duong Nguyen CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2005-08-15 16:15 EDT by Mirko Raner CLA
Modified: 2008-06-28 07:39 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mirko Raner CLA 2005-08-15 16:15:47 EDT
Some of our preference dialogs require explanatory notes as part of the dialog.
For reasons of consistency and uniform look and feel, I prefer to use
PreferencePage.createNoteComposite(...) to add these notes. Some of these notes
are a little bit longer and will not fit into a single line.

Instead of wrapping long messages into multiple lines, the note occupies a
single line that is truncated at the end. The parent container uses a GridLayout
and a widthHint is properly set for the note composite (to prevent the note from
"stretching" the width of the enclosing container).

Looking at the source code of PreferencePage.createNoteComposite, it appears
that the note is indeed intended to wrap (SWT.WRAP is used for the Label).
However, in a GridLayout, SWT.WRAP does not have any effect unless the Label
grabs excess horizontal space.

This work-around will cause the label to wrap properly:

if (note.getChildren().length > 1 && note.getLayout() instanceof GridLayout)
{
    note.getChildren()[1].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}

The work-around makes certain assumptions about the internal layout of the note
composite, so this is not really a good way of handling the situation. In my
opinion, createNoteComposite(...) should already set the GridData in the above
fashion.

This problem was also reported earlier as part of bug 40586, but apparently it
got marked as invalid along with some font issues that were not actual bugs.
Comment 1 Tod Creasey CLA 2007-06-13 15:53:54 EDT
There are currently no plans to work on this however I would be happy to look over a contribution
Comment 2 Karsten ... CLA 2008-06-22 05:17:49 EDT
Currently 'playing' around with this, I've also noticed the following:

The JavaDoc for PreferencePage.createNoteComposite() states "[..]This is designed to take up the full width of the page."; however, the created composite (i.e., the descriptive label) does actually not take up the full page width, and it does not adapt when the page is resized. This could perhaps easily be solved by adding GridData.GRAB_HORIZONTAL to the composite's GridData, and additionally setting the same GridData on the descriptive label.

In detail:

[..]
messageComposite.setLayout(messageLayout);
messageComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL |
  GridData.GRAB_HORIZONTAL)); // Additional style GRAB_HORIZONTAL
messageComposite.setFont(font);
[..]

[..]
messageLabel.setText(message);
messageLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL |
  GridData.GRAB_HORIZONTAL)); // Added layout data
messageLabel.setFont(font);
[..]

Wouldn't this solve the layout issues? Could it perhaps have side effects?
Comment 3 Mirko Raner CLA 2008-06-23 18:10:17 EDT
Hello Karsten,
why don't you check out the latest CVS HEAD contents of org.eclipse.jface, apply and test your changes, and then create a patch? I think your changes are correct, and I doubt that it would break anything. If you submit a patch that can be easily applied by Tod or someone else we probably have a better chance to get this fixed. This is not a high-priority issue for me (I'm actually using my work-around from comment #0), but it still would be nice to get little annoyances like this fixed in the Eclipse code base.
Comment 4 Karsten ... CLA 2008-06-28 07:39:30 EDT
Hm, in the meantime, I've found out the solution provided above is only half of the truth. Actually, it does not work on win32 platforms; on those platforms, it  stretches the PreferencePage rather than wrapping the label text. On Gtk, however, this works correctly, and ATM I do not have a clue of where the difference lies.

It seems on Gtk the PreferencePage is layed out according to the width of the FieldEditor with the largest extent, and additional note composites are wrapped accordingly, while on win32 the note composite itself is taken as base for the PreferencePage width.

Would setting a width hint probably solve this? And, if so, what width should it be based on? Basically, I'd always prefer solutions without setting explicit sizing hints to ensure a composite is always layed out correctly (and automatically) according to its contents, as to avoid unwanted effects..