Skip to content
Snippets Groups Projects
Commit 688a829f authored by Simon Barner's avatar Simon Barner
Browse files

- Add support for BigDecimals

parent 0deacd48
No related branches found
No related tags found
No related merge requests found
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment