]> gerrit.simantics Code Review - simantics/platform.git/blob - diagram/monitor/DefaultFormattedVariableLabel.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / diagram / monitor / DefaultFormattedVariableLabel.java
1 package org.simantics.modeling.ui.diagram.monitor;
2
3 import org.simantics.common.format.Formatter;
4 import org.simantics.databoard.Bindings;
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.common.utils.Logger;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.db.layer0.variable.Variable;
9 import org.simantics.db.layer0.variable.Variables;
10 import org.simantics.scl.runtime.function.FunctionImpl4;
11
12 public class DefaultFormattedVariableLabel extends FunctionImpl4 {
13
14         @Override
15         public Object apply(Object p0, Object p1, Object p2, Object p3) {
16                 
17                 try {
18
19                         ReadGraph graph = (ReadGraph)p0;
20                         Variable root = (Variable)p1;
21                         Formatter formatter = (Formatter)p2;
22                         String rvi = (String)p3;
23                         
24                         Variable var = root.browse(graph, rvi);
25                         
26                         Object value = var.getPossiblePropertyValue(graph, Variables.CONVERTED_VALUE, Bindings.STRING);
27                         if(value == null) {
28                                 value = var.getValue(graph);
29                         }
30                         
31                         return formatter.format(value);
32                         
33                 } catch (DatabaseException e) {
34                         Logger.defaultLogError(e);
35                         return null;
36                 }
37                         
38         }
39
40 }