Bug 284384 - [DataBinding] ControlDecorationSupport should hide validation errors initially
Summary: [DataBinding] ControlDecorationSupport should hide validation errors initially
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: PC All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-23 04:46 EDT by Philipp Kursawe CLA
Modified: 2019-09-06 16:17 EDT (History)
4 users (show)

See Also:


Attachments
Patch (8.81 KB, patch)
2009-07-23 13:49 EDT, Matthew Hall CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philipp Kursawe CLA 2009-07-23 04:46:54 EDT
The situation is as following: You have one or more fields that require valid values by the contract given in their validators. In conjunction with control decorations that leads to the fact that upon first presentation of the controls to the user the binding has already performed the validation before the user had a chance to interact with each field and he sees errors (decorations or messages). It should be the way (as recommended by the Eclipse UI guideline and common sense) that the user should be first informed which fields are required. Only after he interacted with *each* field *that* field validates and presents errors or warnings.
I guess it should be solved using an UpdateStrategy but I tried focus out it did not help. The modify update policy alone is not sufficient to deliver the expected behaviour. It reacts to "SWT.Modify" which also occurs when the Databinding binds the current value of the underlying model to the control. It should disable the validation, apply the model data to the target, and only then activate the validators for the field.

The situation is illustrated in the following screenshots:
1. http://screencast.com/t/KOIkAEtZmrH - Errors presented after opening the wizard for the first time
2. http://screencast.com/t/Q0NxAsMte - User entered first valid data, the "required" decoration appears
3. http://screencast.com/t/eI6tajidib - User entered valid data in both fields, the errors are gone. Thats how it should look when the user opens the wizard the first time (without the values entered).

Of course a workaround would be to pre-fill the mode with valid data, but thats not always a good idea, as users could just click "next" then without much thinking.
Comment 1 Matthew Hall CLA 2009-07-23 13:49:28 EDT
Created attachment 142429 [details]
Patch

Philipp, would you apply this patch and try it out?  Try using ControlDecorationUpdater.required() for your updater and tell me how it works for you.

Matthew
Comment 2 Philipp Kursawe CLA 2009-07-23 14:12:36 EDT
Thats for the quick reaction Matthew. However I am not sure how to use the ControlDecoratorUpdater. I have never used it. The problem I described in that bug is a little different I guess. I am creating the "required" control decorations myself.

label = toolkit.createLabel(parent, "Name" + ":"); //$NON-NLS-2$
GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).applyTo(label);
this.nameText = toolkit.createText(parent, null, SWT.NULL);
GridDataFactory.swtDefaults().hint(200, SWT.DEFAULT).applyTo(this.nameText);
decoration = new ControlDecoration(this.nameText, SWT.TOP | SWT.RIGHT);
decoration.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED).getImage());
decoration.show();

Then I have a managed form with its IMessageManager that I use to update the validation status.
My Databinding validator calls the 
this.messageManager.addMessage(this, status.getMessage(), value, IMessageProvider.ERROR, this.control);
in case of an error. This happens right after opening the dialog (when the model is written to the target, which it should not really do).

My databinding goes like this:
observeValue = BeansObservables.observeValue(input, "name"); //$NON-NLS-1$
			observeValue.addChangeListener(new IChangeListener() {
				public void handleChange(final ChangeEvent arg0) {
					markDirty();
				}
			});
			observeText = SWTObservables.observeText(this.nameText, SWT.Modify);
			getDataBindingContext().bindValue(
					observeText,
					observeValue,
					new UpdateValueStrategy().setBeforeSetValidator(new RegexStringValidator(
							"^([^ ]+) ([^ ]+( [^ ]+)*)",
							"Please enter first and last name.",
							new FormWizardPageValidationHandler(this.page, this.nameText))), null);
							
The class FormWizardPageValidationHandler updates the IMessageManager as described above.

So I have successfully applied your patch but do not know how to use it in my situation. Any further instructions?
Comment 3 Matthew Hall CLA 2009-07-23 17:09:33 EDT
Adapting your example above:

ControlDecorationUpdater updater = ControlDecorationUpdater.required();

Binding binding = getDataBindingContext().bindValue(
					observeText,
					observeValue,
					new UpdateValueStrategy().setBeforeSetValidator(new RegexStringValidator(
							"^([^ ]+) ([^ ]+( [^ ]+)*)",
							"Please enter first and last name.",
							new FormWizardPageValidationHandler(this.page, this.nameText))), null);

ControlDecorationSupport.create(binding, SWT.LEFT | SWT.TOP, null, updater);

ControlDecorationSupport is intended to completely manage the creation, updating and disposal of ControlDecorations for your widgets.

See Snippet033CrossValidationControlDecoration.java in the examples project for an example.
Comment 4 Philipp Kursawe CLA 2009-07-24 06:16:21 EDT
Thanks for the patch. It is working as expected! I will now re-model my IManagedForm based validation framework too.
Comment 5 Philipp Kursawe CLA 2009-07-24 07:18:17 EDT
How would I use the required decoration and have it not track any errors, as I am doing that already in the IManagedForms message manager, and it decorates controls too. So that would then be 2 decorations for one control in case of an error.
Comment 6 Paul Webster CLA 2010-06-09 08:17:20 EDT
Removed from 3.6.  Owners can re-assess.

PW
Comment 7 Eclipse Webmaster CLA 2019-09-06 16:17:15 EDT
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.