--- /dev/null
+package org.simantics.document.linking.report.evaluator;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.document.linking.Activator;\r
+import org.simantics.document.linking.ontology.DocumentLink;\r
+import org.simantics.document.linking.report.DocumentLine;\r
+import org.simantics.objmap.graph.annotations.OrderedSetType;\r
+import org.simantics.objmap.graph.annotations.RelatedGetValue;\r
+import org.simantics.objmap.graph.annotations.RelatedSetValue;\r
+\r
+/**\r
+ * And node combines contents of the child nodes with configurable separator (default " ")\r
+ * \r
+ * If all children return null, the return value is null.\r
+ * \r
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
+ *\r
+ */\r
+@OrderedSetType(DocumentLink.URIs.EvaluatorTree_And)\r
+public class And extends EvaluatorNode implements StringEditableNode{\r
+ \r
+ String separator;\r
+ \r
+ \r
+ public And() {\r
+ separator = " ";\r
+ }\r
+ \r
+ public And(String separator) {\r
+ this.separator = separator;\r
+ }\r
+ \r
+ public void setSeparator(String separator) {\r
+ this.separator = separator;\r
+ }\r
+ \r
+ public String getSeparator() {\r
+ return separator;\r
+ }\r
+ \r
+ \r
+ @Override\r
+ public String getValue(ReadGraph graph, Variable variable, Map<Object, Object> context) throws DatabaseException {\r
+ String s = "";\r
+ for (int i = 0 ; i < children.size(); i++) {\r
+ String s2 = children.get(i).getValue(graph, variable, context);\r
+ if (s2 != null) {\r
+ s+= s2;\r
+ if (i < children.size()-1)\r
+ s+=separator;\r
+ }\r
+ }\r
+ if (s.length() == 0)\r
+ return null;\r
+ return s;\r
+ }\r
+ \r
+ @Override\r
+ public List<DocumentLine> getLines(ReadGraph graph, Variable variable, Map<Object, Object> context) throws DatabaseException {\r
+ List<DocumentLine> result = new ArrayList<DocumentLine>();\r
+ for (int i = 0 ; i < children.size(); i++) {\r
+ List<DocumentLine> list = children.get(i).getLines(graph, variable, context);\r
+ for (int j = 0; j < list.size(); j++) {\r
+ DocumentLine line = list.get(j); \r
+ if (j <= result.size()) {\r
+ result.add(line);\r
+ } else {\r
+ DocumentLine extLine = result.get(j);\r
+ String combined = extLine.getLine() + separator + line.getLine();\r
+ Map<Object,Object> combinedSet = new HashMap<Object, Object>();\r
+ combinedSet.putAll(extLine.getHints());\r
+ combinedSet.putAll(line.getHints());\r
+ \r
+ result.set(j, new DocumentLine(combined,combinedSet));\r
+ }\r
+ }\r
+ }\r
+ return result;\r
+ }\r
+ \r
+\r
+ @Override\r
+ public String toString() {\r
+ return "and " + "(" + separator +")" ;\r
+ }\r
+ \r
+ @RelatedGetValue(DocumentLink.URIs.EvaluatorTree_HasValue)\r
+ @Override\r
+ public String getValue() {\r
+ return separator;\r
+ }\r
+ \r
+ @Override\r
+ public String setValue(String value) {\r
+ separator = value;\r
+ return null;\r
+ }\r
+ \r
+ @RelatedSetValue(DocumentLink.URIs.EvaluatorTree_HasValue)\r
+ public void _setValue(String value) {\r
+ separator = value;\r
+ }\r
+ \r
+ @Override\r
+ public EvaluatorItem copy() {\r
+ And a = new And(separator);\r
+ copyChildren(a);\r
+ return a;\r
+ }\r
+ \r
+ @Override\r
+ public ImageDescriptor getImage() {\r
+ return Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/text_columns.png");\r
+ }\r
+\r
+}\r