1 package com.stateofflow.eclipse.metrics.export.html;
2
3 import com.stateofflow.eclipse.metrics.collator.MetricsCollator;
4 import com.stateofflow.eclipse.metrics.collator.MetricsCollatorSet;
5 import com.stateofflow.eclipse.metrics.location.comparator.LocationComparator;
6 import com.stateofflow.eclipse.metrics.location.comparator.MetricOrderingLocationComparator;
7 import com.stateofflow.eclipse.metrics.location.comparator.PackageNameComparator;
8 import com.stateofflow.eclipse.metrics.location.comparator.QualifiedTypeNameComparator;
9 import com.stateofflow.eclipse.metrics.location.comparator.UnqualifiedTypeNameComparator;
10 import com.stateofflow.eclipse.metrics.metric.MetricId;
11 import com.stateofflow.eclipse.metrics.util.ProgressMonitor;
12
13 final class MetricsPagesWriter {
14 private String level;
15 private final HtmlExportFactory factory;
16
17 public MetricsPagesWriter(final HtmlExportFactory factory) {
18 this.factory = factory;
19 }
20
21 public void writeProjectMetricsPage(final MetricsCollatorSet collator, final ProgressMonitor progressMonitor) {
22 progressMonitor.beginTask("Creating project summary page", 1);
23 createSummaryMetricsPage(collator);
24 }
25
26 public void writeTypeAndMethodMetricsPages(final MetricsCollator collator, final String level, final ProgressMonitor progressMonitor) {
27 this.level = level;
28 progressMonitor.beginTask("Creating " + level + " metrics pages", 3);
29 createUnqualifiedTypeNameOrderedMetricsPage(collator);
30 progressMonitor.worked(1);
31
32 createQualifiedTypeNameOrderedMetricsPage(collator);
33 progressMonitor.worked(1);
34
35 createOrderedByMetricsPages(collator, progressMonitor.newChild(1));
36 }
37
38 public void writePackageMetricsPages(final MetricsCollator collator, final ProgressMonitor progressMonitor) {
39 this.level = HtmlExporter.PACKAGE_METRIC_LEVEL;
40
41 progressMonitor.beginTask("Creating " + HtmlExporter.PACKAGE_METRIC_LEVEL + " metrics pages", 2);
42 createPackageOrderedMetricsPage(collator);
43 progressMonitor.worked(1);
44
45 createOrderedByMetricsPages(collator, progressMonitor.newChild(1));
46 }
47
48 private void createSummaryMetricsPage(final MetricsCollatorSet collator) {
49 factory.createSummaryPageWriter(collator).write();
50 }
51
52 private void createPackageOrderedMetricsPage(final MetricsCollator collator) {
53 factory.createOrderedPageWriter(collator, "Package", null, "Package", HtmlExporter.PACKAGE_METRIC_LEVEL).write(new PackageNameComparator());
54 }
55
56 private void createUnqualifiedTypeNameOrderedMetricsPage(final MetricsCollator collator) {
57 createOrderedMetricsPage(collator, HtmlExporter.UNQUALIFIED_TYPE_NAME_PAGE_NAME_START, "Unqualified Type Name", new UnqualifiedTypeNameComparator());
58 }
59
60 private void createQualifiedTypeNameOrderedMetricsPage(final MetricsCollator collator) {
61 createOrderedMetricsPage(collator, HtmlExporter.QUALIFIED_TYPE_NAME_PAGE_NAME_START, "Qualified Type Name", new QualifiedTypeNameComparator());
62 }
63
64 private void createOrderedMetricsPage(final MetricsCollator collator, final String pageNameStart, final String orderItem, final LocationComparator locationComparator) {
65 factory.createOrderedPageWriter(collator, pageNameStart + level, null, orderItem, level).write(locationComparator);
66 }
67
68 private void createOrderedByMetricsPages(final MetricsCollator collator, final ProgressMonitor progressMonitor) {
69 final MetricId[] metricIds = collator.getSortedMetricIds();
70 progressMonitor.beginTask("Writing Ordered By Metrics Pages", metricIds.length);
71 for (int i = 0; i < metricIds.length; i++) {
72 createOrderedByMetricPage(collator, metricIds[i], factory.getIndexFileName(i, level));
73 progressMonitor.worked(1);
74 }
75 }
76
77 private void createOrderedByMetricPage(final MetricsCollator collator, final MetricId id, final String fileName) {
78 factory.createOrderedPageWriter(collator, fileName, factory.getImageFilePath(id), factory.getPresentations().getPresentationName(id), level).write(new MetricOrderingLocationComparator(collator, id));
79 }
80 }
81