X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.document.linking.ui%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Flinking%2Freport%2Fevaluator%2FIf.java;h=e0e7839391ca9fefc508d8dc32bf818db8a3c8af;hb=e88be95edf1f80781646cfdf717ec1b663264179;hp=2ac3620f83dbc9c811f7e35327b204a648ffc9fd;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/report/evaluator/If.java b/bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/report/evaluator/If.java index 2ac3620f8..e0e783939 100644 --- a/bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/report/evaluator/If.java +++ b/bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/report/evaluator/If.java @@ -1,89 +1,89 @@ -package org.simantics.document.linking.report.evaluator; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.simantics.db.ReadGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.document.linking.Activator; -import org.simantics.document.linking.ontology.DocumentLink; -import org.simantics.document.linking.report.DocumentLine; -import org.simantics.objmap.graph.annotations.OrderedSetType; - -/** - * Checks that the first size does not return null or "false". - * Depending on results evaluates the second child or the third (if it exists). - * - * @author Marko Luukkainen - * - */ -@OrderedSetType(DocumentLink.URIs.EvaluatorTree_If) -public class If extends EvaluatorNode{ - - @Override - public String getValue(ReadGraph graph, Variable variable, Map context) throws DatabaseException { - if (children.size() > 3) - throw new DatabaseException("If node has more than 3 children."); - - String ifVal = children.get(0).getValue(graph, variable, context); - if (ifVal != null && ifVal.length() > 0 && !Boolean.FALSE.toString().equals(ifVal)) { - return children.get(1).getValue(graph, variable, context); - } else if (children.size() == 3) { - return children.get(2).getValue(graph, variable, context); - } - return null; - } - - @Override - public List getLines(ReadGraph graph, Variable variable, Map context) throws DatabaseException { - if (children.size() > 3) - throw new DatabaseException("If node has more than 3 children."); - String ifVal = children.get(0).getValue(graph, variable, context); - if (ifVal != null && ifVal.length() > 0 && !Boolean.FALSE.toString().equals(ifVal)) { - return children.get(1).getLines(graph, variable, context); - } else if (children.size() == 3) { - return children.get(2).getLines(graph, variable, context); - } - return Collections.emptyList(); - } - - - @Override - public String toString() { - return "if"; - } - - @Override - public List> getPossibleChildren(boolean add) { - if (add && children.size() == 3) - return Collections.emptyList(); - return super.getPossibleChildren(add); - } - - @Override - public EvaluatorItem copy() { - If node = new If(); - copyChildren(node); - return node; - - } - - @Override - public ImageDescriptor getImage() { - return Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/help.png"); - } - - @Override - public boolean acceptChild(EvaluatorItem item) { - return children.size() < 3; - } - - @Override - public boolean acceptChild(int index, EvaluatorItem item) { - return children.size() < 3; - } - -} +package org.simantics.document.linking.report.evaluator; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.document.linking.Activator; +import org.simantics.document.linking.ontology.DocumentLink; +import org.simantics.document.linking.report.DocumentLine; +import org.simantics.objmap.graph.annotations.OrderedSetType; + +/** + * Checks that the first size does not return null or "false". + * Depending on results evaluates the second child or the third (if it exists). + * + * @author Marko Luukkainen + * + */ +@OrderedSetType(DocumentLink.URIs.EvaluatorTree_If) +public class If extends EvaluatorNode{ + + @Override + public String getValue(ReadGraph graph, Variable variable, Map context) throws DatabaseException { + if (children.size() > 3) + throw new DatabaseException("If node has more than 3 children."); + + String ifVal = children.get(0).getValue(graph, variable, context); + if (ifVal != null && ifVal.length() > 0 && !Boolean.FALSE.toString().equals(ifVal)) { + return children.get(1).getValue(graph, variable, context); + } else if (children.size() == 3) { + return children.get(2).getValue(graph, variable, context); + } + return null; + } + + @Override + public List getLines(ReadGraph graph, Variable variable, Map context) throws DatabaseException { + if (children.size() > 3) + throw new DatabaseException("If node has more than 3 children."); + String ifVal = children.get(0).getValue(graph, variable, context); + if (ifVal != null && ifVal.length() > 0 && !Boolean.FALSE.toString().equals(ifVal)) { + return children.get(1).getLines(graph, variable, context); + } else if (children.size() == 3) { + return children.get(2).getLines(graph, variable, context); + } + return Collections.emptyList(); + } + + + @Override + public String toString() { + return "if"; + } + + @Override + public List> getPossibleChildren(boolean add) { + if (add && children.size() == 3) + return Collections.emptyList(); + return super.getPossibleChildren(add); + } + + @Override + public EvaluatorItem copy() { + If node = new If(); + copyChildren(node); + return node; + + } + + @Override + public ImageDescriptor getImage() { + return Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/help.png"); + } + + @Override + public boolean acceptChild(EvaluatorItem item) { + return children.size() < 3; + } + + @Override + public boolean acceptChild(int index, EvaluatorItem item) { + return children.size() < 3; + } + +}