mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-08 05:11:04 +00:00
added localization support for leg column header names
This commit is contained in:
1 parent
ca21d5ef0d
commit
e8eb472888
7 files changed
+54
-13
No files matched your search
+5
-2
@@ -118,6 +118,7 @@ public class LeaderboardPanel extends FormPanel {
|
||||
|
||||
public RaceColumn(String raceName, boolean medalRace, boolean enableExpansion, Cell<C> cell) {
|
||||
super(LeaderboardPanel.this, enableExpansion, cell);
|
||||
setHorizontalAlignment(ALIGN_RIGHT);
|
||||
this.raceName = raceName;
|
||||
this.medalRace = medalRace;
|
||||
}
|
||||
@@ -160,7 +161,7 @@ public class LeaderboardPanel extends FormPanel {
|
||||
public Header<SafeHtml> getHeader() {
|
||||
return new SortableExpandableColumnHeader(/* title */ raceName,
|
||||
/* iconURL */ medalRace ? "/images/medal.png" : null,
|
||||
LeaderboardPanel.this, this);
|
||||
LeaderboardPanel.this, this, stringConstants);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +202,7 @@ public class LeaderboardPanel extends FormPanel {
|
||||
int legCount = getLeaderboard().getLegCount(getRaceName());
|
||||
List<SortableColumn<LeaderboardRowDAO, ?>> result = new ArrayList<SortableColumn<LeaderboardRowDAO,?>>();
|
||||
for (int i=0; i<legCount; i++) {
|
||||
result.add(new LegColumn(LeaderboardPanel.this, getRaceName(), /* legIndex */ i));
|
||||
result.add(new LegColumn(LeaderboardPanel.this, getRaceName(), /* legIndex */ i, stringConstants));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -216,6 +217,7 @@ public class LeaderboardPanel extends FormPanel {
|
||||
private class TotalsColumn extends SortableColumn<LeaderboardRowDAO, String> {
|
||||
protected TotalsColumn() {
|
||||
super(new TextCell());
|
||||
setHorizontalAlignment(ALIGN_RIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -271,6 +273,7 @@ public class LeaderboardPanel extends FormPanel {
|
||||
private class RankColumn extends SortableColumn<LeaderboardRowDAO, String> {
|
||||
public RankColumn() {
|
||||
super(new TextCell());
|
||||
setHorizontalAlignment(ALIGN_RIGHT);
|
||||
setSortable(true);
|
||||
}
|
||||
|
||||
|
||||
+29
-6
@@ -22,6 +22,7 @@ import com.sap.sailing.gwt.ui.shared.LegEntryDAO;
|
||||
public class LegColumn extends ExpandableSortableColumn<String> {
|
||||
private final String raceName;
|
||||
private final int legIndex;
|
||||
private final StringConstants stringConstants;
|
||||
|
||||
private abstract class AbstractLegDetailField<T> implements LegDetailField<T> {
|
||||
public T get(LeaderboardRowDAO row) {
|
||||
@@ -50,10 +51,26 @@ public class LegColumn extends ExpandableSortableColumn<String> {
|
||||
}
|
||||
}
|
||||
|
||||
public LegColumn(LeaderboardPanel leaderboardPanel, String raceName, int legIndex) {
|
||||
private class RankGain implements LegDetailField<Integer> {
|
||||
@Override
|
||||
public Integer get(LeaderboardRowDAO row) {
|
||||
LegEntryDAO legEntry = getLegEntry(row);
|
||||
if (legEntry == null || getLegIndex() == 0) {
|
||||
// no gain/loss for first leg
|
||||
return null;
|
||||
} else {
|
||||
LegEntryDAO previousEntry = getLegEntry(row, getLegIndex()-1);
|
||||
return previousEntry == null ? null : previousEntry.rank - legEntry.rank;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public LegColumn(LeaderboardPanel leaderboardPanel, String raceName, int legIndex, StringConstants stringConstants) {
|
||||
super(leaderboardPanel, /* expandable */ true /* all legs have details */, new TextCell());
|
||||
setHorizontalAlignment(ALIGN_RIGHT);
|
||||
this.raceName = raceName;
|
||||
this.legIndex = legIndex;
|
||||
this.stringConstants = stringConstants;
|
||||
}
|
||||
|
||||
private int getLegIndex() {
|
||||
@@ -65,10 +82,15 @@ public class LegColumn extends ExpandableSortableColumn<String> {
|
||||
}
|
||||
|
||||
private LegEntryDAO getLegEntry(LeaderboardRowDAO row) {
|
||||
int theLegIndex = getLegIndex();
|
||||
return getLegEntry(row, theLegIndex);
|
||||
}
|
||||
|
||||
private LegEntryDAO getLegEntry(LeaderboardRowDAO row, int theLegIndex) {
|
||||
LegEntryDAO legEntry = null;
|
||||
LeaderboardEntryDAO entry = row.fieldsByRaceName.get(getRaceName());
|
||||
if (entry != null && entry.legDetails != null) {
|
||||
legEntry = entry.legDetails.get(getLegIndex());
|
||||
legEntry = entry.legDetails.get(theLegIndex);
|
||||
}
|
||||
return legEntry;
|
||||
}
|
||||
@@ -94,8 +116,8 @@ public class LegColumn extends ExpandableSortableColumn<String> {
|
||||
|
||||
@Override
|
||||
public Header<SafeHtml> getHeader() {
|
||||
return new SortableExpandableColumnHeader(/* title */ "Leg "+(legIndex+1),
|
||||
/* iconURL */ null, getLeaderboardPanel(), this);
|
||||
return new SortableExpandableColumnHeader(/* title */ stringConstants.leg()+" "+(legIndex+1),
|
||||
/* iconURL */ null, getLeaderboardPanel(), this, stringConstants);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,8 +129,9 @@ public class LegColumn extends ExpandableSortableColumn<String> {
|
||||
protected List<SortableColumn<LeaderboardRowDAO, ?>> 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));
|
||||
result.add(new FormattedDoubleLegDetailColumn(stringConstants.distanceInMeters(), new DistanceTraveledInMeters(), 1));
|
||||
result.add(new FormattedDoubleLegDetailColumn(stringConstants.averageSpeedInKnots(), new AverageSpeedOverGroundInKnots(), 2));
|
||||
result.add(new LegDetailColumn<Integer>(stringConstants.rankGain(), new RankGain()));
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
+1
@@ -17,6 +17,7 @@ public class LegDetailColumn<T> extends SortableColumn<LeaderboardRowDAO, String
|
||||
|
||||
protected LegDetailColumn(String title, LegDetailField<T> field) {
|
||||
super(new TextCell());
|
||||
setHorizontalAlignment(ALIGN_RIGHT);
|
||||
this.title = title;
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
+5
-4
@@ -41,12 +41,12 @@ public class SortableExpandableColumnHeader extends Header<SafeHtml> {
|
||||
}
|
||||
|
||||
public SortableExpandableColumnHeader(String title, String iconURL, LeaderboardPanel leaderboardPanel,
|
||||
ExpandableSortableColumn<?> column) {
|
||||
super(constructCell(title, iconURL, column.isExpansionEnabled(), leaderboardPanel, column));
|
||||
ExpandableSortableColumn<?> column, StringConstants stringConstants) {
|
||||
super(constructCell(title, iconURL, column.isExpansionEnabled(), leaderboardPanel, column, stringConstants));
|
||||
}
|
||||
|
||||
private static <T> Cell<SafeHtml> constructCell(final String title, final String iconURL, boolean isExpansionEnabled,
|
||||
final LeaderboardPanel leaderboardPanel, final ExpandableSortableColumn<?> column) {
|
||||
final LeaderboardPanel leaderboardPanel, final ExpandableSortableColumn<?> column, final StringConstants stringConstants) {
|
||||
final List<HasCell<SafeHtml, ?>> cells = new ArrayList<HasCell<SafeHtml, ?>>(3);
|
||||
// if it's a medal race, add the cell rendering the medal image
|
||||
if (iconURL != null) {
|
||||
@@ -87,7 +87,8 @@ public class SortableExpandableColumnHeader extends Header<SafeHtml> {
|
||||
cells.add(new HasCell<SafeHtml, SafeHtml>() {
|
||||
@Override
|
||||
public Cell<SafeHtml> getCell() {
|
||||
return new ActionCell<SafeHtml>(column.isExpanded() ? "-" : "+", new ExpandCollapseButtonAction(column)) {
|
||||
return new ActionCell<SafeHtml>(column.isExpanded() ? stringConstants.collapse() : stringConstants.expand(),
|
||||
new ExpandCollapseButtonAction(column)) {
|
||||
/**
|
||||
* carry out event logic, hence call the delegate's execute(...) operation, then stop
|
||||
* propagation to avoid the column being sorted when the expand button is pressed
|
||||
|
||||
+6
@@ -59,4 +59,10 @@ public interface StringConstants extends Constants {
|
||||
String renameRace();
|
||||
String openSelectedLeaderboard();
|
||||
String rank();
|
||||
String collapse();
|
||||
String expand();
|
||||
String leg();
|
||||
String distanceInMeters();
|
||||
String averageSpeedInKnots();
|
||||
String rankGain();
|
||||
}
|
||||
+7
-1
@@ -53,4 +53,10 @@ ok=OK
|
||||
medalRace=Medal Race
|
||||
renameRace=Rename Race
|
||||
openSelectedLeaderboard=Open Selected Leaderboard
|
||||
rank=Rank
|
||||
rank=Rank
|
||||
collapse=-
|
||||
expand=+
|
||||
leg=Leg
|
||||
distanceInMeters=Distance/m
|
||||
averageSpeedInKnots=Average Speed/kts
|
||||
rankGain=Rank Gain
|
||||
Reference in new issue
Block a user