Merge branch 'master' into tracapi

This commit is contained in:
Axel Uhl committed 2014-05-21 14:03:06 +02:00
commit 86c8d73274
5 files changed
+85 -45

No files matched your search

@@ -49,18 +49,26 @@ public class LeaderboardDTO extends AbstractLeaderboardDTO implements Serializab
*/ */
private boolean higherScoresIsBetter; private boolean higherScoresIsBetter;
/**
* Tells whether this leaderboard has data about overall details. This corresponds with the <code>addOverallDetails</code> request parameter
* for a leaderboard DTO computation.
*/
private boolean hasOverallDetails;
LeaderboardDTO() {} // for serialization LeaderboardDTO() {} // for serialization
/** /**
* @param uuidGenerator used to provide the {@link #id ID} for this object (see also {@link #getId()}) and for any clones produced * @param uuidGenerator used to provide the {@link #id ID} for this object (see also {@link #getId()}) and for any clones produced
* from it by the {@link #clone()} operation. * from it by the {@link #clone()} operation.
* @param hasOverallDetails TODO
*/ */
public LeaderboardDTO(Date timePointOfLastCorrectionsValidity, String comment, boolean higherScoreIsBetter, UUIDGenerator uuidGenerator) { public LeaderboardDTO(Date timePointOfLastCorrectionsValidity, String comment, boolean higherScoreIsBetter, UUIDGenerator uuidGenerator, boolean hasOverallDetails) {
initCollections(); initCollections();
id = uuidGenerator.generateRandomUUID(); id = uuidGenerator.generateRandomUUID();
this.timePointOfLastCorrectionsValidity = timePointOfLastCorrectionsValidity; this.timePointOfLastCorrectionsValidity = timePointOfLastCorrectionsValidity;
this.comment = comment; this.comment = comment;
this.higherScoresIsBetter = higherScoreIsBetter; this.higherScoresIsBetter = higherScoreIsBetter;
this.hasOverallDetails = hasOverallDetails;
} }
private void initCollections() { private void initCollections() {
@@ -165,4 +173,12 @@ public class LeaderboardDTO extends AbstractLeaderboardDTO implements Serializab
public void setComment(String comment) { public void setComment(String comment) {
this.comment = comment; this.comment = comment;
} }
/**
* Tells whether this leaderboard has data about overall details. This corresponds with the <code>addOverallDetails</code> request parameter
* for a leaderboard DTO computation.
*/
public boolean hasOverallDetails() {
return hasOverallDetails;
}
} }
@@ -1109,7 +1109,7 @@ public abstract class AbstractSimpleLeaderboardImpl implements Leaderboard, Race
final LeaderboardDTO result = new LeaderboardDTO(this.getScoreCorrection().getTimePointOfLastCorrectionsValidity() == null ? null final LeaderboardDTO result = new LeaderboardDTO(this.getScoreCorrection().getTimePointOfLastCorrectionsValidity() == null ? null
: this.getScoreCorrection().getTimePointOfLastCorrectionsValidity().asDate(), : this.getScoreCorrection().getTimePointOfLastCorrectionsValidity().asDate(),
this.getScoreCorrection() == null ? null : this.getScoreCorrection().getComment(), this this.getScoreCorrection() == null ? null : this.getScoreCorrection().getComment(), this
.getScoringScheme().isHigherBetter(), new UUIDGenerator()); .getScoringScheme().isHigherBetter(), new UUIDGenerator(), addOverallDetails);
result.competitors = new ArrayList<CompetitorDTO>(); result.competitors = new ArrayList<CompetitorDTO>();
result.name = this.getName(); result.name = this.getName();
result.competitorDisplayNames = new HashMap<CompetitorDTO, String>(); result.competitorDisplayNames = new HashMap<CompetitorDTO, String>();
@@ -60,7 +60,7 @@ public class TestColumnSwapping {
public String generateRandomUUID() { public String generateRandomUUID() {
return UUID.randomUUID().toString(); return UUID.randomUUID().toString();
} }
}); }, /* hasOverallDetails */ false);
leaderboardOriginalDTO.addRace("Race1", /* explicitFactor */ null, 2., DEFAULT_FLEET, true, null, null); leaderboardOriginalDTO.addRace("Race1", /* explicitFactor */ null, 2., DEFAULT_FLEET, true, null, null);
leaderboardOriginalDTO.addRace("Race3", /* explicitFactor */ null, 2., DEFAULT_FLEET, true, null, null); leaderboardOriginalDTO.addRace("Race3", /* explicitFactor */ null, 2., DEFAULT_FLEET, true, null, null);
leaderboardOriginalDTO.addRace("Race2", /* explicitFactor */ null, 2., DEFAULT_FLEET, true, null, null); leaderboardOriginalDTO.addRace("Race2", /* explicitFactor */ null, 2., DEFAULT_FLEET, true, null, null);
@@ -123,7 +123,7 @@ public class TestColumnSwapping {
public String generateRandomUUID() { public String generateRandomUUID() {
return UUID.randomUUID().toString(); return UUID.randomUUID().toString();
} }
}); }, /* hasOverallDetails */ false);
assertNotNull("Leaderboard != NULL", lb); assertNotNull("Leaderboard != NULL", lb);
lb.addRace("1", /* explicitFactor */ null, 1., DEFAULT_FLEET, false, null, null); lb.addRace("1", /* explicitFactor */ null, 1., DEFAULT_FLEET, false, null, null);
lb.addRace("2", /* explicitFactor */ null, 1., DEFAULT_FLEET, false, null, null); lb.addRace("2", /* explicitFactor */ null, 1., DEFAULT_FLEET, false, null, null);
@@ -148,6 +148,7 @@ public abstract class ExpandableSortableColumn<C> extends SortableColumn<Leaderb
*/ */
public void toggleExpansion() { public void toggleExpansion() {
if (isExpansionEnabled()) { if (isExpansionEnabled()) {
final boolean oldBusyState = getLeaderboardPanel().getBusyIndicator().isBusy();
getLeaderboardPanel().getBusyIndicator().setBusy(true); getLeaderboardPanel().getBusyIndicator().setBusy(true);
setTogglingInProcess(true); setTogglingInProcess(true);
final CellTable<LeaderboardRowDTO> table = getLeaderboardPanel().getLeaderboardTable(); final CellTable<LeaderboardRowDTO> table = getLeaderboardPanel().getLeaderboardTable();
@@ -175,7 +176,7 @@ public abstract class ExpandableSortableColumn<C> extends SortableColumn<Leaderb
} }
getLeaderboardPanel().getLeaderboardTable().redraw(); getLeaderboardPanel().getLeaderboardTable().redraw();
} }
getLeaderboardPanel().getBusyIndicator().setBusy(false); getLeaderboardPanel().getBusyIndicator().setBusy(oldBusyState);
setTogglingInProcess(false); setTogglingInProcess(false);
} }
}); });
@@ -335,12 +335,17 @@ public class LeaderboardPanel extends SimplePanel implements TimeListener, PlayS
return resources.settingsIcon(); return resources.settingsIcon();
} }
public void updateSettings(LeaderboardSettings newSettings) { public void updateSettings(final LeaderboardSettings newSettings) {
boolean oldShallAddOverallDetails = shallAddOverallDetails();
if (newSettings.getOverallDetailsToShow() != null) {
selectedOverallDetailColumns.clear();
selectedOverallDetailColumns.addAll(newSettings.getOverallDetailsToShow());
}
if (!newSettings.isUpdateUponPlayStateChange() || !currentlyHandlingPlayStateChange) { if (!newSettings.isUpdateUponPlayStateChange() || !currentlyHandlingPlayStateChange) {
settingsUpdatedExplicitly = true; settingsUpdatedExplicitly = true;
} }
setShowAddedScores(newSettings.isShowAddedScores()); setShowAddedScores(newSettings.isShowAddedScores());
List<ExpandableSortableColumn<?>> columnsToExpandAgain = new ArrayList<ExpandableSortableColumn<?>>(); final List<ExpandableSortableColumn<?>> columnsToExpandAgain = new ArrayList<ExpandableSortableColumn<?>>();
for (int i = 0; i < getLeaderboardTable().getColumnCount(); i++) { for (int i = 0; i < getLeaderboardTable().getColumnCount(); i++) {
Column<LeaderboardRowDTO, ?> c = getLeaderboardTable().getColumn(i); Column<LeaderboardRowDTO, ?> c = getLeaderboardTable().getColumn(i);
if (c instanceof ExpandableSortableColumn<?>) { if (c instanceof ExpandableSortableColumn<?>) {
@@ -366,10 +371,6 @@ public class LeaderboardPanel extends SimplePanel implements TimeListener, PlayS
selectedRaceDetails.clear(); selectedRaceDetails.clear();
selectedRaceDetails.addAll(newSettings.getRaceDetailsToShow()); selectedRaceDetails.addAll(newSettings.getRaceDetailsToShow());
} }
if (newSettings.getOverallDetailsToShow() != null) {
selectedOverallDetailColumns.clear();
selectedOverallDetailColumns.addAll(newSettings.getOverallDetailsToShow());
}
// update strategy for determining the race columns to show; if settings' race columns to show is null, use the // update strategy for determining the race columns to show; if settings' race columns to show is null, use the
// previously selected race columns / number of race columns for the new configuration // previously selected race columns / number of race columns for the new configuration
Iterable<String> oldNamesOfRaceColumnsToShow = null; Iterable<String> oldNamesOfRaceColumnsToShow = null;
@@ -414,26 +415,66 @@ public class LeaderboardPanel extends SimplePanel implements TimeListener, PlayS
setRaceColumnSelectionToLastNStrategy(newSettings.getNumberOfLastRacesToShow()); setRaceColumnSelectionToLastNStrategy(newSettings.getNumberOfLastRacesToShow());
break; break;
} }
setAutoExpandPreSelectedRace(false); // avoid expansion during updateLeaderboard(...); will expand later if it
// was expanded before final boolean oldBusyState = getBusyIndicator().isBusy();
// update leaderboard after settings panel column selection change getBusyIndicator().setBusy(true);
updateLeaderboard(leaderboard); Runnable doWhenNecessaryDetailHasBeenLoaded = new Runnable() {
setAutoExpandPreSelectedRace(newSettings.isAutoExpandPreSelectedRace()); @Override
public void run() {
setAutoExpandPreSelectedRace(false); // avoid expansion during updateLeaderboard(...); will expand later
// if it was expanded before
// update leaderboard after settings panel column selection change
updateLeaderboard(leaderboard);
setAutoExpandPreSelectedRace(newSettings.isAutoExpandPreSelectedRace());
if (newSettings.getDelayBetweenAutoAdvancesInMilliseconds() != null) { if (newSettings.getDelayBetweenAutoAdvancesInMilliseconds() != null) {
timer.setRefreshInterval(newSettings.getDelayBetweenAutoAdvancesInMilliseconds()); timer.setRefreshInterval(newSettings.getDelayBetweenAutoAdvancesInMilliseconds());
} }
for (ExpandableSortableColumn<?> expandableSortableColumn : columnsToExpandAgain) { for (ExpandableSortableColumn<?> expandableSortableColumn : columnsToExpandAgain) {
expandableSortableColumn.toggleExpansion(); expandableSortableColumn.toggleExpansion();
} }
if (newSettings.getNameOfRaceToSort() != null) { if (newSettings.getNameOfRaceToSort() != null) {
final RaceColumn<?> raceColumnByRaceName = getRaceColumnByRaceName(newSettings.getNameOfRaceToSort()); final RaceColumn<?> raceColumnByRaceName = getRaceColumnByRaceName(newSettings
if (raceColumnByRaceName != null) { .getNameOfRaceToSort());
getLeaderboardTable().sortColumn(raceColumnByRaceName, /* ascending */true); if (raceColumnByRaceName != null) {
getLeaderboardTable().sortColumn(raceColumnByRaceName, /* ascending */true);
}
}
getBusyIndicator().setBusy(oldBusyState);
} }
};
if (oldShallAddOverallDetails == shallAddOverallDetails() || oldShallAddOverallDetails || getLeaderboard().hasOverallDetails()) {
doWhenNecessaryDetailHasBeenLoaded.run();
} else { // meaning that now the details need to be loaded from the server
updateLeaderboardAndRun(doWhenNecessaryDetailHasBeenLoaded);
} }
} }
/**
* @param callWhenExpansionDataIsLoaded
*/
private void updateLeaderboardAndRun(final Runnable callWhenExpansionDataIsLoaded) {
final LeaderboardDTO previousLeaderboard = getLeaderboard();
getSailingService().getLeaderboardByName(getLeaderboardName(),
timer.getPlayMode() == PlayModes.Live ? null : getLeaderboardDisplayDate(),
/* namesOfRacesForWhichToLoadLegDetails */getNamesOfExpandedRaces(),
shallAddOverallDetails(), previousLeaderboard.getId(), new MarkedAsyncCallback<IncrementalOrFullLeaderboardDTO>(
new AsyncCallback<IncrementalOrFullLeaderboardDTO>() {
@Override
public void onSuccess(IncrementalOrFullLeaderboardDTO result) {
updateLeaderboard(result.getLeaderboardDTO(previousLeaderboard));
callWhenExpansionDataIsLoaded.run();
}
@Override
public void onFailure(Throwable caught) {
getErrorReporter().reportError(
stringMessages.errorTryingToObtainLeaderboardContents(caught.getMessage()),
true /* silentMode */);
}
}));
}
private void setRaceColumnSelectionToLastNStrategy(final Integer numberOfLastRacesToShow) { private void setRaceColumnSelectionToLastNStrategy(final Integer numberOfLastRacesToShow) {
raceColumnSelection = new LastNRacesColumnSelection(numberOfLastRacesToShow, getRaceTimesInfoProvider()); raceColumnSelection = new LastNRacesColumnSelection(numberOfLastRacesToShow, getRaceTimesInfoProvider());
if (timer.getPlayState() != Timer.PlayStates.Playing) { if (timer.getPlayState() != Timer.PlayStates.Playing) {
@@ -788,25 +829,7 @@ public class LeaderboardPanel extends SimplePanel implements TimeListener, PlayS
if (getLeaderboard().getLegCount(getRaceColumnName()) != -1) { if (getLeaderboard().getLegCount(getRaceColumnName()) != -1) {
callWhenExpansionDataIsLoaded.run(); callWhenExpansionDataIsLoaded.run();
} else { } else {
final LeaderboardDTO previousLeaderboard = getLeaderboard(); updateLeaderboardAndRun(callWhenExpansionDataIsLoaded);
getSailingService().getLeaderboardByName(getLeaderboardName(),
timer.getPlayMode() == PlayModes.Live ? null : getLeaderboardDisplayDate(),
/* namesOfRacesForWhichToLoadLegDetails */getNamesOfExpandedRaces(),
shallAddOverallDetails(), previousLeaderboard.getId(), new MarkedAsyncCallback<IncrementalOrFullLeaderboardDTO>(
new AsyncCallback<IncrementalOrFullLeaderboardDTO>() {
@Override
public void onSuccess(IncrementalOrFullLeaderboardDTO result) {
updateLeaderboard(result.getLeaderboardDTO(previousLeaderboard));
callWhenExpansionDataIsLoaded.run();
}
@Override
public void onFailure(Throwable caught) {
getErrorReporter().reportError(
stringMessages.errorTryingToObtainLeaderboardContents(caught.getMessage()),
true /* silentMode */);
}
}));
} }
} }