1 package org.simantics.document.linking.report.evaluator;
3 import java.util.ArrayList;
4 import java.util.HashMap;
8 import org.eclipse.jface.resource.ImageDescriptor;
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.variable.Variable;
12 import org.simantics.document.linking.Activator;
13 import org.simantics.document.linking.ontology.DocumentLink;
14 import org.simantics.document.linking.report.DocumentLine;
15 import org.simantics.objmap.graph.annotations.OrderedSetType;
16 import org.simantics.objmap.graph.annotations.RelatedGetValue;
17 import org.simantics.objmap.graph.annotations.RelatedSetValue;
20 * And node combines contents of the child nodes with configurable separator (default " ")
22 * If all children return null, the return value is null.
24 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
27 @OrderedSetType(DocumentLink.URIs.EvaluatorTree_And)
28 public class And extends EvaluatorNode implements StringEditableNode{
37 public And(String separator) {
38 this.separator = separator;
41 public void setSeparator(String separator) {
42 this.separator = separator;
45 public String getSeparator() {
51 public String getValue(ReadGraph graph, Variable variable, Map<Object, Object> context) throws DatabaseException {
53 for (int i = 0 ; i < children.size(); i++) {
54 String s2 = children.get(i).getValue(graph, variable, context);
57 if (i < children.size()-1)
67 public List<DocumentLine> getLines(ReadGraph graph, Variable variable, Map<Object, Object> context) throws DatabaseException {
68 List<DocumentLine> result = new ArrayList<DocumentLine>();
69 for (int i = 0 ; i < children.size(); i++) {
70 List<DocumentLine> list = children.get(i).getLines(graph, variable, context);
71 for (int j = 0; j < list.size(); j++) {
72 DocumentLine line = list.get(j);
73 if (j <= result.size()) {
76 DocumentLine extLine = result.get(j);
77 String combined = extLine.getLine() + separator + line.getLine();
78 Map<Object,Object> combinedSet = new HashMap<Object, Object>();
79 combinedSet.putAll(extLine.getHints());
80 combinedSet.putAll(line.getHints());
82 result.set(j, new DocumentLine(combined,combinedSet));
91 public String toString() {
92 return "and " + "(" + separator +")" ;
95 @RelatedGetValue(DocumentLink.URIs.EvaluatorTree_HasValue)
97 public String getValue() {
102 public String setValue(String value) {
107 @RelatedSetValue(DocumentLink.URIs.EvaluatorTree_HasValue)
108 public void _setValue(String value) {
113 public EvaluatorItem copy() {
114 And a = new And(separator);
120 public ImageDescriptor getImage() {
121 return Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/text_columns.png");