-/*******************************************************************************\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
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.charts.function;
+
+import org.simantics.charts.ontology.ChartResource;
+import org.simantics.charts.ui.ChartItemLabelRule;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.subscription.SubscriptionItemLabel;
+import org.simantics.scl.reflection.annotations.SCLValue;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class Labels {
+
+ @SCLValue(type = "ReadGraph -> Resource -> a -> String")
+ public static String chartItemLabel(ReadGraph graph, Resource resource, Object context) throws DatabaseException {
+ if (context instanceof Resource) {
+ return ChartItemLabelRule.INSTANCE.getLabel_(graph, (Resource) context);
+ } else if (context instanceof Variable) {
+ Variable var = (Variable)context;
+ Resource r = var.getParent(graph).getPossibleRepresents(graph);
+ if(r == null) return "";
+ return ChartItemLabelRule.INSTANCE.getLabel_(graph, r);
+ } else {
+ throw new DatabaseException("Unknown context " + context);
+ }
+ }
+
+ @SCLValue(type = "ReadGraph -> Resource -> a -> String")
+ public static String chartItemSubscriptionInfo(ReadGraph graph, Resource resource, Object context) throws DatabaseException {
+ Resource chartItem = null;
+ if (context instanceof Resource) {
+ chartItem = (Resource) context;
+ } else if (context instanceof Variable) {
+ Variable var = (Variable) context;
+ chartItem = var.getParent(graph).getPossibleRepresents(graph);
+ } else {
+ throw new DatabaseException("Unknown context " + context);
+ }
+ if (chartItem == null)
+ return "";
+
+ ChartResource CHART = ChartResource.getInstance(graph);
+ Resource subscriptionItem = graph.getPossibleObject(chartItem, CHART.Chart_Item_HasSubscriptionItem);
+ if (subscriptionItem == null)
+ return "Not bound to a subscription item";
+
+ String itemLabel = SubscriptionItemLabel.resolveLabel(graph, subscriptionItem, null, false, false, false);
+
+ Layer0 L0 = Layer0.getInstance(graph);
+ Resource subscription = graph.getPossibleObject(subscriptionItem, L0.PartOf);
+ if (subscription != null) {
+ String subscriptionLabel = graph.getPossibleRelatedValue2(subscription, L0.HasLabel, Bindings.STRING);
+ if (subscriptionLabel != null) {
+ return itemLabel + " in subscription " + subscriptionLabel;
+ }
+ }
+
+ return itemLabel;
+ }
+
}
\ No newline at end of file