]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.charts/src/org/simantics/charts/ui/SCLChart.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / ui / SCLChart.java
1 /*******************************************************************************\r
2  * Copyright (c) 2013 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     Semantum Oy - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.charts.ui;\r
13 \r
14 import java.util.ArrayList;\r
15 import java.util.List;\r
16 \r
17 import org.simantics.charts.query.AddChartItem;\r
18 import org.simantics.charts.query.ChartItemDescriptor;\r
19 import org.simantics.db.Resource;\r
20 import org.simantics.db.WriteGraph;\r
21 import org.simantics.db.exception.DatabaseException;\r
22 import org.simantics.db.layer0.variable.Variable;\r
23 import org.simantics.db.layer0.variable.Variables;\r
24 import org.simantics.modeling.subscription.SCLSubscription;\r
25 \r
26 /**\r
27  * @author Jani Simomaa <jani.simomaa@semantum.fi>\r
28  */\r
29 public class SCLChart {\r
30 \r
31         /**\r
32      * Creates new chart under given model\r
33      * \r
34      * @param targetModel resource of the target model\r
35      * @return resource of the chart\r
36      * @throws DatabaseException on database failures\r
37      */\r
38         public static Resource createNewChart (Resource targetModel) throws DatabaseException {\r
39 \r
40                 Resource chart = NewChart.createChart(targetModel);\r
41                 return chart;\r
42         }\r
43 \r
44         /**\r
45      * Creates new chart group under given model\r
46      * \r
47      * @param targetModel resource of the target model\r
48      * @return resource of the chartGroup\r
49      * @throws DatabaseException on database failures\r
50      */\r
51         public static Resource createNewChartGroup (Resource targetModel) throws DatabaseException {\r
52 \r
53                 Resource chartGroup = NewChartGroup.createChartGroup(targetModel);\r
54                 return chartGroup;\r
55         }\r
56 \r
57         /**\r
58      * Adds chart items to the given chart\r
59      * \r
60      * @param chart resource of the target chart\r
61      * @param variable variable of the item to be created\r
62      * @return resource of the created chart item\r
63      * @throws DatabaseException on database failures\r
64      */\r
65         public static Resource addChartItems (WriteGraph graph, Resource chart, Variable variable) throws DatabaseException {\r
66                 \r
67                 Resource model = Variables.getModel(graph, variable);\r
68                 Resource defaultSubscriptionResource = SCLSubscription.defaultSubscriptionFolder(graph, model);\r
69                 Resource subscriptionItem = SCLSubscription.addSubscriptionItems(graph, defaultSubscriptionResource, variable);\r
70                 \r
71                 List<ChartItemDescriptor> refs = new ArrayList<ChartItemDescriptor>(1);\r
72                 refs.add( AddChartItem.createDescriptor(graph, subscriptionItem) );\r
73 \r
74                 AddChartItem ci = new AddChartItem(     chart, refs     );\r
75                 ci.perform(graph);\r
76                 \r
77                 return ci.chartItem;\r
78         }\r
79 \r
80         /**\r
81      * links given subscription to the given chart\r
82      * \r
83      * @param subscriptionItem resource of the subscription\r
84      * @param chart resource of the chart\r
85      * @return resource of the created chart item\r
86      * @throws DatabaseException on database failures\r
87      */\r
88         public static Resource linkSubToChart (WriteGraph graph, Resource subscriptionItem, Resource chart) throws DatabaseException {\r
89 \r
90                 List<ChartItemDescriptor> refs = new ArrayList<ChartItemDescriptor>(1);\r
91                 refs.add( AddChartItem.createDescriptor(graph, subscriptionItem) );\r
92 \r
93                 AddChartItem ci = new AddChartItem(     chart, refs );          \r
94                 ci.perform(graph);\r
95 \r
96                 return ci.chartItem;\r
97         }\r
98 \r
99 }