Child pages
  • KIML
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Work in Progress

This tutorial is still being worked on. Don't start working on it just yet.

Welcome to the second 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), our very own framework that connects graphical editors with layout algorithms. Once you're finished, you should be able to create new Eclipse plug-ins and know how to write layout algorithms for KIML.

ToDo

Insert link to presentation slides.

Preliminaries

There's a few things to do before we dive into the tutorial itself. For example, to do Eclipse programming, you will have to get your hands on an Eclipse installation first. Read through the following sections to get ready for the tutorial tasks.

Required Software

For this tutorial, we need you to have Eclipse and Git installed:

  1. Install Eclipse. For what we do, we recommend installing the Eclipse Modeling Tools, with a few extras. Our Wiki page on getting Eclipse has the details: simply follow the instructions for downloading and installing Eclipse and you should be set.
  2. You should already have obtained a working Git installation for the first tutorial.

General Remarks

Over the course of this tutorial, you will be writing a bit of code. Here's a few rules we ask you to follow:

  • All the  Java code you write as part of tutorials should be in packages with the prefix de.cau.cs.rtprak.login.tutorialN, where login is your login name as used for your email address at the institute. This rule will apply to all tutorials – once we start with the actual practical projects, we will choose more meaningful package name.
  • All Java classes, fields, and methods should be thoroughly documented with the standard Javadoc comment format. Javadoc comments are well supported by Eclipse through code completion, syntax highlighting, and further features that help you. The code inside your methods should also be well commented. Try to think about what kinds of information would help someone unfamiliar with your code understand it.
  • During this tutorial, we will be using Git mostly from the command line instead of using Eclipse's built-in Git support. This is because we've found Eclipse's Git support to be too unstable and buggy for us to trust it completely.

Finding Documentation

During the tutorial, we will cover each topic only briefly, so it is always a good idea to find more information online. Here's some more resources that will prove helpful:

  • Java Platform, Standard Edition 6 API Specification
    As Java programmers, you will already know this one, but it's so important and helpful that it's worth repeating. The API documentation contains just about everything you need to know about the API provided by Java6.
  • Eclipse Help System
    Eclipse comes with its own help system that contains a wealth of information. You will be spending most of your time in the Platform Plug-in Developer Guide, which contains the following three important sections:
    • Programmer's Guide
      When you encounter a new topic, such as SWT or JFace, the Programmer's Guide often contains helpful articles to give you a first overview. Recommended reading.
    • References -> API Reference
      One of the two most important parts of the Eclipse Help System, the API Reference contains the Javadoc documentation of all Eclipse framework classes. Extremely helpful.
    • References -> Extension Points Reference
      The other of the two most important parts of the Eclipse Help System, the Extension Point Reference lists all extension points of the Eclipse framework along with information about what they are and how to use them. Also extremely helpful.
  • Eclipsepedia
    The official Eclipse Wiki. Contains a wealth of information on Eclipse programming.
  • Eclipse Resources
    Provides forums, tutorials, articles, presentations, etc. on Eclipse and Eclipse-related topics.

You will find that despite of all of these resources Eclipse is still not as well commented and documented as we'd like it to be. Finding out how stuff works in the world of Eclipse can thus sometimes be a challenge. However, this does not only apply to you, but also to many people who are conveniently connected by something called The Internet. It should go without saying that if all else fails, Google often turns up great tutorials or solutions to problems you may run into. And if it doesn't, Miro and I will be happy to help you as well.

As far as KIML and layout algorithms are concerned, you can always refer to our Wiki which has a section about KIML and the KIELER layout projects. The documentation is not complete, however, so feel free to ask Miro or Christoph Daniel for help if you have questions that the documentation fails to answer.

Preparing the Repository

We have created a Git repository for everyone to do his tutorials in. You can access the repository online through our Stash tool over hereClone that repository:

  1. Open a console window and navigate to an empty directory that the repository should be placed in.
  2. Enter the command   git clone ssh://git@git.rtsys.informatik.uni-kiel.de:7999/PRAK/13ss-layout-tutorials.git .   (including the final dot, which tells git to clone the repository into the current directory instead of a subdirectory)
  3. You should now have a clone of the repository in the current directory.

You will use this repository for all your tutorial work, along with everyone else. To make sure that you don't interfere with each other, everyone will work on a different branch. This is not exactly how people usually use Git, but goes to demonstrate Git's flexibility... Add a branch for you to work in:

  1. Enter   git checkout -b login_name

You have just added and checked out a new branch. Everything you commit will go to this branch. To push your local commits to the server (which you will need to do so we can access your results), do the following:

  1. Enter   git push origin login_name

You would usually have to enter git pull first, but since nobody will mess with your branch anyway this won't be necessary. By the way, you only need to mention origin login_name with the first git push, since Git doesn't know where to push the branch yet. After the first time, Git remembers the information and it will be enough to just enter git push.

Finding the KIML Sources

If you want to develop a layout algorithm using KIML, you will have to get your hands at the KIML source code first. Of course, the code is available through a Git repository.

  1. Open a console window and navigate to an empty directory that the repository should be placed in.
  2. Enter the command   git clone ssh://git@git.rtsys.informatik.uni-kiel.de:7999/KIELER/pragmatics.git .
  3. You should now have a clone of the repository in the current directory.

KIML is implemented as an Eclipse plug-in that you will have to import into your Eclipse workspace. We won't do this now; it will be one of the first steps in the development of your layout algorithm.

Developing Your First Layout Algorithm

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 KIML; thinking of and implementing cool layout algorithms is what the rest of the practical will focus on, and that is where the fun will be had!

Remember to replace each occurrence of login_name with your own login name (e.g. msp), and each occurrence of Login_name with your capitalized login name (e.g. Msp).

Setting Up Your Workspace

You will start by importing the plug-ins necessary to program with KIML.

  1. Start Eclipse and create a new workspace.
  2. Setup your workspace as explained in this guide.

Adding a New Plug-in

 

Writing the Layout Algorithm

 

 

 

This exercise will introduce the usage of the Eclipse Plugin Development Environment for developing new layout algorithms to be used in Eclipse diagram editors. Replace each <login> by your own login name (e.g. msp), and each <Login> by your login name with capitalized first letter (e.g. Msp). For any questions contact msp.

  1. Install and set up Eclipse (TODO: describe steps to install and set up Eclipse)
  2. Import the following KIELER plugins: (TODO: describe steps to access and import the KIELER plugins and update the list)
    • de.cau.cs.kieler.core
    • de.cau.cs.kieler.core.kgraph
    • de.cau.cs.kieler.kiml
    • de.cau.cs.kieler.kiml.service
    • de.cau.cs.kieler.kiml.ui
    • de.cau.cs.kieler.klay.layered
  3. Create a new plugin
    1. File → New  Other...  Plug-in Development  Plug-in Project
    2. Project name: de.cau.cs.rtprak.<login>.tutorial2
    3. Next  set version to 0.1.0.qualifier, provider to Christian-Albrechts-Universität zu Kiel, and execution environment to J2SE-1.5 (do this for all plugins that you create!)
    4. The checkboxes in the Options group can be deactivated -> Finish
  4. Commit the new plugin project (TODO: describe steps to commit plugin projects)
  5. Open the file META-INF/MANIFEST.MF  Dependencies tab
    • Add the plugins de.cau.cs.kieler.core and de.cau.cs.kieler.kiml to the list of dependencies, then save the file.
  6. Create a layout provider class with the New  Class wizard
    • Package: de.cau.cs.rtprak.<login>.tutorial2
    • Name: <Login>LayoutProvider
    • Superclass: de.cau.cs.kieler.kiml.AbstractLayoutProvider
  7. Implement the layout provider class
    1. Add the following constant to the class:
    2.     /** default value for spacing between nodes. */
          private static final float DEFAULT_SPACING = 15.0f;
      
    3. Write the following lines at the beginning of the doLayout method:
              progressMonitor.begin("<Login> Layouter", 1);
              KShapeLayout parentLayout = layoutNode.getData(KShapeLayout.class);
              float objectSpacing = parentLayout.getProperty(LayoutOptions.SPACING);
              if (objectSpacing < 0) {
                  objectSpacing = DEFAULT_SPACING;
              }
              float borderSpacing = parentLayout.getProperty(LayoutOptions.BORDER_SPACING);
              if (borderSpacing < 0) {
                  borderSpacing = DEFAULT_SPACING;
              }
      
    4. Write the following line at the end of the doLayout method:
              progressMonitor.done();
      
    5. Implement the rest of the layouter such that the nodes of the input graph are all put in a row.
      • See the KGraph and KLayoutData data structures: the input is a KNode and holds the nodes of the graph in its list of children
      • Iterate over the nodes in the getChildren() list of the layoutNode input
      • Retrieve the size of a node using the following code:
                KShapeLayout nodeLayout = node.getData(KShapeLayout.class);
                float width = nodeLayout.getWidth();
                float height = nodeLayout.getHeight();
        
      • Set the position (x, y) of a node's upper left corner using the following code:
                nodeLayout.setXpos(x);
                nodeLayout.setYpos(y);
        
      • objectSpacing shall be the spacing to be left between each pair of nodes.
      • borderSpacing shall be the spacing to be left to the borders of the drawing: the first node's coordinates shall be (borderSpacing, borderSpacing).
      • At the end of the method, set the width and height of parentLayout so that it is large enough to hold the whole drawing, including borders.
      • Edges may be ignored for now.
  8. Open the file META-INF/MANIFEST.MF  Extensions tab
    1. Add an extension for de.cau.cs.kieler.kiml.layout.layoutProviders
    2. Right-click the extension  New  layoutProvider
    3. Set name to <Login> Test Layouterclass to de.cau.cs.rtprak.<login>.tutorial2.<Login>LayoutProvider
    4. Right-click the new layoutProvider  New  knownOption, set option to de.cau.cs.kieler.spacing
    5. Add another knownOption, set to de.cau.cs.kieler.borderSpacing
  9. Run  Run Configurations...  right-click Eclipse Application  New
    1. Name: Layout
    2. For testing the layouter, a new workspace location will be created; you may configure its destination in Workspace Data  Location
    3. Add the program arguments -debug -consoleLog in the Arguments tab.
    4. Go to Plug-ins tab, select Launch with: plug-ins selected below only
    5. Deselect All, activate Workspace checkbox, Add Required Plug-insApplyRun
  10. Test the layouter in the new Eclipse instance:
    1. New  Project...  General  Project, name test
    2. Right-click test project  New  Other...  KEG Diagram (TODO: if graphs shall be created in another way, describe it here)
    3. Create a graph using the palette on the right.
    4. Window  Show View  Other...  KIELER  Layout
    5. While the graph diagram is open, set Layout Provider or Type in the Layout view to <Login> Test Layouter.
    6. Open the additional views Layout Graph and Layout Time.
    7. Trigger layout with the KIELER Layout button in the toolbar or Ctrl+R L (first Ctrl+R, then L).
    8. See the direct input and output of your algorithm in the Layout Graph view.
    9. See the execution time analysis in the Layout Time view.
  11. Implement another class EdgeRouter.
    1. Add the following method:
          /**
      * Route the edges that are connected with the children of the given node.
      * @param parentNode the parent node of the input graph
      */
      public void routeEdges(final KNode parentNode) {
      getMonitor().begin("Edge Routing", 1);

      getMonitor().done();
      }
    2. Add the following code to the end of the doLayout method in your layout provider:
              EdgeRouter edgeRouter = new EdgeRouter();
              edgeRouter.routeEdges(layoutNode);
      
    3. Implement the routeEdges method:
      • Each edge shall be drawn with three line segments: one vertical segment starting below the source node, one horizonzal segment, and another vertical segment ending below the target node.
      • The horizontal segments of two different edges shall not have the same y-coordinate; for consecutive edges, the distance between their horizontal segments shall equal objectSpacing.
      • See the attached image test-drawing.png for an example.
      • Find the edges using getOutgoingEdges() or getIncomingEdges() on a node.
      • Get the edge layout of an edge to set bend points using this code:
                KEdgeLayout edgeLayout = edge.getData(KEdgeLayout.class);
        
      • Create a bend point using this code:
                KPoint point = KLayoutDataFactory.eINSTANCE.createKPoint();
        
      • Use the getBendPoints() list on the edgeLayout to add bend points (clear the list first to remove points from the previous layout).
      • Set the values of the points returned by getSourcePoint() and getTargetPoint() according to the positions where the edge leaves its source node and reches its target node.
  12. Use your previous run configuration to test the edge router.
  • No labels