]> WPIA git - gigi.git/commitdiff
We don't need abstract here... + include colspan in rendering
authorJanis Streib <janis@dogcraft.de>
Fri, 27 Jun 2014 00:03:13 +0000 (02:03 +0200)
committerJanis Streib <janis@dogcraft.de>
Fri, 27 Jun 2014 00:03:13 +0000 (02:03 +0200)
src/org/cacert/gigi/output/CertificateTable.java
src/org/cacert/gigi/output/DataTable.java

index a3aa4b63993f4bdaf99b5925460a1aa5fba88ca5..836f3449a9f58406a22fc9b93267191e3c4c6d9d 100644 (file)
@@ -28,7 +28,7 @@ public class CertificateTable implements Outputable {
                        cells.add(new Cell("Revoked", true));
                        cells.add(new Cell("Expires", true));
                        cells.add(new Cell("Login", true));
                        cells.add(new Cell("Revoked", true));
                        cells.add(new Cell("Expires", true));
                        cells.add(new Cell("Login", true));
-                       cells.add(new Cell("Comment *", true, "colspan=\"2\""));
+                       cells.add(new Cell("Comment *", true, 2));
                        rs.beforeFirst();
                        while (rs.next()) {
                                // out.println(rs.getString("id"));
                        rs.beforeFirst();
                        while (rs.next()) {
                                // out.println(rs.getString("id"));
@@ -45,18 +45,7 @@ public class CertificateTable implements Outputable {
                                cells.add(new Cell(rs.getString("a"), false));
                                cells.add(new Cell(rs.getString("a"), false));
                        }
                                cells.add(new Cell(rs.getString("a"), false));
                                cells.add(new Cell(rs.getString("a"), false));
                        }
-                       DataTable t = new DataTable() {
-
-                               @Override
-                               protected LinkedList<Cell> getTableContent() {
-                                       return cells;
-                               }
-
-                               @Override
-                               protected int getColoumnCount() {
-                                       return 8;
-                               }
-                       };
+                       DataTable t = new DataTable(9, cells);
                        t.output(out, l, vars);
                        out.println("</form>");
                } catch (SQLException e) {
                        t.output(out, l, vars);
                        out.println("</form>");
                } catch (SQLException e) {
index 47f1fc974c1d4bf769d9d2caca7357f4ee795ff7..60893b0446ef0875453168059abbc0a4881c527e 100644 (file)
@@ -6,19 +6,29 @@ import java.util.Map;
 
 import org.cacert.gigi.Language;
 
 
 import org.cacert.gigi.Language;
 
-public abstract class DataTable implements Outputable {
-       protected abstract int getColoumnCount();
+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) {
 
        @Override
        public void output(PrintWriter out, Language l, Map<String, Object> vars) {
+               int mesCells = cells.size();
+               for (Cell c : cells) {
+                       if (c.getColSpan() > 1) {
+                               mesCells += c.getColSpan();
+                       }
+               }
                out.println("<table align=\"center\" valign=\"middle\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"wrapper\">");
                out.println("<table align=\"center\" valign=\"middle\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"wrapper\">");
-               LinkedList<Cell> tableContnet = getTableContent();
-               for (int i = 0; i < tableContnet.size() / getColoumnCount(); i++) {
+               for (int i = 0; i < mesCells / columnCount; i++) {
                        out.println("<tr>");
                        out.println("<tr>");
-                       for (int j = 0; j < getColoumnCount(); j++) {
-                               Cell current = tableContnet.get((i * getColoumnCount()) + j);
+                       for (int j = 0; j < columnCount;) {
+                               Cell current = cells.get((i * columnCount) + j);
+                               j += current.getColSpan();
                                out.println("<td " + current.getHtmlAttribs()
                                                + " class=\"DataTD\">");
                                out.print(current.shouldTranslate() ? l.getTranslation(current
                                out.println("<td " + current.getHtmlAttribs()
                                                + " class=\"DataTD\">");
                                out.print(current.shouldTranslate() ? l.getTranslation(current
@@ -39,19 +49,26 @@ public abstract class DataTable implements Outputable {
        public static class Cell {
                private String text, htmlAttribs;
                private boolean translate;
        public static class Cell {
                private String text, htmlAttribs;
                private boolean translate;
+               private int colSpan;
 
                public Cell() {
                        this("&nbsp;", false);
                }
 
 
                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.text = text;
                        this.translate = translate;
                        this.htmlAttribs = htmlAttribs;
+                       this.colSpan = colSpan;
                }
 
                public Cell(String text, boolean translate) {
                }
 
                public Cell(String text, boolean translate) {
-                       this(text, translate, "");
+                       this(text, translate, 1, "");
+               }
+
+               public Cell(String text, boolean translate, int colSpan) {
+                       this(text, translate, colSpan, "");
                }
 
                public boolean shouldTranslate() {
                }
 
                public boolean shouldTranslate() {
@@ -62,6 +79,10 @@ public abstract class DataTable implements Outputable {
                        return text;
                }
 
                        return text;
                }
 
+               public int getColSpan() {
+                       return colSpan;
+               }
+
                public String getHtmlAttribs() {
                        return htmlAttribs;
                }
                public String getHtmlAttribs() {
                        return htmlAttribs;
                }