plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/CompoundValidator.java
author Eugene Ostroukhov <eugeneo@symbian.org>
Mon, 23 Aug 2010 17:20:11 -0700
changeset 474 e2f461f0a9e0
parent 470 d4809db37847
child 484 f5df819c1852
permissions -rw-r--r--
All templates are ported to a new framework
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
474
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
     1
/**
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
     2
 * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
     3
 * All rights reserved.
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
     4
 * This component and the accompanying materials are made available
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
     6
 * which accompanies this distribution, and is available
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
     8
 *
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
     9
 * Initial Contributors:
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
    10
 * Symbian Foundation - initial contribution.
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
    11
 * Contributors:
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
    12
 * Description:
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
    13
 * Overview:
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
    14
 * Details:
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
    15
 * Platforms/Drives/Compatibility:
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
    16
 * Assumptions/Requirement/Pre-requisites:
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
    17
 * Failures and causes:
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
    18
 */
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    19
package org.symbian.tools.tmw.internal.ui.wizard;
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
import org.eclipse.core.databinding.validation.IValidator;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    22
import org.eclipse.core.runtime.IStatus;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    23
import org.eclipse.core.runtime.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
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    26
public class CompoundValidator implements IValidator {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    27
	private final IValidator[] validators;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    28
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    29
	public CompoundValidator(IValidator ... validators) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    30
		this.validators = validators;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    31
	}
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
	public CompoundValidator(NonEmptyStringValidator validator,
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    34
			IValidator[] validators) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    35
		this.validators = new IValidator[validators.length + 1];
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    36
		this.validators[0] = validator;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    37
		System.arraycopy(validators, 0, this.validators, 1, validators.length);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    38
	}
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    39
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    40
	public IStatus validate(Object value) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    41
		IStatus status = Status.OK_STATUS;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    42
		
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    43
		for (IValidator validator : validators) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    44
			IStatus s = validator.validate(value);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    45
			switch (s.getSeverity()) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    46
			case IStatus.ERROR:
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    47
				return s;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    48
			case IStatus.WARNING:
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    49
				status = s;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    50
			}
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    51
		}
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    52
		return status;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    53
	}
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    54
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    55
}