Derived settable attributes
No edit summary
No edit summary
Line 16: Line 16:
To help the other function with conversion, a help function like this was created
To help the other function with conversion, a help function like this was created


if  aText.length <= 2 then
if  aText.length <= 2 then
 
  DateTime.Parse('1900-01-01 ' + aText + ':00')
DateTime.Parse('1900-01-01 ' + aText + ':00')
else
 
  DateTime.Parse('1900-01-01 ' + aText)
else
endif
 
DateTime.Parse('1900-01-01 ' + aText)
 
endif


===== Property inspector =====
===== Property inspector =====
Line 33: Line 29:
OCL
OCL


if self.FromTime.notNull then
if self.FromTime.notNull then
 
  self.FromTime.formatDateTime('HH:mm')
self.FromTime.formatDateTime('HH:mm')
else
 
  String.nullValue
else
endif
 
String.nullValue
 
endif


EAL (OclSet)
EAL (OclSet)


self.FromTime := self.StringToTime(vInputParameter)
self.FromTime := self.StringToTime(vInputParameter)


'''/HoursText: String?'''
'''/HoursText: String?'''
Line 51: Line 43:
OCL
OCL


self.Hours.ToString('N2').Replace('.', ',')
self.Hours.ToString('N2').Replace('.', ',')


EAL
EAL


self.Hours := Decimal.Parse(vInputParameter.Replace(',', '.')).Round(2)
self.Hours := Decimal.Parse(vInputParameter.Replace(',', '.')).Round(2)


'''/ToTimeText: String?'''
'''/ToTimeText: String?'''
Line 61: Line 53:
OCL
OCL


if self.FromTime.notNull then
if self.FromTime.notNull then
 
  self.FromTime.AddHours(self.Hours.Value.ToDouble).formatDateTime('HH:mm')
self.FromTime.AddHours(self.Hours.Value.ToDouble).formatDateTime('HH:mm')
else
 
  String.nullValue
else
endif
 
String.nullValue
 
endif


EAL
EAL


if self.FromTime.notNull then
if self.FromTime.notNull then
 
  self.Hours := Decimal.Create(self.StringToTime(vInputParameter).Subtract(self.FromTime).TotalHours)
self.Hours := Decimal.Create(self.StringToTime(vInputParameter).Subtract(self.FromTime).TotalHours)
else
 
  self.FromTime := self.StringToTime(vInputParameter).AddHours(-self.Hours.ToDouble);
else
  0
 
endif
self.FromTime := self.StringToTime(vInputParameter).AddHours(-self.Hours.ToDouble);
 
0
 
endif

Revision as of 12:39, 26 November 2017

Derived attributes use and OCL expression to calculate the presentation of another attribute.

Derived settable attributes use EAL to do the reverse, i.e. setting the source attribute from the entered value.

This opens up special handling of user input and "user shortcuts" in the UI. For example accepting only a number as a time entry.

TimeSpent class example.png

This example uses FromTimeText, HoursText and ToTimeText for user input, but only FromTime and Hours for storing information in the database.

/Date is a derived attribute for easy access to a neighboring class' containing the date in DateTime format.

/EffectiveToTime is a derived attribute used a companion to the FromTime, again for symmetry in access the information.

Support function StringToTime()

To help the other function with conversion, a help function like this was created

if  aText.length <= 2 then
  DateTime.Parse('1900-01-01 ' + aText + ':00')
else
  DateTime.Parse('1900-01-01 ' + aText)
endif
Property inspector

Below is the property inspector setting for an derived settable attribute. Note the AttributeMode and then the Ocl and OclSet code.

DerivedSettable property inspector.png
/FromTimeText: String?

OCL

if self.FromTime.notNull then
  self.FromTime.formatDateTime('HH:mm')
else
  String.nullValue
endif

EAL (OclSet)

self.FromTime := self.StringToTime(vInputParameter)

/HoursText: String?

OCL

self.Hours.ToString('N2').Replace('.', ',')

EAL

self.Hours := Decimal.Parse(vInputParameter.Replace(',', '.')).Round(2)

/ToTimeText: String?

OCL

if self.FromTime.notNull then
  self.FromTime.AddHours(self.Hours.Value.ToDouble).formatDateTime('HH:mm')
else
  String.nullValue
endif

EAL

if self.FromTime.notNull then
  self.Hours := Decimal.Create(self.StringToTime(vInputParameter).Subtract(self.FromTime).TotalHours)
else
  self.FromTime := self.StringToTime(vInputParameter).AddHours(-self.Hours.ToDouble);
  0
endif
This page was edited 47 days ago on 03/26/2024. What links here