From 0955c2fd648b00a41525fd07c66f38a2b59ec80a Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Mon, 21 Nov 2011 21:11:33 +0100 Subject: [PATCH] fixed bug 69 (When untracking a race with race column expanded, at least the default leaderboard messes up) --- .../test/FetchTracksAndStoreLocallyTest.java | 0 .../domain/tracking/impl/TrackedRaceImpl.java | 2 +- .../ui/client/ExpandableSortableColumn.java | 6 +- .../gwt/ui/client/LeaderboardPanel.java | 50 ++++-- .../sailing/gwt/ui/shared/LeaderboardDAO.java | 169 ++++++++---------- .../rpcPolicyManifest/manifest.txt | 1 - .../SailingServer (Proxy).launch | 2 +- 7 files changed, 108 insertions(+), 122 deletions(-) mode change 100644 => 100755 java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/FetchTracksAndStoreLocallyTest.java diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/FetchTracksAndStoreLocallyTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/FetchTracksAndStoreLocallyTest.java old mode 100644 new mode 100755 diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java index 0c709339017..450d5274013 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java @@ -199,7 +199,7 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener { @Override public boolean hasStarted(TimePoint at) { - return getStart().compareTo(at) <= 0; + return getStart() != null && getStart().compareTo(at) <= 0; } protected void setStartTimeReceived(TimePoint start) { diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/ExpandableSortableColumn.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/ExpandableSortableColumn.java index 46ea3eb345f..453e0c5a237 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/ExpandableSortableColumn.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/ExpandableSortableColumn.java @@ -168,11 +168,7 @@ public abstract class ExpandableSortableColumn extends SortableColumn table = getLeaderboardPanel().getLeaderboardTable(); if (isExpanded()) { for (SortableColumn column : getAllVisibleChildren()) { - int columnIndex = table.getColumnIndex(column); - // remove only the children currently displayed - if (columnIndex >= 0) { - getLeaderboardPanel().removeColumn(columnIndex); - } + getLeaderboardPanel().removeColumn(column); // removes only the children currently displayed } // important: toggle expanded state after asking for all visible children setExpanded(!isExpanded()); diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/LeaderboardPanel.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/LeaderboardPanel.java index 427df3d051d..1f09ae6f78c 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/LeaderboardPanel.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/LeaderboardPanel.java @@ -480,9 +480,18 @@ public class LeaderboardPanel extends FormPanel implements TimeListener, PlaySta // removing the columns from the table // is based on column identity int legCount = getLeaderboard().getLegCount(getRaceName()); - for (int i = 0; i < legCount; i++) { - LegColumn legColumn = getLegColumn(i); - result.add(legColumn); + if (legCount != -1) { + for (int i = 0; i < legCount; i++) { + LegColumn legColumn = getLegColumn(i); + result.add(legColumn); + } + } else { + // the race is no longer part of the LeaderboardDAO; consider the non-null legs in legColumns: + for (LegColumn legColumn : legColumns) { + if (legColumn != null) { + result.add(legColumn); + } + } } } return result; @@ -836,11 +845,28 @@ public class LeaderboardPanel extends FormPanel implements TimeListener, PlaySta * table} and fixes the column styles again (see {@link #addColumnStyles(int)}). */ protected void removeColumn(int columnIndex) { + Column c = getLeaderboardTable().getColumn(columnIndex); + if (c instanceof ExpandableSortableColumn) { + ExpandableSortableColumn expandableColumn = (ExpandableSortableColumn) c; + if (expandableColumn.isExpanded()) { + // remove expanded child columns from the leaderboard... + expandableColumn.toggleExpansion(); + // them remember that column c was expanded: + expandableColumn.setExpanded(true); + } + } removeColumnStyles(/* startColumn */columnIndex); getLeaderboardTable().removeColumn(columnIndex); addColumnStyles(/* startColumn */columnIndex); } + protected void removeColumn(Column c) { + int columnIndex = getLeaderboardTable().getColumnIndex(c); + if (columnIndex != -1) { + removeColumn(columnIndex); + } + } + private void loadCompleteLeaderboard(Date date) { getSailingService().getLeaderboardByName(getLeaderboardName(), date, /* namesOfRacesForWhichToLoadLegDetails */getNamesOfExpandedRaces(), new AsyncCallback() { @@ -988,14 +1014,6 @@ public class LeaderboardPanel extends FormPanel implements TimeListener, PlaySta } } - // protected RaceColumn createRaceColumn(Map.Entry> raceNameAndMedalRaceAndTracked) { - // return new TextRaceColumn(raceNameAndMedalRaceAndTracked.getKey(), - // raceNameAndMedalRaceAndTracked.getValue().getA(), - // raceNameAndMedalRaceAndTracked.getValue().getB(), - // RACE_COLUMN_HEADER_STYLE, RACE_COLUMN_STYLE); - // } - protected RaceColumn createRaceColumn(String raceName, boolean isMedalRace, boolean isTracked) { return new TextRaceColumn(raceName, isMedalRace, isTracked, RACE_COLUMN_HEADER_STYLE, RACE_COLUMN_STYLE); } @@ -1004,18 +1022,16 @@ public class LeaderboardPanel extends FormPanel implements TimeListener, PlaySta List> columnsToRemove = new ArrayList>(); for (int i = 0; i < getLeaderboardTable().getColumnCount(); i++) { Column c = getLeaderboardTable().getColumn(i); - /* - * if (c instanceof RaceColumn && (leaderboard == null || - * !leaderboard.raceNamesAndMedalRaceAndTracked.keySet().contains( ((RaceColumn) c).getRaceName()))) { - * columnsToRemove.add(c); } - */ if (c instanceof RaceColumn && (leaderboard == null || !leaderboard.raceListContains(((RaceColumn) c).getRaceName()))) { columnsToRemove.add(c); } } + // Tricky issue: if the race column is currently expanded, we can't know anymore how many detail columns + // there are because the updated LeaderboardDAO object doesn't contain the race anymore. We have to + // collapse and remove all LegColumns following the RaceColumn for (Column c : columnsToRemove) { - getLeaderboardTable().removeColumn(c); + removeColumn(c); } } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/LeaderboardDAO.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/LeaderboardDAO.java index ddf7d93efc8..36b1cf3fb32 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/LeaderboardDAO.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/LeaderboardDAO.java @@ -20,7 +20,6 @@ import com.google.gwt.user.client.rpc.IsSerializable; public class LeaderboardDAO implements IsSerializable { public String name; public List competitors; - //public LinkedHashMap> raceNamesAndMedalRaceAndTracked; private List raceNames; private Map racesMedalRace; private Map racesTracked; @@ -77,17 +76,11 @@ public class LeaderboardDAO implements IsSerializable { */ public boolean scoredInMedalRace(CompetitorDAO competitor) { LeaderboardRowDAO row = rows.get(competitor); - /* - for (Map.Entry> raceNameAndMedalRace : raceNamesAndMedalRaceAndTracked.entrySet()) { - if (raceNameAndMedalRace.getValue().getA() && row.fieldsByRaceName.get(raceNameAndMedalRace.getKey()).totalPoints > 0) { + for (String race : raceNames) { + if (raceIsMedalRace(race) && row.fieldsByRaceName.get(race).totalPoints > 0) { return true; } } - */ - for (String race : raceNames){ - if (raceIsMedalRace(race) && row.fieldsByRaceName.get(race).totalPoints > 0) - return true; - } return false; } @@ -103,35 +96,45 @@ public class LeaderboardDAO implements IsSerializable { @Override public int compare(LeaderboardRowDAO o1, LeaderboardRowDAO o2) { int result; - if (scoredInMedalRace(o1.competitor)) { - if (scoredInMedalRace(o2.competitor)) { - // both scored in medal race - result = getTotalPoints(o1) - getTotalPoints(o2); - // in case of tie, medal race points decide: - if (result == 0) { - result = getMedalRaceScore(o1.competitor) - getMedalRaceScore(o2.competitor); - } - } else { - // only o1 scored in medal race, so o1 scores better = "less" - result = -1; - } + if (o1 == null && o2 == null) { + result = 0; + } else if (o1 == null) { + result = -1; + } else if (o2 == null) { + result = 1; } else { - if (scoredInMedalRace(o2.competitor)) { - // only o2 scored in medal race, so o2 scores better, o1 scores worse = "greater" - result = 1; - } else { - // neither one scored in any medal race - result = getTotalPoints(o1) - getTotalPoints(o2); - // Now if both have equal points, count races won. - if (result == 0) { - result = getNumberOfRacesWon(o2.competitor) - getNumberOfRacesWon(o1.competitor); + if (scoredInMedalRace(o1.competitor)) { + if (scoredInMedalRace(o2.competitor)) { + // both scored in medal race + result = getTotalPoints(o1) - getTotalPoints(o2); + // in case of tie, medal race points decide: + if (result == 0) { + result = getMedalRaceScore(o1.competitor) - getMedalRaceScore(o2.competitor); + } + } else { + // only o1 scored in medal race, so o1 scores better = "less" + result = -1; } - // If number of races won is still equal, use rank in last race where at least one of the two competitors was assigned a score - if (result == 0) { - String nameOfLastRaceSoFar = getNameOfLastRaceSoFar(o1.competitor, o2.competitor); - int netPoints1 = getNetPoints(o1.competitor, nameOfLastRaceSoFar); - int netPoints2 = getNetPoints(o2.competitor, nameOfLastRaceSoFar); - result = netPoints1==0 ? netPoints2==0 ? 0 : -1 : netPoints2==0 ? 1 : netPoints1-netPoints2; + } else { + if (scoredInMedalRace(o2.competitor)) { + // only o2 scored in medal race, so o2 scores better, o1 scores worse = "greater" + result = 1; + } else { + // neither one scored in any medal race + result = getTotalPoints(o1) - getTotalPoints(o2); + // Now if both have equal points, count races won. + if (result == 0) { + result = getNumberOfRacesWon(o2.competitor) - getNumberOfRacesWon(o1.competitor); + } + // If number of races won is still equal, use rank in last race where at least one of the two + // competitors was assigned a score + if (result == 0) { + String nameOfLastRaceSoFar = getNameOfLastRaceSoFar(o1.competitor, o2.competitor); + int netPoints1 = getNetPoints(o1.competitor, nameOfLastRaceSoFar); + int netPoints2 = getNetPoints(o2.competitor, nameOfLastRaceSoFar); + result = netPoints1 == 0 ? netPoints2 == 0 ? 0 : -1 : netPoints2 == 0 ? 1 : netPoints1 + - netPoints2; + } } } } @@ -186,17 +189,11 @@ public class LeaderboardDAO implements IsSerializable { private int getMedalRaceScore(CompetitorDAO competitor) { int result = 0; LeaderboardRowDAO row = rows.get(competitor); - /* - for (Map.Entry> raceNameAndMedalRace : raceNamesAndMedalRaceAndTracked.entrySet()) { - if (raceNameAndMedalRace.getValue().getA() && row.fieldsByRaceName.containsKey(raceNameAndMedalRace.getKey())) { - result += row.fieldsByRaceName.get(raceNameAndMedalRace.getKey()).netPoints; + for (String race : raceNames) { + if (raceIsMedalRace(race) && row.fieldsByRaceName.containsKey(race)) { + result += row.fieldsByRaceName.get(race).netPoints; } } - */ - for (String race : raceNames){ - if (raceIsMedalRace(race) && row.fieldsByRaceName.containsKey(race)) - result += row.fieldsByRaceName.get(race).netPoints; - } return result; } @@ -218,21 +215,8 @@ public class LeaderboardDAO implements IsSerializable { */ private String getNameOfLastRaceSoFar(CompetitorDAO c1, CompetitorDAO c2) { String nameOfLastRaceSoFar = null; - /* - for (String raceName : raceNamesAndMedalRaceAndTracked.keySet()) { + for (String race : raceNames) { for (LeaderboardRowDAO row : rows.values()) { - if (row.competitor.equals(c1) || row.competitor.equals(c2)) { - LeaderboardEntryDAO leaderboardEntryDAO = row.fieldsByRaceName.get(raceName); - if (leaderboardEntryDAO != null && leaderboardEntryDAO.netPoints != 0) { - nameOfLastRaceSoFar = raceName; - break; - } - } - } - } - */ - for (String race : raceNames){ - for (LeaderboardRowDAO row : rows.values()) { if (row.competitor.equals(c1) || row.competitor.equals(c2)) { LeaderboardEntryDAO leaderboardEntryDAO = row.fieldsByRaceName.get(race); if (leaderboardEntryDAO != null && leaderboardEntryDAO.netPoints != 0) { @@ -249,20 +233,12 @@ public class LeaderboardDAO implements IsSerializable { int result = 0; LeaderboardRowDAO row = rows.get(competitor); if (row != null) { - /* - for (String raceName : raceNamesAndMedalRaceAndTracked.keySet()) { - LeaderboardEntryDAO field = row.fieldsByRaceName.get(raceName); + for (String race : raceNames) { + LeaderboardEntryDAO field = row.fieldsByRaceName.get(race); if (field != null && field.netPoints == 1) { result++; } } - */ - for (String race : raceNames){ - LeaderboardEntryDAO field = row.fieldsByRaceName.get(race); - if (field != null && field.netPoints == 1) { - result++; - } - } } return result; } @@ -320,38 +296,37 @@ public class LeaderboardDAO implements IsSerializable { return raceNames; } - public boolean raceListContains(String raceName){ - if (getRaceIdByName(raceName) == -1) - return false; - return true; + public boolean raceListContains(String raceName) { + return getRaceIdByName(raceName) != -1; } - public int getRaceIdByName(String raceName){ - for (int i = 0; i < raceNames.size(); i++) { - if(raceNames.get(i).equals(raceName)) - return i; - } - return -1; + public int getRaceIdByName(String raceName) { + for (int i = 0; i < raceNames.size(); i++) { + if (raceNames.get(i).equals(raceName)) { + return i; + } + } + return -1; } - - public void moveRaceUp(String raceName){ - int index = getRaceIdByName(raceName); - index--; - if (index >= 0){ - raceNames.remove(index+1); - raceNames.add(index, raceName); - } + + public void moveRaceUp(String raceName) { + int index = getRaceIdByName(raceName); + index--; + if (index >= 0) { + raceNames.remove(index + 1); + raceNames.add(index, raceName); + } } - - public void moveRaceDown(String raceName){ - int index = getRaceIdByName(raceName); - if (index == -1) - return; - index++; - if (index < raceNames.size()){ - raceNames.remove(index-1); - raceNames.add(index, raceName); - } + + public void moveRaceDown(String raceName) { + int index = getRaceIdByName(raceName); + if (index != -1) { + index++; + if (index < raceNames.size()) { + raceNames.remove(index - 1); + raceNames.add(index, raceName); + } + } } public void setIsMedalRace(String raceName, boolean isMedalRace){ diff --git a/java/com.sap.sailing.gwt.ui/war/WEB-INF/deploy/com.sap.sailing.gwt.ui.AdminConsole/rpcPolicyManifest/manifest.txt b/java/com.sap.sailing.gwt.ui/war/WEB-INF/deploy/com.sap.sailing.gwt.ui.AdminConsole/rpcPolicyManifest/manifest.txt index 5f6e1521bf7..7fce3ee6e43 100755 --- a/java/com.sap.sailing.gwt.ui/war/WEB-INF/deploy/com.sap.sailing.gwt.ui.AdminConsole/rpcPolicyManifest/manifest.txt +++ b/java/com.sap.sailing.gwt.ui/war/WEB-INF/deploy/com.sap.sailing.gwt.ui.AdminConsole/rpcPolicyManifest/manifest.txt @@ -1,3 +1,2 @@ # Module com.sap.sailing.gwt.ui.AdminConsole # RPC service class, partial path of RPC policy file -com.sap.sailing.gwt.ui.client.SailingService, 0148445E03B6030B90BCBC2A759DFD15.gwt.rpc diff --git a/java/com.sap.sailing.server/SailingServer (Proxy).launch b/java/com.sap.sailing.server/SailingServer (Proxy).launch index c83c7b34a47..160c603f50b 100755 --- a/java/com.sap.sailing.server/SailingServer (Proxy).launch +++ b/java/com.sap.sailing.server/SailingServer (Proxy).launch @@ -24,5 +24,5 @@ - +