Example: Implement a flowchart GMF editor using EuGENia

@namespace(uri="flowchart", prefix="flowchart")
package flowchart;

@gmf.diagram(foo="bar")
class Flowchart {
   val Node[*] nodes;
   val Transition[*] transitions;
}

@gmf.node(label="name", label.icon="false")
abstract class Node {
   attr String name;
   ref Transition[*]#source outgoing;
   ref Transition[*]#target incoming;
}

@gmf.link(label="name", source="source", target="target", target.decoration="arrow")
class Transition {
   attr String name;
   ref Node#outgoing source;
   ref Node#incoming target;
}

class Subflow extends Flowchart, Node{
   
}

@gmf.node(figure=
  "org.eclipse.epsilon.eugenia.examples.flowchart.diagram.figures.SquareFigure")
class Action extends Node {
   
}

@gmf.node(figure=
  "org.eclipse.epsilon.eugenia.examples.flowchart.diagram.figures.DiamondFigure")
class Decision extends Node {
   
}
// Set text of transitionLabel to empty string
var transitionLabel = GmfGraph!Label.all.
  selectOne(l|l.name.println()="TransitionLabelLabel");
transitionLabel.text = "";

// Add bold font to actionLabel
var actionLabel = GmfGraph!Label.all.
  selectOne(l|l.name="ActionLabelFigure");
actionLabel.font = new GmfGraph!BasicFont;
actionLabel.font.style = GmfGraph!FontStyle#BOLD;

// Add italic font to actionLabel
var decisionLabel = GmfGraph!Label.all.
  selectOne(l|l.name="DecisionLabelFigure");
decisionLabel.font = new GmfGraph!BasicFont;
decisionLabel.font.style = GmfGraph!FontStyle#ITALIC;
var genPlugin = GmfGen!GenPlugin.all.first();

genPlugin.requiredPlugins.
  add("org.eclipse.epsilon.eugenia.examples.flowchart.diagram.figures");
package org.eclipse.epsilon.eugenia.examples.flowchart.diagram.figures;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;

public class DiamondFigure extends Figure {
  
  @Override
  public void paint(Graphics graphics) {
    
    Rectangle r = getBounds();
    
    // Define the points of a diamond
    Point p1 = new Point(r.x, r.y + r.height/2);
    Point p2 = new Point(r.x + r.width/2, r.y);
    Point p3 = new Point(r.x + r.width, r.y + r.height/2);
    Point p4 = new Point(r.x + r.width/2, r.y + r.height - 1);
    
    PointList pointList = new PointList();
    pointList.addPoint(p1);
    pointList.addPoint(p2);
    pointList.addPoint(p3);
    pointList.addPoint(p4);
    
    // Fill the shape
    graphics.fillPolygon(pointList);
    
    // Draw the outline
    graphics.drawLine(p1, p2);
    graphics.drawLine(p2, p3);
    graphics.drawLine(p3, p4);
    graphics.drawLine(p4, p1);
    
    // Move the label to the centre of the diamond
    WrappingLabel label = (WrappingLabel) getChildren().get(0);
    LayoutUtil.moveToCenter(label, this, graphics);
    label.paint(graphics);
    
  }
  
}

Check out the code from the SVN:

  • go to the SVN repository
  • navigate to trunk/examples
  • check out the org.eclipse.epsilon.eugenia.examples.flowchart project
  • check out the org.eclipse.epsilon.eugenia.examples.flowchart.diagram.figures project

What's this?

In this example we use EuGENia to implement a flowchart GMF editor, and EOL to polish its appearance.

What are .emf files?

.emf files are Ecore metamodels expressed using the Emfatic textual syntax.

Even more examples...

More examples are available in the examples folder of the SVN repository.