]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/output/DataTable.java
Updated html attribute handling in DataTable
[gigi.git] / src / org / cacert / gigi / output / DataTable.java
index c9ba47b89082eda87f9606b5e9dd8652f9704b13..3f131a224c05ea3df8fe33014c8842c64cf4031e 100644 (file)
@@ -6,29 +6,30 @@ import java.util.Map;
 
 import org.cacert.gigi.Language;
 
-public abstract class DataTable implements Outputable {
-       protected abstract Cell[] getColumns();
+public class DataTable implements Outputable {
+       private LinkedList<Cell> cells;
+       private int columnCount;
 
-       protected abstract LinkedList<Cell> getTableContent();
+       public DataTable(int coloumnCount, LinkedList<Cell> content) {
+               this.columnCount = coloumnCount;
+               this.cells = content;
+       }
 
        @Override
        public void output(PrintWriter out, Language l, Map<String, Object> vars) {
-               out.println("<table align=\"center\" valign=\"middle\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"wrapper\">");
-               out.println("<tr>");
-               for (Cell column : getColumns()) {
-                       out.print("<td " + column.getHtmlAttribs() + " class=\"DataTD\">");
-                       out.print(column.shouldTranslate() ? l.getTranslation(column
-                                       .getText()) : column.getText());
-                       out.println("</td>");
+               int mesCells = cells.size();
+               for (Cell c : cells) {
+                       if (c.getColSpan() > 1) {
+                               mesCells += c.getColSpan();
+                       }
                }
-               out.println("</tr>");
-               LinkedList<Cell> tableContnet = getTableContent();
-               for (int i = 0; i < tableContnet.size() / getColumns().length; i++) {
+               out.println("<table align=\"center\" valign=\"middle\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"wrapper\">");
+               for (int i = 0; i < mesCells / columnCount; i++) {
                        out.println("<tr>");
-                       for (int j = 0; j < getColumns().length; j++) {
-                               Cell current = tableContnet.get((i * getColumns().length) + j);
-                               out.println("<td " + current.getHtmlAttribs()
-                                               + " class=\"DataTD\">");
+                       for (int j = 0; j < columnCount;) {
+                               Cell current = cells.get((i * columnCount) + j);
+                               j += current.getColSpan();
+                               out.println("<td " + current.getHtmlAttribs() + " >");
                                out.print(current.shouldTranslate() ? l.getTranslation(current
                                                .getText()) : current.getText());
                                out.print("</td>");
@@ -38,28 +39,29 @@ public abstract class DataTable implements Outputable {
                out.println("</table>");
        }
 
-       /**
-        * <b>Note:</b> All cells have the html attribute class="DataTD"!
-        * 
-        * @author janis
-        * 
-        */
        public static class Cell {
                private String text, htmlAttribs;
                private boolean translate;
+               private int colSpan;
 
                public Cell() {
                        this("&nbsp;", false);
                }
 
-               public Cell(String text, boolean translate, String htmlAttribs) {
+               public Cell(String text, boolean translate, int colSpan,
+                               String htmlAttribs) {
                        this.text = text;
                        this.translate = translate;
                        this.htmlAttribs = htmlAttribs;
+                       this.colSpan = colSpan;
                }
 
                public Cell(String text, boolean translate) {
-                       this(text, translate, "");
+                       this(text, translate, 1, "class=\"DataTD\"");
+               }
+
+               public Cell(String text, boolean translate, int colSpan) {
+                       this(text, translate, colSpan, "class=\"DataTD\"");
                }
 
                public boolean shouldTranslate() {
@@ -70,6 +72,10 @@ public abstract class DataTable implements Outputable {
                        return text;
                }
 
+               public int getColSpan() {
+                       return colSpan;
+               }
+
                public String getHtmlAttribs() {
                        return htmlAttribs;
                }