From f11ec0dd6ee04bfe2a3796cbae50e02057047d95 Mon Sep 17 00:00:00 2001
From: Simon Barner <barner@fortiss.org>
Date: Wed, 4 May 2016 11:15:14 +0000
Subject: [PATCH] Move -
 org.fortiss.af3.multicore.ui.databinding.validate.NumberPositiveZeroValidator
 - org.fortiss.af3.expression.ui.databinding.validate.IntValidator -
 org.fortiss.af3.expression.ui.databinding.validate.FloatValidator to
 org.fortiss.tooling.base.ui.databinding

refs 2573
---
 .../base/ui/databinding/FloatValidator.java   | 52 +++++++++++++++++++
 .../base/ui/databinding/IntValidator.java     | 52 +++++++++++++++++++
 .../NumberPositiveZeroValidator.java          | 49 +++++++++++++++++
 3 files changed, 153 insertions(+)
 create mode 100644 org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/databinding/FloatValidator.java
 create mode 100644 org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/databinding/IntValidator.java
 create mode 100644 org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/databinding/NumberPositiveZeroValidator.java

diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/databinding/FloatValidator.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/databinding/FloatValidator.java
new file mode 100644
index 000000000..7a8faa99f
--- /dev/null
+++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/databinding/FloatValidator.java
@@ -0,0 +1,52 @@
+/*--------------------------------------------------------------------------+
+$Id$
+|                                                                          |
+| Copyright 2012 ForTISS GmbH                     |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.tooling.base.ui.databinding;
+
+import static org.eclipse.core.databinding.validation.ValidationStatus.cancel;
+import static org.eclipse.core.runtime.Status.OK_STATUS;
+
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * Validator for String to Float conversion.
+ * 
+ * @author hoelzl
+ * @author $Author$
+ * @version $Rev$
+ * @ConQAT.Rating GREEN Hash: 66FE26465159F0F367C315559BA03FF0
+ */
+public class FloatValidator implements IValidator {
+
+	/** Singleton instance. */
+	public static final FloatValidator FLOAT_VALIDATOR = new FloatValidator();
+
+	/** {@inheritDoc} */
+	@Override
+	public IStatus validate(Object value) {
+		if(value instanceof String) {
+			try {
+				Float.valueOf((String)value);
+				return OK_STATUS;
+			} catch(NumberFormatException nfex) {
+				// ignore
+			}
+		}
+		return cancel("Illegal float value!");
+	}
+}
diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/databinding/IntValidator.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/databinding/IntValidator.java
new file mode 100644
index 000000000..fb546e3be
--- /dev/null
+++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/databinding/IntValidator.java
@@ -0,0 +1,52 @@
+/*--------------------------------------------------------------------------+
+$Id$
+|                                                                          |
+| Copyright 2012 ForTISS GmbH                     |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.tooling.base.ui.databinding;
+
+import static org.eclipse.core.databinding.validation.ValidationStatus.cancel;
+import static org.eclipse.core.runtime.Status.OK_STATUS;
+
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * Validator for String to Int conversion.
+ * 
+ * @author hoelzl
+ * @author $Author$
+ * @version $Rev$
+ * @ConQAT.Rating GREEN Hash: F33EF54821FADE10F1B6AA4D5B495CE4
+ */
+public class IntValidator implements IValidator {
+
+	/** Singleton instance. */
+	public static final IntValidator INT_VALIDATOR = new IntValidator();
+
+	/** {@inheritDoc} */
+	@Override
+	public IStatus validate(Object value) {
+		if(value instanceof String) {
+			try {
+				Integer.valueOf((String)value);
+				return OK_STATUS;
+			} catch(NumberFormatException nfex) {
+				// ignore
+			}
+		}
+		return cancel("Illegal int value!");
+	}
+}
diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/databinding/NumberPositiveZeroValidator.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/databinding/NumberPositiveZeroValidator.java
new file mode 100644
index 000000000..498d6b0f8
--- /dev/null
+++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/databinding/NumberPositiveZeroValidator.java
@@ -0,0 +1,49 @@
+/*--------------------------------------------------------------------------+
+$Id$
+|                                                                          |
+| Copyright 2011 ForTISS GmbH                     |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.tooling.base.ui.databinding;
+
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * {@link IValidator} for checking that a numeric value is positive or zero.
+ * 
+ * @author hattendorf
+ * @author $Author$
+ * @version $Rev$
+ * @ConQAT.Rating GREEN Hash: 104C55D6C8A6E1C1AFDD2F64DB56CC20
+ */
+public class NumberPositiveZeroValidator implements IValidator {
+
+	/** Singleton instance. */
+	public static final NumberPositiveZeroValidator INSTANCE = new NumberPositiveZeroValidator();
+
+	/** {@inheritDoc} */
+	@Override
+	public IStatus validate(Object value) {
+		if(!(value instanceof Number)) {
+			return ValidationStatus.cancel("Internal: Expected a Number, but had a " +
+					value.getClass());
+		}
+		if(((Number)value).doubleValue() < 0) {
+			return ValidationStatus.cancel("Value must be positive or zero!");
+		}
+		return ValidationStatus.ok();
+	}
+}
-- 
GitLab