working towards bug 836: parameterizing the Leaderboard.html entry point to select single races

This commit is contained in:
Axel Uhl committed 2012-07-06 01:12:46 +02:00
1 parent 19ea2a78de
commit c261ff19cc
5 files changed
+106 -14

No files matched your search

@@ -1,6 +1,9 @@
package com.sap.sailing.gwt.ui.leaderboard;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.Window;
@@ -10,6 +13,9 @@ import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.sap.sailing.domain.common.DetailType;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.RegattaNameAndRaceName;
import com.sap.sailing.gwt.ui.actions.AsyncActionsExecutor;
import com.sap.sailing.gwt.ui.client.AbstractEntryPoint;
import com.sap.sailing.gwt.ui.client.CompetitorSelectionModel;
@@ -19,21 +25,32 @@ import com.sap.sailing.gwt.ui.client.Timer.PlayModes;
public class LeaderboardEntryPoint extends AbstractEntryPoint {
private static final Logger logger = Logger.getLogger(LeaderboardEntryPoint.class.getName());
private static final String PARAM_LEADERBOARD_GROUP_NAME = "leaderboardGroupName";
private static final String PARAM_EMBEDDED = "embedded";
private static final String PARAM_SHOW_RACE_DETAILS = "showRaceDetails";
private static final String PARAM_RACE_NAME = "raceName";
private static final String PARAM_RACE_DETAIL = "raceDetail";
private static final String PARAM_LEG_DETAIL = "legDetail";
private static final String PARAM_MANEUVER_DETAIL = "maneuverDetail";
private static final String PARAM_AUTO_EXPAND_PRESELECTED_RACE = "autoExpandPreselectedRace";
private static final String PARAM_REGATTA_NAME = "regattaName";
private static final String PARAM_REFRESH_INTERVAL_MILLIS = "refreshIntervalMillis";
private String leaderboardName;
private String leaderboardGroupName;
@Override
public void onModuleLoad() {
super.onModuleLoad();
final boolean showRaceDetails = Window.Location.getParameter("showRaceDetails") != null
&& Window.Location.getParameter("showRaceDetails").equalsIgnoreCase("true");
final boolean embedded = Window.Location.getParameter("embedded") != null
&& Window.Location.getParameter("embedded").equalsIgnoreCase("true");
final boolean showRaceDetails = Window.Location.getParameter(PARAM_SHOW_RACE_DETAILS) != null
&& Window.Location.getParameter(PARAM_SHOW_RACE_DETAILS).equalsIgnoreCase("true");
final boolean embedded = Window.Location.getParameter(PARAM_EMBEDDED) != null
&& Window.Location.getParameter(PARAM_EMBEDDED).equalsIgnoreCase("true");
sailingService.getLeaderboardNames(new AsyncCallback<List<String>>() {
@Override
public void onSuccess(List<String> leaderboardNames) {
leaderboardName = Window.Location.getParameter("name");
leaderboardGroupName = Window.Location.getParameter("leaderboardGroupName");
leaderboardGroupName = Window.Location.getParameter(PARAM_LEADERBOARD_GROUP_NAME);
if (leaderboardNames.contains(leaderboardName)) {
createUI(showRaceDetails, embedded);
} else {
@@ -70,10 +87,10 @@ public class LeaderboardEntryPoint extends AbstractEntryPoint {
} else {
Timer timer = new Timer(PlayModes.Replay, /* delayBetweenAutoAdvancesInMilliseconds */3000l);
timer.setLivePlayDelayInMillis(5000l);
LeaderboardPanel leaderboardPanel = new LeaderboardPanel(sailingService, new AsyncActionsExecutor(),
LeaderboardSettingsFactory.getInstance().createNewDefaultSettings(null, null, null, /* autoExpandFirstRace */ false),
/* preSelectedRace */ null, new CompetitorSelectionModel(/* hasMultiSelection */ true), timer,
leaderboardName, leaderboardGroupName,
LeaderboardPanel leaderboardPanel = new LeaderboardPanel(sailingService, new AsyncActionsExecutor(),
createLeaderboardSettingsFromURLParameters(Window.Location.getParameterMap()),
getPreselectedRace(Window.Location.getParameterMap()), new CompetitorSelectionModel(
/* hasMultiSelection */true), timer, leaderboardName, leaderboardGroupName,
LeaderboardEntryPoint.this, stringMessages, userAgentType, showRaceDetails);
contentScrollPanel.setWidget(leaderboardPanel);
}
@@ -81,4 +98,64 @@ public class LeaderboardEntryPoint extends AbstractEntryPoint {
mainPanel.add(contentScrollPanel);
}
private RaceIdentifier getPreselectedRace(Map<String, List<String>> parameterMap) {
RaceIdentifier result;
if (parameterMap.containsKey(PARAM_RACE_NAME) && parameterMap.get(PARAM_RACE_NAME).size() == 1 &&
parameterMap.containsKey(PARAM_REGATTA_NAME) && parameterMap.get(PARAM_REGATTA_NAME).size() == 1) {
result = new RegattaNameAndRaceName(parameterMap.get(PARAM_REGATTA_NAME).get(0), parameterMap.get(PARAM_RACE_NAME).get(0));
} else {
result = null;
}
return result;
}
/**
* Constructs {@link LeaderboardSettings} from the URL parameters found
*/
private LeaderboardSettings createLeaderboardSettingsFromURLParameters(Map<String, List<String>> parameterMap) {
LeaderboardSettings result;
if (parameterMap.containsKey(PARAM_RACE_NAME) || parameterMap.containsKey(PARAM_RACE_DETAIL) ||
parameterMap.containsKey(PARAM_LEG_DETAIL) || parameterMap.containsKey(PARAM_MANEUVER_DETAIL)) {
List<DetailType> maneuverDetails = getDetailTypeListFromParamValue(parameterMap.get(PARAM_MANEUVER_DETAIL));
List<DetailType> raceDetails = getDetailTypeListFromParamValue(parameterMap.get(PARAM_RACE_DETAIL));
List<DetailType> legDetails = getDetailTypeListFromParamValue(parameterMap.get(PARAM_MANEUVER_DETAIL));
List<String> namesOfRacesToShow = getStringListFromParamValue(parameterMap.get(PARAM_RACE_NAME));
Long refreshIntervalMillis = parameterMap.containsKey(PARAM_REFRESH_INTERVAL_MILLIS) ?
Long.valueOf(parameterMap.get(PARAM_REFRESH_INTERVAL_MILLIS).get(0)) : null;
boolean autoExpandPreSelectedRace = parameterMap.containsKey(PARAM_AUTO_EXPAND_PRESELECTED_RACE) ?
Boolean.valueOf(parameterMap.get(PARAM_AUTO_EXPAND_PRESELECTED_RACE).get(0)) :
(namesOfRacesToShow != null && namesOfRacesToShow.size() == 1);
result = new LeaderboardSettings(maneuverDetails, legDetails, raceDetails, /* namesOfRaceColumnsToShow */ null,
namesOfRacesToShow,
autoExpandPreSelectedRace, refreshIntervalMillis,
/* delay to live */ null, /* sort by column */ (namesOfRacesToShow != null && !namesOfRacesToShow.isEmpty()) ?
namesOfRacesToShow.get(0) : null, /* ascending */ true,
/* updateUponPlayStateChange */ raceDetails.isEmpty() && legDetails.isEmpty());
} else {
result = LeaderboardSettingsFactory.getInstance().createNewDefaultSettings(null, null, null, /* autoExpandFirstRace */ false);
}
return result;
}
private List<DetailType> getDetailTypeListFromParamValue(List<String> list) {
List<DetailType> result = new ArrayList<DetailType>();
if (list != null) {
for (String entry : list) {
try {
result.add(DetailType.valueOf(entry));
} catch (IllegalArgumentException e) {
logger.info("Can't find detail type "+entry+". Ignoring.");
}
}
}
return result;
}
private List<String> getStringListFromParamValue(List<String> list) {
List<String> result = new ArrayList<String>();
if (list != null) {
result.addAll(list);
}
return result;
}
}
@@ -264,7 +264,7 @@ public class LeaderboardPanel extends FormPanel implements TimeListener, PlaySta
}
public void updateSettings(LeaderboardSettings newSettings) {
if (!currentlyHandlingPlayStateChange) {
if (!newSettings.updateUponPlayStateChange() || !currentlyHandlingPlayStateChange) {
settingsUpdatedExplicitly = true;
}
List<ExpandableSortableColumn<?>> columnsToExpandAgain = new ArrayList<ExpandableSortableColumn<?>>();
@@ -963,6 +963,7 @@ public class LeaderboardPanel extends FormPanel implements TimeListener, PlaySta
this.selectedRaceColumns = new ArrayList<RaceColumnDTO>();
this.selectedManeuverDetails = new ArrayList<DetailType>();
settingsUpdatedExplicitly = !settings.updateUponPlayStateChange();
selectedLegDetails.addAll(settings.getLegDetailsToShow());
selectedManeuverDetails.addAll(settings.getManeuverDetailsToShow());
selectedRaceDetails.addAll(settings.getRaceDetailsToShow());
@@ -20,6 +20,7 @@ public class LeaderboardSettings {
private final boolean autoExpandPreSelectedRace;
private final Long delayBetweenAutoAdvancesInMilliseconds;
private final Long delayInMilliseconds;
private final boolean updateUponPlayStateChange;
/**
* An optional sort column; if <code>null</code>, the leaderboard sorting won't be touched when updating the settings.
@@ -38,12 +39,13 @@ public class LeaderboardSettings {
* @param delayInMilliseconds
* @param nameOfRaceToSort
* @param sortAscending
* @param updateUponPlayStateChange TODO
* @param raceColumnsToShow <code>null</code> means don't modify the list of races shown
*/
public LeaderboardSettings(List<DetailType> meneuverDetailsToShow, List<DetailType> legDetailsToShow,
List<DetailType> raceDetailsToShow, List<String> namesOfRaceColumnsToShow,
List<String> namesOfRacesToShow, boolean autoExpandPreSelectedRace, Long delayBetweenAutoAdvancesInMilliseconds,
Long delayInMilliseconds, String nameOfRaceToSort, boolean sortAscending) {
Long delayInMilliseconds, String nameOfRaceToSort, boolean sortAscending, boolean updateUponPlayStateChange) {
if (namesOfRacesToShow != null && namesOfRaceColumnsToShow != null) {
throw new IllegalArgumentException("You can identify races either only by their race or by their column names, not both");
}
@@ -57,6 +59,7 @@ public class LeaderboardSettings {
this.maneuverDetailsToShow = meneuverDetailsToShow;
this.nameOfRaceToSort = nameOfRaceToSort;
this.sortAscending = sortAscending;
this.updateUponPlayStateChange = updateUponPlayStateChange;
}
public List<DetailType> getManeuverDetailsToShow() {
@@ -114,4 +117,12 @@ public class LeaderboardSettings {
return sortAscending;
}
/**
* If <code>true</code>, an update of the settings will behave like a manual settings update, meaning that
* the settings won't automatically be replaced / adjusted when the play state changes.
*/
public boolean updateUponPlayStateChange() {
return updateUponPlayStateChange;
}
}
@@ -144,7 +144,8 @@ public class LeaderboardSettingsDialogComponent implements SettingsDialogCompone
return new LeaderboardSettings(maneuverDetailsToShow, legDetailsToShow, raceDetailsToShow,
namesOfRaceColumnsToShow, /* nameOfRacesToShow */null, autoExpandPreSelectedRace,
1000l * (delayBetweenAutoAdvancesValue == null ? 0l : delayBetweenAutoAdvancesValue.longValue()),
1000 * (delayInSecondsValue == null ? 0 : delayInSecondsValue.longValue()), null, true);
1000 * (delayInSecondsValue == null ? 0 : delayInSecondsValue.longValue()), null, true,
/* updateUponPlayStateChange */ true);
}
@Override
@@ -62,7 +62,8 @@ public class LeaderboardSettingsFactory {
settings = new LeaderboardSettings(maneuverDetails, legDetails, raceDetails, namesOfRaceColumnsToShow,
namesOfRacesToShow,
/* set autoExpandPreSelectedRace to true if we look at a single race */ nameOfRaceColumnToShow != null || nameOfRaceToShow != null, /* refresh interval */ null,
/* delay to live */ null, /* name of race to sort */ nameOfRaceToSort, /* ascending */ true);
/* delay to live */ null, /* name of race to sort */ nameOfRaceToSort, /* ascending */ true,
/* updateUponPlayStateChange */ true);
break;
case Replay:
settings = createNewDefaultSettings(namesOfRaceColumnsToShow, namesOfRacesToShow, nameOfRaceToSort, /* autoExpandFirstRace */
@@ -100,6 +101,7 @@ public class LeaderboardSettingsFactory {
return new LeaderboardSettings(maneuverDetails, legDetails, raceDetails, namesOfRaceColumnsToShow,
namesOfRacesToShow,
autoExpandPreSelectedRace, /* refresh interval */ null,
/* delay to live */ null, /* sort by column */ nameOfRaceToSort, /* ascending */ true);
/* delay to live */ null, /* sort by column */ nameOfRaceToSort, /* ascending */ true,
/* updateUponPlayStateChange */ true);
}
}