diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/auth/CurrentUser.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/auth/CurrentUser.java index b1bb93849..cc139930c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/auth/CurrentUser.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/auth/CurrentUser.java @@ -70,6 +70,10 @@ public void putAttribute(final String name, final String value) { this.attributes.put(name, value); } + public void deleteAttribute(final String name) { + this.attributes.remove(name); + } + public String getAttribute(final String name) { return this.attributes.get(name); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java b/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java index f5d5d926a..59d43c88d 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java @@ -76,6 +76,7 @@ public class EntityTable { private final String sortAttrName; private final String sortOrderAttrName; private final String currentPageAttrName; + private final String columnWidthAttrName; private final boolean markupEnabled; private final Consumer> pageReloadListener; @@ -138,6 +139,7 @@ public class EntityTable { this.sortAttrName = name + "_sort"; this.sortOrderAttrName = name + "_sortOrder"; this.currentPageAttrName = name + "_currentPage"; + this.columnWidthAttrName = name + "_columnWidth"; this.markupEnabled = markupEnabled; this.defaultSortColumn = defaultSortColumn; @@ -236,6 +238,7 @@ public class EntityTable { this.navigator = new TableNavigator(this); createTableColumns(); + this.pageNumber = initCurrentPageFromUserAttr(); initFilterFromUserAttrs(); initSortFromUserAttr(); @@ -317,6 +320,8 @@ public void selectPage(final int pageSelection) { } public void reset() { + deleteColumnWidths(); + adaptColumnWidth(null); this.sortColumn = this.defaultSortColumn; this.sortOrder = this.defaultSortOrder; updateSortUserAttr(); @@ -595,7 +600,7 @@ private void adaptColumnWidth(final Event event) { try { int currentTableWidth = this.table.getParent().getClientArea().width; // If we have all columns with filter we need some more space for the - // filter actions in the right hand side. This tweak gives enough space for that + // filter actions on the right hand side. This tweak gives enough space for that if (this.filter != null && this.columns.size() == this.filter.size()) { currentTableWidth -= 60; } @@ -620,7 +625,7 @@ private void adaptColumnWidth(final Event event) { final int newWidth = (pSize > 0) ? columnUnitSize * column.getWidthProportion() : columnUnitSize; - tableColumn.setWidth(newWidth); + loadOrSetColumnWidth(index, newWidth); if (this.filter != null) { this.filter.adaptColumnWidth(this.table.indexOf(tableColumn), newWidth); } @@ -639,11 +644,7 @@ private void adaptColumnWidthChange(final Event event) { final Widget widget = event.widget; if (widget instanceof TableColumn) { final TableColumn tableColumn = ((TableColumn) widget); - if (this.filter != null) { - this.filter.adaptColumnWidth( - this.table.indexOf(tableColumn), - tableColumn.getWidth()); - } + this.saveColumnSize(table.indexOf(tableColumn)); } } @@ -906,4 +907,37 @@ public void refreshPageSize() { } } + private void saveColumnSize(final int columnIndex) { + final TableColumn column = table.getColumn(columnIndex); + if (column.getWidth() > 0) { + this.pageService + .getCurrentUser() + .putAttribute( + columnWidthAttrName + columnIndex, + String.valueOf(table.getColumn(columnIndex).getWidth())); + } + } + + private void loadOrSetColumnWidth(final int columnIndex, final int defaultWidth) { + int width = defaultWidth; + try { + width = Integer.parseInt(this.pageService + .getCurrentUser() + .getAttribute(columnWidthAttrName + columnIndex)); + } catch (final Exception e) { + // ignore + } + + table.getColumn(columnIndex).setWidth(width); + saveColumnSize(columnIndex); + } + + private void deleteColumnWidths() { + for (int i = 0; i < this.columns.size(); i++) { + this.pageService + .getCurrentUser() + .deleteAttribute(columnWidthAttrName + i); + } + } + }