...
- Right-click in the Package Explorer and select New -> Other. From the list, select KIELER Lightweight Diagrams -> KLighD Project.
- Give your new project a proper name and select the base element of the model you want to visualize. Here's what you should enter here before clicking Finish:
Programming the Visualization
...
- Note that we ask the wizard to create a menu item for files with the
.turingmachine
extension. Those will be the files we save our Turing machines in.
If you have followed these steps, the wizard will have created a new project and opened a file that contains a skeleton synthesis. Let's take a minute to examine a few of the files in that project.
There are two source files in the de.cau.cs.kieler.tutorials.klighd.turingvis
package. The first, OpenDiagramHandler
, implements the logic required to open a KLighD view on a file or model element. The second, TuringMachineDiagramSynthesis
, implements the skeleton of the synthesis we will be writing.
So now we have these two files lying around, which is nice. But KLighD doesn't know that it's supposed to invoke the synthesis to turn Turing machines into diagrams, and Eclipse doesn't know that it's supposed to display commands in context menus. That's what the plugin.xml
file in the project's root directory is for. In there, the synthesis is registered with KLighD, and the menu command is registered with Eclipse.
Programming the Visualization
We will now start filling in the synthesis skeleton, so open the TuringMachineDiagramSynthesis
class:
Code Block | ||||
---|---|---|---|---|
| ||||
/* Package and import statements... */ class TuringMachineDiagramSynthesis extends AbstractDiagramSynthesis<TuringMachine> { @Inject extension KNodeExtensions @Inject extension KEdgeExtensions @Inject extension KPortExtensions @Inject extension KLabelExtensions @Inject extension KRenderingExtensions @Inject extension KContainerRenderingExtensions @Inject extension KPolylineExtensions @Inject extension KColorExtensions extension KRenderingFactory = KRenderingFactory.eINSTANCE override KNode transform(TuringMachine model) { val root = model.createNode().associateWith(model); // Your dsl element <-> diagram figure mapping goes here!! return root; } } |
...