Mercurial > projects > dwt2
comparison org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToCharacterValidator.d @ 78:0a55d2d5a946
Added file for databinding
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 14 Apr 2009 11:35:29 +0200 |
parents | |
children | 6be48cf9f95c |
comparison
equal
deleted
inserted
replaced
76:f05e6e8b2f2d | 78:0a55d2d5a946 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2007 Matt Carter and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * Matt Carter - initial API and implementation | |
10 * Tom Schindl<tom.schindl@bestsolution.at> - bugfix for 217940 | |
11 ******************************************************************************/ | |
12 | |
13 module org.eclipse.core.internal.databinding.validation.StringToCharacterValidator; | |
14 | |
15 import java.lang.all; | |
16 | |
17 import org.eclipse.core.databinding.validation.IValidator; | |
18 import org.eclipse.core.databinding.validation.ValidationStatus; | |
19 import org.eclipse.core.internal.databinding.BindingMessages; | |
20 import org.eclipse.core.internal.databinding.conversion.StringToCharacterConverter; | |
21 import org.eclipse.core.runtime.IStatus; | |
22 import org.eclipse.core.runtime.Status; | |
23 | |
24 /** | |
25 * Validates a String to Character conversion. | |
26 */ | |
27 public class StringToCharacterValidator : IValidator { | |
28 | |
29 private final StringToCharacterConverter converter; | |
30 | |
31 /** | |
32 * @param converter | |
33 */ | |
34 public this(StringToCharacterConverter converter) { | |
35 this.converter = converter; | |
36 } | |
37 | |
38 /* | |
39 * (non-Javadoc) | |
40 * | |
41 * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object) | |
42 */ | |
43 public IStatus validate(Object value) { | |
44 try { | |
45 converter.convert(value); | |
46 } catch (IllegalArgumentException e) { | |
47 // The StringToCharacterConverter throws an IllegalArgumentException | |
48 // if it cannot convert. | |
49 return ValidationStatus.error(BindingMessages | |
50 .getStringcast(BindingMessages.VALIDATE_CHARACTER_HELP)); | |
51 } | |
52 return Status.OK_STATUS; | |
53 } | |
54 | |
55 } |