diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/client/place/event/multiregatta/tabs/MultiregattaOverviewPlace.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/client/place/event/multiregatta/tabs/MultiregattaOverviewPlace.java index 31d96486219..db10f6ae4d1 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/client/place/event/multiregatta/tabs/MultiregattaOverviewPlace.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/client/place/event/multiregatta/tabs/MultiregattaOverviewPlace.java @@ -5,8 +5,9 @@ import com.sap.sailing.gwt.home.client.place.event.AbstractEventPlace; import com.sap.sailing.gwt.home.client.place.event.EventContext; import com.sap.sailing.gwt.home.client.place.event.EventPrefixes; import com.sap.sailing.gwt.home.client.place.event.multiregatta.AbstractMultiregattaEventPlace; +import com.sap.sailing.gwt.home.shared.app.HasMobileVersion; -public class MultiregattaOverviewPlace extends AbstractMultiregattaEventPlace { +public class MultiregattaOverviewPlace extends AbstractMultiregattaEventPlace implements HasMobileVersion { public MultiregattaOverviewPlace(String id) { super(id); } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/desktop/app/DesktopActivityMapper.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/desktop/app/DesktopActivityMapper.java index 3373f702532..436162f4010 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/desktop/app/DesktopActivityMapper.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/desktop/app/DesktopActivityMapper.java @@ -43,10 +43,12 @@ import com.sap.sailing.gwt.home.client.place.start.StartPlace; import com.sap.sailing.gwt.home.client.place.whatsnew.WhatsNewActivityProxy; import com.sap.sailing.gwt.home.client.place.whatsnew.WhatsNewPlace; import com.sap.sailing.gwt.home.shared.SwitchingEntryPoint; +import com.sap.sailing.gwt.home.shared.app.ApplicationPlaceUpdater; import com.sap.sailing.gwt.home.shared.app.HasMobileVersion; public class DesktopActivityMapper implements ActivityMapper { private final DesktopClientFactory clientFactory; + private final ApplicationPlaceUpdater placeUpdater = new ApplicationPlaceUpdater(); public DesktopActivityMapper(DesktopClientFactory clientFactory) { super(); @@ -68,8 +70,6 @@ public class DesktopActivityMapper implements ActivityMapper { } else if (place instanceof ContactPlace) { return new ContactActivityProxy((ContactPlace) place, clientFactory); } else if (place instanceof EventPlace) { - // return new EventActivityProxy((EventPlace) place, clientFactory); - // rerouting old place to new place to make bookmarked URLs to work with the new interface. return getActivity(getRealEventPlace((EventPlace) place)); } else if (place instanceof AbstractEventPlace) { AbstractEventPlace eventPlace = (AbstractEventPlace) place; @@ -87,12 +87,8 @@ public class DesktopActivityMapper implements ActivityMapper { } else if (place instanceof WhatsNewPlace) { return new WhatsNewActivityProxy((WhatsNewPlace) place, clientFactory); } else if (place instanceof RegattaPlace) { -// return new RegattaActivityProxy((RegattaPlace) place, clientFactory); - // rerouting old place to new place to make bookmarked URLs to work with the new interface. return getActivity(getRealRegattaPlace((RegattaPlace) place)); } else if (place instanceof SeriesPlace) { -// return new SeriesActivityProxy((SeriesPlace) place, clientFactory); - // rerouting old place to new place to make bookmarked URLs to work with the new interface. return getActivity(getRealSeriesPlace((SeriesPlace) place)); } else if (place instanceof SearchResultPlace) { return new SearchResultActivityProxy((SearchResultPlace) place, clientFactory); @@ -100,80 +96,79 @@ public class DesktopActivityMapper implements ActivityMapper { return null; } } - - private Place getRealRegattaPlace(RegattaPlace place) { - String eventId = place.getEventUuidAsString(); - if(eventId == null || eventId.isEmpty()) { - return new EventsPlace(); - } - EventContext eventContext = new EventContext().withId(eventId); - String regattaId = place.getLeaderboardIdAsNameString(); - boolean hasRegattaId = (regattaId != null && !regattaId.isEmpty()); - - // TODO evaluate additional parameters - - if(hasRegattaId) { - switch (place.getNavigationTab()) { - case CompetitorAnalytics: - return new RegattaCompetitorAnalyticsPlace(eventContext); - case Leaderboard: - return new RegattaLeaderboardPlace(eventContext); - } - } - return new EventDefaultPlace(eventContext); - } - - @SuppressWarnings("incomplete-switch") - private Place getRealEventPlace(EventPlace place) { - String eventId = place.getEventUuidAsString(); - if(eventId == null || eventId.isEmpty()) { - return new EventsPlace(); - } - EventContext eventContext = new EventContext().withId(eventId); - String regattaId = place.getLeaderboardIdAsNameString(); - boolean hasRegattaId = (regattaId != null && !regattaId.isEmpty()); - if(hasRegattaId) { - eventContext.withRegattaId(regattaId); - - switch (place.getNavigationTab()) { - case Media: - return new RegattaMediaPlace(eventContext); - case Overview: - return new RegattaOverviewPlace(eventContext); - case Regatta: - return new RegattaRacesPlace(eventContext); - } - } else { - switch (place.getNavigationTab()) { - // TODO some places aren't implemented yet - case Media: - return new MultiregattaMediaPlace(eventContext); - case Overview: - return new MultiregattaOverviewPlace(eventContext); - case Schedule: - // Schedule not implemented yet -> using race list - case Regattas: - return new MultiregattaRegattasPlace(eventContext); - } - } - - return new EventDefaultPlace(eventContext); +private Place getRealRegattaPlace(RegattaPlace place) { + String eventId = place.getEventUuidAsString(); + if(eventId == null || eventId.isEmpty()) { + return new EventsPlace(); } + EventContext eventContext = new EventContext().withId(eventId); + String regattaId = place.getLeaderboardIdAsNameString(); + boolean hasRegattaId = (regattaId != null && !regattaId.isEmpty()); - private Place getRealSeriesPlace(SeriesPlace place) { - String seriesId = place.getEventUuidAsString(); - SeriesContext context = new SeriesContext().withId(seriesId); - - // TODO evaluate additional parameters + // TODO evaluate additional parameters + + if(hasRegattaId) { + switch (place.getNavigationTab()) { + case CompetitorAnalytics: + return new RegattaCompetitorAnalyticsPlace(eventContext); + case Leaderboard: + return new RegattaLeaderboardPlace(eventContext); + } + } + return new EventDefaultPlace(eventContext); +} + +@SuppressWarnings("incomplete-switch") +private Place getRealEventPlace(EventPlace place) { + String eventId = place.getEventUuidAsString(); + if(eventId == null || eventId.isEmpty()) { + return new EventsPlace(); + } + EventContext eventContext = new EventContext().withId(eventId); + String regattaId = place.getLeaderboardIdAsNameString(); + boolean hasRegattaId = (regattaId != null && !regattaId.isEmpty()); + if(hasRegattaId) { + eventContext.withRegattaId(regattaId); switch (place.getNavigationTab()) { - case OverallLeaderboard: - return new EventSeriesOverallLeaderboardPlace(context); - case RegattaLeaderboards: - return new EventSeriesLeaderboardsPlace(context); - case CompetitorAnalytics: - return new EventSeriesCompetitorAnalyticsPlace(context); + case Media: + return new RegattaMediaPlace(eventContext); + case Overview: + return new RegattaOverviewPlace(eventContext); + case Regatta: + return new RegattaRacesPlace(eventContext); + } + } else { + switch (place.getNavigationTab()) { + // TODO some places aren't implemented yet + case Media: + return new MultiregattaMediaPlace(eventContext); + case Overview: + return new MultiregattaOverviewPlace(eventContext); + case Schedule: + // Schedule not implemented yet -> using race list + case Regattas: + return new MultiregattaRegattasPlace(eventContext); } - return new SeriesDefaultPlace(context); } + + return new EventDefaultPlace(eventContext); +} + +private Place getRealSeriesPlace(SeriesPlace place) { + String seriesId = place.getEventUuidAsString(); + SeriesContext context = new SeriesContext().withId(seriesId); + + // TODO evaluate additional parameters + + switch (place.getNavigationTab()) { + case OverallLeaderboard: + return new EventSeriesOverallLeaderboardPlace(context); + case RegattaLeaderboards: + return new EventSeriesLeaderboardsPlace(context); + case CompetitorAnalytics: + return new EventSeriesCompetitorAnalyticsPlace(context); + } + return new SeriesDefaultPlace(context); +} } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/mobile/app/MobileActivityMapper.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/mobile/app/MobileActivityMapper.java index c8dc49ed358..4cece9746f1 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/mobile/app/MobileActivityMapper.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/mobile/app/MobileActivityMapper.java @@ -14,11 +14,12 @@ import com.sap.sailing.gwt.home.mobile.places.latestnews.LatestNewsPlace; import com.sap.sailing.gwt.home.mobile.places.minileaderboard.MiniLeaderboardActivityProxy; import com.sap.sailing.gwt.home.mobile.places.minileaderboard.MiniLeaderboardPlace; import com.sap.sailing.gwt.home.shared.SwitchingEntryPoint; +import com.sap.sailing.gwt.home.shared.app.ApplicationPlaceUpdater; import com.sap.sailing.gwt.home.shared.app.HasMobileVersion; - public class MobileActivityMapper implements ActivityMapper { private final MobileApplicationClientFactory clientFactory; + private final ApplicationPlaceUpdater placeUpdater = new ApplicationPlaceUpdater(); public MobileActivityMapper(MobileApplicationClientFactory clientFactory) { super(); @@ -26,7 +27,8 @@ public class MobileActivityMapper implements ActivityMapper { } @Override - public Activity getActivity(Place place) { + public Activity getActivity(Place rawPlace) { + Place place = placeUpdater.getRealPlace(rawPlace); if (!(place instanceof HasMobileVersion)) { GWT.log("Place has no mobile view: " + place.getClass().getName()); SwitchingEntryPoint.reloadApp(); diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/shared/SwitchingEntryPoint.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/shared/SwitchingEntryPoint.java index 828a2e96335..f7d0cf8138c 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/shared/SwitchingEntryPoint.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/shared/SwitchingEntryPoint.java @@ -20,6 +20,7 @@ import com.google.gwt.user.client.ui.RootPanel; import com.sap.sailing.gwt.home.desktop.DesktopEntryPoint; import com.sap.sailing.gwt.home.mobile.MobileEntryPoint; import com.sap.sailing.gwt.home.shared.app.ApplicationHistoryMapper; +import com.sap.sailing.gwt.home.shared.app.ApplicationPlaceUpdater; import com.sap.sailing.gwt.home.shared.app.HasMobileVersion; public class SwitchingEntryPoint implements EntryPoint { @@ -27,7 +28,8 @@ public class SwitchingEntryPoint implements EntryPoint { private static final String SAPSAILING_MOBILE = "sapsailing_mobile"; private static final RegExp isMobileRegExp = RegExp.compile( "Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini", "i"); - private PlaceHistoryMapper hisMap = GWT.create(ApplicationHistoryMapper.class); + private final PlaceHistoryMapper hisMap = GWT.create(ApplicationHistoryMapper.class); + private final ApplicationPlaceUpdater placeUpdater = new ApplicationPlaceUpdater(); @Override public void onModuleLoad() { @@ -36,7 +38,8 @@ public class SwitchingEntryPoint implements EntryPoint { if (hash != null && hash.startsWith("#")) { hash = hash.substring(1); } - Place place = hisMap.getPlace(hash); + Place rawPlace = hisMap.getPlace(hash); + Place place = placeUpdater.getRealPlace(rawPlace); String userWantsMobileUi = Cookies.getCookie(SAPSAILING_MOBILE); if (place != null && !(place instanceof HasMobileVersion)) { LOG.info("We have a dedicated desktop place: " + hash); diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/shared/app/ApplicationPlaceUpdater.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/shared/app/ApplicationPlaceUpdater.java new file mode 100644 index 00000000000..4fdf6261e6a --- /dev/null +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/shared/app/ApplicationPlaceUpdater.java @@ -0,0 +1,115 @@ +package com.sap.sailing.gwt.home.shared.app; + +import com.google.gwt.place.shared.Place; +import com.sap.sailing.gwt.home.client.place.event.EventContext; +import com.sap.sailing.gwt.home.client.place.event.EventDefaultPlace; +import com.sap.sailing.gwt.home.client.place.event.legacy.EventPlace; +import com.sap.sailing.gwt.home.client.place.event.legacy.RegattaPlace; +import com.sap.sailing.gwt.home.client.place.event.legacy.SeriesPlace; +import com.sap.sailing.gwt.home.client.place.event.multiregatta.tabs.MultiregattaMediaPlace; +import com.sap.sailing.gwt.home.client.place.event.multiregatta.tabs.MultiregattaRegattasPlace; +import com.sap.sailing.gwt.home.client.place.event.regatta.tabs.RegattaCompetitorAnalyticsPlace; +import com.sap.sailing.gwt.home.client.place.event.regatta.tabs.RegattaLeaderboardPlace; +import com.sap.sailing.gwt.home.client.place.event.regatta.tabs.RegattaMediaPlace; +import com.sap.sailing.gwt.home.client.place.event.regatta.tabs.RegattaOverviewPlace; +import com.sap.sailing.gwt.home.client.place.event.regatta.tabs.RegattaRacesPlace; +import com.sap.sailing.gwt.home.client.place.events.EventsPlace; +import com.sap.sailing.gwt.home.client.place.fakeseries.SeriesContext; +import com.sap.sailing.gwt.home.client.place.fakeseries.SeriesDefaultPlace; +import com.sap.sailing.gwt.home.client.place.fakeseries.tabs.EventSeriesCompetitorAnalyticsPlace; +import com.sap.sailing.gwt.home.client.place.fakeseries.tabs.EventSeriesLeaderboardsPlace; +import com.sap.sailing.gwt.home.client.place.fakeseries.tabs.EventSeriesOverallLeaderboardPlace; + +/** + * Helper class to support converting old places to new ones. + * + */ +public class ApplicationPlaceUpdater { + + public Place getRealPlace(Place place) { + if (place instanceof EventPlace) { + return getRealEventPlace((EventPlace) place); + } else if (place instanceof RegattaPlace) { + return getRealRegattaPlace((RegattaPlace) place); + } else if (place instanceof SeriesPlace) { + return getRealSeriesPlace((SeriesPlace) place); + } + return place; + } + + private Place getRealRegattaPlace(RegattaPlace place) { + String eventId = place.getEventUuidAsString(); + if (eventId == null || eventId.isEmpty()) { + return new EventsPlace(); + } + EventContext eventContext = new EventContext().withId(eventId); + String regattaId = place.getLeaderboardIdAsNameString(); + boolean hasRegattaId = (regattaId != null && !regattaId.isEmpty()); + + // TODO evaluate additional parameters + + if (hasRegattaId) { + switch (place.getNavigationTab()) { + case CompetitorAnalytics: + return new RegattaCompetitorAnalyticsPlace(eventContext); + case Leaderboard: + return new RegattaLeaderboardPlace(eventContext); + } + } + return new EventDefaultPlace(eventContext); + } + + @SuppressWarnings("incomplete-switch") + private Place getRealEventPlace(EventPlace place) { + String eventId = place.getEventUuidAsString(); + if (eventId == null || eventId.isEmpty()) { + return new EventsPlace(); + } + EventContext eventContext = new EventContext().withId(eventId); + String regattaId = place.getLeaderboardIdAsNameString(); + boolean hasRegattaId = (regattaId != null && !regattaId.isEmpty()); + if (hasRegattaId) { + eventContext.withRegattaId(regattaId); + + switch (place.getNavigationTab()) { + case Media: + return new RegattaMediaPlace(eventContext); + case Overview: + return new RegattaOverviewPlace(eventContext); + case Regatta: + return new RegattaRacesPlace(eventContext); + } + } else { + switch (place.getNavigationTab()) { + // TODO some places aren't implemented yet + case Media: + return new MultiregattaMediaPlace(eventContext); + case Overview: + return new EventDefaultPlace(eventContext); + case Schedule: + // Schedule not implemented yet -> using race list + case Regattas: + return new MultiregattaRegattasPlace(eventContext); + } + } + + return new EventDefaultPlace(eventContext); + } + + private Place getRealSeriesPlace(SeriesPlace place) { + String seriesId = place.getEventUuidAsString(); + SeriesContext context = new SeriesContext().withId(seriesId); + + // TODO evaluate additional parameters + + switch (place.getNavigationTab()) { + case OverallLeaderboard: + return new EventSeriesOverallLeaderboardPlace(context); + case RegattaLeaderboards: + return new EventSeriesLeaderboardsPlace(context); + case CompetitorAnalytics: + return new EventSeriesCompetitorAnalyticsPlace(context); + } + return new SeriesDefaultPlace(context); + } +} diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideoDialog.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideoDialog.java index 5682a23d45a..16edabe8606 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideoDialog.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/VideoDialog.java @@ -5,7 +5,6 @@ import java.util.Collections; import java.util.Date; import java.util.List; -import com.google.gwt.core.shared.GWT; import com.google.gwt.event.logical.shared.ValueChangeEvent; import com.google.gwt.event.logical.shared.ValueChangeHandler; import com.google.gwt.user.client.ui.Grid; @@ -77,7 +76,6 @@ public abstract class VideoDialog extends DataEntryDialog { mimeTypeListBox.addItem(MimeType.youtube.name()); mimeTypeListBox.addItem(MimeType.vimeo.name()); - GWT.debugger(); localeListBox = createListBox(false); localeListBox.addItem(NO_LOCALE_TEXT, ""); localeListBox.addItem("English", "en"); diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboard/LeaderboardEntryPoint.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboard/LeaderboardEntryPoint.java index ffcd2a51caf..1f54ca0315f 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboard/LeaderboardEntryPoint.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboard/LeaderboardEntryPoint.java @@ -1,305 +1,303 @@ -package com.sap.sailing.gwt.ui.leaderboard; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.logging.Logger; - -import com.google.gwt.core.shared.GWT; -import com.google.gwt.dom.client.Style.Unit; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.rpc.AsyncCallback; -import com.google.gwt.user.client.ui.DockLayoutPanel; -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.google.gwt.user.client.ui.Widget; -import com.sap.sailing.domain.common.DetailType; -import com.sap.sailing.domain.common.LeaderboardType; -import com.sap.sailing.domain.common.RegattaAndRaceIdentifier; -import com.sap.sailing.domain.common.RegattaNameAndRaceName; -import com.sap.sailing.domain.common.dto.AbstractLeaderboardDTO; -import com.sap.sailing.gwt.ui.client.AbstractSailingEntryPoint; -import com.sap.sailing.gwt.ui.client.GlobalNavigationPanel; -import com.sap.sailing.gwt.ui.client.LogoAndTitlePanel; -import com.sap.sailing.gwt.ui.client.StringMessages; -import com.sap.sailing.gwt.ui.leaderboard.LeaderboardSettings.RaceColumnSelectionStrategies; -import com.sap.sailing.gwt.ui.shared.EventDTO; -import com.sap.sse.common.Util; -import com.sap.sse.gwt.client.async.AsyncActionsExecutor; -import com.sap.sse.gwt.client.async.MarkedAsyncCallback; -import com.sap.sse.gwt.client.dialog.DataEntryDialog; -import com.sap.sse.gwt.client.player.Timer; -import com.sap.sse.gwt.client.player.Timer.PlayModes; -import com.sap.sse.gwt.client.player.Timer.PlayStates; -import com.sap.sse.gwt.shared.GwtHttpRequestUtils; - - -public class LeaderboardEntryPoint extends AbstractSailingEntryPoint { - private static final Logger logger = Logger.getLogger(LeaderboardEntryPoint.class.getName()); - - private String leaderboardName; - private String leaderboardGroupName; - private LeaderboardType leaderboardType; - private GlobalNavigationPanel globalNavigationPanel; - private EventDTO event; - - @Override - protected void doOnModuleLoad() { - GWT.debugger(); - super.doOnModuleLoad(); - final boolean showRaceDetails = GwtHttpRequestUtils.getBooleanParameter(LeaderboardUrlSettings.PARAM_SHOW_RACE_DETAILS, false /* default*/); - final boolean embedded = GwtHttpRequestUtils.getBooleanParameter(LeaderboardUrlSettings.PARAM_EMBEDDED, false /* default*/); - final boolean hideToolbar = GwtHttpRequestUtils.getBooleanParameter(LeaderboardUrlSettings.PARAM_HIDE_TOOLBAR, false /* default*/); - final String eventIdAsString = GwtHttpRequestUtils.getStringParameter(LeaderboardUrlSettings.PARAM_EVENT_ID, null /* default*/); - final UUID eventId = eventIdAsString == null ? null : UUID.fromString(eventIdAsString); - - leaderboardName = Window.Location.getParameter("name"); - leaderboardGroupName = Window.Location.getParameter(LeaderboardUrlSettings.PARAM_LEADERBOARD_GROUP_NAME); - - if (leaderboardName != null) { - final Runnable checkLeaderboardNameAndCreateUI = new Runnable() { - @Override - public void run() { - sailingService.checkLeaderboardName(leaderboardName, - new MarkedAsyncCallback>( - new AsyncCallback>() { - @Override - public void onSuccess(Util.Pair leaderboardNameAndType) { - if (leaderboardNameAndType != null - && leaderboardName.equals(leaderboardNameAndType.getA())) { - Window.setTitle(leaderboardName); - leaderboardType = leaderboardNameAndType.getB(); - createUI(showRaceDetails, embedded, hideToolbar, event); - } else { - RootPanel.get().add(new Label(getStringMessages().noSuchLeaderboard())); - } - } - - @Override - public void onFailure(Throwable t) { - reportError("Error trying to obtain list of leaderboard names: " - + t.getMessage()); - } - })); - } - }; - if (eventId == null) { - checkLeaderboardNameAndCreateUI.run(); // use null-initialized event field - } else { - sailingService.getEventById(eventId, /* withStatisticalData */false, new MarkedAsyncCallback( - new AsyncCallback() { - @Override - public void onFailure(Throwable caught) { - reportError("Error trying to obtain event "+eventId+": " + caught.getMessage()); - } - - @Override - public void onSuccess(EventDTO result) { - event = result; - checkLeaderboardNameAndCreateUI.run(); - } - })); - } - } else { - RootPanel.get().add(new Label(getStringMessages().noSuchLeaderboard())); - } - final String zoomTo = Window.Location.getParameter(LeaderboardUrlSettings.PARAM_ZOOM_TO); - if (zoomTo != null) { - RootPanel.getBodyElement().setAttribute( - "style", - "zoom: " + zoomTo + ";-moz-transform: scale(" + zoomTo - + ");-moz-transform-origin: 0 0;-o-transform: scale(" + zoomTo - + ");-o-transform-origin: 0 0;-webkit-transform: scale(" + zoomTo - + ");-webkit-transform-origin: 0 0;"); - } - } - - private void createUI(boolean showRaceDetails, boolean embedded, boolean hideToolbar, EventDTO event) { - DockLayoutPanel mainPanel = new DockLayoutPanel(Unit.PX); - RootLayoutPanel.get().add(mainPanel); - LogoAndTitlePanel logoAndTitlePanel = null; - if (!embedded) { - // Hack to shorten the leaderboardName in case of overall leaderboards - String leaderboardDisplayName = Window.Location.getParameter("displayName"); - if (leaderboardDisplayName == null || leaderboardDisplayName.isEmpty()) { - leaderboardDisplayName = leaderboardName; - } - globalNavigationPanel = new GlobalNavigationPanel(getStringMessages(), true, null, leaderboardGroupName, event, null); - logoAndTitlePanel = new LogoAndTitlePanel(leaderboardGroupName, leaderboardDisplayName, getStringMessages(), this, getUserService()) { - @Override - public void onResize() { - super.onResize(); - if (isSmallWidth()) { - remove(globalNavigationPanel); - } else { - add(globalNavigationPanel); - } - } - }; - logoAndTitlePanel.addStyleName("LogoAndTitlePanel"); - if (!isSmallWidth()) { - logoAndTitlePanel.add(globalNavigationPanel); - } - mainPanel.addNorth(logoAndTitlePanel, 68); - } - ScrollPanel contentScrollPanel = new ScrollPanel(); - long delayBetweenAutoAdvancesInMilliseconds = 3000l; - final RegattaAndRaceIdentifier preselectedRace = getPreselectedRace(Window.Location.getParameterMap()); - // make a single live request as the default but don't continue to play by default - Timer timer = new Timer(PlayModes.Live, PlayStates.Paused, delayBetweenAutoAdvancesInMilliseconds); - final LeaderboardSettings leaderboardSettings = createLeaderboardSettingsFromURLParameters(Window.Location.getParameterMap()); - if (leaderboardSettings.getDelayBetweenAutoAdvancesInMilliseconds() != null) { - timer.setPlayMode(PlayModes.Live); // the leaderboard, viewed via the entry point, goes "live" and "playing" if an auto-refresh - } // interval has been specified - boolean autoExpandLastRaceColumn = GwtHttpRequestUtils.getBooleanParameter(LeaderboardUrlSettings.PARAM_AUTO_EXPAND_LAST_RACE_COLUMN, false); - boolean showCharts = GwtHttpRequestUtils.getBooleanParameter(LeaderboardUrlSettings.PARAM_SHOW_CHARTS, false); - boolean showOverallLeaderboard = GwtHttpRequestUtils.getBooleanParameter(LeaderboardUrlSettings.PARAM_SHOW_OVERALL_LEADERBOARD, false); - boolean showSeriesLeaderboards = GwtHttpRequestUtils.getBooleanParameter(LeaderboardUrlSettings.PARAM_SHOW_SERIES_LEADERBOARDS, false); - String chartDetailParam = GwtHttpRequestUtils.getStringParameter(LeaderboardUrlSettings.PARAM_CHART_DETAIL, null); - final DetailType chartDetailType; - if (chartDetailParam != null && (DetailType.REGATTA_RANK.name().equals(chartDetailParam) || DetailType.OVERALL_RANK.name().equals(chartDetailParam) || - DetailType.REGATTA_TOTAL_POINTS_SUM.name().equals(chartDetailParam))) { - chartDetailType = DetailType.valueOf(chartDetailParam); - } else { - chartDetailType = leaderboardType.isMetaLeaderboard() ? DetailType.OVERALL_RANK : DetailType.REGATTA_RANK; - } - - final Widget leaderboardViewer; - if (leaderboardType.isMetaLeaderboard()) { - leaderboardViewer = new MetaLeaderboardViewer(sailingService, new AsyncActionsExecutor(), - timer, leaderboardSettings, null, preselectedRace, leaderboardGroupName, leaderboardName, this, getStringMessages(), - userAgent, showRaceDetails, hideToolbar, autoExpandLastRaceColumn, showCharts, chartDetailType, showSeriesLeaderboards); - } else { - leaderboardViewer = new LeaderboardViewer(sailingService, new AsyncActionsExecutor(), - timer, leaderboardSettings, preselectedRace, leaderboardGroupName, leaderboardName, this, getStringMessages(), - userAgent, showRaceDetails, hideToolbar, autoExpandLastRaceColumn, showCharts, chartDetailType, showOverallLeaderboard); - } - contentScrollPanel.setWidget(leaderboardViewer); - mainPanel.add(contentScrollPanel); - } - - private RegattaAndRaceIdentifier getPreselectedRace(Map> parameterMap) { - RegattaAndRaceIdentifier result; - if (parameterMap.containsKey(LeaderboardUrlSettings.PARAM_RACE_NAME) && parameterMap.get(LeaderboardUrlSettings.PARAM_RACE_NAME).size() == 1 && - parameterMap.containsKey(LeaderboardUrlSettings.PARAM_REGATTA_NAME) && parameterMap.get(LeaderboardUrlSettings.PARAM_REGATTA_NAME).size() == 1) { - result = new RegattaNameAndRaceName(parameterMap.get(LeaderboardUrlSettings.PARAM_REGATTA_NAME).get(0), parameterMap.get(LeaderboardUrlSettings.PARAM_RACE_NAME).get(0)); - } else { - result = null; - } - return result; - } - - /** - * Constructs {@link LeaderboardSettings} from the URL parameters found - */ - private LeaderboardSettings createLeaderboardSettingsFromURLParameters(Map> parameterMap) { - LeaderboardSettings result; - Long refreshIntervalMillis = parameterMap.containsKey(LeaderboardUrlSettings.PARAM_REFRESH_INTERVAL_MILLIS) ? Long - .valueOf(parameterMap.get(LeaderboardUrlSettings.PARAM_REFRESH_INTERVAL_MILLIS).get(0)) : null; - RaceColumnSelectionStrategies raceColumnSelectionStrategy; - final Integer numberOfLastRacesToShow; - if (parameterMap.containsKey(LeaderboardUrlSettings.PARAM_NAME_LAST_N)) { - raceColumnSelectionStrategy = RaceColumnSelectionStrategies.LAST_N; - numberOfLastRacesToShow = Integer.valueOf(parameterMap.get(LeaderboardUrlSettings.PARAM_NAME_LAST_N).get(0)); - } else if (isSmallWidth()) { - raceColumnSelectionStrategy = RaceColumnSelectionStrategies.LAST_N; - int width = Window.getClientWidth(); - numberOfLastRacesToShow = (width-275)/40; - } else { - raceColumnSelectionStrategy = RaceColumnSelectionStrategies.EXPLICIT; - numberOfLastRacesToShow = null; - } - if (parameterMap.containsKey(LeaderboardUrlSettings.PARAM_RACE_NAME) || parameterMap.containsKey(LeaderboardUrlSettings.PARAM_RACE_DETAIL) || - parameterMap.containsKey(LeaderboardUrlSettings.PARAM_LEG_DETAIL) || parameterMap.containsKey(LeaderboardUrlSettings.PARAM_MANEUVER_DETAIL) || - parameterMap.containsKey(LeaderboardUrlSettings.PARAM_OVERALL_DETAIL) || parameterMap.containsKey(LeaderboardUrlSettings.PARAM_SHOW_ADDED_SCORES) || - parameterMap.containsKey(LeaderboardUrlSettings.PARAM_SHOW_OVERALL_COLUMN_WITH_NUMBER_OF_RACES_COMPLETED) - || parameterMap.containsKey(LeaderboardUrlSettings.PARAM_SHOW_COMPETITOR_NAME_COLUMNS)) { - List maneuverDetails = getDetailTypeListFromParamValue(parameterMap.get(LeaderboardUrlSettings.PARAM_MANEUVER_DETAIL)); - List raceDetails = getDetailTypeListFromParamValue(parameterMap.get(LeaderboardUrlSettings.PARAM_RACE_DETAIL)); - List overallDetails = getDetailTypeListFromParamValue(parameterMap.get(LeaderboardUrlSettings.PARAM_OVERALL_DETAIL)); - if (overallDetails.isEmpty()) { - overallDetails = Collections.singletonList(DetailType.REGATTA_RANK); - } - List legDetails = getDetailTypeListFromParamValue(parameterMap.get(LeaderboardUrlSettings.PARAM_LEG_DETAIL)); - List namesOfRacesToShow = getStringListFromParamValue(parameterMap.get(LeaderboardUrlSettings.PARAM_RACE_NAME)); - boolean showAddedScores = parameterMap.containsKey(LeaderboardUrlSettings.PARAM_SHOW_ADDED_SCORES) ? - Boolean.valueOf(parameterMap.get(LeaderboardUrlSettings.PARAM_SHOW_ADDED_SCORES).get(0)) : false; - boolean showOverallColumnWithNumberOfRacesSailedPerCompetitor = parameterMap.containsKey(LeaderboardUrlSettings.PARAM_SHOW_OVERALL_COLUMN_WITH_NUMBER_OF_RACES_COMPLETED) ? - Boolean.valueOf(parameterMap.get(LeaderboardUrlSettings.PARAM_SHOW_OVERALL_COLUMN_WITH_NUMBER_OF_RACES_COMPLETED).get(0)) : false; - boolean autoExpandPreSelectedRace = parameterMap.containsKey(LeaderboardUrlSettings.PARAM_AUTO_EXPAND_PRESELECTED_RACE) ? - Boolean.valueOf(parameterMap.get(LeaderboardUrlSettings.PARAM_AUTO_EXPAND_PRESELECTED_RACE).get(0)) : - (namesOfRacesToShow != null && namesOfRacesToShow.size() == 1); - boolean showCompetitorSailIdColumn = true; - boolean showCompetitorFullNameColumn = true; - if (parameterMap.containsKey(LeaderboardUrlSettings.PARAM_SHOW_COMPETITOR_NAME_COLUMNS)) { - String value = parameterMap.get(LeaderboardUrlSettings.PARAM_SHOW_COMPETITOR_NAME_COLUMNS).get(0); - if (value.equals(LeaderboardUrlSettings.COMPETITOR_NAME_COLUMN_FULL_NAME)) { - showCompetitorSailIdColumn = false; - } else if (value.equals(LeaderboardUrlSettings.COMPETITOR_NAME_COLUMN_SAIL_ID)) { - showCompetitorFullNameColumn = false; - } else if (value.trim().equals("")) { - showCompetitorFullNameColumn = false; - showCompetitorSailIdColumn = false; - } - } - result = new LeaderboardSettings(maneuverDetails, legDetails, raceDetails, overallDetails, - /* namesOfRaceColumnsToShow */ null, - namesOfRacesToShow, numberOfLastRacesToShow, - autoExpandPreSelectedRace, refreshIntervalMillis, /* sort by column */ (namesOfRacesToShow != null && !namesOfRacesToShow.isEmpty()) ? - namesOfRacesToShow.get(0) : null, - /* ascending */ true, /* updateUponPlayStateChange */ raceDetails.isEmpty() && legDetails.isEmpty(), - raceColumnSelectionStrategy, showAddedScores, showOverallColumnWithNumberOfRacesSailedPerCompetitor, - showCompetitorSailIdColumn, showCompetitorFullNameColumn); - - } else { - final List overallDetails = Collections.singletonList(DetailType.REGATTA_RANK); - result = LeaderboardSettingsFactory.getInstance().createNewDefaultSettings(null, null, - /* overallDetails */ overallDetails, null, - /* autoExpandFirstRace */false, refreshIntervalMillis, numberOfLastRacesToShow, - raceColumnSelectionStrategy); - } - return result; - } - - private List getDetailTypeListFromParamValue(List list) { - List result = new ArrayList(); - 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 getStringListFromParamValue(List list) { - List result = new ArrayList(); - if (list != null) { - result.addAll(list); - } - return result; - } - - /** - * Assembles a dialog that other parts of the application can use to let the user parameterize a leaderboard and - * obtain the according URL for it. This keeps the "secrets" of which URL parameters have which meaning encapsulated - * within this class.

- * - * The implementation by and large uses the {@link LeaderboardSettingsDialogComponent}'s widget and adds to it a checkbox - * for driving the {@link #LeaderboardUrlSettings.PARAM_EMBEDDED} field. - * - * @see LeaderboardEntryPoint#getUrl(String, LeaderboardSettings, boolean) - */ - public static DataEntryDialog getUrlConfigurationDialog(final AbstractLeaderboardDTO leaderboard, - final StringMessages stringMessages) { - return new LeaderboardUrlConfigurationDialog(stringMessages, leaderboard); - } - -} +package com.sap.sailing.gwt.ui.leaderboard; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.logging.Logger; + +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.DockLayoutPanel; +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.google.gwt.user.client.ui.Widget; +import com.sap.sailing.domain.common.DetailType; +import com.sap.sailing.domain.common.LeaderboardType; +import com.sap.sailing.domain.common.RegattaAndRaceIdentifier; +import com.sap.sailing.domain.common.RegattaNameAndRaceName; +import com.sap.sailing.domain.common.dto.AbstractLeaderboardDTO; +import com.sap.sailing.gwt.ui.client.AbstractSailingEntryPoint; +import com.sap.sailing.gwt.ui.client.GlobalNavigationPanel; +import com.sap.sailing.gwt.ui.client.LogoAndTitlePanel; +import com.sap.sailing.gwt.ui.client.StringMessages; +import com.sap.sailing.gwt.ui.leaderboard.LeaderboardSettings.RaceColumnSelectionStrategies; +import com.sap.sailing.gwt.ui.shared.EventDTO; +import com.sap.sse.common.Util; +import com.sap.sse.gwt.client.async.AsyncActionsExecutor; +import com.sap.sse.gwt.client.async.MarkedAsyncCallback; +import com.sap.sse.gwt.client.dialog.DataEntryDialog; +import com.sap.sse.gwt.client.player.Timer; +import com.sap.sse.gwt.client.player.Timer.PlayModes; +import com.sap.sse.gwt.client.player.Timer.PlayStates; +import com.sap.sse.gwt.shared.GwtHttpRequestUtils; + + +public class LeaderboardEntryPoint extends AbstractSailingEntryPoint { + private static final Logger logger = Logger.getLogger(LeaderboardEntryPoint.class.getName()); + + private String leaderboardName; + private String leaderboardGroupName; + private LeaderboardType leaderboardType; + private GlobalNavigationPanel globalNavigationPanel; + private EventDTO event; + + @Override + protected void doOnModuleLoad() { + super.doOnModuleLoad(); + final boolean showRaceDetails = GwtHttpRequestUtils.getBooleanParameter(LeaderboardUrlSettings.PARAM_SHOW_RACE_DETAILS, false /* default*/); + final boolean embedded = GwtHttpRequestUtils.getBooleanParameter(LeaderboardUrlSettings.PARAM_EMBEDDED, false /* default*/); + final boolean hideToolbar = GwtHttpRequestUtils.getBooleanParameter(LeaderboardUrlSettings.PARAM_HIDE_TOOLBAR, false /* default*/); + final String eventIdAsString = GwtHttpRequestUtils.getStringParameter(LeaderboardUrlSettings.PARAM_EVENT_ID, null /* default*/); + final UUID eventId = eventIdAsString == null ? null : UUID.fromString(eventIdAsString); + + leaderboardName = Window.Location.getParameter("name"); + leaderboardGroupName = Window.Location.getParameter(LeaderboardUrlSettings.PARAM_LEADERBOARD_GROUP_NAME); + + if (leaderboardName != null) { + final Runnable checkLeaderboardNameAndCreateUI = new Runnable() { + @Override + public void run() { + sailingService.checkLeaderboardName(leaderboardName, + new MarkedAsyncCallback>( + new AsyncCallback>() { + @Override + public void onSuccess(Util.Pair leaderboardNameAndType) { + if (leaderboardNameAndType != null + && leaderboardName.equals(leaderboardNameAndType.getA())) { + Window.setTitle(leaderboardName); + leaderboardType = leaderboardNameAndType.getB(); + createUI(showRaceDetails, embedded, hideToolbar, event); + } else { + RootPanel.get().add(new Label(getStringMessages().noSuchLeaderboard())); + } + } + + @Override + public void onFailure(Throwable t) { + reportError("Error trying to obtain list of leaderboard names: " + + t.getMessage()); + } + })); + } + }; + if (eventId == null) { + checkLeaderboardNameAndCreateUI.run(); // use null-initialized event field + } else { + sailingService.getEventById(eventId, /* withStatisticalData */false, new MarkedAsyncCallback( + new AsyncCallback() { + @Override + public void onFailure(Throwable caught) { + reportError("Error trying to obtain event "+eventId+": " + caught.getMessage()); + } + + @Override + public void onSuccess(EventDTO result) { + event = result; + checkLeaderboardNameAndCreateUI.run(); + } + })); + } + } else { + RootPanel.get().add(new Label(getStringMessages().noSuchLeaderboard())); + } + final String zoomTo = Window.Location.getParameter(LeaderboardUrlSettings.PARAM_ZOOM_TO); + if (zoomTo != null) { + RootPanel.getBodyElement().setAttribute( + "style", + "zoom: " + zoomTo + ";-moz-transform: scale(" + zoomTo + + ");-moz-transform-origin: 0 0;-o-transform: scale(" + zoomTo + + ");-o-transform-origin: 0 0;-webkit-transform: scale(" + zoomTo + + ");-webkit-transform-origin: 0 0;"); + } + } + + private void createUI(boolean showRaceDetails, boolean embedded, boolean hideToolbar, EventDTO event) { + DockLayoutPanel mainPanel = new DockLayoutPanel(Unit.PX); + RootLayoutPanel.get().add(mainPanel); + LogoAndTitlePanel logoAndTitlePanel = null; + if (!embedded) { + // Hack to shorten the leaderboardName in case of overall leaderboards + String leaderboardDisplayName = Window.Location.getParameter("displayName"); + if (leaderboardDisplayName == null || leaderboardDisplayName.isEmpty()) { + leaderboardDisplayName = leaderboardName; + } + globalNavigationPanel = new GlobalNavigationPanel(getStringMessages(), true, null, leaderboardGroupName, event, null); + logoAndTitlePanel = new LogoAndTitlePanel(leaderboardGroupName, leaderboardDisplayName, getStringMessages(), this, getUserService()) { + @Override + public void onResize() { + super.onResize(); + if (isSmallWidth()) { + remove(globalNavigationPanel); + } else { + add(globalNavigationPanel); + } + } + }; + logoAndTitlePanel.addStyleName("LogoAndTitlePanel"); + if (!isSmallWidth()) { + logoAndTitlePanel.add(globalNavigationPanel); + } + mainPanel.addNorth(logoAndTitlePanel, 68); + } + ScrollPanel contentScrollPanel = new ScrollPanel(); + long delayBetweenAutoAdvancesInMilliseconds = 3000l; + final RegattaAndRaceIdentifier preselectedRace = getPreselectedRace(Window.Location.getParameterMap()); + // make a single live request as the default but don't continue to play by default + Timer timer = new Timer(PlayModes.Live, PlayStates.Paused, delayBetweenAutoAdvancesInMilliseconds); + final LeaderboardSettings leaderboardSettings = createLeaderboardSettingsFromURLParameters(Window.Location.getParameterMap()); + if (leaderboardSettings.getDelayBetweenAutoAdvancesInMilliseconds() != null) { + timer.setPlayMode(PlayModes.Live); // the leaderboard, viewed via the entry point, goes "live" and "playing" if an auto-refresh + } // interval has been specified + boolean autoExpandLastRaceColumn = GwtHttpRequestUtils.getBooleanParameter(LeaderboardUrlSettings.PARAM_AUTO_EXPAND_LAST_RACE_COLUMN, false); + boolean showCharts = GwtHttpRequestUtils.getBooleanParameter(LeaderboardUrlSettings.PARAM_SHOW_CHARTS, false); + boolean showOverallLeaderboard = GwtHttpRequestUtils.getBooleanParameter(LeaderboardUrlSettings.PARAM_SHOW_OVERALL_LEADERBOARD, false); + boolean showSeriesLeaderboards = GwtHttpRequestUtils.getBooleanParameter(LeaderboardUrlSettings.PARAM_SHOW_SERIES_LEADERBOARDS, false); + String chartDetailParam = GwtHttpRequestUtils.getStringParameter(LeaderboardUrlSettings.PARAM_CHART_DETAIL, null); + final DetailType chartDetailType; + if (chartDetailParam != null && (DetailType.REGATTA_RANK.name().equals(chartDetailParam) || DetailType.OVERALL_RANK.name().equals(chartDetailParam) || + DetailType.REGATTA_TOTAL_POINTS_SUM.name().equals(chartDetailParam))) { + chartDetailType = DetailType.valueOf(chartDetailParam); + } else { + chartDetailType = leaderboardType.isMetaLeaderboard() ? DetailType.OVERALL_RANK : DetailType.REGATTA_RANK; + } + + final Widget leaderboardViewer; + if (leaderboardType.isMetaLeaderboard()) { + leaderboardViewer = new MetaLeaderboardViewer(sailingService, new AsyncActionsExecutor(), + timer, leaderboardSettings, null, preselectedRace, leaderboardGroupName, leaderboardName, this, getStringMessages(), + userAgent, showRaceDetails, hideToolbar, autoExpandLastRaceColumn, showCharts, chartDetailType, showSeriesLeaderboards); + } else { + leaderboardViewer = new LeaderboardViewer(sailingService, new AsyncActionsExecutor(), + timer, leaderboardSettings, preselectedRace, leaderboardGroupName, leaderboardName, this, getStringMessages(), + userAgent, showRaceDetails, hideToolbar, autoExpandLastRaceColumn, showCharts, chartDetailType, showOverallLeaderboard); + } + contentScrollPanel.setWidget(leaderboardViewer); + mainPanel.add(contentScrollPanel); + } + + private RegattaAndRaceIdentifier getPreselectedRace(Map> parameterMap) { + RegattaAndRaceIdentifier result; + if (parameterMap.containsKey(LeaderboardUrlSettings.PARAM_RACE_NAME) && parameterMap.get(LeaderboardUrlSettings.PARAM_RACE_NAME).size() == 1 && + parameterMap.containsKey(LeaderboardUrlSettings.PARAM_REGATTA_NAME) && parameterMap.get(LeaderboardUrlSettings.PARAM_REGATTA_NAME).size() == 1) { + result = new RegattaNameAndRaceName(parameterMap.get(LeaderboardUrlSettings.PARAM_REGATTA_NAME).get(0), parameterMap.get(LeaderboardUrlSettings.PARAM_RACE_NAME).get(0)); + } else { + result = null; + } + return result; + } + + /** + * Constructs {@link LeaderboardSettings} from the URL parameters found + */ + private LeaderboardSettings createLeaderboardSettingsFromURLParameters(Map> parameterMap) { + LeaderboardSettings result; + Long refreshIntervalMillis = parameterMap.containsKey(LeaderboardUrlSettings.PARAM_REFRESH_INTERVAL_MILLIS) ? Long + .valueOf(parameterMap.get(LeaderboardUrlSettings.PARAM_REFRESH_INTERVAL_MILLIS).get(0)) : null; + RaceColumnSelectionStrategies raceColumnSelectionStrategy; + final Integer numberOfLastRacesToShow; + if (parameterMap.containsKey(LeaderboardUrlSettings.PARAM_NAME_LAST_N)) { + raceColumnSelectionStrategy = RaceColumnSelectionStrategies.LAST_N; + numberOfLastRacesToShow = Integer.valueOf(parameterMap.get(LeaderboardUrlSettings.PARAM_NAME_LAST_N).get(0)); + } else if (isSmallWidth()) { + raceColumnSelectionStrategy = RaceColumnSelectionStrategies.LAST_N; + int width = Window.getClientWidth(); + numberOfLastRacesToShow = (width-275)/40; + } else { + raceColumnSelectionStrategy = RaceColumnSelectionStrategies.EXPLICIT; + numberOfLastRacesToShow = null; + } + if (parameterMap.containsKey(LeaderboardUrlSettings.PARAM_RACE_NAME) || parameterMap.containsKey(LeaderboardUrlSettings.PARAM_RACE_DETAIL) || + parameterMap.containsKey(LeaderboardUrlSettings.PARAM_LEG_DETAIL) || parameterMap.containsKey(LeaderboardUrlSettings.PARAM_MANEUVER_DETAIL) || + parameterMap.containsKey(LeaderboardUrlSettings.PARAM_OVERALL_DETAIL) || parameterMap.containsKey(LeaderboardUrlSettings.PARAM_SHOW_ADDED_SCORES) || + parameterMap.containsKey(LeaderboardUrlSettings.PARAM_SHOW_OVERALL_COLUMN_WITH_NUMBER_OF_RACES_COMPLETED) + || parameterMap.containsKey(LeaderboardUrlSettings.PARAM_SHOW_COMPETITOR_NAME_COLUMNS)) { + List maneuverDetails = getDetailTypeListFromParamValue(parameterMap.get(LeaderboardUrlSettings.PARAM_MANEUVER_DETAIL)); + List raceDetails = getDetailTypeListFromParamValue(parameterMap.get(LeaderboardUrlSettings.PARAM_RACE_DETAIL)); + List overallDetails = getDetailTypeListFromParamValue(parameterMap.get(LeaderboardUrlSettings.PARAM_OVERALL_DETAIL)); + if (overallDetails.isEmpty()) { + overallDetails = Collections.singletonList(DetailType.REGATTA_RANK); + } + List legDetails = getDetailTypeListFromParamValue(parameterMap.get(LeaderboardUrlSettings.PARAM_LEG_DETAIL)); + List namesOfRacesToShow = getStringListFromParamValue(parameterMap.get(LeaderboardUrlSettings.PARAM_RACE_NAME)); + boolean showAddedScores = parameterMap.containsKey(LeaderboardUrlSettings.PARAM_SHOW_ADDED_SCORES) ? + Boolean.valueOf(parameterMap.get(LeaderboardUrlSettings.PARAM_SHOW_ADDED_SCORES).get(0)) : false; + boolean showOverallColumnWithNumberOfRacesSailedPerCompetitor = parameterMap.containsKey(LeaderboardUrlSettings.PARAM_SHOW_OVERALL_COLUMN_WITH_NUMBER_OF_RACES_COMPLETED) ? + Boolean.valueOf(parameterMap.get(LeaderboardUrlSettings.PARAM_SHOW_OVERALL_COLUMN_WITH_NUMBER_OF_RACES_COMPLETED).get(0)) : false; + boolean autoExpandPreSelectedRace = parameterMap.containsKey(LeaderboardUrlSettings.PARAM_AUTO_EXPAND_PRESELECTED_RACE) ? + Boolean.valueOf(parameterMap.get(LeaderboardUrlSettings.PARAM_AUTO_EXPAND_PRESELECTED_RACE).get(0)) : + (namesOfRacesToShow != null && namesOfRacesToShow.size() == 1); + boolean showCompetitorSailIdColumn = true; + boolean showCompetitorFullNameColumn = true; + if (parameterMap.containsKey(LeaderboardUrlSettings.PARAM_SHOW_COMPETITOR_NAME_COLUMNS)) { + String value = parameterMap.get(LeaderboardUrlSettings.PARAM_SHOW_COMPETITOR_NAME_COLUMNS).get(0); + if (value.equals(LeaderboardUrlSettings.COMPETITOR_NAME_COLUMN_FULL_NAME)) { + showCompetitorSailIdColumn = false; + } else if (value.equals(LeaderboardUrlSettings.COMPETITOR_NAME_COLUMN_SAIL_ID)) { + showCompetitorFullNameColumn = false; + } else if (value.trim().equals("")) { + showCompetitorFullNameColumn = false; + showCompetitorSailIdColumn = false; + } + } + result = new LeaderboardSettings(maneuverDetails, legDetails, raceDetails, overallDetails, + /* namesOfRaceColumnsToShow */ null, + namesOfRacesToShow, numberOfLastRacesToShow, + autoExpandPreSelectedRace, refreshIntervalMillis, /* sort by column */ (namesOfRacesToShow != null && !namesOfRacesToShow.isEmpty()) ? + namesOfRacesToShow.get(0) : null, + /* ascending */ true, /* updateUponPlayStateChange */ raceDetails.isEmpty() && legDetails.isEmpty(), + raceColumnSelectionStrategy, showAddedScores, showOverallColumnWithNumberOfRacesSailedPerCompetitor, + showCompetitorSailIdColumn, showCompetitorFullNameColumn); + + } else { + final List overallDetails = Collections.singletonList(DetailType.REGATTA_RANK); + result = LeaderboardSettingsFactory.getInstance().createNewDefaultSettings(null, null, + /* overallDetails */ overallDetails, null, + /* autoExpandFirstRace */false, refreshIntervalMillis, numberOfLastRacesToShow, + raceColumnSelectionStrategy); + } + return result; + } + + private List getDetailTypeListFromParamValue(List list) { + List result = new ArrayList(); + 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 getStringListFromParamValue(List list) { + List result = new ArrayList(); + if (list != null) { + result.addAll(list); + } + return result; + } + + /** + * Assembles a dialog that other parts of the application can use to let the user parameterize a leaderboard and + * obtain the according URL for it. This keeps the "secrets" of which URL parameters have which meaning encapsulated + * within this class.

+ * + * The implementation by and large uses the {@link LeaderboardSettingsDialogComponent}'s widget and adds to it a checkbox + * for driving the {@link #LeaderboardUrlSettings.PARAM_EMBEDDED} field. + * + * @see LeaderboardEntryPoint#getUrl(String, LeaderboardSettings, boolean) + */ + public static DataEntryDialog getUrlConfigurationDialog(final AbstractLeaderboardDTO leaderboard, + final StringMessages stringMessages) { + return new LeaderboardUrlConfigurationDialog(stringMessages, leaderboard); + } + +}