ParameterCatalogs.html 126 KB
Newer Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
<p>Workbench basics</p>
<div class="ulist">
<ul>
<li>
<p>Concepts: features, resources, perspectives, views, editors</p>
</li>
<li>
<p>Opening perspectives and views</p>
</li>
<li>
<p>Installing new software manually</p>
</li>
</ul>
</div>
</li>
<li>
<p>Team support with Git</p>
</li>
</ul>
</div>
</li>
<li>
<p>Learn how to use the Ecore diagram editor</p>
</li>
<li>
<p>Launch the Eclipse Marketplace</p>
</li>
</ul>
</div>
<div class="paragraph">
1031
1032
<p>For now, you can dismiss the welcome screen. It can be opened anytime by executing <code>Help &#8594; Welcome</code>.
Now you should see the initial layout of Eclipse with <em>Model Explorer</em> and <em>Outline</em> on the left and a big empty editing area to the right with a <em>Properties</em> view below.</p>
1033
1034
1035
1036
</div>
</div>
<div class="sect2">
<h3 id="truemodeling-parameter-catalogs-for-simulation-with-ecore"><a class="anchor" href="#truemodeling-parameter-catalogs-for-simulation-with-ecore"></a>Modeling Parameter Catalogs for Simulation with Ecore</h3>
1037
1038
<div class="quoteblock">
<blockquote>
1039
<div class="paragraph">
1040
1041
1042
1043
1044
1045
<p>There are two hard problems in computer science: cache invalidation, naming things, and off-by-1 errors.</p>
</div>
</blockquote>
<div class="attribution">
&#8212; Phil Karlton / N.N.
</div>
1046
1047
</div>
<div class="paragraph">
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
<p>It takes time and effort to come along with good names for model entities, projects, files, and so on.
Also, specific naming conventions are in place to enhance readability of models and program code.
Since it is not always clear where names provided during modeling are used later, I compiled a list of names important in Ecore projects and added examples and comments to elucidate their meaning and naming conventions.</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 1. Naming</caption>
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Name</th>
<th class="tableblock halign-left valign-top">Demo Catalog Example</th>
<th class="tableblock halign-left valign-top">Real World Expample</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Namespace URI</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://example.org/democatalog" class="bare">http://example.org/democatalog</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://hft-stuttgart.de/buildingphysics" class="bare">http://hft-stuttgart.de/buildingphysics</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Namespace Prefix</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">democat</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">buildphys</p></td>
</tr>
<tr>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1078
<td class="tableblock halign-left valign-top"><p class="tableblock">Base Package (reverse domain)<sup class="footnote">[<a id="_footnoteref_7" class="footnote" href="#_footnotedef_7" title="View footnote.">7</a>]</sup></p></td>
1079
<td class="tableblock halign-left valign-top"><p class="tableblock">org.example</p></td>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1080
<td class="tableblock halign-left valign-top"><p class="tableblock">de.hftstuttgart</p></td>
1081
1082
1083
1084
1085
1086
1087
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Main Package</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">democatalog</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">buildingphysics</p></td>
</tr>
<tr>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1088
1089
<td class="tableblock halign-left valign-top"><p class="tableblock">Eclipse Project<sup class="footnote">[<a id="_footnoteref_8" class="footnote" href="#_footnotedef_8" title="View footnote.">8</a>]</sup></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">org.example.democatalog.model</p></td>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1090
<td class="tableblock halign-left valign-top"><p class="tableblock">de.hftstuttgart.buildingphysics</p></td>
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Class Prefix</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Democatalog</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Buildingphysics</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">XML File Suffix</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">democatalog</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">buildingphysics</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Classes</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">e.g. SolarPanel</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">e.g. WindowType</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Attributes</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">e.g. nominalPower</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">e.g. id</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Associations</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">e.g. solarPanels</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">e.g. windowTypes</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>Classes are written in <a href="https://en.wikipedia.org/wiki/Camel_case">Camel case notation</a> starting with an upper case letter. Associations and attributes are written the same way, but starting with a lower case letter.</p>
</div>
<div class="paragraph">
<p>All other names should be derived from the globally unique <em>name space</em> of the project, in our example: <code>example.org/democatalog</code>.
It consists of a global unique domain name and a path to the project, unique within that domain.</p>
</div>
<div class="paragraph">
<p>Use the names of example <em>Demo Catalog</em> to create your first Ecore modeling project:</p>
1128
1129
1130
1131
1132
1133
1134
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Execute <code>File &#8594; New &#8594; Ecore Modeling Project</code> from main menu&#8201;&#8212;&#8201;not <code>Modeling Project</code>!</p>
</li>
<li>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1135
<p>Name the project <code>org.example.democatalog.model</code> and uncheck <code>Use default location</code> so that the new project is <strong>not</strong> stored in workspace but a different directory you create/choose, then click <code>Next &gt;</code></p>
1136
1137
</li>
<li>
1138
<p>Provide <code>democatalog</code> as main Java package name, uncheck <code>Use default namespace parameter</code> and provide <code><a href="http://example.org/democatalog" class="bare">http://example.org/democatalog</a></code> as <em>Ns URI</em> and <code>democat</code> as  <em>Ns prefix</em></p>
1139
1140
</li>
<li>
1141
<p>Click <code>Finish</code>.</p>
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
</li>
</ol>
</div>
<div class="paragraph">
<p>Eclipse should look like below with an new empty graphical Ecore diagram editor opened.
The diagram is automatically named <code>democatalog</code> after the package name for the Java classes that will be generated from it (provided above).
The <em>Model Explorer</em> shows the contents of the new Ecore modeling project.</p>
</div>
<div class="imageblock thumb">
<div class="content">
<img src="ParameterCatalogs2Images/DemoCatalogEmpty.png" alt="DemoCatalogEmpty">
</div>
<div class="title">Figure 3. New Ecore Modeling Project</div>
</div>
<div class="paragraph">
<p>To get your feet wet, do this:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Drag a <em>Class</em> from the palette on the right onto the editor&#8217;s canvas: it will materialize as a rectangle labeled <code>NewEClass1</code>.</p>
</li>
<li>
<p>The class symbol should be selected initially, so you can see its attributes in the <em>Properties</em> view.</p>
</li>
<li>
<p>In there replace <code>NewEClass1</code> by <code>EnergyComponentsCatalog</code> to rename the class.</p>
</li>
<li>
<p>Click anywhere on the canvas and notice that the class symbol is deselected and the toolbar at the top adapts accordingly.</p>
</li>
<li>
<p>In the toolbar change <code>100%</code> to <code>75%</code> to scale diagram.</p>
</li>
<li>
<p>Execute <code>File &#8594; Save</code> to save model and diagram on disk.</p>
</li>
<li>
<p>Close diagram editor <code>democatalog</code> by closing its tab.</p>
</li>
<li>
<p>Reopen saved diagram by double click on entry <code>democatalog</code> in <em>Model Explorer</em>.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>Technically, everything is in place now to begin modeling the data that the projected catalog shall contain.
Except &#8230;&#8203; understanding the basics of object-oriented modeling would be helpful.
This is why developers should support domain experts at this stage.</p>
</div>
<div class="paragraph">
<div class="title">Model Data with Class Diagrams</div>
<p>Ecore diagrams are simplified UML class diagrams.
Here some resources on what this is all about:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="http://www.cs.toronto.edu/~sme/CSC340F/slides/11-objects.pdf">Toronto Lecture on Object Oriented Modeling</a></p>
</li>
<li>
<p><a href="http://agilemodeling.com/artifacts/classDiagram.htm">UML 2 Class Diagrams: An Agile Introduction</a></p>
</li>
<li>
<p><a href="https://www.amazon.de/UML-Classroom-Einführung-objektorientierte-Modellierung-ebook/dp/B00AIBE1QA/ref=sr_1_2?__mk_de_DE=ÅMÅŽÕÑ&amp;dchild=1&amp;keywords=UML&amp;qid=1585854599&amp;sr=8-2">UML @ Classroom: Eine Einführung in die objektorientierte Modellierung (German Book)</a></p>
</li>
</ul>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
<div class="paragraph">
<p>Beginners are strongly encouraged to read the first two resources.
The first one contains a gentle introduction, especially suited for domain experts.
The second one can also serve as reference.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>We will touch central object-oriented concepts <em>Class</em>, <em>Object</em>, <em>Attribute</em>, <em>Association</em>, <em>Composition</em>, and <em>Multiplicity</em> in an example below, but work through above sources to get a deeper understanding and to enhance your modeling skills.</p>
</div>
<div class="paragraph">
<p>Note that above sources differentiate between <em>conceptual</em> and <em>detailed</em> models.
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1231
We go for detailed models, since only these contain enough information to generate code.
1232
1233
1234
1235
1236
1237
1238
1239
1240
Having said this, it is usually a good idea to have two or three conceptual iterations at a white board to agree on the broad approach before going too much into detail.
But even if one starts with Ecore models right away, these also can be adapted any time to follow a new train of thought.</p>
</div>
<div class="paragraph">
<p>See here the essential and typical structure of a parameter catalog in a class diagram.
Instead of artificial example classes like <em>Foo</em> and <em>Bar</em> it shows classes from an existing catalog, albeit in very condensed form.</p>
</div>
<div class="imageblock thumb">
<div class="content">
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1241
<img src="http://localhost:53031/afx/cache/28c119036261e39473751e5cb111acc9.png" alt="28c119036261e39473751e5cb111acc9">
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
</div>
<div class="title">Figure 4. Principle Structure of a Parameter Catalog</div>
</div>
<div class="paragraph">
<p>The diagram models four types of technical components whose data shall be stored in the catalog, e.g. for parameterization of simulation models later: <em>Boiler</em>, <em>CombinedHeatPower</em>, <em>SolarPanel</em>, and <em>Inverter</em>.</p>
</div>
<div class="paragraph">
<p>The catalog itself is represented by class <em>EnergyComponentsCatalog</em>.
Unlike dozens, hundreds, or even thousands of objects to be cataloged&#8201;&#8212;&#8201;Boilers, Inverters etc.&#8201;&#8212;&#8201;there will be just exactly <strong>one</strong> catalog object in the data representing the catalog itself.
Its "singularity" is not visible in the class diagram, but an <em>Ecore</em> convention requires that all objects must form a composition hierarchy with only one root object.</p>
</div>
<div class="paragraph">
<div class="title">Composition</div>
<p>If, in the domain, one object is composed of others, this is expressed by a special kind of association called <em>composition</em>.
Compositions are depicted as a link with a diamond shape attached to the containing object. In the <em>Boiler</em> case said link translates to: The <em>EnergyComponentsCatalog</em> contains&#8201;&#8212;&#8201;or is composed of&#8201;&#8212;&#8201;zero or more (<code>0..*</code>) boiler objects stored in a list named <code>boilers</code>.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
<div class="paragraph">
1266
1267
<p>Note that class names&#8201;&#8212;&#8201;despite the fact that they model a set of similar objects&#8201;&#8212;&#8201;are always written in <em>singular</em>!
Names for list-like associations and attributes usually are written in plural form.</p>
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<div class="title">Inheritance</div>
<p>Besides composition of <strong>objects</strong>, the model above shows another, completely different, kind of hierarchy: the inheritance hierarchy between <strong>classes</strong>.
Whenever classes of objects share the same attributes or associations, we don&#8217;t like to repeat ourselves by adding that attribute or relation to all classes again and again.
Instead, we add a <em>super class</em> to define common attributes and associations and connect it to <em>sub classes</em> that will automatically <em>inherit</em> all the features of their super class.</p>
</div>
<div class="paragraph">
<p>In our example above, common to all four energy components are attributes <code>modelName</code> and <code>revisionYear</code>, thus these are modeled by class <code>EnergyComponent</code> that is directly or indirectly a super class of <em>Boiler</em>, <em>CombinedHeatPower</em>, <em>SolarPanel</em>, and <em>Inverter</em>.
1281
1282
Similar, <em>Boiler</em> and <em>CombinedHeatPower</em> share attribute <code>installedThermalPower</code> factored out by class <em>ChemicalDevice</em>.
<em>SolarPanel</em> and <em>Inverter</em> share attribute <code>nominalPower</code> modeled in abstract class <em>ElectricalDevice</em>.</p>
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
</div>
<div class="paragraph">
<div class="title">Associations</div>
<p>You probably noticed a fifth type of objects contained in the catalog, namely <code>Manufacturer</code> objects stored in list <code>manufactureres</code>.
How come? Ok, here is the story:</p>
</div>
<div class="sidebarblock">
<div class="content">
<div class="title">Domain Expert Meets Developer</div>
<div class="paragraph">
<p><em>Exp</em>: &#8220;I&#8217;d like to store a component&#8217;s manufacturer. Shall I add a String attribute <code>manufacturerName</code> to all classes like <em>Boiler</em>, <em>Inverter</em> and so on to store the manufacturer&#8217;s name?&#8221;</p>
</div>
<div class="paragraph">
<p><em>Dev</em> shudders: &#8220;Well, what do you mean by "&#8230;&#8203; and so on"?&#8221;</p>
</div>
<div class="paragraph">
<p><em>Exp</em>: &#8220;Basically, I mean all energy components.&#8221;</p>
</div>
<div class="paragraph">
<p><em>Dev</em>: &#8220;Fine. We already have a class representing all those energy components, brilliantly named <em>EnergyComponent</em>. Thus, we can define <code>manfacturerName</code> there, following one of Developer&#8217;s holy principles: "<em>DRY</em>&#8201;&#8212;&#8201;Don&#8217;t repeat yourself!"
By the way: Is the name all you want to know about manufacturers?&#8221;</p>
</div>
<div class="paragraph">
<p><em>Exp</em>: &#8220;Mhm, maybe we need to know if they are still in business &#8230;&#8203;&#8221;</p>
</div>
<div class="paragraph">
<p><em>Dev</em>: &#8220;&#8230;&#8203; or even since when they were out of business, if at all &#8230;&#8203;&#8221;</p>
</div>
<div class="paragraph">
<p><em>Exp</em>: &#8220;&#8230;&#8203; and the country or region they are active.&#8221;</p>
</div>
<div class="paragraph">
<p><em>Dev</em>: &#8220;Ok, so it&#8217;s not just the name&#8201;&#8212;&#8201;we need a class <code>Manufacturer</code> to model all these information.&#8221;</p>
</div>
<div class="paragraph">
<p><em>Exp</em> sighs.</p>
</div>
<div class="paragraph">
<p><em>Dev</em>: &#8220;Come on, its not that hard to add a class to our data model, isn&#8217;t it?&#8221;</p>
</div>
<div class="paragraph">
<p><em>Exp</em>: &#8220;Ok, but how can we express what components a manufacturer produces?&#8221;</p>
</div>
<div class="paragraph">
<p><em>Dev</em>: &#8220;Wasn&#8217;t it the other way around? I thought, you just wanted to know the manufacturer of a component?&#8221;</p>
</div>
<div class="paragraph">
<p><em>Exp</em>: &#8220;What is the difference?&#8221;</p>
</div>
<div class="paragraph">
<p><em>Dev</em>: &#8220;In data modeling, it is the difference between a uni-directional and a bi-directional association.&#8221;</p>
</div>
<div class="paragraph">
<p><em>Exp</em>: &#8220;&#8230;&#8203;?&#8221;</p>
</div>
<div class="paragraph">
<p><em>Dev</em>: &#8220;Let&#8217;s put it that way: The difference between a link with an arrow on one side or on both sides.&#8221;</p>
</div>
<div class="paragraph">
<p><em>Exp</em>: &#8220;Ok. We don&#8217;t need a list of components per manufacturer, but simply a reference from the component to its manufacturer.&#8221;</p>
</div>
<div class="paragraph">
<p><em>Dev</em>: &#8220;Fine, then in Ecore please create a simple reference from class <code>EnergyComponent</code> to class <code>Manufacturer</code>, maybe named <code>producedBy</code>.&#8221;</p>
</div>
<div class="paragraph">
<p><em>Exp</em>: &#8220;I will try this and get back to you.&#8221;</p>
</div>
<div class="paragraph">
<p><em>Dev</em>: &#8220;Fine &#8230;&#8203; good meeting.&#8221;</p>
</div>
</div>
</div>
<div class="paragraph">
<p>Observe in our data model, reference <code>producedBy</code> points <em>from</em> <code>EnergyComponent</code> <em>to</em> <code>Manufacturer</code> making it uni-directional reference.
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1357
One can simply query the manufacturer of a product, but not the other way around.
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
With a bi-directional reference both queries would be available.</p>
</div>
<div class="paragraph">
<p>Observe also the annotations <code>0..*</code> and <code>1..1</code> near class <code>Manufacturer</code>.
These are <em>multiplicities</em> of associations: An <code>EnergyComponentsCatalog</code> contains zero, one, or many objects of class <code>Manufacturer</code> and an <code>EnergyComponent</code> must reference exactly one manufacturer&#8201;&#8212;&#8201;not less, not more.</p>
</div>
<div class="openblock float-group">
<div class="content">
<div class="imageblock right thumb">
<div class="content">
<img src="ParameterCatalogs2Images/EcoreRelations.gif" alt="EcoreRelations" width="200">
</div>
<div class="title">Figure 5. Ecore Relations</div>
</div>
<div class="paragraph">
<p>To recapitulate: Our example parameter catalog already exhibits all four types of relations provided by Ecore.
You find these in the Ecore editor&#8217;s palette shown here.
To create a relation between a sub class and a super class use tool <code>SuperType</code>.
Use the other tools to create an association between classes, may it be a simple (uni-directional) reference, a bi-directional reference, or a composition.</p>
</div>
</div>
</div>
<div class="paragraph">
<div class="title">Attributes and Enumerations</div>
<p>Obviously, attributes are central in data modeling.
Create one by dragging it from the palette onto our one and only class so far: <code>EnergyComponentsCatalog</code>.
The class symbol will turn red to indicate an error.
Hover with the mouse pointer over the new attribute and a tooltip with a more or less helpful error message will appear.
Current error is caused by that no data type was set for the new attribute.
Data types for attributes can be integer or floating point numbers, strings, dates, booleans, and more.
To get rid of the error:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>If not already selected, select new attribute by clicking at it in the editor.</p>
</li>
<li>
<p>In view <em>Properties</em> find <code>EType</code> and click button <code>&#8230;&#8203;</code> to see a quite long list of available data types.</p>
</li>
<li>
<p>Choose <code>EString [java.lang:String]</code> from the list and the error is gone.</p>
</li>
</ol>
</div>
<div class="openblock float-group">
<div class="content">
<div class="imageblock right thumb">
<div class="content">
<img src="ParameterCatalogs2Images/EcoreClassWithAttribute.png" alt="EcoreClassWithAttribute" width="200">
</div>
<div class="title">Figure 6. Class with Attribute</div>
</div>
<div class="paragraph">
<p>Change the attribute&#8217;s name to <code>author</code> and the class should look like shown here.</p>
</div>
<div class="paragraph">
<p>Most data types to choose from begin with letter <strong>E</strong> like in <strong>E</strong>core.
These are just Ecore enabled variants of the respective Java types, thus, choose EInt for an int, EFloat for a 32 bit floating point number, EDouble for a 64 bit one, and so on.</p>
</div>
<div class="paragraph">
<p>Ecore allows to introduce new data types.
We employ this feature later to enable data models with physical units and quantities.</p>
</div>
</div>
</div>
<div class="paragraph">
<p>There exists one other means to define the values an attribute can take, namely enumerations of distinct literals. Take <em>Monday</em>, <em>Tuesday</em>, <em>Wednesday</em>, &#8230;&#8203; as a typical example for representing weekdays.
In our example data model you&#8217;ll find one <em>Enumeration</em> named <code>BoilerType</code> with values <code>LowTemperature</code> and <code>Condensing</code>.</p>
</div>
<div class="paragraph">
<div class="title">Homework</div>
<p>The next section deals with generation of Java code from data models. To have more to play with, please implement our example model in Ecore now.</p>
</div>
<div class="openblock float-group">
<div class="content">
<div class="imageblock right thumb">
<div class="content">
<img src="ParameterCatalogs2Images/EcoreClassifier.png" alt="EcoreClassifier" width="200">
</div>
<div class="title">Figure 7. Abstract Class</div>
</div>
<div class="paragraph">
<p>To do this, there is one more thing to know about classes: the difference between ordinary classes and abstract classes.
'Ordinary class' doesn&#8217;t sound nice, therefore, classes that are not abstract are called <em>concrete</em> classes.
Our example diagram depicts abstract classes with letter <strong>A</strong> while concrete classes are labeled with <strong>C</strong>. You add abstract classes to a model with a special palette tool shown here.</p>
</div>
<div class="paragraph">
<p>The thing is: Objects can be created for concrete classes only!</p>
</div>
<div class="paragraph">
<p>In our example, it makes no sense to create an object from class <em>EnergyComponent</em>, because there is not such a thing like an energy component <em>per se</em>.
Therefore, this class is <em>abstract</em>.
It is true that an inverter <em>is</em> an energy component, thus inheriting all its features, but it was <em>created</em> as <em>Inverter</em>, not as <em>EnergyComponent</em>.</p>
</div>
<div class="paragraph">
<p>Super classes will be abstract most of the time.
So my advice is: Model a super class as abstract class unless you convince yourself that there exist real objects in the domain that belong to the super class but, at the same time, do not belong to any of its sub classes.
In the Ecore editor properties view, you can specify if a class is abstract or not, simply by toggling check box <code>Abstract</code>.</p>
</div>
</div>
</div>
<div class="paragraph">
<p>Two more tips and you are ready to rock and roll!&#8201;&#8212;&#8201;At least with your homework.</p>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
<div class="paragraph">
<p>An exhaustive user manual for Ecore diagram editor is available. Execute <code>Help &#8594; Welcome</code> and follow link <code>Learn how to use the diagram editor</code>.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
<div class="paragraph">
<p>If Ecore models get bigger, you may find it more convenient to work with a form based UI instead of, or in addition to, the diagram editor.
Open this kind of editor via command <code>Open With &#8594; Ecore Editor</code> from the context menu over entry <code>democatalog.ecore</code> in the <em>Model Explorer</em> view.
Note that Eclipse synchronizes different editors of the same content automatically.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="truegeneration-of-java-code-from-data-model"><a class="anchor" href="#truegeneration-of-java-code-from-data-model"></a>Generation of Java Code from Data Model</h3>
<div class="paragraph">
<p>By now, your Ecore model should look like this:</p>
</div>
<div id="fig-example-model" class="imageblock thumb">
<div class="content">
1501
<img src="ParameterCatalogs2Images/Homework.png" alt="Homework">
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
</div>
<div class="title">Figure 8. Example Model (Homework)</div>
</div>
<div class="paragraph">
<p>Let us bring the model to life, that is, generate code from it that creates, reads, updates, and deletes concrete data objects of modeled classes in computers.
I would like to tell you that this is done with just one click but, actually, you need two or three:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Make sure all files are saved (<code>File &#8594; Save All</code>)</p>
</li>
<li>
1515
<p>Execute <code>Generate &#8594; Model Code</code> from the context menu of Ecore editor <code>democatalog</code></p>
1516
1517
</li>
<li>
1518
<p>Execute <code>Generate &#8594; Edit Code</code> from the same context menu</p>
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
</li>
</ol>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
<div class="paragraph">
<p>Please do <strong>not</strong> execute <code>Generate &#8594; All</code> or <code>Generate &#8594; Editor Code</code>.</p>
</div>
<div class="imageblock thumb">
<div class="content">
<img src="ParameterCatalogs2Images/GenerateMenu.png" alt="GeneratedClasses" width="260">
</div>
</div>
<div class="paragraph">
<p>This would create code for a simple user interface, but we use more advanced EMF Forms for that later.
1539
If, by mistake, project <code>org.example.democatalog.editor</code> was created, just delete it from <em>Model Explorer</em> and do not forget to check <code>Delete project contents on disk</code> in confirmation dialog.</p>
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
</div>
</td>
</tr>
</table>
</div>
<div class="openblock float-group">
<div class="content">
<div class="imageblock right thumb">
<div class="content">
<img src="ParameterCatalogs2Images/GeneratedClasses.png" alt="GeneratedClasses" width="260">
</div>
<div class="title">Figure 9. Generated Classes</div>
</div>
<div class="paragraph">
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1554
<p><code>Generate &#8594; Model Code</code> creates classes that represent the modeled data in code. These classes are located in three packages under directory <code>src-gen</code> in <code>org.example.democatalog.model</code>.</p>
1555
1556
</div>
<div class="paragraph">
1557
<p><code>Generate &#8594; Edit Code</code> creates a whole new Eclipse project named <code>org.example.democatalog.edit</code>, again with generated classes under directory <code>src-gen</code>.</p>
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
</div>
<div class="paragraph">
<p>You may have a look at some Java classes for curiosity by double clicking at them in <em>Model Explorer</em>. There is no point in trying to understand the code in detail, but observe token <code>@generated</code> present in the comments of all classes, fields and methods. Classes, fields and methods marked with this token are (re)generated whenever above commands are executed.</p>
</div>
<div class="paragraph">
<p>Sometimes it maybe required to manually adapt generated code&#8201;&#8212;&#8201;after all our concern is "low code", not "no code" development. In that case, we will replace <code>@generated</code> by <code>@generated NOT</code> to prevent code regeneration.</p>
</div>
<div class="paragraph">
<p>After code generation, you may have noticed some warnings showed up in view <em>Problems</em>.</p>
</div>
<div class="imageblock thumb">
<div class="content">
<img src="ParameterCatalogs2Images/Warnings.gif" alt="Warnings" width="500">
</div>
<div class="title">Figure 10. Warnings</div>
</div>
<div class="paragraph">
<p>In general, it is highly recommended to resolve warnings, and errors of course, but we will make an exception from the rule, since the warnings are uncritical and would reappear each time code is regenerated.</p>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="truegeneration-and-tweaking-of-user-interface"><a class="anchor" href="#truegeneration-and-tweaking-of-user-interface"></a>Generation and Tweaking of User Interface</h3>
<div class="paragraph">
<p>In this section you will learn how to generate and tweak a CRUD user interface based on Ecore data model and Java classes created for our demo parameters catalog above. Topics described here are discussed in more detail in tutorial <a href="https://eclipsesource.com/blogs/tutorials/getting-started-with-EMF-Forms/">Getting started with EMF Forms</a>.
To find out what user interface controls and layouts are provided by this framework have a look at <a href="https://eclipsesource.com/blogs/tutorials/emf-forms-view-model-elements/">EMF Forms – View Model Elements</a>. <em>EMF Forms</em> is already part of package <em>Eclipse Modeling Tools</em>, so we can create a third Eclipse project/plugin that implements a user interface for editing catalog data without further ado:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
1589
<p>In the <em>Model Explorer</em> execute <code>EMF Forms &#8594; Create View Model Project</code> from context menu over <code>democatalog.ecore</code></p>
1590
1591
</li>
<li>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1592
<p>Leave project name <code>org.example.democatalog.viewmodel</code> as is but uncheck <code>Use default location</code>&#8201;&#8212;&#8201;as we always do&#8201;&#8212;&#8201;and browse to the directory containing <code>org.example.democatalog.model</code></p>
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
</li>
<li>
<p>Click <code>Next &gt;</code> and select <code>EnergyComponentsCatalog</code> as data element we want to create a user interface for</p>
</li>
<li>
<p>Leave <code>Fill view model with default layout</code> checked and click <code>Finish</code>.</p>
</li>
</ol>
</div>
<div class="paragraph">
1603
<p>According to these inputs a new project is created with file <code>EnergyComponentsCatalog.view</code> under directory <code>viewmodels</code>.
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
This file opens automatically in a special <em>View Editor</em>.</p>
</div>
<div class="imageblock thumb">
<div class="content">
<img src="ParameterCatalogs2Images/ViewModel.png" alt="ViewModel1">
</div>
<div class="title">Figure 11. New View Model</div>
</div>
<div class="paragraph">
<p>Like the <strong>data</strong> of our catalog are modeled as Ecore file using a dedicated graphical editor, so will our catalog’s <strong>user interface</strong> be modeled in <code>.view</code> files, again using a special editor.</p>
</div>
<div class="paragraph">
<p>Since we opted for <code>Fill view model with default layout</code> the catalog&#8217;s UI is filled initially with default controls for all data items assigned to Ecore type <code>EnergyComponentsCatalog</code> like a string control for <code>author</code> or list controls for <code>boilers</code>, <code>chps</code>, and so on.</p>
</div>
<div class="paragraph">
<p>See red arrow in the above screen-shot?
It points to a button that opens a functional preview of the modeled user interface.</p>
</div>
<div class="imageblock thumb">
<div class="content">
<img src="ParameterCatalogs2Images/ViewEditorPreview.png" alt="ViewModel1" width="500">
</div>
<div class="title">Figure 12. User Interface Preview</div>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
<div class="paragraph">
<p>Double click on tab <em>EMF Forms Preview</em> to enlarge view for better handling&#8201;&#8212;&#8201;double click again to get back.</p>
</div>
<div class="paragraph">
<p>Enable auto refresh mode <span class="image"><img src="ParameterCatalogs2Images/ViewModelAutomaticRefresh.gif" alt="ViewModelAutomaticRefresh" width="40"></span> to let each change in the view model instantly be reflected in the preview.</p>
</div>
<div class="paragraph">
<p>Given your screen is big enough, you may want to dock-out the preview by dragging tab <em>EMF Forms Preview</em> out of Eclipse&#8217;s main window.
Seeing editor and preview side by side is a great way to explore the possibilities of view models.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Red input field and exclamation mark in the preview signal missing or inconsistent data.
Ecore data model specifies attribute <code>author</code> with a lower bound of one, meaning it is a mandatory attribute.
As soon as an author&#8217;s name is provided, the error indication disappears.
This is what <em>functional</em> preview means.
You can even create new boilers or other objects in lists provided, with all forms created "automagically" with respect to our underlying Ecore data model.</p>
</div>
<div class="paragraph">
<p>Of course, such automatic approach has its limits.
1658
In our case, a long list of lists is not very user-friendly, because one has to scroll up and down to find a specific list.
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
Also, no specific object data are shown in the list and data can only be edited in a pop-up form (no inline editing).</p>
</div>
<div class="paragraph">
<p>How should a better UI look and feel like?</p>
</div>
<div class="paragraph">
<p>If there are many lists (types) of entities&#8201;&#8212;&#8201;the normal case for parameter catalogs&#8201;&#8212;&#8201;users should select what list they want to work with by selecting it from a list or tree view that is always visible, the <em>master view</em>.
Once a type is selected in the master view, a table with all objects of this list/type shall appear sidelong in a <em>detail view</em>, ready for editing.</p>
</div>
<div class="paragraph">
<p>In <em>EMF Forms</em> master-detail-views can be modeled either with <em>Categorization</em> or <em>Tree Master Detail</em> UI components.
The latter not only allows to edit information displayed in the detail view, but also the tree of elements in the master view.
Opposed to that, a <em>Categorization</em> presents a fixed hierarchy of elements to choose from.
This is exactly what we need as there are only a fixed number of types of objects to be edited in a parameters catalog.</p>
</div>
<div class="sect3">
<h4 id="trueadding-tables-to-the-ui"><a class="anchor" href="#trueadding-tables-to-the-ui"></a>Adding Tables to the UI</h4>
<div class="openblock float-group">
<div class="content">
<div class="imageblock right thumb">
<div class="content">
<img src="ParameterCatalogs2Images/ViewModelDeleteControls.gif" alt="ViewModelDeleteControls" width="300">
</div>
<div class="title">Figure 13. Delete default list controls</div>
</div>
<div class="paragraph">
<p>But first, we replace the default controls for lists of boilers, chps, and so on by tables. As shown here, select all list controls in the view model and execute <code>Delete</code> from context menu. Refresh <em>View Editor Preview</em> to verify that only field <code>Author*</code> is left.</p>
</div>
</div>
</div>
<div class="openblock float-group">
<div class="content">
<div class="imageblock right thumb">
<div class="content">
<img src="ParameterCatalogs2Images/ViewModelCreateTable.gif" alt="ViewModelCreateTable" width="300">
</div>
<div class="title">Figure 14. Create Table Control</div>
</div>
<div class="paragraph">
<p>Next, create a table that shall display all boilers in a catalog:
Select <code>EnergyComponentsCatalog</code>, activate context menu and choose <code>TableControl</code> from the list of available UI elements.
(EnergyComponentsCatalog represents the root view of the UI and, as such, accepts quite a lot of different UI components as child components.)</p>
</div>
<div class="paragraph">
<p>Entry <code>TableControl</code> was inserted into the list of interface elements below <code>Control author</code>.
Checking updated preview reveals no table but a message basically saying that a reference to the domain model is missing, in other words: <em>EMF Forms</em> does not know yet what data to present in table.
Click on entry <code>TableControl</code> to see its details.
A red exclamation mark indicates the missing <code>Domain Model Reference*</code>.
Click on <span class="image"><img src="ParameterCatalogs2Images/ButtonLinkPlus.gif" alt="ButtonLinkPlus" width="40"></span> and be ready to chase a sequence of dialogs:</p>
</div>
</div>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Click on another <span class="image"><img src="ParameterCatalogs2Images/ButtonLinkPlus.gif" alt="ButtonLinkPlus" width="40"></span> in dialog <code>Configure TableDomainModelReference</code></p>
</li>
<li>
<p>In wizard <code>New Reference Element</code> select <code>model &#8594; FeaturePathDomainModelReference</code> and click <code>Next &gt;</code></p>
</li>
<li>
<p>Click <code>Link Domain Model EFeature</code> and in appearing pop-up list choose reference to list of objects you want to edit in the table, e.g. <code>boilers</code>; confirm with <code>OK</code> safely ignoring warning about missing <code>PropertyDescriptor</code>.</p>
</li>
<li>
<p><code>Finish</code> wizard <code>New Reference Element</code></p>
</li>
<li>
<p><code>Finish</code> dialog <code>Configure TableDomainModelReference</code>.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>This was some work, but as reward we get a fully specified table control in <em>View Editor</em> that "translates" into a preview where we can create, read, update, and delete boilers.</p>
</div>
<div class="imageblock thumb">
<div class="content">
<img src="ParameterCatalogs2Images/ViewModelWithTable.gif" alt="ViewModelWithTable.gif">
</div>
<div class="title">Figure 15. Table for Boilers</div>
</div>
<div class="paragraph">
<p>Moreover, clicking at a table header sorts all objects in it (rows) according to the values in this column.
Column widths can adapted, too.</p>
</div>
<div class="openblock float-group">
<div class="content">
<div class="imageblock right thumb">
<div class="content">
<img src="ParameterCatalogs2Images/ViewModelTweakTable.gif" alt="ViewModelTweakTable" width="300">
</div>
<div class="title">Figure 16. Modify Table Control</div>
</div>
<div class="paragraph">
<p>Table UIs can be tweaked in many ways, e.g. selection and sequence of columns can be declared via list <code>Column Domain Model References</code>. To fill this list with defaults, execute <code>Generate Columns</code> from table control&#8217;s context menu. Reorder them as you like or delete columns that are not important to the user.</p>
</div>
<div class="paragraph">
<p>Notice here an important overall feature of <em>EMF Forms</em>: If something is left unspecified, be it the view model for an Ecore object type or the specification of table columns, <em>EMF Forms</em> will always find a default solution! Applied to columns specification this means we get default columns automatically back in the moment the last column is removed from list <code>Column Domain Model References</code>.</p>
</div>
<div class="paragraph">
<p>If explicit column specifications are present further configurations can be added to a table control from its context menu, e.g. initial column widths or read-only status of columns. See <a href="https://eclipsesource.com/de/blogs/2018/01/31/emf-forms-1-15-0-feature-enhanced-table-renderer/">here</a> for details.</p>
</div>
</div>
</div>
<div class="paragraph">
<p>By default only attributes are displayed and directly editable in tables while references to other objects&#8201;&#8212;&#8201;in our case the reference to a manufacturer&#8201;&#8212;&#8201;are not.</p>
</div>
<div class="openblock float-group">
<div class="content">
<div class="imageblock right thumb">
<div class="content">
<img src="ParameterCatalogs2Images/ViewModelWithPanel.gif" alt="ViewModelWithPanel" width="300">
</div>
<div class="title">Figure 17. Default  Panel for Boilers</div>
</div>
<div class="paragraph">
<p>To get the default (<em>sic!</em>) editing panel for an selected table row, in <em>View Editor</em> just set <code>Detail Editing*</code> from <code>None</code> to <code>WithPanel</code>, <strong>press <em>Tab</em></strong>, and save. For boilers, <em>EMF Forms</em> will create the editing panel shown here. Regardless wether users edit data in the panel or directly in the table&#8201;&#8212;&#8201;both will stay in sync any time.</p>
</div>
</div>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
<div class="paragraph">
<p><em>View editor</em> exhibits an irritating behavior: With preview auto-refresh turned on, any change in the details view is reflected instantly in the preview, even without saving the form or leaving the edited field.</p>
</div>
<div class="paragraph">
<p>On the other hand, <strong>saving</strong> an updated view editor only takes into account edited fields after they have lost focus, e.g. by pressing <em>Tab</em> key or clicking with the mouse into another field.
So, saving a form before the focus has shifted from the last edited field won&#8217;t honor this edit, that is you won&#8217;t necessarily get what you see.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>One last thing: Enter <code>boilers</code> as name for the table control so we can distinguish it from the other four table controls to come.</p>
</div>
<div class="paragraph">
<p>Yes! &#8230;&#8203; Please repeat above procedure to create table controls for chps, solar panels, inverters and manufacturers, too. I did this in about 3 minutes. ;-)</p>
</div>
</div>
<div class="sect3">
<h4 id="truemaster-detail-view-with-categories"><a class="anchor" href="#truemaster-detail-view-with-categories"></a>Master-Detail View with Categories</h4>
<div class="paragraph">
<p>In last section we improved our catalog&#8217;s UI by replacing simple object lists by tables that can be sorted, customized and edited inline as well as in an associated panel.
Alas, instead a list of lists we have got an even bigger list of tables.</p>
</div>
<div class="paragraph">
1810
<p>High time to introduce a master-detail view that presents categories of object types in a master view and, after one is selected, the according object table in the detail view.</p>
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
</div>
<div class="openblock float-group">
<div class="content">
<div class="imageblock right thumb">
<div class="content">
<img src="ParameterCatalogs2Images/ViewModelCatgorization1.gif" alt="ViewModelCatgorization1" width="180">
</div>
<div class="title">Figure 18. Category Tree</div>
</div>
<div class="paragraph">
<p>Add a <em>Categorization</em> view to the list of UI elements in <em>View Editor</em> by selecting <code>EnergyComponentsCatalog</code> and choose <code>Categorization</code> from its contect menu.</p>
</div>
<div class="paragraph">
<p>Now add two <code>Composite Category</code> elements and one <code>Leaf Category</code> to <code>Categorization</code> from according context menu. This gives us three top level entries in the hierarchy.</p>
</div>
<div class="paragraph">
<p>In the same way add two <code>Leaf Category</code> elements to each <code>Composite Category</code> resulting in the hierarchy depicted here.</p>
</div>
</div>
</div>
<div class="openblock float-group">
<div class="content">
<div class="imageblock right thumb">
<div class="content">
<img src="ParameterCatalogs2Images/ViewModelCatgorization2.gif" alt="ViewModelCatgorization2" width="260">
</div>
<div class="title">Figure 19. Completed View Model</div>
</div>
<div class="paragraph">
<p>This screen shot shows the view model of our UI when finished. To get there:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Select UI element <code>Categorization</code> and rename it to <code>Categories</code></p>
</li>
<li>
<p>Rename composite and leaf categories as depicted here</p>
</li>
<li>
<p>Drag all table controls one by one into the suited leaf category</p>
</li>
<li>
<p>Confirm master-detail view works as expected in the preview.</p>
</li>
</ol>
</div>
</div>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
<div class="paragraph">
<p>The UI hierarchy to access tables for entity types is independent, and usually will differ, from aggregation and inheritance hierarchies present in Ecore data model (compare fig. <a href="#fig-example-model">Example Model</a>).</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Note that <em>EMF Forms Preview</em> provides these buttons <span class="image"><img src="ParameterCatalogs2Images/ViewModelPersistence.gif" alt="PreviewPersistanceButtons" width="68"></span> to clear, load and store edited data.
In fact, this feature gives us a fully functional prototype.
At least during refinement of model and UI, data sets can be created, edited, and tested for usability without the need to built a full blown, deployable application&#8201;&#8212;&#8201;see parts <em>Accessing and Using Parameter Catalogs</em> and <em>Build (Parameter Catalog) Applications with Eclipse Tycho</em> below.</p>
</div>
<div class="paragraph">
1880
1881
<p>Be aware that in some cases the view model must adapt to changes in data model, e.g. a new leaf category and table component must be created for a new catalog object type.
Other changes are automatically reflected in the generated UI, at least for default forms and default table columns.
1882
1883
1884
1885
1886
1887
1888
To our convenience, view model specifications incompatible with data model are indicated by error badges in the <em>View Editor</em>.</p>
</div>
<div class="paragraph">
<p>Changes in data model also can make existing XML data incompatible. There are tools for data migration, but for now, recreation of test data or manual editing of XML file is the way to go.</p>
</div>
</div>
</div>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1889
1890
<div class="sect2">
<h3 id="trueadd-units-to-the-mix"><a class="anchor" href="#trueadd-units-to-the-mix"></a>Add Units to the Mix</h3>
1891
<div class="paragraph">
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1892
<p>As mentioned earlier, parameter catalogs should be able to represent quantities, not just bare numbers.
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1893
1894
1895
1896
See <a href="https://onlinelibrary.wiley.com/doi/full/10.1002/spe.2926">Unit of measurement libraries, their popularity and suitability</a> for a systematic account of open source solutions in the this area.</p>
</div>
<div class="paragraph">
<p>Java provides an extensive framework to deal with quantities and their units defined in <a href="https://docs.google.com/document/d/12KhosAFriGCczBs6gwtJJDfg_QlANT92_lhxUWO2gCY/edit#heading=h.6698n7erex5o">Java Specification Request (JSR) 385</a>.
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1897
The reference implementation for this framework is <a href="https://unitsofmeasurement.github.io/indriya/">Indriya</a>. Demos of its usage can be found at <a href="https://unitsofmeasurement.github.io/uom-demos/" class="bare">https://unitsofmeasurement.github.io/uom-demos/</a>.</p>
1898
1899
</div>
<div class="paragraph">
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1900
<p>To make Indriya available Ecore data models and EMF Forms, the author has created two plug-ins that can easily be added to Eclipse. To do so, open dialog <code>Help &#8594; Install New Software&#8230;&#8203;</code> and enter site <code><a href="https://transfer.hft-stuttgart.de/pages/neqmodplus/indriya-p2/release_target_211/" class="bare">https://transfer.hft-stuttgart.de/pages/neqmodplus/indriya-p2/release_target_211/</a></code> like depicted below.</p>
1901
</div>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1902
1903
1904
<div class="imageblock thumb">
<div class="content">
<img src="ParameterCatalogs2Images/AddUpdateSite.png" alt="Install Plug-in" width="500">
1905
</div>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1906
<div class="title">Figure 20. Install Plug-in from Specific Update Site</div>
1907
1908
</div>
<div class="paragraph">
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1909
<p>Select Indriya plug-in, press <code>Next &gt;</code> and acknowledge all following dialogs, including security warnings.</p>
1910
1911
</div>
<div class="paragraph">
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1912
1913
<p>Do the same for the City Units plug-in available at site <code><a href="https://transfer.hft-stuttgart.de/pages/neqmodplus/de.hft-stuttgart.cityunits/release_target_101/" class="bare">https://transfer.hft-stuttgart.de/pages/neqmodplus/de.hft-stuttgart.cityunits/release_target_101/</a></code>
Finally, restart Eclipse to complete plug-in installation.</p>
1914
1915
</div>
<div class="paragraph">
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1916
<p>While the first plug-in installs Indriya, the second plug-in adds some specific units for urban simulation, EMF Forms editor fields for quantities, and Ecore types used for modeling quantities as attributes of classes.</p>
1917
1918
</div>
<div class="paragraph">
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1919
<p>Make the new Ecore types <code>QuantityLong</code> and <code>QuantityDouble</code> available like so:</p>
1920
1921
1922
1923
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1924
1925
1926
1927
<p>Open <code>Sample Ecore Model Editor</code> from the context menu over your Ecore model</p>
</li>
<li>
<p>From the context menu in this editor, execute <code>Load Resource&#8230;&#8203;</code> and then <code>Browse Target Platform Packages&#8230;&#8203;</code></p>
1928
1929
</li>
<li>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1930
1931
<p>Select package <code><a href="https://www.hftstuttgart.de/quantities" class="bare">https://www.hftstuttgart.de/quantities</a></code> and confirm the addition of
<code>platform:/resource/de.hftstuttgart.cityunits.model/model/Quantities.ecore</code>.</p>
1932
1933
1934
</li>
</ol>
</div>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1935
1936
1937
1938
1939
<div class="imageblock right thumb">
<div class="content">
<img src="ParameterCatalogs2Images/QuantityDoubleAttributeType.png" alt="Install Plug-in" width="300">
</div>
<div class="title">Figure 21. Set QuantityDouble Type</div>
1940
1941
</div>
<div class="paragraph">
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1942
<p>From now on, the new attribute types are available to model quantities with integer or floating point values as can be seen on the screenshot to the right.</p>
1943
1944
</div>
<div class="paragraph">
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1945
<p>Note here, that I also changed the default value from <code>0.0</code> to <code>0.0 V</code> to indicate that <code>maxDCVoltage</code> of inverters is given in <strong>Volt</strong>.</p>
1946
</div>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1947
1948
1949
1950
<div class="paragraph">
<p>The symbols for defining units follow SI and other standards, including decimal prefixes like <code>m</code> for Milli or <code>G</code> for Giga as well as derived units, that is: <code>mV</code>, <code>GV</code> or <code>kW·h/m³</code> are all valid unit definitions. This is all documented well in the resources mentioned at the top of this section, but for convenience, a table with valid units, including some specific units for urban simulation, is compiled in <a href="UnitsExamples.md" class="bare">UnitsExamples.md</a>.</p>
</div>
<div class="paragraph">
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1951
<p>If a unit symbol cannot be interpreted, this error is not already detected while generating and compiling code from model, but not before run time when the application tries to create the default value. In that case, you will see an error message like this:</p>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
</div>
<div class="imageblock thumb">
<div class="content">
<img src="ParameterCatalogs2Images/ErrorInUnitDefinition.png" alt="Install Plug-in" width="400">
</div>
<div class="title">Figure 22. Error Message for Wrong Unit Definition</div>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
<div class="paragraph">
<p>Be told that each attribute of type <code>QuantityLong</code> or <code>QuantityDouble</code> has to have a unit defined in its <code>Default Value Literal</code>, even optional attributes that do not require a numerical value to be set. For these, too, the Ecore model must specify the unit to use.</p>
</div>
<div class="paragraph">
<p>In other words: If you do not want to preset an attribute with a numerical default, you can omit the numerical part, but still must provide the unit symbol as <code>Default Value Literal</code>, e.g. <code>V</code> will work as well as <code>1.0 V</code> but leaving the numeric value initially undefined.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>One last technicality. <strong>Before</strong> code from an Ecore model with attributes of type <code>QuantityLong</code> or <code>QuantityDouble</code> can be generated correctly, we must tell Eclipse to reuse the corresponding generator model from the City Units plug-in:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
1981
<li>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1982
<p>In package or project explorer find your generator model, e.g. <code>democatalog.genmodel</code> and execute <code>Reload&#8230;&#8203;</code> from its context menu</p>
1983
1984
</li>
<li>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1985
<p>Choose <code>Ecore model</code>, press <code>Next &gt;</code> and <code>Load</code> the model (again)</p>
1986
1987
</li>
<li>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1988
<p><code>Next &gt;</code> will open the page  below. In section <em>Referenced Generator Models</em> select the Quantities generator model as depicted and click on <code>Finish</code>.</p>
1989
</li>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1990
1991
1992
1993
1994
1995
</ol>
</div>
<div class="imageblock thumb">
<div class="content">
<img src="ParameterCatalogs2Images/ReferenceGeneratorModel.png" alt="Install Plug-in" width="500">
</div>
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1996
<div class="title">Figure 23. Add Reference to Imported Generator Model</div>
1997
1998
</div>
<div class="paragraph">
Kai-Holger Brassel's avatar
Kai-Holger Brassel committed
1999
<p>If no generator model is available for selection, press button <code>Add&#8230;&#8203;</code> to add it first (this only works if <code>QuantityLong</code> or <code>QuantityDouble</code> were used at least once in the Ecore model).</p>
2000
</div>
For faster browsing, not all history is shown. View entire blame