mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-25 06:58:39 +00:00
a first draft showing two detail columns within a leg
This commit is contained in:
+37
-2
@@ -1,11 +1,13 @@
|
||||
package com.sap.sailing.gwt.ui.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gwt.cell.client.TextCell;
|
||||
import com.google.gwt.safehtml.shared.SafeHtml;
|
||||
import com.google.gwt.user.cellview.client.Header;
|
||||
import com.sap.sailing.gwt.ui.client.LegDetailColumn.LegDetailField;
|
||||
import com.sap.sailing.gwt.ui.shared.LeaderboardEntryDAO;
|
||||
import com.sap.sailing.gwt.ui.shared.LeaderboardRowDAO;
|
||||
import com.sap.sailing.gwt.ui.shared.LegEntryDAO;
|
||||
@@ -21,6 +23,33 @@ public class LegColumn extends ExpandableSortableColumn<String> {
|
||||
private final String raceName;
|
||||
private final int legIndex;
|
||||
|
||||
private abstract class AbstractLegDetailField<T> implements LegDetailField<T> {
|
||||
public T get(LeaderboardRowDAO row) {
|
||||
LegEntryDAO entry = getLegEntry(row);
|
||||
if (entry == null) {
|
||||
return null;
|
||||
} else {
|
||||
return getFromNonNullEntry(entry);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract T getFromNonNullEntry(LegEntryDAO entry);
|
||||
}
|
||||
|
||||
private class DistanceTraveledInMeters extends AbstractLegDetailField<Double> {
|
||||
@Override
|
||||
protected Double getFromNonNullEntry(LegEntryDAO entry) {
|
||||
return entry.distanceTraveledInMeters;
|
||||
}
|
||||
}
|
||||
|
||||
private class AverageSpeedOverGroundInKnots extends AbstractLegDetailField<Double> {
|
||||
@Override
|
||||
protected Double getFromNonNullEntry(LegEntryDAO entry) {
|
||||
return entry.averageSpeedOverGroundInKnots;
|
||||
}
|
||||
}
|
||||
|
||||
public LegColumn(LeaderboardPanel leaderboardPanel, String raceName, int legIndex) {
|
||||
super(leaderboardPanel, /* expandable */ true /* all legs have details */, new TextCell());
|
||||
this.raceName = raceName;
|
||||
@@ -76,8 +105,14 @@ public class LegColumn extends ExpandableSortableColumn<String> {
|
||||
|
||||
@Override
|
||||
protected List<SortableColumn<LeaderboardRowDAO, ?>> createExpansionColumns() {
|
||||
// TODO this is where dynamic column configuration will go
|
||||
return super.createExpansionColumns();
|
||||
List<SortableColumn<LeaderboardRowDAO, ?>> result = new ArrayList<SortableColumn<LeaderboardRowDAO,?>>();
|
||||
try {
|
||||
result.add(new FormattedDoubleLegDetailColumn("Distance/m", new DistanceTraveledInMeters(), 1));
|
||||
result.add(new FormattedDoubleLegDetailColumn("Average Speed/kts", new AverageSpeedOverGroundInKnots(), 2));
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Executable
+59
@@ -0,0 +1,59 @@
|
||||
package com.sap.sailing.gwt.ui.client;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.google.gwt.cell.client.TextCell;
|
||||
import com.google.gwt.user.cellview.client.Header;
|
||||
import com.google.gwt.user.cellview.client.TextHeader;
|
||||
import com.sap.sailing.gwt.ui.shared.LeaderboardRowDAO;
|
||||
|
||||
public class LegDetailColumn<T> extends SortableColumn<LeaderboardRowDAO, String> {
|
||||
private final String title;
|
||||
private final LegDetailField<T> field;
|
||||
|
||||
public interface LegDetailField<T> {
|
||||
T get(LeaderboardRowDAO row);
|
||||
}
|
||||
|
||||
protected LegDetailColumn(String title, LegDetailField<T> field) {
|
||||
super(new TextCell());
|
||||
this.title = title;
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
protected String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
protected LegDetailField<T> getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<LeaderboardRowDAO> getComparator() {
|
||||
return new Comparator<LeaderboardRowDAO>() {
|
||||
@Override
|
||||
public int compare(LeaderboardRowDAO o1, LeaderboardRowDAO o2) {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Comparable<T> value1 = (Comparable<T>) field.get(o1);
|
||||
T value2 = field.get(o2);
|
||||
return value1 == null ? value2 == null ? 0 : -1 : value2 == null ? 1 : value1.compareTo(value2);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Header<?> getHeader() {
|
||||
return new TextHeader(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(LeaderboardRowDAO row) {
|
||||
T fieldValue = field.get(row);
|
||||
return fieldValue == null ? "" : fieldValue.toString();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -115,7 +115,7 @@
|
||||
<configuration>
|
||||
<!-- non-debug -->
|
||||
<!-- proxy -->
|
||||
<argLine>-Dfile.encoding=cp1252 -Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080 -Dtractrac.tunnel=true -Dtractrac.tunnel.host=10.18.10.38 -Dmongo.host=10.18.10.38 -Xmx1024m -XX:PermSize=256m -XX:-UseGCOverheadLimit -XX:+UseParallelGC</argLine>
|
||||
<argLine>-Dfile.encoding=cp1252 -Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080 -Dtractrac.tunnel=true -Dtractrac.tunnel.host=10.18.10.38 -Dmongo.hostname=10.18.10.38 -Xmx1024m -XX:PermSize=256m -XX:-UseGCOverheadLimit -XX:+UseParallelGC</argLine>
|
||||
<!-- -->
|
||||
<!-- no proxy
|
||||
<argLine>-Dfile.encoding=cp1252 -Xmx1024m -XX:PermSize=256m -XX:-UseGCOverheadLimit -XX:+UseParallelGC</argLine>
|
||||
|
||||
Reference in New Issue
Block a user