KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > internal > databinding > provisional > validation > String2BigDecimalValidator


1 /*
2  * Copyright (C) 2005 db4objects Inc. http://www.db4o.com
3  *
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
8  *
9  * Contributors:
10  * db4objects - Initial API and implementation
11  */

12 package org.eclipse.jface.internal.databinding.provisional.validation;
13
14 import java.math.BigDecimal JavaDoc;
15
16 import org.eclipse.jface.internal.databinding.internal.BindingMessages;
17
18
19 /**
20  * DoubleValidator. Verify data input for Doubles
21  *
22  * @author djo
23  */

24 public class String2BigDecimalValidator implements IValidator {
25     
26     /* (non-Javadoc)
27      * @see org.eclipse.jface.databinding.validator.IValidator#isPartiallyValid(java.lang.Object)
28      */

29     public ValidationError isPartiallyValid(Object JavaDoc fragment) {
30         if (((String JavaDoc)fragment).matches("\\-?[0-9]*\\.?[0-9]*([0-9]+[e|E]\\-?([0-9]+\\.)?[0-9]*)?")) //$NON-NLS-1$
31
return null;
32
33         return ValidationError.error(getHint());
34     }
35     
36     /* (non-Javadoc)
37      * @see org.eclipse.jface.viewers.ICellEditorValidator#isValid(java.lang.Object)
38      */

39     public ValidationError isValid(Object JavaDoc value) {
40         try {
41             new BigDecimal JavaDoc((String JavaDoc)value);
42             return null;
43         } catch (Throwable JavaDoc t) {
44             return ValidationError.error(getHint());
45         }
46     }
47
48     private String JavaDoc getHint() {
49         return BindingMessages.getString("Validate_Like") + //$NON-NLS-1$
50
BindingMessages.getString("Validate_Number_Examples"); //$NON-NLS-1$
51
}
52
53 }
54
Popular Tags