diff --git a/org.fortiss.tooling.base.ui/META-INF/MANIFEST.MF b/org.fortiss.tooling.base.ui/META-INF/MANIFEST.MF index 82c8ad63d4c60630dded2d0c8a0a05fde2d99502..9bb1ff85da9bb0ceadff74e98f30f861d556d799 100644 --- a/org.fortiss.tooling.base.ui/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.base.ui/META-INF/MANIFEST.MF @@ -19,7 +19,6 @@ Export-Package: org.fortiss.tooling.base.ui, org.fortiss.tooling.base.ui.annotation.view.generic.filter, org.fortiss.tooling.base.ui.compose, org.fortiss.tooling.base.ui.contentprovider, - org.fortiss.tooling.base.ui.databinding, org.fortiss.tooling.base.ui.dialog, org.fortiss.tooling.base.ui.dnd.gef, org.fortiss.tooling.base.ui.dnd.jface, diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/.ratings deleted file mode 100644 index 1ecd0e2699b19474fcc7cfefb77678de22cf7208..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/.ratings +++ /dev/null @@ -1,7 +0,0 @@ -AbstractDecoratedStyledTextCellDatabindingEditingSupport.java 7db18b7973f945f087c0188f485fe3a63007d6c8 GREEN -AbstractDecoratedTextCellDatabindingEditingSupport.java 35f02a80a8d66975eace1805247ff4e2f8129283 GREEN -AbstractStyledTextCellDatabindingEditingSupport.java 8207d7cc6e5d49f8bca0b46fe92a08df85ad9094 GREEN -AbstractTextCellDatabindingEditingSupport.java 348e8377f8da4f8a4073c96cee58178635641678 GREEN -FloatValidator.java 371c13a05481c3d03304e82997b523eeec8746aa GREEN -IntValidator.java 6362bd7648937720f85027878e3e84d2b5a534d5 GREEN -NumberPositiveZeroValidator.java c960cf31a35f352cf31fa96a409073c04e83ca02 GREEN diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/.ratings index 5b50759a2e8de1c1639b582a8e86f03c1ad85d13..16c1534386d115e94e2a6106fc20f35f4acd5893 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/.ratings +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/.ratings @@ -7,5 +7,4 @@ DiagramEditorBase.java 09663ce095074d1a8eef086284eea0a7776e0431 GREEN DiagramKeyHandler.java cfd15ac8f9fc933739cef5e7039960e19826d1ce GREEN FormsEditorBase.java 4046d340913d951340084ae7240d79f8e75cb8d4 GREEN GEFEditorBase.java e668f596f45f07215994cbbd3929a9438331718f GREEN -StyledTextCellEditor.java c709c5092bf54d42ddbac53c8751659020060aef GREEN TreeViewerEditorBase.java 1c59689ff57c4f3cc180d85f13021fc03461ecb0 GREEN diff --git a/org.fortiss.tooling.kernel.ui/META-INF/MANIFEST.MF b/org.fortiss.tooling.kernel.ui/META-INF/MANIFEST.MF index d893684a74a43041601318d6d29bd08f55375ecd..83d8cef86dade7ad413cb5d8a3d44a6898f8194f 100644 --- a/org.fortiss.tooling.kernel.ui/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.kernel.ui/META-INF/MANIFEST.MF @@ -13,7 +13,9 @@ Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-Vendor: fortiss GmbH Export-Package: org.fortiss.tooling.kernel.ui, + org.fortiss.tooling.kernel.ui.databinding, org.fortiss.tooling.kernel.ui.dnd, + org.fortiss.tooling.kernel.ui.editor, org.fortiss.tooling.kernel.ui.extension, org.fortiss.tooling.kernel.ui.extension.base, org.fortiss.tooling.kernel.ui.extension.data, diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/.ratings new file mode 100644 index 0000000000000000000000000000000000000000..9dd0f6021e7168c022352a59336ac1298854887e --- /dev/null +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/.ratings @@ -0,0 +1,10 @@ +AbstractDecoratedStyledTextCellDatabindingEditingSupport.java a0b06a9bd98ce28da3e5df86b2cb289b5a7a2eab GREEN +AbstractDecoratedTextCellDatabindingEditingSupport.java d82943c0d4000b164beb45b00c64665cdcab2352 GREEN +AbstractStyledTextCellDatabindingEditingSupport.java 6ddea6d5cb18847f202043d9bb2bd8a55ae27a12 GREEN +AbstractTextCellDatabindingEditingSupport.java 8728e78f399a63c11f020fa447c002f42d735771 GREEN +FloatValidator.java 3173a438f0dc773331be9c7d57478984e1fd52b6 GREEN +IntValidator.java 934eee306191839be6d319432a1a238ff38c3f66 GREEN +NumberPositiveValidator.java c45d4433c260e1e7bd4117954221dacb6d2df225 GREEN +NumberPositiveZeroValidator.java 8ba0dfdcc8b8ad2154f2fb3e6217ff585e59d6e5 GREEN +NumberValidator.java 1acdc8a42e9d081251c698a90014989733b50120 GREEN +NumberValueValidatorBase.java a8cda58d8bba6fdc05c6ac3249dbf1b53fcb0c2b GREEN diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/AbstractDecoratedStyledTextCellDatabindingEditingSupport.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/AbstractDecoratedStyledTextCellDatabindingEditingSupport.java similarity index 98% rename from org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/AbstractDecoratedStyledTextCellDatabindingEditingSupport.java rename to org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/AbstractDecoratedStyledTextCellDatabindingEditingSupport.java index 7db18b7973f945f087c0188f485fe3a63007d6c8..a0b06a9bd98ce28da3e5df86b2cb289b5a7a2eab 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/AbstractDecoratedStyledTextCellDatabindingEditingSupport.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/AbstractDecoratedStyledTextCellDatabindingEditingSupport.java @@ -13,7 +13,7 @@ | See the License for the specific language governing permissions and | | limitations under the License. | +--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.databinding; +package org.fortiss.tooling.kernel.ui.databinding; import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.DECORATION_KEY; import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.performCellTextBinding; diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/AbstractDecoratedTextCellDatabindingEditingSupport.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/AbstractDecoratedTextCellDatabindingEditingSupport.java similarity index 98% rename from org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/AbstractDecoratedTextCellDatabindingEditingSupport.java rename to org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/AbstractDecoratedTextCellDatabindingEditingSupport.java index 35f02a80a8d66975eace1805247ff4e2f8129283..d82943c0d4000b164beb45b00c64665cdcab2352 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/AbstractDecoratedTextCellDatabindingEditingSupport.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/AbstractDecoratedTextCellDatabindingEditingSupport.java @@ -13,7 +13,7 @@ | See the License for the specific language governing permissions and | | limitations under the License. | +--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.databinding; +package org.fortiss.tooling.kernel.ui.databinding; import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.DECORATION_KEY; import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.performCellTextBinding; diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/AbstractStyledTextCellDatabindingEditingSupport.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/AbstractStyledTextCellDatabindingEditingSupport.java similarity index 95% rename from org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/AbstractStyledTextCellDatabindingEditingSupport.java rename to org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/AbstractStyledTextCellDatabindingEditingSupport.java index 8207d7cc6e5d49f8bca0b46fe92a08df85ad9094..6ddea6d5cb18847f202043d9bb2bd8a55ae27a12 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/AbstractStyledTextCellDatabindingEditingSupport.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/AbstractStyledTextCellDatabindingEditingSupport.java @@ -13,14 +13,14 @@ | See the License for the specific language governing permissions and | | limitations under the License. | +--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.databinding; +package org.fortiss.tooling.kernel.ui.databinding; import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.ColumnViewer; import org.eclipse.swt.widgets.Composite; -import org.fortiss.tooling.base.ui.editor.StyledTextCellEditor; +import org.fortiss.tooling.kernel.ui.editor.StyledTextCellEditor; import org.fortiss.tooling.kernel.ui.extension.base.EditorBase; /** diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/AbstractTextCellDatabindingEditingSupport.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/AbstractTextCellDatabindingEditingSupport.java similarity index 94% rename from org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/AbstractTextCellDatabindingEditingSupport.java rename to org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/AbstractTextCellDatabindingEditingSupport.java index 348e8377f8da4f8a4073c96cee58178635641678..8728e78f399a63c11f020fa447c002f42d735771 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/AbstractTextCellDatabindingEditingSupport.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/AbstractTextCellDatabindingEditingSupport.java @@ -13,7 +13,7 @@ | See the License for the specific language governing permissions and | | limitations under the License. | +--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.databinding; +package org.fortiss.tooling.kernel.ui.databinding; import org.eclipse.core.databinding.Binding; import org.eclipse.core.databinding.DataBindingContext; @@ -28,7 +28,6 @@ import org.eclipse.jface.viewers.EditingSupport; import org.eclipse.jface.viewers.TextCellEditor; import org.eclipse.jface.viewers.ViewerCell; import org.eclipse.swt.widgets.Composite; -import org.fortiss.tooling.base.ui.fieldassist.FieldAssist; import org.fortiss.tooling.kernel.ui.util.DataBindingUtils; /** @@ -73,23 +72,12 @@ public abstract class AbstractTextCellDatabindingEditingSupport extends EditingS protected CellEditor createCellEditor(ColumnViewer viewer) { CellEditor cellEditor = new TextCellEditor((Composite)viewer.getControl()); setupCellEditor(cellEditor); - setupFieldAssist(cellEditor); return cellEditor; } /** Set up the new created {@link CellEditor} */ protected abstract void setupCellEditor(CellEditor cellEditor); - /** - * Sets up {@link FieldAssist} for the cellEditor. - * - * @param cellEditor - * The {@link CellEditor} to create a {@link FieldAssist} for. - */ - protected void setupFieldAssist(CellEditor cellEditor) { - // Empty - } - /** {@inheritDoc} */ @Override public CellEditor getCellEditor(Object model) { diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/NumberPositiveZeroValidator.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/FloatValidator.java similarity index 56% rename from org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/NumberPositiveZeroValidator.java rename to org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/FloatValidator.java index c960cf31a35f352cf31fa96a409073c04e83ca02..3173a438f0dc773331be9c7d57478984e1fd52b6 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/NumberPositiveZeroValidator.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/FloatValidator.java @@ -1,5 +1,5 @@ /*-------------------------------------------------------------------------+ -| Copyright 2011 fortiss GmbH | +| 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. | @@ -13,32 +13,28 @@ | See the License for the specific language governing permissions and | | limitations under the License. | +--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.databinding; +package org.fortiss.tooling.kernel.ui.databinding; -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.runtime.IStatus; +import java.text.NumberFormat; /** - * {@link IValidator} for checking that a numeric value is positive or zero. + * Validator to check if a number is an floating point number. * - * @author hattendorf + * @author hoelzl, barner */ -public class NumberPositiveZeroValidator implements IValidator { +public class FloatValidator extends NumberValidator { - /** Singleton instance. */ - public static final NumberPositiveZeroValidator INSTANCE = new NumberPositiveZeroValidator(); + /** {@link FloatValidator} singleton instance. */ + public static final FloatValidator FLOAT_VALIDATOR = new FloatValidator(); + + /** Constructor. */ + private FloatValidator() { + super(NumberFormat.getNumberInstance()); + } /** {@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(); + protected String getFormatName() { + return "Floating point"; } } diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/IntValidator.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/IntValidator.java new file mode 100644 index 0000000000000000000000000000000000000000..934eee306191839be6d319432a1a238ff38c3f66 --- /dev/null +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/IntValidator.java @@ -0,0 +1,40 @@ +/*-------------------------------------------------------------------------+ +| 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.kernel.ui.databinding; + +import java.text.NumberFormat; + +/** + * Validator to check if a number is an integer. + * + * @author hoelzl, barner + */ +public class IntValidator extends NumberValidator { + + /** {@link IntValidator} singleton instance. */ + public static final IntValidator INT_VALIDATOR = new IntValidator(); + + /** Constructor. */ + private IntValidator() { + super(NumberFormat.getIntegerInstance()); + } + + /** {@inheritDoc} */ + @Override + protected String getFormatName() { + return "Integer"; + } +} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/IntValidator.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/NumberPositiveValidator.java similarity index 69% rename from org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/IntValidator.java rename to org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/NumberPositiveValidator.java index 6362bd7648937720f85027878e3e84d2b5a534d5..c45d4433c260e1e7bd4117954221dacb6d2df225 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/IntValidator.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/NumberPositiveValidator.java @@ -1,5 +1,5 @@ /*-------------------------------------------------------------------------+ -| Copyright 2012 fortiss GmbH | +| Copyright 2018 fortiss GmbH | | | | Licensed under the Apache License, Version 2.0 (the "License"); | | you may not use this file except in compliance with the License. | @@ -13,35 +13,32 @@ | See the License for the specific language governing permissions and | | limitations under the License. | +--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.databinding; +package org.fortiss.tooling.kernel.ui.databinding; import static org.eclipse.core.databinding.validation.ValidationStatus.cancel; -import static org.eclipse.core.runtime.Status.OK_STATUS; +import static org.eclipse.core.databinding.validation.ValidationStatus.ok; import org.eclipse.core.databinding.validation.IValidator; import org.eclipse.core.runtime.IStatus; /** - * Validator for String to Int conversion. + * {@link IValidator} for checking that a numeric value is positive. * - * @author hoelzl + * @author barner */ -public class IntValidator implements IValidator { +public class NumberPositiveValidator extends NumberValueValidatorBase { /** Singleton instance. */ - public static final IntValidator INT_VALIDATOR = new IntValidator(); + public static final NumberPositiveValidator NUMBER_POSITIVE_VALIDATOR = + new NumberPositiveValidator(); /** {@inheritDoc} */ @Override - public IStatus validate(Object value) { - if(value instanceof String) { - try { - Integer.valueOf((String)value); - return OK_STATUS; - } catch(NumberFormatException nfex) { - // ignore - } + protected IStatus doValidate(Number number) { + if(number.doubleValue() <= 0) { + return cancel("Value must be > 0"); } - return cancel("Illegal int value!"); + + return ok(); } } diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/FloatValidator.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/NumberPositiveZeroValidator.java similarity index 68% rename from org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/FloatValidator.java rename to org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/NumberPositiveZeroValidator.java index 371c13a05481c3d03304e82997b523eeec8746aa..8ba0dfdcc8b8ad2154f2fb3e6217ff585e59d6e5 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/FloatValidator.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/NumberPositiveZeroValidator.java @@ -1,5 +1,5 @@ /*-------------------------------------------------------------------------+ -| Copyright 2012 fortiss GmbH | +| Copyright 2018 fortiss GmbH | | | | Licensed under the Apache License, Version 2.0 (the "License"); | | you may not use this file except in compliance with the License. | @@ -13,35 +13,32 @@ | See the License for the specific language governing permissions and | | limitations under the License. | +--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.databinding; +package org.fortiss.tooling.kernel.ui.databinding; import static org.eclipse.core.databinding.validation.ValidationStatus.cancel; -import static org.eclipse.core.runtime.Status.OK_STATUS; +import static org.eclipse.core.databinding.validation.ValidationStatus.ok; import org.eclipse.core.databinding.validation.IValidator; import org.eclipse.core.runtime.IStatus; /** - * Validator for String to Float conversion. + * {@link IValidator} for checking that a numeric value is positive or zero. * - * @author hoelzl + * @author barner */ -public class FloatValidator implements IValidator { +public class NumberPositiveZeroValidator extends NumberValueValidatorBase { /** Singleton instance. */ - public static final FloatValidator FLOAT_VALIDATOR = new FloatValidator(); + public static final NumberPositiveZeroValidator NUMBER_POSITIVE_ZERO_VALIDATOR = + new NumberPositiveZeroValidator(); /** {@inheritDoc} */ @Override - public IStatus validate(Object value) { - if(value instanceof String) { - try { - Float.valueOf((String)value); - return OK_STATUS; - } catch(NumberFormatException nfex) { - // ignore - } + protected IStatus doValidate(Number number) { + if(number.doubleValue() < 0) { + return cancel("Value must be >= 0"); } - return cancel("Illegal float value!"); + + return ok(); } } diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/NumberValidator.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/NumberValidator.java new file mode 100644 index 0000000000000000000000000000000000000000..1acdc8a42e9d081251c698a90014989733b50120 --- /dev/null +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/NumberValidator.java @@ -0,0 +1,82 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2018 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.kernel.ui.databinding; + +import static org.eclipse.core.databinding.validation.ValidationStatus.cancel; +import static org.eclipse.core.databinding.validation.ValidationStatus.ok; + +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.text.ParsePosition; + +import org.eclipse.core.databinding.validation.IValidator; +import org.eclipse.core.runtime.IStatus; + +/** + * Validates if a given input is a valid {@link Number}. + * + * @author barner + */ +public abstract class NumberValidator implements IValidator { + + /** The number format used in the current locale. */ + private final NumberFormat format; + + /** Character used to separate blocks of large numbers. */ + private Character groupingSeparator; + + /** Constructor. */ + protected NumberValidator(NumberFormat format) { + this.format = format; + if(format instanceof DecimalFormat) { + DecimalFormat df = (DecimalFormat)format; + groupingSeparator = df.getDecimalFormatSymbols().getGroupingSeparator(); + } + } + + /** Returns the format name. */ + protected abstract String getFormatName(); + + /** {@inheritDoc} */ + @Override + public IStatus validate(Object value) { + String input = value != null ? value.toString() : ""; + String trimmedInput = input.trim(); + if(trimmedInput.isEmpty()) { + return ok(); + } + if((groupingSeparator != null) && (trimmedInput.indexOf(groupingSeparator) != -1)) { + return cancel("Grouping separator \'" + groupingSeparator + "\' not allowed"); + } + + ParsePosition p = new ParsePosition(0); + format.parse(trimmedInput, p); + int errorIndex = p.getErrorIndex(); + + if(errorIndex == -1) { + // In case the input has a valid prefix, the error index will not indicate a problem. + // Therefore, check if the entire input was parsed. + if(p.getIndex() < trimmedInput.length()) { + errorIndex = p.getIndex(); + } else { + return ok(); + } + } + + int n = input.indexOf(trimmedInput) + errorIndex; + return cancel(getFormatName() + " format validation failed at position " + n); + } +} diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/NumberValueValidatorBase.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/NumberValueValidatorBase.java new file mode 100644 index 0000000000000000000000000000000000000000..a8cda58d8bba6fdc05c6ac3249dbf1b53fcb0c2b --- /dev/null +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/NumberValueValidatorBase.java @@ -0,0 +1,52 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2018 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.kernel.ui.databinding; + +import static org.eclipse.core.databinding.validation.ValidationStatus.cancel; +import static org.eclipse.core.databinding.validation.ValidationStatus.ok; +import static org.fortiss.tooling.kernel.utils.LoggingUtils.error; + +import org.eclipse.core.databinding.validation.IValidator; +import org.eclipse.core.runtime.IStatus; +import org.fortiss.tooling.kernel.ToolingKernelActivator; + +/** + * Base class for {@link IValidator}s to check the value of {@link Number}s. + * + * @author barner + */ +public abstract class NumberValueValidatorBase implements IValidator { + + /** {@inheritDoc} */ + @Override + public final IStatus validate(Object value) { + if(value == null) { + return ok(); + } + + if(!(value instanceof Number)) { + String typeName = value.getClass().getSimpleName(); + error(ToolingKernelActivator.getDefault(), "Value \"" + value.toString() + + "\" is not a number but of type " + typeName + "."); + return cancel("Value is not a number"); + } + + return doValidate((Number)value); + } + + /** Checks the value of the provided {@link Number}. */ + protected abstract IStatus doValidate(Number number); +} diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/package.html b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/package.html similarity index 100% rename from org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/databinding/package.html rename to org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/databinding/package.html diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/editor/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/editor/.ratings new file mode 100644 index 0000000000000000000000000000000000000000..8ca4189f26e2c4aaa0df50d3d8a001a500bd169d --- /dev/null +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/editor/.ratings @@ -0,0 +1 @@ +StyledTextCellEditor.java e844c8236bb162bcbe980e47796f7e93c57a14d6 GREEN diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/StyledTextCellEditor.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/editor/StyledTextCellEditor.java similarity index 98% rename from org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/StyledTextCellEditor.java rename to org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/editor/StyledTextCellEditor.java index c709c5092bf54d42ddbac53c8751659020060aef..e844c8236bb162bcbe980e47796f7e93c57a14d6 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/StyledTextCellEditor.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/editor/StyledTextCellEditor.java @@ -13,7 +13,7 @@ | See the License for the specific language governing permissions and | | limitations under the License. | +--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.editor; +package org.fortiss.tooling.kernel.ui.editor; import org.eclipse.jface.viewers.TextCellEditor; import org.eclipse.swt.widgets.Composite; diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/.ratings index 832374ffe86b507c132a54627e90c1d3f30ed071..66aceca19cfde5f9c670997ae6411b0e402b5229 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/.ratings @@ -10,7 +10,7 @@ ModelEditorBindingBase.java 4c5ac569c0b6e7678fc8191096b26dfd09fdcb98 GREEN ModelElementHandlerBase.java 384727748f125c9d43f19d9c0eba4ba1be5a7a26 GREEN MultiEObjectActionBase.java 9e237d8ea640c4194e4877af4a9cfce88698e543 GREEN NamedCommentedModelElementHandlerBase.java 681b98b50b362f01abb7a36f108f4f11b9e51829 GREEN -PropertySectionBase.java c061c62531621d96b1e1d1c27ad99889c92bacb7 YELLOW +PropertySectionBase.java 0a39bd8587eeeeb72693b57e80ae8951c3e45c22 YELLOW TutorialStepUIAtomicBase.java cea2a158158b476de2108d2309afcf47f217b6d9 GREEN TutorialStepUIAtomicWithWhitelistBase.java a9788ae514f62d27169c737ef59fb583234b5d43 GREEN TutorialStepUICompositeBase.java 8225210eacb5b88de47d78280c5819f572f00ffa GREEN diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/PropertySectionBase.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/PropertySectionBase.java index c061c62531621d96b1e1d1c27ad99889c92bacb7..0a39bd8587eeeeb72693b57e80ae8951c3e45c22 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/PropertySectionBase.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/PropertySectionBase.java @@ -21,15 +21,15 @@ import static org.eclipse.core.databinding.conversion.NumberToStringConverter.fr 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.databinding.FloatValidator.FLOAT_VALIDATOR; +import static org.fortiss.tooling.kernel.ui.databinding.IntValidator.INT_VALIDATOR; +import static org.fortiss.tooling.kernel.ui.databinding.NumberPositiveValidator.NUMBER_POSITIVE_VALIDATOR; 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; import org.eclipse.core.databinding.observable.value.IObservableValue; import org.eclipse.core.databinding.validation.IValidator; import org.eclipse.emf.common.notify.Notification; @@ -193,21 +193,39 @@ public abstract class PropertySectionBase extends AbstractPropertySection { protected abstract void setSectionInput(Object input); /** - * Creates a text widget, which has a {@link ControlDecoration} attached. + * Creates a {@link Text} control which has a {@link ControlDecoration} attached. * The decoration is stored as widget data for convenience. */ - protected Text createDecoratedText(String labelText, int style) { + protected Text createDecoratedText(String value, int style) { + Text text = createTextWithUndo(getWidgetFactory(), composite, value, style); + text.setData(DECORATION_KEY, new ControlDecoration(text, SWT.LEFT | SWT.TOP)); + return text; + } + + /** + * Creates a {@link Text} control which has a {@link ControlDecoration} attached. + * The decoration is stored as widget data for convenience. + */ + protected Text createDecoratedText(String value) { + return createDecoratedText(value, SWT.NONE); + } + + /** + * Creates a form text field, which has a {@link ControlDecoration} attached. + * The decoration is stored as widget data for convenience. + */ + protected Text createDecoratedFormText(String labelText, int style) { Text text = createFormText(labelText, style); text.setData(DECORATION_KEY, new ControlDecoration(text, SWT.LEFT | SWT.TOP)); return text; } /** - * Creates a text widget, which has a {@link ControlDecoration} attached. + * Creates a form text field, which has a {@link ControlDecoration} attached. * The decoration is stored as widget data for convenience. */ - protected Text createDecoratedText(String labelText) { - return createDecoratedText(labelText, SWT.NONE); + protected Text createDecoratedFormText(String labelText) { + return createDecoratedFormText(labelText, SWT.NONE); } /** Creates form text field. */ @@ -294,13 +312,8 @@ public abstract class PropertySectionBase extends AbstractPropertySection { return button; } - /** Creates a form entry. */ + /** Creates a form entry and returns the {@link Label}. */ protected Label createFormEntry(Control control, String labelName) { - return createFormEntryAndReturnLabel(control, labelName); - } - - /** Creates a form entry and return the label */ - protected Label createFormEntryAndReturnLabel(Control control, String labelName) { labelName = labelName.trim(); if(labelName.endsWith(":")) { labelName = labelName.replaceAll(":$", ""); @@ -335,7 +348,7 @@ public abstract class PropertySectionBase extends AbstractPropertySection { * fraction digits to be used in the String representation. */ protected void bindPositiveBigDecimalValue(Control text, IObservableValue<?> observedValue) { - bindBigDecimalValue(text, observedValue, NumberPositiveValidator.INSTANCE); + bindBigDecimalValue(text, observedValue, NUMBER_POSITIVE_VALIDATOR); } /** @@ -344,8 +357,19 @@ public abstract class PropertySectionBase extends AbstractPropertySection { */ protected void bindPositiveBigDecimalValue(Control text, IObservableValue<?> observedValue, int maxFractionDigits) { - bindBigDecimalValue(text, observedValue, NumberPositiveValidator.INSTANCE, - maxFractionDigits); + bindBigDecimalValue(text, observedValue, NUMBER_POSITIVE_VALIDATOR, maxFractionDigits); + } + + /** + * Binds a {@link BigDecimal} value with the default number of a maximum of three fraction + * digits to be used in the String representation. + */ + private void bindBigDecimalValue(Control text, IObservableValue<?> observedValue, + IValidator numberValidator, NumberFormat nf) { + + nf.setGroupingUsed(false); + performComplexTextBinding(dbc, text, observedValue, fromBigDecimal(nf), toBigDecimal(nf), + FLOAT_VALIDATOR, numberValidator); } /** @@ -354,10 +378,9 @@ public abstract class PropertySectionBase extends AbstractPropertySection { */ 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); + + NumberFormat nf = NumberFormat.getNumberInstance(); + bindBigDecimalValue(text, observedValue, numberValidator, nf); } /** @@ -369,10 +392,7 @@ public abstract class PropertySectionBase extends AbstractPropertySection { 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); + bindBigDecimalValue(text, observedValue, numberValidator, nf); } /** @@ -380,7 +400,7 @@ public abstract class PropertySectionBase extends AbstractPropertySection { * to be used in the String representation. */ protected void bindPositiveDoubleValue(Control text, IObservableValue<?> observedValue) { - bindDoubleValue(text, observedValue, NumberPositiveValidator.INSTANCE); + bindDoubleValue(text, observedValue, NUMBER_POSITIVE_VALIDATOR); } /** @@ -389,7 +409,7 @@ public abstract class PropertySectionBase extends AbstractPropertySection { */ protected void bindPositiveDoubleValue(Control text, IObservableValue<?> observedValue, int maxFractionDigits) { - bindDoubleValue(text, observedValue, NumberPositiveValidator.INSTANCE, maxFractionDigits); + bindDoubleValue(text, observedValue, NUMBER_POSITIVE_VALIDATOR, maxFractionDigits); } /** @@ -399,7 +419,7 @@ public abstract class PropertySectionBase extends AbstractPropertySection { protected void bindDoubleValue(Control text, IObservableValue<?> observedValue, IValidator numberValidator) { performComplexTextBinding(dbc, text, observedValue, fromDouble(false), toDouble(false), - TextToDoubleValidator.INSTANCE, numberValidator); + FLOAT_VALIDATOR, numberValidator); } /** @@ -412,18 +432,18 @@ public abstract class PropertySectionBase extends AbstractPropertySection { NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(maxFractionDigits); performComplexTextBinding(dbc, text, observedValue, fromDouble(nf, false), - toDouble(nf, false), TextToDoubleValidator.INSTANCE, numberValidator); + toDouble(nf, false), FLOAT_VALIDATOR, numberValidator); } /** Binds a positive integer value. */ protected void bindPositiveIntegerValue(Control text, IObservableValue<?> observedValue) { - bindIntegerValue(text, observedValue, NumberPositiveValidator.INSTANCE); + bindIntegerValue(text, observedValue, NUMBER_POSITIVE_VALIDATOR); } /** Binds a integer value. */ protected void bindIntegerValue(Control text, IObservableValue<?> observedValue, IValidator numberValidator) { performComplexTextBinding(dbc, text, observedValue, fromInteger(false), toInteger(false), - TextToIntegerValidator.INSTANCE, numberValidator); + INT_VALIDATOR, numberValidator); } } diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/properties/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/properties/.ratings index 2db8f8fa8dbb6b97778224e4ef7a3fb251c2f3f0..c29bdc6ee95d8b6638d10ba2e9619367024ebe87 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/properties/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/properties/.ratings @@ -1,3 +1,3 @@ -IdLabeledPropertySection.java dcfb39d225391c87f47e29f6d1ba1cb22a3d3fe4 GREEN +IdLabeledPropertySection.java 8a360874918ca84a319ae7668011a19cea574148 GREEN NamedCommentedPropertySection.java d4fab618eca361f132b1baafecd66ad8f7919dfa YELLOW PropertiesAdapterFactory.java edcf34766a60f21c9ba22a1ba73aa487c3d9a946 GREEN diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/properties/IdLabeledPropertySection.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/properties/IdLabeledPropertySection.java index dcfb39d225391c87f47e29f6d1ba1cb22a3d3fe4..8a360874918ca84a319ae7668011a19cea574148 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/properties/IdLabeledPropertySection.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/properties/IdLabeledPropertySection.java @@ -46,7 +46,7 @@ public class IdLabeledPropertySection extends PropertySectionBase { super.createControls(parent, aTabbedPropertySheetPage); idText = createFormText("ID"); - idText.setEnabled(false); + idText.setEditable(false); } /** {@inheritDoc} */