001package org.javasimon.console.action;
002
003import org.javasimon.Simon;
004import org.javasimon.console.html.HtmlBuilder;
005import org.javasimon.console.text.StringifierFactory;
006
007import java.io.IOException;
008import java.io.Writer;
009
010/**
011 * HTML generator for Detail view.
012 *
013 * @author gquintana
014 */
015public class DetailHtmlBuilder extends HtmlBuilder<DetailHtmlBuilder> {
016
017        public DetailHtmlBuilder(Writer writer, StringifierFactory stringifierFactory) {
018                super(writer, stringifierFactory);
019        }
020
021        public DetailHtmlBuilder beginSection(String id, String title) throws IOException {
022                return begin("div", id, "sectionPanel")
023                        .begin("div", null, "title").write(title).end("div")
024                        .begin("table", null, "sectionTable");
025        }
026
027        public DetailHtmlBuilder endSection() throws IOException {
028                return end("table").end("div");
029        }
030
031        public DetailHtmlBuilder beginRow() throws IOException {
032                return begin("tr");
033        }
034
035        public DetailHtmlBuilder endRow() throws IOException {
036                return end("tr");
037        }
038
039        public DetailHtmlBuilder labelCell(String propertyLabel) throws IOException {
040                return begin("td class=\"label\"").text(propertyLabel).end("td");
041        }
042
043        public DetailHtmlBuilder beginValueCell() throws IOException {
044                return beginValueCell("");
045        }
046
047        public DetailHtmlBuilder beginValueCell(String extraAttrs) throws IOException {
048                return begin("td class=\"value\"" + extraAttrs);
049        }
050
051        public DetailHtmlBuilder endValueCell() throws IOException {
052                return end("td");
053        }
054
055        public DetailHtmlBuilder valueCell(String text) throws IOException {
056                return beginValueCell().write(text).endValueCell();
057        }
058
059        public DetailHtmlBuilder valueCell(String extraAttr, String text) throws IOException {
060                return beginValueCell(extraAttr).write(text).endValueCell();
061        }
062
063        public DetailHtmlBuilder simonProperty(Simon simon, String propertyLabel, String propertyName) throws IOException {
064                return labelCell(propertyLabel).beginValueCell().simonProperty(simon, propertyName).endValueCell();
065        }
066
067        public DetailHtmlBuilder simonProperty(Simon simon, String propertyLabel, String propertyName, Integer colSpan) throws IOException {
068                return labelCell(propertyLabel).beginValueCell(" colspan=\"" + colSpan + "\"").simonProperty(simon, propertyName).endValueCell();
069        }
070}