implementing the busy state as a counter in LeaderboardPanel; see bug 3855, comment #5

Change-Id: Ife9d96e93d2b7b82391ab798f9bc01934ba483b6
This commit is contained in:
Axel Uhl committed 2016-08-09 18:40:25 +02:00
1 parent 74e6bcdefd
commit c505faa759
8 files changed
+69 -48

No files matched your search

@@ -225,7 +225,7 @@ public class OldLeaderboard extends Composite implements BusyStateChangeListener
@Override
public void onBusyStateChange(boolean busyState) {
busyIndicator.setBusy(busyState);
if(delegate != null) {
if (delegate != null) {
delegate.setBusyState(busyState);
}
}
@@ -190,7 +190,7 @@ public abstract class ExpandableSortableColumn<C> extends LeaderboardSortableCol
queuedToggleRequests.add(expand);
} else {
final boolean oldBusyState = getLeaderboardPanel().isBusy();
getLeaderboardPanel().setBusyState(true);
getLeaderboardPanel().addBusyTask();
setTogglingInProcess(true);
final CellTable<LeaderboardRowDTO> table = getLeaderboardPanel().getLeaderboardTable();
if (table == null) {
@@ -248,7 +248,7 @@ public abstract class ExpandableSortableColumn<C> extends LeaderboardSortableCol
* @param busyState the busy state value to set
*/
private void finishCurrentToggling(boolean busyState) {
getLeaderboardPanel().setBusyState(busyState);
getLeaderboardPanel().removeBusyTask();
setTogglingInProcess(false);
if (!queuedToggleRequests.isEmpty()) {
changeExpansionState(queuedToggleRequests.remove(0));
@@ -302,6 +302,12 @@ public class LeaderboardPanel extends SimplePanel implements Component<Leaderboa
private ImageResource pauseIcon;
private ImageResource playIcon;
/**
* For a leaderboard, zero or more tasks may be currently busy. The counter keeps track. If it goes
* to {@code 0}, the {@link #busyIndicator} is set to non-busy. If it goes from {@code 0} to {@code 1}
* the {@link #busyIndicator} is set to busy.
*/
private int busyTaskCounter;
private final BusyIndicator busyIndicator;
private final Set<BusyStateChangeListener> busyStateChangeListeners;
@@ -485,8 +491,7 @@ public class LeaderboardPanel extends SimplePanel implements Component<Leaderboa
break;
}
final boolean oldBusyState = isBusy();
setBusyState(true);
addBusyTask();
Runnable doWhenNecessaryDetailHasBeenLoaded = new Runnable() {
@Override
public void run() {
@@ -503,13 +508,12 @@ public class LeaderboardPanel extends SimplePanel implements Component<Leaderboa
expandableSortableColumn.changeExpansionState(/* expand */ true);
}
if (newSettings.getNameOfRaceToSort() != null) {
final RaceColumn<?> raceColumnByRaceName = getRaceColumnByRaceName(newSettings
.getNameOfRaceToSort());
final RaceColumn<?> raceColumnByRaceName = getRaceColumnByRaceName(newSettings.getNameOfRaceToSort());
if (raceColumnByRaceName != null) {
getLeaderboardTable().sortColumn(raceColumnByRaceName, /* ascending */true);
}
}
setBusyState(oldBusyState);
removeBusyTask();
}
};
if (oldShallAddOverallDetails == shallAddOverallDetails() || oldShallAddOverallDetails || getLeaderboard().hasOverallDetails()) {
@@ -1894,7 +1898,7 @@ public class LeaderboardPanel extends SimplePanel implements Component<Leaderboa
mainPanel.setWidget(contentPanel);
this.setTitle(stringMessages.leaderboard());
if (timer.isInitialized()) {
loadCompleteLeaderboard(getLeaderboardDisplayDate());
loadCompleteLeaderboard(/* showProgress */ false);
}
}
@@ -1965,9 +1969,8 @@ public class LeaderboardPanel extends SimplePanel implements Component<Leaderboa
filterClearButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
setBusyState(true);
competitorFilterPanel.clearAllActiveFilters();
timeChanged(new Date(), null);
loadCompleteLeaderboard(/* showProgress */ true);
}
});
filterControlPanel.add(filterClearButton);
@@ -2271,7 +2274,8 @@ public class LeaderboardPanel extends SimplePanel implements Component<Leaderboa
}
}
private void loadCompleteLeaderboard(Date date) {
public void loadCompleteLeaderboard(boolean showProgress) {
final Date date = getLeaderboardDisplayDate();
if (needsDataLoading()) {
GetLeaderboardByNameAction getLeaderboardByNameAction = new GetLeaderboardByNameAction(sailingService,
getLeaderboardName(), useNullAsTimePoint() ? null : date,
@@ -2282,19 +2286,15 @@ public class LeaderboardPanel extends SimplePanel implements Component<Leaderboa
@Override
public void onSuccess(LeaderboardDTO result) {
updateLeaderboard(result);
setBusyState(false);
}
@Override
public void onFailure(Throwable caught) {
setBusyState(false);
getErrorReporter()
.reportError("Error trying to obtain leaderboard contents: " + caught.getMessage(),
true /* silentMode */);
}
});
} else {
setBusyState(false);
}
}
@@ -2303,9 +2303,9 @@ public class LeaderboardPanel extends SimplePanel implements Component<Leaderboa
}
/**
* In {@link PlayModes#Live live mode}, when {@link #loadCompleteLeaderboard(Date) loading the leaderboard contents}, <code>null</code>
* In {@link PlayModes#Live live mode}, when {@link #loadCompleteLeaderboard(boolean) loading the leaderboard contents}, <code>null</code>
* is used as time point. The condition for this is encapsulated in this method so others can find out. For example, when a time change
* is signaled due to local offset / delay adjustments, no additional call to {@link #loadCompleteLeaderboard(Date)} would be required
* is signaled due to local offset / delay adjustments, no additional call to {@link #loadCompleteLeaderboard(boolean)} would be required
* as <code>null</code> will be passed in any case, not being affected by local time offsets.
*/
private boolean useNullAsTimePoint() {
@@ -2450,7 +2450,6 @@ public class LeaderboardPanel extends SimplePanel implements Component<Leaderboa
liveRaceLabel.setVisible(hasLiveRace);
}
informLeaderboardUpdateListenersAboutLeaderboardUpdated(leaderboard);
setBusyState(false);
}
}
@@ -3079,7 +3078,7 @@ public class LeaderboardPanel extends SimplePanel implements Component<Leaderboa
*/
@Override
public void timeChanged(Date newTime, Date oldTime) {
loadCompleteLeaderboard(getLeaderboardDisplayDate());
loadCompleteLeaderboard(/* showProgress */ false);
}
@Override
@@ -3336,8 +3335,7 @@ public class LeaderboardPanel extends SimplePanel implements Component<Leaderboa
return busyIndicator.isBusy();
}
@Override
public void setBusyState(boolean isBusy) {
private void setBusyState(boolean isBusy) {
if (busyIndicator.isBusy() != isBusy) {
busyIndicator.setBusy(isBusy);
for (BusyStateChangeListener listener : busyStateChangeListeners) {
@@ -3345,6 +3343,22 @@ public class LeaderboardPanel extends SimplePanel implements Component<Leaderboa
}
}
}
@Override
public void addBusyTask() {
busyTaskCounter++;
if (busyTaskCounter == 1) {
setBusyState(true);
}
}
@Override
public void removeBusyTask() {
busyTaskCounter--;
if (busyTaskCounter == 0) {
setBusyState(false);
}
}
@Override
public String getId() {
@@ -248,8 +248,7 @@ public class MultiLeaderboardPanel extends AbstractLazyComponent<LeaderboardSett
@Override
public void setVisible(boolean visible) {
super.setVisible(visible);
if(visible) {
if (visible) {
readAndUpdateLeaderboardsOfMetaleaderboard();
} else {
updateSelectedLeaderboard(null, -1);
@@ -258,7 +257,7 @@ public class MultiLeaderboardPanel extends AbstractLazyComponent<LeaderboardSett
@Override
public void timeChanged(Date newTime, Date oldTime) {
if(selectedLeaderboardPanel != null) {
if (selectedLeaderboardPanel != null) {
selectedLeaderboardPanel.timeChanged(newTime, oldTime);
}
}
@@ -275,7 +274,7 @@ public class MultiLeaderboardPanel extends AbstractLazyComponent<LeaderboardSett
@Override
public void setSelectedLeaderboard(LeaderboardPanel selectedLeaderboard) {
if(this.selectedLeaderboardPanel != selectedLeaderboard) {
if (this.selectedLeaderboardPanel != selectedLeaderboard) {
this.selectedLeaderboardPanel = selectedLeaderboard;
for (SelectedLeaderboardChangeListener listener : selectedLeaderboardChangeListeners) {
listener.onSelectedLeaderboardChanged(selectedLeaderboardPanel);
@@ -320,13 +320,13 @@ public class EditableLeaderboardPanel extends LeaderboardPanel {
final RowUpdateWhiteboard<LeaderboardRowDTO> whiteboard = new RowUpdateWhiteboard<LeaderboardRowDTO>(
EditableLeaderboardPanel.this.getData());
getWhiteboardOwner().whiteboardProduced(whiteboard);
setBusyState(true);
addBusyTask();
getSailingService().updateLeaderboardMaxPointsReason(getLeaderboardName(), row.competitor.getIdAsString(),
raceColumnName, value == null || value.trim().length() == 0 ? null : MaxPointsReason.valueOf(value.trim()),
getLeaderboardDisplayDate(), new AsyncCallback<Util.Triple<Double, Double, Boolean>>() {
@Override
public void onFailure(Throwable t) {
setBusyState(false);
removeBusyTask();
getErrorReporter().reportError(
"Error trying to update max points reason for competitor "
+ row.competitor.getName() + " in leaderboard " + getLeaderboardName()
@@ -335,7 +335,7 @@ public class EditableLeaderboardPanel extends LeaderboardPanel {
@Override
public void onSuccess(Util.Triple<Double, Double, Boolean> newTotalAndNetPointsAndIsCorrected) {
setBusyState(false);
removeBusyTask();
row.fieldsByRaceColumnName.get(raceColumnName).reasonForMaxPoints = value == null
|| value.length() == 0 ? null : MaxPointsReason.valueOf(value.trim());
row.fieldsByRaceColumnName.get(raceColumnName).totalPoints = newTotalAndNetPointsAndIsCorrected.getA();
@@ -445,14 +445,14 @@ public class EditableLeaderboardPanel extends LeaderboardPanel {
final RowUpdateWhiteboard<LeaderboardRowDTO> whiteboard = new RowUpdateWhiteboard<LeaderboardRowDTO>(
EditableLeaderboardPanel.this.getData());
getWhiteboardOwner().whiteboardProduced(whiteboard);
setBusyState(true);
addBusyTask();
getSailingService().updateLeaderboardScoreCorrection(getLeaderboardName(), row.competitor.getIdAsString(), raceColumnName,
value == null || value.trim().length() == 0 ? null : value.trim().equals("n/a") ? null
: Double.valueOf(value.trim()), getLeaderboardDisplayDate(),
new AsyncCallback<Util.Triple<Double, Double, Boolean>>() {
@Override
public void onFailure(Throwable t) {
setBusyState(false);
removeBusyTask();
getErrorReporter().reportError("Error trying to update score correction for competitor "+
row.competitor.getName()+" in leaderboard "+getLeaderboardName()+
" for race "+raceColumnName+": "+t.getMessage()+
@@ -461,7 +461,7 @@ public class EditableLeaderboardPanel extends LeaderboardPanel {
@Override
public void onSuccess(Util.Triple<Double, Double, Boolean> newTotalAndTotalPointsAndIsCorrected) {
setBusyState(false);
removeBusyTask();
final LeaderboardEntryDTO leaderboardEntryDTO = row.fieldsByRaceColumnName.get(raceColumnName);
leaderboardEntryDTO.totalPoints = value == null || value.length() == 0 ? newTotalAndTotalPointsAndIsCorrected
.getA() : Double.valueOf(value.trim());
@@ -524,13 +524,13 @@ public class EditableLeaderboardPanel extends LeaderboardPanel {
row.fieldsByRaceColumnName.get(raceColumnName).totalPoints, new DialogCallback<Util.Pair<MaxPointsReason, Double>>() {
@Override
public void ok(final Util.Pair<MaxPointsReason, Double> editedObject) {
setBusyState(true);
addBusyTask();
getSailingService().updateLeaderboardScoreCorrection(getLeaderboardName(), row.competitor.getIdAsString(), raceColumnName,
editedObject.getB(), getLeaderboardDisplayDate(),
new AsyncCallback<Util.Triple<Double, Double, Boolean>>() {
@Override
public void onFailure(Throwable t) {
setBusyState(false);
removeBusyTask();
getErrorReporter().reportError("Error trying to update score correction for competitor "+
row.competitor.getName()+" in leaderboard "+getLeaderboardName()+
" for race "+raceColumnName+": "+t.getMessage()+
@@ -544,7 +544,7 @@ public class EditableLeaderboardPanel extends LeaderboardPanel {
new AsyncCallback<Util.Triple<Double, Double, Boolean>>() {
@Override
public void onFailure(Throwable t) {
setBusyState(false);
removeBusyTask();
getErrorReporter().reportError("Error trying to update score correction for competitor "+
row.competitor.getName()+" in leaderboard "+getLeaderboardName()+
" for race "+raceColumnName+": "+t.getMessage()+
@@ -553,7 +553,7 @@ public class EditableLeaderboardPanel extends LeaderboardPanel {
@Override
public void onSuccess(Util.Triple<Double, Double, Boolean> newTotalAndNetPointsAndIsCorrected) {
setBusyState(false);
removeBusyTask();
final LeaderboardEntryDTO leaderboardEntryDTO = row.fieldsByRaceColumnName.get(raceColumnName);
leaderboardEntryDTO.reasonForMaxPoints = editedObject.getA();
leaderboardEntryDTO.totalPoints = newTotalAndNetPointsAndIsCorrected.getA();
@@ -656,7 +656,7 @@ public class EditableLeaderboardPanel extends LeaderboardPanel {
showUncorrectedTotalPointsCheckbox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
timeChanged(getTimer().getTime(), getTimer().getTime());
loadCompleteLeaderboard(/* showProgress */ true);
}
});
scoreCorrectionInfoGrid.setWidget(0, 3, showUncorrectedTotalPointsCheckbox);
@@ -716,7 +716,7 @@ public class EditableLeaderboardPanel extends LeaderboardPanel {
public void onSuccess(Void result) {
Window.setStatus("Successfully unsuppressed competitor "+object.getName());
// force a reload of the entire editable leaderboard to hide the now suppressed competitor
timeChanged(getLeaderboardDisplayDate(), null);
loadCompleteLeaderboard(/* showProgress */ true);
}
});
}
@@ -788,7 +788,7 @@ public class EditableLeaderboardPanel extends LeaderboardPanel {
@Override
public void onSuccess(Void result) {
// force a reload of the entire editable leaderboard to hide the now suppressed competitor
timeChanged(getLeaderboardDisplayDate(), null);
loadCompleteLeaderboard(/* showProgress */ true);
}
});
}
@@ -409,20 +409,20 @@ public class MatchAndApplyScoreCorrectionsDialog extends DataEntryDialog<BulkSco
@Override
public void ok(final BulkScoreCorrectionDTO result) {
leaderboardPanel.setBusyState(true);
leaderboardPanel.addBusyTask();
sailingService.updateLeaderboardScoreCorrectionsAndMaxPointsReasons(result, new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable caught) {
leaderboardPanel.setBusyState(false);
leaderboardPanel.removeBusyTask();
errorReporter.reportError(stringMessages.errorUpdatingScoresForLeaderboard(result.getLeaderboardName(),
caught.getMessage()));
}
@Override
public void onSuccess(Void result) {
leaderboardPanel.removeBusyTask();
Window.setStatus(stringMessages.successfullyUpdatedScores());
leaderboardPanel.timeChanged(/* time point is ignored */ null, null); // reload leaderboard contents to reflect changes
// leaderboard panel sets busy indicator to non-busy after done with updating
leaderboardPanel.loadCompleteLeaderboard(/* showProgress */ true); // reload leaderboard contents to reflect changes
}
});
}
@@ -221,19 +221,19 @@ public class ResultSelectionAndApplyDialog extends DataEntryDialog<Util.Triple<S
final String eventName = providerNameAndEventNameBoatClassNameCapturedWhen.getB();
final String boatClassName = providerNameAndEventNameBoatClassNameCapturedWhen.getC().getA();
final Date timePointWhenResultPublished = providerNameAndEventNameBoatClassNameCapturedWhen.getC().getB();
leaderboardPanel.setBusyState(true);
leaderboardPanel.addBusyTask();
sailingService.getScoreCorrections(scoreCorrectionProviderName, eventName, boatClassName, timePointWhenResultPublished,
new AsyncCallback<RegattaScoreCorrectionDTO>() {
@Override
public void onFailure(Throwable caught) {
leaderboardPanel.setBusyState(false);
leaderboardPanel.removeBusyTask();
errorReporter.reportError(stringMessages.errorObtainingScoreCorrections(scoreCorrectionProviderName,
eventName, boatClassName, timePointWhenResultPublished.toString(), caught.getMessage()));
}
@Override
public void onSuccess(RegattaScoreCorrectionDTO result) {
leaderboardPanel.setBusyState(false);
leaderboardPanel.removeBusyTask();
new MatchAndApplyScoreCorrectionsDialog(leaderboardPanel, stringMessages, sailingService,
errorReporter, result).show();
}
@@ -7,7 +7,15 @@ public interface BusyStateProvider {
void removeBusyStateChangeListener(BusyStateChangeListener listener);
void setBusyState(boolean isBusy);
boolean isBusy();
/**
* A new task has begun that keeps us busy
*/
void addBusyTask();
/**
* A task that kept us busy has finished
*/
void removeBusyTask();
}