...
The generated code includes a parser for text files in your syntax. This parser is simply used with the same interface as for any other EMF models: resource sets. Your final task for this tutorial is to reuse the Turing controller you implemented in the EMF tutorial for simulating Turing Machine models, this time applying it to .tuxt
text files. However, instead of using a fixed path to your model file, we will now use a menu contribution in order to set the file path dynamically. This contribution will be put into the popup menu of the Navigator / Project Explorer view by configuring a visibility expression that tests the currently selected (right-clicked) elements. The contribution shall only be visible if the selected files have the extension tuxt, which is assigned to our mighty textual syntax.
- Go to the plugin where you created and registered
TuringHeadController
, the Turing Machine simulator. Openplugin.xml
→ Dependencies and add org.eclipse.ui if not on the list yet. Go to Extensions and add org.eclipse.ui.menus. - Add a menuContribution element to the new extension and set "popup:org.eclipse.ui.popup.any?after=additions" as locationURI (without quotation marks).
- Add a command element to the menuContribution with the following attributes:
- commandId: de.cau.cs.rtprak.login.setSimFile
- label: Set Simulation File
- Add a visibleWhen element to the command, and add an iterate element to the visibleWhen with the following attributes:
- operator: and
- ifEmpty: false
- Add an adapt element to the iterate with the following attribute:
- type: org.eclipse.core.resources.IResource
- Add a test element to the adapt with the following attributes:
- property: org.eclipse.core.resources.extension
- value: tuxt
- 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 setorg.eclipse.core.commands.AbstractHandler
as superclass instead.
Use the following method stub for
SetFileHandler
:Code Block theme Eclipse language java /** * {@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; }}
- Add a public static field named
modelFile
toTuringHeadController
and directly set that field in the TODO part of theexecute
method shown above. - 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 theinitialize
method. - 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.