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