<
From version < 9.1 >
edited by msp
on 2012/10/31 21:47
To version < 10.1 >
edited by msp
on 2012/10/31 22:02
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -66,7 +66,7 @@
66 66  
67 67  = Parsing =
68 68  
69 -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 {{code language="none"}}.tuxt{{/code}} 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.
69 +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 {{code language="none"}}.tuxt{{/code}} 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.
70 70  
71 71  1. Go to the plugin where you created and registered {{code language="none"}}TuringHeadController{{/code}}, the Turing Machine simulator. Open {{code language="none"}}plugin.xml{{/code}} → //Dependencies// and add org.eclipse.ui if not on the list yet. Go to //Extensions// and add org.eclipse.ui.menus.
72 72  1. Add a //menuContribution// element to the new extension and set "popup:org.eclipse.ui.popup.any?after=additions" as //locationURI// (without quotation marks).
... ... @@ -89,20 +89,25 @@
89 89  Use the following method stub for SetFileHandler{{code language="none"}}{{/code}}:
90 90  
91 91  {{code theme="Eclipse" language="java"}}
92 - /**
93 - * {@inheritDoc}
94 - */
95 - @Override
96 - public Object execute(ExecutionEvent event) throws ExecutionException {
97 - ISelection selection = HandlerUtil.getCurrentSelection(event);
98 - if (selection instanceof IStructuredSelection) {
99 - Object element = ((IStructuredSelection) selection).getFirstElement();
100 - if (element instanceof IFile) {
101 - IFile file = (IFile) element;
102 - // TODO update the static reference to the simulation file
103 - }
104 - }
105 - return null;
106 - }
92 +/**
93 + * {@inheritDoc}
94 + */
95 +@Override
96 +public Object execute(ExecutionEvent event) throws ExecutionException {
97 + ISelection selection = HandlerUtil.getCurrentSelection(event);
98 + if (selection instanceof IStructuredSelection) {
99 + Object element = ((IStructuredSelection) selection).getFirstElement();
100 + if (element instanceof IFile) {
101 + IFile file = (IFile) element;
102 + // TODO update the static reference to the simulation file
103 + }
104 + }
105 + return null;
106 +}
107 107  {{/code}}
108 108  )))
109 +1. Add a public static field named {{code language="none"}}modelFile{{/code}} to {{code language="none"}}TuringHeadController{{/code}} and directly set that field in the TODO part of the {{code language="none"}}execute{{/code}} method shown above.
110 +1. Use the resource set code shown in the EMF tutorial for loading model files (without the stand-alone part) in order to load the {{code language="none"}}modelFile{{/code}} in the {{code language="none"}}initialize{{/code}} method.
111 +1. 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.
112 +
113 +\\
Confluence.Code.ConfluencePageClass[0]
Id
... ... @@ -1,1 +1,1 @@
1 -2982426
1 +2982428
URL
... ... @@ -1,1 +1,1 @@
1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/2982426/Textual Modeling with Xtext
1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/2982428/Textual Modeling with Xtext