1 package org.simantics.document.linking.report.templates;
4 import java.util.Collection;
5 import java.util.HashMap;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.document.DocumentResource;
11 import org.simantics.document.linking.report.Document.TextSize;
12 import org.simantics.document.linking.report.TableColumn.Alignment;
13 import org.simantics.document.linking.report.Document;
14 import org.simantics.document.linking.report.TextItem;
15 import org.simantics.document.linking.report.URLItem;
16 import org.simantics.document.linking.report.evaluator.AlignmentHint;
17 import org.simantics.document.linking.report.evaluator.Date;
18 import org.simantics.document.linking.report.evaluator.EvaluatorNode;
19 import org.simantics.document.linking.report.evaluator.Lines;
20 import org.simantics.document.linking.report.evaluator.Or;
21 import org.simantics.document.linking.report.evaluator.TextSizeHint;
22 import org.simantics.document.linking.report.evaluator.Variable;
23 import org.simantics.document.linking.report.templates.custom.CustomizableContent;
24 import org.simantics.document.linking.report.templates.custom.EvaluatorCustomizableContent;
27 public abstract class DocumentWriter<T> extends TableReportWriter<T> implements CustomizableContentProvider{
29 Map<String, CustomizableContent> content = new HashMap<String, CustomizableContent>();
33 Map<Object, Object> context;
35 public DocumentWriter() {
36 setDefaultContent(null);
40 public void start(ReadGraph graph, Resource model, Document writer,
41 Map<Object, Object> context) throws Exception {
43 this.doc = DocumentResource.getInstance(graph);
44 this.context = context;
45 this.document = writer;
50 public CustomizableContent getContent(String id) {
51 return content.get(id);
55 public void setContent(String id, CustomizableContent content) {
56 this.content.put(id, content);
60 public void setDefaultContent(String id) {
61 if ("Document".equals(id) || id == null) {
62 EvaluatorCustomizableContent c = new EvaluatorCustomizableContent("Document format");
64 item.addChild(new Variable("#HasLabel"));
65 item.addChild(new Variable("#HasName"));
67 c.setSupportStyles(false);
68 c.setSupportMultiline(true);
69 content.put("Document", c);
71 if ("Title".equals(id) || id == null) {
72 EvaluatorCustomizableContent e = new EvaluatorCustomizableContent("Document Title");
73 EvaluatorNode lines = new Lines();
75 nameOr.createChild(Variable.class).setVariableRef("#HasLabel");
76 nameOr.createChild(Variable.class).setVariableRef("#HasName");
77 lines.createChild(TextSizeHint.class).setTextSize(TextSize.HUGE).createChild(AlignmentHint.class).setAlignment(Alignment.CENTER).addChild(nameOr.copy());
78 lines.createChild(TextSizeHint.class).setTextSize(TextSize.HUGE).createChild(AlignmentHint.class).setAlignment(Alignment.CENTER).createChild(Variable.class).setVariableRef("DocumentName");
79 lines.createChild(TextSizeHint.class).setTextSize(TextSize.LARGE).createChild(AlignmentHint.class).setAlignment(Alignment.CENTER).createChild(Date.class);
81 e.setSupportStyles(true);
82 e.setSupportMultiline(true);
83 content.put("Title", e);
88 public Collection<String> getContentIds() {
89 return content.keySet();
92 protected TextItem getDocumentItem(Resource document) throws Exception{
94 if (graph.isInstanceOf(document, doc.UrlDocument)) {
95 item = this.document.newItem(URLItem.class);
96 ((URLItem)item).setURL(new URL((String)graph.getRelatedValue(document, doc.HasUrl)));
98 item = this.document.newItem(TextItem.class);
100 item.setText(getContent("Document").getContent(graph, document,context));
104 protected TextItem getNonExistingDocumentItem() throws Exception{
105 TextItem item = this.document.newItem(TextItem.class);
106 item.setText("[DOCUMENT DOES NOT EXIST]");