From: Janis Streib Date: Fri, 27 Jun 2014 00:03:13 +0000 (+0200) Subject: We don't need abstract here... + include colspan in rendering X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=c29a2359a3e34c7c131d1d05b601ce9e20eb1a76 We don't need abstract here... + include colspan in rendering --- diff --git a/src/org/cacert/gigi/output/CertificateTable.java b/src/org/cacert/gigi/output/CertificateTable.java index a3aa4b63..836f3449 100644 --- a/src/org/cacert/gigi/output/CertificateTable.java +++ b/src/org/cacert/gigi/output/CertificateTable.java @@ -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("Comment *", true, "colspan=\"2\"")); + cells.add(new Cell("Comment *", true, 2)); 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)); } - DataTable t = new DataTable() { - - @Override - protected LinkedList getTableContent() { - return cells; - } - - @Override - protected int getColoumnCount() { - return 8; - } - }; + DataTable t = new DataTable(9, cells); t.output(out, l, vars); out.println(""); } catch (SQLException e) { diff --git a/src/org/cacert/gigi/output/DataTable.java b/src/org/cacert/gigi/output/DataTable.java index 47f1fc97..60893b04 100644 --- a/src/org/cacert/gigi/output/DataTable.java +++ b/src/org/cacert/gigi/output/DataTable.java @@ -6,19 +6,29 @@ import java.util.Map; import org.cacert.gigi.Language; -public abstract class DataTable implements Outputable { - protected abstract int getColoumnCount(); +public class DataTable implements Outputable { + private LinkedList cells; + private int columnCount; - protected abstract LinkedList getTableContent(); + public DataTable(int coloumnCount, LinkedList content) { + this.columnCount = coloumnCount; + this.cells = content; + } @Override public void output(PrintWriter out, Language l, Map vars) { + int mesCells = cells.size(); + for (Cell c : cells) { + if (c.getColSpan() > 1) { + mesCells += c.getColSpan(); + } + } out.println(""); - LinkedList tableContnet = getTableContent(); - for (int i = 0; i < tableContnet.size() / getColoumnCount(); i++) { + for (int i = 0; i < mesCells / columnCount; i++) { out.println(""); - 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("
"); 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; + private int colSpan; public Cell() { this(" ", 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, ""); + } + + public Cell(String text, boolean translate, int colSpan) { + this(text, translate, colSpan, ""); } public boolean shouldTranslate() { @@ -62,6 +79,10 @@ public abstract class DataTable implements Outputable { return text; } + public int getColSpan() { + return colSpan; + } + public String getHtmlAttribs() { return htmlAttribs; }