X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.charts%2Fsrc%2Forg%2Fsimantics%2Fcharts%2Fui%2FSCLChart.java;fp=bundles%2Forg.simantics.charts%2Fsrc%2Forg%2Fsimantics%2Fcharts%2Fui%2FSCLChart.java;h=e6748e881a5b8bad3e14a659d5a371d166bc6bc7;hp=5f61740e279b60e61797148eb90e033644e19b22;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.charts/src/org/simantics/charts/ui/SCLChart.java b/bundles/org.simantics.charts/src/org/simantics/charts/ui/SCLChart.java index 5f61740e2..e6748e881 100644 --- a/bundles/org.simantics.charts/src/org/simantics/charts/ui/SCLChart.java +++ b/bundles/org.simantics.charts/src/org/simantics/charts/ui/SCLChart.java @@ -1,99 +1,99 @@ -/******************************************************************************* - * Copyright (c) 2013 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Semantum Oy - initial API and implementation - *******************************************************************************/ -package org.simantics.charts.ui; - -import java.util.ArrayList; -import java.util.List; - -import org.simantics.charts.query.AddChartItem; -import org.simantics.charts.query.ChartItemDescriptor; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.db.layer0.variable.Variables; -import org.simantics.modeling.subscription.SCLSubscription; - -/** - * @author Jani Simomaa - */ -public class SCLChart { - - /** - * Creates new chart under given model - * - * @param targetModel resource of the target model - * @return resource of the chart - * @throws DatabaseException on database failures - */ - public static Resource createNewChart (Resource targetModel) throws DatabaseException { - - Resource chart = NewChart.createChart(targetModel); - return chart; - } - - /** - * Creates new chart group under given model - * - * @param targetModel resource of the target model - * @return resource of the chartGroup - * @throws DatabaseException on database failures - */ - public static Resource createNewChartGroup (Resource targetModel) throws DatabaseException { - - Resource chartGroup = NewChartGroup.createChartGroup(targetModel); - return chartGroup; - } - - /** - * Adds chart items to the given chart - * - * @param chart resource of the target chart - * @param variable variable of the item to be created - * @return resource of the created chart item - * @throws DatabaseException on database failures - */ - public static Resource addChartItems (WriteGraph graph, Resource chart, Variable variable) throws DatabaseException { - - Resource model = Variables.getModel(graph, variable); - Resource defaultSubscriptionResource = SCLSubscription.defaultSubscriptionFolder(graph, model); - Resource subscriptionItem = SCLSubscription.addSubscriptionItems(graph, defaultSubscriptionResource, variable); - - List refs = new ArrayList(1); - refs.add( AddChartItem.createDescriptor(graph, subscriptionItem) ); - - AddChartItem ci = new AddChartItem( chart, refs ); - ci.perform(graph); - - return ci.chartItem; - } - - /** - * links given subscription to the given chart - * - * @param subscriptionItem resource of the subscription - * @param chart resource of the chart - * @return resource of the created chart item - * @throws DatabaseException on database failures - */ - public static Resource linkSubToChart (WriteGraph graph, Resource subscriptionItem, Resource chart) throws DatabaseException { - - List refs = new ArrayList(1); - refs.add( AddChartItem.createDescriptor(graph, subscriptionItem) ); - - AddChartItem ci = new AddChartItem( chart, refs ); - ci.perform(graph); - - return ci.chartItem; - } - +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.charts.ui; + +import java.util.ArrayList; +import java.util.List; + +import org.simantics.charts.query.AddChartItem; +import org.simantics.charts.query.ChartItemDescriptor; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.modeling.subscription.SCLSubscription; + +/** + * @author Jani Simomaa + */ +public class SCLChart { + + /** + * Creates new chart under given model + * + * @param targetModel resource of the target model + * @return resource of the chart + * @throws DatabaseException on database failures + */ + public static Resource createNewChart (Resource targetModel) throws DatabaseException { + + Resource chart = NewChart.createChart(targetModel); + return chart; + } + + /** + * Creates new chart group under given model + * + * @param targetModel resource of the target model + * @return resource of the chartGroup + * @throws DatabaseException on database failures + */ + public static Resource createNewChartGroup (Resource targetModel) throws DatabaseException { + + Resource chartGroup = NewChartGroup.createChartGroup(targetModel); + return chartGroup; + } + + /** + * Adds chart items to the given chart + * + * @param chart resource of the target chart + * @param variable variable of the item to be created + * @return resource of the created chart item + * @throws DatabaseException on database failures + */ + public static Resource addChartItems (WriteGraph graph, Resource chart, Variable variable) throws DatabaseException { + + Resource model = Variables.getModel(graph, variable); + Resource defaultSubscriptionResource = SCLSubscription.defaultSubscriptionFolder(graph, model); + Resource subscriptionItem = SCLSubscription.addSubscriptionItems(graph, defaultSubscriptionResource, variable); + + List refs = new ArrayList(1); + refs.add( AddChartItem.createDescriptor(graph, subscriptionItem) ); + + AddChartItem ci = new AddChartItem( chart, refs ); + ci.perform(graph); + + return ci.chartItem; + } + + /** + * links given subscription to the given chart + * + * @param subscriptionItem resource of the subscription + * @param chart resource of the chart + * @return resource of the created chart item + * @throws DatabaseException on database failures + */ + public static Resource linkSubToChart (WriteGraph graph, Resource subscriptionItem, Resource chart) throws DatabaseException { + + List refs = new ArrayList(1); + refs.add( AddChartItem.createDescriptor(graph, subscriptionItem) ); + + AddChartItem ci = new AddChartItem( chart, refs ); + ci.perform(graph); + + return ci.chartItem; + } + } \ No newline at end of file