Skip to content

Commit 8ebca7a

Browse files
committed
[SAFRAN-1071] Add M2Doc services for database partial view diagrams
1 parent 7d1a406 commit 8ebca7a

5 files changed

Lines changed: 285 additions & 1 deletion

File tree

designs/database/plugins/org.obeonetwork.dsl.database.design/src/org/obeonetwork/dsl/database/design/IDatabaseViewpointConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ public interface IDatabaseViewpointConstants {
2828

2929
public static String DATABASE_DIAGRAM_ID = "Database Diagram";
3030
public static String SCHEMA_DIAGRAM_ID = "Schema Diagram";
31+
public static String DATABASE_PARTIAL_VIEW_DIAGRAM_ID = "Database Partial View";
32+
public static String SCHEMA_PARTIAL_VIEW_DIAGRAM_ID = "Schema Partial View";
3133

3234
}

m2doc/database/plugins/org.obeonetwork.database.m2doc.services/META-INF/MANIFEST.MF

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ Require-Bundle: org.eclipse.core.runtime,
99
org.obeonetwork.m2doc,
1010
org.eclipse.help,
1111
org.eclipse.emf.common,
12-
org.eclipse.acceleo.annotations
12+
org.eclipse.acceleo.annotations,
13+
org.eclipse.sirius.ui,
14+
org.obeonetwork.dsl.database.design
1315
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
1416
Bundle-ActivationPolicy: lazy
1517
Export-Package: org.obeonetwork.database.m2doc.services
1618
Bundle-Vendor: Obeo Network
19+
Import-Package: org.obeonetwork.m2doc.sirius.services

m2doc/database/plugins/org.obeonetwork.database.m2doc.services/plugin.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<service
2323
class="org.obeonetwork.database.m2doc.services.DataBaseServices">
2424
</service>
25+
<service
26+
class="org.obeonetwork.database.m2doc.services.SchemaServices">
27+
</service>
2528
<service
2629
class="org.obeonetwork.database.m2doc.services.ForeignKeyElementServices">
2730
</service>
@@ -52,6 +55,9 @@
5255
<service
5356
class="org.obeonetwork.database.m2doc.services.DataBaseServices">
5457
</service>
58+
<service
59+
class="org.obeonetwork.database.m2doc.services.SchemaServices">
60+
</service>
5561
<service
5662
class="org.obeonetwork.database.m2doc.services.ForeignKeyElementServices">
5763
</service>

m2doc/database/plugins/org.obeonetwork.database.m2doc.services/src/org/obeonetwork/database/m2doc/services/DataBaseServices.java

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
*******************************************************************************/
1111
package org.obeonetwork.database.m2doc.services;
1212

13+
import java.io.IOException;
1314
import java.util.ArrayList;
1415
import java.util.HashSet;
1516
import java.util.List;
1617
import java.util.Set;
1718

1819
import org.eclipse.acceleo.annotations.api.documentation.Documentation;
1920
import org.eclipse.acceleo.annotations.api.documentation.Example;
21+
import org.eclipse.sirius.business.api.query.EObjectQuery;
22+
import org.eclipse.sirius.business.api.session.Session;
23+
import org.eclipse.sirius.ui.tools.api.actions.export.SizeTooLargeException;
2024
import org.obeonetwork.dsl.database.AbstractTable;
2125
import org.obeonetwork.dsl.database.DataBase;
2226
import org.obeonetwork.dsl.database.ForeignKey;
@@ -25,9 +29,12 @@
2529
import org.obeonetwork.dsl.database.Table;
2630
import org.obeonetwork.dsl.database.TableContainer;
2731
import org.obeonetwork.dsl.database.View;
32+
import org.obeonetwork.dsl.database.design.IDatabaseViewpointConstants;
2833
import org.obeonetwork.dsl.database.util.DatabaseSwitch;
2934
import org.obeonetwork.dsl.typeslibrary.NativeTypesLibrary;
3035
import org.obeonetwork.dsl.typeslibrary.TypesLibrary;
36+
import org.obeonetwork.m2doc.element.MImage;
37+
import org.obeonetwork.m2doc.sirius.services.M2DocSiriusServices;
3138

3239
/**
3340
* AQL Services for M2Doc.
@@ -193,6 +200,131 @@ public List<Sequence> localSequences(DataBase db) {
193200
return result;
194201
}
195202

203+
// @formatter:off
204+
@Documentation(
205+
comment = "{m:database.asDatabaseImage()}",
206+
value = "Returns a collection of images representing the target Database Database Diagrams.",
207+
examples = {
208+
@Example(
209+
expression = "{m:database.asDatabaseImage()}",
210+
result = "A sequence of images.")
211+
}
212+
)
213+
// @formatter:on
214+
public List<MImage> asDatabaseImage(DataBase database) throws SizeTooLargeException, IOException {
215+
Session session = new EObjectQuery(database).getSession();
216+
List<MImage> images = new M2DocSiriusServices(session, true).asImageByRepresentationDescriptionName(database,
217+
IDatabaseViewpointConstants.DATABASE_DIAGRAM_ID);
218+
219+
return images;
220+
}
221+
222+
// @formatter:off
223+
@Documentation(
224+
comment = "{m:database.asDatabaseImage(width)}",
225+
value = "Returns a collection of images representing the target Database Database Diagrams scaled to the given width keeping the initial image ratio.",
226+
examples = {
227+
@Example(
228+
expression = "{m:database.asDatabaseImage(400)}",
229+
result = "A sequence of images.")
230+
}
231+
)
232+
// @formatter:on
233+
public List<MImage> asDatabaseImage(DataBase database, int width) throws SizeTooLargeException, IOException {
234+
Session session = new EObjectQuery(database).getSession();
235+
List<MImage> images = new M2DocSiriusServices(session, true).asImageByRepresentationDescriptionName(database,
236+
IDatabaseViewpointConstants.DATABASE_DIAGRAM_ID);
237+
images.forEach(i -> i.conserveRatio());
238+
images.forEach(i -> i.setWidth(width));
239+
240+
return images;
241+
}
242+
243+
// @formatter:off
244+
@Documentation(
245+
comment = "{m:database.asDatabaseImage(width, height)}",
246+
value = "Returns a collection of images representing the target Database Database Diagrams scaled to the given width and heigth.",
247+
examples = {
248+
@Example(
249+
expression = "{m:database.asDatabaseImage(400, 300)}",
250+
result = "A sequence of images.")
251+
}
252+
)
253+
// @formatter:on
254+
public List<MImage> asDatabaseImage(DataBase database, int width, int height)
255+
throws SizeTooLargeException, IOException {
256+
Session session = new EObjectQuery(database).getSession();
257+
List<MImage> images = new M2DocSiriusServices(session, true).asImageByRepresentationDescriptionName(database,
258+
IDatabaseViewpointConstants.DATABASE_DIAGRAM_ID);
259+
images.forEach(i -> i.setHeight(height));
260+
images.forEach(i -> i.setWidth(width));
261+
262+
return images;
263+
}
264+
265+
// @formatter:off
266+
@Documentation(
267+
comment = "{m:database.asDatabasePartialViewImage()}",
268+
value = "Returns a collection of images representing the target Database Database Partial View Diagrams.",
269+
examples = {
270+
@Example(
271+
expression = "{m:database.asDatabasePartialViewImage()}",
272+
result = "A sequence of images.")
273+
}
274+
)
275+
// @formatter:on
276+
public List<MImage> asDatabasePartialViewImage(DataBase database) throws SizeTooLargeException, IOException {
277+
Session session = new EObjectQuery(database).getSession();
278+
List<MImage> images = new M2DocSiriusServices(session, true).asImageByRepresentationDescriptionName(database,
279+
IDatabaseViewpointConstants.DATABASE_PARTIAL_VIEW_DIAGRAM_ID);
280+
281+
return images;
282+
}
283+
284+
// @formatter:off
285+
@Documentation(
286+
comment = "{m:database.asDatabasePartialViewImage(width)}",
287+
value = "Returns a collection of images representing the target Database Database Partial View Diagrams scaled to the given width keeping the initial image ratio.",
288+
examples = {
289+
@Example(
290+
expression = "{m:database.asDatabasePartialViewImage(400)}",
291+
result = "A sequence of images.")
292+
}
293+
)
294+
// @formatter:on
295+
public List<MImage> asDatabasePartialViewImage(DataBase database, int width)
296+
throws SizeTooLargeException, IOException {
297+
Session session = new EObjectQuery(database).getSession();
298+
List<MImage> images = new M2DocSiriusServices(session, true).asImageByRepresentationDescriptionName(database,
299+
IDatabaseViewpointConstants.DATABASE_PARTIAL_VIEW_DIAGRAM_ID);
300+
images.forEach(i -> i.conserveRatio());
301+
images.forEach(i -> i.setWidth(width));
302+
303+
return images;
304+
}
305+
306+
// @formatter:off
307+
@Documentation(
308+
comment = "{m:database.asDatabasePartialViewImage(width, height)}",
309+
value = "Returns a collection of images representing the target Database Database Partial View Diagrams scaled to the given width and heigth.",
310+
examples = {
311+
@Example(
312+
expression = "{m:database.asDatabasePartialViewImage(400, 300)}",
313+
result = "A sequence of images.")
314+
}
315+
)
316+
// @formatter:on
317+
public List<MImage> asDatabasePartialViewImage(DataBase database, int width, int height)
318+
throws SizeTooLargeException, IOException {
319+
Session session = new EObjectQuery(database).getSession();
320+
List<MImage> images = new M2DocSiriusServices(session, true).asImageByRepresentationDescriptionName(database,
321+
IDatabaseViewpointConstants.DATABASE_PARTIAL_VIEW_DIAGRAM_ID);
322+
images.forEach(i -> i.setHeight(height));
323+
images.forEach(i -> i.setWidth(width));
324+
325+
return images;
326+
}
327+
196328
/**
197329
* Switch class used to collect the tables of a data base.
198330
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
package org.obeonetwork.database.m2doc.services;
2+
3+
import java.io.IOException;
4+
import java.util.List;
5+
6+
import org.eclipse.acceleo.annotations.api.documentation.Documentation;
7+
import org.eclipse.acceleo.annotations.api.documentation.Example;
8+
import org.eclipse.sirius.business.api.query.EObjectQuery;
9+
import org.eclipse.sirius.business.api.session.Session;
10+
import org.eclipse.sirius.ui.tools.api.actions.export.SizeTooLargeException;
11+
import org.obeonetwork.dsl.database.Schema;
12+
import org.obeonetwork.dsl.database.design.IDatabaseViewpointConstants;
13+
import org.obeonetwork.m2doc.element.MImage;
14+
import org.obeonetwork.m2doc.sirius.services.M2DocSiriusServices;
15+
16+
public class SchemaServices {
17+
18+
// @formatter:off
19+
@Documentation(
20+
comment = "{m:schema.asSchemaImage()}",
21+
value = "Returns a collection of images representing the target Schema Schema Diagrams.",
22+
examples = {
23+
@Example(
24+
expression = "{m:schema.asSchemaImage()}",
25+
result = "A sequence of images.")
26+
}
27+
)
28+
// @formatter:on
29+
public List<MImage> asSchemaImage(Schema schema) throws SizeTooLargeException, IOException {
30+
Session session = new EObjectQuery(schema).getSession();
31+
List<MImage> images = new M2DocSiriusServices(session, true).asImageByRepresentationDescriptionName(schema,
32+
IDatabaseViewpointConstants.SCHEMA_DIAGRAM_ID);
33+
34+
return images;
35+
}
36+
37+
// @formatter:off
38+
@Documentation(
39+
comment = "{m:schema.asSchemaImage(width)}",
40+
value = "Returns a collection of images representing the target Schema Schema Diagrams scaled to the given width keeping the initial image ratio.",
41+
examples = {
42+
@Example(
43+
expression = "{m:schema.asSchemaImage(400)}",
44+
result = "A sequence of images.")
45+
}
46+
)
47+
// @formatter:on
48+
public List<MImage> asSchemaImage(Schema schema, int width) throws SizeTooLargeException, IOException {
49+
Session session = new EObjectQuery(schema).getSession();
50+
List<MImage> images = new M2DocSiriusServices(session, true).asImageByRepresentationDescriptionName(schema,
51+
IDatabaseViewpointConstants.SCHEMA_DIAGRAM_ID);
52+
images.forEach(i -> i.conserveRatio());
53+
images.forEach(i -> i.setWidth(width));
54+
55+
return images;
56+
}
57+
58+
// @formatter:off
59+
@Documentation(
60+
comment = "{m:schema.asSchemaImage(width, height)}",
61+
value = "Returns a collection of images representing the target Schema Schema Diagrams scaled to the given width and heigth.",
62+
examples = {
63+
@Example(
64+
expression = "{m:schema.asSchemaImage(400, 300)}",
65+
result = "A sequence of images.")
66+
}
67+
)
68+
// @formatter:on
69+
public List<MImage> asSchemaImage(Schema schema, int width, int height) throws SizeTooLargeException, IOException {
70+
Session session = new EObjectQuery(schema).getSession();
71+
List<MImage> images = new M2DocSiriusServices(session, true).asImageByRepresentationDescriptionName(schema,
72+
IDatabaseViewpointConstants.SCHEMA_DIAGRAM_ID);
73+
images.forEach(i -> i.setHeight(height));
74+
images.forEach(i -> i.setWidth(width));
75+
76+
return images;
77+
}
78+
79+
// @formatter:off
80+
@Documentation(
81+
comment = "{m:schema.asSchemaPartialViewImage()}",
82+
value = "Returns a collection of images representing the target Schema Schema Partial View Diagrams.",
83+
examples = {
84+
@Example(
85+
expression = "{m:schema.asSchemaPartialViewImage()}",
86+
result = "A sequence of images.")
87+
}
88+
)
89+
// @formatter:on
90+
public List<MImage> asSchemaPartialViewImage(Schema schema) throws SizeTooLargeException, IOException {
91+
Session session = new EObjectQuery(schema).getSession();
92+
List<MImage> images = new M2DocSiriusServices(session, true).asImageByRepresentationDescriptionName(schema,
93+
IDatabaseViewpointConstants.SCHEMA_PARTIAL_VIEW_DIAGRAM_ID);
94+
95+
return images;
96+
}
97+
98+
// @formatter:off
99+
@Documentation(
100+
comment = "{m:schema.asSchemaPartialViewImage(width)}",
101+
value = "Returns a collection of images representing the target Schema Schema Partial View Diagrams scaled to the given width keeping the initial image ratio.",
102+
examples = {
103+
@Example(
104+
expression = "{m:schema.asSchemaPartialViewImage(400)}",
105+
result = "A sequence of images.")
106+
}
107+
)
108+
// @formatter:on
109+
public List<MImage> asSchemaPartialViewImage(Schema schema, int width) throws SizeTooLargeException, IOException {
110+
Session session = new EObjectQuery(schema).getSession();
111+
List<MImage> images = new M2DocSiriusServices(session, true).asImageByRepresentationDescriptionName(schema,
112+
IDatabaseViewpointConstants.SCHEMA_PARTIAL_VIEW_DIAGRAM_ID);
113+
images.forEach(i -> i.conserveRatio());
114+
images.forEach(i -> i.setWidth(width));
115+
116+
return images;
117+
}
118+
119+
// @formatter:off
120+
@Documentation(
121+
comment = "{m:schema.asSchemaPartialViewImage(width, height)}",
122+
value = "Returns a collection of images representing the target Schema Schema Partial View Diagrams scaled to the given width and heigth.",
123+
examples = {
124+
@Example(
125+
expression = "{m:schema.asSchemaPartialViewImage(400, 300)}",
126+
result = "A sequence of images.")
127+
}
128+
)
129+
// @formatter:on
130+
public List<MImage> asSchemaPartialViewImage(Schema schema, int width, int height)
131+
throws SizeTooLargeException, IOException {
132+
Session session = new EObjectQuery(schema).getSession();
133+
List<MImage> images = new M2DocSiriusServices(session, true).asImageByRepresentationDescriptionName(schema,
134+
IDatabaseViewpointConstants.SCHEMA_PARTIAL_VIEW_DIAGRAM_ID);
135+
images.forEach(i -> i.setHeight(height));
136+
images.forEach(i -> i.setWidth(width));
137+
138+
return images;
139+
}
140+
141+
}

0 commit comments

Comments
 (0)