From 688a829fcb3a904ca801aafb6bd8d068afb1e733 Mon Sep 17 00:00:00 2001
From: Simon Barner <barner@fortiss.org>
Date: Thu, 21 Apr 2016 15:14:43 +0000
Subject: [PATCH] - Add support for BigDecimals

---
 .../extension/base/PropertySectionBase.java   | 52 ++++++++++++++++++-
 1 file changed, 50 insertions(+), 2 deletions(-)

diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/PropertySectionBase.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/PropertySectionBase.java
index d957805b6..e358c8914 100644
--- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/PropertySectionBase.java
+++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/PropertySectionBase.java
@@ -17,14 +17,18 @@ $Id$
 +--------------------------------------------------------------------------*/
 package org.fortiss.tooling.kernel.ui.extension.base;
 
+import static org.eclipse.core.databinding.conversion.NumberToStringConverter.fromBigDecimal;
 import static org.eclipse.core.databinding.conversion.NumberToStringConverter.fromDouble;
 import static org.eclipse.core.databinding.conversion.NumberToStringConverter.fromInteger;
+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.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 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;
@@ -63,7 +67,7 @@ import com.ibm.icu.text.NumberFormat;
  * @author hoelzl
  * @author $Author$
  * @version $Rev$
- * @ConQAT.Rating GREEN Hash: 5D14BE37F51FE3DB774A7902691F0EEE
+ * @ConQAT.Rating YELLOW Hash: 742920607D7071B83FFCBAC89A37BE31
  */
 public abstract class PropertySectionBase extends AbstractPropertySection {
 
@@ -91,7 +95,6 @@ public abstract class PropertySectionBase extends AbstractPropertySection {
 		 */
 		getWidgetFactory().createList(composite, SWT.NONE).setLayoutData(new GridData(1, 1));
 		getWidgetFactory().createLabel(composite, "", SWT.NONE).setLayoutData(new GridData(1, 1));
-
 	}
 
 	/** {@inheritDoc} */
@@ -286,6 +289,51 @@ public abstract class PropertySectionBase extends AbstractPropertySection {
 		dbc = new EMFDataBindingContext();
 	}
 
+	/**
+	 * Binds a positive {@link BigDecimal} value with the default number of a maximum of three
+	 * fraction digits to be used in the String representation.
+	 */
+	protected void bindPositiveBigDecimalValue(Control text, IObservableValue observedValue) {
+		bindBigDecimalValue(text, observedValue, NumberPositiveValidator.INSTANCE);
+	}
+
+	/**
+	 * Binds a positive {@link BigDecimal} value with a user defined maximum number of fraction
+	 * digits to be used in the String representation.
+	 */
+	protected void bindPositiveBigDecimalValue(Control text, IObservableValue observedValue,
+			int maxFractionDigits) {
+		bindBigDecimalValue(text, observedValue, NumberPositiveValidator.INSTANCE,
+				maxFractionDigits);
+	}
+
+	/**
+	 * Binds a {@link BigDecimal} value with the default number of a maximum of three fraction
+	 * digits to be used in the String representation.
+	 */
+	protected void bindBigDecimalValue(Control text, IObservableValue observedValue,
+			IValidator numberValidator) {
+		// TextToDoubleValidator checks format of fractional numbers and is hence also suitable for
+		// BigDecimals
+		performComplexTextBinding(dbc, text, observedValue, fromBigDecimal(), toBigDecimal(),
+				TextToDoubleValidator.INSTANCE, numberValidator);
+	}
+
+	/**
+	 * Binds a BigDecimal value with a user defined maximum number of fraction digits to be
+	 * used in the String representation.
+	 */
+	protected void bindBigDecimalValue(Control text, IObservableValue observedValue,
+			IValidator numberValidator, int maxFractionDigits) {
+
+		NumberFormat nf = NumberFormat.getNumberInstance();
+		nf.setMaximumFractionDigits(maxFractionDigits);
+		// TextToDoubleValidator checks format of fractional numbers and is hence also suitable for
+		// BigDecimals
+		performComplexTextBinding(dbc, text, observedValue, fromBigDecimal(nf), toBigDecimal(nf),
+				TextToDoubleValidator.INSTANCE, numberValidator);
+	}
+
 	/**
 	 * Binds a positive double value with the default number of a maximum of three fraction digits
 	 * to be used in the String representation.
-- 
GitLab