From: Antti Villberg Date: Wed, 26 Sep 2018 07:31:36 +0000 (+0200) Subject: String formatter property using SCL function instead of adapter X-Git-Tag: v1.43.0~136^2~351 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F42%2F2242%2F5;p=simantics%2Fplatform.git String formatter property using SCL function instead of adapter gitlab #135 Change-Id: Ibecb72ea24a00112c49b8f381ad1fd9b7eee438f --- diff --git a/bundles/org.simantics.selectionview.ontology/graph/Selectionview.pgraph b/bundles/org.simantics.selectionview.ontology/graph/Selectionview.pgraph index 4bfeebffa..861f705d7 100644 --- a/bundles/org.simantics.selectionview.ontology/graph/Selectionview.pgraph +++ b/bundles/org.simantics.selectionview.ontology/graph/Selectionview.pgraph @@ -48,6 +48,7 @@ SEL.TypedVariableTabContribution "Dynamic -> String" { @@ -117,20 +118,28 @@ public class DisplayValueVariableAdapter extends SimpleContextualAdapter formatterFunction = property.getPossiblePropertyValue(graph, SEL.formatter); + if(formatterFunction != null) { + value = formatterFunction.apply(property.getValue(graph)); + } + } + if(value == null) { Datatype dt = property.getPossibleDatatype(graph); if(dt != null) { if(!isPrimitive(dt)) { Binding binding = Bindings.getBinding(dt); try { - value = DataValuePrinter.writeValueSingleLine(binding, value); + value = DataValuePrinter.writeValueSingleLine(binding, property.getValue(graph)); } catch (IOException e) { e.printStackTrace(); } catch (BindingException e) { diff --git a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/function/All.java b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/function/All.java index 7d9d1dba8..79541b061 100644 --- a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/function/All.java +++ b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/function/All.java @@ -53,7 +53,9 @@ import org.simantics.scl.compiler.types.TVar; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; import org.simantics.scl.reflection.annotations.SCLValue; +import org.simantics.scl.runtime.function.Function1; import org.simantics.selectionview.SelectionInput; +import org.simantics.selectionview.SelectionViewResources; import org.simantics.selectionview.StandardSelectionInput; import org.simantics.ui.colors.Colors; import org.simantics.ui.fonts.Fonts; @@ -451,15 +453,20 @@ public class All { Object value = null; Resource formatter = property.getPossiblePropertyValue(graph, Variables.FORMATTER); if(formatter != null) { - Formatter fmt = graph.adaptContextual(formatter, property, Variable.class, Formatter.class); value = fmt.format(property.getValue(graph)); - - } else { + } + if(value == null) { + SelectionViewResources SEL = SelectionViewResources.getInstance(graph); + Function1 formatterFunction = property.getPossiblePropertyValue(graph, SEL.formatter); + if(formatterFunction != null) { + value = formatterFunction.apply(property.getValue(graph)); + } + } + if(value == null) { Variant variant = property.getVariantValue(graph); value = variant.getValue(); - Binding binding = variant.getBinding(); if(binding != null) { Datatype dt = binding.type();