Welcome to this tutorial! We will work our way through installing a proper Eclipse setup and developing a first very basic layout algorithm. The layout algorithm will integrate with KIML (KIELER Infrastructure for Meta-Layout ELK (Eclipse Layout Kernel), our very own framework that connects graphical editors with layout algorithms. Once you're finished, you should be able to write layout algorithms for KIMLELK. And you should have a running Eclipse-based application that should look something like this:
...
Now that the preliminaries are out of the way, it's time to develop your first layout algorithm! It will, however, be a very simple one. This tutorial focuses on creating Eclipse plug-ins and on learning how to develop with KIMLELK.
Adding a New Plug-in
We need to create a new plug-in to implement the layout algorithm in. Switch back to the Java or Plug-in Development perspective and follow these steps:
...
Layout algorithms interface with KIML ELK by means of a layout provider class that has to be created and registered with KIML.
...
Before you can test your layout code, you will have to register your new layout provider with KIMLELK.
- RicktRight-click the
package and select New > File.de.cau.cs.kieler.simplelayout
- Create a file simple.elkm and double click it to open it.
- When asked whether you want to add the Xtext nature, select yes.
The file is used to specify meta information for your layout algorithm. For this, copy the following code snippet into your editor:
Code Block language java package de.cau.cs.kieler.simplelayout bundle { label "Simple Layout Algoritms" classmetadataClass SimpleOptionsSimpleMetaDataProvider } algorithm simple(SimpleLayoutProvider) { label "Simple Test Layouter" metadataClass SimpleOptions supports supports org.eclipse.elk.spacing.border supports org.eclipse.elk.spacing.node }
- You still have to register the file with Eclipse. Open the
META-INF/MANIFEST.MF
file again and switch to the Extensions tab. - Add an extension for
org.eclipse.elk.core.layoutProviders
. - Right-click the extension and click New > provider.
- Set the class to your layout bundle's meta data provider class name (use the browse button and enter
SimpleOptions
SimpleMetaDataProvider
). Note thatSimpleOptions
SimpleMetaDataProvider
is automatically generated from the .elkm file you created. Its name is specified by theclass
metadataClass
keyword in thebundle
section. What is also created is theSimpleOptions
class, which contains everything you need to access layout options from within your layout algorithm. - Save the editor
- Your workspace should look similar to this
...
- Click New > Project... > General > Project and set the project name to something like
Test
. - Right-click the new project and click New > Other > KGraph > Random KGraph. Enter a meaningful name and click Finish.
- Open the .kgt file. To show up the Diagram vie, seöect select Window > Show View > Other... > Other > Diagram
- Open the Layout view through Window > Show View > Other... > Eclipse Diagram Layout > Layout. Move the view somewhere such that you can see the view and the diagram simultaneously.
- Chose your Simple Test Layouter in the Layout Algorithm section of the Layout View. (If the Layout View shows no properties, click the white background in the Diagram View once.)
- You should see something similar to this
...
Once you're done implementing the edge routing code, test it by running your debug configuration again, as before.