From 2fe31ac21df43b48fc2439dc5d2faca2d4084e3f Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Wed, 28 Oct 2015 08:54:49 +0100 Subject: [PATCH] OO-1754: prevent sorting columns which are flagged as not sortable, add a dummy compare method to the static column instead of the AssertException --- .../table/StaticColumnDescriptor.java | 5 ++-- .../olat/core/gui/components/table/Table.java | 28 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) 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 b93e5ac1283..10a8a0cedf3 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 @@ -28,7 +28,6 @@ package org.olat.core.gui.components.table; import org.olat.core.gui.render.Renderer; import org.olat.core.gui.render.StringOutput; -import org.olat.core.logging.AssertException; /** * Description:<br> @@ -108,8 +107,10 @@ public class StaticColumnDescriptor implements ColumnDescriptor { /** * @see org.olat.core.gui.components.table.ColumnDescriptor#compareTo(int, int) */ + @Override public int compareTo(final int rowa, final int rowb) { - throw new AssertException("staticcolumndescriptor was called to be sorted, but did not offer to be sorted"); + //dummy order but fixed + return rowb - rowa; } /** diff --git a/src/main/java/org/olat/core/gui/components/table/Table.java b/src/main/java/org/olat/core/gui/components/table/Table.java index 8a2feed72a0..952582d5717 100644 --- a/src/main/java/org/olat/core/gui/components/table/Table.java +++ b/src/main/java/org/olat/core/gui/components/table/Table.java @@ -525,23 +525,21 @@ public class Table extends AbstractComponent { protected void resort() { if (isSortingEnabled() && sortColumn < getColumnCount()) { ColumnDescriptor currentSortingCd = getColumnDescriptor(sortColumn); // we sort after this - // column descriptor - // notify all nonactive ColumnDescriptors about their state - int cdcnt = getColumnCount(); - for (int i = 0; i < cdcnt; i++) { - ColumnDescriptor cd = getColumnDescriptor(i); - if (cd != currentSortingCd){ - cd.otherColumnDescriptorSorted(); + if(currentSortingCd != null && currentSortingCd.isSortingAllowed()) { + // column descriptor + // notify all nonactive ColumnDescriptors about their state + int cdcnt = getColumnCount(); + for (int i = 0; i < cdcnt; i++) { + ColumnDescriptor cd = getColumnDescriptor(i); + if (cd != currentSortingCd){ + cd.otherColumnDescriptorSorted(); + } } + currentSortingCd.sortingAboutToStart(); + Collections.sort(sorter, new TableComparator(currentSortingCd, sortAscending)); + } else { + log.error("Sort column not found:" + sortColumn + " in columns: " + columnOrder, null); } - - if (currentSortingCd == null){ - throw new RuntimeException("cannot find columndesc for column " - + sortColumn - + " in sorting process, maybe you have set the tabledatamodel before the columndescriptors?"); - } - currentSortingCd.sortingAboutToStart(); - Collections.sort(sorter, new TableComparator(currentSortingCd, sortAscending)); } } -- GitLab