package org.opennms.web.svclayer;

import java.util.ArrayList;
import java.util.List;

/**
 * The idea of this class is to represent a simple table that has column headers
 * and rows.  
 * @author brozow
 *
 */
public class SimpleWebTable {
	
	public static class Cell {
		private Object m_content;
		private String m_styleClass;
		private String m_link;
		public Cell() {}
                public Cell(Object content, String styleClass) {
                        m_content = content;
                        m_styleClass = styleClass;
                }
                public Cell(Object content, String styleClass, String link) {
                        m_content = content;
                        m_styleClass = styleClass;
                        m_link = link;
                }
		public Object getContent() {
			return m_content;
		}
		public void setContent(Object content) {
			m_content = content;
		}
		public String getStyleClass() {
			return m_styleClass;
		}
		public void setStyleClass(String styleClass) {
			m_styleClass = styleClass;
		}
		public String getLink() {
			return m_link;
		}
		
		public void setLink(String link) {
			m_link = link;
		}
	}
	
	
	private List<Cell> m_columnHeaders = new ArrayList<Cell>();
	private List<List<Cell>> m_rows = new ArrayList<List<Cell>>();
	private List<Cell> m_currentRow = null;
	private String m_title = "";
	
	public List<Cell> getColumnHeaders() {
		return m_columnHeaders;
	}
	
	public List<List<Cell>> getRows() {
		return m_rows;
	}
	
	public String getTitle() {
		return m_title;
	}
	
	public void setTitle(String title) {
		m_title  = title;
	}
	
	public Cell addColumn(Object headerContent, String headerStyle) {
		Cell headerCell = new Cell(headerContent, headerStyle);
		m_columnHeaders.add(headerCell);
		return headerCell;
	}
	
	public void newRow() {
		List<Cell> row = new ArrayList<Cell>();
		m_rows.add(row);
		m_currentRow = row;
	}
	
        public Cell addCell(Object cellContent, String cellStyle, String link) {
            if (m_currentRow == null) {
                throw new IllegalStateException("make sure you call newRow before trying to add any cells to the table!");
            }
                
            Cell cell = new Cell(cellContent, cellStyle, link);
            m_currentRow.add(cell);
            return cell;
        }
        
        public Cell addCell(Object cellContent, String cellStyle) {
            return addCell(cellContent, cellStyle, null);
        }
}

@@ -80,16 +80,46 @@
 .List;%0A%0A
+import org.opennms.web.Util;%0A%0A
 /**%0A * T
@@ -2494,10 +2494,1452 @@
       %7D%0A
+        %0A    public String toString() %7B%0A        StringBuffer buf = new StringBuffer();%0A        %0A        buf.append(%22%3Ctable%3E%5Cn%22);%0A%0A        buf.append(%22  %3Ctr%3E%5Cn%22);%0A        for (Cell cell : getColumnHeaders()) %7B%0A            buf.append(%22    %3Cth style=%5C%22%22 + cell.getStyleClass()%0A                    + %22%5C%22%3E%5Cn%22);%0A            if (cell.getLink() != null) %7B%0A                buf.append(%22      %3Ca href=%5C%22%22%0A                        + Util.htmlify(cell.getLink()) + %22%5C%22%3E%22%0A                        + cell.getContent() + %22%3C/a%3E%5Cn%22);%0A            %7D else %7B%0A                buf.append(%22      %22 + cell.getContent() + %22%5Cn%22);%0A            %7D%0A            buf.append(%22    %3C/th%3E%5Cn%22);%0A        %7D%0A        buf.append(%22  %3C/tr%3E%5Cn%22);%0A%0A        for (List%3CCell%3E cells : getRows()) %7B%0A            buf.append(%22  %3Ctr%3E%5Cn%22);%0A            for (Cell cell : cells) %7B%0A                buf.append(%22    %3Ctr style=%5C%22%22 + cell.getStyleClass()%0A                        + %22%5C%22%3E%5Cn%22);%0A                if (cell.getLink() != null) %7B%0A                    buf.append(%22      %3Ca href=%5C%22%22%0A                            + Util.htmlify(cell.getLink()) + %22%5C%22%3E%22%0A                            + cell.getContent() + %22%3C/a%3E%5Cn%22);%0A                %7D else %7B%0A                    buf.append(%22      %22 + cell.getContent() + %22%5Cn%22);%0A                %7D%0A                buf.append(%22    %3C/tr%3E%5Cn%22);%0A            %7D%0A            buf.append(%22  %3C/tr%3E%5Cn%22);%0A        %7D%0A%0A        buf.append(%22%3C/table%3E%5Cn%22);%0A        %0A        return buf.toString();%0A    %7D%0A
 %7D%0A

Add toString() method to help with testing