GroupPage.java
1/*******************************************************************************
2 * Copyright (c) 2009, 2010 Mountainminds GmbH & Co. KG and Contributors
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Marc R. Hoffmann - initial API and implementation
10 *
11 *******************************************************************************/
12package org.jacoco.report.html;
13
14import java.io.IOException;
15import java.util.ArrayList;
16import java.util.List;
17
18import org.jacoco.core.analysis.ICoverageNode;
19import org.jacoco.report.IReportVisitor;
20import org.jacoco.report.ISourceFileLocator;
21import org.jacoco.report.ReportOutputFolder;
22import org.jacoco.report.html.resources.Resources;
23
24/**
25 * Page showing coverage information for a node that groups other nodes. The
26 * page shows a table of linked nodes.
27 *
28 * @author Marc R. Hoffmann
29 * @version 0.4.1.20101007204400
30 */
31public class GroupPage extends NodePage {
32
33 private final List<NodePage> children = new ArrayList<NodePage>();
34
35 /**
36 * Creates a new visitor in the given context.
37 *
38 * @param node
39 * @param parent
40 * @param folder
41 * @param context
42 */
43 public GroupPage(final ICoverageNode node, final ReportPage parent,
44 final ReportOutputFolder folder, final IHTMLReportContext context) {
45 super(node, parent, folder, context);
46 }
47
48 public IReportVisitor visitChild(final ICoverageNode node) {
49 final NodePage child;
50 switch (node.getElementType()) {
51 case PACKAGE:
52 child = new PackagePage(node, this, folder.subFolder(node.getName()
53 .replace('/', '.')), context);
54 break;
55 default:
56 child = new GroupPage(node, this, folder.subFolder(node.getName()),
57 context);
58 break;
59 }
60 children.add(child);
61 return child;
62 }
63
64 @Override
65 public void visitEnd(final ISourceFileLocator sourceFileLocator)
66 throws IOException {
67 super.visitEnd(sourceFileLocator);
68 // free memory, otherwise we will keep the complete tree:
69 children.clear();
70 }
71
72 @Override
73 protected void headExtra(final HTMLElement head) throws IOException {
74 super.headExtra(head);
75 head.script("text/javascript",
76 context.getResources().getLink(folder, Resources.SORT_SCRIPT));
77 }
78
79 @Override
80 protected String getOnload() {
81 return "initialSort()";
82 }
83
84 @Override
85 protected void content(final HTMLElement body) throws IOException {
86 context.getTable().render(body, children, getNode(),
87 context.getResources(), folder);
88 }
89
90 @Override
91 protected String getFileName() {
92 return "index.html";
93 }
94
95}