implemented rank gain/loss column with icons

This commit is contained in:
Axel Uhl committed 2011-09-13 16:52:45 +02:00
1 parent e8eb472888
commit a4dfa31cb2
7 files changed
+80 -17

No files matched your search

@@ -1,15 +1,16 @@
package com.sap.sailing.gwt.ui.client;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.i18n.client.NumberFormat;
import com.sap.sailing.gwt.ui.shared.LeaderboardRowDAO;
public class FormattedDoubleLegDetailColumn extends LegDetailColumn<Double> {
public class FormattedDoubleLegDetailColumn extends LegDetailColumn<Double, String> {
private final NumberFormat formatter;
public FormattedDoubleLegDetailColumn(String title,
com.sap.sailing.gwt.ui.client.LegDetailColumn.LegDetailField<Double> field,
int decimals) {
super(title, field);
super(title, field, new TextCell());
StringBuilder patternBuilder = new StringBuilder("0");
if (decimals > 0) {
patternBuilder.append('.');
@@ -60,7 +60,7 @@ public class LegColumn extends ExpandableSortableColumn<String> {
return null;
} else {
LegEntryDAO previousEntry = getLegEntry(row, getLegIndex()-1);
return previousEntry == null ? null : previousEntry.rank - legEntry.rank;
return previousEntry == null ? null : legEntry.rank - previousEntry.rank;
}
}
}
@@ -131,7 +131,7 @@ public class LegColumn extends ExpandableSortableColumn<String> {
try {
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()));
result.add(new RankGainColumn(stringConstants.rankGain(), new RankGain()));
return result;
} catch (Exception e) {
throw new RuntimeException(e);
@@ -2,21 +2,21 @@ package com.sap.sailing.gwt.ui.client;
import java.util.Comparator;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.cell.client.Cell;
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> {
public abstract class LegDetailColumn<FieldType, RenderingType> extends SortableColumn<LeaderboardRowDAO, RenderingType> {
private final String title;
private final LegDetailField<T> field;
private final LegDetailField<FieldType> field;
public interface LegDetailField<T> {
T get(LeaderboardRowDAO row);
}
protected LegDetailColumn(String title, LegDetailField<T> field) {
super(new TextCell());
protected LegDetailColumn(String title, LegDetailField<FieldType> field, Cell<RenderingType> cell) {
super(cell);
setHorizontalAlignment(ALIGN_RIGHT);
this.title = title;
this.field = field;
@@ -26,7 +26,7 @@ public class LegDetailColumn<T> extends SortableColumn<LeaderboardRowDAO, String
return title;
}
protected LegDetailField<T> getField() {
protected LegDetailField<FieldType> getField() {
return field;
}
@@ -37,8 +37,8 @@ public class LegDetailColumn<T> extends SortableColumn<LeaderboardRowDAO, String
public int compare(LeaderboardRowDAO o1, LeaderboardRowDAO o2) {
try {
@SuppressWarnings("unchecked")
Comparable<T> value1 = (Comparable<T>) field.get(o1);
T value2 = field.get(o2);
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);
} catch (Exception e) {
throw new RuntimeException(e);
@@ -52,9 +52,4 @@ public class LegDetailColumn<T> extends SortableColumn<LeaderboardRowDAO, String
return new TextHeader(title);
}
@Override
public String getValue(LeaderboardRowDAO row) {
T fieldValue = field.get(row);
return fieldValue == null ? "" : fieldValue.toString();
}
}
@@ -0,0 +1,49 @@
package com.sap.sailing.gwt.ui.client;
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.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());
}
@Override
public Integer getValue(LeaderboardRowDAO row) {
return getField().get(row);
}
private static class RankGainCell extends AbstractSafeHtmlCell<Integer> {
public RankGainCell() {
super(new SafeHtmlRenderer<Integer>() {
@Override
public SafeHtml render(Integer rank) {
SafeHtmlBuilder builder = new SafeHtmlBuilder();
render(rank, builder);
return builder.toSafeHtml();
}
@Override
public void render(Integer rankDelta, SafeHtmlBuilder builder) {
if (rankDelta != null) {
if (rankDelta < 0) {
builder.appendHtmlConstant("<img src=\"/images/arrow-gain.png\"/>");
} else if (rankDelta > 0) {
builder.appendHtmlConstant("<img src=\"/images/arrow-loss.png\"/>");
}
builder.append(Math.abs(rankDelta));
}
}
});
}
@Override
protected void render(com.google.gwt.cell.client.Cell.Context context, SafeHtml data, SafeHtmlBuilder sb) {
sb.append(data);
}
}
}
@@ -0,0 +1,18 @@
package com.sap.sailing.gwt.ui.client;
import com.google.gwt.cell.client.TextCell;
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());
}
@Override
public String getValue(LeaderboardRowDAO row) {
FieldType fieldValue = getField().get(row);
return fieldValue == null ? "" : fieldValue.toString();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 B