Show last authors
1 These instructions should guide you if you'd like to try out using KLighD for visualizing your own models or data structures. A minimal example is shown where a trivial data structure is visualized with KLighD.
2
3 == Step-By-Step Guide ==
4
5 In order to get this example working, please follow the instructions below:
6
7 1. Download Eclipse Kepler (Modeling Edition):
8 Windows x64: [[http:~~/~~/www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/kepler/SR1/eclipse-modeling-kepler-SR1-win32-x86_64.zip&mirror_id=546>>url:http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/kepler/SR1/eclipse-modeling-kepler-SR1-win32-x86_64.zip&mirror_id=546||shape="rect"]]
9 Mac x64: [[http:~~/~~/www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/kepler/SR1/eclipse-modeling-kepler-SR1-macosx-cocoa-x86_64.tar.gz>>url:http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/kepler/SR1/eclipse-modeling-kepler-SR1-macosx-cocoa-x86_64.tar.gz||shape="rect"]]
10 Other: [[http:~~/~~/www.eclipse.org/downloads/packages/eclipse-modeling-tools/keplersr1>>url:http://www.eclipse.org/downloads/packages/eclipse-modeling-tools/keplersr1||shape="rect"]]
11 1. Add the KIELER Pragmatics Nightly update site to your Eclipse (Help -> Install New Software ... -> Add)[[:
12 >>url:http://rtsys.informatik.uni-kiel.de/~~kieler/updatesite/||shape="rect"]][[http:~~/~~/rtsys.informatik.uni-kiel.de/~~~~kieler/updatesite/nightly/pragmatics/>>url:http://rtsys.informatik.uni-kiel.de/~~kieler/updatesite/nightly/pragmatics/||shape="rect"]]
13 1. Select
14 [x] Layout,
15 [x] Lightweight Diagrams, and
16 [x] Sources
17 to be installed into your Eclipse. You may need to re-start Eclipse after finishing the installation process.
18 1. Download the following file, unzip it and import it as an existing project into your Eclipse workspace:
19 [[attach:de.cau.cs.kieler.klighd.example.mydata.zip]]
20 1. You may now create a new run configuration and run everything as an Eclipse Application.
21 1. Once you click on the red-circled button, you should see the synthesized diagram as follows:
22 [[image:attach:klighd-minimal-example.png]]
23
24
25
26 == The Details ==
27
28 Mainly there a three classes involved:
29
30 1. **MyData.java** : It contains a trivial hierarchical data model, in reality you can use your own data structures or models instead.
31 1. **MyDataDiagrammSynthesisAction.java** : This is an Eclipse Action implementation for triggering the diagram synthesis, in reality you can use your own code in order to synthesize or update your data/model visualization.
32 1. **MyDataDiagramSynthesis.xtend** : This ist the most essential part, it is the transformation from your data/model to the view model (the diagram). You can use this as a bare bone example and extend it as you like. Note that it already uses several KLighD extension libraries that are included. These libraries can be inspected also if you are searching for further features that you want to use, they contain the most common features already.
33
34 == The Files ==
35
36 {{code title="MyData.java" language="java"}}
37 public class MyData {
38
39 public String name;
40 public List<MyData> subData = new LinkedList<MyData>();
41
42 public static MyData getTestData() {
43 MyData d1 = new MyData();
44 d1.name = "all data";
45 MyData d2 = new MyData();
46 d2.name = "outer data";
47 MyData d3 = new MyData();
48 d3.name = "inner 1";
49 MyData d4 = new MyData();
50 d4.name = "inner 2";
51 MyData d5 = new MyData();
52 d5.name = "inner 5";
53 MyData d6 = new MyData();
54 d6.name = "most inner 6";
55 d1.subData.add(d2);
56 d2.subData.add(d3);
57 d2.subData.add(d4);
58 d2.subData.add(d5);
59 d4.subData.add(d6);
60 return d1;
61 }
62
63 }
64 {{/code}}
65
66 {{code title="MyDataDiagrammSynthesisAction.java" language="java"}}
67 public class MyDataDiagrammSynthesisAction implements
68 IWorkbenchWindowActionDelegate {
69 public MyDataDiagrammSynthesisAction() {
70 }
71 public void run(IAction action) {
72
73 // Get some static dummy test data
74 MyData data = MyData.getTestData();
75 // Prepare the diagram synthesis: Create a new klighdUpdateDiagramEffect
76 KlighdUpdateDiagramEffect klighdEffect = new KlighdUpdateDiagramEffect(
77 "de.cau.cs.kieler.klighd.example.mydata.MyDataDiagramSynthesis",
78 "KLighD MyData Diagram", data);
79 // FIXME: Note that the incremental update currently is under re-development
80 // for Eclipse Kepler after large API changes to EMF Compare had been made.
81 // At this time we cannot use the incremental update strategy (commented out).
82 // As soon as it is fixed, uncomment the line below and delete the
83 // SimpleUpdateStrategy line:
84
85 // klighdEffect.setProperty(LightDiagramServices.REQUESTED_UPDATE_STRATEGY,
86 // UpdateStrategy.ID);
87 klighdEffect.setProperty(
88 LightDiagramServices.REQUESTED_UPDATE_STRATEGY,
89 SimpleUpdateStrategy.ID);
90 // Do the diagram synthesis
91 klighdEffect.execute();
92 }
93 public void selectionChanged(IAction action, ISelection selection) {
94 }
95 public void dispose() {
96 }
97 public void init(IWorkbenchWindow window) {
98 }
99 }
100 {{/code}}
101
102 {{code title="MyDataDiagramSynthesis.xtend"}}
103 class MyDataDiagramSynthesis extends AbstractDiagramSynthesis<MyData> {
104 @Inject extension KNodeExtensions
105 @Inject extension KEdgeExtensions
106 @Inject extension KPortExtensions
107 @Inject extension KLabelExtensions
108 @Inject extension KRenderingExtensions
109 @Inject extension KContainerRenderingExtensions
110 @Inject extension KPolylineExtensions
111 @Inject extension KColorExtensions
112 // Some self-defined colors
113 private static val KColor BLUE1 = RENDERING_FACTORY.createKColor() =>
114 [it.red = 248; it.green = 249; it.blue = 253];
115 private static val KColor BLUE2 = RENDERING_FACTORY.createKColor() =>
116 [it.red = 205; it.green = 220; it.blue = 243];
117 // Additional transformation option to hide or show a shadow
118 private static val SynthesisOption SHOW_SHADOW = SynthesisOption::createCheckOption("Shadow", true);
119 // Add all transformation options (comma separated)
120 override getDisplayedSynthesisOptions() {
121 return ImmutableList::of(
122 SHOW_SHADOW
123 );
124 }
125 override KNode transform(MyData data) {
126 val root = data.createNode()
127 root.putToLookUpWith(data) => [
128 // Optional Layout parameters can be set
129 //it.addLayoutParam(LayoutOptions::ALGORITHM, "de.cau.cs.kieler.kiml.ogdf.planarization");
130 //it.addLayoutParam(LayoutOptions::SPACING, 75f);
131 //it.addLayoutParam(LayoutOptions::DIRECTION, Direction::UP);
132 // A rounded rectangle is created for every MyData instance
133 it.addRoundedRectangle(5, 5) => [
134 // Set linewith, foreground color, and a fading background color
135 it.lineWidth = 1;
136 it.setForeground("darkGray".color)
137 // We need a fresh copy of each color item, because it is contained by its element
138 it.setBackgroundGradient(BLUE1.copy, BLUE2.copy, 90)
139 // Here we see a how to use a boolean transformation/diagram option
140 if (SHOW_SHADOW.booleanValue) {
141 it.shadow = "black".color;
142 }
143 // Set a text
144 it.addText(" " + data.name + " ") => [
145 it.setFontSize(9)
146 it.setForeground("black".color)
147 ]
148 // If this is a hierarchical MyData instance, then create horizontal splitter,
149 // a child area, and add its children
150 if (data.subData.length > 0) {
151 it.setGridPlacement(1);
152 it.addHorizontalSeperatorLine(1, 2).setForeground("darkGray".color)
153 it.addChildArea().setGridPlacementData() => [
154 from(LEFT, 3, 0, TOP, 3, 0).to(RIGHT, 3, 0, BOTTOM, 3, 0)
155 minCellHeight = 5;
156 minCellWidth = 5;
157 ];
158 for (subData : data.subData) {
159 // To the recursive call to transform for all children
160 val child = subData.transform
161 // It is important to add all children to the root!
162 root.children.add(child)
163 }
164 }
165 ]
166 ]
167 return root;
168 }
169 }
170 {{/code}}
171
172
173
174
175
176 Eclipse