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