import org.cacert.gigi.Language;
public abstract class DataTable implements Outputable {
- protected abstract String[] getColumns();
+ protected abstract int getColoumnCount();
protected abstract LinkedList<Cell> getTableContent();
@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 (String column : getColumns()) {
- out.print("<td class=\"DataTD\">");
- out.print(l.getTranslation(column));
- out.println("</td>");
- }
- out.println("</tr>");
LinkedList<Cell> tableContnet = getTableContent();
- for (int i = 0; i < tableContnet.size() / getColumns().length; i++) {
+ for (int i = 0; i < tableContnet.size() / getColoumnCount(); 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);
+ for (int j = 0; j < getColoumnCount(); j++) {
+ Cell current = tableContnet.get((i * getColoumnCount()) + j);
+ out.println("<td " + current.getHtmlAttribs()
+ + " class=\"DataTD\">");
out.print(current.shouldTranslate() ? l.getTranslation(current
.getText()) : current.getText());
out.print("</td>");
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(" ", 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() {
return text;
}
- }
-
- public static class EmptyCell extends Cell {
-
- public EmptyCell() {
- super(" ", false);
+ public String getHtmlAttribs() {
+ return htmlAttribs;
}
}