Example: Implement a GMF editor with end labels in connections using EuGENia

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

class Model {
   val Class[*] clases;
   val Association[*] asociations;

abstract class NamedElement {
   attr String name;

class Class extends NamedElement {

@gmf.link(source="source", target="target")
class Association extends NamedElement {
   ref Class source;
   ref Class target;
   attr String sourceLabel;
   attr String targetLabel;
var association = ECore!EClass.all.selectOne(c|c.name = "Association");
association.createLinkEndLabel("sourceLabel", true);
association.createLinkEndLabel("targetLabel", false);

operation ECore!EClass createLinkEndLabel(attribute:String, source:Boolean){
  var endName;
  if (source) {
    endName = "Source";
  else {
    endName = "Target";
  var labelName = self.name + endName + "Label";
  // Create the figure descriptor and the label
  var labelFigureDescriptor = 
    createFigureDescriptor(labelName + "Figure");
  var label = new GmfGraph!Label;
  label.name = labelName;
  label.text = endName;
  labelFigureDescriptor.actualFigure = label;
  // Create the diagram label
  var diagramLabel = new GmfGraph!DiagramLabel;
  diagramLabel.figure = labelFigureDescriptor;
  diagramLabel.name = labelName;
  diagramLabel.elementIcon = false;
  // Specify if the label will be placed at the beginning/end of the link
  var alignmentFacet =new GmfGraph!AlignmentFacet;
  if (source){
    alignmentFacet.alignment = GmfGraph!Alignment#END;
  else {
    alignmentFacet.alignment = GmfGraph!Alignment#BEGINNING;
  // Specify how far the label should be from the line
  var labelOffsetFacet = new GmfGraph!LabelOffsetFacet;
  labelOffsetFacet.x = 5;
  labelOffsetFacet.y = 5;
  // Create the label/attribute mapping in the .gmfmap model
  var featureLabelMapping = new GmfMap!FeatureLabelMapping;
  featureLabelMapping.diagramLabel = diagramLabel;
    selectOne(sf|sf.name = attribute));
  featureLabelMapping.readOnly = false;
  var linkMapping = GmfMap!LinkMapping.all.
    selectOne(lm|lm.domainMetaElement = self);


operation createFigureDescriptor(name : String) {
  var figureDescriptor = new GmfGraph!FigureDescriptor;
  figureDescriptor.name = name;
  return figureDescriptor;

Clone Epsilon's Git repository and then:

What's this?

In this example we use EuGENia to implement a GMF editor with end labels in connections.

What are .emf files?

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

More examples...

Epsilon Object Language
Epsilon Transformation Language
Epsilon Generation Language
Epsilon Validation Language
Epsilon Merging Language
Epsilon Flock
Epsilon Model Generation Language
Epsilon Pattern Language
Combining the Epsilon Languages

Even more examples...

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