1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
13 * Created on 6.10.2005
14 * @author Toni Kalajainen
16 package org.simantics.utils.ui.validators;
18 import org.eclipse.jface.dialogs.IInputValidator;
21 * Validator Multiplexer. Allows to combine multiple validators
24 public class MultiValidator implements IInputValidator {
26 private final IInputValidator validators[];
28 private final AcceptType acceptType;
30 public enum AcceptType {
31 ALL_MUST_PASS, ONE_MUST_PASS
34 public MultiValidator(IInputValidator validators[], AcceptType acceptType) {
35 this.acceptType = acceptType;
36 this.validators = new IInputValidator[validators.length];
37 for (int i = 0; i < validators.length; i++)
38 this.validators[i] = validators[i];
41 public String isValid(String newText) {
42 if (acceptType == AcceptType.ALL_MUST_PASS) {
43 for (int i = 0; i < validators.length; i++) {
44 String result = validators[i].isValid(newText);
51 if (acceptType == AcceptType.ONE_MUST_PASS) {
53 for (int i = 0; i < validators.length; i++) {
54 String result = validators[i].isValid(newText);