Skip to main content
Jump to: navigation, search

Difference between revisions of "STEM Create EMF Project"

(Create Generator Model (GenModel))
(How to create a JSON Logger for STEM: Tutorial demonstrating a new EMF Project)
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
= New Logger Tutorial: How to create a new EMF Project =
+
= How to create a JSON Logger for STEM =
  
  # Notes
+
'''Tutorial demonstrating a new EMF Project'''
 +
 
 +
  # Note:
 
  * I substitute "`org.eclipse.stem`" with "`o.e.s`" in places
 
  * I substitute "`org.eclipse.stem`" with "`o.e.s`" in places
  
Line 50: Line 52:
  
 
* In the `Properties` view, make the changes to these sections
 
* In the `Properties` view, make the changes to these sections
* All
+
** All
* Edit
+
** Edit
* Remove '.edit' from the Edit plug-in ID and Directory
+
*** 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)
+
*** Set Edit Plug-in Class to have the fully qualified package name (org.eclipse.stem.loggers.json)
* Editor
+
** Editor
* Remove '.editor' from Editor plug-in ID and Directory
+
*** Remove '.editor' from Editor plug-in ID and Directory
* Set Editor Plug-in to have fully qualified package name (org.eclipse.stem.loggers.json)
+
*** Set Editor Plug-in to have fully qualified package name (org.eclipse.stem.loggers.json)
* Model
+
** Model
* No changes, although discuss suppressions (incl suppress notifications)
+
*** No changes, although discuss suppressions (incl suppress notifications)
* Model Class Defaults
+
** Model Class Defaults
* Public constructors to true
+
*** 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
+
*** 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
+
** Model Feature Defaults
* No Changes
+
*** No Changes
* Templates & Merge
+
** Templates & Merge
* This is an interesting section and is used by parts of STEM to extend EMF (the Model Builder)
+
*** This is an interesting section and is used by parts of STEM to extend EMF (the Model Builder)
* No changes required right now
+
*** No changes required right now
* Next, Select the `json` EPackage
+
** Next, Select the `json` EPackage
* Set Base Package to be `org.eclipse.stem.loggers`
+
*** Set Base Package to be `org.eclipse.stem.loggers`
* Set Model / File Extension to `logger`
+
*** Set Model / File Extension to `logger`
* Save Genmodel
+
** Save Genmodel
  
 
== Run the EMF Code Generator ==
 
== Run the EMF Code Generator ==
Line 78: Line 80:
 
== Correct Errors from Code Generation ==
 
== Correct Errors from Code Generation ==
  
== Remove unneeded lines from `JsonPackage.java == `
+
* Remove unneeded lines from '''JsonPackage.java'''
* Open `src/o.e.s.loggers.json/JsonPackage.java`
+
** Open '''src/o.e.s.loggers.json/JsonPackage.java'''
* Comment out lines with errors
+
** Comment out lines with errors
* Lines 167, 176, 185, 194, 203
+
*** Lines 167, 176, 185, 194, 203
* Save `JsonPackage.java`
+
** Save '''JsonPackage.java'''
==  Fix error in `JsonEditor` ==
+
 
* Open `src/org.eclipse.stem.loggers.json.presentation/JsonEditor.java`
+
==  Fix error in JsonEditor ==
* Go to line 984, change:
+
`EditUIUtil.getURI(getEditorInput(), editingDomain.getResourceSet().getURIConverter());` to `EditUIUtil.getURI(getEditorInput());`
+
* Open `src/org.eclipse.stem.loggers.json.presentation/JsonEditor.java`
+
* Go to line 984,  
 +
change:
 +
'''EditUIUtil.getURI(getEditorInput(), editingDomain.getResourceSet().getURIConverter());'''
 +
to  
 +
'''EditUIUtil.getURI(getEditorInput());'''
  
 
== Add Extension Point definition ==  
 
== Add Extension Point definition ==  
  
Open org.eclipse.stem.loggers.json/plugin.xml
+
* Open org.eclipse.stem.loggers.json/plugin.xml
Add:
+
  
```
+
Inside the '''<plugin>''' tag
<extension point="org.eclipse.stem.core.logger">
+
Add:
<classdef class="org.eclipse.stem.loggers.json.impl.JSONLoggerImpl">
+
</classdef>
+
<dublin_core
+
category_id="/"
+
creator="%dc_creator"
+
description="%dc_descr"
+
identifier="%dc_identifier"
+
license="%dc_license"
+
publisher="%dc_publisher"
+
source="%dc_source"
+
title="%dc_title"/>
+
</extension>
+
```
+
  
inside the `<plugin>` tag
+
<extension point="org.eclipse.stem.core.logger">
 +
  <classdef class="org.eclipse.stem.loggers.json.impl.JSONLoggerImpl">
 +
  </classdef>
 +
  <dublin_core
 +
    category_id="/"
 +
    creator="%dc_creator"
 +
    description="%dc_descr"
 +
    identifier="%dc_identifier"
 +
    license="%dc_license"
 +
    publisher="%dc_publisher"
 +
    source="%dc_source"
 +
    title="%dc_title"/>
 +
</extension>
  
Next, open org.eclipse.stem.loggers.json/plugin.properties and add or update the properties to
+
* Next, open org.eclipse.stem.loggers.json/plugin.properties and add or update the properties to
  
```
+
pluginName = STEM JSON Logger
pluginName = STEM JSON Logger
+
providerName = Eclipse Foundation
providerName = Eclipse Foundation
+
 
 
dc_identifier=org.eclipse.stem.loggers.json.dublin_core
+
dc_identifier=org.eclipse.stem.loggers.json.dublin_core
dc_publisher = The Eclipse Foundation
+
dc_publisher = The Eclipse Foundation
dc_license = Eclipse Public License (EPL)
+
dc_license = Eclipse Public License (EPL)
dc_title = JSON File Logger
+
dc_title = JSON File Logger
dc_descr = STEM logger for writing the results of a simulation to a JSON formatted file
+
dc_descr = STEM logger for writing the results of a simulation to a JSON formatted file
dc_creator = STEM team
+
dc_creator = STEM team
dc_source = http://wiki.eclipse.org/STEM_Loggers
+
dc_source = http://wiki.eclipse.org/STEM_Loggers
```
+
  
== Add the new plug-in to STEM's **Run Configuration==  
+
== Add the new plug-in to STEM's '''Run Configuration''' ==  
* Go to Run menu > Run Configurations
+
 
* Select `stem2.product`, then select **Plug-ins** tab
+
* Go to Run menu > Run Configurations
* Scroll through **Plug-ins** and check `org.eclipse.stem.loggers.json`
+
* Select '''stem2.product''', then select **'''Plug-ins'''** tab
* Click **Apply** then **Close**
+
* Scroll through **Plug-ins** and check '''org.eclipse.stem.loggers.json'''
 +
* Click **Apply** then **Close**
  
 
== Test Creating Logger in STEM ==  
 
== Test Creating Logger in STEM ==  
Line 144: Line 147:
 
* Add the following lines to override the parent methods called when a loggable event occurs
 
* Add the following lines to override the parent methods called when a loggable event occurs
  
```
+
@Override
@Override
+
public void simulationEvent(SimulationEvent event) {
public void simulationEvent(SimulationEvent event) {
+
 
+
}
}
+
  
@Override
+
@Override
public void loggerEvent(ISimulation simulation, LOGGER_EVENTS 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'''
  
* 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.
+
  System.err.println("JSON Logger Event: ["+event+"]");
* 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+"]");`
+

Latest revision as of 01:38, 30 April 2016

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 JsonPackage.java
    • Open src/o.e.s.loggers.json/JsonPackage.java
    • Comment out lines with errors
      • Lines 167, 176, 185, 194, 203
    • Save JsonPackage.java

Fix error in JsonEditor

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

Add Extension Point definition

  • Open org.eclipse.stem.loggers.json/plugin.xml
Inside the <plugin> tag 
Add:
<extension point="org.eclipse.stem.core.logger">
 <classdef class="org.eclipse.stem.loggers.json.impl.JSONLoggerImpl">
 </classdef>
 <dublin_core
   category_id="/"
   creator="%dc_creator"
   description="%dc_descr"
   identifier="%dc_identifier"
   license="%dc_license"
   publisher="%dc_publisher"
   source="%dc_source"
   title="%dc_title"/>
</extension>
  • Next, open org.eclipse.stem.loggers.json/plugin.properties and add or update the properties to
pluginName = STEM JSON Logger
providerName = Eclipse Foundation
dc_identifier=org.eclipse.stem.loggers.json.dublin_core
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 = http://wiki.eclipse.org/STEM_Loggers

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/JSONLoggerImpl.java`
  • Add the following lines to override the parent methods called when a loggable event occurs
@Override
public void simulationEvent(SimulationEvent event) {

}
@Override
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