Community
Participate
Working Groups
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; }
Thanks for the suggested fix, targeting Eclipse 3.8.
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.
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).
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.
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.
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
(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 :).