1 /*******************************************************************************
2 * Copyright (c) 2011 Association for Decentralized Information Management in
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 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.charts.function;
14 import org.simantics.charts.ontology.ChartResource;
15 import org.simantics.charts.ui.ChartItemLabelRule;
16 import org.simantics.databoard.Bindings;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.layer0.variable.Variable;
21 import org.simantics.layer0.Layer0;
22 import org.simantics.modeling.subscription.SubscriptionItemLabel;
23 import org.simantics.scl.reflection.annotations.SCLValue;
26 * @author Tuukka Lehtonen
30 @SCLValue(type = "ReadGraph -> Resource -> a -> String")
31 public static String chartItemLabel(ReadGraph graph, Resource resource, Object context) throws DatabaseException {
32 if (context instanceof Resource) {
33 return ChartItemLabelRule.INSTANCE.getLabel_(graph, (Resource) context);
34 } else if (context instanceof Variable) {
35 Variable var = (Variable)context;
36 Resource r = var.getParent(graph).getPossibleRepresents(graph);
37 if(r == null) return "";
38 return ChartItemLabelRule.INSTANCE.getLabel_(graph, r);
40 throw new DatabaseException("Unknown context " + context);
44 @SCLValue(type = "ReadGraph -> Resource -> a -> String")
45 public static String chartItemSubscriptionInfo(ReadGraph graph, Resource resource, Object context) throws DatabaseException {
46 Resource chartItem = null;
47 if (context instanceof Resource) {
48 chartItem = (Resource) context;
49 } else if (context instanceof Variable) {
50 Variable var = (Variable) context;
51 chartItem = var.getParent(graph).getPossibleRepresents(graph);
53 throw new DatabaseException("Unknown context " + context);
55 if (chartItem == null)
58 ChartResource CHART = ChartResource.getInstance(graph);
59 Resource subscriptionItem = graph.getPossibleObject(chartItem, CHART.Chart_Item_HasSubscriptionItem);
60 if (subscriptionItem == null)
61 return "Not bound to a subscription item";
63 String itemLabel = SubscriptionItemLabel.resolveLabel(graph, subscriptionItem, null, false, false, false);
65 Layer0 L0 = Layer0.getInstance(graph);
66 Resource subscription = graph.getPossibleObject(subscriptionItem, L0.PartOf);
67 if (subscription != null) {
68 String subscriptionLabel = graph.getPossibleRelatedValue2(subscription, L0.HasLabel, Bindings.STRING);
69 if (subscriptionLabel != null) {
70 return itemLabel + " in subscription " + subscriptionLabel;