diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 805e95d686783b6f719a3b614a64c1b9c264f02f..7145f4049178a7d5dbe5b012ba19a49af6143551 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,11 +1,11 @@ variables: - RELEASE_DIR: "public/release_target_102" + RELEASE_DIR: "public/release_target_110" pages: stage: deploy tags: - docker # use shared runner - image: maven:3.6.3-adoptopenjdk-15 + image: maven:3.6.3-adoptopenjdk-16 script: - mvn --version - mvn clean install # build p2 repo diff --git a/de.hftstuttgart.cityunits.feature/feature.xml b/de.hftstuttgart.cityunits.feature/feature.xml index 648f9210c10de51a322458ec44afc91790d79167..33e749e1521b516b260ca13cc20b96935569bd6b 100644 --- a/de.hftstuttgart.cityunits.feature/feature.xml +++ b/de.hftstuttgart.cityunits.feature/feature.xml @@ -2,14 +2,13 @@ <feature id="de.hftstuttgart.cityunits.feature" label="City Units" - version="1.0.2" + version="1.1.0" provider-name="HfT Stuttgart"> <description url="http://www.example.com/description"> Provides Indriya reference implementation of units of measurement (JSR 385) together with required dependencies and extensions -that introduces Ecore data types for double and long valued units. - +that introduces Ecore data types for double valued units. Certain units relevant to City simulations are also added. </description> @@ -22,24 +21,12 @@ Certain units relevant to City simulations are also added. </license> <requires> - <import plugin="org.eclipse.emf.ecore"/> - <import plugin="org.eclipse.emf.edit" version="2.8.0" match="compatible"/> - <import plugin="org.eclipse.core.runtime" version="3.8.0" match="compatible"/> - <import plugin="org.eclipse.emf.databinding" version="1.3.0" match="compatible"/> - <import plugin="org.eclipse.jface"/> - <import plugin="javax.inject"/> - <import plugin="org.eclipse.emfforms.common"/> - <import plugin="org.eclipse.swt"/> <import plugin="tech.units.indriya" version="2.1.1" match="compatible"/> <import plugin="javax.measure.unit-api" version="2.1.1" match="compatible"/> + <import plugin="org.eclipse.core.runtime" version="3.8.0" match="compatible"/> + <import plugin="org.eclipse.emf.ecore"/> <import plugin="uom-lib-common" version="2.1.0" match="compatible"/> - <import plugin="org.eclipse.emf.ecp.edit.swt" version="1.24.0" match="compatible"/> - <import plugin="org.eclipse.emf.ecp.ui.view.swt" version="1.24.0" match="compatible"/> - <import plugin="org.eclipse.emf.ecp.view.core.swt" version="1.24.0" match="compatible"/> - <import plugin="org.eclipse.emf.ecp.view.template.model" version="1.24.0" match="compatible"/> - <import plugin="org.eclipse.emfforms.core.services.editsupport" version="1.24.0" match="compatible"/> - <import plugin="org.eclipse.emfforms.swt.core.di" version="1.24.0" match="compatible"/> - <import plugin="org.eclipse.emfforms.localization" version="1.24.0" match="compatible"/> + <import plugin="org.eclipse.emf.edit" version="2.8.0" match="compatible"/> </requires> <plugin @@ -49,13 +36,6 @@ Certain units relevant to City simulations are also added. version="0.0.0" unpack="false"/> - <plugin - id="de.hftstuttgart.cityunits.ui.renderer" - download-size="0" - install-size="0" - version="0.0.0" - unpack="false"/> - <plugin id="de.hftstuttgart.cityunits.model.edit" download-size="0" diff --git a/de.hftstuttgart.cityunits.feature/pom.xml b/de.hftstuttgart.cityunits.feature/pom.xml index 17e371faabde130a59403ff7fc075c676a7ba363..6ddbcfd52f3cc65fb180d902c49eee996e2caf8b 100644 --- a/de.hftstuttgart.cityunits.feature/pom.xml +++ b/de.hftstuttgart.cityunits.feature/pom.xml @@ -9,7 +9,7 @@ <parent> <groupId>de.hftstuttgart</groupId> <artifactId>de.hftstuttgart.cityunits</artifactId> - <version>1.0.2</version> + <version>1.1.0</version> </parent> </project> \ No newline at end of file diff --git a/de.hftstuttgart.cityunits.model.edit/.classpath b/de.hftstuttgart.cityunits.model.edit/.classpath index d116359246ee6800ba985bf91b14957149f7db34..b405857762d046f304557814e3acb25a3c08bdc2 100644 --- a/de.hftstuttgart.cityunits.model.edit/.classpath +++ b/de.hftstuttgart.cityunits.model.edit/.classpath @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-15"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src/"/> <classpathentry kind="output" path="target/classes"/> diff --git a/de.hftstuttgart.cityunits.model.edit/META-INF/MANIFEST.MF b/de.hftstuttgart.cityunits.model.edit/META-INF/MANIFEST.MF index 1fefb7254b04ff417797df708e6b3499a90ca574..a1311fc4527f943d51a14f2f8555477d1a322c2d 100644 --- a/de.hftstuttgart.cityunits.model.edit/META-INF/MANIFEST.MF +++ b/de.hftstuttgart.cityunits.model.edit/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: de.hftstuttgart.cityunits.model.edit;singleton:=true Automatic-Module-Name: de.hftstuttgart.cityunits.model.edit -Bundle-Version: 1.0.2 +Bundle-Version: 1.1.0 Bundle-ClassPath: . Bundle-Activator: de.hftstuttgart.cityunits.model.quantities.provider.QuantitiesEditPlugin$Implementation Bundle-Vendor: %providerName @@ -12,4 +12,5 @@ Export-Package: de.hftstuttgart.cityunits.model.quantities.provider Require-Bundle: org.eclipse.core.runtime, de.hftstuttgart.cityunits.model;visibility:=reexport, org.eclipse.emf.edit;visibility:=reexport +Eclipse-LazyStart: true Bundle-ActivationPolicy: lazy diff --git a/de.hftstuttgart.cityunits.model.edit/pom.xml b/de.hftstuttgart.cityunits.model.edit/pom.xml index ac13c6fba986ea026098ce6c290b40ba04ba1667..6fbcf13821f1c999a85cf2fe739f3f3b18942068 100644 --- a/de.hftstuttgart.cityunits.model.edit/pom.xml +++ b/de.hftstuttgart.cityunits.model.edit/pom.xml @@ -11,7 +11,7 @@ <parent> <groupId>de.hftstuttgart</groupId> <artifactId>de.hftstuttgart.cityunits</artifactId> - <version>1.0.2</version> + <version>1.1.0</version> </parent> </project> \ No newline at end of file diff --git a/de.hftstuttgart.cityunits.model/.classpath b/de.hftstuttgart.cityunits.model/.classpath index d116359246ee6800ba985bf91b14957149f7db34..41fde4753fdf7bb5135e9476971f21eacc967700 100644 --- a/de.hftstuttgart.cityunits.model/.classpath +++ b/de.hftstuttgart.cityunits.model/.classpath @@ -1,7 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-15"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16"> + <attributes> + <attribute name="module" value="true"/> + </attributes> + </classpathentry> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="src" path="src/"/> + <classpathentry kind="src" path="src"/> <classpathentry kind="output" path="target/classes"/> </classpath> diff --git a/de.hftstuttgart.cityunits.model/META-INF/MANIFEST.MF b/de.hftstuttgart.cityunits.model/META-INF/MANIFEST.MF index 824f68a1385553f8ddce068ee9593e04fed22f4d..38e163bf5c48e94e44c969197fd2fab0d198c11b 100644 --- a/de.hftstuttgart.cityunits.model/META-INF/MANIFEST.MF +++ b/de.hftstuttgart.cityunits.model/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: de.hftstuttgart.cityunits.model;singleton:=true -Bundle-Version: 1.0.2 +Bundle-Version: 1.1.0 Bundle-ClassPath: . Bundle-Vendor: %providerName Bundle-Localization: plugin @@ -12,6 +12,7 @@ Require-Bundle: tech.units.indriya;bundle-version="[2.1.1,3.0.0)", org.eclipse.core.runtime, org.eclipse.emf.ecore;visibility:=reexport, uom-lib-common;bundle-version="[2.1.0,3.0.0)" +Eclipse-LazyStart: true Bundle-ActivationPolicy: lazy Export-Package: de.hftstuttgart.cityunits.model; uses:="javax.measure, @@ -19,5 +20,4 @@ Export-Package: de.hftstuttgart.cityunits.model; tech.units.indriya", de.hftstuttgart.cityunits.model.quantities; uses:="org.eclipse.emf.ecore", - de.hftstuttgart.cityunits.model.quantities.impl, - de.hftstuttgart.cityunits.model.quantities.util + de.hftstuttgart.cityunits.model.quantities.impl diff --git a/de.hftstuttgart.cityunits.model/model/Quantities.ecore b/de.hftstuttgart.cityunits.model/model/Quantities.ecore index 537a85e9a46d54d52fbde5ad52b7138683516af0..254886aa7d98e0f1659366a85d4cc348dd340226 100644 --- a/de.hftstuttgart.cityunits.model/model/Quantities.ecore +++ b/de.hftstuttgart.cityunits.model/model/Quantities.ecore @@ -1,12 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="quantities" nsURI="https://www.hftstuttgart.de/quantities" nsPrefix="quant"> - <eClassifiers xsi:type="ecore:EDataType" name="QuantityDouble" instanceClassName="de.hftstuttgart.cityunits.model.NullableQuantity"/> - <eClassifiers xsi:type="ecore:EDataType" name="QuantityLong" instanceClassName="de.hftstuttgart.cityunits.model.NullableQuantity"/> - <eClassifiers xsi:type="ecore:EDataType" name="Fraction" instanceClassName="java.lang.Double"> - <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> - <details key="minInclusive" value="0.0"/> - <details key="maxInclusive" value="1.0"/> - </eAnnotations> - </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="Quantity" instanceClassName="de.hftstuttgart.cityunits.model.NullableQuantity"/> </ecore:EPackage> diff --git a/de.hftstuttgart.cityunits.model/model/Quantities.genmodel b/de.hftstuttgart.cityunits.model/model/Quantities.genmodel index 1371397775f31e48bb469e6b5bf1276695ab0713..765791c806a99e8b198cb33141db9285c9f27e0b 100644 --- a/de.hftstuttgart.cityunits.model/model/Quantities.genmodel +++ b/de.hftstuttgart.cityunits.model/model/Quantities.genmodel @@ -2,15 +2,11 @@ <genmodel:GenModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" modelDirectory="/de.hftstuttgart.cityunits.model/src" creationIcons="false" modelPluginID="de.hftstuttgart.cityunits.model" modelName="Quantities" rootExtendsClass="org.eclipse.emf.ecore.impl.MinimalEObjectImpl$Container" - importerID="org.eclipse.emf.importer.ecore" complianceLevel="15.0" copyrightFields="false" - operationReflection="true" importOrganizing="true"> + importerID="org.eclipse.emf.importer.ecore" complianceLevel="11.0" copyrightFields="false" + importOrganizing="true"> <foreignModel>Quantities.ecore</foreignModel> <genPackages prefix="Quantities" basePackage="de.hftstuttgart.cityunits.model" disposableProviderFactory="true" ecorePackage="Quantities.ecore#/"> - <genDataTypes ecoreDataType="Quantities.ecore#//QuantityDouble" create="return de.hftstuttgart.cityunits.model.NullableQuantity.create(it);" - convert="return it == null ? null : it.toString();"/> - <genDataTypes ecoreDataType="Quantities.ecore#//QuantityLong" create="return de.hftstuttgart.cityunits.model.NullableQuantity.create(it);" - convert="return it == null ? null : it.toString();"/> - <genDataTypes ecoreDataType="Quantities.ecore#//Fraction"/> + <genDataTypes ecoreDataType="Quantities.ecore#//Quantity" create="return de.hftstuttgart.cityunits.model.NullableQuantity.create(it);"/> </genPackages> </genmodel:GenModel> diff --git a/de.hftstuttgart.cityunits.model/pom.xml b/de.hftstuttgart.cityunits.model/pom.xml index 7de7acca7c05779a7821dcf9ca34c85737345415..e74dd9e2b7f1def2cb58a6ea05e29468ca652203 100644 --- a/de.hftstuttgart.cityunits.model/pom.xml +++ b/de.hftstuttgart.cityunits.model/pom.xml @@ -9,7 +9,7 @@ <parent> <groupId>de.hftstuttgart</groupId> <artifactId>de.hftstuttgart.cityunits</artifactId> - <version>1.0.2</version> + <version>1.1.0</version> </parent> </project> \ No newline at end of file diff --git a/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/NullableQuantity.java b/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/NullableQuantity.java index 32dd5c0acfccd2195e59d5642aa1e0f2a2d9b7a9..798f73e33e725df093eddcc0baca353dd7e9edd0 100644 --- a/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/NullableQuantity.java +++ b/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/NullableQuantity.java @@ -10,6 +10,7 @@ import javax.measure.Unit; import org.eclipse.core.runtime.Platform; +import tech.units.indriya.AbstractUnit; import tech.units.indriya.format.SimpleQuantityFormat; import tech.units.indriya.quantity.Quantities; @@ -32,25 +33,33 @@ public class NullableQuantity { UrbanSimulationUnits.getInstance(); } - public static NullableQuantity create(String str) { - NullableQuantity newNullableQuantity = null; + public static NullableQuantity create(String quantityString) { + NullableQuantity newNullableQuantity; + Number num = null; + String trimmed = quantityString.trim(); try { - NumberFormat.getInstance().parse(str); - newNullableQuantity = new NullableQuantity(str); - } catch (final ParseException ex) { // no number value present: create NullQuantity just with unit + num = NumberFormat.getInstance().parse(trimmed); + newNullableQuantity = new NullableQuantity(trimmed); + } catch (final ParseException ex) { + // no number value present: create NullQuantity just with unit try { - NullableQuantity dummy = new NullableQuantity("1 " + str); //$NON-NLS-1$ + NullableQuantity dummy = new NullableQuantity("1 " + trimmed); //$NON-NLS-1$ newNullableQuantity = new NullQuantity(dummy.getUnit()); - } catch (final IllegalArgumentException ex1) { // Unit could not be parsed - Platform.getLog(NullableQuantity.class).warn("Unit '" + str + "' could not be parsed!", ex); + } catch (final IllegalArgumentException ex1) { + // number and unit could not be parsed: default to dimensionless null quantity + newNullableQuantity = new NullQuantity(AbstractUnit.ONE); } } catch (final IllegalArgumentException ex) { // Quantity could not be parsed - Platform.getLog(NullableQuantity.class).warn("Quantity '" + str + "' could not be parsed!", ex); + // unit could not be parsed: default to dimensionless quantity + newNullableQuantity = create(num, AbstractUnit.ONE); } return newNullableQuantity; } public static NullableQuantity create(Number number, Unit<?> unit) { + if (unit == null) { + unit = AbstractUnit.ONE; + } return number == null ? new NullQuantity(unit) : new NullableQuantity(number, unit); } @@ -80,7 +89,7 @@ public class NullableQuantity { } public Unit<?> getUnit() { - return quantity.getUnit(); + return quantity.getUnit(); // AbstractUnit.ONE is just omitted } @Override @@ -100,7 +109,7 @@ public class NullableQuantity { @Override public String toString() { - return "<unknown> " + getUnit().toString(); + return getUnit() == AbstractUnit.ONE ? "" : getUnit().toString(); } } } diff --git a/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/quantities/QuantitiesPackage.java b/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/quantities/QuantitiesPackage.java index 04ece655807e73cac353fba3da026b16f69f70c7..73bea74e15eae3301e71d557c025adb429c48de2 100644 --- a/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/quantities/QuantitiesPackage.java +++ b/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/quantities/QuantitiesPackage.java @@ -55,70 +55,26 @@ public interface QuantitiesPackage extends EPackage { QuantitiesPackage eINSTANCE = de.hftstuttgart.cityunits.model.quantities.impl.QuantitiesPackageImpl.init(); /** - * The meta object id for the '<em>Quantity Double</em>' data type. + * The meta object id for the '<em>Quantity</em>' data type. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see de.hftstuttgart.cityunits.model.NullableQuantity - * @see de.hftstuttgart.cityunits.model.quantities.impl.QuantitiesPackageImpl#getQuantityDouble() + * @see de.hftstuttgart.cityunits.model.quantities.impl.QuantitiesPackageImpl#getQuantity() * @generated */ - int QUANTITY_DOUBLE = 0; - - /** - * The meta object id for the '<em>Quantity Long</em>' data type. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @see de.hftstuttgart.cityunits.model.NullableQuantity - * @see de.hftstuttgart.cityunits.model.quantities.impl.QuantitiesPackageImpl#getQuantityLong() - * @generated - */ - int QUANTITY_LONG = 1; + int QUANTITY = 0; /** - * The meta object id for the '<em>Fraction</em>' data type. + * Returns the meta object for data type '{@link de.hftstuttgart.cityunits.model.NullableQuantity <em>Quantity</em>}'. * <!-- begin-user-doc --> * <!-- end-user-doc --> - * @see java.lang.Double - * @see de.hftstuttgart.cityunits.model.quantities.impl.QuantitiesPackageImpl#getFraction() - * @generated - */ - int FRACTION = 2; - - - /** - * Returns the meta object for data type '{@link de.hftstuttgart.cityunits.model.NullableQuantity <em>Quantity Double</em>}'. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @return the meta object for data type '<em>Quantity Double</em>'. + * @return the meta object for data type '<em>Quantity</em>'. * @see de.hftstuttgart.cityunits.model.NullableQuantity * @model instanceClass="de.hftstuttgart.cityunits.model.NullableQuantity" * @generated */ - EDataType getQuantityDouble(); - - /** - * Returns the meta object for data type '{@link de.hftstuttgart.cityunits.model.NullableQuantity <em>Quantity Long</em>}'. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @return the meta object for data type '<em>Quantity Long</em>'. - * @see de.hftstuttgart.cityunits.model.NullableQuantity - * @model instanceClass="de.hftstuttgart.cityunits.model.NullableQuantity" - * @generated - */ - EDataType getQuantityLong(); - - /** - * Returns the meta object for data type '{@link java.lang.Double <em>Fraction</em>}'. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @return the meta object for data type '<em>Fraction</em>'. - * @see java.lang.Double - * @model instanceClass="java.lang.Double" - * extendedMetaData="minInclusive='0.0' maxInclusive='1.0'" - * @generated - */ - EDataType getFraction(); + EDataType getQuantity(); /** * Returns the factory that creates the instances of the model. @@ -144,34 +100,14 @@ public interface QuantitiesPackage extends EPackage { */ interface Literals { /** - * The meta object literal for the '<em>Quantity Double</em>' data type. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @see de.hftstuttgart.cityunits.model.NullableQuantity - * @see de.hftstuttgart.cityunits.model.quantities.impl.QuantitiesPackageImpl#getQuantityDouble() - * @generated - */ - EDataType QUANTITY_DOUBLE = eINSTANCE.getQuantityDouble(); - - /** - * The meta object literal for the '<em>Quantity Long</em>' data type. + * The meta object literal for the '<em>Quantity</em>' data type. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see de.hftstuttgart.cityunits.model.NullableQuantity - * @see de.hftstuttgart.cityunits.model.quantities.impl.QuantitiesPackageImpl#getQuantityLong() - * @generated - */ - EDataType QUANTITY_LONG = eINSTANCE.getQuantityLong(); - - /** - * The meta object literal for the '<em>Fraction</em>' data type. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @see java.lang.Double - * @see de.hftstuttgart.cityunits.model.quantities.impl.QuantitiesPackageImpl#getFraction() + * @see de.hftstuttgart.cityunits.model.quantities.impl.QuantitiesPackageImpl#getQuantity() * @generated */ - EDataType FRACTION = eINSTANCE.getFraction(); + EDataType QUANTITY = eINSTANCE.getQuantity(); } diff --git a/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/quantities/impl/QuantitiesFactoryImpl.java b/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/quantities/impl/QuantitiesFactoryImpl.java index 77208bfb433eae8df4bf0cc6cd8acedd69cb0e2b..61b140417e40251a9519644989c4870376e3a056 100644 --- a/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/quantities/impl/QuantitiesFactoryImpl.java +++ b/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/quantities/impl/QuantitiesFactoryImpl.java @@ -71,12 +71,8 @@ public class QuantitiesFactoryImpl extends EFactoryImpl implements QuantitiesFac @Override public Object createFromString(EDataType eDataType, String initialValue) { switch (eDataType.getClassifierID()) { - case QuantitiesPackage.QUANTITY_DOUBLE: - return createQuantityDoubleFromString(eDataType, initialValue); - case QuantitiesPackage.QUANTITY_LONG: - return createQuantityLongFromString(eDataType, initialValue); - case QuantitiesPackage.FRACTION: - return createFractionFromString(eDataType, initialValue); + case QuantitiesPackage.QUANTITY: + return createQuantityFromString(eDataType, initialValue); default: throw new IllegalArgumentException("The datatype '" + eDataType.getName() + "' is not a valid classifier"); } @@ -90,12 +86,8 @@ public class QuantitiesFactoryImpl extends EFactoryImpl implements QuantitiesFac @Override public String convertToString(EDataType eDataType, Object instanceValue) { switch (eDataType.getClassifierID()) { - case QuantitiesPackage.QUANTITY_DOUBLE: - return convertQuantityDoubleToString(eDataType, instanceValue); - case QuantitiesPackage.QUANTITY_LONG: - return convertQuantityLongToString(eDataType, instanceValue); - case QuantitiesPackage.FRACTION: - return convertFractionToString(eDataType, instanceValue); + case QuantitiesPackage.QUANTITY: + return convertQuantityToString(eDataType, instanceValue); default: throw new IllegalArgumentException("The datatype '" + eDataType.getName() + "' is not a valid classifier"); } @@ -106,7 +98,7 @@ public class QuantitiesFactoryImpl extends EFactoryImpl implements QuantitiesFac * <!-- end-user-doc --> * @generated */ - public NullableQuantity createQuantityDouble(final String it) { + public NullableQuantity createQuantity(final String it) { return de.hftstuttgart.cityunits.model.NullableQuantity.create(it); } @@ -115,8 +107,8 @@ public class QuantitiesFactoryImpl extends EFactoryImpl implements QuantitiesFac * <!-- end-user-doc --> * @generated */ - public NullableQuantity createQuantityDoubleFromString(EDataType eDataType, String initialValue) { - return createQuantityDouble(initialValue); + public NullableQuantity createQuantityFromString(EDataType eDataType, String initialValue) { + return createQuantity(initialValue); } /** @@ -124,70 +116,7 @@ public class QuantitiesFactoryImpl extends EFactoryImpl implements QuantitiesFac * <!-- end-user-doc --> * @generated */ - public String convertQuantityDouble(final NullableQuantity it) { - return it == null ? null : it.toString(); - } - - /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - public String convertQuantityDoubleToString(EDataType eDataType, Object instanceValue) { - return convertQuantityDouble((NullableQuantity)instanceValue); - } - - /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - public NullableQuantity createQuantityLong(final String it) { - return de.hftstuttgart.cityunits.model.NullableQuantity.create(it); - } - - /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - public NullableQuantity createQuantityLongFromString(EDataType eDataType, String initialValue) { - return createQuantityLong(initialValue); - } - - /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - public String convertQuantityLong(final NullableQuantity it) { - return it == null ? null : it.toString(); - } - - /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - public String convertQuantityLongToString(EDataType eDataType, Object instanceValue) { - return convertQuantityLong((NullableQuantity)instanceValue); - } - - /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - public Double createFractionFromString(EDataType eDataType, String initialValue) { - return (Double)super.createFromString(eDataType, initialValue); - } - - /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - public String convertFractionToString(EDataType eDataType, Object instanceValue) { + public String convertQuantityToString(EDataType eDataType, Object instanceValue) { return super.convertToString(eDataType, instanceValue); } diff --git a/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/quantities/impl/QuantitiesPackageImpl.java b/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/quantities/impl/QuantitiesPackageImpl.java index a030ec985def3f8ebfa0a68b48ad1ff421d80c55..4fa3ed1a3d85bdcbfdd0d44653b04aa131646b28 100644 --- a/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/quantities/impl/QuantitiesPackageImpl.java +++ b/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/quantities/impl/QuantitiesPackageImpl.java @@ -5,12 +5,8 @@ package de.hftstuttgart.cityunits.model.quantities.impl; import de.hftstuttgart.cityunits.model.NullableQuantity; import de.hftstuttgart.cityunits.model.quantities.QuantitiesFactory; import de.hftstuttgart.cityunits.model.quantities.QuantitiesPackage; - -import de.hftstuttgart.cityunits.model.quantities.util.QuantitiesValidator; import org.eclipse.emf.ecore.EDataType; import org.eclipse.emf.ecore.EPackage; - -import org.eclipse.emf.ecore.EValidator; import org.eclipse.emf.ecore.impl.EPackageImpl; /** @@ -25,21 +21,7 @@ public class QuantitiesPackageImpl extends EPackageImpl implements QuantitiesPac * <!-- end-user-doc --> * @generated */ - private EDataType quantityDoubleEDataType = null; - - /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - private EDataType quantityLongEDataType = null; - - /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - private EDataType fractionEDataType = null; + private EDataType quantityEDataType = null; /** * Creates an instance of the model <b>Package</b>, registered with @@ -94,16 +76,6 @@ public class QuantitiesPackageImpl extends EPackageImpl implements QuantitiesPac // Initialize created meta-data theQuantitiesPackage.initializePackageContents(); - // Register package validator - EValidator.Registry.INSTANCE.put - (theQuantitiesPackage, - new EValidator.Descriptor() { - @Override - public EValidator getEValidator() { - return QuantitiesValidator.INSTANCE; - } - }); - // Mark meta-data to indicate it can't be changed theQuantitiesPackage.freeze(); @@ -118,28 +90,8 @@ public class QuantitiesPackageImpl extends EPackageImpl implements QuantitiesPac * @generated */ @Override - public EDataType getQuantityDouble() { - return quantityDoubleEDataType; - } - - /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - @Override - public EDataType getQuantityLong() { - return quantityLongEDataType; - } - - /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - @Override - public EDataType getFraction() { - return fractionEDataType; + public EDataType getQuantity() { + return quantityEDataType; } /** @@ -171,9 +123,7 @@ public class QuantitiesPackageImpl extends EPackageImpl implements QuantitiesPac isCreated = true; // Create data types - quantityDoubleEDataType = createEDataType(QUANTITY_DOUBLE); - quantityLongEDataType = createEDataType(QUANTITY_LONG); - fractionEDataType = createEDataType(FRACTION); + quantityEDataType = createEDataType(QUANTITY); } /** @@ -200,33 +150,10 @@ public class QuantitiesPackageImpl extends EPackageImpl implements QuantitiesPac setNsURI(eNS_URI); // Initialize data types - initEDataType(quantityDoubleEDataType, NullableQuantity.class, "QuantityDouble", IS_SERIALIZABLE, !IS_GENERATED_INSTANCE_CLASS); - initEDataType(quantityLongEDataType, NullableQuantity.class, "QuantityLong", IS_SERIALIZABLE, !IS_GENERATED_INSTANCE_CLASS); - initEDataType(fractionEDataType, Double.class, "Fraction", IS_SERIALIZABLE, !IS_GENERATED_INSTANCE_CLASS); + initEDataType(quantityEDataType, NullableQuantity.class, "Quantity", IS_SERIALIZABLE, !IS_GENERATED_INSTANCE_CLASS); // Create resource createResource(eNS_URI); - - // Create annotations - // http:///org/eclipse/emf/ecore/util/ExtendedMetaData - createExtendedMetaDataAnnotations(); - } - - /** - * Initializes the annotations for <b>http:///org/eclipse/emf/ecore/util/ExtendedMetaData</b>. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - protected void createExtendedMetaDataAnnotations() { - String source = "http:///org/eclipse/emf/ecore/util/ExtendedMetaData"; - addAnnotation - (fractionEDataType, - source, - new String[] { - "minInclusive", "0.0", - "maxInclusive", "1.0" - }); } } //QuantitiesPackageImpl diff --git a/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/quantities/util/QuantitiesValidator.java b/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/quantities/util/QuantitiesValidator.java deleted file mode 100644 index a79b6bf8ea17790153e8592b1eb4cc3bd05b2cb4..0000000000000000000000000000000000000000 --- a/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/quantities/util/QuantitiesValidator.java +++ /dev/null @@ -1,186 +0,0 @@ -/** - */ -package de.hftstuttgart.cityunits.model.quantities.util; - -import de.hftstuttgart.cityunits.model.NullableQuantity; - -import de.hftstuttgart.cityunits.model.quantities.*; - -import java.util.Map; - -import org.eclipse.emf.common.util.DiagnosticChain; -import org.eclipse.emf.common.util.ResourceLocator; - -import org.eclipse.emf.ecore.EPackage; - -import org.eclipse.emf.ecore.util.EObjectValidator; - -/** - * <!-- begin-user-doc --> - * The <b>Validator</b> for the model. - * <!-- end-user-doc --> - * @see de.hftstuttgart.cityunits.model.quantities.QuantitiesPackage - * @generated - */ -public class QuantitiesValidator extends EObjectValidator { - /** - * The cached model package - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - public static final QuantitiesValidator INSTANCE = new QuantitiesValidator(); - - /** - * A constant for the {@link org.eclipse.emf.common.util.Diagnostic#getSource() source} of diagnostic {@link org.eclipse.emf.common.util.Diagnostic#getCode() codes} from this package. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @see org.eclipse.emf.common.util.Diagnostic#getSource() - * @see org.eclipse.emf.common.util.Diagnostic#getCode() - * @generated - */ - public static final String DIAGNOSTIC_SOURCE = "de.hftstuttgart.cityunits.model.quantities"; - - /** - * A constant with a fixed name that can be used as the base value for additional hand written constants. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - private static final int GENERATED_DIAGNOSTIC_CODE_COUNT = 0; - - /** - * A constant with a fixed name that can be used as the base value for additional hand written constants in a derived class. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - protected static final int DIAGNOSTIC_CODE_COUNT = GENERATED_DIAGNOSTIC_CODE_COUNT; - - /** - * Creates an instance of the switch. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - public QuantitiesValidator() { - super(); - } - - /** - * Returns the package of this validator switch. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - @Override - protected EPackage getEPackage() { - return QuantitiesPackage.eINSTANCE; - } - - /** - * Calls <code>validateXXX</code> for the corresponding classifier of the model. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - @Override - protected boolean validate(int classifierID, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) { - switch (classifierID) { - case QuantitiesPackage.QUANTITY_DOUBLE: - return validateQuantityDouble((NullableQuantity)value, diagnostics, context); - case QuantitiesPackage.QUANTITY_LONG: - return validateQuantityLong((NullableQuantity)value, diagnostics, context); - case QuantitiesPackage.FRACTION: - return validateFraction((Double)value, diagnostics, context); - default: - return true; - } - } - - /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - public boolean validateQuantityDouble(NullableQuantity quantityDouble, DiagnosticChain diagnostics, Map<Object, Object> context) { - return true; - } - - /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - public boolean validateQuantityLong(NullableQuantity quantityLong, DiagnosticChain diagnostics, Map<Object, Object> context) { - return true; - } - - /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - public boolean validateFraction(Double fraction, DiagnosticChain diagnostics, Map<Object, Object> context) { - boolean result = validateFraction_Min(fraction, diagnostics, context); - if (result || diagnostics != null) result &= validateFraction_Max(fraction, diagnostics, context); - return result; - } - - /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - * @see #validateFraction_Min - */ - public static final Double FRACTION__MIN__VALUE = Double.valueOf(0.0); - - /** - * Validates the Min constraint of '<em>Fraction</em>'. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - public boolean validateFraction_Min(Double fraction, DiagnosticChain diagnostics, Map<Object, Object> context) { - boolean result = fraction.compareTo(FRACTION__MIN__VALUE) >= 0; - if (!result && diagnostics != null) - reportMinViolation(QuantitiesPackage.Literals.FRACTION, fraction, FRACTION__MIN__VALUE, true, diagnostics, context); - return result; - } - - /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - * @see #validateFraction_Max - */ - public static final Double FRACTION__MAX__VALUE = Double.valueOf(1.0); - - /** - * Validates the Max constraint of '<em>Fraction</em>'. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - public boolean validateFraction_Max(Double fraction, DiagnosticChain diagnostics, Map<Object, Object> context) { - boolean result = fraction.compareTo(FRACTION__MAX__VALUE) <= 0; - if (!result && diagnostics != null) - reportMaxViolation(QuantitiesPackage.Literals.FRACTION, fraction, FRACTION__MAX__VALUE, true, diagnostics, context); - return result; - } - - /** - * Returns the resource locator that will be used to fetch messages for this validator's diagnostics. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @generated - */ - @Override - public ResourceLocator getResourceLocator() { - // TODO - // Specialize this to return a resource locator for messages specific to this validator. - // Ensure that you remove @generated or mark it @generated NOT - return super.getResourceLocator(); - } - -} //QuantitiesValidator diff --git a/de.hftstuttgart.cityunits.p2site/pom.xml b/de.hftstuttgart.cityunits.p2site/pom.xml index 4f4285e76ad9766c51f8b4cee32ab1ea1ce8f14f..edf3266fb855f76b34ef4b290569a31627f6ebc4 100644 --- a/de.hftstuttgart.cityunits.p2site/pom.xml +++ b/de.hftstuttgart.cityunits.p2site/pom.xml @@ -3,9 +3,10 @@ <artifactId>de.hftstuttgart.cityunits.p2site</artifactId> <packaging>eclipse-repository</packaging> <name>City Units P2 Site Generation</name> + <parent> <groupId>de.hftstuttgart</groupId> <artifactId>de.hftstuttgart.cityunits</artifactId> - <version>1.0.2</version> + <version>1.1.0</version> </parent> </project> \ No newline at end of file diff --git a/de.hftstuttgart.cityunits.p2site/site.xml b/de.hftstuttgart.cityunits.p2site/site.xml index c511614cf8fa5f11b6b450599a79bb266f473726..570d4a593e34fb4c53d32c53bc2f5799596b5648 100644 --- a/de.hftstuttgart.cityunits.p2site/site.xml +++ b/de.hftstuttgart.cityunits.p2site/site.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <site> - <feature url="features/de.hftstuttgart.cityunits.feature_1.0.2.jar" id="de.hftstuttgart.cityunits.feature" version="1.0.2"> + <feature url="features/de.hftstuttgart.cityunits.feature_1.1.0.jar" id="de.hftstuttgart.cityunits.feature" version="1.1.0"> <category name="de.hftstuttgart.cityunits"/> </feature> <category-def name="de.hftstuttgart.cityunits" label="HfT Stuttgart City Units"> diff --git a/de.hftstuttgart.cityunits.target/HowToDefineTargetPlatform.md b/de.hftstuttgart.cityunits.target/HowToDefineTargetPlatform.md index acadbc322f08950d87d60fa9c65359f24ba85b5e..ce2b82d3001d4a1209bb6e1c4bffcee95e62cf7b 100644 --- a/de.hftstuttgart.cityunits.target/HowToDefineTargetPlatform.md +++ b/de.hftstuttgart.cityunits.target/HowToDefineTargetPlatform.md @@ -2,7 +2,7 @@ Create new or edit old `.target` file. -In Target Definition editor add target definition file and add add six features from four P2 sites: +In Target Definition editor add target definition file and add six features from four P2 sites: * From the site for latest Eclipse release, e.g. `http://download.eclipse.org/releases/2020-12` add: `Eclipse RT Target Platform Components -> Equinox Target Components` and `General Purpose Tools -> Eclipse e4 Tools Developer Resources`. * From the site for latest Orbit release, e.g. `https://download.eclipse.org/tools/orbit/downloads/2020-12/` add: `JUnit` and `JUnit Jupiter API` from category `Orbit Bundles By Scope: Testing`. diff --git a/de.hftstuttgart.cityunits.target/cityunits.target.target b/de.hftstuttgart.cityunits.target/cityunits.target.target index bcb575e45d0d6eb562f7eee15cf40b0679796a15..f92425d0a69a094b2e4805ec538ef8a1a4030bd6 100644 --- a/de.hftstuttgart.cityunits.target/cityunits.target.target +++ b/de.hftstuttgart.cityunits.target/cityunits.target.target @@ -18,7 +18,6 @@ </location> <location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="false" type="InstallableUnit"> <repository location="http://download.eclipse.org/ecp/releases/releases_target_125/"/> - <unit id="org.eclipse.emf.ecp.emfforms.sdk.feature.feature.group" version="1.25.0.20200916-0800"/> </location> </locations> </target> \ No newline at end of file diff --git a/de.hftstuttgart.cityunits.target/pom.xml b/de.hftstuttgart.cityunits.target/pom.xml index 5412a8a83be2e34aeb220fa9b6a1eca7bc5eb019..e2006e66ab4751daff26960162741b8db4396df0 100644 --- a/de.hftstuttgart.cityunits.target/pom.xml +++ b/de.hftstuttgart.cityunits.target/pom.xml @@ -9,7 +9,7 @@ <parent> <groupId>de.hftstuttgart</groupId> <artifactId>de.hftstuttgart.cityunits</artifactId> - <version>1.0.2</version> + <version>1.1.0</version> </parent> </project> \ No newline at end of file diff --git a/de.hftstuttgart.cityunits.tests/.classpath b/de.hftstuttgart.cityunits.tests/.classpath index 130799695e1630a3df54346636c73fff54c56c35..0850a94735c593a64d0d0e5cb8d3cd514d61aa5c 100644 --- a/de.hftstuttgart.cityunits.tests/.classpath +++ b/de.hftstuttgart.cityunits.tests/.classpath @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-15"> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16"> <attributes> <attribute name="maven.pomderived" value="true"/> </attributes> diff --git a/de.hftstuttgart.cityunits.tests/META-INF/MANIFEST.MF b/de.hftstuttgart.cityunits.tests/META-INF/MANIFEST.MF index c7cbb5f3d7af421300fae0ec72ae5ea62969a7d8..4842d96f810e0e06a6cdb145c2cc487eb41c3d73 100644 --- a/de.hftstuttgart.cityunits.tests/META-INF/MANIFEST.MF +++ b/de.hftstuttgart.cityunits.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Tests Bundle-SymbolicName: de.hftstuttgart.cityunits.tests -Bundle-Version: 1.0.2 +Bundle-Version: 1.1.0 Automatic-Module-Name: de.hft.stuttgart.cityunits.tests Import-Package: de.hftstuttgart.cityunits.model, org.junit;version="4.13.0", diff --git a/de.hftstuttgart.cityunits.tests/pom.xml b/de.hftstuttgart.cityunits.tests/pom.xml index ea290f5478979da90c677a8bf08191d417a7640d..36d49944cd4f3d934e5bf4b67ce58a58046faecd 100644 --- a/de.hftstuttgart.cityunits.tests/pom.xml +++ b/de.hftstuttgart.cityunits.tests/pom.xml @@ -9,7 +9,7 @@ <parent> <groupId>de.hftstuttgart</groupId> <artifactId>de.hftstuttgart.cityunits</artifactId> - <version>1.0.2</version> + <version>1.1.0</version> </parent> </project> \ No newline at end of file diff --git a/de.hftstuttgart.cityunits.tests/src/de/hftstuttgart/cityunits/tests/QuantityTest.java b/de.hftstuttgart.cityunits.tests/src/de/hftstuttgart/cityunits/tests/QuantityTest.java index 3ac669ef457ec59b93c6731dca8cab821b7df70e..0312b15e346a5205e7eb95f91aa271b2ffa981b5 100644 --- a/de.hftstuttgart.cityunits.tests/src/de/hftstuttgart/cityunits/tests/QuantityTest.java +++ b/de.hftstuttgart.cityunits.tests/src/de/hftstuttgart/cityunits/tests/QuantityTest.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.*; import java.util.Locale; import java.util.Locale.Category; +import java.util.Optional; import javax.measure.Quantity; import javax.measure.Unit; @@ -15,7 +16,9 @@ import org.junit.jupiter.api.Test; import de.hftstuttgart.cityunits.model.CarbonEmission; import de.hftstuttgart.cityunits.model.VolumetricFlowRate; import de.hftstuttgart.cityunits.model.Intensity; +import de.hftstuttgart.cityunits.model.NullableQuantity; import de.hftstuttgart.cityunits.model.UrbanSimulationUnits; +import tech.units.indriya.AbstractUnit; import tech.units.indriya.quantity.Quantities; import tech.units.indriya.unit.Units; @@ -92,4 +95,45 @@ class QuantityTest { assertTrue(q.isEquivalentTo(Quantities.getQuantity((String) "5.2007 tonCOâ‚‚eq").asType(CarbonEmission.class)), "Wrong conversion from kg of COâ‚‚eq to ton of COâ‚‚eq!"); } + + @Test + void testFallbackUnit() { + NullableQuantity q = NullableQuantity.create("99 Luftballons"); + assertEquals("one", q.getUnit().toString(), "Wrong Unit!"); + assertEquals(99, q.getNumber().get(), "Wrong Number!"); + } + + @Test + void testDimensionless() { + NullableQuantity q = NullableQuantity.create("2.19"); + assertEquals("one", q.getUnit().toString(), "Wrong Unit!"); + assertEquals(2.19, q.getNumber().get(), "Wrong Number!"); + + q = NullableQuantity.create("97 "); + assertEquals("one", q.getUnit().toString(), "Wrong Unit!"); + assertEquals(97, q.getNumber().get(), "Wrong Number!"); + } + + @Test + void testMissingValue() { + NullableQuantity q = NullableQuantity.create("kg"); + assertEquals("kg", q.getUnit().toString(), "Wrong Unit!"); + assertEquals(Optional.empty(), q.getNumber(), "Number not empty!"); + + q = NullableQuantity.create(" m "); + assertEquals(Units.METRE, q.getUnit(), "Wrong Unit!"); + assertEquals(Optional.empty(), q.getNumber(), "Number not empty!"); + } + + @Test + void testMissingValueAndUnit() { + NullableQuantity q = NullableQuantity.create(""); + assertEquals(AbstractUnit.ONE, q.getUnit(), "Wrong Unit!"); + assertEquals(Optional.empty(), q.getNumber(), "Number not empty!"); + + q = NullableQuantity.create(" "); + assertEquals(AbstractUnit.ONE, q.getUnit(), "Wrong Unit!"); + assertEquals(Optional.empty(), q.getNumber(), "Number not empty!"); + } + } diff --git a/de.hftstuttgart.cityunits.ui.renderer/.classpath b/de.hftstuttgart.cityunits.ui.renderer/.classpath deleted file mode 100644 index f5ef1792a59e6de6676b179a830f4eee417366cc..0000000000000000000000000000000000000000 --- a/de.hftstuttgart.cityunits.ui.renderer/.classpath +++ /dev/null @@ -1,11 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-15"> - <attributes> - <attribute name="module" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="src" path="src/"/> - <classpathentry kind="output" path="target/classes"/> -</classpath> diff --git a/de.hftstuttgart.cityunits.ui.renderer/.project b/de.hftstuttgart.cityunits.ui.renderer/.project deleted file mode 100644 index 593ecce63fedd81d4e436bea9dd1f0c7b130e4a1..0000000000000000000000000000000000000000 --- a/de.hftstuttgart.cityunits.ui.renderer/.project +++ /dev/null @@ -1,39 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>de.hftstuttgart.cityunits.ui.renderer</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.ManifestBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.SchemaBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.ds.core.builder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.m2e.core.maven2Builder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.m2e.core.maven2Nature</nature> - <nature>org.eclipse.pde.PluginNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> diff --git a/de.hftstuttgart.cityunits.ui.renderer/META-INF/MANIFEST.MF b/de.hftstuttgart.cityunits.ui.renderer/META-INF/MANIFEST.MF deleted file mode 100644 index 7549dc24147cf015c6e5d1fc29d3eec08f85b6a1..0000000000000000000000000000000000000000 --- a/de.hftstuttgart.cityunits.ui.renderer/META-INF/MANIFEST.MF +++ /dev/null @@ -1,28 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: QuantityControl -Bundle-SymbolicName: de.hftstuttgart.cityunits.ui.renderer;singleton:=true -Bundle-Version: 1.0.2 -Bundle-Vendor: HfT Stuttgart -Export-Package: de.hftstuttgart.cityunits.ui.renderer;version="1.0.2" -Require-Bundle: de.hftstuttgart.cityunits.model;bundle-version="1.0.2", - org.eclipse.emf.ecp.edit.swt;bundle-version="[1.24.0,2.0.0)", - org.eclipse.emf.ecp.ui.view.swt;bundle-version="[1.24.0,2.0.0)", - org.eclipse.emf.ecp.view.core.swt;bundle-version="[1.24.0,2.0.0)", - org.eclipse.emf.ecp.view.template.model;bundle-version="[1.24.0,2.0.0)", - org.eclipse.emf.edit;bundle-version="[2.8.0,3.0.0)", - org.eclipse.core.runtime;bundle-version="[3.8.0,4.0.0)", - org.eclipse.emfforms.core.services.editsupport;bundle-version="[1.24.0,2.0.0)", - org.eclipse.emf.databinding;bundle-version="[1.3.0,2.0.0)", - org.eclipse.emfforms.swt.core.di;bundle-version="[1.24.0,2.0.0)", - org.eclipse.emfforms.localization;bundle-version="[1.24.0,2.0.0)", - org.eclipse.jface;bundle-version="0.0.0", - javax.measure.unit-api;bundle-version="[2.1.1,3.0.0)" -Service-Component: OSGI-INF/quantityRendererService.xml -Bundle-ActivationPolicy: lazy -Import-Package: javax.inject;version="1.0.0", - org.eclipse.emfforms.spi.common.report;version="[1.24.0, 2.0.0)", - org.eclipse.jface.layout;version="0.0.0", - org.eclipse.swt;version="0.0.0", - org.eclipse.swt.widgets;version="0.0.0" -Automatic-Module-Name: de.hftstuttgart.units.ui.eclipse.quantityrenderer diff --git a/de.hftstuttgart.cityunits.ui.renderer/OSGI-INF/quantityRendererService.xml b/de.hftstuttgart.cityunits.ui.renderer/OSGI-INF/quantityRendererService.xml deleted file mode 100644 index 14c25c48f558b7d3bb7cf17c7a42914ede395f73..0000000000000000000000000000000000000000 --- a/de.hftstuttgart.cityunits.ui.renderer/OSGI-INF/quantityRendererService.xml +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="de.hftstuttgart.units.ui.rendererservice"> - <implementation class="de.hftstuttgart.cityunits.ui.renderer.QuantityControlRendererService"/> - <service> - <provide interface="org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService"/> - </service> - <reference bind="setEMFFormsDatabinding" cardinality="1..1" interface="org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding" name="EMFFormsDatabinding" policy="static"/> - <reference bind="setReportService" cardinality="1..1" interface="org.eclipse.emfforms.spi.common.report.ReportService" name="ReportService" policy="static"/> -</scr:component> diff --git a/de.hftstuttgart.cityunits.ui.renderer/build.properties b/de.hftstuttgart.cityunits.ui.renderer/build.properties deleted file mode 100644 index 6210e849b591d26fa9e17057ad3e8d09511917b6..0000000000000000000000000000000000000000 --- a/de.hftstuttgart.cityunits.ui.renderer/build.properties +++ /dev/null @@ -1,5 +0,0 @@ -output.. = bin/ -bin.includes = META-INF/,\ - .,\ - OSGI-INF/ -source.. = src/ diff --git a/de.hftstuttgart.cityunits.ui.renderer/pom.xml b/de.hftstuttgart.cityunits.ui.renderer/pom.xml deleted file mode 100644 index 7b5138b3c1b1d833fe3a80465f2f03612cde6735..0000000000000000000000000000000000000000 --- a/de.hftstuttgart.cityunits.ui.renderer/pom.xml +++ /dev/null @@ -1,14 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <artifactId>de.hftstuttgart.cityunits.ui.renderer</artifactId> - <packaging>eclipse-plugin</packaging> - <name>City Units SWT Renderer</name> - - <parent> - <groupId>de.hftstuttgart</groupId> - <artifactId>de.hftstuttgart.cityunits</artifactId> - <version>1.0.2</version> - </parent> -</project> \ No newline at end of file diff --git a/de.hftstuttgart.cityunits.ui.renderer/src/de/hftstuttgart/cityunits/ui/renderer/QuantityControlRenderer.java b/de.hftstuttgart.cityunits.ui.renderer/src/de/hftstuttgart/cityunits/ui/renderer/QuantityControlRenderer.java deleted file mode 100644 index 491193e2c6e24f331564b75cbec5f1db53e13e57..0000000000000000000000000000000000000000 --- a/de.hftstuttgart.cityunits.ui.renderer/src/de/hftstuttgart/cityunits/ui/renderer/QuantityControlRenderer.java +++ /dev/null @@ -1,374 +0,0 @@ -package de.hftstuttgart.cityunits.ui.renderer; - -import java.math.BigInteger; -import java.text.DecimalFormat; -import java.text.ParseException; -import java.text.ParsePosition; - -import javax.inject.Inject; -import javax.measure.Unit; - -import org.eclipse.core.databinding.Binding; -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.UpdateValueStrategy; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecp.edit.internal.swt.controls.NumericalHelper; -import org.eclipse.emf.ecp.edit.spi.swt.util.ECPDialogExecutor; -import org.eclipse.emf.ecp.view.internal.core.swt.MessageKeys; -import org.eclipse.emf.ecp.view.spi.context.ViewModelContext; -import org.eclipse.emf.ecp.view.spi.core.swt.renderer.TextControlSWTRenderer; -import org.eclipse.emf.ecp.view.spi.model.VControl; -import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference; -import org.eclipse.emf.ecp.view.template.model.VTViewTemplateProvider; -import org.eclipse.emf.edit.command.SetCommand; -import org.eclipse.emfforms.spi.common.locale.EMFFormsLocaleChangeListener; -import org.eclipse.emfforms.spi.common.locale.EMFFormsLocaleProvider; -import org.eclipse.emfforms.spi.common.report.ReportService; -import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException; -import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding; -import org.eclipse.emfforms.spi.core.services.editsupport.EMFFormsEditSupport; -import org.eclipse.emfforms.spi.core.services.label.EMFFormsLabelProvider; -import org.eclipse.emfforms.spi.localization.EMFFormsLocalizationService; -import org.eclipse.jface.dialogs.IDialogLabelKeys; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - -import de.hftstuttgart.cityunits.model.NullableQuantity; -import de.hftstuttgart.cityunits.model.quantities.QuantitiesPackage; - - -public class QuantityControlRenderer extends TextControlSWTRenderer { - - private final EMFFormsLocalizationService localizationService; - private final EMFFormsLocaleProvider localeProvider; - private EMFFormsLocaleChangeListener emfFormsLocaleChangeListener; - private Unit<?> unit; - - /** - * Default constructor. - * - * @param vElement the view model element to be rendered - * @param viewContext the view context - * @param reportService The {@link ReportService} - * @param emfFormsDatabinding The {@link EMFFormsDatabinding} - * @param emfFormsLabelProvider The {@link EMFFormsLabelProvider} - * @param vtViewTemplateProvider The {@link VTViewTemplateProvider} - * @param emfFormsEditSupport The {@link EMFFormsEditSupport} - * @param localizationService The {@link EMFFormsLocalizationService} - * @param localeProvider The {@link EMFFormsLocaleProvider} - */ - @Inject - // CHECKSTYLE.OFF: ParameterNumber - public QuantityControlRenderer(VControl vElement, ViewModelContext viewContext, ReportService reportService, - EMFFormsDatabinding emfFormsDatabinding, EMFFormsLabelProvider emfFormsLabelProvider, - VTViewTemplateProvider vtViewTemplateProvider, EMFFormsEditSupport emfFormsEditSupport, - EMFFormsLocalizationService localizationService, EMFFormsLocaleProvider localeProvider) { - // CHECKSTYLE.ON: ParameterNumber - super(vElement, viewContext, reportService, emfFormsDatabinding, emfFormsLabelProvider, vtViewTemplateProvider, - emfFormsEditSupport); - this.localizationService = localizationService; - this.localeProvider = localeProvider; - } - - @Override - protected Control createSWTControl(Composite parent) { - final VFeaturePathDomainModelReference featureRef = (VFeaturePathDomainModelReference) getVElement() - .getDomainModelReference(); - final String defaultString = featureRef.getDomainModelEFeature().getDefaultValueLiteral(); - final NullableQuantity defaultValue = NullableQuantity.create(defaultString); - unit = defaultValue.getUnit(); - - final Composite composite = new Composite(parent, SWT.NONE); - GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite); - GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.BEGINNING).applyTo(composite); - final Control control = super.createSWTControl(composite); - final Label label = new Label(composite, SWT.PUSH); - label.setText(unit.toString()); - return control; - } - - @Override - protected int getDefaultAlignment() { - return SWT.RIGHT; - } - - /* - * (non-Javadoc) - * @see org.eclipse.emf.ecp.edit.internal.swt.controls.AbstractTextControl#getTextVariantID() - */ - @Override - protected String getTextVariantID() { - return "org_eclipse_emf_ecp_control_numerical"; //$NON-NLS-1$ - } - - @Override - protected String getTextMessage() { - return ""; //$NON-NLS-1$ - } - - @Override - protected Object convert(Text text, EDataType attributeType, String value) throws DatabindingFailedException { - final EStructuralFeature eStructuralFeature = (EStructuralFeature) getModelValue().getValueType(); - final NumericalTargetToModelUpdateStrategy converter = new NumericalTargetToModelUpdateStrategy( - eStructuralFeature, getModelValue(), getDataBindingContext(), text); - return converter.convert(value); - } - - @Override - protected Binding[] createBindings(final Control control) throws DatabindingFailedException { - final EStructuralFeature structuralFeature = (EStructuralFeature) getModelValue().getValueType(); - - final UpdateValueStrategy<?, ?> targetToModelStrategy = withPreSetValidation( - new NumericalTargetToModelUpdateStrategy(structuralFeature, getModelValue(), getDataBindingContext(), - (Text) Composite.class.cast(control).getChildren()[0])); - final NumericalModelToTargetUpdateStrategy modelToTargetStrategy = new NumericalModelToTargetUpdateStrategy( - getInstanceClass(structuralFeature), false); - final Binding binding = bindValue(control, getModelValue(), getDataBindingContext(), - targetToModelStrategy, modelToTargetStrategy); - final Binding tooltipBinding = createTooltipBinding(control, getModelValue(), getDataBindingContext(), - targetToModelStrategy, - new NumericalModelToTargetUpdateStrategy(getInstanceClass(structuralFeature), true)); - - emfFormsLocaleChangeListener = new EMFFormsLocaleChangeListener() { - - /** - * {@inheritDoc} - * - * @see org.eclipse.emfforms.spi.common.locale.EMFFormsLocaleChangeListener#notifyLocaleChange() - */ - @Override - public void notifyLocaleChange() { - ((Text) control).setMessage(getTextMessage()); - binding.updateModelToTarget(); - } - }; - localeProvider.addEMFFormsLocaleChangeListener(emfFormsLocaleChangeListener); - - return new Binding[] { binding, tooltipBinding }; - } - - private Class<?> getInstanceClass(EStructuralFeature feature) { - if (feature.getEType() == QuantitiesPackage.eINSTANCE.getQuantityDouble()) { - return Double.class; - } else if (feature.getEType() == QuantitiesPackage.eINSTANCE.getQuantityLong()) { - return Long.class; - } - assert false; - return null; - } - - @Override - protected String getTextFromTextField(Text text, EDataType attributeType) { - return text.getText().isBlank() ? null : super.getTextFromTextField(text, attributeType); - } - - /** - * Converts the numerical value from the model to the target. Locale settings are respected, - * i.e. formatting is performed according to the current locale. - */ - private class NumericalModelToTargetUpdateStrategy extends ModelToTargetUpdateStrategy { - - private final Class<?> instanceClass; - - NumericalModelToTargetUpdateStrategy(Class<?> instanceClass, boolean tooltip) { - super(tooltip); - this.instanceClass = instanceClass; - } - - @Override - public Object convertValue(Object value) { - if (value == null) { - return ""; //$NON-NLS-1$ - } - return ((NullableQuantity) value).getNumber() - .map(n -> NumericalHelper.setupFormat(localeProvider.getLocale(), instanceClass).format(n)) - .orElse(""); //$NON-NLS-1$ - } - } - - /** - * More specific target to model update strategy that convert the string - * in the text field to a number. If the string is a invalid number, - * for instance because of the current locale, the value is reset to - * the last valid value found in the mode. - */ - private class NumericalTargetToModelUpdateStrategy extends TargetToModelUpdateStrategy { - - private final Text text; - private final IObservableValue<?> modelValue; - private final EStructuralFeature eStructuralFeature; - private final DataBindingContext dataBindingContext; - - NumericalTargetToModelUpdateStrategy(EStructuralFeature eStructuralFeature, - IObservableValue<?> modelValue, DataBindingContext dataBindingContext, Text text) { - super(eStructuralFeature.isUnsettable()); - this.eStructuralFeature = eStructuralFeature; - this.modelValue = modelValue; - this.dataBindingContext = dataBindingContext; - this.text = text; - } - - @Override - protected Object convertValue(final Object value) { - final DecimalFormat format = NumericalHelper.setupFormat( - localeProvider.getLocale(), getInstanceClass(eStructuralFeature)); - - try { - Number number = null; - if (value == null) { - number = NumericalHelper.getDefaultValue(getInstanceClass(eStructuralFeature)); - } else { - final ParsePosition pp = new ParsePosition(0); - number = format.parse((String) value, pp); - if (pp.getErrorIndex() != -1 || pp.getIndex() != ((String) value).length()) { - return getOldValue(value); - } - if (isInteger(getInstanceClass(eStructuralFeature))) { - boolean maxValue = false; - boolean minValue = false; - final Class<?> instanceClass = getInstanceClass(eStructuralFeature); - if (number.doubleValue() >= getInstanceMaxValue(instanceClass)) { - maxValue = true; - } else if (number.doubleValue() <= getInstanceMinValue(instanceClass)) { - minValue = true; - } - - if (maxValue || minValue) { - return numberToQuantity(number); - } - } - } - String formatedNumber = ""; //$NON-NLS-1$ - if (number != null) { - formatedNumber = format.format(number); - } - if (formatedNumber.length() == 0) { - return null; - } - return numberToQuantity(format.parse(formatedNumber)); - } catch (final ParseException ex) { - return getOldValue(value); - } - } - - /** - * Whether the given class is an integer. - * - * @param instanceClass the class to check - * @return <code>true</code> if integer, <code>false</code> otherwise - */ - private boolean isInteger(Class<?> instanceClass) { - if (instanceClass.isPrimitive()) { - return long.class == instanceClass - || int.class == instanceClass - || short.class == instanceClass - || byte.class == instanceClass; - } - return BigInteger.class == instanceClass - || Long.class == instanceClass - || BigInteger.class == instanceClass - || Short.class == instanceClass - || Byte.class == instanceClass; - } - - private Object numberToQuantity(Number number) { - return NullableQuantity.create(number, unit); - } - - private double getInstanceMinValue(Class<?> instanceClass) { - if (Integer.class == instanceClass || int.class == instanceClass) { - return Integer.MIN_VALUE; - } - if (Long.class == instanceClass || long.class == instanceClass) { - return Long.MIN_VALUE; - } - if (Short.class == instanceClass || short.class == instanceClass) { - return Short.MIN_VALUE; - } - - return Double.NaN; - } - - private double getInstanceMaxValue(Class<?> instanceClass) { - if (Integer.class == instanceClass || int.class == instanceClass) { - return Integer.MAX_VALUE; - } - if (Long.class == instanceClass || long.class == instanceClass) { - return Long.MAX_VALUE; - } - if (Short.class == instanceClass || short.class == instanceClass) { - return Short.MAX_VALUE; - } - - return Double.NaN; - } - - @Override - protected IStatus doSet(IObservableValue observableValue, Object value) { - final IStatus status = super.doSet(observableValue, value); - // update targets after a model change triggered by the target to model databinding - dataBindingContext.updateTargets(); - return status; - } - - private Object getOldValue(final Object value) { - if (eStructuralFeature.getDefaultValue() == null && value == null || value.equals("")) { //$NON-NLS-1$ - return null; - } - final Object result = modelValue.getValue(); - - final MessageDialog messageDialog = new MessageDialog(text.getShell(), - localizationService.getString(getClass(), MessageKeys.NumericalControl_InvalidNumber), null, - localizationService.getString(getClass(), MessageKeys.NumericalControl_InvalidNumberWillBeUnset), - MessageDialog.ERROR, - new String[] { JFaceResources.getString(IDialogLabelKeys.OK_LABEL_KEY) }, 0); - - new ECPDialogExecutor(messageDialog) { - @Override - public void handleResult(int codeResult) { - - } - }.execute(); - - dataBindingContext.updateTargets(); - if (eStructuralFeature.isUnsettable() && result == null) { - // showUnsetLabel(); - return SetCommand.UNSET_VALUE; - } - return result; - } - - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.ecp.view.spi.core.swt.renderer.TextControlSWTRenderer#getUnsetText() - */ - @Override - protected String getUnsetText() { - return localizationService.getString(getClass(), MessageKeys.NumericalControl_NoNumberClickToSetNumber); - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.ecp.view.spi.core.swt.SimpleControlSWTRenderer#dispose() - */ - @Override - protected void dispose() { - super.dispose(); - localeProvider.removeEMFFormsLocaleChangeListener(emfFormsLocaleChangeListener); - } - -} diff --git a/de.hftstuttgart.cityunits.ui.renderer/src/de/hftstuttgart/cityunits/ui/renderer/QuantityControlRendererService.java b/de.hftstuttgart.cityunits.ui.renderer/src/de/hftstuttgart/cityunits/ui/renderer/QuantityControlRendererService.java deleted file mode 100644 index 02cbd2aa4c94d712de2bc5b7a20a107bb49ba764..0000000000000000000000000000000000000000 --- a/de.hftstuttgart.cityunits.ui.renderer/src/de/hftstuttgart/cityunits/ui/renderer/QuantityControlRendererService.java +++ /dev/null @@ -1,86 +0,0 @@ -package de.hftstuttgart.cityunits.ui.renderer; - -import org.eclipse.core.databinding.property.value.IValueProperty; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecp.view.spi.context.ViewModelContext; -import org.eclipse.emf.ecp.view.spi.model.VControl; -import org.eclipse.emf.ecp.view.spi.model.VElement; -import org.eclipse.emfforms.spi.common.report.ReportService; -import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException; -import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport; -import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding; -import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer; -import org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService; - -import de.hftstuttgart.cityunits.model.NullableQuantity; - -/** - * QuantityRendererService which provides the QuantityRenderer. - * - * @author Kai Brassel - * - */ -public class QuantityControlRendererService implements EMFFormsDIRendererService<VControl> { - - private EMFFormsDatabinding databindingService; - private ReportService reportService; - - /** - * Called by the initializer to set the EMFFormsDatabinding. - * - * @param databindingService The EMFFormsDatabinding - */ - protected void setEMFFormsDatabinding(EMFFormsDatabinding databindingService) { - this.databindingService = databindingService; - } - - /** - * Called by the initializer to set the ReportService. - * - * @param reportService The ReportService - */ - protected void setReportService(ReportService reportService) { - this.reportService = reportService; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#isApplicable(VElement,ViewModelContext) - */ - @Override - public double isApplicable(VElement vElement, ViewModelContext viewModelContext) { - if (!VControl.class.isInstance(vElement)) { - return NOT_APPLICABLE; - } - final VControl control = (VControl) vElement; - if (control.getDomainModelReference() == null) { - return NOT_APPLICABLE; - } - @SuppressWarnings("rawtypes") - IValueProperty valueProperty; - try { - valueProperty = databindingService.getValueProperty(control.getDomainModelReference(), - viewModelContext.getDomainModel()); - } catch (final DatabindingFailedException ex) { - reportService.report(new DatabindingFailedReport(ex)); - return NOT_APPLICABLE; - } - final EStructuralFeature eStructuralFeature = EStructuralFeature.class.cast(valueProperty.getValueType()); - if (eStructuralFeature.getEType().getInstanceClass() == NullableQuantity.class) { - return 9; // 9 - not 10 - to avoid priority clash with multi-valued attributes - } - return NOT_APPLICABLE; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#getRendererClass() - */ - @Override - public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() { - return QuantityControlRenderer.class; - } - -} diff --git a/pom.xml b/pom.xml index 71b619332dfdae0b4d5e9fe135586272c072f4f6..2d9d4f1d7e78048c02214524b00a74548a99350b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>de.hftstuttgart</groupId> <artifactId>de.hftstuttgart.cityunits</artifactId> - <version>1.0.2</version> + <version>1.1.0</version> <packaging>pom</packaging> <name>City Units Parent POM</name> @@ -19,8 +19,8 @@ <artifactId>tycho-maven-plugin</artifactId> <version>${tycho-version}</version> <configuration> - <source>15</source> - <target>15</target> + <source>16</source> + <target>16</target> <encoding>UTF-8</encoding> </configuration> <extensions>true</extensions> @@ -36,7 +36,7 @@ <artifact> <groupId>de.hftstuttgart</groupId> <artifactId>de.hftstuttgart.cityunits.target</artifactId> - <version>1.0.2</version> + <version>1.1.0</version> </artifact> </target> <environments> @@ -90,7 +90,6 @@ <module>de.hftstuttgart.cityunits.feature</module> <module>de.hftstuttgart.cityunits.model</module> <module>de.hftstuttgart.cityunits.model.edit</module> - <module>de.hftstuttgart.cityunits.ui.renderer</module> <module>de.hftstuttgart.cityunits.p2site</module> <module>de.hftstuttgart.cityunits.tests</module> </modules>