Meta-Modelling with eMoflon::IBeX
Learn how to use the EMF modelling framework with eMoflon::IBeX

Sokoban (Japanese for warehouse keeper) is a cool puzzle game, in which you (the sokoban) have to push boxes to designated end positions.  The warehouse is typically littered with unmovable boulders to make things more challenging.  In this first part of our handbook we’ll concentrate on modelling the concepts and relations required to describe this game using EMF and eMoflon::Core, which provides a few extra goodies to make working with EMF more easy and enjoyable.  eMoflon::Core is part of the eMoflon::IBeX tool suite, which also supports unidirectional and bidirectional model transformation via graph transformations.    

To enjoy this handbook you should have very basic knowledge of Eclipse, Java, and more or less of meta-modelling in general (we won’t explain what exactly a meta-model is).

Install eMoflon::IBeX

  1. Install Eclipse Modeling Tools.  Make sure you take Eclipse Modeling.  We always try to support the very latest version of Eclipse so go ahead and take the latest.
  1. Install eMoflon::IBeX:
  • Click on HelpInstall New Software.
  • Paste this update site into the Eclipse Installation Manager
  • Select eMoflon IBeX::Democles and make sure that “Contact all update sites during install…” is selected. 
  • Before clicking on Next, you have to enable all newly added update sites.  To do this click on Manage, select all sites as indicated in the screenshot below, and click Apply and Close.  If you skip this step, the installation will fail due to missing dependencies.
  • Start the installation (you might have to select the eMoflon IBeX::Democles update site again in the drop-down menu)  by clicking Next.  This might take some time depending on your internet connection.  To speed things up you could try deactivating some standard Eclipse update sites (such as The Eclipse Project Updates), which you don’t need right now for the installation.
  1. Switch to the eMoflon perspective:
  • To confirm that the installation was successful, open the eMoflon perspective by choosing WindowOpen PerspectiveOther…
  • Choose eMoflon from the list and click Open.
  • If everything went well, your workspace should now look like this (new features outlined in red).
  1. Make sure PlantUML is installed and configured properly:  Note the PlantUML view to the right of the editor area directly beside the standard Outline view.  We use PlantUML a lot for visualising all kind of stuff and you’ll have to install Graphviz yourself to get it running (but you might be lucky and already have this installed on your system).
  1. For this handbook, we’ll be using Emfatic as a lightweight, textual concrete syntax for meta modelling with Ecore.  As a final installation step, navigate again to  HelpInstall New Software and filter the available update sites for “Emfatic”.  You should be able to find a single currently disabled update site http://download.eclipse.org/emfatic/update.  Enable it and click Apply and Close.  Now choose this new update site in the installation manager, install it, and restart your Eclipse instance.  If no “categorized items” were found you might have to append “/site.xml” to the update site, i.e., use http://download.eclipse.org/emfatic/update/site.xml instead (seems to be sometimes the case on Mac OS X).

Create a new meta-model

  1. Create an eMoflon EMF Project by clicking on the new wizard button in the toolbar (the one with a project and a cute little plug/adapter symbol).
    
  1. Choose SokobanLanguage” as project name and click Finish.  Leave all default settings as they are.  Don’t be creative here and just do as you’re told so everything else works later (you’ve been warned).
  1. In the newly created project, navigate to the .emf file under /model and double-click it to open the Emfatic editor and outline:
  1. To automate the process of generating Java code from this file every time you save it, go to Window → Preferences (Eclipse → Preferences on a Mac) and filter for “Emfatic”.  Check the box that says “Automatically … when saving emfatic … file”.  Choose Apply and Close.  

Add concepts and relations for Sokoban

Creating concepts as classes

  • Add your first EClass by appending the following to the Emfatic file:
class Block {

}
  • Now that you know how to add classes, go ahead and add Board, Boulder, Field, Figure, and of course Sokoban.
  • Make Figure abstract by prepending the keyword abstract to the class.  

Adding super classes

  • Make Block inherit from Boulder by adding extends Boulder” after its name (just like with Java).   Note that you can get code completion by typing the first few letters, e.g., “Bo” and then pressing Ctrl + “.” repeatedly to cycle through completions.
  • Repeat this step to make Boulder and Sokoban inherit from Figure.
  • Now is probably a good time to play around with our visualisation.  Open the Ecore file SokobanLanguage.ecore that is beside SokobanLanguage.emf.  Click on the PlantUML view to set focus to it (and bring it infront of the Outline view).  As from now on, always look in the view to see what is being visualised.  For meta-models we provide a helpful class diagram visualisation that adjusts itself to what you select in the editor.  If you select the root element the entire meta-model is visualised, if you select a set of elements only these elements and their direct neighbours are visualised.  This is pretty awesomely helpful when trying to make sense of a huge meta-model with scores of classes.  Choose the root node in the editor to visualise the entire meta-model (see the screenshot below).  See what happens when you only choose one of the classes.  How about choosing two?  Be careful not make any changes to your meta model in the tree editor; while you could use this tree editor for meta modelling, we prefer to use the textual syntax for editing and the tree editor and visualisation for inspecting and viewing a meta model.  Arrange your workspace as necessary for working productively with all these editors and views (see our suggestion below):

Creating parent-child relations as containment references

  • Make Boards contain Fields by creating a so called containment reference “fields”: 
class Board {