1 /*******************************************************************************
2 * Copyright (c) 2013 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.charts.ui;
14 import java.util.ArrayList;
15 import java.util.List;
17 import org.simantics.charts.query.AddChartItem;
18 import org.simantics.charts.query.ChartItemDescriptor;
19 import org.simantics.db.Resource;
20 import org.simantics.db.WriteGraph;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.layer0.variable.Variable;
23 import org.simantics.db.layer0.variable.Variables;
24 import org.simantics.modeling.subscription.SCLSubscription;
27 * @author Jani Simomaa <jani.simomaa@semantum.fi>
29 public class SCLChart {
32 * Creates new chart under given model
34 * @param targetModel resource of the target model
35 * @return resource of the chart
36 * @throws DatabaseException on database failures
38 public static Resource createNewChart (Resource targetModel) throws DatabaseException {
40 Resource chart = NewChart.createChart(targetModel);
45 * Creates new chart group under given model
47 * @param targetModel resource of the target model
48 * @return resource of the chartGroup
49 * @throws DatabaseException on database failures
51 public static Resource createNewChartGroup (Resource targetModel) throws DatabaseException {
53 Resource chartGroup = NewChartGroup.createChartGroup(targetModel);
58 * Adds chart items to the given chart
60 * @param chart resource of the target chart
61 * @param variable variable of the item to be created
62 * @return resource of the created chart item
63 * @throws DatabaseException on database failures
65 public static Resource addChartItems (WriteGraph graph, Resource chart, Variable variable) throws DatabaseException {
67 Resource model = Variables.getModel(graph, variable);
68 Resource defaultSubscriptionResource = SCLSubscription.defaultSubscriptionFolder(graph, model);
69 Resource subscriptionItem = SCLSubscription.addSubscriptionItems(graph, defaultSubscriptionResource, variable);
71 List<ChartItemDescriptor> refs = new ArrayList<ChartItemDescriptor>(1);
72 refs.add( AddChartItem.createDescriptor(graph, subscriptionItem) );
74 AddChartItem ci = new AddChartItem( chart, refs );
81 * links given subscription to the given chart
83 * @param subscriptionItem resource of the subscription
84 * @param chart resource of the chart
85 * @return resource of the created chart item
86 * @throws DatabaseException on database failures
88 public static Resource linkSubToChart (WriteGraph graph, Resource subscriptionItem, Resource chart) throws DatabaseException {
90 List<ChartItemDescriptor> refs = new ArrayList<ChartItemDescriptor>(1);
91 refs.add( AddChartItem.createDescriptor(graph, subscriptionItem) );
93 AddChartItem ci = new AddChartItem( chart, refs );