Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Trigger multivalidator in AggregateValidationStatus changelistener
Trigger multivalidator in AggregateValidationStatus changelistener [message #1773395] Wed, 27 September 2017 11:47
baum peter is currently offline baum peterFriend
Messages: 1
Registered: September 2017
Junior Member
I have an AggregateValidationStatus with an IChangeListener

		aggregateValidationStatus.addChangeListener(new IChangeListener() {
			public void handleChange(ChangeEvent event) {
				System.out.println("changed");
				boolean formIsValid = true;
				aggregateValidationStatus.getValue();
				for (Object o : dataBindingContext.getBindings()) {
					Binding binding = (Binding) o;
					IStatus status = (IStatus) binding.getValidationStatus().getValue();
					if (!status.isOK()) {
						formIsValid = false;
					}

					Control control = null;
					if (binding.getTarget() instanceof ISWTObservable) {
						ISWTObservable swtObservable = (ISWTObservable) binding.getTarget();
						control = (Control) swtObservable.getWidget();
					}
					if (binding.getTarget() instanceof CalendarComboObservableValue) {
						CalendarComboObservableValue observable = (CalendarComboObservableValue) binding.getTarget();
						control = (Control) observable.getControl();
					}

					if (binding.getTarget() instanceof IViewerObservable) {
						IViewerObservable observable = (IViewerObservable) binding.getTarget();
						control = observable.getViewer().getControl();
					}

					ControlDecoration decoration = decoratorMap.get(control);
					if (decoration != null) {
						if (status.isOK() || status.matches(Status.WARNING)) {
							decoration.hide();
						} else {
							decoration.setDescriptionText(status.getMessage());
							decoration.show();
						}
					}
				}
				if (saveBtn != null)
					saveBtn.setEnabled(formIsValid);
			}
		});


In this listener I have to trigger the validation of my MultiValidator

	private class PeriodValidator extends MultiValidator {

		private IObservableValue start;
		private IObservableValue end;

		public PeriodValidator(IObservableValue start, IObservableValue end) {
			System.out.println("create validator");
			this.start = start;
			this.end = end;
		}

		@Override
		protected IStatus validate() {
			Date startDate = (Date) start.getValue();
			Date endDate = (Date) end.getValue();

			if (start != null && end != null) {
				if (startDate.after(endDate)) {
					return ValidationStatus.error("From is after To");
				}
			}
			return ValidationStatus.OK_STATUS;
		}
	}


The MultiValidator is added to the DataBindingContext as ValidationStatusProvider. Also the databinding for the 2 components I observe for the MultiValidator is working fine.

		dbFactory.addBinding(periodFromCalendar, "timePeriodFrom",
				new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE)
						.setConverter(new Converter(Date.class, Date.class) {

							@Override
							public Object convert(Object fromObject) {
								Calendar c = Calendar.getInstance();
								c.setTime((Date) fromObject);
								c.set(Calendar.DAY_OF_MONTH, 1);
								return c.getTime();
							}
						}),
				new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE));

		dbFactory.addBinding(periodToCalendar, "timePeriodTo",
				new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE)
						.setConverter(new Converter(Date.class, Date.class) {

							@Override
							public Object convert(Object fromObject) {
								Calendar c = Calendar.getInstance();
								c.setTime((Date) fromObject);
								c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
								return c.getTime();
							}
						}),
				new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE));

		dbFactory.addValidationStatusProvider(
				new PeriodValidator(new CalendarComboObservableValue(periodFromCalendar, SWT.Modify),
						new CalendarComboObservableValue(periodToCalendar, SWT.Modify)));


Sadly the validation is never triggered and therefore the MultiValidator is useless and my AggregateValidationStatus return always true. How to I trigger the validation at the start of the IChangeListener?
Note that its an jface dialog
Previous Topic:How to remove the default the Filter Text Box from ElementListSelectionDialog
Next Topic: TextEdit code design decision
Goto Forum:
  


Current Time: Sat Nov 17 02:58:51 GMT 2018

Powered by FUDForum. Page generated in 0.02194 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top