mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-08 13:20:57 +00:00
null values are now always sorted towards the bottom of the table
This commit is contained in:
1 parent
b823eebfed
commit
f1edc793ac
11 files changed
+63
-31
No files matched your search
+1
-1
@@ -74,7 +74,7 @@ public class TrackedLegOfCompetitorImpl implements TrackedLegOfCompetitor {
|
||||
public Distance getDistanceTraveled(TimePoint timePoint) {
|
||||
MarkPassing legStart = getMarkPassingForLegStart();
|
||||
if (legStart == null) {
|
||||
return Distance.NULL;
|
||||
return null;
|
||||
} else {
|
||||
MarkPassing legEnd = getMarkPassingForLegEnd();
|
||||
TimePoint end = timePoint;
|
||||
|
||||
-4
@@ -3,7 +3,6 @@ package com.sap.sailing.gwt.ui.client;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gwt.cell.client.Cell;
|
||||
@@ -192,9 +191,6 @@ public abstract class ExpandableSortableColumn<C> extends SortableColumn<Leaderb
|
||||
super.render(context, object, html);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract Comparator<LeaderboardRowDAO> getComparator();
|
||||
|
||||
@Override
|
||||
public abstract Header<SafeHtml> getHeader();
|
||||
}
|
||||
+3
-2
@@ -2,6 +2,7 @@ package com.sap.sailing.gwt.ui.client;
|
||||
|
||||
import com.google.gwt.cell.client.TextCell;
|
||||
import com.google.gwt.i18n.client.NumberFormat;
|
||||
import com.google.gwt.user.cellview.client.CellTable;
|
||||
import com.sap.sailing.gwt.ui.shared.LeaderboardRowDAO;
|
||||
|
||||
public class FormattedDoubleLegDetailColumn extends LegDetailColumn<Double, String> {
|
||||
@@ -9,8 +10,8 @@ public class FormattedDoubleLegDetailColumn extends LegDetailColumn<Double, Stri
|
||||
|
||||
public FormattedDoubleLegDetailColumn(String title,
|
||||
com.sap.sailing.gwt.ui.client.LegDetailColumn.LegDetailField<Double> field,
|
||||
int decimals) {
|
||||
super(title, field, new TextCell());
|
||||
int decimals, CellTable<LeaderboardRowDAO> leaderboardTable) {
|
||||
super(title, field, new TextCell(), leaderboardTable);
|
||||
StringBuilder patternBuilder = new StringBuilder("0");
|
||||
if (decimals > 0) {
|
||||
patternBuilder.append('.');
|
||||
|
||||
+16
-3
@@ -22,6 +22,7 @@ import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
|
||||
import com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo;
|
||||
import com.google.gwt.user.cellview.client.Header;
|
||||
import com.google.gwt.user.cellview.client.TextHeader;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.FormPanel;
|
||||
@@ -155,8 +156,11 @@ public class LeaderboardPanel extends FormPanel {
|
||||
return new Comparator<LeaderboardRowDAO>() {
|
||||
@Override
|
||||
public int compare(LeaderboardRowDAO o1, LeaderboardRowDAO o2) {
|
||||
return o1.fieldsByRaceName.get(raceName).netPoints
|
||||
- o2.fieldsByRaceName.get(raceName).netPoints;
|
||||
boolean ascending = isSortedAscendingForThisColumn(getLeaderboardPanel().getLeaderboardTable());
|
||||
LeaderboardEntryDAO o1Entry = o1.fieldsByRaceName.get(raceName);
|
||||
LeaderboardEntryDAO o2Entry = o2.fieldsByRaceName.get(raceName);
|
||||
return o1Entry == null ? o2Entry == null ? 0 : ascending?1:-1
|
||||
: o2Entry == null ? ascending?-1:1 : o1Entry.netPoints - o2Entry.netPoints;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -321,7 +325,16 @@ public class LeaderboardPanel extends FormPanel {
|
||||
VerticalPanel vp = new VerticalPanel();
|
||||
HorizontalPanel hp = new HorizontalPanel();
|
||||
hp.setSpacing(10);
|
||||
hp.add(new Image("/images/sap_66_transparent.png"));
|
||||
Image sapLogo = new Image("/images/sap_66_transparent.png");
|
||||
sapLogo.setTitle(stringConstants.sapSailingAnalytics());
|
||||
sapLogo.setAltText(stringConstants.sapSailingAnalytics());
|
||||
sapLogo.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
Window.Location.assign("http://www.sap.com");
|
||||
}
|
||||
});
|
||||
hp.add(sapLogo);
|
||||
hp.add(new Label(leaderboardName));
|
||||
Button refreshButton = new Button(stringConstants.refresh());
|
||||
hp.add(refreshButton);
|
||||
|
||||
+14
-14
@@ -100,20 +100,15 @@ public class LegColumn extends ExpandableSortableColumn<String> {
|
||||
return new Comparator<LeaderboardRowDAO>() {
|
||||
@Override
|
||||
public int compare(LeaderboardRowDAO o1, LeaderboardRowDAO o2) {
|
||||
return safeGetLegRank(o1) - safeGetLegRank(o2);
|
||||
boolean ascending = isSortedAscendingForThisColumn(getLeaderboardPanel().getLeaderboardTable());
|
||||
LegEntryDAO o1Entry = getLegEntry(o1);
|
||||
LegEntryDAO o2Entry = getLegEntry(o2);
|
||||
return o1Entry == null ? o2Entry == null ? 0 : ascending?1:-1
|
||||
: o2Entry == null ? ascending?-1:1 : o1Entry.rank - o2Entry.rank;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private int safeGetLegRank(LeaderboardRowDAO row) {
|
||||
int result = 0;
|
||||
LegEntryDAO legEntry = getLegEntry(row);
|
||||
if (legEntry != null) {
|
||||
result = legEntry.rank;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Header<SafeHtml> getHeader() {
|
||||
return new SortableExpandableColumnHeader(/* title */ stringConstants.leg()+" "+(legIndex+1),
|
||||
@@ -122,16 +117,21 @@ public class LegColumn extends ExpandableSortableColumn<String> {
|
||||
|
||||
@Override
|
||||
public String getValue(LeaderboardRowDAO row) {
|
||||
return ""+safeGetLegRank(row);
|
||||
LegEntryDAO legEntry = getLegEntry(row);
|
||||
if (legEntry != null) {
|
||||
return ""+legEntry.rank;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<SortableColumn<LeaderboardRowDAO, ?>> createExpansionColumns() {
|
||||
List<SortableColumn<LeaderboardRowDAO, ?>> result = new ArrayList<SortableColumn<LeaderboardRowDAO,?>>();
|
||||
try {
|
||||
result.add(new FormattedDoubleLegDetailColumn(stringConstants.distanceInMeters(), new DistanceTraveledInMeters(), 1));
|
||||
result.add(new FormattedDoubleLegDetailColumn(stringConstants.averageSpeedInKnots(), new AverageSpeedOverGroundInKnots(), 2));
|
||||
result.add(new RankGainColumn(stringConstants.rankGain(), new RankGain()));
|
||||
result.add(new FormattedDoubleLegDetailColumn(stringConstants.distanceInMeters(), new DistanceTraveledInMeters(), 1, getLeaderboardPanel().getLeaderboardTable()));
|
||||
result.add(new FormattedDoubleLegDetailColumn(stringConstants.averageSpeedInKnots(), new AverageSpeedOverGroundInKnots(), 2, getLeaderboardPanel().getLeaderboardTable()));
|
||||
result.add(new RankGainColumn(stringConstants.rankGain(), new RankGain(), getLeaderboardPanel().getLeaderboardTable()));
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
+7
-2
@@ -3,6 +3,7 @@ package com.sap.sailing.gwt.ui.client;
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.google.gwt.cell.client.Cell;
|
||||
import com.google.gwt.user.cellview.client.CellTable;
|
||||
import com.google.gwt.user.cellview.client.Header;
|
||||
import com.google.gwt.user.cellview.client.TextHeader;
|
||||
import com.sap.sailing.gwt.ui.shared.LeaderboardRowDAO;
|
||||
@@ -10,16 +11,18 @@ import com.sap.sailing.gwt.ui.shared.LeaderboardRowDAO;
|
||||
public abstract class LegDetailColumn<FieldType, RenderingType> extends SortableColumn<LeaderboardRowDAO, RenderingType> {
|
||||
private final String title;
|
||||
private final LegDetailField<FieldType> field;
|
||||
private final CellTable<LeaderboardRowDAO> leaderboardTable;
|
||||
|
||||
public interface LegDetailField<T> {
|
||||
T get(LeaderboardRowDAO row);
|
||||
}
|
||||
|
||||
protected LegDetailColumn(String title, LegDetailField<FieldType> field, Cell<RenderingType> cell) {
|
||||
protected LegDetailColumn(String title, LegDetailField<FieldType> field, Cell<RenderingType> cell, CellTable<LeaderboardRowDAO> leaderboardTable) {
|
||||
super(cell);
|
||||
setHorizontalAlignment(ALIGN_RIGHT);
|
||||
this.title = title;
|
||||
this.field = field;
|
||||
this.leaderboardTable = leaderboardTable;
|
||||
}
|
||||
|
||||
protected String getTitle() {
|
||||
@@ -35,11 +38,13 @@ public abstract class LegDetailColumn<FieldType, RenderingType> extends Sortable
|
||||
return new Comparator<LeaderboardRowDAO>() {
|
||||
@Override
|
||||
public int compare(LeaderboardRowDAO o1, LeaderboardRowDAO o2) {
|
||||
boolean ascending = isSortedAscendingForThisColumn(leaderboardTable);
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Comparable<FieldType> value1 = (Comparable<FieldType>) field.get(o1);
|
||||
FieldType value2 = field.get(o2);
|
||||
return value1 == null ? value2 == null ? 0 : -1 : value2 == null ? 1 : value1.compareTo(value2);
|
||||
return value1 == null ? value2 == null ? 0 : ascending?1:-1
|
||||
: value2 == null ? ascending?-1:1 : value1.compareTo(value2);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
+3
-2
@@ -4,11 +4,12 @@ import com.google.gwt.cell.client.AbstractSafeHtmlCell;
|
||||
import com.google.gwt.safehtml.shared.SafeHtml;
|
||||
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
||||
import com.google.gwt.text.shared.SafeHtmlRenderer;
|
||||
import com.google.gwt.user.cellview.client.CellTable;
|
||||
import com.sap.sailing.gwt.ui.shared.LeaderboardRowDAO;
|
||||
|
||||
public class RankGainColumn extends LegDetailColumn<Integer, Integer> {
|
||||
public RankGainColumn(String title, LegDetailField<Integer> field) {
|
||||
super(title, field, new RankGainCell());
|
||||
public RankGainColumn(String title, LegDetailField<Integer> field, CellTable<LeaderboardRowDAO> leaderboardTable) {
|
||||
super(title, field, new RankGainCell(), leaderboardTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+13
@@ -3,8 +3,11 @@ package com.sap.sailing.gwt.ui.client;
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.google.gwt.cell.client.Cell;
|
||||
import com.google.gwt.user.cellview.client.CellTable;
|
||||
import com.google.gwt.user.cellview.client.Column;
|
||||
import com.google.gwt.user.cellview.client.ColumnSortList;
|
||||
import com.google.gwt.user.cellview.client.Header;
|
||||
import com.sap.sailing.gwt.ui.shared.LeaderboardRowDAO;
|
||||
|
||||
public abstract class SortableColumn<T, C> extends Column<T, C> {
|
||||
protected SortableColumn(Cell<C> cell) {
|
||||
@@ -12,6 +15,16 @@ public abstract class SortableColumn<T, C> extends Column<T, C> {
|
||||
setSortable(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* To enable sorting of <code>null</code> values to the end even in ascending order, the comparators provided
|
||||
* by the subclasses will want to know whether the leaderboard table is currently sorted in ascending order
|
||||
* for this column.
|
||||
*/
|
||||
protected boolean isSortedAscendingForThisColumn(CellTable<LeaderboardRowDAO> leaderboardTable) {
|
||||
ColumnSortList sortList = leaderboardTable.getColumnSortList();
|
||||
return sortList.size() > 0 && sortList.get(0).getColumn() == this && sortList.get(0).isAscending();
|
||||
}
|
||||
|
||||
public abstract Comparator<T> getComparator();
|
||||
|
||||
public abstract Header<?> getHeader();
|
||||
|
||||
+1
@@ -65,4 +65,5 @@ public interface StringConstants extends Constants {
|
||||
String distanceInMeters();
|
||||
String averageSpeedInKnots();
|
||||
String rankGain();
|
||||
String sapSailingAnalytics();
|
||||
}
|
||||
+2
-1
@@ -59,4 +59,5 @@ expand=+
|
||||
leg=Leg
|
||||
distanceInMeters=Distance/m
|
||||
averageSpeedInKnots=Average Speed/kts
|
||||
rankGain=Rank Gain
|
||||
rankGain=Rank Gain
|
||||
sapSailingAnalytics=SAP Sailing Analytics
|
||||
+3
-2
@@ -1,13 +1,14 @@
|
||||
package com.sap.sailing.gwt.ui.client;
|
||||
|
||||
import com.google.gwt.cell.client.TextCell;
|
||||
import com.google.gwt.user.cellview.client.CellTable;
|
||||
import com.sap.sailing.gwt.ui.shared.LeaderboardRowDAO;
|
||||
|
||||
public class StringRenderingLegDetailColumn<FieldType> extends LegDetailColumn<FieldType, String> {
|
||||
|
||||
protected StringRenderingLegDetailColumn(String title,
|
||||
com.sap.sailing.gwt.ui.client.LegDetailColumn.LegDetailField<FieldType> field) {
|
||||
super(title, field, new TextCell());
|
||||
com.sap.sailing.gwt.ui.client.LegDetailColumn.LegDetailField<FieldType> field, CellTable<LeaderboardRowDAO> leaderboardTable) {
|
||||
super(title, field, new TextCell(), leaderboardTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user