]> gerrit.simantics Code Review - simantics/platform.git/blob
d6a3b37b2317255fa210861ef8c20027e25e08e4
[simantics/platform.git] /
1 package org.simantics.document.linking.report;
2
3 import java.text.DateFormat;
4 import java.util.ArrayList;
5 import java.util.List;
6 import java.util.Map;
7
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.db.common.utils.NameUtils;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.document.linking.report.Document.TextSize;
13 import org.simantics.document.linking.report.TableColumn.Alignment;
14 import org.simantics.document.linking.report.templates.CustomizableContentProvider;
15 import org.simantics.document.linking.report.templates.ReportWriter;
16 import org.simantics.document.linking.report.templates.custom.CustomizableContent;
17
18
19 public abstract class DocumentTitlePage implements DocumentElement{
20         
21         
22         public void writeTitle(ReadGraph graph, Map<Object, Object> context) throws Exception {
23                 ReportWriter<?> reportWriter = (ReportWriter<?>)context.get(ReportWriter.class);
24                 CustomizableContent content = null;
25                 if (reportWriter instanceof CustomizableContentProvider) {
26                         content = ((CustomizableContentProvider)reportWriter).getContent("Title");
27                 }
28                 if (content == null)
29                         writeTitle(getDefaultLines(graph, (Resource)context.get("model"), (String)context.get("DocumentName")));
30                 else {
31                         
32                         List<DocumentLine> lines = content.getLines(graph, (Resource)context.get("model"), context);
33                         writeTitle(lines);
34                 }
35         }
36         
37         protected abstract void writeTitle(List<DocumentLine> lines) throws Exception;
38
39
40         public List<DocumentLine> getDefaultLines(ReadGraph graph, Resource model, String documentName) throws DatabaseException{
41                 List<DocumentLine> result = new ArrayList<DocumentLine>();
42                 
43                 String modelName = NameUtils.getSafeLabel(graph, model);
44                 if (modelName.length() == 0)
45                         modelName = NameUtils.getSafeName(graph, model);
46                 
47                 java.util.Date date = new java.util.Date(System.currentTimeMillis());
48                 String dateString = DateFormat.getDateTimeInstance().format(date);
49         
50                 result.add(new DocumentLine(modelName, Alignment.class, Alignment.CENTER, TextSize.class, TextSize.HUGE));
51                 result.add(new DocumentLine(documentName, Alignment.class, Alignment.CENTER, TextSize.class, TextSize.HUGE));
52                 result.add(new DocumentLine(dateString, Alignment.class, Alignment.CENTER, TextSize.class, TextSize.LARGE));
53                 
54                 return result;
55         }
56         
57         
58
59 }