]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/report/evaluator/Variable.java
Externalize org.simantics.document.linking.ui
[simantics/platform.git] / bundles / org.simantics.document.linking.ui / src / org / simantics / document / linking / report / evaluator / Variable.java
1 package org.simantics.document.linking.report.evaluator;
2
3 import java.util.Map;
4
5 import org.eclipse.jface.resource.ImageDescriptor;
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.document.linking.Activator;
9 import org.simantics.document.linking.ontology.DocumentLink;
10 import org.simantics.document.linking.utils.SourceLinkUtil;
11 import org.simantics.objmap.graph.annotations.GraphType;
12 import org.simantics.objmap.graph.annotations.RelatedGetValue;
13 import org.simantics.objmap.graph.annotations.RelatedSetValue;
14
15
16 @GraphType(DocumentLink.URIs.EvaluatorTree_Variable)
17 public class Variable extends EvaluatorLeaf implements StringEditableNode{
18         
19         String variableRef = "#HasName"; //$NON-NLS-1$
20         
21         public Variable() {
22                 
23         }
24         
25         public Variable(String variableRef) {
26                 this.variableRef = variableRef;
27         }
28         
29         public void setVariableRef(String variableRef) {
30                 this.variableRef = variableRef;
31         }
32         
33         public String getVariableRef() {
34                 return variableRef;
35         }
36         
37         @Override
38         public String getValue(ReadGraph graph, org.simantics.db.layer0.variable.Variable variable, Map<Object, Object> context) throws DatabaseException {
39                 if (context.containsKey(variableRef))
40                         return SourceLinkUtil.getValueString(context.get(variableRef));
41                 try {
42                         org.simantics.db.layer0.variable.Variable propertyVar = PredefinedVariables.getInstance().getVariable(graph, variableRef, null, variable);
43                         if (propertyVar.getRepresents(graph) == null)
44                                 return null;
45                         return SourceLinkUtil.getValueString(propertyVar.getValue(graph));
46                 } catch (Exception e) {
47                         return null;
48                 }
49         }
50         
51         
52         
53
54         @Override
55         public String toString() {
56                 return variableRef;
57         }
58         
59         @RelatedGetValue(DocumentLink.URIs.EvaluatorTree_HasValue)
60         @Override
61         public String getValue() {
62                 return variableRef;
63         }
64         
65         
66         @Override
67         public String setValue(String value) {
68                 if (value.length() == 0)
69                         return "Variable reference cannot be empty"; //$NON-NLS-1$
70                 variableRef = value;
71                 return null;
72         }
73         
74         @RelatedSetValue(DocumentLink.URIs.EvaluatorTree_HasValue)
75         public void _setValue(String value) {
76                 variableRef = value;
77         }
78         
79         
80         @Override
81         public EvaluatorItem copy() {
82                 return new Variable(variableRef);
83         }
84         
85         @Override
86         public ImageDescriptor getImage() {
87                 return Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/database_go.png"); //$NON-NLS-1$ //$NON-NLS-2$
88         }
89         
90
91 }