Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
NeqModPlus
Energy Components Catalog
Commits
7ad4aed5
Commit
7ad4aed5
authored
Mar 17, 2021
by
Kai-Holger Brassel
Browse files
Replaced custom unit projects by external cityunits and indriya plugins
parent
01673354
Changes
115
Hide whitespace changes
Inline
Side-by-side
de.hftstuttgart.units.ui.renderer/META-INF/MANIFEST.MF
deleted
100644 → 0
View file @
01673354
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: QuantityControl
Bundle-SymbolicName: de.hftstuttgart.units.ui.renderer;singleton:=true
Bundle-Version: 1.0.0
Bundle-Vendor: Eclipse Modeling Project
Export-Package: de.hftstuttgart.units.ui.renderer;version="1.24.0"
Require-Bundle: org.eclipse.emf.ecp.edit.swt;bundle-version="1.23.0",
org.eclipse.emf.ecp.ui.view.swt;bundle-version="1.23.0",
org.eclipse.emf.ecp.view.core.swt;bundle-version="1.23.0",
org.eclipse.emf.ecp.view.template.model;bundle-version="1.23.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.23.0",
org.eclipse.emf.databinding;bundle-version="[1.3.0,2.0.0)",
org.eclipse.emfforms.swt.core.di;bundle-version="1.23.0",
de.hftstuttgart.energycomponents.model;bundle-version="1.0.0",
de.hftstuttgart.units;bundle-version="1.0.0",
de.hftstuttgart.indriya.osgiplugin;bundle-version="1.0.0",
org.eclipse.emfforms.localization,
org.eclipse.jface
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.23.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
de.hftstuttgart.units.ui.renderer/OSGI-INF/quantityRendererService.xml
deleted
100644 → 0
View file @
01673354
<?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.units.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>
de.hftstuttgart.units.ui.renderer/build.properties
deleted
100644 → 0
View file @
01673354
output..
=
bin/
bin.includes
=
META-INF/,
\
.,
\
OSGI-INF/
source..
=
src/
de.hftstuttgart.units.ui.renderer/src/de/hftstuttgart/units/ui/renderer/QuantityControlRenderer.java
deleted
100644 → 0
View file @
01673354
package
de.hftstuttgart.units.ui.renderer
;
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.Activator
;
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.energycomponents.EnCompPackage
;
import
de.hftstuttgart.units.NullableQuantity
;
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
()
==
EnCompPackage
.
eINSTANCE
.
getQuantityDouble
())
{
return
Double
.
class
;
}
else
if
(
feature
.
getEType
()
==
EnCompPackage
.
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
(
NumericalHelper
.
isInteger
(
getInstanceClass
(
eStructuralFeature
)))
{
boolean
maxValue
=
false
;
boolean
minValue
=
false
;
final
Class
<?>
instanceClass
=
getInstanceClass
(
eStructuralFeature
);
try
{
if
(
number
.
doubleValue
()
>=
getInstanceMaxValue
(
instanceClass
))
{
maxValue
=
true
;
}
else
if
(
number
.
doubleValue
()
<=
getInstanceMinValue
(
instanceClass
))
{
minValue
=
true
;
}
}
catch
(
final
IllegalArgumentException
ex
)
{
Activator
.
logException
(
ex
);
}
catch
(
final
SecurityException
ex
)
{
Activator
.
logException
(
ex
);
}
catch
(
final
IllegalAccessException
ex
)
{
Activator
.
logException
(
ex
);
}
catch
(
final
NoSuchFieldException
ex
)
{
Activator
.
logException
(
ex
);
}
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
);
}
}
private
Object
numberToQuantity
(
Number
number
)
{
return
NullableQuantity
.
create
(
number
,
unit
);
}
private
double
getInstanceMinValue
(
Class
<?>
instanceClass
)
throws
IllegalArgumentException
,
IllegalAccessException
,
NoSuchFieldException
,
SecurityException
{
if
(
Integer
.
class
.
isAssignableFrom
(
instanceClass
)
||
Integer
.
class
.
getField
(
"TYPE"
).
get
(
null
).
equals
(
instanceClass
))
{
//$NON-NLS-1$
return
Integer
.
MIN_VALUE
;
}
if
(
Long
.
class
.
isAssignableFrom
(
instanceClass
)
||
Long
.
class
.
getField
(
"TYPE"
).
get
(
null
).
equals
(
instanceClass
))
{
//$NON-NLS-1$
return
Long
.
MIN_VALUE
;
}
if
(
Short
.
class
.
isAssignableFrom
(
instanceClass
)
||
Short
.
class
.
getField
(
"TYPE"
).
get
(
null
).
equals
(
instanceClass
))
{
//$NON-NLS-1$
return
Short
.
MIN_VALUE
;
}
return
Double
.
NaN
;
}
private
double
getInstanceMaxValue
(
Class
<?>
instanceClass
)
throws
IllegalArgumentException
,
IllegalAccessException
,
NoSuchFieldException
,
SecurityException
{
if
(
Integer
.
class
.
isAssignableFrom
(
instanceClass
)
||
Integer
.
class
.
getField
(
"TYPE"
).
get
(
null
).
equals
(
instanceClass
))
{
//$NON-NLS-1$
return
Integer
.
MAX_VALUE
;
}
if
(
Long
.
class
.
isAssignableFrom
(
instanceClass
)
||
Long
.
class
.
getField
(
"TYPE"
).
get
(
null
).
equals
(
instanceClass
))
{
//$NON-NLS-1$
return
Long
.
MAX_VALUE
;
}
if
(
Short
.
class
.
isAssignableFrom
(
instanceClass
)
||
Short
.
class
.
getField
(
"TYPE"
).
get
(
null
).
equals
(
instanceClass
))
{
//$NON-NLS-1$
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
);
}
}
de.hftstuttgart.units.ui.renderer/src/de/hftstuttgart/units/ui/renderer/QuantityControlRendererService.java
deleted
100644 → 0
View file @
01673354
package
de.hftstuttgart.units.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.units.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
;
}
}
de.hftstuttgart.units/.classpath
deleted
100644 → 0
View file @
01673354
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.launching.JRE_CONTAINER"
>
<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=
"bin"
/>
</classpath>
de.hftstuttgart.units/.project
deleted
100644 → 0
View file @
01673354
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>
de.hftstuttgart.units
</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>
</buildSpec>
<natures>
<nature>
org.eclipse.pde.PluginNature
</nature>
<nature>
org.eclipse.jdt.core.javanature
</nature>
</natures>
</projectDescription>
de.hftstuttgart.units/META-INF/MANIFEST.MF
deleted
100644 → 0
View file @
01673354
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Units
Bundle-SymbolicName: de.hftstuttgart.units
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: HfT Stuttgart
Automatic-Module-Name: de.hftstuttgart.units
Require-Bundle: de.hftstuttgart.indriya.osgiplugin;bundle-version="1.0.0"
Export-Package: de.hftstuttgart.units
de.hftstuttgart.units/build.properties
deleted
100644 → 0
View file @
01673354
source..
=
src/
output..
=
bin/
bin.includes
=
META-INF/,
\
.
de.hftstuttgart.units/src/de/hftstuttgart/units/Dollar.java
deleted
100644 → 0
View file @
01673354
package
de.hftstuttgart.units
;
import
javax.measure.Quantity
;
/**
* This interface represents the intensity dimension.
*/
public
interface
Dollar
extends
Quantity
<
Dollar
>
{
}
\ No newline at end of file
de.hftstuttgart.units/src/de/hftstuttgart/units/Euro.java
deleted
100644 → 0
View file @
01673354
package
de.hftstuttgart.units
;
import
javax.measure.Quantity
;
/**
* This interface represents the intensity dimension.
*/
public
interface
Euro
extends
Quantity
<
Euro
>
{
}
\ No newline at end of file
de.hftstuttgart.units/src/de/hftstuttgart/units/Intensity.java
deleted
100644 → 0
View file @
01673354
package
de.hftstuttgart.units
;
import
javax.measure.Quantity
;
/**
* This interface represents the intensity dimension.
*/
public
interface
Intensity
extends
Quantity
<
Intensity
>
{
}
\ No newline at end of file
de.hftstuttgart.units/src/de/hftstuttgart/units/NullableQuantity.java
deleted
100644 → 0
View file @
01673354
package
de.hftstuttgart.units
;
import
java.text.NumberFormat
;
import
java.text.ParseException
;
import
java.util.Locale
;
import
java.util.Optional
;
import
javax.measure.Quantity
;
import
javax.measure.Unit
;
import
tech.units.indriya.format.SimpleQuantityFormat
;
import
tech.units.indriya.quantity.Quantities
;
/**
* A <code>NullableQuantity</code> wraps a <code>javax.measure.Quantity</code> having
* a numerical value that is either a <code>Double</code>, a <code>Long</code>,
* or <code>null</code>. The latter case represents an unknown numerical
* value of a specific unit. On the other hand, the <code>javax.measure.Unit</code>
* of the quantity is always defined.
*/
public
class
NullableQuantity
{
static
{
// TODO Implement specific QuantityFormat to enable custom number format?
// ensure that editing, (de)serialization and default values of units all work
// with the same number format (Decimal point etc.)
Locale
.
setDefault
(
Locale
.
ENGLISH
);
// specific additional units for urban simulation like TON (t), PARTS_PER_MILLION (ppm), DECIBEL (dB)
UrbanSimulationUnits
.
getInstance
();
}
public
static
NullableQuantity
create
(
String
str
)
{
NullableQuantity
newNullableQuantity
=
null
;
try
{
NumberFormat
.
getInstance
().
parse
(
str
);
newNullableQuantity
=
new
NullableQuantity
(
str
);
}
catch
(
final
ParseException
ex
)
{
// no number value present: create NullQuantity just with unit
try
{
NullableQuantity
dummy
=
new
NullableQuantity
(
"1 "
+
str
);
//$NON-NLS-1$
newNullableQuantity
=
new
NullQuantity
(
dummy
.
getUnit
());
}
catch
(
final
IllegalArgumentException
ex1
)
{
// Unit could not be parsed
System
.
out
.
println
(
"Unit '"
+
str
+
"' could not be parsed!"
);
//TODO
ex
.
printStackTrace
();
}
}
catch
(
final
IllegalArgumentException
ex
)
{
// Quantity could not be parsed
System
.
out
.
println
(
"Quantity '"
+
str
+
"' could not be parsed!"
);
//TODO
ex
.
printStackTrace
();
}
return
newNullableQuantity
;
}
public
static
NullableQuantity
create
(
Number
number
,
Unit
<?>
unit
)
{
return
number
==
null
?
new
NullQuantity
(
unit
)
:
new
NullableQuantity
(
number
,
unit
);
}
private
final
Quantity
<?>
quantity
;
private
NullableQuantity
(
String
str
)
{
quantity
=
Quantities
.
getQuantity
(
str
);
}
private
NullableQuantity
(
Number
number
,
Unit
<?>
unit
)
{
quantity
=
Quantities
.
getQuantity
(
number
,
unit
);
}
/**
* In case of an unknown numerical value of the quantity an empty <code>Optional</code> is returned via subclass.
* @return the wrapped <code>javax.measure.Quantity</code> if its numerical value is present
*/
public
Optional
<
Quantity
<?>>
getQuantity
()
{
return
Optional
.
of
(
quantity
);
}
/**
* @return numerical value of the wrapped <code>javax.measure.Quantity</code> if present
*/
public
Optional
<
Number
>
getNumber
()
{
return
getQuantity
().
map
(
Quantity:
:
getValue
);
}
public
Unit
<?>
getUnit
()
{
return
quantity
.
getUnit
();
}
@Override
public
String
toString
()
{
return
SimpleQuantityFormat
.
getInstance
().
format
(
quantity
);
}
private
static
class
NullQuantity
extends
NullableQuantity
{
public
NullQuantity
(
Unit
<?>
unit
)
{
super
(
1
,
unit
);
}
public
Optional
<
Quantity
<?>>
getQuantity
()
{
return
Optional
.
empty
();
}
@Override
public
String
toString
()
{
return
"<unknown> "
+
getUnit
().
toString
();
}
}
}
de.hftstuttgart.units/src/de/hftstuttgart/units/UrbanSimulationUnits.java
deleted
100644 → 0
View file @
01673354
package
de.hftstuttgart.units
;
import
java.math.BigInteger
;
import
javax.measure.Dimension
;
import
javax.measure.Quantity
;
import
javax.measure.Unit
;
import
javax.measure.quantity.Dimensionless
;
import
javax.measure.quantity.Mass
;
import
javax.measure.spi.SystemOfUnits
;
import
tech.units.indriya.AbstractSystemOfUnits
;
import
tech.units.indriya.AbstractUnit
;
import
tech.units.indriya.format.SimpleUnitFormat
;
import
tech.units.indriya.function.LogConverter
;
import
tech.units.indriya.function.MultiplyConverter
;
import
tech.units.indriya.unit.AlternateUnit
;
import
tech.units.indriya.unit.BaseUnit
;
import
tech.units.indriya.unit.TransformedUnit
;
import
tech.units.indriya.unit.UnitDimension
;
import
tech.units.indriya.unit.Units
;
public
class
UrbanSimulationUnits
extends
AbstractSystemOfUnits
{
private
static
final
UrbanSimulationUnits
INSTANCE
=
new
UrbanSimulationUnits
();
@Override
public
String
getName
()
{
return
getClass
().
getSimpleName
();
}
public
static
final
Unit
<
Dimensionless
>
PARTS_PER_MILLION
=
addUnit
(
new
TransformedUnit
<>(
AbstractUnit
.
ONE
,
MultiplyConverter
.
ofRational
(
BigInteger
.
ONE
,
BigInteger
.
valueOf
(
1000000
))));
public
static
final
Unit
<
Dimensionless
>
DECIBEL
=
addUnit
(
AbstractUnit
.
ONE
.
transform
(
new
LogConverter
(
10
).
inverse
().
concatenate
(
MultiplyConverter
.
ofRational
(
BigInteger
.
ONE
,
BigInteger
.
TEN
))));
public
static
final
Unit
<
Mass
>
TON
=
addUnit
(
Units
.
KILOGRAM
.
multiply
(
1000
));
public
static
final
Unit
<
Intensity
>
IRRADIANCE
=
addUnit
(
new
AlternateUnit
<
Intensity
>(
Units
.
WATT
.
divide
(
Units
.
SQUARE_METRE
),
"W/m2"
));
// To model costs I added monetary units quick and dirty as SI base units. According to JavaDoc of AbstractUnit,
// monetary units should rather be implemented in an extra type hierarchy below ComparableUnit.
public
final
static
Dimension
MONEY_DIMENSION
=
UnitDimension
.
parse
(
'M'
);
public
final
static
Unit
<
Euro
>
EURO
=
new
BaseUnit
<
Euro
>(
"€"
,
MONEY_DIMENSION
);
public
final
static
Unit
<
Dollar
>
DOLLAR
=
new
BaseUnit
<
Dollar
>(
"$"
,
MONEY_DIMENSION
);
static
{
SimpleUnitFormat
.
getInstance
().
label
(
TON
,
"t"
);
SimpleUnitFormat
.
getInstance
().
label
(
DECIBEL
,
"dB"
);
SimpleUnitFormat
.
getInstance
().
label
(
PARTS_PER_MILLION
,
"ppm"
);
SimpleUnitFormat
.
getInstance
().
label
(
EURO
,
"€"
);
SimpleUnitFormat
.
getInstance
().
label
(
DOLLAR
,
"$"
);
}
/**
* Returns the unique instance of this class.
*
* @return the Units instance.
*/
public
static
SystemOfUnits
getInstance
()
{
return
INSTANCE
;
}
/**
* Adds a new unit not mapped to any specified quantity type.
*
* @param unit the unit being added.
* @return <code>unit</code>.
*/
private
static
<
U
extends
Unit
<?>>
U
addUnit
(
U
unit
)
{
INSTANCE
.
units
.
add
(
unit
);
return
unit
;
}
/**
* Adds a new unit and maps it to the specified quantity type.
*
* @param unit the unit being added.
* @param type the quantity type.
* @return <code>unit</code>.
*/
private
static
<
U
extends
AbstractUnit
<?>>
U
addUnit
(
U
unit
,
Class
<?
extends
Quantity
<?>>
type
)
{
INSTANCE
.
units
.
add
(
unit
);
INSTANCE
.
quantityToUnit
.
put
(
type
,
unit
);
return
unit
;
}
}
de.hftstuttgart.units/src/de/hftstuttgart/units/VolumetricFlowRate.java
deleted
100644 → 0
View file @
01673354
package
de.hftstuttgart.units
;
import
javax.measure.Quantity
;
/**
* Define Volumetric Flow Rate type (basic unit is m^3/s).
*/
public
interface
VolumetricFlowRate
extends
Quantity
<
VolumetricFlowRate
>
{
}
\ No newline at end of file
Prev
1
2
3
4
5
6
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment