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