TablePage.java revision e69ba4dbb015949c5d84ba7bbb0b53efac28bb23
1/*******************************************************************************
2 * Copyright (c) 2009, 2012 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.internal.html.page;
13
14import java.io.IOException;
15import java.util.ArrayList;
16import java.util.List;
17
18import org.jacoco.core.analysis.ICoverageNode;
19import org.jacoco.report.internal.ReportOutputFolder;
20import org.jacoco.report.internal.html.HTMLElement;
21import org.jacoco.report.internal.html.IHTMLReportContext;
22import org.jacoco.report.internal.html.resources.Resources;
23import org.jacoco.report.internal.html.table.ITableItem;
24
25/**
26 * Report page that contains a table of items linked to other pages.
27 *
28 * @param 
29 *            type of the node represented by this page
30 */
31public abstract class TablePage<NodeType extends ICoverageNode> extends
32		NodePage<NodeType> {
33
34	private final List<ITableItem> items = new ArrayList<ITableItem>();
35
36	/**
37	 * Creates a new node page.
38	 *
39	 * @param node
40	 *            corresponding node
41	 * @param parent
42	 *            optional hierarchical parent
43	 * @param folder
44	 *            base folder to create this report in
45	 * @param context
46	 *            settings context
47	 */
48	protected TablePage(final NodeType node, final ReportPage parent,
49			final ReportOutputFolder folder, final IHTMLReportContext context) {
50		super(node, parent, folder, context);
51	}
52
53	/**
54	 * Adds the given item to the table. Method must be called before the page
55	 * is rendered.
56	 *
57	 * @param item
58	 */
59	public void addItem(final ITableItem item) {
60		items.add(item);
61	}
62
63	@Override
64	protected void head(final HTMLElement head) throws IOException {
65		super.head(head);
66		head.script("text/javascript",
67				context.getResources().getLink(folder, Resources.SORT_SCRIPT));
68	}
69
70	@Override
71	protected void content(final HTMLElement body) throws IOException {
72		context.getTable().render(body, items, getNode(),
73				context.getResources(), folder);
74		// free memory, otherwise we will keep the complete page tree:
75		items.clear();
76	}
77
78}
79