Commit 7c6a05a4 authored by Simon Barner's avatar Simon Barner
Browse files

Double input format validation: check if the entire string was parsed

* org.conqat.ide.commons.ui.databinding.validate.TextToDoubleValidator
  also accepted inputs where only a prefix was valid (followed by some
* Local version of TextToDoubleValidator checks if the entire input was

Issue-Ref: 3582

Signed-off-by: Simon Barner's avatarSimon Barner <>
parent d7196a4c
......@@ -8,7 +8,7 @@ 4c5ac569c0b6e7678fc8191096b26dfd09fdcb98 GREEN 384727748f125c9d43f19d9c0eba4ba1be5a7a26 GREEN 9e237d8ea640c4194e4877af4a9cfce88698e543 GREEN 681b98b50b362f01abb7a36f108f4f11b9e51829 GREEN 3601ee8bd77be45ff770a5ee1c7536f100bee6b2 GREEN c545ad187b8fcff8fc9e592a923b7c0b1522133b YELLOW cea2a158158b476de2108d2309afcf47f217b6d9 GREEN a9788ae514f62d27169c737ef59fb583234b5d43 GREEN 8225210eacb5b88de47d78280c5819f572f00ffa GREEN
......@@ -21,17 +21,20 @@ import static
import static org.eclipse.core.databinding.conversion.StringToNumberConverter.toBigDecimal;
import static org.eclipse.core.databinding.conversion.StringToNumberConverter.toDouble;
import static org.eclipse.core.databinding.conversion.StringToNumberConverter.toInteger;
import static org.eclipse.core.databinding.validation.ValidationStatus.cancel;
import static org.eclipse.core.databinding.validation.ValidationStatus.ok;
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.DECORATION_KEY;
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.performComplexTextBinding;
import static org.fortiss.tooling.kernel.ui.util.WidgetsFactory.createTextWithUndo;
import java.math.BigDecimal;
import java.text.ParsePosition;
import org.conqat.ide.commons.ui.databinding.validate.NumberPositiveValidator;
import org.conqat.ide.commons.ui.databinding.validate.TextToDoubleValidator;
import org.conqat.ide.commons.ui.databinding.validate.TextToIntegerValidator;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.databinding.EMFDataBindingContext;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
......@@ -66,6 +69,35 @@ import;
public abstract class PropertySectionBase extends AbstractPropertySection {
/** Validates if a given input is a valid {@link Number}. */
private static class TextToDoubleValidator implements IValidator {
/** Singleton instance. */
public static final TextToDoubleValidator INSTANCE = new TextToDoubleValidator();
/** The number format used in the current locale. */
private final NumberFormat format = NumberFormat.getNumberInstance();
/** {@inheritDoc} */
public IStatus validate(Object value) {
assert (value != null);
ParsePosition p = new ParsePosition(0);
String input = value.toString();
format.parse(input, p);
int errorIndex = p.getErrorIndex();
// In case the input as a valid prefix, the error index will not indicate a problem.
// Therefore, check if the entire input was parsed.
if(errorIndex == -1 && p.getIndex() < input.length()) {
errorIndex = p.getIndex();
return errorIndex == -1 ? ok() : cancel(
"Double number format validation failed at position " + errorIndex + ".");
/** Label width. */
public static final int PROPERTIES_LABEL_WIDTH = 150;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment