remove now unnecessary workaround for grid sorting

This commit is contained in:
f43nd1r 2019-11-27 04:13:55 +01:00
parent 76b3e07172
commit 700d100fdf
3 changed files with 4 additions and 33 deletions

View file

@ -20,12 +20,8 @@ import com.faendir.acra.dataprovider.QueryDslDataProvider;
import com.faendir.acra.ui.component.HasSize;
import com.querydsl.core.types.Expression;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.ComponentEvent;
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.ComponentUtil;
import com.vaadin.flow.component.Composite;
import com.vaadin.flow.component.DomEvent;
import com.vaadin.flow.component.EventData;
import com.vaadin.flow.component.grid.FooterRow;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.grid.GridSortOrder;
@ -148,32 +144,7 @@ public class MyGrid<T> extends Composite<Grid<T>> implements LocaleChangeObserve
columnCaptions.forEach((column, caption) -> column.setHeader(getTranslation(caption.getFirst(), caption.getSecond())));
}
public void setInitialSort(List<GridSortOrder<T>> order) {
addLoadingListener(e -> {
if(!e.isLoading()) {
getContent().sort(order);
e.unregisterListener();
}
});
}
private Registration addLoadingListener(
ComponentEventListener<LoadingChangedEvent> listener) {
return ComponentUtil.addListener(this, LoadingChangedEvent.class, listener);
}
@DomEvent("loading-changed")
public static class LoadingChangedEvent extends ComponentEvent<MyGrid<?>> {
private boolean loading;
public LoadingChangedEvent(MyGrid<?> source, boolean fromClient, @EventData("element.loading") boolean loading) {
super(source, fromClient);
this.loading = loading;
}
public boolean isLoading() {
return loading;
}
public void sort(List<GridSortOrder<T>> order) {
getContent().sort(order);
}
}

View file

@ -47,7 +47,7 @@ public class ReportList extends MyGrid<Report>{
setSelectionMode(Grid.SelectionMode.NONE);
addColumn(new ComponentRenderer<>(avatarService::getAvatar) , QReport.report.installationId, Messages.USER);
Grid.Column<Report> dateColumn = addColumn(new TimeSpanRenderer<>(Report::getDate), QReport.report.date, Messages.DATE);
setInitialSort(GridSortOrder.desc(dateColumn).build());
sort(GridSortOrder.desc(dateColumn).build());
addColumn(report -> report.getStacktrace().getVersion().getCode(), QReport.report.stacktrace.version.code, Messages.APP_VERSION);
addColumn(Report::getAndroidVersion, QReport.report.androidVersion, Messages.ANDROID_VERSION);
addColumn(Report::getPhoneModel, QReport.report.phoneModel, Messages.DEVICE);

View file

@ -95,7 +95,7 @@ public class BugTab extends AppTab<VerticalLayout> {
}, Messages.MERGE_BUGS);
Grid.Column<VBug> countColumn = bugs.addColumn(VBug::getReportCount, QReport.report.count(), Messages.REPORTS);
Grid.Column<VBug> dateColumn = bugs.addColumn(new TimeSpanRenderer<>(VBug::getLastReport), QReport.report.date.max(), Messages.LATEST_REPORT);
bugs.setInitialSort(GridSortOrder.desc(dateColumn).build());
bugs.sort(GridSortOrder.desc(dateColumn).build());
bugs.addColumn(VBug::getHighestVersionCode, QReport.report.stacktrace.version.code.max(), Messages.LATEST_VERSION);
bugs.addColumn(VBug::getUserCount, QReport.report.installationId.countDistinct(), Messages.AFFECTED_USERS);
bugs.addColumn(bug -> bug.getBug().getTitle(), QBug.bug.title, Messages.TITLE).setAutoWidth(false).setFlexGrow(1);