--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.charts.ui;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.simantics.charts.query.AddChartItem;\r
+import org.simantics.charts.query.ChartItemDescriptor;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
+import org.simantics.modeling.subscription.SCLSubscription;\r
+\r
+/**\r
+ * @author Jani Simomaa <jani.simomaa@semantum.fi>\r
+ */\r
+public class SCLChart {\r
+\r
+ /**\r
+ * Creates new chart under given model\r
+ * \r
+ * @param targetModel resource of the target model\r
+ * @return resource of the chart\r
+ * @throws DatabaseException on database failures\r
+ */\r
+ public static Resource createNewChart (Resource targetModel) throws DatabaseException {\r
+\r
+ Resource chart = NewChart.createChart(targetModel);\r
+ return chart;\r
+ }\r
+\r
+ /**\r
+ * Creates new chart group under given model\r
+ * \r
+ * @param targetModel resource of the target model\r
+ * @return resource of the chartGroup\r
+ * @throws DatabaseException on database failures\r
+ */\r
+ public static Resource createNewChartGroup (Resource targetModel) throws DatabaseException {\r
+\r
+ Resource chartGroup = NewChartGroup.createChartGroup(targetModel);\r
+ return chartGroup;\r
+ }\r
+\r
+ /**\r
+ * Adds chart items to the given chart\r
+ * \r
+ * @param chart resource of the target chart\r
+ * @param variable variable of the item to be created\r
+ * @return resource of the created chart item\r
+ * @throws DatabaseException on database failures\r
+ */\r
+ public static Resource addChartItems (WriteGraph graph, Resource chart, Variable variable) throws DatabaseException {\r
+ \r
+ Resource model = Variables.getModel(graph, variable);\r
+ Resource defaultSubscriptionResource = SCLSubscription.defaultSubscriptionFolder(graph, model);\r
+ Resource subscriptionItem = SCLSubscription.addSubscriptionItems(graph, defaultSubscriptionResource, variable);\r
+ \r
+ List<ChartItemDescriptor> refs = new ArrayList<ChartItemDescriptor>(1);\r
+ refs.add( AddChartItem.createDescriptor(graph, subscriptionItem) );\r
+\r
+ AddChartItem ci = new AddChartItem( chart, refs );\r
+ ci.perform(graph);\r
+ \r
+ return ci.chartItem;\r
+ }\r
+\r
+ /**\r
+ * links given subscription to the given chart\r
+ * \r
+ * @param subscriptionItem resource of the subscription\r
+ * @param chart resource of the chart\r
+ * @return resource of the created chart item\r
+ * @throws DatabaseException on database failures\r
+ */\r
+ public static Resource linkSubToChart (WriteGraph graph, Resource subscriptionItem, Resource chart) throws DatabaseException {\r
+\r
+ List<ChartItemDescriptor> refs = new ArrayList<ChartItemDescriptor>(1);\r
+ refs.add( AddChartItem.createDescriptor(graph, subscriptionItem) );\r
+\r
+ AddChartItem ci = new AddChartItem( chart, refs ); \r
+ ci.perform(graph);\r
+\r
+ return ci.chartItem;\r
+ }\r
+\r
+}
\ No newline at end of file