]> WPIA git - gigi.git/commitdiff
UPD: More advanced cells
authorJanis Streib <janis@dogcraft.de>
Thu, 26 Jun 2014 23:33:31 +0000 (01:33 +0200)
committerJanis Streib <janis@dogcraft.de>
Thu, 26 Jun 2014 23:33:31 +0000 (01:33 +0200)
src/org/cacert/gigi/output/CertificateTable.java
src/org/cacert/gigi/output/DataTable.java

index a5c43d853cc708d2942c0a5c71f4dd22357c6715..ce0e5d56c2b80d68a0ede1c2789310c131066954 100644 (file)
@@ -8,7 +8,6 @@ import java.util.Map;
 
 import org.cacert.gigi.Language;
 import org.cacert.gigi.output.DataTable.Cell;
-import org.cacert.gigi.output.DataTable.EmptyCell;
 
 public class CertificateTable implements Outputable {
        String resultSet;
@@ -25,7 +24,7 @@ public class CertificateTable implements Outputable {
                        rs.beforeFirst();
                        while (rs.next()) {
                                // out.println(rs.getString("id"));
-                               cells.add(new EmptyCell());
+                               cells.add(new Cell());
                                cells.add(new Cell("State", false));
                                cells.add(new Cell(rs.getString("CN"), false));
                                cells.add(new Cell(rs.getString("serial"), false));
@@ -46,10 +45,14 @@ public class CertificateTable implements Outputable {
                                }
 
                                @Override
-                               protected String[] getColumns() {
-                                       return new String[] { "Renew/Revoke/Delete", "Status",
-                                                       "Email Address", "SerialNumber", "Revoked",
-                                                       "Expires", "Login", "Comment*" };
+                               protected Cell[] getColumns() {
+                                       return new Cell[] { new Cell("Renew/Revoke/Delete", true),
+                                                       new Cell("Status", true),
+                                                       new Cell("Email Address", true),
+                                                       new Cell("SerialNumber", true),
+                                                       new Cell("Revoked", true),
+                                                       new Cell("Expires", true), new Cell("Login", true),
+                                                       new Cell("Comment*", true, "colspan=\"2\"") };
                                }
                        };
                        t.output(out, l, vars);
index 8c8b06e66d4570f6b88698aa26ee7f54cbf2e2f8..c9ba47b89082eda87f9606b5e9dd8652f9704b13 100644 (file)
@@ -7,7 +7,7 @@ import java.util.Map;
 import org.cacert.gigi.Language;
 
 public abstract class DataTable implements Outputable {
-       protected abstract String[] getColumns();
+       protected abstract Cell[] getColumns();
 
        protected abstract LinkedList<Cell> getTableContent();
 
@@ -15,9 +15,10 @@ public abstract class DataTable implements Outputable {
        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 (String column : getColumns()) {
-                       out.print("<td class=\"DataTD\">");
-                       out.print(l.getTranslation(column));
+               for (Cell column : getColumns()) {
+                       out.print("<td " + column.getHtmlAttribs() + " class=\"DataTD\">");
+                       out.print(column.shouldTranslate() ? l.getTranslation(column
+                                       .getText()) : column.getText());
                        out.println("</td>");
                }
                out.println("</tr>");
@@ -25,8 +26,9 @@ public abstract class DataTable implements Outputable {
                for (int i = 0; i < tableContnet.size() / getColumns().length; i++) {
                        out.println("<tr>");
                        for (int j = 0; j < getColumns().length; j++) {
-                               out.println("<td class=\"DataTD\">");
                                Cell current = tableContnet.get((i * getColumns().length) + j);
+                               out.println("<td " + current.getHtmlAttribs()
+                                               + " class=\"DataTD\">");
                                out.print(current.shouldTranslate() ? l.getTranslation(current
                                                .getText()) : current.getText());
                                out.print("</td>");
@@ -36,13 +38,28 @@ 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;
+               private String text, htmlAttribs;
                private boolean translate;
 
-               public Cell(String text, boolean translate) {
+               public Cell() {
+                       this("&nbsp;", false);
+               }
+
+               public Cell(String text, boolean translate, String htmlAttribs) {
                        this.text = text;
                        this.translate = translate;
+                       this.htmlAttribs = htmlAttribs;
+               }
+
+               public Cell(String text, boolean translate) {
+                       this(text, translate, "");
                }
 
                public boolean shouldTranslate() {
@@ -53,12 +70,8 @@ public abstract class DataTable implements Outputable {
                        return text;
                }
 
-       }
-
-       public static class EmptyCell extends Cell {
-
-               public EmptyCell() {
-                       super("&nbsp;", false);
+               public String getHtmlAttribs() {
+                       return htmlAttribs;
                }
 
        }