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