]> gerrit.simantics Code Review - simantics/platform.git/blob
c18a1b6e41c96cdcb5a82e77abaa6339fe86aa00
[simantics/platform.git] /
1 package org.simantics.document.linking.report.evaluator;
2
3 import java.util.Collections;
4 import java.util.List;
5 import java.util.Map;
6
7 import org.eclipse.jface.resource.ImageDescriptor;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.db.layer0.variable.Variable;
11 import org.simantics.document.linking.Activator;
12 import org.simantics.document.linking.ontology.DocumentLink;
13 import org.simantics.document.linking.report.DocumentLine;
14 import org.simantics.objmap.graph.annotations.OrderedSetType;
15
16
17 /**
18  * Or node returns the first non null value of children.
19  * 
20  * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
21  *
22  */
23
24 @OrderedSetType(DocumentLink.URIs.EvaluatorTree_Or)
25 public class Or extends EvaluatorNode{
26         
27         
28         
29         @Override
30         public String getValue(ReadGraph graph, Variable variable, Map<Object, Object> context) throws DatabaseException {
31                 
32                 for (int i = 0 ; i < children.size(); i++) {
33                         String s =  children.get(i).getValue(graph, variable, context);
34                         if (s != null && s.length() > 0)
35                                 return s;
36                 }
37                 
38                 return null;
39         }
40         
41         @Override
42         public List<DocumentLine> getLines(ReadGraph graph,     Variable variable, Map<Object, Object> context) throws DatabaseException {
43                 for (int i = 0 ; i < children.size(); i++) {
44                         List<DocumentLine> list = children.get(i).getLines(graph, variable, context);
45                         if (list.size() > 0)
46                                 return list;
47                 }
48                 return Collections.emptyList();
49         }
50         
51         @Override
52         public String toString() {
53                 return "or";
54         }
55         
56         @Override
57         public EvaluatorItem copy() {
58                 Or or = new Or();
59                 copyChildren(or);
60                 return or;
61         }
62         
63         @Override
64         public ImageDescriptor getImage() {
65                 return Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/text_list_numbers.png");
66         }
67         
68         
69
70 }