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:
- Click File > New > Other... > Plug-in Development > Plug-in Project.
- Enter
de.cau.cs.kieler.simplelayout
as the project name. Click Next. - Set the execution environment to J2SEJavaSE-1.58. (do this for all plug-ins that you create!)
- Uncheck all checkboxes in the Options group and click Finish.
- If Eclipse asks you whether the Plug-in Development perspective should be opened, choose either Yes or No. It doesn't make much of a difference anyway.
...
- In your new plug-in, open the file
META-INF/MANIFEST.MF
. The plug-in manifest editor will open. Open its Dependencies tab. - Add dependencies to the following plug-ins:
deorg.caueclipse.cselk.kieler.core
deorg.caueclipse.cs.kieler.core.kgraph
de.cau.cs.kieler.kiml
elk.graph
- Save the editor.
Layout algorithms interface with KIML ELK by means of a layout provider class that has to be created and registered with KIML.
- Right-click the source folder of your plug-in and click New > Class.
- Set the package to
, enterde.cau.cs.kieler.simplelayout
SimpleLayoutProvider
as the class name, and selectdeorg.caueclipse.cselk.kielercore.kiml.AbstractLayoutProvider
as the superclass. (This will only be available through the Browse dialog if you have saved the plug-in manifest editor; if you haven't, Eclipse won't know about the new dependencies yet.) - Select Generate comments and click Finish.
...
Add the following constants:
Code Block language java /** default value for spacing between nodes. */ private static final float DEFAULT_SPACING = 15.0f;
Use the following code as the skeleton of the doLayoutthe
layout(...)
method:Code Block language java progressMonitor.begin("Simple layouter", 1); KShapeLayout parentLayout = parentNodelayoutGraph.getData(KShapeLayout.class); float objectSpacing = parentLayout.getProperty(LayoutOptionsCoreOptions.SPACING_NODE); if (objectSpacing < 0) { objectSpacing = DEFAULT_SPACING; } float borderSpacing = parentLayout.getProperty(LayoutOptionsCoreOptions.SPACING_BORDER_SPACING); if (borderSpacing < 0) { borderSpacing = DEFAULT_SPACING; } // TODO: Insert actual layout code. progressMonitor.done();
- Press CTRL+SHIFT+O or select Source > Organize Imports from the context menu to add all required imports.
- It is now time to write the code that places the nodes.Your code should place them next to each other in a row, as seen in the screenshot at the beginning of the tutorial.
...
Before you can test your layout code, you will have to register your new layout provider with KIML.ELK.
- Right-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" metadataClass SimpleMetaDataProvider } algorithm simple(SimpleLayoutProvider) { label "Simple Test Layouter" metadataClass SimpleOptions 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 defor
org.caueclipse.cselk.kielercore.kiml.layout.layoutProviders
. - Right-click the extension and click New > layoutAlgorithm provider.
- Set the name to
Simple Test Layouter
and the class to your layout bundle's meta data provider class name (use the browse button and enterSimpleLayoutProvider
SimpleMetaDataProvider
). - Right-click the new layoutAlgorithm and click New > knownOption. Set option to
de.cau.cs.kieler.spacing
. - Add another knownOption for
de.cau.cs.kieler.borderSpacing
.Note thatSimpleMetaDataProvider
is automatically generated from the .elkm file you created. Its name is specified by themetadataClass
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
We will now have to add a new run configuration that will start an Eclipse instance with your layout code loaded into the application, ready to be used.
- Click Run > Debug Configurations...
- Right-click Eclipse Application and click New. Set the configuration's name to
Layout Test
. - In the Arguments tab, make sure the the program arguments include
-debug
and-consoleLog
. - On the Plug-ins tab, set Launch with to plug-ins selected below only.
- Click Deselect All.
- Check the Workspace item in the tree.
- Check the following plugins under Target Platform are checked:
de.cau.cs.kieler.
kgraph.text.ui
de.cau.cs.kieler.klighd.xtext
org.eclipse.ui.ide.application
org.eclipse.platform
- Click Add Required Plug-ins. Press it twice (just to be sure!).
- Click Apply to save your changes and then Debug to start an Eclipse instance to test with.
Test the layouter in your new Eclipse instance:
- Click the green button with the yellow thunderbold and check the Enable view management and all other checkboxes.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 diagram. Another view with graphical representations of the nodes should pop up..kgt file. To show up the Diagram vie, select Window > Show View > Other... > Other > Diagram
- Open the Layout view through Window > Show View > Other... > KIELER 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
...
Info | |||||||
---|---|---|---|---|---|---|---|
| |||||||
Here's a few tips for implementing the edge routing:
|
Once you're done implementing the edge routing code, test it by running your debug configuration again, as before.