X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fadapters%2FSCLLabelRule.java;h=243ef4d3693c74545b9aec74f521d551555aaeda;hp=b788128c380318f0ac817e486e26dad633facff1;hb=fa7f0fb93e91d0042387faff57393758dcdbf890;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLLabelRule.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLLabelRule.java index b788128c3..243ef4d36 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLLabelRule.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLLabelRule.java @@ -1,57 +1,64 @@ -package org.simantics.modeling.adapters; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.simantics.browsing.ui.model.labels.LabelRule; -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.db.layer0.variable.Variables; -import org.simantics.modeling.ModelingResources; -import org.simantics.scl.runtime.SCLContext; -import org.simantics.scl.runtime.function.Function1; - -public class SCLLabelRule implements LabelRule { - - private Resource rule; - - public SCLLabelRule(ReadGraph graph, Resource rule) { - this.rule = rule; - } - - @Override - public boolean isCompatible(Class contentType) { - return contentType.equals(Resource.class) || contentType.equals(Variable.class); - } - - @Override - public Map getLabel(ReadGraph graph, Object content) throws DatabaseException { - ModelingResources MOD = ModelingResources.getInstance(graph); - - Variable ruleVariable = Variables.getVariable(graph, rule); - - Function1> getLabels = ruleVariable.getPossiblePropertyValue(graph, MOD.SCLLabelRule_getLabels); - if(getLabels == null) return Collections.emptyMap(); - - SCLContext sclContext = SCLContext.getCurrent(); - Object oldGraph = sclContext.get("graph"); - try { - sclContext.put("graph", graph); - List value = getLabels.apply(content); - Map result = new HashMap<>(); - for(int i=0;i contentType) { + return contentType.equals(Resource.class) || contentType.equals(Variable.class); + } + + @Override + public Map getLabel(ReadGraph graph, Object content) throws DatabaseException { + ModelingResources MOD = ModelingResources.getInstance(graph); + + Variable ruleVariable = Variables.getVariable(graph, rule); + + Function1> getLabels = ruleVariable.getPossiblePropertyValue(graph, MOD.SCLLabelRule_getLabels); + if(getLabels == null) { + LOGGER.warn("Didn't find value for subject={}, predicate={}.", rule, ModelingResources.URIs.SCLLabelRule_getLabels); + return Collections.emptyMap(); + } + + SCLContext sclContext = SCLContext.getCurrent(); + Object oldGraph = sclContext.get("graph"); + try { + sclContext.put("graph", graph); + List value = getLabels.apply(content); + Map result = new HashMap<>(); + for(int i=0;i