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
10 * Semantum Oy - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.charts.ui;
\r
14 import java.util.ArrayList;
\r
15 import java.util.List;
\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
27 * @author Jani Simomaa <jani.simomaa@semantum.fi>
\r
29 public class SCLChart {
\r
32 * Creates new chart under given model
\r
34 * @param targetModel resource of the target model
\r
35 * @return resource of the chart
\r
36 * @throws DatabaseException on database failures
\r
38 public static Resource createNewChart (Resource targetModel) throws DatabaseException {
\r
40 Resource chart = NewChart.createChart(targetModel);
\r
45 * Creates new chart group under given model
\r
47 * @param targetModel resource of the target model
\r
48 * @return resource of the chartGroup
\r
49 * @throws DatabaseException on database failures
\r
51 public static Resource createNewChartGroup (Resource targetModel) throws DatabaseException {
\r
53 Resource chartGroup = NewChartGroup.createChartGroup(targetModel);
\r
58 * Adds chart items to the given chart
\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
65 public static Resource addChartItems (WriteGraph graph, Resource chart, Variable variable) throws DatabaseException {
\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
71 List<ChartItemDescriptor> refs = new ArrayList<ChartItemDescriptor>(1);
\r
72 refs.add( AddChartItem.createDescriptor(graph, subscriptionItem) );
\r
74 AddChartItem ci = new AddChartItem( chart, refs );
\r
77 return ci.chartItem;
\r
81 * links given subscription to the given chart
\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
88 public static Resource linkSubToChart (WriteGraph graph, Resource subscriptionItem, Resource chart) throws DatabaseException {
\r
90 List<ChartItemDescriptor> refs = new ArrayList<ChartItemDescriptor>(1);
\r
91 refs.add( AddChartItem.createDescriptor(graph, subscriptionItem) );
\r
93 AddChartItem ci = new AddChartItem( chart, refs );
\r
96 return ci.chartItem;
\r