diff --git a/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/CompetitorDTO.java b/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/CompetitorDTO.java index a62de9e107f..8259b035046 100644 --- a/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/CompetitorDTO.java +++ b/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/CompetitorDTO.java @@ -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(); diff --git a/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/CompetitorDTOImpl.java b/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/CompetitorDTOImpl.java index 7c641c44377..0a5a1dd2bd1 100755 --- a/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/CompetitorDTOImpl.java +++ b/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/CompetitorDTOImpl.java @@ -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; diff --git a/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/CompetitorWithBoatDTOImpl.java b/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/CompetitorWithBoatDTOImpl.java index d51e2cc723d..8cc19cf4ad3 100644 --- a/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/CompetitorWithBoatDTOImpl.java +++ b/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/CompetitorWithBoatDTOImpl.java @@ -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(); diff --git a/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/PreviousCompetitorDTOImpl.java b/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/PreviousCompetitorDTOImpl.java index 367ab2102cf..b0c4771c0aa 100755 --- a/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/PreviousCompetitorDTOImpl.java +++ b/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/PreviousCompetitorDTOImpl.java @@ -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() { diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboard/LeaderboardPanel.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboard/LeaderboardPanel.java index d91b72d7191..43664b8b530 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboard/LeaderboardPanel.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboard/LeaderboardPanel.java @@ -875,17 +875,28 @@ public abstract class LeaderboardPanel 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 getComparator() { return new InvertibleComparatorAdapter() { @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 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)); } } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboardedit/EditableLeaderboardPanel.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboardedit/EditableLeaderboardPanel.java index 2e450a867cd..5788cac4d9e 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboardedit/EditableLeaderboardPanel.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboardedit/EditableLeaderboardPanel.java @@ -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 getComparator() { return new InvertibleComparatorAdapter() { @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