org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/CompoundValidator.java
author Eugene Ostroukhov <eugeneo@symbian.org>
Fri, 13 Aug 2010 16:28:00 -0700
changeset 463 aea4c83725d8
permissions -rw-r--r--
Project template work-in-progress
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     1
package org.symbian.tools.tmw.internal.ui.wizard;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     2
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     3
import org.eclipse.core.databinding.validation.IValidator;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     4
import org.eclipse.core.runtime.IStatus;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     5
import org.eclipse.core.runtime.Status;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     6
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     7
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     8
public class CompoundValidator implements IValidator {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     9
	private final IValidator[] validators;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    10
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    11
	public CompoundValidator(IValidator ... validators) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    12
		this.validators = validators;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    13
	}
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    14
	
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    15
	public CompoundValidator(NonEmptyStringValidator validator,
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    16
			IValidator[] validators) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    17
		this.validators = new IValidator[validators.length + 1];
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    18
		this.validators[0] = validator;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    19
		System.arraycopy(validators, 0, this.validators, 1, validators.length);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    20
	}
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    21
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    22
	public IStatus validate(Object value) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    23
		IStatus status = Status.OK_STATUS;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    24
		
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    25
		for (IValidator validator : validators) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    26
			IStatus s = validator.validate(value);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    27
			switch (s.getSeverity()) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    28
			case IStatus.ERROR:
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    29
				return s;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    30
			case IStatus.WARNING:
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    31
				status = s;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    32
			}
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    33
		}
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    34
		return status;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    35
	}
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    36
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    37
}