Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This tutorial presents the Xtext framework, a toolsuite for the generation of plain text based model editors. Such textual editors provide syntax highlighting, content assist (ctrl-space), an outline, and much more out-of-the-box. You will start by creating a textual syntax for Turing Machines.

 


Table of Contents
 


Preliminaries

There's a few things to do before we dive into the tutorial itself. 

...

If you have already completed the Eclipse Modeling Framework (EMF) tutorial and created your own turing machine metamodel, you are encouraged to use it to perform this tutorial. If you did not (or if you want to start from scratch) feel free to follow the steps of this section to retrieve a working metamodel.

  1. Download the zip file with all our prepared tutorial plugins from our Stash. Unzip the file.
  2. Open the context menu within the Package-Explorer (on the very left, right-click the empty space).
  3. Select Import. Then chose General > Existing Projects into Workspace.
  4. Browse to the location where you unzipped the downloaded plug-ins. Check the check box in front of all the de.cau.cs.kieler.tutorials.klighd.* projects and press Finish.

...

  1. Go to the plugin where you created and registered TuringHeadController, the Turing Machine simulator. Open plugin.xml → Dependencies and add org.eclipse.ui if not on the list yet. Go to Extensions and add org.eclipse.ui.menus.
  2. Add a menuContribution element to the new extension and set "popup:org.eclipse.ui.popup.any?after=additions" as locationURI (without quotation marks).
  3. Add a command element to the menuContribution with the following attributes:
    • commandId: de.cau.cs.rtprak.login.setSimFile
    • label: Set Simulation File
  4. Add a visibleWhen element to the command, and add an iterate element to the visibleWhen with the following attributes:
    • operator: and
    • ifEmpty: false
  5. Add an adapt element to the iterate with the following attribute:
    • type: org.eclipse.core.resources.IResource
  6. Add a test element to the adapt with the following attributes:
    • property: org.eclipse.core.resources.extension
    • value: tuxt
  7. Add a new extension org.eclipse.ui.commands and add a command element to it with the following attributes:
    • id: de.cau.cs.rtprak.login.setSimFile
    • name: Set Simulation File
    • Click on defaultHandler to open a dialog for creation of a new handler class. Name the new class SetFileHandler and put it into some package of that plugin. Remove the suggested interface and set org.eclipse.core.commands.AbstractHandler as superclass instead.
  8. Use the following method stub for SetFileHandler (this requires a plugin dependency to org.eclipse.core.resources):

    Code Block
    languagejava
    /**
     * {@inheritDoc}
     */
    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        ISelection selection = HandlerUtil.getCurrentSelection(event);
        if (selection instanceof IStructuredSelection) {
            Object element = ((IStructuredSelection) selection).getFirstElement();
            if (element instanceof IFile) {
                IFile file = (IFile) element;
                // TODO update the static reference to the simulation file
            }
        }
        return null;
    }
  9. Add a public static field named modelFile to TuringHeadController and directly set that field in the TODO part of the execute method shown above.
  10. Use the resource set code shown in the EMF tutorial for loading model files (without the stand-alone part) in order to load the modelFile in the initialize method.
  11. Now you should be able to simulate models written in your textual syntax: start Eclipse, right-click a textual Turing Machine file (*.tuxt), select Set Simulation File, and run simulation in your Tape view using the correct controller.

...


Info

This tutorial was originally created by Christoph Daniel Schulze and Miro Spönemann for the Eclipse Project WT 12/13.