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 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) {
		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);
		m_currentRow.add(cell);
		return cell;
		
		
	}

}

@@ -372,115 +372,416 @@
  %7B%7D%0A
-%09%09public Cell(Object content, String styleClass) %7B%0A%09%09%09m_content = content;%0A%09%09%09m_styleClass = styleClass;%0A%09%09
+                public Cell(Object content, String styleClass) %7B%0A                        m_content = content;%0A                        m_styleClass = styleClass;%0A                %7D%0A                public Cell(Object content, String styleClass, String link) %7B%0A                        m_content = content;%0A                        m_styleClass = styleClass;%0A                        m_link = link;%0A                
 %7D%0A%09%09
@@ -1905,25 +1905,32 @@
 = row;%0A%09%7D%0A%09%0A
-%09
+        
 public Cell 
@@ -1973,22 +1973,45 @@
 ellStyle
-) %7B%0A%09%09
+, String link) %7B%0A            
 if (m_cu
@@ -2027,20 +2027,35 @@
 == null)
-%0A%09%09%09
+ %7B%0A                
 throw ne
@@ -2153,21 +2153,59 @@
 ble!%22);%0A
-%09%09%0A%09%09
+            %7D%0A                %0A            
 Cell cel
@@ -2239,21 +2239,37 @@
 ellStyle
-);%0A%09%09
+, link);%0A            
 m_curren
@@ -2280,26 +2280,36 @@
 .add(cell);%0A
-%09%09
+            
 return cell;
@@ -2313,16 +2313,161 @@
 ll;%0A
-%09%09%0A%09%09%0A%09%7D%0A
+        %7D%0A        %0A        public Cell addCell(Object cellContent, String cellStyle) %7B%0A            return addCell(cellContent, cellStyle, null);%0A        %7D
 %0A%7D%0A

Add methods to create a cell with a link specified