]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
String formatter property using SCL function instead of adapter
authorAntti Villberg <antti.villberg@semantum.fi>
Wed, 26 Sep 2018 07:31:36 +0000 (09:31 +0200)
committerAntti Villberg <antti.villberg@semantum.fi>
Wed, 26 Sep 2018 07:31:36 +0000 (09:31 +0200)
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..74f1b62bc37e3dcb4ce799964bdfb130e4b4590e 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> {
        
@@ -119,11 +120,19 @@ public class DisplayValueVariableAdapter extends SimpleContextualAdapter<Variabl
        
        Object value = property.getValue(graph);
 
-       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 {
+        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));
+        }
+        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) {
index 7d9d1dba8b02bfcddc51526ff42a6f0491940949..10aaf26ea42ba539e7b13d4c2c7eeb2c2fc76abd 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,22 @@ 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();