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.modeling.subscription;
\r
14 import java.util.ArrayList;
\r
15 import java.util.Collection;
\r
16 import java.util.List;
\r
18 import org.simantics.db.ReadGraph;
\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.VariableReference;
\r
24 import org.simantics.layer0.Layer0;
\r
25 import org.simantics.modeling.ModelingResources;
\r
28 * @author Jani Simomaa <jani.simomaa@semantum.fi>
\r
30 public class SCLSubscription {
\r
33 * Creates new folder under given models subscription folder
\r
35 * @param model resource of the target model
\r
36 * @param name name of the folder
\r
37 * @return resource of the folder
\r
38 * @throws DatabaseException on database failures
\r
40 public static Resource addSubscriptionFolder (WriteGraph graph, Resource model, String name) throws DatabaseException {
\r
42 NewSubscription folder = new NewSubscription(model, name);
\r
43 folder.perform(graph);
\r
44 return folder.subscription;
\r
48 * Adds subscription item with default plotting values to the given subscription resource (folder).
\r
50 * @param subscriptionresource resource of the subscription folder
\r
51 * @param variable variable of the item to be created
\r
52 * @return resource of the subscription item
\r
53 * @throws DatabaseException on database failures
\r
55 public static Resource addSubscriptionItems (WriteGraph graph, Resource subscriptionresource, Variable variable) throws DatabaseException {
\r
57 VariableReference ref = new VariableReference(variable.getRVI(graph), variable.getDatatype(graph), null);
\r
58 List<VariableReference> references = new ArrayList<VariableReference>(1);
\r
59 references.add(ref);
\r
60 AddSubscriptionItems subitems = new AddSubscriptionItems(subscriptionresource, references);
\r
62 subitems.perform(graph);
\r
63 return subitems.result.get(subitems.result.size() -1);
\r
67 * Adds subscription item to the given subscription resource (folder) with advanced plotting values that user can define.
\r
69 * @param subscriptionresource resource of the subscription folder
\r
70 * @param variable variable of the item to be created
\r
77 * @return resource of the subscription item
\r
78 * @throws DatabaseException on database failures
\r
80 public static Resource newSubscriptionItem (WriteGraph graph, Resource subscriptionresource, Variable variable, double interval, double deadband, double gain, double bias, String unit, String label) throws DatabaseException {
\r
82 NewSubscriptionItem ns = new NewSubscriptionItem(
\r
83 subscriptionresource,
\r
90 variable.getRVI(graph),
\r
91 variable.getDatatype(graph)
\r
96 return ns.subscriptionItem;
\r
100 * Returns the default subscription folder of the given model. If folder with label Default is not found, returns some other subscription folder
\r
102 * @param model resource of the target model
\r
103 * @return resource of the subscription folder
\r
104 * @throws DatabaseException on database failures
\r
106 public static Resource defaultSubscriptionFolder (ReadGraph graph, Resource model) throws DatabaseException {
\r
108 Layer0 l0 = Layer0.getInstance(graph);
\r
109 ModelingResources MR = ModelingResources.getInstance(graph);
\r
110 Collection<Resource> childrens = graph.getObjects(model, l0.ConsistsOf);
\r
111 Resource folder = null;
\r
112 for (final Resource children : childrens) {
\r
114 if (graph.isInstanceOf(children, MR.Subscription)) {
\r
116 String label = graph.getRelatedValue2(folder, l0.HasLabel);
\r
117 if (label.equals("Default")) {
\r
125 public static String getLabel(ReadGraph graph, Resource subscription) throws DatabaseException {
\r
127 return SubscriptionItemLabel.resolveLabel(graph, subscription, true);
\r