]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.selectionview/src/org/simantics/selectionview/DisplayValueVariableAdapter.java
String formatter property using SCL function instead of adapter
[simantics/platform.git] / bundles / org.simantics.selectionview / src / org / simantics / selectionview / DisplayValueVariableAdapter.java
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) {