]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.charts/src/org/simantics/charts/ui/SCLChart.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / ui / SCLChart.java
1 /*******************************************************************************
2  * Copyright (c) 2013 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.charts.ui;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
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;
25
26 /**
27  * @author Jani Simomaa <jani.simomaa@semantum.fi>
28  */
29 public class SCLChart {
30
31         /**
32      * Creates new chart under given model
33      * 
34      * @param targetModel resource of the target model
35      * @return resource of the chart
36      * @throws DatabaseException on database failures
37      */
38         public static Resource createNewChart (Resource targetModel) throws DatabaseException {
39
40                 Resource chart = NewChart.createChart(targetModel);
41                 return chart;
42         }
43
44         /**
45      * Creates new chart group under given model
46      * 
47      * @param targetModel resource of the target model
48      * @return resource of the chartGroup
49      * @throws DatabaseException on database failures
50      */
51         public static Resource createNewChartGroup (Resource targetModel) throws DatabaseException {
52
53                 Resource chartGroup = NewChartGroup.createChartGroup(targetModel);
54                 return chartGroup;
55         }
56
57         /**
58      * Adds chart items to the given chart
59      * 
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
64      */
65         public static Resource addChartItems (WriteGraph graph, Resource chart, Variable variable) throws DatabaseException {
66                 
67                 Resource model = Variables.getModel(graph, variable);
68                 Resource defaultSubscriptionResource = SCLSubscription.defaultSubscriptionFolder(graph, model);
69                 Resource subscriptionItem = SCLSubscription.addSubscriptionItems(graph, defaultSubscriptionResource, variable);
70                 
71                 List<ChartItemDescriptor> refs = new ArrayList<ChartItemDescriptor>(1);
72                 refs.add( AddChartItem.createDescriptor(graph, subscriptionItem) );
73
74                 AddChartItem ci = new AddChartItem(     chart, refs     );
75                 ci.perform(graph);
76                 
77                 return ci.chartItem;
78         }
79
80         /**
81      * links given subscription to the given chart
82      * 
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
87      */
88         public static Resource linkSubToChart (WriteGraph graph, Resource subscriptionItem, Resource chart) throws DatabaseException {
89
90                 List<ChartItemDescriptor> refs = new ArrayList<ChartItemDescriptor>(1);
91                 refs.add( AddChartItem.createDescriptor(graph, subscriptionItem) );
92
93                 AddChartItem ci = new AddChartItem(     chart, refs );          
94                 ci.perform(graph);
95
96                 return ci.chartItem;
97         }
98
99 }