Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Picto Xtext Example: add plantuml-based transformation and other views #120

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.epsilon.examples.picto.xtext.domainmodel.example</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
datatype String

entity Blog {
"Main entity. A blog is composed of posts"

title: String
many posts: Post
}

entity HasAuthor {
author: String
}

entity Post extends HasAuthor {
"Starting message of each blog entry"

title: String
content: String
many comments: Comment
}

entity Comment extends HasAuthor {
"Messages that capture the discussion around a post"

content: String
many responses: Comment
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Blog domain model report

## Element stats

<picto-view path="Stats"/>

## Types usage

<picto-view path="Types"/>

## Core Entities

<picto-view path="Custom, Core"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?nsuri picto?>
<picto format="egx" transformation="platform:/plugin/org.eclipse.epsilon.examples.picto.xtext.domainmodel.picto/picto/dmodel.egx" standalone="true">
<model type="EMF">
<parameter name="name" value="M"/>
<parameter name="metamodelUri" value="http://www.eclipse.org/epsilon/examples/picto/xtext/domainmodel/Domainmodel"/>
<parameter name="modelFile" file="blog.dmodel"/>
</model>

<!-- A custom view produced by invoking an EGX rule -->
<view path="Custom, Core" icon="diagram-ff00ff" type="Entities2PlantUML">
<parameter name="inputEntities" values="Blog, Post, Comment"/>
</view>

<!-- A custom static view that renders a Markdown document -->
<view path="Readme" icon="document" format="markdown" source="readme.md" position="0"/>
</picto>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src
src-gen
plugin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
datatype String

entity Blog {
"Main entity. A blog is composed of posts"

title: String
many posts: Post
}
Expand All @@ -10,12 +12,16 @@ entity HasAuthor {
}

entity Post extends HasAuthor {
"Starting message of each blog entry"

title: String
content: String
many comments: Comment
}

entity Comment extends HasAuthor {
"Messages that capture the discussion around a post"

content: String
many responses: Comment
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
[%
// TODO: make a list of colours big enough to reuse this barchart with ease
var labels = Sequence{"Data types",
"Entities",
"Features"};

var values = Sequence{DataType.all.size(),
Entity.all.size(),
Feature.all.size()};
%]
<html>
<head>
<meta charset="utf-8"/>
<style>
#graphContainer {
margin: 0 auto;
}
</style>
</head>
<body>
<div id="graphContainer">
<canvas id="myChart" width="600" height="300"></canvas>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.5.1/chart.min.js"></script>
<script>
const labels = [[%=labels.quote()%]]
const data = {
labels: labels,
datasets: [{
axis: 'y',
data: [[%=values.quote()%]],
fill: true,
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(255, 205, 86, 0.2)',
'rgba(54, 162, 235, 0.2)',
],
borderColor: [
'rgb(255, 99, 132)',
'rgb(255, 205, 86)',
'rgb(54, 162, 235)',
],
borderWidth: 1
}]
};

const config = {
type: 'bar',
data,
options: {
indexAxis: 'y',

plugins: {
title: {
display: true,
text: 'Number of Elements per Type',
font: {size: 24}
},
legend: {
display: false
}
},
responsive: false
}
};

// render the chart
var myChart = new Chart(document.getElementById('myChart'), config);
</script>
</body>
</html>
[%
operation Sequence quote() {
return self.collect(elem | '"' + elem + '"')
.concat(", ");
}
%]
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
rule StatsChart {
template : "barchart.egl"

parameters : Map {
"position" = "1",
"path" = List{"Stats"},
"icon" = "barchart",
"format" = "html"
}
}

rule TypesTable {
template : "typeStats.pinset"

parameters : Map {
"position" = "2",
"path" = Sequence{"Types"},
"icon" = "table",
"format" = "csv"
}
}

rule AllEntities {

template : "entity2plantuml.egl"

parameters : Map{
"position" = "3",
"path" = Sequence{"All Entities"},
"icon" = "diagram-ffffff",
"format" = "plantuml",
"inputEntities" = Entity.all.name,
"layers" = Sequence {
Map {"id"="documentation", "title"="Documentation", "active"=false},
Map {"id"="supertype", "title"="Supertype"},
Map {"id"="inlineReferences", "title"="Inline references"},
Map {"id"="referenceLabels", "title"="Reference labels", "active"=false}
}
}
}

rule Entity2PlantUML
transform e : Entity {

template : "entity2plantuml.egl"

parameters : Map {
"position" = "4",
"path" = Sequence{"Entities", e.name},
"icon" = "diagram-ffffff",
"format" = "plantuml",
"layers" = Sequence {
Map {"id"="documentation", "title"="Documentation"},
Map {"id"="supertype", "title"="Supertype"},
Map {"id"="subtypes", "title"="Subtypes"},
Map {"id"="inlineReferences", "title"="Inline references"},
Map {"id"="referenceLabels", "title"="Reference labels"}
}
}
}

rule Entity2Graphviz
transform e : Entity {

template : "entity2graphviz.egl"

parameters : Map{
"path" = Sequence{"Entities-Graphviz", e.name},
"icon" = "diagram-ffffff",
"format" = "graphviz-dot"
}

}

@lazy
rule Entities2PlantUML {

template : "entity2plantuml.egl"

parameters : Map {
// requires "inputEntities" to work
"format" = "plantuml",
"layers" = Sequence {
Map {"id"="documentation", "title"="Documentation"},
Map {"id"="supertype", "title"="Supertype", "active"=false},
Map {"id"="inlineReferences", "title"="Inline references", "active"=false},
Map {"id"="referenceLabels", "title"="Reference labels"}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ digraph G {
[%
operation Entity getLabel() {

var onClick = "top.showView(['Model','" + self.name + "'])";
var onClick = "top.showView(['Entities-Graphviz','" + self.name + "'])";

if (self == e) {
onClick = "top.showElement('" + self.id + "', '" + self.eResource.uri + "')";
Expand Down Expand Up @@ -54,6 +54,7 @@ operation Entity getLabel() {
}

label += "</table>";

return label;
}

Expand Down
Loading
Loading