1 package org.simantics.document.linking.report.evaluator;
3 import java.util.Collections;
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;
17 * Checks that the first size does not return null or "false".
18 * Depending on results evaluates the second child or the third (if it exists).
20 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
23 @OrderedSetType(DocumentLink.URIs.EvaluatorTree_If)
24 public class If extends EvaluatorNode{
27 public String getValue(ReadGraph graph, Variable variable, Map<Object, Object> context) throws DatabaseException {
28 if (children.size() > 3)
29 throw new DatabaseException("If node has more than 3 children.");
31 String ifVal = children.get(0).getValue(graph, variable, context);
32 if (ifVal != null && ifVal.length() > 0 && !Boolean.FALSE.toString().equals(ifVal)) {
33 return children.get(1).getValue(graph, variable, context);
34 } else if (children.size() == 3) {
35 return children.get(2).getValue(graph, variable, context);
41 public List<DocumentLine> getLines(ReadGraph graph, Variable variable, Map<Object, Object> context) throws DatabaseException {
42 if (children.size() > 3)
43 throw new DatabaseException("If node has more than 3 children.");
44 String ifVal = children.get(0).getValue(graph, variable, context);
45 if (ifVal != null && ifVal.length() > 0 && !Boolean.FALSE.toString().equals(ifVal)) {
46 return children.get(1).getLines(graph, variable, context);
47 } else if (children.size() == 3) {
48 return children.get(2).getLines(graph, variable, context);
50 return Collections.emptyList();
55 public String toString() {
60 public List<Class<? extends EvaluatorItem>> getPossibleChildren(boolean add) {
61 if (add && children.size() == 3)
62 return Collections.emptyList();
63 return super.getPossibleChildren(add);
67 public EvaluatorItem copy() {
75 public ImageDescriptor getImage() {
76 return Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/help.png");
80 public boolean acceptChild(EvaluatorItem item) {
81 return children.size() < 3;
85 public boolean acceptChild(int index, EvaluatorItem item) {
86 return children.size() < 3;