Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 357906 - [Forms] The message's foreground color is never cleared
Summary: [Forms] The message's foreground color is never cleared
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: User Assistance (show other bugs)
Version: 3.8   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 3.8 M3   Edit
Assignee: Chris Goldthorpe CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-16 02:59 EDT by Laurent Goubet CLA
Modified: 2011-09-26 03:01 EDT (History)
1 user (show)

See Also:


Attachments
Modification to forms examples to create test case (12.28 KB, text/x-java)
2011-09-20 13:04 EDT, Chris Goldthorpe CLA
no flags Details
Modified error page (12.39 KB, text/x-java)
2011-09-23 03:42 EDT, Laurent Goubet CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Laurent Goubet CLA 2011-09-16 02:59:20 EDT
If I add an error message to a form, the foreground color of the message region in the form heading is set to red (org.eclipse.ui.internal.forms.widgets.FormHeading#showMessage(String, int IMessage[] calls "updateForeground" since the new type differs from the old type (IMessageProvider.Error instead of IMessageProvider.NONE)).

However, if I now clear all messages (Form.getMessageManager().removeAllMessages(), but it really happens whenever we remove the _last_ message), then we enter this condition of FormHeading.MessageRegion#showMessage() :

if (newMessage == null) {
	// clearing of the message
	if (oldControl != null && oldControl.getVisible())
		oldControl.setVisible(false);
	return;
}

as you can see, "messageType" here has been updated to a new type (IMessageProvider.NONE instead of IMessageProvider.ERROR)... but "updateForeground" never gets called. If we now add a new message to the form, whatever its type, its color will be red (ERROR).

The "if" should be changed to 

if (newMessage == null) {
	// clearing of the message
	if (oldControl != null && oldControl.getVisible())
		oldControl.setVisible(false);
	if (oldType != newType)
		updateForeground();
	return;
}
Comment 1 Chris Goldthorpe CLA 2011-09-16 15:11:53 EDT
Thanks for the suggested fix, targeting Eclipse 3.8.
Comment 2 Chris Goldthorpe CLA 2011-09-19 17:20:10 EDT
Can you provide a test case for this? I thought that I would be able to reproduce this by adding a button to org.eclipse.ui.forms.examples.internal.rcp.ErrorMessagesPage which called removeAllMessages() but the colors continued to change with no problem.
Comment 3 Laurent Goubet CLA 2011-09-20 03:09:50 EDT
Hi Chris,

The code on my side has become quite large, so using that as a test case would be a little complicated.

Do note that the color is updated even in my case, the only problem is the color of the first message we add after the remove :

 - My form is displaying an error message, thus with red text
 - I remove this message (no text displayed on the UI)
 - I add a warning message : it is properly displayed in yellow (no problem in this case)
 - I remove this message (no text displayed)
 - I add a new message with no severity : the text is displayed in yellow instead of black.

The issue only gets visible when the first message we add after a call to removeAll has "IMessageProvider.NONE" severity (and the last message that was displayed before we "removeAll" had another severity).
Comment 4 Chris Goldthorpe CLA 2011-09-20 13:04:17 EDT
Created attachment 203700 [details]
Modification to forms examples to create test case

I tried to create a test case by modifying code in org.eclipse.ui.forms.examples.internal.rcp.ErrorMessagesPage and have attached my modifications. I modified the page so there would be buttons to add a warning, an error, a message of type IMessageProvider.NONE and a button to clear all messages - I could not reproduce the problem. If you are able to get org.eclipse.ui.forms.examples from source control ( Git or CVS )can you try my modification and see what happens. I'm guessing we are doing something slightly different to one another.
Comment 5 Laurent Goubet CLA 2011-09-23 03:42:05 EDT
Created attachment 203882 [details]
Modified error page

Chris,

Just tested your modified example... And yes, we are doing things a little differently. First of all, your code does not have a button to add a "normal" message with no severity (IMessageProvider.ERROR, IMP.WARNNING, IMP.INFORMATION and IMP.NONE are the four supported, the one that poses a problem when added first after a clear is the fourth, NONE).

Second, and that actually seems to be the problem, I am not using an Hyperlink to display the messages of my form, but a CLabel (i.e, I did not add hyperlink listeners on it, so FormHeading.MessageRegion#getMessageControl() returns "messageLabel" in my case ... but "messageHyperlink" in yours). The missing "updateForeground" call is also reproduced with the Hyperling, but somehow, that Control does not seem to care if we do not tell him to reset its foreground to the default "black" color.

Attached is ErrorMessagePage with the modifications to reproduce : I commented out the call to "addHyperlinkListener" (along with all methods that were only called from there) and implemented a button to add a "no severity" message. You can reproduce by simply clicking on any of the "error" or "warning" button, clearing the message through the appropriate button, then clicking the "no severity" button : the message will appear in either yellow or red according to the last message displayed before the clear.
Comment 6 Chris Goldthorpe CLA 2011-09-23 14:20:45 EDT
I can now see the problem and agree with your suggested fix.

Fixed in streams R3_development and R4_development with commit message:
Bug 357906 - [Forms] The message's foreground color is never cleared
Comment 7 Laurent Goubet CLA 2011-09-26 03:01:36 EDT
(In reply to comment #6)
> I can now see the problem and agree with your suggested fix.
> 
> Fixed in streams R3_development and R4_development with commit message:
> Bug 357906 - [Forms] The message's foreground color is never cleared

Thanks, that will be one less awkward workaround in my code :).