]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
String formatter property using SCL function instead of adapter 42/2242/5
authorAntti Villberg <antti.villberg@semantum.fi>
Wed, 26 Sep 2018 07:31:36 +0000 (09:31 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 28 Sep 2018 19:52:01 +0000 (19:52 +0000)
gitlab #135

Change-Id: Ibecb72ea24a00112c49b8f381ad1fd9b7eee438f

bundles/org.simantics.selectionview.ontology/graph/Selectionview.pgraph
bundles/org.simantics.selectionview/src/org/simantics/selectionview/DisplayValueVariableAdapter.java
bundles/org.simantics.selectionview/src/org/simantics/selectionview/function/All.java

index 4bfeebffadc11bad23a571dfa5f576fcbb3b6ec9..861f705d7a31dc8061d1848b347cb613ddcdb4ea 100644 (file)
@@ -48,6 +48,7 @@ SEL.TypedVariableTabContribution <T SEL.VariableTabContribution
 SEL.HasDisplayColumn <R L0.HasProperty : L0.FunctionalRelation
 
 SEL.HasFormatter <R L0.HasProperty : L0X.ResourcePropertyRelation
+SEL.formatter ==> "Dynamic -> String" <R L0.HasProperty
 
 SEL.HasDisplayProperty <R L0.HasProperty : L0.FunctionalRelation
   L0.RequiresValueType "String"
index 2eaba75d60db700d72c2d1a337363df7c265ef43..7d90d33926c9d94675dbed2665d44515548f4f15 100644 (file)
@@ -31,6 +31,7 @@ import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
 import org.simantics.layer0.Layer0;
 import org.simantics.modeling.ModelingResources;
+import org.simantics.scl.runtime.function.Function1;
 
 public class DisplayValueVariableAdapter extends SimpleContextualAdapter<Variable, ModelledVariablePropertyDescriptor> {
        
@@ -117,20 +118,28 @@ public class DisplayValueVariableAdapter extends SimpleContextualAdapter<Variabl
        String expression = possibleExpression(graph, property);
        if(expression != null) return expression;
        
-       Object value = property.getValue(graph);
+       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(value);
-       } else {
+               value = fmt.format(property.getValue(graph));
+       }
+       if(value == null) {
+               SelectionViewResources SEL = SelectionViewResources.getInstance(graph);
+               Function1<Object,String> 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) {
index 7d9d1dba8b02bfcddc51526ff42a6f0491940949..79541b06134deb344a5f6f71c4dda854edcfc145 100644 (file)
@@ -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<Object,String> 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();