From d9b0a83004ff549015e5b95580c8b70d6f57bdc9 Mon Sep 17 00:00:00 2001 From: uhensler <urs.hensler@frentix.com> Date: Tue, 12 Mar 2019 11:24:05 +0100 Subject: [PATCH] OO-3962: Right alignment of headers in course statistic --- .../ChecklistMultiSelectColumnDescriptor.java | 19 +++++ .../components/table/ColumnDescriptor.java | 3 + .../table/DefaultColumnDescriptor.java | 77 +++++++------------ .../table/MultiSelectColumnDescriptor.java | 16 ++++ .../table/StaticColumnDescriptor.java | 68 ++++++---------- .../gui/components/table/TableRenderer.java | 4 +- .../statistic/StatisticDisplayController.java | 16 ++-- .../statistic/TotalAwareColumnDescriptor.java | 5 +- .../daily/DailyStatisticManager.java | 2 +- 9 files changed, 104 insertions(+), 106 deletions(-) diff --git a/src/main/java/de/bps/olat/modules/cl/ChecklistMultiSelectColumnDescriptor.java b/src/main/java/de/bps/olat/modules/cl/ChecklistMultiSelectColumnDescriptor.java index 209c962a6b5..43e92bc242d 100644 --- a/src/main/java/de/bps/olat/modules/cl/ChecklistMultiSelectColumnDescriptor.java +++ b/src/main/java/de/bps/olat/modules/cl/ChecklistMultiSelectColumnDescriptor.java @@ -48,6 +48,7 @@ public class ChecklistMultiSelectColumnDescriptor implements ColumnDescriptor { return column; } + @Override public void renderValue(StringOutput sb, int row, Renderer renderer) { // add checkbox int currentPosInModel = table.getSortedRow(row); @@ -63,6 +64,7 @@ public class ChecklistMultiSelectColumnDescriptor implements ColumnDescriptor { } } + @Override public int compareTo(int rowa, int rowb) { boolean rowaChecked = (Boolean) table.getTableDataModel().getValueAt(rowa, column); boolean rowbChecked = (Boolean) table.getTableDataModel().getValueAt(rowb, column); @@ -71,54 +73,71 @@ public class ChecklistMultiSelectColumnDescriptor implements ColumnDescriptor { return 0; } + @Override public boolean equals(Object object) { if (object instanceof ChecklistMultiSelectColumnDescriptor) return true; return false; } + @Override public String getHeaderKey() { return this.headerKey; } + @Override public boolean translateHeaderKey() { return false; } + @Override public int getAlignment() { return ColumnDescriptor.ALIGNMENT_CENTER; } + + @Override + public int getHeaderAlignment() { + return ColumnDescriptor.ALIGNMENT_LEFT; + } + @Override public String getAction(int row) { // no action return null; } + @Override public String getPopUpWindowAttributes() { // no PopuWindow return null; } + @Override public boolean isPopUpWindowAction() { return false; } + @Override public boolean isSortingAllowed() { return true; } + @Override public void modelChanged() { // nothing to do here } + @Override public void otherColumnDescriptorSorted() { // nothing to do here } + @Override public void setTable(Table table) { this.table = table; } + @Override public void sortingAboutToStart() { // nothing to do here } diff --git a/src/main/java/org/olat/core/gui/components/table/ColumnDescriptor.java b/src/main/java/org/olat/core/gui/components/table/ColumnDescriptor.java index a8d1b162acc..83e187acb39 100644 --- a/src/main/java/org/olat/core/gui/components/table/ColumnDescriptor.java +++ b/src/main/java/org/olat/core/gui/components/table/ColumnDescriptor.java @@ -75,6 +75,8 @@ public interface ColumnDescriptor { * @return */ int getAlignment(); + + int getHeaderAlignment(); /** * @param sb @@ -142,4 +144,5 @@ public interface ColumnDescriptor { */ String getPopUpWindowAttributes(); + } \ No newline at end of file diff --git a/src/main/java/org/olat/core/gui/components/table/DefaultColumnDescriptor.java b/src/main/java/org/olat/core/gui/components/table/DefaultColumnDescriptor.java index 763fa840db7..76432984a9c 100644 --- a/src/main/java/org/olat/core/gui/components/table/DefaultColumnDescriptor.java +++ b/src/main/java/org/olat/core/gui/components/table/DefaultColumnDescriptor.java @@ -51,6 +51,7 @@ public class DefaultColumnDescriptor implements ColumnDescriptor { private String action; private String headerKey; private int alignment; + private int headerAlignment; private boolean popUpWindowAction; private String popUpWindowAttributes; //protected to allow overriding of compare method @@ -81,24 +82,28 @@ public class DefaultColumnDescriptor implements ColumnDescriptor { * @param alignment left, middle or right; constants in ColumnDescriptor */ public DefaultColumnDescriptor(final String headerKey, final int dataColumn, final String action, final Locale locale, final int alignment) { + this(headerKey, dataColumn, action, locale, alignment, ColumnDescriptor.ALIGNMENT_LEFT); + } + + public DefaultColumnDescriptor(final String headerKey, final int dataColumn, final String action, final Locale locale, final int alignment, final int headerAlignment) { this.dataColumn = dataColumn; this.headerKey = headerKey; this.action = action; this.locale = locale; this.alignment = alignment; + this.headerAlignment = headerAlignment; if (locale != null) { formatter = Formatter.getInstance(locale); collator = Collator.getInstance(locale); } } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#getHeaderKey() - */ + @Override public String getHeaderKey() { return headerKey; } + @Override public boolean translateHeaderKey() { return translateHeaderKey; } @@ -120,9 +125,7 @@ public class DefaultColumnDescriptor implements ColumnDescriptor { return table.getTableDataModel().getValueAt(table.getSortedRow(row),dataColumn); } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#renderValue(org.olat.core.gui.render.StringOutput, int, org.olat.core.gui.render.Renderer) - */ + @Override public void renderValue(final StringOutput sb, final int row, final Renderer renderer) { Object val = getModelData(row); if (val == null) { @@ -153,13 +156,16 @@ public class DefaultColumnDescriptor implements ColumnDescriptor { } } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#getAlignment() - */ + @Override public int getAlignment() { return alignment; } + @Override + public int getHeaderAlignment() { + return headerAlignment; + } + /** * is called repeatedly caused by Collections.sort(...); * @see org.olat.core.gui.components.table.ColumnDescriptor#compareTo(int, int) @@ -233,92 +239,63 @@ public class DefaultColumnDescriptor implements ColumnDescriptor { return ba? (bb? 0: -1):(bb? 1: 0); } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#setTable(org.olat.core.gui.components.table.Table) - */ + @Override public void setTable(final Table table) { this.table = table; } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#getAction(int) - */ + @Override public String getAction(final int row) { return action; } - - - - /** - * Sets the alignment. - * @param alignment The alignment to set - */ public void setAlignment(final int alignment) { this.alignment= alignment; } + + public void setHeaderAlignment(final int headerAlignment) { + this.headerAlignment= headerAlignment; + } - /** - * @return Table - */ protected Table getTable() { return table; } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#modelChanged() - */ + @Override public void modelChanged() { // empty } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#sortingAboutToStart() - */ + @Override public void sortingAboutToStart() { // empty } - /** - * @return int - */ @Override public int getDataColumn() { return dataColumn; } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#otherColumnDescriptorSorted() - */ + @Override public void otherColumnDescriptorSorted() { // empty } - - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#isSortingAllowed() - */ + @Override public boolean isSortingAllowed() { return true; } - /** - * @return Locale - */ public Locale getLocale() { return locale; } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#isPopUpWindowAction() - */ + @Override public boolean isPopUpWindowAction() { return popUpWindowAction; } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#getPopUpWindowAttributes() - */ + @Override public String getPopUpWindowAttributes() { return popUpWindowAttributes; } diff --git a/src/main/java/org/olat/core/gui/components/table/MultiSelectColumnDescriptor.java b/src/main/java/org/olat/core/gui/components/table/MultiSelectColumnDescriptor.java index 356748fa12a..1b96f3a0b12 100644 --- a/src/main/java/org/olat/core/gui/components/table/MultiSelectColumnDescriptor.java +++ b/src/main/java/org/olat/core/gui/components/table/MultiSelectColumnDescriptor.java @@ -115,6 +115,7 @@ class MultiSelectColumnDescriptor implements ColumnDescriptor { } } + @Override public String getHeaderKey() { // render as checkbox icon to minimize used space for header Translator trans = (table != null ? table.getTranslator() : null); @@ -122,42 +123,57 @@ class MultiSelectColumnDescriptor implements ColumnDescriptor { return "<i class='o_icon o_icon_checkbox_checked o_icon-lg' title=\"" + choice + "\"> </i>"; } + @Override public boolean translateHeaderKey() { return false; } + @Override public int getAlignment() { return ColumnDescriptor.ALIGNMENT_LEFT; } + @Override + public int getHeaderAlignment() { + return getAlignment(); + } + + @Override public String getAction(final int row) { return null; } + @Override public String getPopUpWindowAttributes() { return null; } + @Override public boolean isPopUpWindowAction() { return false; } + @Override public boolean isSortingAllowed() { return true; } + @Override public void modelChanged() { // nothing to do here } + @Override public void otherColumnDescriptorSorted() { // nothing to do here } + @Override public void setTable(final Table table) { this.table = table; } + @Override public void sortingAboutToStart() { // nothing to do here } diff --git a/src/main/java/org/olat/core/gui/components/table/StaticColumnDescriptor.java b/src/main/java/org/olat/core/gui/components/table/StaticColumnDescriptor.java index 2a7579a83fc..09c7753613f 100644 --- a/src/main/java/org/olat/core/gui/components/table/StaticColumnDescriptor.java +++ b/src/main/java/org/olat/core/gui/components/table/StaticColumnDescriptor.java @@ -40,6 +40,7 @@ import org.olat.core.gui.render.StringOutput; public class StaticColumnDescriptor implements ColumnDescriptor { private String headerKey; private int alignment; + private int headerAlignment; private String action; private String cellValue; private boolean popUpWindowAction; @@ -57,18 +58,15 @@ public class StaticColumnDescriptor implements ColumnDescriptor { this.headerKey = headerKey; this.cellValue = cellValue; this.alignment = ALIGNMENT_LEFT; + this.headerAlignment = ALIGNMENT_LEFT; } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#getHeaderKey() - */ + @Override public String getHeaderKey() { return headerKey; } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#translateHeaderKey() - */ + @Override public boolean translateHeaderKey() { return translateHeaderKey; } @@ -89,90 +87,72 @@ public class StaticColumnDescriptor implements ColumnDescriptor { return -1; } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#getAlignment() - */ + @Override public int getAlignment() { return alignment; } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#renderValue(org.olat.core.gui.render.StringOutput, int, org.olat.core.gui.render.Renderer) - */ + @Override + public int getHeaderAlignment() { + return headerAlignment; + } + + + @Override public void renderValue(final StringOutput so, final int row, final Renderer renderer) { so.append(cellValue); } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#compareTo(int, int) - */ @Override public int compareTo(final int rowa, final int rowb) { //dummy order but fixed return rowb - rowa; } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#setTable(org.olat.core.gui.components.table.Table) - */ + @Override public void setTable(final Table arg0) { // not needed here, ignore } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#getAction(int) - */ + @Override public String getAction(final int row) { return action; } - /** - * Sets the alignment. - * - * @param alignment The alignment to set - */ public void setAlignment(final int alignment) { this.alignment = alignment; } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#modelChanged() - */ + public void setheaderAlignment(final int headerAlignment) { + this.headerAlignment = headerAlignment; + } + + @Override public void modelChanged() { // } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#sortingAboutToStart() - */ + @Override public void sortingAboutToStart() { // } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#otherColumnDescriptorSorted() - */ + @Override public void otherColumnDescriptorSorted() { // } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#isSortingAllowed() - */ + @Override public boolean isSortingAllowed() { return false; } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#isPopUpWindowAction() - */ + @Override public boolean isPopUpWindowAction() { return popUpWindowAction; } - /** - * @see org.olat.core.gui.components.table.ColumnDescriptor#getPopUpWindowAttributes() - */ + @Override public String getPopUpWindowAttributes() { return popUpWindowAttributes; } diff --git a/src/main/java/org/olat/core/gui/components/table/TableRenderer.java b/src/main/java/org/olat/core/gui/components/table/TableRenderer.java index 467014d24b1..a5e6a2165ba 100644 --- a/src/main/java/org/olat/core/gui/components/table/TableRenderer.java +++ b/src/main/java/org/olat/core/gui/components/table/TableRenderer.java @@ -329,7 +329,9 @@ public class TableRenderer extends DefaultComponentRenderer { header = cd.getHeaderKey(); } - target.append("<th>"); + int alignment = cd.getHeaderAlignment(); + String cssHeaderClass = (alignment == ColumnDescriptor.ALIGNMENT_LEFT ? "text-left" : (alignment == ColumnDescriptor.ALIGNMENT_RIGHT ? "text-right" : "text-center")); + target.append("<th class='").append(cssHeaderClass).append("'>"); // header either a link or not if (table.isSortingEnabled() && cd.isSortingAllowed()) { target.append("<a class='o_orderby' "); diff --git a/src/main/java/org/olat/course/statistic/StatisticDisplayController.java b/src/main/java/org/olat/course/statistic/StatisticDisplayController.java index 9c3afda666e..d31a073d739 100644 --- a/src/main/java/org/olat/course/statistic/StatisticDisplayController.java +++ b/src/main/java/org/olat/course/statistic/StatisticDisplayController.java @@ -188,18 +188,20 @@ public class StatisticDisplayController extends BasicController { tableController.addColumnDescriptor(statisticManager.createColumnDescriptor(ureq, aColumnId, aHeader)); } - tableController.addColumnDescriptor(new CustomRenderColumnDescriptor("stat.table.header.total", column, - StatisticDisplayController.CLICK_TOTAL_ACTION+column, ureq.getLocale(), ColumnDescriptor.ALIGNMENT_RIGHT, new TotalColumnRenderer()) { + CustomRenderColumnDescriptor columnDescriptor = new CustomRenderColumnDescriptor("stat.table.header.total", + column, StatisticDisplayController.CLICK_TOTAL_ACTION + column, ureq.getLocale(), + ColumnDescriptor.ALIGNMENT_RIGHT, new TotalColumnRenderer()) { @Override public String getAction(int row) { - if (row==table.getTableDataModel().getRowCount()-1) { + if (row == table.getTableDataModel().getRowCount() - 1) { return super.getAction(row); - } else { - return null; } + return null; } - - }); + + }; + columnDescriptor.setHeaderAlignment(ColumnDescriptor.ALIGNMENT_RIGHT); + tableController.addColumnDescriptor(columnDescriptor); tableController.setTableDataModel(result); diff --git a/src/main/java/org/olat/course/statistic/TotalAwareColumnDescriptor.java b/src/main/java/org/olat/course/statistic/TotalAwareColumnDescriptor.java index 670ce5fa980..b2be66ca8f5 100644 --- a/src/main/java/org/olat/course/statistic/TotalAwareColumnDescriptor.java +++ b/src/main/java/org/olat/course/statistic/TotalAwareColumnDescriptor.java @@ -51,16 +51,15 @@ import org.olat.core.gui.render.StringOutput; public class TotalAwareColumnDescriptor extends DefaultColumnDescriptor { public TotalAwareColumnDescriptor(String headerKey, int dataColumn, String action, Locale locale, int alignment) { - super(headerKey, dataColumn, action, locale, alignment); + super(headerKey, dataColumn, action, locale, alignment, alignment); } @Override public String getAction(int row) { if (row==table.getTableDataModel().getRowCount()-1) { return super.getAction(row); - } else { - return null; } + return null; } @Override diff --git a/src/main/java/org/olat/course/statistic/daily/DailyStatisticManager.java b/src/main/java/org/olat/course/statistic/daily/DailyStatisticManager.java index 9ddc3d691ac..449134a67d8 100644 --- a/src/main/java/org/olat/course/statistic/daily/DailyStatisticManager.java +++ b/src/main/java/org/olat/course/statistic/daily/DailyStatisticManager.java @@ -89,7 +89,7 @@ public class DailyStatisticManager implements IStatisticManager { log.warn("createColumnDescriptor: ParseException while parsing "+headerId+".", pe); } TotalAwareColumnDescriptor cd = new TotalAwareColumnDescriptor(header, column, - StatisticDisplayController.CLICK_TOTAL_ACTION+column, ureq.getLocale(), ColumnDescriptor.ALIGNMENT_RIGHT); + StatisticDisplayController.CLICK_TOTAL_ACTION+column, ureq.getLocale(), ColumnDescriptor.ALIGNMENT_RIGHT); cd.setTranslateHeaderKey(false); return cd; } -- GitLab