]> gerrit.simantics Code Review - simantics/platform.git/blob
7394154662ae18e7a0538b6acef0d39564e4d999
[simantics/platform.git] /
1 package org.simantics.document.linking.report.templates.custom;
2
3 import java.util.Collections;
4 import java.util.List;
5 import java.util.Map;
6
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.db.layer0.variable.Variable;
11 import org.simantics.document.linking.report.DocumentLine;
12 import org.simantics.document.linking.report.evaluator.EvaluatorItem;
13 import org.simantics.document.linking.utils.SourceLinkUtil;
14
15
16 public class EvaluatorCustomizableContent implements CustomizableContent{
17
18         String description;     
19         EvaluatorItem item;
20         
21         boolean supportStyles = false;
22         boolean supportMultiline = true;
23         
24         public EvaluatorCustomizableContent(String description) {
25                 this.description = description;
26         }
27         
28         @Override
29         public String getCustomizationDescription() {
30                 return description;
31         }
32         
33         @Override
34         public String getContent(ReadGraph graph, Resource resource, Map<Object, Object> context)
35                         throws DatabaseException {
36                 if (!SourceLinkUtil.isValidReference(graph, resource))
37                         return "Deleted reference";
38                 Variable variable = graph.adapt(resource, Variable.class);
39                 return item.getValue(graph, variable,context);
40         }
41         
42         @Override
43         public List<DocumentLine> getLines(ReadGraph graph, Resource resource, Map<Object, Object> context)
44                         throws DatabaseException {
45                 if (!SourceLinkUtil.isValidReference(graph, resource))
46                         return Collections.singletonList(new DocumentLine("Deleted reference"));
47                 Variable variable = graph.adapt(resource, Variable.class);
48                 return item.getLines(graph, variable,context);
49         }
50         
51         public void setItem(EvaluatorItem item) {
52                 this.item = item;
53         }
54         
55         public EvaluatorItem getItem() {
56                 return item;
57         }
58         
59         public boolean isSupportStyles() {
60                 return supportStyles;
61         }
62         
63         public void setSupportStyles(boolean supportStyles) {
64                 this.supportStyles = supportStyles;
65         }
66         
67         public boolean isSupportMultiline() {
68                 return supportMultiline;
69         }
70         public void setSupportMultiline(boolean supportMultiline) {
71                 this.supportMultiline = supportMultiline;
72         }
73 }