--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.charts.function;\r
+\r
+import org.simantics.charts.ontology.ChartResource;\r
+import org.simantics.charts.ui.ChartItemLabelRule;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.subscription.SubscriptionItemLabel;\r
+import org.simantics.scl.reflection.annotations.SCLValue;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class Labels {\r
+\r
+ @SCLValue(type = "ReadGraph -> Resource -> a -> String")\r
+ public static String chartItemLabel(ReadGraph graph, Resource resource, Object context) throws DatabaseException {\r
+ if (context instanceof Resource) {\r
+ return ChartItemLabelRule.INSTANCE.getLabel_(graph, (Resource) context);\r
+ } else if (context instanceof Variable) {\r
+ Variable var = (Variable)context;\r
+ Resource r = var.getParent(graph).getPossibleRepresents(graph);\r
+ if(r == null) return "";\r
+ return ChartItemLabelRule.INSTANCE.getLabel_(graph, r);\r
+ } else {\r
+ throw new DatabaseException("Unknown context " + context);\r
+ }\r
+ }\r
+\r
+ @SCLValue(type = "ReadGraph -> Resource -> a -> String")\r
+ public static String chartItemSubscriptionInfo(ReadGraph graph, Resource resource, Object context) throws DatabaseException {\r
+ Resource chartItem = null;\r
+ if (context instanceof Resource) {\r
+ chartItem = (Resource) context;\r
+ } else if (context instanceof Variable) {\r
+ Variable var = (Variable) context;\r
+ chartItem = var.getParent(graph).getPossibleRepresents(graph);\r
+ } else {\r
+ throw new DatabaseException("Unknown context " + context);\r
+ }\r
+ if (chartItem == null)\r
+ return "";\r
+\r
+ ChartResource CHART = ChartResource.getInstance(graph);\r
+ Resource subscriptionItem = graph.getPossibleObject(chartItem, CHART.Chart_Item_HasSubscriptionItem);\r
+ if (subscriptionItem == null)\r
+ return "Not bound to a subscription item";\r
+\r
+ String itemLabel = SubscriptionItemLabel.resolveLabel(graph, subscriptionItem, null, false, false, false);\r
+\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ Resource subscription = graph.getPossibleObject(subscriptionItem, L0.PartOf);\r
+ if (subscription != null) {\r
+ String subscriptionLabel = graph.getPossibleRelatedValue2(subscription, L0.HasLabel, Bindings.STRING);\r
+ if (subscriptionLabel != null) {\r
+ return itemLabel + " in subscription " + subscriptionLabel;\r
+ }\r
+ }\r
+\r
+ return itemLabel;\r
+ }\r
+\r
+}
\ No newline at end of file