mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-10 21:02:40 +00:00
Bug 4980: In LeaderboardPanel we now prefer to show the sail ID instead
of the competitor short name for leaderboards where boats can't change. For leaderboard with changing boats, we still prefer the competitor short name. The same applies to EditableLeaderboardPanel.
This commit is contained in:
1 parent
4899fcc1be
commit
e91c19dff6
6 files changed
+60
-15
No files matched your search
+9
@@ -38,6 +38,15 @@ public interface CompetitorDTO extends Serializable, MappableToDevice {
|
||||
* of the competitor's {@link #getName() name} unless it's empty in which case an empty string is returned.
|
||||
*/
|
||||
String getShortInfo();
|
||||
|
||||
/**
|
||||
* Returns a derived short information about a competitor depending on the information available.
|
||||
* Depending on the given preferSailId we prefer either {@link #getShortName() short name} or the sail ID from {@link CompetitorWithBoatDTO#getBoat() boat}
|
||||
* if available. If both values aren't available, the boat name is used if a boat is available. If all these
|
||||
* attributes have no value, a three-letter acronym is constructed from the name by using the first two and the last letter
|
||||
* of the competitor's {@link #getName() name} unless it's empty in which case an empty string is returned.
|
||||
*/
|
||||
String getShortInfo(boolean preferSailId);
|
||||
|
||||
Color getColor();
|
||||
|
||||
|
||||
+8
-3
@@ -155,6 +155,11 @@ public class CompetitorDTOImpl extends NamedDTO implements CompetitorDTO, Serial
|
||||
|
||||
@Override
|
||||
public String getShortInfo() {
|
||||
return getShortInfo(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getShortInfo(boolean preferSailId) {
|
||||
final String result;
|
||||
if (getShortName() != null && !getShortName().trim().isEmpty()) {
|
||||
result = getShortName();
|
||||
@@ -164,9 +169,9 @@ public class CompetitorDTOImpl extends NamedDTO implements CompetitorDTO, Serial
|
||||
result = null;
|
||||
} else {
|
||||
result = (trimmedName.length()>0?""+trimmedName.charAt(0):"")
|
||||
+ (trimmedName.length()>1?trimmedName.charAt(1):"")
|
||||
+ (trimmedName.length()>0?trimmedName.charAt(trimmedName.length()-1):"");
|
||||
|
||||
+ (trimmedName.length()>1?trimmedName.charAt(1):"")
|
||||
+ (trimmedName.length()>0?trimmedName.charAt(trimmedName.length()-1):"");
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
+5
-3
@@ -59,11 +59,13 @@ public class CompetitorWithBoatDTOImpl extends CompetitorDTOImpl implements Comp
|
||||
public CompetitorWithBoatDTO getCompetitorFromPrevious(LeaderboardDTO previousVersion) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortInfo() {
|
||||
public String getShortInfo(boolean preferSailId) {
|
||||
final String result;
|
||||
if (getShortName() != null && !getShortName().trim().isEmpty()) {
|
||||
if (preferSailId && getBoat() != null && getBoat().getSailId() != null) {
|
||||
result = getBoat().getSailId();
|
||||
} else if (getShortName() != null && !getShortName().trim().isEmpty()) {
|
||||
result = getShortName();
|
||||
} else if (getBoat() != null) {
|
||||
result = getBoat().getSailId() != null ? getBoat().getSailId() : getBoat().getName();
|
||||
|
||||
+6
@@ -52,6 +52,12 @@ public class PreviousCompetitorDTOImpl implements CompetitorDTO {
|
||||
throw new RuntimeException("Internal error. Objects of type "+PreviousCompetitorDTOImpl.class.getName()+
|
||||
" need to be replaced by an object of "+CompetitorWithBoatDTOImpl.class.getName()+" after deserialization");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getShortInfo(boolean preferSailId) {
|
||||
throw new RuntimeException("Internal error. Objects of type "+PreviousCompetitorDTOImpl.class.getName()+
|
||||
" need to be replaced by an object of "+CompetitorWithBoatDTOImpl.class.getName()+" after deserialization");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTwoLetterIsoCountryCode() {
|
||||
|
||||
+18
-7
@@ -875,17 +875,28 @@ public abstract class LeaderboardPanel<LS extends LeaderboardSettings> extends A
|
||||
// an overflow to the next column (see https://bugzilla.sapsailing.com/bugzilla/show_bug.cgi?id=3537)
|
||||
setCellStyleNames(style.getTableresources().cellTableStyle().cellTableSailIdColumn());
|
||||
}
|
||||
|
||||
/**
|
||||
* Depending on the {@link LeaderboardDTO LeaderboardDTO's}
|
||||
* {@link AbstractLeaderboardDTO#canBoatsOfCompetitorsChangePerRace canBoatsOfCompetitorsChangePerRace} flag
|
||||
* there is a different precedence of showing either the sail ID (no changing boats) or the competitor short
|
||||
* name (changing boats). This method handles the resolution of the text to show for a competitor in this column.
|
||||
*/
|
||||
private String getRealTextToShow(CompetitorDTO competitor) {
|
||||
boolean preferSailId = !getLeaderboard().canBoatsOfCompetitorsChangePerRace;
|
||||
return competitor.getShortInfo(preferSailId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InvertibleComparator<T> getComparator() {
|
||||
return new InvertibleComparatorAdapter<T>() {
|
||||
@Override
|
||||
public int compare(T o1, T o2) {
|
||||
return competitorFetcher.getCompetitor(o1).getShortInfo() == null
|
||||
? competitorFetcher.getCompetitor(o2).getShortInfo() == null ? 0 : -1
|
||||
: competitorFetcher.getCompetitor(o2).getShortInfo() == null ? 1
|
||||
: Collator.getInstance().compare(competitorFetcher.getCompetitor(o1).getShortInfo(),
|
||||
competitorFetcher.getCompetitor(o2).getShortInfo());
|
||||
final String competitor1ShortInfo = getRealTextToShow(competitorFetcher.getCompetitor(o1));
|
||||
final String competitor2ShortInfo = getRealTextToShow(competitorFetcher.getCompetitor(o2));
|
||||
return competitor1ShortInfo == null ? competitor2ShortInfo == null ? 0 : -1
|
||||
: competitor2ShortInfo == null ? 1
|
||||
: Collator.getInstance().compare(competitor1ShortInfo, competitor2ShortInfo);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -900,12 +911,12 @@ public abstract class LeaderboardPanel<LS extends LeaderboardSettings> extends A
|
||||
public void render(Context context, T object, SafeHtmlBuilder sb) {
|
||||
final CompetitorDTO competitor = competitorFetcher.getCompetitor(object);
|
||||
LeaderboardPanel.this.renderCompetitorText(competitor, isShowCompetitorShortName(),
|
||||
!isShowCompetitorFullName(), sb, builder -> builder.appendEscaped(competitor.getShortInfo()));
|
||||
!isShowCompetitorFullName(), sb, builder -> builder.appendEscaped(getRealTextToShow(competitor)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(T object) {
|
||||
return competitorFetcher.getCompetitor(object).getShortInfo();
|
||||
return getRealTextToShow(competitorFetcher.getCompetitor(object));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-2
@@ -45,6 +45,7 @@ import com.sap.sailing.domain.common.DetailType;
|
||||
import com.sap.sailing.domain.common.InvertibleComparator;
|
||||
import com.sap.sailing.domain.common.MaxPointsReason;
|
||||
import com.sap.sailing.domain.common.SortingOrder;
|
||||
import com.sap.sailing.domain.common.dto.AbstractLeaderboardDTO;
|
||||
import com.sap.sailing.domain.common.dto.CompetitorDTO;
|
||||
import com.sap.sailing.domain.common.dto.LeaderboardDTO;
|
||||
import com.sap.sailing.domain.common.dto.LeaderboardEntryDTO;
|
||||
@@ -133,12 +134,23 @@ public class EditableLeaderboardPanel extends MultiRaceLeaderboardPanel {
|
||||
super(new TextCell(), SortingOrder.ASCENDING, EditableLeaderboardPanel.this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Depending on the {@link LeaderboardDTO LeaderboardDTO's}
|
||||
* {@link AbstractLeaderboardDTO#canBoatsOfCompetitorsChangePerRace canBoatsOfCompetitorsChangePerRace} flag
|
||||
* there is a different precedence of showing either the sail ID (no changing boats) or the competitor short
|
||||
* name (changing boats). This method handles the resolution of the text to show for a competitor in this column.
|
||||
*/
|
||||
private String getRealTextToShow(CompetitorDTO competitor) {
|
||||
boolean preferSailId = !getLeaderboard().canBoatsOfCompetitorsChangePerRace;
|
||||
return competitor.getShortInfo(preferSailId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InvertibleComparator<CompetitorDTO> getComparator() {
|
||||
return new InvertibleComparatorAdapter<CompetitorDTO>() {
|
||||
@Override
|
||||
public int compare(CompetitorDTO o1, CompetitorDTO o2) {
|
||||
return Collator.getInstance().compare(o1.getShortInfo(), o2.getShortInfo());
|
||||
return Collator.getInstance().compare(getRealTextToShow(o1), getRealTextToShow(o2));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -161,7 +173,7 @@ public class EditableLeaderboardPanel extends MultiRaceLeaderboardPanel {
|
||||
sb.append(FlagImageRenderer.image(flagImageResource.getSafeUri().asString()));
|
||||
sb.appendHtmlConstant(" ");
|
||||
}
|
||||
sb.appendEscaped(object.getShortInfo());
|
||||
sb.appendEscaped(getRealTextToShow(object));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user