Learn how to use the EMF modelling framework with eMoflon::IBeX
Sokoban(Japanese for warehouse keeper) is a cool puzzle game, in which you(thesokoban) 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 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.
Click on Help → Install New Software.
Paste this update siteinto the EclipseInstallationManager
Select eMoflon IBeX::Democlesand make sure that“Contact all update sites during install…” is selected.
Before clicking onNext, you have to enable allnewly added updatesites. To do this click on Manage, select all sites as indicated in the screenshot below, and clickApply and Close. If you skip this step, the installation will fail due to missing dependencies.
Start the installation 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.
Switch to the eMoflon perspective:
To confirm that the installation was successful, open the eMoflon perspective by choosing Window → Open Perspective → Other…
Choose eMoflon from the list and click Open.
If everything went well, your workspace should now look like this(new featuresoutlined in red).
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 to get it running(but you might be lucky and already have this installed on your system).
Create a new meta-model
Create an eMoflon EMF Projectby clicking on the the new wizard button in the toolbar(the one with a project and a cute little plug/adapter symbol).
Choose“SokobanLanguage”as project name and click Finish. Don’t be creative here and just do as you’re told so everything else works later(you’ve been warned).
In the newly created project, navigate to the .ecore file under /model and double-click it to open the Sample Ecore Editor:
Add concepts and relations for Sokoban
Creating concepts as classes
Add your first EClass by right clickingthe SokobanLanguage package, going toNew Child and choosingEClass:
Choose the newly created EClass in the editor and enter“Block” as namein the Properties viewbelow the editor(marked in the screenshot). Leave all other properties as they are for the moment.
Click on the PlantUML view to set focus to it(and bring it infront of the Outline view). As from now, 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.
Now that you know how to add classes, go ahead and addBoard, Boulder, Field, Figure and of course Sokoban.
Make the Figureabstract by selecting it, and then settingits property Abstracttotrue.
Adding super classes
MakeBlock inherit from Boulder by selectingBlock,going to ESuperTypes under Properties, and selecting the little button to the right of the property entry. This should pop-up an extra window from which you can chooseBoulder as a super class. Click Add and finally click OK.
Repeat this step to make Boulder and Sokobaninherit from Figure. Your editor should look something like this:
Now is probably a good time to play around with the visualisation. 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?
Creating parent-child relations as containmentreferences