]> gerrit.simantics Code Review - simantics/platform.git/blob
7d7abde42beeac330150348491c3336e4a1d7519
[simantics/platform.git] /
1 package org.simantics.document.linking.report.evaluator;
2
3 import java.util.ArrayList;
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  * Combines child node contents to separate lines.
18  * 
19  * If all children return null, the return value is null.
20  * 
21  * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
22  *
23  */
24 @OrderedSetType(DocumentLink.URIs.EvaluatorTree_Lines)
25 public class Lines extends EvaluatorNode {
26
27         
28         @Override
29         public String getValue(ReadGraph graph, Variable variable, Map<Object, Object> context) throws DatabaseException {
30                 String s = "";
31                 for (int i = 0 ; i < children.size(); i++) {
32                         String s2 = children.get(i).getValue(graph, variable, context);
33                         if (s2 != null) {
34                                 s+= s2;
35                                 if (i < children.size()-1)
36                                         s+=System.getProperty("line.separator");
37                         }
38                 }
39                 if (s.length() == 0)
40                         return null;
41                 return s;
42         }
43         
44
45         @Override
46         public String toString() {
47                 return "Lines" ;
48         }
49         
50         
51         
52         @Override
53         public List<DocumentLine> getLines(ReadGraph graph,     Variable variable, Map<Object, Object> context) throws DatabaseException {
54                 List<DocumentLine> result = new ArrayList<DocumentLine>();
55                 for (int i = 0 ; i < children.size(); i++) {
56                         result.addAll(children.get(i).getLines(graph, variable, context));
57                 }
58                 return result;
59         }
60         
61         @Override
62         public EvaluatorItem copy() {
63                 Lines lines = new Lines();
64                 copyChildren(lines);
65                 return lines;
66         }
67         
68         @Override
69         public ImageDescriptor getImage() {
70                 return Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/text_linespacing.png");
71         }
72
73 }