1 package org.simantics.document.linking.report.evaluator;
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.HashMap;
9 import org.eclipse.jface.resource.ImageDescriptor;
10 import org.simantics.db.ReadGraph;
11 import org.simantics.db.Resource;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.db.layer0.variable.Variable;
14 import org.simantics.document.linking.Activator;
15 import org.simantics.document.linking.ontology.DocumentLink;
16 import org.simantics.document.linking.report.DocumentLine;
17 import org.simantics.objmap.graph.annotations.OrderedSetType;
18 import org.simantics.objmap.graph.annotations.RelatedGetValue;
19 import org.simantics.objmap.graph.annotations.RelatedSetValue;
21 @OrderedSetType(DocumentLink.URIs.EvaluatorTree_Path)
22 public class Path extends EvaluatorNode implements StringEditableNode{
30 public Path(String separator) {
31 this.separator = separator;
35 public String toString() {
36 return "path " + "(" + separator +")" ;
40 public String setValue(String value) {
45 @RelatedSetValue(DocumentLink.URIs.EvaluatorTree_HasValue)
46 public void _setValue(String value) {
50 @RelatedGetValue(DocumentLink.URIs.EvaluatorTree_HasValue)
52 public String getValue() {
57 public String getValue(ReadGraph graph, Variable variable,
58 Map<Object, Object> context) throws DatabaseException {
59 Resource model = (Resource)context.get("model");
61 Variable parent = variable.getParent(graph);
62 while (parent != null) {
63 text = children.get(0).getValue(graph, parent, context) + separator + text;
64 parent = parent.getParent(graph);
65 if (model.equals(parent.getRepresents(graph)))
68 if (text.length() == 0)
70 return text.substring(0,text.length()-separator.length());
74 public List<DocumentLine> getLines(ReadGraph graph, Variable variable,
75 Map<Object, Object> context) throws DatabaseException {
76 List<DocumentLine> result = new ArrayList<DocumentLine>();
77 Resource model = (Resource)context.get("model");
78 for (int i = 0 ; i < children.size(); i++) {
79 Variable parent = variable.getParent(graph);
80 while (parent != null) {
81 List<DocumentLine> list = children.get(i).getLines(graph, parent, context);
82 for (int j = 0; j < list.size(); j++) {
83 DocumentLine line = list.get(j);
84 if (j <= result.size()) {
87 DocumentLine extLine = result.get(j);
88 String combined = line.getLine() + separator + extLine.getLine();
89 Map<Object,Object> combinedSet = new HashMap<Object, Object>();
90 combinedSet.putAll(extLine.getHints());
91 combinedSet.putAll(line.getHints());
93 result.set(j, new DocumentLine(combined,combinedSet));
96 parent = parent.getParent(graph);
97 if (model.equals(parent.getRepresents(graph)))
105 public ImageDescriptor getImage() {
106 return Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/folder.png");
110 public EvaluatorItem copy() {
111 Path path = new Path();
116 public List<Class<? extends EvaluatorItem>> getPossibleChildren(boolean add) {
117 if (add && children.size() > 0)
118 return Collections.emptyList();
119 return super.getPossibleChildren(add);
123 public boolean acceptChild(EvaluatorItem item) {
124 return children.size() == 0;
128 public boolean acceptChild(int index, EvaluatorItem item) {
129 return children.size() == 0;