Races list - Avoid reinitialization of SortedCellTable for race lists

This commit is contained in:
Benjamin Barth committed 2015-07-20 12:24:28 +02:00
1 parent cd57fda51d
commit e9a0099976
4 files changed
+63 -26

No files matched your search

@@ -211,4 +211,13 @@
.racesListIcon > div {
vertical-align: middle;
display: inline-block;
}
.racesListHideColumn {
width: 0 !important;
padding: 0 !important;
margin: 0 !important;
border: medium none !important;
}
.racesListHideColumn > * {
display: none !important;
}
@@ -49,5 +49,6 @@ public interface RacesListLiveResources extends ClientBundle {
String raceslistlive();
String racesListIcon();
String racesListHideColumn();
}
}
@@ -1,8 +1,9 @@
package com.sap.sailing.gwt.home.client.place.event.partials.racelist;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.ColumnSortList;
import com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo;
import com.google.gwt.user.cellview.client.Header;
@@ -38,22 +39,33 @@ public abstract class AbstractRaceList<T extends RaceMetadataDTO<? extends Abstr
protected AbstractRaceList(EventView.Presenter presenter) {
CSS.ensureInjected();
this.raceViewerButtonColumn = RaceListColumnFactory.getRaceViewerButtonColumn(presenter);
this.cellTable = new SortedCellTable<T>(0, CleanCellTableResources.INSTANCE);
this.cellTableContainer.setWidget(this.cellTable);
this.initTableStyle();
this.initWidget(cellTableContainer);
}
@SuppressWarnings("unchecked")
protected void setTableData(Collection<T> data) {
ColumnSortList sortList = this.cellTable == null ? null : this.cellTable.getColumnSortList();
this.cellTable = new SortedCellTable<T>(data.size(), CleanCellTableResources.INSTANCE);
this.cellTableContainer.setWidget(this.cellTable);
this.initTableStyle();
this.initTableColumns();
if (this.cellTable.getColumnCount() == 0) {
this.initTableColumns();
}
ColumnSortList sortList = this.cellTable.getColumnSortList();
List<ColumnSortInfo> oldSortInfos = new ArrayList<ColumnSortList.ColumnSortInfo>(sortList.size());
for (int i = sortList.size() - 1; i >= 0; i--) {
oldSortInfos.add(sortList.get(i));
}
this.cellTable.setPageSize(data.size());
for (int i = 0; i < this.cellTable.getColumnCount(); i++) {
SortableRaceListColumn<T, ?> column = (SortableRaceListColumn<T, ?>) this.cellTable.getColumn(i);
column.getHeader().setHeaderStyleNames(column.getCurrentHeaderStyle());
column.setCellStyleNames(column.getCurrentColumnStyle());
}
this.cellTable.setList(data);
if (sortList != null && sortList.size() > 0) {
for (int i = sortList.size() - 1; i >= 0; i--) {
ColumnSortInfo sortInfo = sortList.get(i);
Column<T, ?> column = (Column<T, ?>) sortInfo.getColumn();
if(this.cellTable.getColumnIndex(column) >= 0) {
if (!oldSortInfos.isEmpty()) {
for (ColumnSortInfo sortInfo : oldSortInfos) {
SortableRaceListColumn<T, ?> column = (SortableRaceListColumn<T, ?>) sortInfo.getColumn();
if(column.isShowDetails()) {
this.cellTable.sortColumn(column, sortInfo.isAscending());
}
}
@@ -74,23 +86,21 @@ public abstract class AbstractRaceList<T extends RaceMetadataDTO<? extends Abstr
}
protected abstract void initTableColumns();
protected void add(SortableRaceListColumn<T, ?> column) {
if (column.isShowDetails()) {
if (column.getColumnStyle() != null) {
column.setCellStyleNames(column.getColumnStyle());
}
Header<?> header = column.getHeader();
if (header != null && column.getHeaderStyle() != null) {
header.setHeaderStyleNames(column.getHeaderStyle());
}
boolean ascending = column.getPreferredSortingOrder().isAscending();
InvertibleComparator<T> comperator = column.getComparator();
if (comperator != null) {
comperator.setAscending(ascending);
}
this.cellTable.addColumn(column, header, comperator, ascending);
if (column.getColumnStyle() != null) {
column.setCellStyleNames(column.getColumnStyle());
}
Header<?> header = column.getHeader();
if (header != null && column.getHeaderStyle() != null) {
header.setHeaderStyleNames(column.getHeaderStyle());
}
boolean ascending = column.getPreferredSortingOrder().isAscending();
InvertibleComparator<T> comperator = column.getComparator();
if (comperator != null) {
comperator.setAscending(ascending);
}
this.cellTable.addColumn(column, header, comperator, ascending);
}
}
@@ -5,6 +5,7 @@ import com.google.gwt.user.cellview.client.Header;
import com.google.gwt.user.cellview.client.TextHeader;
import com.sap.sailing.domain.common.InvertibleComparator;
import com.sap.sailing.domain.common.SortingOrder;
import com.sap.sailing.gwt.home.client.place.event.partials.raceListLive.RacesListLiveResources;
import com.sap.sailing.gwt.ui.client.shared.controls.SortableColumn;
import com.sap.sse.common.Util;
@@ -54,4 +55,20 @@ public abstract class SortableRaceListColumn<T, C> extends SortableColumn<T, C>
protected final String getStyleNamesString(String... styleNames) {
return Util.join(" ", styleNames);
}
private static final String COLUMN_HIDDEN_STYLE = RacesListLiveResources.INSTANCE.css().racesListHideColumn();
protected final String getCurrentHeaderStyle() {
return getShowOrHiddenStyle(getHeaderStyle());
}
protected final String getCurrentColumnStyle() {
return getShowOrHiddenStyle(getColumnStyle());
}
private String getShowOrHiddenStyle(String showStyle) {
showStyle = showStyle == null ? "" : showStyle;
return showDetails ? showStyle : getStyleNamesString(showStyle, COLUMN_HIDDEN_STYLE);
}
}