Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 518142 - FormLayout in Form doesn't ignore body size when instructed to do so
Summary: FormLayout in Form doesn't ignore body size when instructed to do so
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.7   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 4.8 M3   Edit
Assignee: Peter Severin CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-12 13:51 EDT by Peter Severin CLA
Modified: 2017-10-10 23:40 EDT (History)
4 users (show)

See Also:


Attachments
Take in account IGNORE_BODY flag in form layout (768 bytes, patch)
2017-09-22 08:47 EDT, Peter Severin CLA
no flags Details | Diff
Before the fix (19.31 KB, image/png)
2017-09-22 08:47 EDT, Peter Severin CLA
no flags Details
After the fix (40.54 KB, image/png)
2017-09-22 08:47 EDT, Peter Severin CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Severin CLA 2017-06-12 13:51:22 EDT
Fix for Bug 196692 introduce another bug. The description is below.

I've been testing my plugin (WireframeSketcher) with RC version of Eclipse 4.7 and I've encountered a problem that I've tracked down to the change in this bug. I've been using a feature of Form that allows to ignore the body in layout calculation. This feature is enabled as follows:

scrolledForm.getForm().setData(FormUtil.IGNORE_BODY, Boolean.TRUE);

Unfortunately the changes in this bug break this feature and now the size of the body is always taken in account, regardless of the IGNORE_BODY flag. I've narrowed down this change to Form$FormLayout$computeMinimumWidth. This method now looks like this:

public int computeMinimumWidth(Composite composite, boolean flushCache) {
	initCaches(flushCache);
	return Math.max(headCache.computeMinimumWidth(), bodyCache.computeMinimumWidth());
}

This has changed from before:

public int computeMinimumWidth(Composite composite, boolean flushCache) {
	return computeSize(composite, 5, SWT.DEFAULT, flushCache).x;
}

Note that the minimum width calculation now always takes the body into account.

The fix is as simple as the following:

public int computeMinimumWidth(Composite composite, boolean flushCache) {
	initCaches(flushCache);
	boolean ignoreBody = form.getData(FormUtil.IGNORE_BODY) != null;
	return Math.max(headCache.computeMinimumWidth(), ignoreBody ? 0 : bodyCache.computeMinimumWidth());
}
Comment 1 Andrey Loskutov CLA 2017-06-12 14:14:34 EDT
Peter, can you please provide a patch & a test for it?
https://wiki.eclipse.org/Platform_UI/How_to_Contribute
Comment 2 Peter Severin CLA 2017-09-22 08:47:22 EDT
Created attachment 270313 [details]
Take in account IGNORE_BODY flag in form layout

Andrey, I apologize for the delayed reply. I couldn't way for this issue to be fixed and hacked around Eclipse code on my side to create a workaround for it.

I've attached a patch that fixes this issue. I've tested if with WireframeSketcher where I've encountered this issue.

As for the test, I am not sure how to isolate this functionality properly. I'm including the before and after screenshots of the results that I get in my plugin. There is a form with a header and a StyledText in the body. With a long text set on StyledText the layout takes in account StyledText's preferred size and then forces the entire form to be of that size. Setting the flag to ignore the body allows to ignore the size of the StyledText and just consider the size of the header for the layout.

Let me know if this is enough to include the fix into the next version.
Comment 3 Peter Severin CLA 2017-09-22 08:47:37 EDT
Created attachment 270314 [details]
Before the fix
Comment 4 Peter Severin CLA 2017-09-22 08:47:53 EDT
Created attachment 270315 [details]
After the fix
Comment 5 Lars Vogel CLA 2017-09-22 09:07:07 EDT
Peter, can you please upload a Gerrit for the change?
Comment 6 Eclipse Genie CLA 2017-09-22 10:03:49 EDT
New Gerrit change created: https://git.eclipse.org/r/105624
Comment 7 Peter Severin CLA 2017-09-22 12:04:06 EDT
Lars, I've added a unit test and uploaded it to the initial Gerrit Change. However I'm not sure if I did it correctly. It's my first time using Gerrit. Can you take a look?
Comment 9 Mickael Istria CLA 2017-10-10 14:11:00 EDT
Thanks a lot Peter!
Comment 10 Lars Vogel CLA 2017-10-10 14:44:53 EDT
(In reply to Mickael Istria from comment #9)
> Thanks a lot Peter!

Also thanks from me Peter, sorry that I was not able to timely review your patch, I'm currently very busy with customer work. Thanks to Mickael for stepping up!
Comment 11 Peter Severin CLA 2017-10-10 23:40:51 EDT
Thanks you, guys! It was a nice introduction into the Eclipse committer's workflow :)