Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: for the plan.

Jump to: navigation, search

STEM Create EMF Project

How to create a JSON Logger for STEM

Tutorial demonstrating a new EMF Project

# Note:
* I substitute "`org.eclipse.stem`" with "`o.e.s`" in places

Create an EMF Project

1. File -> New -> Eclipse Modeling Framework -> Empty EMF Project 2. Project Name: `org.eclipse.stem.loggers.json`

(note: another way to do this it to create the EMF model from a regular (non-EMF) project, then use the code generator to generate the EMF project. This can be useful if you're experimenting and will need to delete

Create Ecore Model

  1. File > New > Other > EMF -> Ecore Model. Click **Next**.
  2. Enter name `json.ecore`. **Finish**.
  3. The **EMF Ecore Model Editor** should now open
  4. Load Resource references:
    1. Right click, **Load Resources** > **Browse Workspace**
    2. Select `o.e.s.loggers/model/SimulationLogger.ecore`
  5. Set EPackage details. Select the (empty) EPackage in the editor
    1. Name: `json2`
    2. Ns Prefix: `org.eclipse.stem.loggers.json`
    3. NS URI: `http:///org/eclipse/stem/loggers/json`
  6. Create EClass
    1. Right click on `json` EPackage > New Child -> EClass
    2. Name: `JsonLogger`
    3. ESuper Type: `SynchronousDecoratorPropertyLogger`
  7. Add new `logPath` EAttribute to `JsonLogger`
    1. Right click on `JsonLogger` > New Child -> EAttribute
    2. Name: `logPath`
    3. EType: `EString`
  8. Add new `prettyPrint` EAttribute to EClass
    1. Name: prettyPrint
    2. EType: EBoolean
    3. Default value literal: false
  9. Save `json.ecore`

Create Generator Model (GenModel)

  1. Right click on the `json.ecore` file
  2. File > New > Other > EMF > EMF Generator Model. **Next**
  3. File name: `json.genmodel` in the `o.e.s.loggers.json/model` folder. **Next**
  4. Model importer; **Ecore Model**. **Next**
  5. Select `json.ecore` and click **Load**. **Next**
  6. Select the appropriate packages:
    1. Root packages (top): `json`
    2. Referenced generator models (bottom): Select the require ones (until errors go away)
    3. Click **Finish**

Customize the Generator Model (Tricky)

  • In the `Properties` view, make the changes to these sections
    • All
    • Edit
      • Remove '.edit' from the Edit plug-in ID and Directory
      • Set Edit Plug-in Class to have the fully qualified package name (org.eclipse.stem.loggers.json)
    • Editor
      • Remove '.editor' from Editor plug-in ID and Directory
      • Set Editor Plug-in to have fully qualified package name (org.eclipse.stem.loggers.json)
    • Model
      • No changes, although discuss suppressions (incl suppress notifications)
    • Model Class Defaults
      • Public constructors to true
      • Set `Root Extends Class` to `org.eclipse.emf.ecore.impl.EObjectImpl` (the current default refers to new EMF behavior that is not understood or tested
    • Model Feature Defaults
      • No Changes
    • Templates & Merge
      • This is an interesting section and is used by parts of STEM to extend EMF (the Model Builder)
      • No changes required right now
    • Next, Select the `json` EPackage
      • Set Base Package to be `org.eclipse.stem.loggers`
      • Set Model / File Extension to `logger`
    • Save Genmodel

Run the EMF Code Generator

  • Right click on the GenModel (Top icon)
  • Select Generate Model > Generate All

Correct Errors from Code Generation

  • Remove unneeded lines from
    • Open src/o.e.s.loggers.json/
    • Comment out lines with errors
      • Lines 167, 176, 185, 194, 203
    • Save

Fix error in JsonEditor

  • Open `src/org.eclipse.stem.loggers.json.presentation/`
  • Go to line 984,
EditUIUtil.getURI(getEditorInput(), editingDomain.getResourceSet().getURIConverter());

Add Extension Point definition

  • Open org.eclipse.stem.loggers.json/plugin.xml
Inside the <plugin> tag 
<extension point="org.eclipse.stem.core.logger">
 <classdef class="org.eclipse.stem.loggers.json.impl.JSONLoggerImpl">
  • Next, open org.eclipse.stem.loggers.json/ and add or update the properties to
pluginName = STEM JSON Logger
providerName = Eclipse Foundation
dc_publisher = The Eclipse Foundation
dc_license = Eclipse Public License (EPL)
dc_title = JSON File Logger
dc_descr = STEM logger for writing the results of a simulation to a JSON formatted file
dc_creator = STEM team
dc_source =

Add the new plug-in to STEM's Run Configuration

  • Go to Run menu > Run Configurations
  • Select stem2.product, then select **Plug-ins** tab
  • Scroll through **Plug-ins** and check org.eclipse.stem.loggers.json
  • Click **Apply** then **Close**

Test Creating Logger in STEM

  • Launch STEM
  • Click the new Logger wizard, JSON File Logger should be in the list. Select it

* Notice how the names in the wizard aren't really filled out yet. This is because we haven't hooked in the UI adapters yet. You can create the logger without these UI hooks, but the display (and NLS-supported) names don't show up

Implement the Logger

  • Open `o.e.s.loggers.json.impl/`
  • Add the following lines to override the parent methods called when a loggable event occurs
public void simulationEvent(SimulationEvent event) {

public void loggerEvent(ISimulation simulation, LOGGER_EVENTS event) {

  • The loggerEvents(...) method receives notifications of logger events, including the creation of a new simulation that has a logger, the enabling or disabling of loggers, etc.
  • The simulationEvent(...) method receives notifications of simulation events.
  • To see a stream of events being received by the logger in the console, add the following to simulationEvent
System.err.println("JSON Logger Event: ["+event+"]");

Back to the top