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%2Ffunction%2FLabels.java;fp=bundles%2Forg.simantics.charts%2Fsrc%2Forg%2Fsimantics%2Fcharts%2Ffunction%2FLabels.java;h=a909e03fd1ab21c552014c995b2d5d1643bc656e;hp=5454733d1e4032803b9e3abc0fa8ddd60e5f4092;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.charts/src/org/simantics/charts/function/Labels.java b/bundles/org.simantics.charts/src/org/simantics/charts/function/Labels.java index 5454733d1..a909e03fd 100644 --- a/bundles/org.simantics.charts/src/org/simantics/charts/function/Labels.java +++ b/bundles/org.simantics.charts/src/org/simantics/charts/function/Labels.java @@ -1,77 +1,77 @@ -/******************************************************************************* - * 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; - } - +/******************************************************************************* + * 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