1 package org.simantics.document.linking.report;
3 import java.text.DateFormat;
4 import java.util.ArrayList;
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;
19 public abstract class DocumentTitlePage implements DocumentElement{
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");
29 writeTitle(getDefaultLines(graph, (Resource)context.get("model"), (String)context.get("DocumentName")));
32 List<DocumentLine> lines = content.getLines(graph, (Resource)context.get("model"), context);
37 protected abstract void writeTitle(List<DocumentLine> lines) throws Exception;
40 public List<DocumentLine> getDefaultLines(ReadGraph graph, Resource model, String documentName) throws DatabaseException{
41 List<DocumentLine> result = new ArrayList<DocumentLine>();
43 String modelName = NameUtils.getSafeLabel(graph, model);
44 if (modelName.length() == 0)
45 modelName = NameUtils.getSafeName(graph, model);
47 java.util.Date date = new java.util.Date(System.currentTimeMillis());
48 String dateString = DateFormat.getDateTimeInstance().format(date);
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));