Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 353031

Summary: UI-Forms: MessageManager always displays "1 error found" instead of actual error message
Product: [Eclipse Project] Platform Reporter: Leo Savernik <l.savernik>
Component: User AssistanceAssignee: platform-ua-inbox <platform-ua-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: cgold
Version: 4.1   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard: stalebug

Description Leo Savernik CLA 2011-07-25 14:59:07 EDT
Build Identifier: 20100218-1602

I'm using Form's IMessageManager infrastructure to associate error messages with controls, i. e. using

IMessageManager.addMessage(Object key, String messageText, Object data,
			int type, Control control)

to associate error messages with specific controls.

This works quite well. However, if there is exactly one error message in MessageManager's queue, the form header always displays "1 error found" instead of the error message itself.

First I suspected that MessageManager could not handle it, however, it provides the necessary provisions in

MessageManager.update(ArrayList mergedList)
...
		if (peers.size() == 1 && ((Message) peers.get(0)).prefix == null) {
...

So the single message is only displayed iff the prefix is null.

The DefaultPrefixProvider never yields a null prefix. So I tried to outsmart the MessageManager and rolled out my own NullPrefixProvider

	static class NullPrefixProvider implements IMessagePrefixProvider {
		@Override
		public String getPrefix(Control control) {
			return null;
		}
	}
...
	form.getMessageManager().setMessagePrefixProvider(new NullPrefixProvider());

But loo. MessageManager's ControlDecorator foiled my plan. It forcefully converts all null-prefixes into empty strings:

		private void createPrefix() {
			if (prefixProvider == null) {
				prefix = ""; //$NON-NLS-1$
				return;
			}
			prefix = prefixProvider.getPrefix(decoration.getControl());
			if (prefix == null)
				// make a prefix anyway
				prefix = ""; //$NON-NLS-1$
		}

That means a single message attached to a control can never be displayed in the header. This behaviour is highly unpractical as typically there is exactly one control that does not validate, namely the one the user is currently editing. My forms shall be useable by keyboard navigation only, therefore I cannot force the user to move the mouse to the header or the decorator icon to reproduce the message.

I found a non-pleasing and quite hacky workaround:
Whenever I issue a call to
	messageManager.addMessage(... message ...);
I immediately afterwards append
	form.setMessage.add(message, IMessageProvider.ERROR);

and for messageManager.removeMessage
	form.setMessage.add(null, IMessageProvider.ERROR);

This will always display the last error message in the header. When more than one error message is in queue, removing one message will clear the header message, leaving the wrong impression no more errors are prevailing (however, the decorator icons are not affected).

Additionally, I had to pass to my validator classes a reference to the form which degrades their loose coupling to the UI code.

Reproducible: Always
Comment 1 Lars Vogel CLA 2019-11-14 03:15:54 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

If the bug is still relevant, please remove the "stalebug" whiteboard tag.