1 package com.stateofflow.eclipse.metrics.export.html;
2
3 import com.stateofflow.eclipse.metrics.collator.MetricsCollator;
4 import com.stateofflow.eclipse.metrics.metric.MetricId;
5
6 final class MetricsTableHeaderWriter {
7 private HtmlPageBuilder pageBuilder;
8 private int fragmentNumber;
9 private String level;
10 private final HtmlExportFactory factory;
11
12 public MetricsTableHeaderWriter(final HtmlExportFactory factory) {
13 this.factory = factory;
14 }
15
16 public void write(final HtmlPageBuilder pageBuilder, final int fragmentNumber, final String level, final MetricId[] metricIds, final MetricsCollator collator) {
17 this.pageBuilder = pageBuilder;
18 this.fragmentNumber = fragmentNumber;
19 this.level = level;
20
21 writeMetricsTableMetricsHeaders(metricIds, collator);
22 writeMetricsTableLocationHeaders();
23 writeMetricsTablePackageHeader();
24 }
25
26 private void writeMetricsTablePackageHeader() {
27 if (HtmlExporter.PACKAGE_METRIC_LEVEL.equals(level)) {
28 pageBuilder.createElement("TH", pageBuilder.getHtmlLink(HtmlExporter.PACKAGE_METRIC_LEVEL + "." + fragmentNumber, "Package"));
29 } else {
30 pageBuilder.createElement("TH", pageBuilder.getHtmlLink(HtmlExporter.QUALIFIED_TYPE_NAME_PAGE_NAME_START + level + "." + fragmentNumber, "Package"));
31 }
32 }
33
34 private void writeMetricsTableLocationHeaders() {
35 if (!HtmlExporter.PACKAGE_METRIC_LEVEL.equals(level)) {
36 pageBuilder.createElement("TH", "Line");
37 if (HtmlExporter.METHOD_METRIC_LEVEL.equals(level)) {
38 pageBuilder.createElement("TH", "Method");
39 }
40 pageBuilder.createElement("TH", pageBuilder.getHtmlLink(HtmlExporter.UNQUALIFIED_TYPE_NAME_PAGE_NAME_START + level + "." + fragmentNumber, "Type"));
41 }
42 }
43
44 private void writeMetricsTableMetricsHeaders(final MetricId[] metricIds, final MetricsCollator collator) {
45 for (int i = 0; i < metricIds.length; i++) {
46 pageBuilder.openElement("TH").printLink(factory.getIndexFileName(i, level) + "." + fragmentNumber, factory.getPresentations().getShortPresentationName(metricIds[i]));
47 if (collator.getAggregationSteps(metricIds[i]) > 0) {
48 pageBuilder.openElement("BR").print("(max)");
49 }
50 pageBuilder.closeElementAndNewline("TH");
51 }
52 }
53 }
54