diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/app/PlaceNavigator.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/app/PlaceNavigator.java index 4225cc0a314..02f1ea7e2ef 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/app/PlaceNavigator.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/app/PlaceNavigator.java @@ -1,17 +1,14 @@ -package com.sap.sailing.gwt.autoplay.client.app; - -import com.sap.sailing.gwt.autoplay.client.place.player.AutoPlayerConfiguration; -import com.sap.sailing.gwt.autoplay.client.place.player.LeaderboardWithHeaderPerspectiveLifecycle; -import com.sap.sailing.gwt.ui.leaderboard.LeaderboardWithHeaderPerspectiveSettings; -import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveLifecycle; -import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveSettings; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleAndComponentSettings; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleAndSettings; - -public interface PlaceNavigator { - void goToStart(); - void goToPlayer(AutoPlayerConfiguration playerConfig, PerspectiveLifecycleAndSettings leaderboardPerspectiveAndSettings, - PerspectiveLifecycleAndSettings raceboardPerspectiveAndSettings, - PerspectiveLifecycleAndComponentSettings leaderboardPerspectiveComponentLifecyclesAndSettings, - PerspectiveLifecycleAndComponentSettings raceboardPerspectiveComponentLifecyclesAndSettings); -} +package com.sap.sailing.gwt.autoplay.client.app; + +import com.sap.sailing.gwt.autoplay.client.place.player.AutoPlayerConfiguration; +import com.sap.sailing.gwt.autoplay.client.place.player.LeaderboardWithHeaderPerspectiveLifecycle; +import com.sap.sailing.gwt.ui.leaderboard.LeaderboardWithHeaderPerspectiveSettings; +import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveLifecycle; +import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveSettings; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleWithAllSettings; + +public interface PlaceNavigator { + void goToStart(); + void goToPlayer(AutoPlayerConfiguration playerConfig, PerspectiveLifecycleWithAllSettings leaderboardPerspectiveLifecycleWithAllSettings, + PerspectiveLifecycleWithAllSettings raceboardPerspectiveLifecycleWithAllSettings); +} diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/app/PlaceNavigatorImpl.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/app/PlaceNavigatorImpl.java index cc2cde382af..89c00607f84 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/app/PlaceNavigatorImpl.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/app/PlaceNavigatorImpl.java @@ -1,38 +1,35 @@ -package com.sap.sailing.gwt.autoplay.client.app; - -import com.google.gwt.place.shared.PlaceController; -import com.sap.sailing.gwt.autoplay.client.place.player.AutoPlayerConfiguration; -import com.sap.sailing.gwt.autoplay.client.place.player.LeaderboardWithHeaderPerspectiveLifecycle; -import com.sap.sailing.gwt.autoplay.client.place.player.PlayerPlace; -import com.sap.sailing.gwt.autoplay.client.place.start.StartPlace; -import com.sap.sailing.gwt.ui.leaderboard.LeaderboardWithHeaderPerspectiveSettings; -import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveLifecycle; -import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveSettings; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleAndComponentSettings; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleAndSettings; - -public class PlaceNavigatorImpl implements PlaceNavigator { - private final PlaceController placeController; - - protected PlaceNavigatorImpl(PlaceController placeController) { - super(); - this.placeController = placeController; - } - - @Override - public void goToStart() { - placeController.goTo(new StartPlace()); - } - - @Override - public void goToPlayer( - AutoPlayerConfiguration playerConfig,PerspectiveLifecycleAndSettings leaderboardPerspectiveAndSettings, - PerspectiveLifecycleAndSettings raceboardPerspectiveAndSettings, - PerspectiveLifecycleAndComponentSettings leaderboardPerspectiveComponentLifecyclesAndSettings, - PerspectiveLifecycleAndComponentSettings raceboardPerspectiveComponentLifecyclesAndSettings) { - PlayerPlace playerPlace = new PlayerPlace(playerConfig, leaderboardPerspectiveAndSettings, raceboardPerspectiveAndSettings, - leaderboardPerspectiveComponentLifecyclesAndSettings, raceboardPerspectiveComponentLifecyclesAndSettings); - placeController.goTo(playerPlace); - } - -} +package com.sap.sailing.gwt.autoplay.client.app; + +import com.google.gwt.place.shared.PlaceController; +import com.sap.sailing.gwt.autoplay.client.place.player.AutoPlayerConfiguration; +import com.sap.sailing.gwt.autoplay.client.place.player.LeaderboardWithHeaderPerspectiveLifecycle; +import com.sap.sailing.gwt.autoplay.client.place.player.PlayerPlace; +import com.sap.sailing.gwt.autoplay.client.place.start.StartPlace; +import com.sap.sailing.gwt.ui.leaderboard.LeaderboardWithHeaderPerspectiveSettings; +import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveLifecycle; +import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveSettings; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleWithAllSettings; + +public class PlaceNavigatorImpl implements PlaceNavigator { + private final PlaceController placeController; + + protected PlaceNavigatorImpl(PlaceController placeController) { + super(); + this.placeController = placeController; + } + + @Override + public void goToStart() { + placeController.goTo(new StartPlace()); + } + + @Override + public void goToPlayer( + AutoPlayerConfiguration playerConfig, + PerspectiveLifecycleWithAllSettings leaderboardPerspectiveLifecycleWithAllSettings, + PerspectiveLifecycleWithAllSettings raceboardPerspectiveLifecyclesWithAllSettings) { + PlayerPlace playerPlace = new PlayerPlace(playerConfig, leaderboardPerspectiveLifecycleWithAllSettings, raceboardPerspectiveLifecyclesWithAllSettings); + placeController.goTo(playerPlace); + } + +} diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/player/AutoPlayController.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/player/AutoPlayController.java index 2b866f58df8..5c54a2b1278 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/player/AutoPlayController.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/player/AutoPlayController.java @@ -1,242 +1,234 @@ -package com.sap.sailing.gwt.autoplay.client.place.player; - -import java.util.ArrayList; -import java.util.Date; -import java.util.Map; - -import com.google.gwt.user.client.rpc.AsyncCallback; -import com.sap.sailing.domain.common.RaceIdentifier; -import com.sap.sailing.domain.common.RegattaAndRaceIdentifier; -import com.sap.sailing.domain.common.dto.FleetDTO; -import com.sap.sailing.domain.common.dto.LeaderboardDTO; -import com.sap.sailing.domain.common.dto.RaceColumnDTO; -import com.sap.sailing.gwt.ui.client.CompetitorSelectionModel; -import com.sap.sailing.gwt.ui.client.LeaderboardUpdateListener; -import com.sap.sailing.gwt.ui.client.MediaServiceAsync; -import com.sap.sailing.gwt.ui.client.RaceTimesInfoProvider; -import com.sap.sailing.gwt.ui.client.RaceTimesInfoProviderListener; -import com.sap.sailing.gwt.ui.client.SailingServiceAsync; -import com.sap.sailing.gwt.ui.client.StringMessages; -import com.sap.sailing.gwt.ui.leaderboard.LeaderboardWithHeaderPerspectiveSettings; -import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspective; -import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveLifecycle; -import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveSettings; -import com.sap.sailing.gwt.ui.shared.RaceTimesInfoDTO; -import com.sap.sailing.gwt.ui.shared.RaceboardDataDTO; -import com.sap.sse.gwt.client.ErrorReporter; -import com.sap.sse.gwt.client.async.AsyncActionsExecutor; -import com.sap.sse.gwt.client.player.Timer; -import com.sap.sse.gwt.client.player.Timer.PlayModes; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleAndComponentSettings; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleAndSettings; -import com.sap.sse.gwt.client.useragent.UserAgentDetails; -import com.sap.sse.security.ui.client.UserService; - -public class AutoPlayController implements RaceTimesInfoProviderListener, LeaderboardUpdateListener { - private static final int REFRESH_INTERVAL_IN_MILLIS_LEADERBOARD = 10000; - private static final long REFRESH_INTERVAL_IN_MILLIS_RACEBOARD = 1000; - private static final long WAIT_TIME_AFTER_END_OF_RACE_MIILIS = 60 * 1000; // 1 min - private final SailingServiceAsync sailingService; - private final MediaServiceAsync mediaService; - private final UserService userService; - private final ErrorReporter errorReporter; - private final UserAgentDetails userAgent; - private final AsyncActionsExecutor asyncActionsExecutor; - - /** - * We use two timers: one for the leaderboard, one for the race board. This way, we can stop one while the other continues. - * This way, the other component stops its auto-updates. - */ - private final Timer leaderboardTimer; - private final Timer raceboardTimer; - private final RaceTimesInfoProvider raceTimesInfoProvider; - private AutoPlayModes activeTvView; - private boolean isInitialScreen = true; - - // leaderboard perspective related attributes - private LeaderboardDTO currentLeaderboard; - - // raceboard perspective related attributes - private RegattaAndRaceIdentifier currentLiveRace; - - private final PerspectiveLifecycleAndSettings leaderboardPerspectiveLifecycleAndSettings; - private final PerspectiveLifecycleAndSettings raceboardPerspectiveLifecycleAndSettings; - private final PerspectiveLifecycleAndComponentSettings leaderboardPerspectiveComponentLifecyclesAndSettings; - private final PerspectiveLifecycleAndComponentSettings raceboardPerspectiveComponentLifecyclesAndSettings; - private final PlayerView playerView; - private final AutoPlayerConfiguration autoPlayerConfiguration; - - public AutoPlayController(SailingServiceAsync sailingService, MediaServiceAsync mediaService, - UserService userService, ErrorReporter errorReporter, AutoPlayerConfiguration autoPlayerConfiguration, - UserAgentDetails userAgent, long delayToLiveInMillis, boolean showRaceDetails, PlayerView playerView, - PerspectiveLifecycleAndSettings leaderboardPerspectiveLifecycleAndSettings, - PerspectiveLifecycleAndSettings raceboardPerspectiveLifecycleAndSettings, - PerspectiveLifecycleAndComponentSettings leaderboardPerspectiveComponentLifecyclesAndSettings, - PerspectiveLifecycleAndComponentSettings raceboardPerspectiveComponentLifecyclesAndSettings) { - this.sailingService = sailingService; - this.mediaService = mediaService; - this.userService = userService; - this.errorReporter = errorReporter; - this.autoPlayerConfiguration = autoPlayerConfiguration; - this.userAgent = userAgent; - this.playerView = playerView; - this.leaderboardPerspectiveLifecycleAndSettings = leaderboardPerspectiveLifecycleAndSettings; - this.raceboardPerspectiveLifecycleAndSettings = raceboardPerspectiveLifecycleAndSettings; - this.leaderboardPerspectiveComponentLifecyclesAndSettings = leaderboardPerspectiveComponentLifecyclesAndSettings; - this.raceboardPerspectiveComponentLifecyclesAndSettings = raceboardPerspectiveComponentLifecyclesAndSettings; - - asyncActionsExecutor = new AsyncActionsExecutor(); - currentLeaderboard = null; - leaderboardTimer = new Timer(PlayModes.Live, /* delayBetweenAutoAdvancesInMilliseconds */1000l); - leaderboardTimer.setLivePlayDelayInMillis(delayToLiveInMillis); - leaderboardTimer.setRefreshInterval(REFRESH_INTERVAL_IN_MILLIS_LEADERBOARD); - leaderboardTimer.play(); - raceboardTimer = new Timer(PlayModes.Live, /* delayBetweenAutoAdvancesInMilliseconds */1000l); - raceboardTimer.setLivePlayDelayInMillis(delayToLiveInMillis); - raceboardTimer.setRefreshInterval(REFRESH_INTERVAL_IN_MILLIS_RACEBOARD); - raceboardTimer.play(); - - raceTimesInfoProvider = new RaceTimesInfoProvider(sailingService, asyncActionsExecutor, errorReporter, new ArrayList(), 3000l); - raceTimesInfoProvider.addRaceTimesInfoProviderListener(this); - } - - private void showLeaderboard() { - if (activeTvView != AutoPlayModes.Leaderboard) { - playerView.clearContent(); - - boolean withFullscreenButton = autoPlayerConfiguration.isFullscreenMode() && isInitialScreen; - - LeaderboardWithHeaderPerspective leaderboardPerspective = new LeaderboardWithHeaderPerspective(leaderboardPerspectiveLifecycleAndSettings.getSettings(), - leaderboardPerspectiveComponentLifecyclesAndSettings, - sailingService, asyncActionsExecutor, - new CompetitorSelectionModel(/* hasMultiSelection */ true), leaderboardTimer, - autoPlayerConfiguration.getLeaderboardName(), errorReporter, StringMessages.INSTANCE, - userAgent, withFullscreenButton); - - playerView.setContent(leaderboardPerspective); - currentLiveRace = null; - activeTvView = AutoPlayModes.Leaderboard; - raceboardTimer.pause(); - leaderboardTimer.setPlayMode(PlayModes.Live); - - leaderboardPerspective.addLeaderboardUpdateListener(this); - - isInitialScreen = false; - } - } - - private void showRaceBoard() { - if (activeTvView != AutoPlayModes.Raceboard) { - sailingService.getRaceboardData(currentLiveRace.getRegattaName(), currentLiveRace.getRaceName(), - autoPlayerConfiguration.getLeaderboardName(), null, null, new AsyncCallback() { - @Override - public void onSuccess(RaceboardDataDTO result) { - playerView.clearContent(); - - RaceBoardPerspective raceboardPerspective = new RaceBoardPerspective(raceboardPerspectiveLifecycleAndSettings.getSettings(), - raceboardPerspectiveComponentLifecyclesAndSettings, sailingService, mediaService, userService, asyncActionsExecutor, - result.getCompetitorAndTheirBoats(), raceboardTimer, currentLiveRace, autoPlayerConfiguration.getLeaderboardName(), - /** leaderboardGroupName */ null, /** eventId */ null, errorReporter, - StringMessages.INSTANCE, userAgent, raceTimesInfoProvider); - - playerView.setContent(raceboardPerspective); - - activeTvView = AutoPlayModes.Raceboard; - leaderboardTimer.pause(); - raceboardTimer.setPlayMode(PlayModes.Live); - - isInitialScreen = false; - } - - @Override - public void onFailure(Throwable caught) { - errorReporter.reportError("Error while loading data for raceboard: " + caught.getMessage()); - } - }); - - } - } - - public void updatePlayMode(AutoPlayModes tvView) { - switch (tvView) { - case Leaderboard: - showLeaderboard(); - break; - case Raceboard: - showRaceBoard(); - break; - } - } - - @Override - public void raceTimesInfosReceived(Map raceTimesInfo, long clientTimeWhenRequestWasSent, Date serverTimeDuringRequest, long clientTimeWhenResponseWasReceived) { - raceboardTimer.adjustClientServerOffset(clientTimeWhenRequestWasSent, serverTimeDuringRequest, clientTimeWhenResponseWasReceived); - leaderboardTimer.adjustClientServerOffset(clientTimeWhenRequestWasSent, serverTimeDuringRequest, clientTimeWhenResponseWasReceived); - if (currentLiveRace != null) { - RaceTimesInfoDTO currentRaceTimes = raceTimesInfo.get(currentLiveRace); - - Date endOfRace = currentRaceTimes.endOfRace; - if (endOfRace != null && raceboardTimer.getTime().getTime() > endOfRace.getTime() + WAIT_TIME_AFTER_END_OF_RACE_MIILIS - && raceboardTimer.getPlayMode() == PlayModes.Live) { - updatePlayMode(AutoPlayModes.Leaderboard); - } - } else { - currentLiveRace = checkForLiveRace(raceboardTimer.getLiveTimePointInMillis()); - if (currentLiveRace != null) { - updatePlayMode(AutoPlayModes.Raceboard); - } else { - updatePlayMode(AutoPlayModes.Leaderboard); - } - } - } - - private RegattaAndRaceIdentifier checkForLiveRace(long serverTimePointAsMillis) { - RegattaAndRaceIdentifier result = null; - Map raceTimesInfos = raceTimesInfoProvider.getRaceTimesInfos(); - for (RaceColumnDTO race : currentLeaderboard.getRaceList()) { - for (FleetDTO fleet : race.getFleets()) { - RegattaAndRaceIdentifier raceIdentifier = race.getRaceIdentifier(fleet); - if(raceIdentifier != null) { - RaceTimesInfoDTO raceTimes = raceTimesInfos.get(raceIdentifier); - if (raceTimes != null && raceTimes.startOfTracking != null && raceTimes.getStartOfRace() != null && raceTimes.endOfRace == null) { - long startTimeInMs = raceTimes.getStartOfRace().getTime(); - long timeToSwitchBeforeRaceStartInMs = autoPlayerConfiguration.getTimeToSwitchBeforeRaceStartInSeconds() * 1000; - long delayToLiveInMs = raceTimes.delayToLiveInMs; - // the switch to the live race should happen at a defined timepoint before the race start (default is 3 min) - if (serverTimePointAsMillis - delayToLiveInMs > startTimeInMs - timeToSwitchBeforeRaceStartInMs) { - return raceIdentifier; - } - } - } - } - } - return result; - } - - private void updateRaceTimesInfoProvider() { - boolean addedRaces = false; - for (RaceColumnDTO race : currentLeaderboard.getRaceList()) { - for (FleetDTO fleet : race.getFleets()) { - RegattaAndRaceIdentifier raceIdentifier = race.getRaceIdentifier(fleet); - if (raceIdentifier != null && !raceTimesInfoProvider.containsRaceIdentifier(raceIdentifier)) { - raceTimesInfoProvider.addRaceIdentifier(raceIdentifier, false); - addedRaces = true; - } - } - } - if (addedRaces) { - raceTimesInfoProvider.forceTimesInfosUpdate(); - } - } - - @Override - public void updatedLeaderboard(LeaderboardDTO leaderboard) { - this.currentLeaderboard = leaderboard; - updateRaceTimesInfoProvider(); - } - - @Override - public void currentRaceSelected(RaceIdentifier raceIdentifier, RaceColumnDTO raceColumn) { - // no-op - } -} +package com.sap.sailing.gwt.autoplay.client.place.player; + +import java.util.ArrayList; +import java.util.Date; +import java.util.Map; + +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.sap.sailing.domain.common.RaceIdentifier; +import com.sap.sailing.domain.common.RegattaAndRaceIdentifier; +import com.sap.sailing.domain.common.dto.FleetDTO; +import com.sap.sailing.domain.common.dto.LeaderboardDTO; +import com.sap.sailing.domain.common.dto.RaceColumnDTO; +import com.sap.sailing.gwt.ui.client.CompetitorSelectionModel; +import com.sap.sailing.gwt.ui.client.LeaderboardUpdateListener; +import com.sap.sailing.gwt.ui.client.MediaServiceAsync; +import com.sap.sailing.gwt.ui.client.RaceTimesInfoProvider; +import com.sap.sailing.gwt.ui.client.RaceTimesInfoProviderListener; +import com.sap.sailing.gwt.ui.client.SailingServiceAsync; +import com.sap.sailing.gwt.ui.client.StringMessages; +import com.sap.sailing.gwt.ui.leaderboard.LeaderboardWithHeaderPerspectiveSettings; +import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspective; +import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveLifecycle; +import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveSettings; +import com.sap.sailing.gwt.ui.shared.RaceTimesInfoDTO; +import com.sap.sailing.gwt.ui.shared.RaceboardDataDTO; +import com.sap.sse.gwt.client.ErrorReporter; +import com.sap.sse.gwt.client.async.AsyncActionsExecutor; +import com.sap.sse.gwt.client.player.Timer; +import com.sap.sse.gwt.client.player.Timer.PlayModes; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleWithAllSettings; +import com.sap.sse.gwt.client.useragent.UserAgentDetails; +import com.sap.sse.security.ui.client.UserService; + +public class AutoPlayController implements RaceTimesInfoProviderListener, LeaderboardUpdateListener { + private static final int REFRESH_INTERVAL_IN_MILLIS_LEADERBOARD = 10000; + private static final long REFRESH_INTERVAL_IN_MILLIS_RACEBOARD = 1000; + private static final long WAIT_TIME_AFTER_END_OF_RACE_MIILIS = 60 * 1000; // 1 min + private final SailingServiceAsync sailingService; + private final MediaServiceAsync mediaService; + private final UserService userService; + private final ErrorReporter errorReporter; + private final UserAgentDetails userAgent; + private final AsyncActionsExecutor asyncActionsExecutor; + + /** + * We use two timers: one for the leaderboard, one for the race board. This way, we can stop one while the other continues. + * This way, the other component stops its auto-updates. + */ + private final Timer leaderboardTimer; + private final Timer raceboardTimer; + private final RaceTimesInfoProvider raceTimesInfoProvider; + private AutoPlayModes activeTvView; + private boolean isInitialScreen = true; + + // leaderboard perspective related attributes + private LeaderboardDTO currentLeaderboard; + + // raceboard perspective related attributes + private RegattaAndRaceIdentifier currentLiveRace; + + private final PerspectiveLifecycleWithAllSettings leaderboardPerspectiveLifecycleWithAllSettings; + private final PerspectiveLifecycleWithAllSettings raceboardPerspectiveLifecycleWithAllSettings; + private final PlayerView playerView; + private final AutoPlayerConfiguration autoPlayerConfiguration; + + public AutoPlayController(SailingServiceAsync sailingService, MediaServiceAsync mediaService, + UserService userService, ErrorReporter errorReporter, AutoPlayerConfiguration autoPlayerConfiguration, + UserAgentDetails userAgent, long delayToLiveInMillis, boolean showRaceDetails, PlayerView playerView, + PerspectiveLifecycleWithAllSettings leaderboardPerspectiveLifecycleWithAllSettings, + PerspectiveLifecycleWithAllSettings raceboardPerspectiveLifecycleWithAllSettings) { + this.sailingService = sailingService; + this.mediaService = mediaService; + this.userService = userService; + this.errorReporter = errorReporter; + this.autoPlayerConfiguration = autoPlayerConfiguration; + this.userAgent = userAgent; + this.playerView = playerView; + this.leaderboardPerspectiveLifecycleWithAllSettings = leaderboardPerspectiveLifecycleWithAllSettings; + this.raceboardPerspectiveLifecycleWithAllSettings = raceboardPerspectiveLifecycleWithAllSettings; + + asyncActionsExecutor = new AsyncActionsExecutor(); + currentLeaderboard = null; + leaderboardTimer = new Timer(PlayModes.Live, /* delayBetweenAutoAdvancesInMilliseconds */1000l); + leaderboardTimer.setLivePlayDelayInMillis(delayToLiveInMillis); + leaderboardTimer.setRefreshInterval(REFRESH_INTERVAL_IN_MILLIS_LEADERBOARD); + leaderboardTimer.play(); + raceboardTimer = new Timer(PlayModes.Live, /* delayBetweenAutoAdvancesInMilliseconds */1000l); + raceboardTimer.setLivePlayDelayInMillis(delayToLiveInMillis); + raceboardTimer.setRefreshInterval(REFRESH_INTERVAL_IN_MILLIS_RACEBOARD); + raceboardTimer.play(); + + raceTimesInfoProvider = new RaceTimesInfoProvider(sailingService, asyncActionsExecutor, errorReporter, new ArrayList(), 3000l); + raceTimesInfoProvider.addRaceTimesInfoProviderListener(this); + } + + private void showLeaderboard() { + if (activeTvView != AutoPlayModes.Leaderboard) { + playerView.clearContent(); + + boolean withFullscreenButton = autoPlayerConfiguration.isFullscreenMode() && isInitialScreen; + + LeaderboardWithHeaderPerspective leaderboardPerspective = new LeaderboardWithHeaderPerspective(leaderboardPerspectiveLifecycleWithAllSettings, + sailingService, asyncActionsExecutor, + new CompetitorSelectionModel(/* hasMultiSelection */ true), leaderboardTimer, + autoPlayerConfiguration.getLeaderboardName(), errorReporter, StringMessages.INSTANCE, + userAgent, withFullscreenButton); + + playerView.setContent(leaderboardPerspective); + currentLiveRace = null; + activeTvView = AutoPlayModes.Leaderboard; + raceboardTimer.pause(); + leaderboardTimer.setPlayMode(PlayModes.Live); + + leaderboardPerspective.addLeaderboardUpdateListener(this); + + isInitialScreen = false; + } + } + + private void showRaceBoard() { + if (activeTvView != AutoPlayModes.Raceboard) { + sailingService.getRaceboardData(currentLiveRace.getRegattaName(), currentLiveRace.getRaceName(), + autoPlayerConfiguration.getLeaderboardName(), null, null, new AsyncCallback() { + @Override + public void onSuccess(RaceboardDataDTO result) { + playerView.clearContent(); + + RaceBoardPerspective raceboardPerspective = new RaceBoardPerspective(raceboardPerspectiveLifecycleWithAllSettings, + sailingService, mediaService, userService, asyncActionsExecutor, + result.getCompetitorAndTheirBoats(), raceboardTimer, currentLiveRace, autoPlayerConfiguration.getLeaderboardName(), + /** leaderboardGroupName */ null, /** eventId */ null, errorReporter, + StringMessages.INSTANCE, userAgent, raceTimesInfoProvider); + + playerView.setContent(raceboardPerspective); + + activeTvView = AutoPlayModes.Raceboard; + leaderboardTimer.pause(); + raceboardTimer.setPlayMode(PlayModes.Live); + + isInitialScreen = false; + } + + @Override + public void onFailure(Throwable caught) { + errorReporter.reportError("Error while loading data for raceboard: " + caught.getMessage()); + } + }); + + } + } + + public void updatePlayMode(AutoPlayModes tvView) { + switch (tvView) { + case Leaderboard: + showLeaderboard(); + break; + case Raceboard: + showRaceBoard(); + break; + } + } + + @Override + public void raceTimesInfosReceived(Map raceTimesInfo, long clientTimeWhenRequestWasSent, Date serverTimeDuringRequest, long clientTimeWhenResponseWasReceived) { + raceboardTimer.adjustClientServerOffset(clientTimeWhenRequestWasSent, serverTimeDuringRequest, clientTimeWhenResponseWasReceived); + leaderboardTimer.adjustClientServerOffset(clientTimeWhenRequestWasSent, serverTimeDuringRequest, clientTimeWhenResponseWasReceived); + if (currentLiveRace != null) { + RaceTimesInfoDTO currentRaceTimes = raceTimesInfo.get(currentLiveRace); + + Date endOfRace = currentRaceTimes.endOfRace; + if (endOfRace != null && raceboardTimer.getTime().getTime() > endOfRace.getTime() + WAIT_TIME_AFTER_END_OF_RACE_MIILIS + && raceboardTimer.getPlayMode() == PlayModes.Live) { + updatePlayMode(AutoPlayModes.Leaderboard); + } + } else { + currentLiveRace = checkForLiveRace(raceboardTimer.getLiveTimePointInMillis()); + if (currentLiveRace != null) { + updatePlayMode(AutoPlayModes.Raceboard); + } else { + updatePlayMode(AutoPlayModes.Leaderboard); + } + } + } + + private RegattaAndRaceIdentifier checkForLiveRace(long serverTimePointAsMillis) { + RegattaAndRaceIdentifier result = null; + Map raceTimesInfos = raceTimesInfoProvider.getRaceTimesInfos(); + for (RaceColumnDTO race : currentLeaderboard.getRaceList()) { + for (FleetDTO fleet : race.getFleets()) { + RegattaAndRaceIdentifier raceIdentifier = race.getRaceIdentifier(fleet); + if(raceIdentifier != null) { + RaceTimesInfoDTO raceTimes = raceTimesInfos.get(raceIdentifier); + if (raceTimes != null && raceTimes.startOfTracking != null && raceTimes.getStartOfRace() != null && raceTimes.endOfRace == null) { + long startTimeInMs = raceTimes.getStartOfRace().getTime(); + long timeToSwitchBeforeRaceStartInMs = autoPlayerConfiguration.getTimeToSwitchBeforeRaceStartInSeconds() * 1000; + long delayToLiveInMs = raceTimes.delayToLiveInMs; + // the switch to the live race should happen at a defined timepoint before the race start (default is 3 min) + if (serverTimePointAsMillis - delayToLiveInMs > startTimeInMs - timeToSwitchBeforeRaceStartInMs) { + return raceIdentifier; + } + } + } + } + } + return result; + } + + private void updateRaceTimesInfoProvider() { + boolean addedRaces = false; + for (RaceColumnDTO race : currentLeaderboard.getRaceList()) { + for (FleetDTO fleet : race.getFleets()) { + RegattaAndRaceIdentifier raceIdentifier = race.getRaceIdentifier(fleet); + if (raceIdentifier != null && !raceTimesInfoProvider.containsRaceIdentifier(raceIdentifier)) { + raceTimesInfoProvider.addRaceIdentifier(raceIdentifier, false); + addedRaces = true; + } + } + } + if (addedRaces) { + raceTimesInfoProvider.forceTimesInfosUpdate(); + } + } + + @Override + public void updatedLeaderboard(LeaderboardDTO leaderboard) { + this.currentLeaderboard = leaderboard; + updateRaceTimesInfoProvider(); + } + + @Override + public void currentRaceSelected(RaceIdentifier raceIdentifier, RaceColumnDTO raceColumn) { + // no-op + } +} diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/player/LeaderboardWithHeaderPerspective.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/player/LeaderboardWithHeaderPerspective.java index e312d0fbd75..1c191119e42 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/player/LeaderboardWithHeaderPerspective.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/player/LeaderboardWithHeaderPerspective.java @@ -1,248 +1,247 @@ -package com.sap.sailing.gwt.autoplay.client.place.player; - -import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.RepeatingCommand; -import com.google.gwt.dom.client.Style.FontWeight; -import com.google.gwt.dom.client.Style.Unit; -import com.google.gwt.event.logical.shared.ResizeEvent; -import com.google.gwt.event.logical.shared.ResizeHandler; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.ui.DockLayoutPanel; -import com.google.gwt.user.client.ui.Widget; -import com.sap.sailing.gwt.autoplay.client.shared.header.SAPHeader; -import com.sap.sailing.gwt.autoplay.client.shared.header.SAPHeaderLifecycle; -import com.sap.sailing.gwt.autoplay.client.shared.header.SAPHeaderSettings; -import com.sap.sailing.gwt.autoplay.client.shared.oldleaderboard.OldLeaderboard; -import com.sap.sailing.gwt.common.client.CSS3Util; -import com.sap.sailing.gwt.common.client.FullscreenUtil; -import com.sap.sailing.gwt.ui.client.CompetitorSelectionProvider; -import com.sap.sailing.gwt.ui.client.LeaderboardUpdateListener; -import com.sap.sailing.gwt.ui.client.LeaderboardUpdateProvider; -import com.sap.sailing.gwt.ui.client.SailingServiceAsync; -import com.sap.sailing.gwt.ui.client.StringMessages; -import com.sap.sailing.gwt.ui.leaderboard.LeaderboardPanel; -import com.sap.sailing.gwt.ui.leaderboard.LeaderboardPanelLifecycle; -import com.sap.sailing.gwt.ui.leaderboard.LeaderboardSettings; -import com.sap.sailing.gwt.ui.leaderboard.LeaderboardWithHeaderPerspectiveSettings; -import com.sap.sse.gwt.client.ErrorReporter; -import com.sap.sse.gwt.client.async.AsyncActionsExecutor; -import com.sap.sse.gwt.client.player.Timer; -import com.sap.sse.gwt.client.shared.components.SettingsDialogComponent; -import com.sap.sse.gwt.client.shared.perspective.AbstractPerspectiveComposite; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleAndComponentSettings; -import com.sap.sse.gwt.client.useragent.UserAgentDetails; - -/** - * A perspective managing a header with a single leaderboard filling the rest of the screen. - * @author Frank - * - */ -public class LeaderboardWithHeaderPerspective extends AbstractPerspectiveComposite implements LeaderboardUpdateProvider { - private LeaderboardWithHeaderPerspectiveSettings settings; - private final DockLayoutPanel dockPanel; - private final static int SAP_HEADER_HEIGHT = 70; - private final Widget currentContentWidget; - private final LeaderboardPanel leaderboardPanel; - private final LeaderboardWithHeaderPerspectiveLifecycle perspectiveLifecycle; - private final PerspectiveLifecycleAndComponentSettings componentLifecyclesAndSettings; - - public LeaderboardWithHeaderPerspective(LeaderboardWithHeaderPerspectiveSettings perspectiveSettings, - PerspectiveLifecycleAndComponentSettings componentLifecyclesAndSettings, - SailingServiceAsync sailingService, AsyncActionsExecutor asyncActionsExecutor, - CompetitorSelectionProvider competitorSelectionProvider, Timer timer, - String leaderboardName, final ErrorReporter errorReporter, final StringMessages stringMessages, - UserAgentDetails userAgent, boolean startInFullScreenMode) { - super(); - this.settings = perspectiveSettings; - this.perspectiveLifecycle = componentLifecyclesAndSettings.getPerspectiveLifecycle(); - this.componentLifecyclesAndSettings = componentLifecyclesAndSettings; - - Window.addResizeHandler(new ResizeHandler() { - @Override - public void onResize(ResizeEvent event) { - if(LeaderboardWithHeaderPerspective.this.settings.isLeaderboardAutoZoom()) { - autoZoomContentWidget(SAP_HEADER_HEIGHT, currentContentWidget); - } - } - }); - - SAPHeaderLifecycle sapHeaderLifecycle = perspectiveLifecycle.getSapHeaderLifecycle(); - SAPHeader sapHeader = createSAPHeader(sapHeaderLifecycle, componentLifecyclesAndSettings.getComponentSettings().getSettingsOfComponentLifecycle(sapHeaderLifecycle), startInFullScreenMode); - leaderboardPanel = createLeaderboardPanel(sailingService, asyncActionsExecutor, - competitorSelectionProvider, timer, leaderboardName, errorReporter, stringMessages, userAgent); - - leaderboardPanel.getContentWidget().getElement().getStyle().setFontWeight(FontWeight.BOLD); - - components.add(sapHeader); - components.add(leaderboardPanel); - - dockPanel = new DockLayoutPanel(Unit.PX); - dockPanel.addNorth(sapHeader, SAP_HEADER_HEIGHT); - - OldLeaderboard oldLeaderboard = new OldLeaderboard(leaderboardPanel); - leaderboardPanel.addLeaderboardUpdateListener(oldLeaderboard); - - currentContentWidget = oldLeaderboard.getContentWidget(); - - if(settings.isLeaderboardAutoZoom()) { - autoZoomContentWidget(SAP_HEADER_HEIGHT, currentContentWidget); - } else { - Double zoom = settings.getLeaderboardZoomFactor(); - zoomContentWidget(SAP_HEADER_HEIGHT, currentContentWidget, zoom); - } - - dockPanel.add(oldLeaderboard); - - initWidget(dockPanel); - } - - @Override - public String getPerspectiveName() { - return perspectiveLifecycle.getPerspectiveName(); - } - - @Override - public String getLocalizedShortName() { - return perspectiveLifecycle.getLocalizedShortName(); - } - - @Override - public Widget getEntryWidget() { - return this; - } - - @Override - public boolean isVisible() { - return false; - } - - @Override - public void setVisible(boolean visibility) { - } - - @Override - public boolean hasSettings() { - return perspectiveLifecycle.hasSettings(); - } - - @Override - public SettingsDialogComponent getSettingsDialogComponent() { - return perspectiveLifecycle.getSettingsDialogComponent(settings); - } - - @Override - public LeaderboardWithHeaderPerspectiveSettings getSettings() { - return settings; - } - - @Override - public void updateSettings(LeaderboardWithHeaderPerspectiveSettings newSettings) { - this.settings = newSettings; - } - - @Override - public String getDependentCssClassName() { - return ""; - } - - private void zoomContentWidget(final int headerHeight, final Widget contentWidget, final double scaleFactor) { - if(contentWidget != null) { - Scheduler.get().scheduleFixedPeriod(new RepeatingCommand() { - public boolean execute () { - boolean invokeAgain = true; - if(currentContentWidget.getOffsetHeight() > 50) { - scaleContentWidget(headerHeight, contentWidget, scaleFactor); - FullscreenUtil.requestFullscreen(); - - invokeAgain = false; - } - return invokeAgain; - } - }, 1000); - } - } - - private void autoZoomContentWidget(final int headerHeight, final Widget contentWidget) { - if(contentWidget != null) { - Scheduler.get().scheduleFixedPeriod(new RepeatingCommand() { - public boolean execute () { - boolean invokeAgain = true; - if(currentContentWidget.getOffsetHeight() > 50) { - scaleContentWidget(headerHeight, contentWidget); - invokeAgain = false; - } - return invokeAgain; - } - }, 1000); - } - } - - private void scaleContentWidget(int headerHeight, Widget contentWidget, double scaleFactor) { - int clientWidth = Window.getClientWidth(); - int contentWidth = contentWidget.getOffsetWidth(); - - double diffX = clientWidth - contentWidth * scaleFactor; - - scaleContentWidget(headerHeight, contentWidget, scaleFactor, diffX); - } - - private void scaleContentWidget(int headerHeight, Widget contentWidget) { - int clientWidth = Window.getClientWidth(); - int clientHeight = Window.getClientHeight() - headerHeight; - - int contentWidth = contentWidget.getOffsetWidth(); - int contentHeight = contentWidget.getOffsetHeight(); - - double scaleFactorX = clientWidth / (double) contentWidth; - double scaleFactorY = clientHeight / (double) contentHeight; - - Double scaleFactor = scaleFactorX > scaleFactorY ? scaleFactorY : scaleFactorX; - if(scaleFactor < 1.0) { - scaleFactor = 1.0; - } - double diffX = clientWidth - contentWidth * scaleFactor; - - scaleContentWidget(headerHeight, contentWidget, scaleFactor, diffX); - } - - private void scaleContentWidget(int headerHeight, Widget contentWidget, double scaleFactor, double diffX) { - if(scaleFactor > 0.0) { - CSS3Util.setProperty(contentWidget.getElement().getStyle(), "transform", "translateX(" + diffX / 2.0 + "px) scale(" + scaleFactor + ")"); - CSS3Util.setProperty(contentWidget.getElement().getStyle(), "transformOrigin", "0 0"); - } - } - - @Override - public void addLeaderboardUpdateListener(LeaderboardUpdateListener listener) { - leaderboardPanel.addLeaderboardUpdateListener(listener); - } - - @Override - public void removeLeaderboardUpdateListener(LeaderboardUpdateListener listener) { - leaderboardPanel.removeLeaderboardUpdateListener(listener); - } - - private SAPHeader createSAPHeader(SAPHeaderLifecycle componentLifecycle, SAPHeaderSettings settings, - boolean withFullscreenButton) { - return new SAPHeader(componentLifecycle, settings, withFullscreenButton); - } - - private LeaderboardPanel createLeaderboardPanel(SailingServiceAsync sailingService, AsyncActionsExecutor asyncActionsExecutor, - CompetitorSelectionProvider competitorSelectionProvider, Timer timer, - String leaderboardName, final ErrorReporter errorReporter, final StringMessages stringMessages, - final UserAgentDetails userAgent) { - LeaderboardPanelLifecycle leaderboardPanelLifecycle = perspectiveLifecycle.getLeaderboardPanelLifecycle(); - LeaderboardSettings leaderboardSettings = componentLifecyclesAndSettings.getComponentSettings().getSettingsOfComponentLifecycle(leaderboardPanelLifecycle); - - LeaderboardPanel leaderboardPanel = new LeaderboardPanel(sailingService, asyncActionsExecutor, - leaderboardSettings, /*isEmbedded*/true, /* preSelectedRace */null, - competitorSelectionProvider, timer, /* leaderboardGroupName */"", - leaderboardName, errorReporter, stringMessages, - userAgent, /*showRaceDetails */false, /* competitorSearchTextBox */ null, /* showRegattaRank */ - /* showSelectionCheckbox */false, /* raceTimesInfoProvider */null, false, /* autoExpandLastRaceColumn */ - /* adjustTimerDelay */true, /*autoApplyTopNFilter*/ false, false); - - return leaderboardPanel; - } - -} +package com.sap.sailing.gwt.autoplay.client.place.player; + +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.RepeatingCommand; +import com.google.gwt.dom.client.Style.FontWeight; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.event.logical.shared.ResizeEvent; +import com.google.gwt.event.logical.shared.ResizeHandler; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.ui.DockLayoutPanel; +import com.google.gwt.user.client.ui.Widget; +import com.sap.sailing.gwt.autoplay.client.shared.header.SAPHeader; +import com.sap.sailing.gwt.autoplay.client.shared.header.SAPHeaderLifecycle; +import com.sap.sailing.gwt.autoplay.client.shared.header.SAPHeaderSettings; +import com.sap.sailing.gwt.autoplay.client.shared.oldleaderboard.OldLeaderboard; +import com.sap.sailing.gwt.common.client.CSS3Util; +import com.sap.sailing.gwt.common.client.FullscreenUtil; +import com.sap.sailing.gwt.ui.client.CompetitorSelectionProvider; +import com.sap.sailing.gwt.ui.client.LeaderboardUpdateListener; +import com.sap.sailing.gwt.ui.client.LeaderboardUpdateProvider; +import com.sap.sailing.gwt.ui.client.SailingServiceAsync; +import com.sap.sailing.gwt.ui.client.StringMessages; +import com.sap.sailing.gwt.ui.leaderboard.LeaderboardPanel; +import com.sap.sailing.gwt.ui.leaderboard.LeaderboardPanelLifecycle; +import com.sap.sailing.gwt.ui.leaderboard.LeaderboardSettings; +import com.sap.sailing.gwt.ui.leaderboard.LeaderboardWithHeaderPerspectiveSettings; +import com.sap.sse.gwt.client.ErrorReporter; +import com.sap.sse.gwt.client.async.AsyncActionsExecutor; +import com.sap.sse.gwt.client.player.Timer; +import com.sap.sse.gwt.client.shared.components.SettingsDialogComponent; +import com.sap.sse.gwt.client.shared.perspective.AbstractPerspectiveComposite; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleWithAllSettings; +import com.sap.sse.gwt.client.useragent.UserAgentDetails; + +/** + * A perspective managing a header with a single leaderboard filling the rest of the screen. + * @author Frank + * + */ +public class LeaderboardWithHeaderPerspective extends AbstractPerspectiveComposite implements LeaderboardUpdateProvider { + private LeaderboardWithHeaderPerspectiveSettings settings; + private final DockLayoutPanel dockPanel; + private final static int SAP_HEADER_HEIGHT = 70; + private final Widget currentContentWidget; + private final LeaderboardPanel leaderboardPanel; + private final LeaderboardWithHeaderPerspectiveLifecycle perspectiveLifecycle; + private final PerspectiveLifecycleWithAllSettings componentLifecyclesAndSettings; + + public LeaderboardWithHeaderPerspective(PerspectiveLifecycleWithAllSettings perspectiveLifecycleWithAllSettings, + SailingServiceAsync sailingService, AsyncActionsExecutor asyncActionsExecutor, + CompetitorSelectionProvider competitorSelectionProvider, Timer timer, + String leaderboardName, final ErrorReporter errorReporter, final StringMessages stringMessages, + UserAgentDetails userAgent, boolean startInFullScreenMode) { + super(); + this.settings = perspectiveLifecycleWithAllSettings.getPerspectiveSettings(); + this.perspectiveLifecycle = perspectiveLifecycleWithAllSettings.getPerspectiveLifecycle(); + this.componentLifecyclesAndSettings = perspectiveLifecycleWithAllSettings; + + Window.addResizeHandler(new ResizeHandler() { + @Override + public void onResize(ResizeEvent event) { + if(LeaderboardWithHeaderPerspective.this.settings.isLeaderboardAutoZoom()) { + autoZoomContentWidget(SAP_HEADER_HEIGHT, currentContentWidget); + } + } + }); + + SAPHeaderLifecycle sapHeaderLifecycle = perspectiveLifecycle.getSapHeaderLifecycle(); + SAPHeader sapHeader = createSAPHeader(sapHeaderLifecycle, perspectiveLifecycleWithAllSettings.getComponentSettings().getSettingsOfComponentLifecycle(sapHeaderLifecycle), startInFullScreenMode); + leaderboardPanel = createLeaderboardPanel(sailingService, asyncActionsExecutor, + competitorSelectionProvider, timer, leaderboardName, errorReporter, stringMessages, userAgent); + + leaderboardPanel.getContentWidget().getElement().getStyle().setFontWeight(FontWeight.BOLD); + + components.add(sapHeader); + components.add(leaderboardPanel); + + dockPanel = new DockLayoutPanel(Unit.PX); + dockPanel.addNorth(sapHeader, SAP_HEADER_HEIGHT); + + OldLeaderboard oldLeaderboard = new OldLeaderboard(leaderboardPanel); + leaderboardPanel.addLeaderboardUpdateListener(oldLeaderboard); + + currentContentWidget = oldLeaderboard.getContentWidget(); + + if(settings.isLeaderboardAutoZoom()) { + autoZoomContentWidget(SAP_HEADER_HEIGHT, currentContentWidget); + } else { + Double zoom = settings.getLeaderboardZoomFactor(); + zoomContentWidget(SAP_HEADER_HEIGHT, currentContentWidget, zoom); + } + + dockPanel.add(oldLeaderboard); + + initWidget(dockPanel); + } + + @Override + public String getPerspectiveName() { + return perspectiveLifecycle.getPerspectiveName(); + } + + @Override + public String getLocalizedShortName() { + return perspectiveLifecycle.getLocalizedShortName(); + } + + @Override + public Widget getEntryWidget() { + return this; + } + + @Override + public boolean isVisible() { + return false; + } + + @Override + public void setVisible(boolean visibility) { + } + + @Override + public boolean hasSettings() { + return perspectiveLifecycle.hasSettings(); + } + + @Override + public SettingsDialogComponent getSettingsDialogComponent() { + return perspectiveLifecycle.getSettingsDialogComponent(settings); + } + + @Override + public LeaderboardWithHeaderPerspectiveSettings getSettings() { + return settings; + } + + @Override + public void updateSettings(LeaderboardWithHeaderPerspectiveSettings newSettings) { + this.settings = newSettings; + } + + @Override + public String getDependentCssClassName() { + return ""; + } + + private void zoomContentWidget(final int headerHeight, final Widget contentWidget, final double scaleFactor) { + if(contentWidget != null) { + Scheduler.get().scheduleFixedPeriod(new RepeatingCommand() { + public boolean execute () { + boolean invokeAgain = true; + if(currentContentWidget.getOffsetHeight() > 50) { + scaleContentWidget(headerHeight, contentWidget, scaleFactor); + FullscreenUtil.requestFullscreen(); + + invokeAgain = false; + } + return invokeAgain; + } + }, 1000); + } + } + + private void autoZoomContentWidget(final int headerHeight, final Widget contentWidget) { + if(contentWidget != null) { + Scheduler.get().scheduleFixedPeriod(new RepeatingCommand() { + public boolean execute () { + boolean invokeAgain = true; + if(currentContentWidget.getOffsetHeight() > 50) { + scaleContentWidget(headerHeight, contentWidget); + invokeAgain = false; + } + return invokeAgain; + } + }, 1000); + } + } + + private void scaleContentWidget(int headerHeight, Widget contentWidget, double scaleFactor) { + int clientWidth = Window.getClientWidth(); + int contentWidth = contentWidget.getOffsetWidth(); + + double diffX = clientWidth - contentWidth * scaleFactor; + + scaleContentWidget(headerHeight, contentWidget, scaleFactor, diffX); + } + + private void scaleContentWidget(int headerHeight, Widget contentWidget) { + int clientWidth = Window.getClientWidth(); + int clientHeight = Window.getClientHeight() - headerHeight; + + int contentWidth = contentWidget.getOffsetWidth(); + int contentHeight = contentWidget.getOffsetHeight(); + + double scaleFactorX = clientWidth / (double) contentWidth; + double scaleFactorY = clientHeight / (double) contentHeight; + + Double scaleFactor = scaleFactorX > scaleFactorY ? scaleFactorY : scaleFactorX; + if(scaleFactor < 1.0) { + scaleFactor = 1.0; + } + double diffX = clientWidth - contentWidth * scaleFactor; + + scaleContentWidget(headerHeight, contentWidget, scaleFactor, diffX); + } + + private void scaleContentWidget(int headerHeight, Widget contentWidget, double scaleFactor, double diffX) { + if(scaleFactor > 0.0) { + CSS3Util.setProperty(contentWidget.getElement().getStyle(), "transform", "translateX(" + diffX / 2.0 + "px) scale(" + scaleFactor + ")"); + CSS3Util.setProperty(contentWidget.getElement().getStyle(), "transformOrigin", "0 0"); + } + } + + @Override + public void addLeaderboardUpdateListener(LeaderboardUpdateListener listener) { + leaderboardPanel.addLeaderboardUpdateListener(listener); + } + + @Override + public void removeLeaderboardUpdateListener(LeaderboardUpdateListener listener) { + leaderboardPanel.removeLeaderboardUpdateListener(listener); + } + + private SAPHeader createSAPHeader(SAPHeaderLifecycle componentLifecycle, SAPHeaderSettings settings, + boolean withFullscreenButton) { + return new SAPHeader(componentLifecycle, settings, withFullscreenButton); + } + + private LeaderboardPanel createLeaderboardPanel(SailingServiceAsync sailingService, AsyncActionsExecutor asyncActionsExecutor, + CompetitorSelectionProvider competitorSelectionProvider, Timer timer, + String leaderboardName, final ErrorReporter errorReporter, final StringMessages stringMessages, + final UserAgentDetails userAgent) { + LeaderboardPanelLifecycle leaderboardPanelLifecycle = perspectiveLifecycle.getLeaderboardPanelLifecycle(); + LeaderboardSettings leaderboardSettings = componentLifecyclesAndSettings.getComponentSettings().getSettingsOfComponentLifecycle(leaderboardPanelLifecycle); + + LeaderboardPanel leaderboardPanel = new LeaderboardPanel(sailingService, asyncActionsExecutor, + leaderboardSettings, /*isEmbedded*/true, /* preSelectedRace */null, + competitorSelectionProvider, timer, /* leaderboardGroupName */"", + leaderboardName, errorReporter, stringMessages, + userAgent, /*showRaceDetails */false, /* competitorSearchTextBox */ null, /* showRegattaRank */ + /* showSelectionCheckbox */false, /* raceTimesInfoProvider */null, false, /* autoExpandLastRaceColumn */ + /* adjustTimerDelay */true, /*autoApplyTopNFilter*/ false, false); + + return leaderboardPanel; + } + +} diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/player/PlayerActivity.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/player/PlayerActivity.java index b2847ae2b72..d2e3019ccaa 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/player/PlayerActivity.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/player/PlayerActivity.java @@ -1,64 +1,63 @@ -package com.sap.sailing.gwt.autoplay.client.place.player; - -import java.util.UUID; - -import com.google.gwt.activity.shared.AbstractActivity; -import com.google.gwt.event.shared.EventBus; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.rpc.AsyncCallback; -import com.google.gwt.user.client.ui.AcceptsOneWidget; -import com.sap.sailing.gwt.ui.shared.EventDTO; -import com.sap.sse.gwt.client.mvp.ErrorView; -import com.sap.sse.gwt.client.useragent.UserAgentDetails; -import com.sap.sse.gwt.shared.GwtHttpRequestUtils; - -public class PlayerActivity extends AbstractActivity { - private final PlayerClientFactory clientFactory; - private final PlayerPlace playerPlace; - private AutoPlayController autoPlayController; - - private static final String PARAM_SHOW_RACE_DETAILS = "showRaceDetails"; - private static final String PARAM_DELAY_TO_LIVE_MILLIS = "delayToLiveMillis"; - - public PlayerActivity(PlayerPlace playerPlace, PlayerClientFactory clientFactory) { - this.playerPlace = playerPlace; - this.clientFactory = clientFactory; - this.autoPlayController = null; - } - - @Override - public void start(final AcceptsOneWidget panel, EventBus eventBus) { - final boolean showRaceDetails = GwtHttpRequestUtils.getBooleanParameter(PARAM_SHOW_RACE_DETAILS, false); - final long delayToLiveMillis = Window.Location.getParameter(PARAM_DELAY_TO_LIVE_MILLIS) != null ? Long - .valueOf(Window.Location.getParameter(PARAM_DELAY_TO_LIVE_MILLIS)) : 5000l; // default 5s - - UUID eventUUID = UUID.fromString(playerPlace.getConfiguration().getEventUidAsString()); - clientFactory.getSailingService().getEventById(eventUUID, true, new AsyncCallback() { - @Override - public void onSuccess(final EventDTO event) { - UserAgentDetails userAgent = new UserAgentDetails(Window.Navigator.getUserAgent()); - - PlayerView view = clientFactory.createPlayerView(); - panel.setWidget(view.asWidget()); - - autoPlayController = new AutoPlayController(clientFactory.getSailingService(), clientFactory - .getMediaService(), clientFactory.getUserService(), clientFactory.getErrorReporter(), - playerPlace.getConfiguration(), userAgent, delayToLiveMillis, showRaceDetails, view, - playerPlace.getLeaderboardPerspectiveLifecycleAndSettings(), playerPlace.getRaceboardPerspectiveLifecycleAndSettings(), - playerPlace.getLeaderboardPerspectiveComponentLifecyclesAndSettings(), - playerPlace.getRaceboardPerspectiveComponentLifecyclesAndSettings()); - autoPlayController.updatePlayMode(AutoPlayModes.Leaderboard); - } - - @Override - public void onFailure(Throwable caught) { - createErrorView("Error while loading the event with service getEventById()", caught, panel); - } - }); - } - - private void createErrorView(String errorMessage, Throwable errorReason, AcceptsOneWidget panel) { - ErrorView view = clientFactory.createErrorView(errorMessage, errorReason); - panel.setWidget(view.asWidget()); - } -} +package com.sap.sailing.gwt.autoplay.client.place.player; + +import java.util.UUID; + +import com.google.gwt.activity.shared.AbstractActivity; +import com.google.gwt.event.shared.EventBus; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.AcceptsOneWidget; +import com.sap.sailing.gwt.ui.shared.EventDTO; +import com.sap.sse.gwt.client.mvp.ErrorView; +import com.sap.sse.gwt.client.useragent.UserAgentDetails; +import com.sap.sse.gwt.shared.GwtHttpRequestUtils; + +public class PlayerActivity extends AbstractActivity { + private final PlayerClientFactory clientFactory; + private final PlayerPlace playerPlace; + private AutoPlayController autoPlayController; + + private static final String PARAM_SHOW_RACE_DETAILS = "showRaceDetails"; + private static final String PARAM_DELAY_TO_LIVE_MILLIS = "delayToLiveMillis"; + + public PlayerActivity(PlayerPlace playerPlace, PlayerClientFactory clientFactory) { + this.playerPlace = playerPlace; + this.clientFactory = clientFactory; + this.autoPlayController = null; + } + + @Override + public void start(final AcceptsOneWidget panel, EventBus eventBus) { + final boolean showRaceDetails = GwtHttpRequestUtils.getBooleanParameter(PARAM_SHOW_RACE_DETAILS, false); + final long delayToLiveMillis = Window.Location.getParameter(PARAM_DELAY_TO_LIVE_MILLIS) != null ? Long + .valueOf(Window.Location.getParameter(PARAM_DELAY_TO_LIVE_MILLIS)) : 5000l; // default 5s + + UUID eventUUID = UUID.fromString(playerPlace.getConfiguration().getEventUidAsString()); + clientFactory.getSailingService().getEventById(eventUUID, true, new AsyncCallback() { + @Override + public void onSuccess(final EventDTO event) { + UserAgentDetails userAgent = new UserAgentDetails(Window.Navigator.getUserAgent()); + + PlayerView view = clientFactory.createPlayerView(); + panel.setWidget(view.asWidget()); + + autoPlayController = new AutoPlayController(clientFactory.getSailingService(), clientFactory + .getMediaService(), clientFactory.getUserService(), clientFactory.getErrorReporter(), + playerPlace.getConfiguration(), userAgent, delayToLiveMillis, showRaceDetails, view, + playerPlace.getLeaderboardPerspectiveLifecycleWithAllSettings(), + playerPlace.getRaceboardPerspectiveLifecycleWithAllSettings()); + autoPlayController.updatePlayMode(AutoPlayModes.Leaderboard); + } + + @Override + public void onFailure(Throwable caught) { + createErrorView("Error while loading the event with service getEventById()", caught, panel); + } + }); + } + + private void createErrorView(String errorMessage, Throwable errorReason, AcceptsOneWidget panel) { + ErrorView view = clientFactory.createErrorView(errorMessage, errorReason); + panel.setWidget(view.asWidget()); + } +} diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/player/PlayerPlace.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/player/PlayerPlace.java index e93d661bf93..99ba920d64e 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/player/PlayerPlace.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/player/PlayerPlace.java @@ -1,82 +1,64 @@ -package com.sap.sailing.gwt.autoplay.client.place.player; - -import com.google.gwt.place.shared.PlaceTokenizer; -import com.sap.sailing.gwt.common.client.AbstractBasePlace; -import com.sap.sailing.gwt.ui.leaderboard.LeaderboardWithHeaderPerspectiveSettings; -import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveLifecycle; -import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveSettings; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleAndComponentSettings; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleAndSettings; - -public class PlayerPlace extends AbstractBasePlace { - private final AutoPlayerConfiguration playerConfiguration; - - private final PerspectiveLifecycleAndSettings leaderboardPerspectiveLifecycleAndSettings; - private final PerspectiveLifecycleAndSettings raceboardPerspectiveLifecycleAndSettings; - - private final PerspectiveLifecycleAndComponentSettings leaderboardPerspectiveComponentLifecyclesAndSettings; - private final PerspectiveLifecycleAndComponentSettings raceboardPerspectiveComponentLifecyclesAndSettings; - - public PlayerPlace(String url) { - super(url); - - String eventUuidAsString = getParameter(AutoPlayerConfiguration.PARAM_EVENTID); - String leaderboardName= getParameter(AutoPlayerConfiguration.PARAM_LEADEROARD_NAME); - Boolean fullscreen = Boolean.valueOf(getParameter(AutoPlayerConfiguration.PARAM_FULLSCREEN)); - Integer timeToSwitchBeforeRaceStartInSeconds = Integer.valueOf(getParameter(AutoPlayerConfiguration.PARAM_TIME_TO_SWITCH_BEFORE_RACE_START)); - - this.playerConfiguration = new AutoPlayerConfiguration(eventUuidAsString, leaderboardName, fullscreen, timeToSwitchBeforeRaceStartInSeconds); - this.leaderboardPerspectiveLifecycleAndSettings = null; - this.raceboardPerspectiveLifecycleAndSettings = null; - this.leaderboardPerspectiveComponentLifecyclesAndSettings = null; - this.raceboardPerspectiveComponentLifecyclesAndSettings = null; - } - - public PlayerPlace(AutoPlayerConfiguration playerConfiguration, - PerspectiveLifecycleAndSettings leaderboardPerspectiveLifecyleAndSettings, - PerspectiveLifecycleAndSettings raceboardPerspectiveLifecyleAndSettings, - PerspectiveLifecycleAndComponentSettings leaderboardPerspectiveComponentLifecyclesAndSettings, - PerspectiveLifecycleAndComponentSettings raceboardPerspectiveComponentLifecyclesAndSettings) { - super(AutoPlayerConfiguration.PARAM_EVENTID, playerConfiguration.getEventUidAsString(), - AutoPlayerConfiguration.PARAM_FULLSCREEN, String.valueOf(playerConfiguration.isFullscreenMode()), - AutoPlayerConfiguration.PARAM_LEADEROARD_NAME, playerConfiguration.getLeaderboardName(), - AutoPlayerConfiguration.PARAM_TIME_TO_SWITCH_BEFORE_RACE_START, String.valueOf(playerConfiguration.getTimeToSwitchBeforeRaceStartInSeconds())); - this.playerConfiguration = playerConfiguration; - this.leaderboardPerspectiveLifecycleAndSettings = leaderboardPerspectiveLifecyleAndSettings; - this.raceboardPerspectiveLifecycleAndSettings = raceboardPerspectiveLifecyleAndSettings; - this.leaderboardPerspectiveComponentLifecyclesAndSettings = leaderboardPerspectiveComponentLifecyclesAndSettings; - this.raceboardPerspectiveComponentLifecyclesAndSettings = raceboardPerspectiveComponentLifecyclesAndSettings; - } - - public AutoPlayerConfiguration getConfiguration() { - return this.playerConfiguration; - } - - public static class Tokenizer implements PlaceTokenizer { - @Override - public String getToken(PlayerPlace place) { - return place.getParametersAsToken(); - } - - @Override - public PlayerPlace getPlace(String url) { - return new PlayerPlace(url); - } - } - - public PerspectiveLifecycleAndSettings getLeaderboardPerspectiveLifecycleAndSettings() { - return leaderboardPerspectiveLifecycleAndSettings; - } - - public PerspectiveLifecycleAndSettings getRaceboardPerspectiveLifecycleAndSettings() { - return raceboardPerspectiveLifecycleAndSettings; - } - - public PerspectiveLifecycleAndComponentSettings getLeaderboardPerspectiveComponentLifecyclesAndSettings() { - return leaderboardPerspectiveComponentLifecyclesAndSettings; - } - - public PerspectiveLifecycleAndComponentSettings getRaceboardPerspectiveComponentLifecyclesAndSettings() { - return raceboardPerspectiveComponentLifecyclesAndSettings; - } -} +package com.sap.sailing.gwt.autoplay.client.place.player; + +import com.google.gwt.place.shared.PlaceTokenizer; +import com.sap.sailing.gwt.common.client.AbstractBasePlace; +import com.sap.sailing.gwt.ui.leaderboard.LeaderboardWithHeaderPerspectiveSettings; +import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveLifecycle; +import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveSettings; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleWithAllSettings; + +public class PlayerPlace extends AbstractBasePlace { + private final AutoPlayerConfiguration playerConfiguration; + + private final PerspectiveLifecycleWithAllSettings leaderboardPerspectiveLifecycleWithAllSettings; + private final PerspectiveLifecycleWithAllSettings raceboardPerspectiveLifecycleWithAllSettings; + + public PlayerPlace(String url) { + super(url); + + String eventUuidAsString = getParameter(AutoPlayerConfiguration.PARAM_EVENTID); + String leaderboardName= getParameter(AutoPlayerConfiguration.PARAM_LEADEROARD_NAME); + Boolean fullscreen = Boolean.valueOf(getParameter(AutoPlayerConfiguration.PARAM_FULLSCREEN)); + Integer timeToSwitchBeforeRaceStartInSeconds = Integer.valueOf(getParameter(AutoPlayerConfiguration.PARAM_TIME_TO_SWITCH_BEFORE_RACE_START)); + + this.playerConfiguration = new AutoPlayerConfiguration(eventUuidAsString, leaderboardName, fullscreen, timeToSwitchBeforeRaceStartInSeconds); + this.leaderboardPerspectiveLifecycleWithAllSettings = null; + this.raceboardPerspectiveLifecycleWithAllSettings = null; + } + + public PlayerPlace(AutoPlayerConfiguration playerConfiguration, + PerspectiveLifecycleWithAllSettings leaderboardPerspectiveLifecycleWithAllSettings, + PerspectiveLifecycleWithAllSettings raceboardPerspectiveLifecycleWithAllSettings) { + super(AutoPlayerConfiguration.PARAM_EVENTID, playerConfiguration.getEventUidAsString(), + AutoPlayerConfiguration.PARAM_FULLSCREEN, String.valueOf(playerConfiguration.isFullscreenMode()), + AutoPlayerConfiguration.PARAM_LEADEROARD_NAME, playerConfiguration.getLeaderboardName(), + AutoPlayerConfiguration.PARAM_TIME_TO_SWITCH_BEFORE_RACE_START, String.valueOf(playerConfiguration.getTimeToSwitchBeforeRaceStartInSeconds())); + this.playerConfiguration = playerConfiguration; + this.leaderboardPerspectiveLifecycleWithAllSettings = leaderboardPerspectiveLifecycleWithAllSettings; + this.raceboardPerspectiveLifecycleWithAllSettings = raceboardPerspectiveLifecycleWithAllSettings; + } + + public AutoPlayerConfiguration getConfiguration() { + return this.playerConfiguration; + } + + public static class Tokenizer implements PlaceTokenizer { + @Override + public String getToken(PlayerPlace place) { + return place.getParametersAsToken(); + } + + @Override + public PlayerPlace getPlace(String url) { + return new PlayerPlace(url); + } + } + + public PerspectiveLifecycleWithAllSettings getLeaderboardPerspectiveLifecycleWithAllSettings() { + return leaderboardPerspectiveLifecycleWithAllSettings; + } + + public PerspectiveLifecycleWithAllSettings getRaceboardPerspectiveLifecycleWithAllSettings() { + return raceboardPerspectiveLifecycleWithAllSettings; + } +} diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/start/DesktopStartView.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/start/DesktopStartView.java index a28519639a5..e6170f48aae 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/start/DesktopStartView.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/start/DesktopStartView.java @@ -1,325 +1,294 @@ -package com.sap.sailing.gwt.autoplay.client.place.start; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.DivElement; -import com.google.gwt.dom.client.Style.Unit; -import com.google.gwt.dom.client.Style.Visibility; -import com.google.gwt.event.dom.client.ChangeEvent; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.i18n.client.LocaleInfo; -import com.google.gwt.uibinder.client.UiBinder; -import com.google.gwt.uibinder.client.UiField; -import com.google.gwt.uibinder.client.UiHandler; -import com.google.gwt.user.client.ui.Button; -import com.google.gwt.user.client.ui.CheckBox; -import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.FlowPanel; -import com.google.gwt.user.client.ui.IntegerBox; -import com.google.gwt.user.client.ui.ListBox; -import com.google.gwt.user.client.ui.Widget; -import com.google.web.bindery.event.shared.EventBus; -import com.sap.sailing.domain.common.dto.AbstractLeaderboardDTO; -import com.sap.sailing.gwt.autoplay.client.app.PlaceNavigator; -import com.sap.sailing.gwt.autoplay.client.place.player.AutoPlayerConfiguration; -import com.sap.sailing.gwt.autoplay.client.place.player.LeaderboardWithHeaderPerspectiveLifecycle; -import com.sap.sailing.gwt.autoplay.client.shared.header.SAPHeader; -import com.sap.sailing.gwt.autoplay.client.shared.header.SAPHeaderLifecycle; -import com.sap.sailing.gwt.common.client.SharedResources; -import com.sap.sailing.gwt.common.client.i18n.TextMessages; -import com.sap.sailing.gwt.ui.client.StringMessages; -import com.sap.sailing.gwt.ui.leaderboard.LeaderboardWithHeaderPerspectiveSettings; -import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveLifecycle; -import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveSettings; -import com.sap.sailing.gwt.ui.shared.EventDTO; -import com.sap.sailing.gwt.ui.shared.LeaderboardGroupDTO; -import com.sap.sailing.gwt.ui.shared.StrippedLeaderboardDTO; -import com.sap.sse.common.settings.Settings; -import com.sap.sse.gwt.client.dialog.DataEntryDialog.DialogCallback; -import com.sap.sse.gwt.client.event.LocaleChangeEvent; -import com.sap.sse.gwt.client.shared.components.CompositeLifecycleSettings; -import com.sap.sse.gwt.client.shared.components.LifecycleSettingsDialog; -import com.sap.sse.gwt.client.shared.components.SettingsDialogComponent; -import com.sap.sse.gwt.client.shared.perspective.Perspective; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycle; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleAndComponentSettings; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleAndSettings; - -public class DesktopStartView extends Composite implements StartView { - private static StartPageViewUiBinder uiBinder = GWT.create(StartPageViewUiBinder.class); - - interface StartPageViewUiBinder extends UiBinder { - } - - @UiField(provided=true) SAPHeader sapHeader; - @UiField(provided=true) ListBox localeSelectionBox; - @UiField(provided=true) ListBox eventSelectionBox; - @UiField(provided=true) ListBox leaderboardSelectionBox; - @UiField CheckBox startInFullscreenModeBox; - @UiField Button startAutoPlayButton; - @UiField DivElement leaderboardSelectionUi; - @UiField DivElement screenConfigurationUi; - @UiField FlowPanel leaderboardPerspectiveSettingsPanel; - @UiField FlowPanel raceboardPerspectiveSettingsPanel; - - @UiField CheckBox autoSwitchToRaceboard; - @UiField IntegerBox timeToRaceStartInSeconds; - - private final PlaceNavigator navigator; - private final EventBus eventBus; - private final List events; - - private PerspectiveLifecycleAndSettings leaderboardPerspectiveLifecycleAndSettings; - private PerspectiveLifecycleAndSettings raceboardPerspectiveLifecycleAndSettings; - - private PerspectiveLifecycleAndComponentSettings leaderboardPerspectiveComponentLifecyclesAndSettings; - private PerspectiveLifecycleAndComponentSettings raceboardPerspectiveComponentLifecyclesAndSettings; - - private final int defaultTimeToRaceStartTimeInSeconds = 180; - - public DesktopStartView(PlaceNavigator navigator, EventBus eventBus) { - super(); - this.navigator = navigator; - this.eventBus = eventBus; - this.events = new ArrayList(); - - SAPHeaderLifecycle sapHeaderLifecycle = new SAPHeaderLifecycle(TextMessages.INSTANCE.autoPlayerConfiguration(), StringMessages.INSTANCE); - sapHeader = new SAPHeader(sapHeaderLifecycle, sapHeaderLifecycle.createDefaultSettings(), false); - eventSelectionBox = new ListBox(); - eventSelectionBox.setMultipleSelect(false); - leaderboardSelectionBox = new ListBox(); - leaderboardSelectionBox.setMultipleSelect(false); - localeSelectionBox = new ListBox(); - localeSelectionBox.setMultipleSelect(false); - - LocaleInfo currentLocale = LocaleInfo.getCurrentLocale(); - int i = 0; - for (String localeName : LocaleInfo.getAvailableLocaleNames()) { - if (!localeName.equals("default")) { - String displayName = LocaleInfo.getLocaleNativeDisplayName(localeName); - localeSelectionBox.addItem(displayName); - if (currentLocale.getLocaleName().equals(localeName)) { - localeSelectionBox.setSelectedIndex(i); - } - i++; - } - } - - initWidget(uiBinder.createAndBindUi(this)); - this.ensureDebugId("AutoPlayStartView"); - - startInFullscreenModeBox.setValue(true); - autoSwitchToRaceboard.setValue(true); - timeToRaceStartInSeconds.setValue(defaultTimeToRaceStartTimeInSeconds); - - leaderboardSelectionUi.getStyle().setVisibility(Visibility.HIDDEN); - screenConfigurationUi.getStyle().setVisibility(Visibility.HIDDEN); - - startAutoPlayButton.setEnabled(false); - startAutoPlayButton.addStyleName(SharedResources.INSTANCE.mainCss().buttoninactive()); - } - - private void updatePerspectives(AbstractLeaderboardDTO leaderboard) { - LeaderboardWithHeaderPerspectiveLifecycle leaderboardPerspectiveLifecycle = new LeaderboardWithHeaderPerspectiveLifecycle(leaderboard, StringMessages.INSTANCE); - LeaderboardWithHeaderPerspectiveSettings leaderboardPerspectiveSettings = leaderboardPerspectiveLifecycle.createDefaultSettings(); - - CompositeLifecycleSettings leaderboardPerspectiveComponentsLifecyclesAndSettings = leaderboardPerspectiveLifecycle.getComponentLifecyclesAndDefaultSettings(); - leaderboardPerspectiveComponentLifecyclesAndSettings = new PerspectiveLifecycleAndComponentSettings<>(leaderboardPerspectiveLifecycle, - leaderboardPerspectiveComponentsLifecyclesAndSettings); - - RaceBoardPerspectiveLifecycle raceboardPerspectiveLifecycle = new RaceBoardPerspectiveLifecycle(leaderboard, StringMessages.INSTANCE); - RaceBoardPerspectiveSettings raceboardPerspectiveSettings = raceboardPerspectiveLifecycle.createDefaultSettings(); - - CompositeLifecycleSettings raceboardPerspectiveComponentsLifecyclesAndSettings = raceboardPerspectiveLifecycle.getComponentLifecyclesAndDefaultSettings(); - - raceboardPerspectiveComponentLifecyclesAndSettings = new PerspectiveLifecycleAndComponentSettings<>(raceboardPerspectiveLifecycle, - raceboardPerspectiveComponentsLifecyclesAndSettings); - - leaderboardPerspectiveLifecycleAndSettings = new PerspectiveLifecycleAndSettings<>(leaderboardPerspectiveLifecycle, leaderboardPerspectiveSettings); - raceboardPerspectiveLifecycleAndSettings = new PerspectiveLifecycleAndSettings<>(raceboardPerspectiveLifecycle, raceboardPerspectiveSettings); - } - - private , S extends Settings> void openPerspectiveSettingsDialog(final PerspectiveLifecycleAndSettings perspectiveLifecycleAndSettings) { - SettingsDialogComponent settingsDialogComponent = perspectiveLifecycleAndSettings.getPerspectiveLifecycle().getSettingsDialogComponent(perspectiveLifecycleAndSettings.getSettings()); - - LifecycleSettingsDialog dialog = new LifecycleSettingsDialog(perspectiveLifecycleAndSettings.getPerspectiveLifecycle(), settingsDialogComponent, StringMessages.INSTANCE, new DialogCallback() { - @Override - public void ok(S newSettings) { - perspectiveLifecycleAndSettings.setSettings(newSettings); - }; - @Override - public void cancel() { - } - }); - dialog.show(); - } - - private void openPerspectiveComponentSettingsDialog(final PerspectiveLifecycle perspectiveLifecycle, - final PerspectiveLifecycleAndComponentSettings perspectiveComponentsLifeyclesAndSettings) { - TabbedPerspectiveConfigurationDialog dialog = new TabbedPerspectiveConfigurationDialog(StringMessages.INSTANCE, - perspectiveLifecycle, perspectiveComponentsLifeyclesAndSettings.getComponentSettings(), new DialogCallback() { - @Override - public void cancel() { - } - - @Override - public void ok(CompositeLifecycleSettings newSettings) { - perspectiveComponentsLifeyclesAndSettings.setComponentSettings(newSettings); - } - }); - dialog.show(); - } - - @Override - public void setEvents(List events) { - this.events.clear(); - this.events.addAll(events); - - eventSelectionBox.addItem("Please select an event"); - for(EventDTO event: events) { - eventSelectionBox.addItem(event.getName()); - } - } - - @UiHandler("eventSelectionBox") - void onEventSelectionChange(ChangeEvent event) { - EventDTO selectedEvent = getSelectedEvent(); - if(selectedEvent != null) { - leaderboardSelectionBox.clear(); - leaderboardSelectionBox.addItem("Please select a leaderboard"); - for(LeaderboardGroupDTO leaderboardGroup: selectedEvent.getLeaderboardGroups()) { - for(StrippedLeaderboardDTO leaderboard: leaderboardGroup.getLeaderboards()) { - leaderboardSelectionBox.addItem(leaderboard.name); - } - } - } - leaderboardSelectionUi.getStyle().setVisibility(selectedEvent != null ? Visibility.VISIBLE : Visibility.HIDDEN); - } - - @UiHandler("leaderboardSelectionBox") - void onLeaderboardSelectionChange(ChangeEvent event) { - String selectedLeaderboardName = getSelectedLeaderboardName(); - if(selectedLeaderboardName != null) { - startAutoPlayButton.setEnabled(true); - startAutoPlayButton.removeStyleName(SharedResources.INSTANCE.mainCss().buttoninactive()); - - StrippedLeaderboardDTO selectedLeaderboard = getSelectedLeaderboard(); - this.updatePerspectives(selectedLeaderboard); - - createPerspectiveSettingsUI(leaderboardPerspectiveLifecycleAndSettings, leaderboardPerspectiveComponentLifecyclesAndSettings, leaderboardPerspectiveSettingsPanel); - createPerspectiveSettingsUI(raceboardPerspectiveLifecycleAndSettings, raceboardPerspectiveComponentLifecyclesAndSettings, raceboardPerspectiveSettingsPanel); - } else { - startAutoPlayButton.setEnabled(false); - startAutoPlayButton.addStyleName(SharedResources.INSTANCE.mainCss().buttoninactive()); - } - screenConfigurationUi.getStyle().setVisibility(selectedLeaderboardName != null ? Visibility.VISIBLE : Visibility.HIDDEN); - } - - private , PLC extends PerspectiveLifecycle, S extends Settings> void createPerspectiveSettingsUI(final PerspectiveLifecycleAndSettings perspectiveLifecycleAndSettings, - final PerspectiveLifecycleAndComponentSettings perspectiveComponentsLifeyclesAndSettings, - FlowPanel perspectiveSettingsPanel) { - perspectiveSettingsPanel.clear(); - - Button perspectiveSettingsButton = new Button("Page settings"); - perspectiveSettingsButton.getElement().getStyle().setMarginRight(10, Unit.PX); - perspectiveSettingsPanel.add(perspectiveSettingsButton); - perspectiveSettingsButton.setEnabled(perspectiveLifecycleAndSettings.getPerspectiveLifecycle().hasSettings()); - perspectiveSettingsButton.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - openPerspectiveSettingsDialog(perspectiveLifecycleAndSettings); - } - }); - - Button perspectiveComponentSettingsButton = new Button("Page component settings"); - perspectiveSettingsPanel.add(perspectiveComponentSettingsButton); - perspectiveComponentSettingsButton.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - openPerspectiveComponentSettingsDialog((PerspectiveLifecycle) perspectiveLifecycleAndSettings.getPerspectiveLifecycle(), - perspectiveComponentsLifeyclesAndSettings); - } - }); - - } - - @UiHandler("localeSelectionBox") - void onLocaleSelectionChange(ChangeEvent event) { - String selectedLocale = getSelectedLocale(); - LocaleChangeEvent localeChangeEvent = new LocaleChangeEvent(selectedLocale); - eventBus.fireEvent(localeChangeEvent); - } - - @UiHandler("startAutoPlayButton") - void startAutoPlayClicked(ClickEvent event) { - EventDTO selectedEvent = getSelectedEvent(); - String selectedLeaderboardName = getSelectedLeaderboardName(); - - if(selectedEvent != null && selectedLeaderboardName != null) { - navigator.goToPlayer(new AutoPlayerConfiguration(selectedEvent.id.toString(), selectedLeaderboardName, - startInFullscreenModeBox.getValue(), timeToRaceStartInSeconds.getValue()), - leaderboardPerspectiveLifecycleAndSettings, raceboardPerspectiveLifecycleAndSettings, - leaderboardPerspectiveComponentLifecyclesAndSettings, - raceboardPerspectiveComponentLifecyclesAndSettings); - } - } - - private String getSelectedLocale() { - String result = null; - int selectedIndex = localeSelectionBox.getSelectedIndex(); - if(selectedIndex >= 0) { - String selectedLocale = localeSelectionBox.getItemText(selectedIndex); - for (String localeName : LocaleInfo.getAvailableLocaleNames()) { - if(!localeName.equals("default")) { - String displayName = LocaleInfo.getLocaleNativeDisplayName(localeName); - if(displayName.equals(selectedLocale)) { - result = localeName; - break; - } - } - } - - } - return result; - } - - private String getSelectedLeaderboardName() { - String result = null; - int selectedIndex = leaderboardSelectionBox.getSelectedIndex(); - if(selectedIndex > 0) { - result = leaderboardSelectionBox.getItemText(selectedIndex); - } - return result; - } - - private StrippedLeaderboardDTO getSelectedLeaderboard() { - EventDTO selectedEvent = getSelectedEvent(); - String selectedLeaderboardName = getSelectedLeaderboardName(); - for (LeaderboardGroupDTO leaderboardGroup : selectedEvent.getLeaderboardGroups()) { - for (StrippedLeaderboardDTO leaderboard : leaderboardGroup.getLeaderboards()) { - if (leaderboard.name.equals(selectedLeaderboardName)) { - return leaderboard; - } - } - } - return null; - } - - private EventDTO getSelectedEvent() { - EventDTO result = null; - int selectedIndex = eventSelectionBox.getSelectedIndex(); - if(events != null && selectedIndex > 0) { - String selectedItemText = eventSelectionBox.getItemText(selectedIndex); - for(EventDTO event: events) { - if(event.getName().equals(selectedItemText)) { - result = event; - break; - } - } - } - return result; - } -} +package com.sap.sailing.gwt.autoplay.client.place.start; + +import java.util.ArrayList; +import java.util.List; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.DivElement; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.dom.client.Style.Visibility; +import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.i18n.client.LocaleInfo; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.uibinder.client.UiHandler; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.CheckBox; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.IntegerBox; +import com.google.gwt.user.client.ui.ListBox; +import com.google.gwt.user.client.ui.Widget; +import com.google.web.bindery.event.shared.EventBus; +import com.sap.sailing.domain.common.dto.AbstractLeaderboardDTO; +import com.sap.sailing.gwt.autoplay.client.app.PlaceNavigator; +import com.sap.sailing.gwt.autoplay.client.place.player.AutoPlayerConfiguration; +import com.sap.sailing.gwt.autoplay.client.place.player.LeaderboardWithHeaderPerspectiveLifecycle; +import com.sap.sailing.gwt.autoplay.client.shared.header.SAPHeader; +import com.sap.sailing.gwt.autoplay.client.shared.header.SAPHeaderLifecycle; +import com.sap.sailing.gwt.common.client.SharedResources; +import com.sap.sailing.gwt.common.client.i18n.TextMessages; +import com.sap.sailing.gwt.ui.client.StringMessages; +import com.sap.sailing.gwt.ui.leaderboard.LeaderboardWithHeaderPerspectiveSettings; +import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveLifecycle; +import com.sap.sailing.gwt.ui.raceboard.RaceBoardPerspectiveSettings; +import com.sap.sailing.gwt.ui.shared.EventDTO; +import com.sap.sailing.gwt.ui.shared.LeaderboardGroupDTO; +import com.sap.sailing.gwt.ui.shared.StrippedLeaderboardDTO; +import com.sap.sse.common.settings.Settings; +import com.sap.sse.gwt.client.dialog.DataEntryDialog.DialogCallback; +import com.sap.sse.gwt.client.event.LocaleChangeEvent; +import com.sap.sse.gwt.client.shared.components.CompositeLifecycleSettings; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveCompositeLifecycleSettings; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveCompositeLifecycleTabbedSettingsDialog; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycle; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleAndSettings; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleWithAllSettings; + +public class DesktopStartView extends Composite implements StartView { + private static StartPageViewUiBinder uiBinder = GWT.create(StartPageViewUiBinder.class); + + interface StartPageViewUiBinder extends UiBinder { + } + + @UiField(provided=true) SAPHeader sapHeader; + @UiField(provided=true) ListBox localeSelectionBox; + @UiField(provided=true) ListBox eventSelectionBox; + @UiField(provided=true) ListBox leaderboardSelectionBox; + @UiField CheckBox startInFullscreenModeBox; + @UiField Button startAutoPlayButton; + @UiField DivElement leaderboardSelectionUi; + @UiField DivElement screenConfigurationUi; + @UiField FlowPanel leaderboardPerspectiveSettingsPanel; + @UiField FlowPanel raceboardPerspectiveSettingsPanel; + + @UiField CheckBox autoSwitchToRaceboard; + @UiField IntegerBox timeToRaceStartInSeconds; + + private final PlaceNavigator navigator; + private final EventBus eventBus; + private final List events; + + private PerspectiveLifecycleWithAllSettings leaderboardPerspectiveLifecyclesAndSettings; + private PerspectiveLifecycleWithAllSettings raceboardPerspectiveLifecyclesAndSettings; + + private final int defaultTimeToRaceStartTimeInSeconds = 180; + + public DesktopStartView(PlaceNavigator navigator, EventBus eventBus) { + super(); + this.navigator = navigator; + this.eventBus = eventBus; + this.events = new ArrayList(); + + SAPHeaderLifecycle sapHeaderLifecycle = new SAPHeaderLifecycle(TextMessages.INSTANCE.autoPlayerConfiguration(), StringMessages.INSTANCE); + sapHeader = new SAPHeader(sapHeaderLifecycle, sapHeaderLifecycle.createDefaultSettings(), false); + eventSelectionBox = new ListBox(); + eventSelectionBox.setMultipleSelect(false); + leaderboardSelectionBox = new ListBox(); + leaderboardSelectionBox.setMultipleSelect(false); + localeSelectionBox = new ListBox(); + localeSelectionBox.setMultipleSelect(false); + + LocaleInfo currentLocale = LocaleInfo.getCurrentLocale(); + int i = 0; + for (String localeName : LocaleInfo.getAvailableLocaleNames()) { + if (!localeName.equals("default")) { + String displayName = LocaleInfo.getLocaleNativeDisplayName(localeName); + localeSelectionBox.addItem(displayName); + if (currentLocale.getLocaleName().equals(localeName)) { + localeSelectionBox.setSelectedIndex(i); + } + i++; + } + } + + initWidget(uiBinder.createAndBindUi(this)); + this.ensureDebugId("AutoPlayStartView"); + + startInFullscreenModeBox.setValue(true); + autoSwitchToRaceboard.setValue(true); + timeToRaceStartInSeconds.setValue(defaultTimeToRaceStartTimeInSeconds); + + leaderboardSelectionUi.getStyle().setVisibility(Visibility.HIDDEN); + screenConfigurationUi.getStyle().setVisibility(Visibility.HIDDEN); + + startAutoPlayButton.setEnabled(false); + startAutoPlayButton.addStyleName(SharedResources.INSTANCE.mainCss().buttoninactive()); + } + + private void updatePerspectives(AbstractLeaderboardDTO leaderboard) { + LeaderboardWithHeaderPerspectiveLifecycle leaderboardPerspectiveLifecycle = new LeaderboardWithHeaderPerspectiveLifecycle(leaderboard, StringMessages.INSTANCE); + LeaderboardWithHeaderPerspectiveSettings leaderboardPerspectiveSettings = leaderboardPerspectiveLifecycle.createDefaultSettings(); + + CompositeLifecycleSettings leaderboardPerspectiveComponentsLifecyclesAndSettings = leaderboardPerspectiveLifecycle.getComponentLifecyclesAndDefaultSettings(); + PerspectiveLifecycleAndSettings leaderboardPerspectiveLifecycleAndSettings = new PerspectiveLifecycleAndSettings<>(leaderboardPerspectiveLifecycle, leaderboardPerspectiveSettings); + + leaderboardPerspectiveLifecyclesAndSettings = new PerspectiveLifecycleWithAllSettings<>(leaderboardPerspectiveLifecycle, + new PerspectiveCompositeLifecycleSettings<>(leaderboardPerspectiveLifecycleAndSettings,leaderboardPerspectiveComponentsLifecyclesAndSettings)); + + RaceBoardPerspectiveLifecycle raceboardPerspectiveLifecycle = new RaceBoardPerspectiveLifecycle(leaderboard, StringMessages.INSTANCE); + RaceBoardPerspectiveSettings raceboardPerspectiveSettings = raceboardPerspectiveLifecycle.createDefaultSettings(); + + CompositeLifecycleSettings raceboardPerspectiveComponentsLifecyclesAndSettings = raceboardPerspectiveLifecycle.getComponentLifecyclesAndDefaultSettings(); + PerspectiveLifecycleAndSettings raceboardPerspectiveLifecycleAndSettings = new PerspectiveLifecycleAndSettings<>(raceboardPerspectiveLifecycle, raceboardPerspectiveSettings); + + raceboardPerspectiveLifecyclesAndSettings = new PerspectiveLifecycleWithAllSettings<>(raceboardPerspectiveLifecycle, + new PerspectiveCompositeLifecycleSettings<>(raceboardPerspectiveLifecycleAndSettings,raceboardPerspectiveComponentsLifecyclesAndSettings)); + } + + private

, S extends Settings> void openPerspectiveSettingsDialog(final PerspectiveLifecycleWithAllSettings perspectiveLifecycleAndSettings) { + PerspectiveCompositeLifecycleTabbedSettingsDialog dialog = new PerspectiveCompositeLifecycleTabbedSettingsDialog<>(StringMessages.INSTANCE, + perspectiveLifecycleAndSettings.getAllSettings(), perspectiveLifecycleAndSettings.getPerspectiveLifecycle().getPerspectiveName(), + new DialogCallback>() { + @Override + public void ok(PerspectiveCompositeLifecycleSettings newSettings) { + perspectiveLifecycleAndSettings.setAllSettings(newSettings); + }; + + @Override + public void cancel() { + } + }); + + dialog.show(); + } + + @Override + public void setEvents(List events) { + this.events.clear(); + this.events.addAll(events); + + eventSelectionBox.addItem("Please select an event"); + for(EventDTO event: events) { + eventSelectionBox.addItem(event.getName()); + } + } + + @UiHandler("eventSelectionBox") + void onEventSelectionChange(ChangeEvent event) { + EventDTO selectedEvent = getSelectedEvent(); + if(selectedEvent != null) { + leaderboardSelectionBox.clear(); + leaderboardSelectionBox.addItem("Please select a leaderboard"); + for(LeaderboardGroupDTO leaderboardGroup: selectedEvent.getLeaderboardGroups()) { + for(StrippedLeaderboardDTO leaderboard: leaderboardGroup.getLeaderboards()) { + leaderboardSelectionBox.addItem(leaderboard.name); + } + } + } + leaderboardSelectionUi.getStyle().setVisibility(selectedEvent != null ? Visibility.VISIBLE : Visibility.HIDDEN); + } + + @UiHandler("leaderboardSelectionBox") + void onLeaderboardSelectionChange(ChangeEvent event) { + String selectedLeaderboardName = getSelectedLeaderboardName(); + if(selectedLeaderboardName != null) { + startAutoPlayButton.setEnabled(true); + startAutoPlayButton.removeStyleName(SharedResources.INSTANCE.mainCss().buttoninactive()); + + StrippedLeaderboardDTO selectedLeaderboard = getSelectedLeaderboard(); + this.updatePerspectives(selectedLeaderboard); + + createPerspectiveSettingsUI(leaderboardPerspectiveLifecyclesAndSettings, leaderboardPerspectiveSettingsPanel); + createPerspectiveSettingsUI(raceboardPerspectiveLifecyclesAndSettings, raceboardPerspectiveSettingsPanel); + } else { + startAutoPlayButton.setEnabled(false); + startAutoPlayButton.addStyleName(SharedResources.INSTANCE.mainCss().buttoninactive()); + } + screenConfigurationUi.getStyle().setVisibility(selectedLeaderboardName != null ? Visibility.VISIBLE : Visibility.HIDDEN); + } + + private

, S extends Settings> void createPerspectiveSettingsUI( + final PerspectiveLifecycleWithAllSettings perspectiveLifecycleWithAllSettings, + FlowPanel perspectiveSettingsPanel) { + perspectiveSettingsPanel.clear(); + + Button perspectiveSettingsButton = new Button("Page settings"); + perspectiveSettingsButton.getElement().getStyle().setMarginRight(10, Unit.PX); + perspectiveSettingsPanel.add(perspectiveSettingsButton); + perspectiveSettingsButton.setEnabled(perspectiveLifecycleWithAllSettings.getAllSettings().hasSettings()); + perspectiveSettingsButton.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + openPerspectiveSettingsDialog(perspectiveLifecycleWithAllSettings); + } + }); + } + + @UiHandler("localeSelectionBox") + void onLocaleSelectionChange(ChangeEvent event) { + String selectedLocale = getSelectedLocale(); + LocaleChangeEvent localeChangeEvent = new LocaleChangeEvent(selectedLocale); + eventBus.fireEvent(localeChangeEvent); + } + + @UiHandler("startAutoPlayButton") + void startAutoPlayClicked(ClickEvent event) { + EventDTO selectedEvent = getSelectedEvent(); + String selectedLeaderboardName = getSelectedLeaderboardName(); + + if(selectedEvent != null && selectedLeaderboardName != null) { + navigator.goToPlayer(new AutoPlayerConfiguration(selectedEvent.id.toString(), selectedLeaderboardName, + startInFullscreenModeBox.getValue(), timeToRaceStartInSeconds.getValue()), + leaderboardPerspectiveLifecyclesAndSettings, raceboardPerspectiveLifecyclesAndSettings); + } + } + + private String getSelectedLocale() { + String result = null; + int selectedIndex = localeSelectionBox.getSelectedIndex(); + if(selectedIndex >= 0) { + String selectedLocale = localeSelectionBox.getItemText(selectedIndex); + for (String localeName : LocaleInfo.getAvailableLocaleNames()) { + if(!localeName.equals("default")) { + String displayName = LocaleInfo.getLocaleNativeDisplayName(localeName); + if(displayName.equals(selectedLocale)) { + result = localeName; + break; + } + } + } + + } + return result; + } + + private String getSelectedLeaderboardName() { + String result = null; + int selectedIndex = leaderboardSelectionBox.getSelectedIndex(); + if(selectedIndex > 0) { + result = leaderboardSelectionBox.getItemText(selectedIndex); + } + return result; + } + + private StrippedLeaderboardDTO getSelectedLeaderboard() { + EventDTO selectedEvent = getSelectedEvent(); + String selectedLeaderboardName = getSelectedLeaderboardName(); + for (LeaderboardGroupDTO leaderboardGroup : selectedEvent.getLeaderboardGroups()) { + for (StrippedLeaderboardDTO leaderboard : leaderboardGroup.getLeaderboards()) { + if (leaderboard.name.equals(selectedLeaderboardName)) { + return leaderboard; + } + } + } + return null; + } + + private EventDTO getSelectedEvent() { + EventDTO result = null; + int selectedIndex = eventSelectionBox.getSelectedIndex(); + if(events != null && selectedIndex > 0) { + String selectedItemText = eventSelectionBox.getItemText(selectedIndex); + for(EventDTO event: events) { + if(event.getName().equals(selectedItemText)) { + result = event; + break; + } + } + } + return result; + } +} diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/start/TabbedPerspectiveConfigurationDialog.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/start/TabbedPerspectiveConfigurationDialog.java deleted file mode 100644 index 583eb228084..00000000000 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/autoplay/client/place/start/TabbedPerspectiveConfigurationDialog.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.sap.sailing.gwt.autoplay.client.place.start; - -import com.sap.sailing.gwt.ui.client.StringMessages; -import com.sap.sse.gwt.client.shared.components.CompositeLifecycleSettings; -import com.sap.sse.gwt.client.shared.components.CompositeLifecycleTabbedSettingsDialog; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycle; - -/** - * @author Frank Mittag (c5163874) - * - */ -public class TabbedPerspectiveConfigurationDialog extends CompositeLifecycleTabbedSettingsDialog { - - public TabbedPerspectiveConfigurationDialog(StringMessages stringConstants, PerspectiveLifecycle perspectiveLifecycle, - CompositeLifecycleSettings perspectiveComponentsLifeyclesAndSettings) { - super(stringConstants, perspectiveComponentsLifeyclesAndSettings, perspectiveLifecycle.getPerspectiveName()); - } - - public TabbedPerspectiveConfigurationDialog(StringMessages stringConstants, PerspectiveLifecycle perspectiveLifecycle, - CompositeLifecycleSettings perspectiveComponentsLifeyclesAndSettings, DialogCallback callback) { - super(stringConstants, perspectiveComponentsLifeyclesAndSettings, perspectiveLifecycle.getPerspectiveName(), callback); - } -} diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/raceboard/RaceBoardEntryPoint.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/raceboard/RaceBoardEntryPoint.java index f75492d7ddc..f10be3a388b 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/raceboard/RaceBoardEntryPoint.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/raceboard/RaceBoardEntryPoint.java @@ -1,144 +1,147 @@ - -package com.sap.sailing.gwt.ui.raceboard; - -import java.util.Collections; -import java.util.UUID; - -import com.google.gwt.core.client.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.rpc.ServiceDefTarget; -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.sap.sailing.gwt.ui.client.AbstractSailingEntryPoint; -import com.sap.sailing.gwt.ui.client.LogoAndTitlePanel; -import com.sap.sailing.gwt.ui.client.MediaService; -import com.sap.sailing.gwt.ui.client.MediaServiceAsync; -import com.sap.sailing.gwt.ui.client.RaceTimesInfoProvider; -import com.sap.sailing.gwt.ui.client.RemoteServiceMappingConstants; -import com.sap.sailing.gwt.ui.client.StringMessages; -import com.sap.sailing.gwt.ui.shared.RaceWithCompetitorsDTO; -import com.sap.sailing.gwt.ui.shared.RaceboardDataDTO; -import com.sap.sse.gwt.client.EntryPointHelper; -import com.sap.sse.gwt.client.async.AsyncActionsExecutor; -import com.sap.sse.gwt.client.player.Timer; -import com.sap.sse.gwt.client.player.Timer.PlayModes; -import com.sap.sse.gwt.client.shared.components.CompositeLifecycleSettings; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleAndComponentSettings; - -public class RaceBoardEntryPoint extends AbstractSailingEntryPoint { - private RaceWithCompetitorsDTO selectedRace; - - private static final String PARAM_REGATTA_NAME = "regattaName"; - private static final String PARAM_RACE_NAME = "raceName"; - private static final String PARAM_LEADERBOARD_NAME = "leaderboardName"; - private static final String PARAM_LEADERBOARD_GROUP_NAME = "leaderboardGroupName"; - private static final String PARAM_EVENT_ID = "eventId"; - - private String regattaName; - private String raceName; - private String leaderboardName; - private String leaderboardGroupName; - private UUID eventId; - - private final MediaServiceAsync mediaService = GWT.create(MediaService.class); - - @Override - protected void doOnModuleLoad() { - super.doOnModuleLoad(); - EntryPointHelper.registerASyncService((ServiceDefTarget) mediaService, RemoteServiceMappingConstants.mediaServiceRemotePath); - // read mandatory parameters - regattaName = Window.Location.getParameter(PARAM_REGATTA_NAME); - raceName = Window.Location.getParameter(PARAM_RACE_NAME); - String leaderboardNameParamValue = Window.Location.getParameter(PARAM_LEADERBOARD_NAME); - String leaderboardGroupNameParamValue = Window.Location.getParameter(PARAM_LEADERBOARD_GROUP_NAME); - if (leaderboardNameParamValue != null && !leaderboardNameParamValue.isEmpty()) { - leaderboardName = leaderboardNameParamValue; - } - if (leaderboardGroupNameParamValue != null && !leaderboardGroupNameParamValue.isEmpty()) { - leaderboardGroupName = leaderboardGroupNameParamValue; - } - String eventIdParamValue = Window.Location.getParameter(PARAM_EVENT_ID); - if (eventIdParamValue != null && !eventIdParamValue.isEmpty()) { - eventId = UUID.fromString(eventIdParamValue); - } - if (leaderboardGroupNameParamValue != null && !leaderboardGroupNameParamValue.isEmpty()) { - leaderboardGroupName = leaderboardGroupNameParamValue; - } - if (regattaName == null || regattaName.isEmpty() || raceName == null || raceName.isEmpty() || - leaderboardName == null || leaderboardName.isEmpty()) { - createErrorPage("This page requires a valid regatta name, race name and leaderboard name."); - return; - } - - // read perspective settings parameters from URL - final RaceBoardPerspectiveSettings perspectiveSettings = RaceBoardPerspectiveSettings.readSettingsFromURL(); - - sailingService.getRaceboardData(regattaName, raceName, leaderboardName, leaderboardGroupName, eventId, new AsyncCallback() { - @Override - public void onSuccess(RaceboardDataDTO raceboardData) { - if (!raceboardData.isValidLeaderboard()) { - createErrorPage(getStringMessages().noSuchLeaderboard()); - return; - } - if (eventId != null && !raceboardData.isValidEvent()) { - createErrorPage(getStringMessages().noSuchEvent()); - } - if (leaderboardGroupName != null) { - if(!raceboardData.isValidLeaderboardGroup()) { - createErrorPage(getStringMessages().leaderboardNotContainedInLeaderboardGroup(leaderboardName, leaderboardGroupName)); - return; - } - if (eventId != null && raceboardData.isValidLeaderboardGroup() && !raceboardData.isValidEvent()) { - createErrorPage(getStringMessages().leaderboardGroupNotContainedInEvent(leaderboardGroupName, eventId.toString())); - return; - } - } - if (raceboardData.getRace() == null) { - createErrorPage("Could not obtain a race with name " + raceName + " for a regatta with name " + regattaName); - return; - } - - createPerspectivePage(raceboardData, perspectiveSettings); - } - - @Override - public void onFailure(Throwable caught) { - reportError("Error trying to create the raceboard: " + caught.getMessage()); - } - }); - } - - private void createErrorPage(String message) { - final DockLayoutPanel vp = new DockLayoutPanel(Unit.PX); - LogoAndTitlePanel logoAndTitlePanel = new LogoAndTitlePanel(getStringMessages(), this, getUserService()); - logoAndTitlePanel.addStyleName("LogoAndTitlePanel"); - RootLayoutPanel.get().add(vp); - vp.addNorth(logoAndTitlePanel, 100); - vp.add(new Label(message)); - } - - private void createPerspectivePage(RaceboardDataDTO raceboardData, RaceBoardPerspectiveSettings perspectiveSettings) { - selectedRace = raceboardData.getRace(); - Window.setTitle(selectedRace.getName()); - Timer timer = new Timer(PlayModes.Replay, 1000l); - AsyncActionsExecutor asyncActionsExecutor = new AsyncActionsExecutor(); - RaceTimesInfoProvider raceTimesInfoProvider = new RaceTimesInfoProvider(sailingService, asyncActionsExecutor, this, - Collections.singletonList(selectedRace.getRaceIdentifier()), 5000l /* requestInterval*/); - - RaceBoardPerspectiveLifecycle raceboardPerspectiveLifecycle = new RaceBoardPerspectiveLifecycle(null, StringMessages.INSTANCE); - CompositeLifecycleSettings raceboardPerspectiveComponentsLifecyclesAndSettings = raceboardPerspectiveLifecycle.getComponentLifecyclesAndDefaultSettings(); - - PerspectiveLifecycleAndComponentSettings componentLifecyclesAndSettings = new PerspectiveLifecycleAndComponentSettings<>(raceboardPerspectiveLifecycle, - raceboardPerspectiveComponentsLifecyclesAndSettings); - - RaceBoardPerspective raceBoardPerspective = new RaceBoardPerspective(perspectiveSettings, - componentLifecyclesAndSettings, sailingService, mediaService, getUserService(), - asyncActionsExecutor, raceboardData.getCompetitorAndTheirBoats(), timer, selectedRace.getRaceIdentifier(), leaderboardName, - leaderboardGroupName, eventId, RaceBoardEntryPoint.this, getStringMessages(), userAgent, raceTimesInfoProvider); - - RootLayoutPanel.get().add(raceBoardPerspective); - } -} + +package com.sap.sailing.gwt.ui.raceboard; + +import java.util.Collections; +import java.util.UUID; + +import com.google.gwt.core.client.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.rpc.ServiceDefTarget; +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.sap.sailing.gwt.ui.client.AbstractSailingEntryPoint; +import com.sap.sailing.gwt.ui.client.LogoAndTitlePanel; +import com.sap.sailing.gwt.ui.client.MediaService; +import com.sap.sailing.gwt.ui.client.MediaServiceAsync; +import com.sap.sailing.gwt.ui.client.RaceTimesInfoProvider; +import com.sap.sailing.gwt.ui.client.RemoteServiceMappingConstants; +import com.sap.sailing.gwt.ui.client.StringMessages; +import com.sap.sailing.gwt.ui.shared.RaceWithCompetitorsDTO; +import com.sap.sailing.gwt.ui.shared.RaceboardDataDTO; +import com.sap.sse.gwt.client.EntryPointHelper; +import com.sap.sse.gwt.client.async.AsyncActionsExecutor; +import com.sap.sse.gwt.client.player.Timer; +import com.sap.sse.gwt.client.player.Timer.PlayModes; +import com.sap.sse.gwt.client.shared.components.CompositeLifecycleSettings; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveCompositeLifecycleSettings; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleAndSettings; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleWithAllSettings; + +public class RaceBoardEntryPoint extends AbstractSailingEntryPoint { + private RaceWithCompetitorsDTO selectedRace; + + private static final String PARAM_REGATTA_NAME = "regattaName"; + private static final String PARAM_RACE_NAME = "raceName"; + private static final String PARAM_LEADERBOARD_NAME = "leaderboardName"; + private static final String PARAM_LEADERBOARD_GROUP_NAME = "leaderboardGroupName"; + private static final String PARAM_EVENT_ID = "eventId"; + + private String regattaName; + private String raceName; + private String leaderboardName; + private String leaderboardGroupName; + private UUID eventId; + + private final MediaServiceAsync mediaService = GWT.create(MediaService.class); + + @Override + protected void doOnModuleLoad() { + super.doOnModuleLoad(); + EntryPointHelper.registerASyncService((ServiceDefTarget) mediaService, RemoteServiceMappingConstants.mediaServiceRemotePath); + // read mandatory parameters + regattaName = Window.Location.getParameter(PARAM_REGATTA_NAME); + raceName = Window.Location.getParameter(PARAM_RACE_NAME); + String leaderboardNameParamValue = Window.Location.getParameter(PARAM_LEADERBOARD_NAME); + String leaderboardGroupNameParamValue = Window.Location.getParameter(PARAM_LEADERBOARD_GROUP_NAME); + if (leaderboardNameParamValue != null && !leaderboardNameParamValue.isEmpty()) { + leaderboardName = leaderboardNameParamValue; + } + if (leaderboardGroupNameParamValue != null && !leaderboardGroupNameParamValue.isEmpty()) { + leaderboardGroupName = leaderboardGroupNameParamValue; + } + String eventIdParamValue = Window.Location.getParameter(PARAM_EVENT_ID); + if (eventIdParamValue != null && !eventIdParamValue.isEmpty()) { + eventId = UUID.fromString(eventIdParamValue); + } + if (leaderboardGroupNameParamValue != null && !leaderboardGroupNameParamValue.isEmpty()) { + leaderboardGroupName = leaderboardGroupNameParamValue; + } + if (regattaName == null || regattaName.isEmpty() || raceName == null || raceName.isEmpty() || + leaderboardName == null || leaderboardName.isEmpty()) { + createErrorPage("This page requires a valid regatta name, race name and leaderboard name."); + return; + } + + // read perspective settings parameters from URL + final RaceBoardPerspectiveSettings perspectiveSettings = RaceBoardPerspectiveSettings.readSettingsFromURL(); + + sailingService.getRaceboardData(regattaName, raceName, leaderboardName, leaderboardGroupName, eventId, new AsyncCallback() { + @Override + public void onSuccess(RaceboardDataDTO raceboardData) { + if (!raceboardData.isValidLeaderboard()) { + createErrorPage(getStringMessages().noSuchLeaderboard()); + return; + } + if (eventId != null && !raceboardData.isValidEvent()) { + createErrorPage(getStringMessages().noSuchEvent()); + } + if (leaderboardGroupName != null) { + if(!raceboardData.isValidLeaderboardGroup()) { + createErrorPage(getStringMessages().leaderboardNotContainedInLeaderboardGroup(leaderboardName, leaderboardGroupName)); + return; + } + if (eventId != null && raceboardData.isValidLeaderboardGroup() && !raceboardData.isValidEvent()) { + createErrorPage(getStringMessages().leaderboardGroupNotContainedInEvent(leaderboardGroupName, eventId.toString())); + return; + } + } + if (raceboardData.getRace() == null) { + createErrorPage("Could not obtain a race with name " + raceName + " for a regatta with name " + regattaName); + return; + } + + createPerspectivePage(raceboardData, perspectiveSettings); + } + + @Override + public void onFailure(Throwable caught) { + reportError("Error trying to create the raceboard: " + caught.getMessage()); + } + }); + } + + private void createErrorPage(String message) { + final DockLayoutPanel vp = new DockLayoutPanel(Unit.PX); + LogoAndTitlePanel logoAndTitlePanel = new LogoAndTitlePanel(getStringMessages(), this, getUserService()); + logoAndTitlePanel.addStyleName("LogoAndTitlePanel"); + RootLayoutPanel.get().add(vp); + vp.addNorth(logoAndTitlePanel, 100); + vp.add(new Label(message)); + } + + private void createPerspectivePage(RaceboardDataDTO raceboardData, RaceBoardPerspectiveSettings perspectiveSettings) { + selectedRace = raceboardData.getRace(); + Window.setTitle(selectedRace.getName()); + Timer timer = new Timer(PlayModes.Replay, 1000l); + AsyncActionsExecutor asyncActionsExecutor = new AsyncActionsExecutor(); + RaceTimesInfoProvider raceTimesInfoProvider = new RaceTimesInfoProvider(sailingService, asyncActionsExecutor, this, + Collections.singletonList(selectedRace.getRaceIdentifier()), 5000l /* requestInterval*/); + + RaceBoardPerspectiveLifecycle raceboardPerspectiveLifecycle = new RaceBoardPerspectiveLifecycle(null, StringMessages.INSTANCE); + CompositeLifecycleSettings raceboardPerspectiveComponentsLifecyclesAndSettings = raceboardPerspectiveLifecycle.getComponentLifecyclesAndDefaultSettings(); + PerspectiveLifecycleAndSettings raceboardPerspectiveLifecycleAndSettings = new PerspectiveLifecycleAndSettings<>(raceboardPerspectiveLifecycle, perspectiveSettings); + + PerspectiveLifecycleWithAllSettings raceboardPerspectiveLifecyclesAndSettings = new PerspectiveLifecycleWithAllSettings<>(raceboardPerspectiveLifecycle, + new PerspectiveCompositeLifecycleSettings<>(raceboardPerspectiveLifecycleAndSettings,raceboardPerspectiveComponentsLifecyclesAndSettings)); + + RaceBoardPerspective raceBoardPerspective = new RaceBoardPerspective( + raceboardPerspectiveLifecyclesAndSettings, sailingService, mediaService, getUserService(), + asyncActionsExecutor, raceboardData.getCompetitorAndTheirBoats(), timer, selectedRace.getRaceIdentifier(), leaderboardName, + leaderboardGroupName, eventId, RaceBoardEntryPoint.this, getStringMessages(), userAgent, raceTimesInfoProvider); + + RootLayoutPanel.get().add(raceBoardPerspective); + } +} diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/raceboard/RaceBoardPanel.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/raceboard/RaceBoardPanel.java index 794e8ee1606..25cb82ae034 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/raceboard/RaceBoardPanel.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/raceboard/RaceBoardPanel.java @@ -79,7 +79,7 @@ import com.sap.sse.gwt.client.player.TimeRangeWithZoomModel; import com.sap.sse.gwt.client.player.Timer; import com.sap.sse.gwt.client.shared.components.Component; import com.sap.sse.gwt.client.shared.components.SettingsDialog; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleAndComponentSettings; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleWithAllSettings; import com.sap.sse.gwt.client.useragent.UserAgentDetails; import com.sap.sse.security.ui.authentication.AuthenticationClientFactory; import com.sap.sse.security.ui.authentication.AuthenticationClientFactoryImpl; @@ -145,7 +145,7 @@ public class RaceBoardPanel extends SimplePanel implements LeaderboardUpdateList private static final RaceMapResources raceMapResources = GWT.create(RaceMapResources.class); - private final PerspectiveLifecycleAndComponentSettings componentLifecyclesAndSettings; + private final PerspectiveLifecycleWithAllSettings componentLifecyclesAndSettings; /** * @param eventId * an optional event that can be used for "back"-navigation in case the race board shows a race in the @@ -155,7 +155,7 @@ public class RaceBoardPanel extends SimplePanel implements LeaderboardUpdateList * padding is provided for the RaceTimePanel that aligns its right border with that of the charts, and * the charts are created. This decision is made once on startup in the {@link RaceBoardEntryPoint} class. */ - public RaceBoardPanel(PerspectiveLifecycleAndComponentSettings componentLifecyclesAndSettings, + public RaceBoardPanel(PerspectiveLifecycleWithAllSettings componentLifecyclesAndSettings, SailingServiceAsync sailingService, MediaServiceAsync mediaService, UserService userService, AsyncActionsExecutor asyncActionsExecutor, Map competitorsAndTheirBoats, Timer timer, RegattaAndRaceIdentifier selectedRaceIdentifier, String leaderboardName, diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/raceboard/RaceBoardPerspective.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/raceboard/RaceBoardPerspective.java index 336f2915c10..535ff9aca19 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/raceboard/RaceBoardPerspective.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/raceboard/RaceBoardPerspective.java @@ -1,176 +1,175 @@ -package com.sap.sailing.gwt.ui.raceboard; - -import java.util.Map; -import java.util.UUID; - -import com.google.gwt.dom.client.Style.Unit; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.user.client.ui.Button; -import com.google.gwt.user.client.ui.DockLayoutPanel; -import com.google.gwt.user.client.ui.FlowPanel; -import com.google.gwt.user.client.ui.Widget; -import com.sap.sailing.domain.common.RegattaAndRaceIdentifier; -import com.sap.sailing.domain.common.dto.BoatDTO; -import com.sap.sailing.domain.common.dto.CompetitorDTO; -import com.sap.sailing.gwt.ui.client.LeaderboardUpdateListener; -import com.sap.sailing.gwt.ui.client.LeaderboardUpdateProvider; -import com.sap.sailing.gwt.ui.client.MediaServiceAsync; -import com.sap.sailing.gwt.ui.client.RaceTimesInfoProvider; -import com.sap.sailing.gwt.ui.client.SailingServiceAsync; -import com.sap.sailing.gwt.ui.client.StringMessages; -import com.sap.sse.gwt.client.ErrorReporter; -import com.sap.sse.gwt.client.async.AsyncActionsExecutor; -import com.sap.sse.gwt.client.panels.ResizableFlowPanel; -import com.sap.sse.gwt.client.player.Timer; -import com.sap.sse.gwt.client.shared.components.SettingsDialogComponent; -import com.sap.sse.gwt.client.shared.perspective.AbstractPerspectiveComposite; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleAndComponentSettings; -import com.sap.sse.gwt.client.useragent.UserAgentDetails; -import com.sap.sse.security.ui.client.UserService; - -/** - * A perspective managing a RaceboardPanel and the corresponding timepanel. - * @author Frank - * - */ -public class RaceBoardPerspective extends AbstractPerspectiveComposite implements LeaderboardUpdateProvider { - private RaceBoardPerspectiveSettings settings; - private final DockLayoutPanel dockPanel; - private final static int TIMEPANEL_COLLAPSED_HEIGHT = 67; - private final static int TIMEPANEL_EXPANDED_HEIGHT = 96; - - private final RaceBoardPerspectiveLifecycle perspectiveLifecycle; - - private final RaceBoardPanel raceBoardPanel; - private final FlowPanel timePanel; - - public RaceBoardPerspective(RaceBoardPerspectiveSettings perspectiveSettings, - PerspectiveLifecycleAndComponentSettings componentLifecyclesAndSettings, - SailingServiceAsync sailingService, MediaServiceAsync mediaService, - UserService userService, AsyncActionsExecutor asyncActionsExecutor, - Map competitorsAndTheirBoats, Timer timer, - RegattaAndRaceIdentifier selectedRaceIdentifier, String leaderboardName, - String leaderboardGroupName, UUID eventId, - ErrorReporter errorReporter, StringMessages stringMessages, - UserAgentDetails userAgent, RaceTimesInfoProvider raceTimesInfoProvider) { - super(); - this.settings = perspectiveSettings; - this.perspectiveLifecycle = componentLifecyclesAndSettings.getPerspectiveLifecycle(); - - this.raceBoardPanel = new RaceBoardPanel(componentLifecyclesAndSettings, sailingService, mediaService, userService, asyncActionsExecutor, - competitorsAndTheirBoats, timer, selectedRaceIdentifier, leaderboardName, null, /* event */null, settings, - errorReporter, stringMessages, userAgent, raceTimesInfoProvider); - this.raceBoardPanel.setSize("100%", "100%"); - this.timePanel = createTimePanelLayoutWrapper(); - - boolean advanceTimePanelEnabled = true; - if(advanceTimePanelEnabled) { - manageTimePanelToggleButton(advanceTimePanelEnabled); - } - - dockPanel = new DockLayoutPanel(Unit.PX); - dockPanel.addSouth(timePanel, TIMEPANEL_COLLAPSED_HEIGHT); - dockPanel.add(raceBoardPanel); - dockPanel.addStyleName("dockLayoutPanel"); - - initWidget(dockPanel); - } - - private void manageTimePanelToggleButton(boolean advanceTimePanelEnabled) { - final Button toggleButton = raceBoardPanel.getTimePanel().getAdvancedToggleButton(); - - if(advanceTimePanelEnabled) { - toggleButton.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - boolean advancedModeShown = raceBoardPanel.getTimePanel().toggleAdvancedMode(); - if (advancedModeShown) { - dockPanel.setWidgetSize(timePanel, TIMEPANEL_EXPANDED_HEIGHT); - toggleButton.removeStyleDependentName("Closed"); - toggleButton.addStyleDependentName("Open"); - } else { - dockPanel.setWidgetSize(timePanel, TIMEPANEL_COLLAPSED_HEIGHT); - toggleButton.addStyleDependentName("Closed"); - toggleButton.removeStyleDependentName("Open"); - } - } - }); - } else { - toggleButton.setVisible(false); - } - } - - private FlowPanel createTimePanelLayoutWrapper() { - FlowPanel timeLineInnerBgPanel = new ResizableFlowPanel(); - timeLineInnerBgPanel.addStyleName("timeLineInnerBgPanel"); - timeLineInnerBgPanel.add(raceBoardPanel.getTimePanel()); - - FlowPanel timeLineInnerPanel = new ResizableFlowPanel(); - timeLineInnerPanel.add(timeLineInnerBgPanel); - timeLineInnerPanel.addStyleName("timeLineInnerPanel"); - - FlowPanel timelinePanel = new ResizableFlowPanel(); - timelinePanel.add(timeLineInnerPanel); - timelinePanel.addStyleName("timeLinePanel"); - - return timelinePanel; - } - - @Override - public String getPerspectiveName() { - return perspectiveLifecycle.getPerspectiveName(); - } - - @Override - public String getLocalizedShortName() { - return perspectiveLifecycle.getLocalizedShortName(); - } - - @Override - public Widget getEntryWidget() { - return this; - } - - @Override - public boolean isVisible() { - return false; - } - - @Override - public void setVisible(boolean visibility) { - } - - @Override - public boolean hasSettings() { - return perspectiveLifecycle.hasSettings(); - } - - @Override - public SettingsDialogComponent getSettingsDialogComponent() { - return perspectiveLifecycle.getSettingsDialogComponent(settings); - } - - @Override - public RaceBoardPerspectiveSettings getSettings() { - return settings; - } - - @Override - public void updateSettings(RaceBoardPerspectiveSettings newSettings) { - this.settings = newSettings; - } - - @Override - public String getDependentCssClassName() { - return ""; - } - - @Override - public void addLeaderboardUpdateListener(LeaderboardUpdateListener listener) { - } - - @Override - public void removeLeaderboardUpdateListener(LeaderboardUpdateListener listener) { - } -} +package com.sap.sailing.gwt.ui.raceboard; + +import java.util.Map; +import java.util.UUID; + +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.DockLayoutPanel; +import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.Widget; +import com.sap.sailing.domain.common.RegattaAndRaceIdentifier; +import com.sap.sailing.domain.common.dto.BoatDTO; +import com.sap.sailing.domain.common.dto.CompetitorDTO; +import com.sap.sailing.gwt.ui.client.LeaderboardUpdateListener; +import com.sap.sailing.gwt.ui.client.LeaderboardUpdateProvider; +import com.sap.sailing.gwt.ui.client.MediaServiceAsync; +import com.sap.sailing.gwt.ui.client.RaceTimesInfoProvider; +import com.sap.sailing.gwt.ui.client.SailingServiceAsync; +import com.sap.sailing.gwt.ui.client.StringMessages; +import com.sap.sse.gwt.client.ErrorReporter; +import com.sap.sse.gwt.client.async.AsyncActionsExecutor; +import com.sap.sse.gwt.client.panels.ResizableFlowPanel; +import com.sap.sse.gwt.client.player.Timer; +import com.sap.sse.gwt.client.shared.components.SettingsDialogComponent; +import com.sap.sse.gwt.client.shared.perspective.AbstractPerspectiveComposite; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveLifecycleWithAllSettings; +import com.sap.sse.gwt.client.useragent.UserAgentDetails; +import com.sap.sse.security.ui.client.UserService; + +/** + * A perspective managing a RaceboardPanel and the corresponding timepanel. + * @author Frank + * + */ +public class RaceBoardPerspective extends AbstractPerspectiveComposite implements LeaderboardUpdateProvider { + private RaceBoardPerspectiveSettings settings; + private final DockLayoutPanel dockPanel; + private final static int TIMEPANEL_COLLAPSED_HEIGHT = 67; + private final static int TIMEPANEL_EXPANDED_HEIGHT = 96; + + private final RaceBoardPerspectiveLifecycle perspectiveLifecycle; + + private final RaceBoardPanel raceBoardPanel; + private final FlowPanel timePanel; + + public RaceBoardPerspective(PerspectiveLifecycleWithAllSettings perspectiveLifecycleWithAllSettings, + SailingServiceAsync sailingService, MediaServiceAsync mediaService, + UserService userService, AsyncActionsExecutor asyncActionsExecutor, + Map competitorsAndTheirBoats, Timer timer, + RegattaAndRaceIdentifier selectedRaceIdentifier, String leaderboardName, + String leaderboardGroupName, UUID eventId, + ErrorReporter errorReporter, StringMessages stringMessages, + UserAgentDetails userAgent, RaceTimesInfoProvider raceTimesInfoProvider) { + super(); + this.settings = perspectiveLifecycleWithAllSettings.getAllSettings().getPerspectiveLifecycleAndSettings().getSettings(); + this.perspectiveLifecycle = perspectiveLifecycleWithAllSettings.getPerspectiveLifecycle(); + + this.raceBoardPanel = new RaceBoardPanel(perspectiveLifecycleWithAllSettings, sailingService, mediaService, userService, asyncActionsExecutor, + competitorsAndTheirBoats, timer, selectedRaceIdentifier, leaderboardName, null, /* event */null, settings, + errorReporter, stringMessages, userAgent, raceTimesInfoProvider); + this.raceBoardPanel.setSize("100%", "100%"); + this.timePanel = createTimePanelLayoutWrapper(); + + boolean advanceTimePanelEnabled = true; + if(advanceTimePanelEnabled) { + manageTimePanelToggleButton(advanceTimePanelEnabled); + } + + dockPanel = new DockLayoutPanel(Unit.PX); + dockPanel.addSouth(timePanel, TIMEPANEL_COLLAPSED_HEIGHT); + dockPanel.add(raceBoardPanel); + dockPanel.addStyleName("dockLayoutPanel"); + + initWidget(dockPanel); + } + + private void manageTimePanelToggleButton(boolean advanceTimePanelEnabled) { + final Button toggleButton = raceBoardPanel.getTimePanel().getAdvancedToggleButton(); + + if(advanceTimePanelEnabled) { + toggleButton.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + boolean advancedModeShown = raceBoardPanel.getTimePanel().toggleAdvancedMode(); + if (advancedModeShown) { + dockPanel.setWidgetSize(timePanel, TIMEPANEL_EXPANDED_HEIGHT); + toggleButton.removeStyleDependentName("Closed"); + toggleButton.addStyleDependentName("Open"); + } else { + dockPanel.setWidgetSize(timePanel, TIMEPANEL_COLLAPSED_HEIGHT); + toggleButton.addStyleDependentName("Closed"); + toggleButton.removeStyleDependentName("Open"); + } + } + }); + } else { + toggleButton.setVisible(false); + } + } + + private FlowPanel createTimePanelLayoutWrapper() { + FlowPanel timeLineInnerBgPanel = new ResizableFlowPanel(); + timeLineInnerBgPanel.addStyleName("timeLineInnerBgPanel"); + timeLineInnerBgPanel.add(raceBoardPanel.getTimePanel()); + + FlowPanel timeLineInnerPanel = new ResizableFlowPanel(); + timeLineInnerPanel.add(timeLineInnerBgPanel); + timeLineInnerPanel.addStyleName("timeLineInnerPanel"); + + FlowPanel timelinePanel = new ResizableFlowPanel(); + timelinePanel.add(timeLineInnerPanel); + timelinePanel.addStyleName("timeLinePanel"); + + return timelinePanel; + } + + @Override + public String getPerspectiveName() { + return perspectiveLifecycle.getPerspectiveName(); + } + + @Override + public String getLocalizedShortName() { + return perspectiveLifecycle.getLocalizedShortName(); + } + + @Override + public Widget getEntryWidget() { + return this; + } + + @Override + public boolean isVisible() { + return false; + } + + @Override + public void setVisible(boolean visibility) { + } + + @Override + public boolean hasSettings() { + return perspectiveLifecycle.hasSettings(); + } + + @Override + public SettingsDialogComponent getSettingsDialogComponent() { + return perspectiveLifecycle.getSettingsDialogComponent(settings); + } + + @Override + public RaceBoardPerspectiveSettings getSettings() { + return settings; + } + + @Override + public void updateSettings(RaceBoardPerspectiveSettings newSettings) { + this.settings = newSettings; + } + + @Override + public String getDependentCssClassName() { + return ""; + } + + @Override + public void addLeaderboardUpdateListener(LeaderboardUpdateListener listener) { + } + + @Override + public void removeLeaderboardUpdateListener(LeaderboardUpdateListener listener) { + } +} diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeLifecycleSettings.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeLifecycleSettings.java new file mode 100644 index 00000000000..7f7ffb42321 --- /dev/null +++ b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeLifecycleSettings.java @@ -0,0 +1,34 @@ +package com.sap.sse.gwt.client.shared.perspective; + +import com.sap.sse.common.settings.AbstractSettings; +import com.sap.sse.common.settings.Settings; +import com.sap.sse.gwt.client.shared.components.CompositeLifecycleSettings; + +/** + * A composite setting for a perspective and it's components. + * @author Frank + * + */ +public class PerspectiveCompositeLifecycleSettings

, S extends Settings> extends AbstractSettings { + private final CompositeLifecycleSettings componentLifeycycleSettings; + private final PerspectiveLifecycleAndSettings perspectiveLifecycleAndSettings; + + public PerspectiveCompositeLifecycleSettings(PerspectiveLifecycleAndSettings perspectiveLifecycleAndSettings, + CompositeLifecycleSettings componentLifeycycleSettings) { + this.perspectiveLifecycleAndSettings = perspectiveLifecycleAndSettings; + this.componentLifeycycleSettings = componentLifeycycleSettings; + } + + public CompositeLifecycleSettings getComponentLifecyclesAndSettings() { + return componentLifeycycleSettings; + } + + public PerspectiveLifecycleAndSettings getPerspectiveLifecycleAndSettings() { + return perspectiveLifecycleAndSettings; + } + + public boolean hasSettings() { + return ((perspectiveLifecycleAndSettings != null && perspectiveLifecycleAndSettings.getPerspectiveLifecycle().hasSettings()) || + (componentLifeycycleSettings != null && componentLifeycycleSettings.hasSettings())); + } +} diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeLifecycleTabbedSettingsComponent.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeLifecycleTabbedSettingsComponent.java new file mode 100644 index 00000000000..e499a85f61c --- /dev/null +++ b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeLifecycleTabbedSettingsComponent.java @@ -0,0 +1,86 @@ +package com.sap.sse.gwt.client.shared.perspective; + +import com.google.gwt.user.client.ui.Widget; +import com.sap.sse.common.settings.Settings; +import com.sap.sse.gwt.client.shared.components.Component; +import com.sap.sse.gwt.client.shared.components.ComponentLifecycleAndSettings; +import com.sap.sse.gwt.client.shared.components.SettingsDialogComponent; + +/** + * A component, that contains a collection of settings components in a tabbed panel. + * + * @author Frank (c5163874) + */ +public class PerspectiveCompositeLifecycleTabbedSettingsComponent

, S extends Settings> implements Component> { + + private PerspectiveCompositeLifecycleSettings compositeLifecycleSettings; + private final String title; + + public PerspectiveCompositeLifecycleTabbedSettingsComponent(PerspectiveCompositeLifecycleSettings compositeLifecycleSettings) { + this(compositeLifecycleSettings, null); + } + + public PerspectiveCompositeLifecycleTabbedSettingsComponent(PerspectiveCompositeLifecycleSettings compositeLifecycleSettings, String title) { + this.compositeLifecycleSettings = compositeLifecycleSettings; + this.title = title; + } + + @Override + public boolean hasSettings() { + return compositeLifecycleSettings.hasSettings(); + } + + @Override + public SettingsDialogComponent> getSettingsDialogComponent() { + return new PerspectiveCompositeLifecycleTabbedSettingsDialogComponent(compositeLifecycleSettings); + } + + @Override + public PerspectiveCompositeLifecycleSettings getSettings() { + return compositeLifecycleSettings; + } + + @Override + public void updateSettings(PerspectiveCompositeLifecycleSettings newSettings) { + this.compositeLifecycleSettings = newSettings; + } + + @Override + public String getLocalizedShortName() { + if (title != null && !title.isEmpty()) { + return title; + } else { + StringBuilder result = new StringBuilder(); + boolean first = true; + for (ComponentLifecycleAndSettings component : compositeLifecycleSettings.getComponentLifecyclesAndSettings().getSettingsPerComponentLifecycle()) { + if (first) { + first = false; + } else { + result.append(" / "); + } + result.append(component.getComponentLifecycle().getLocalizedShortName()); + } + return result.toString(); + } + } + + @Override + public Widget getEntryWidget() { + throw new RuntimeException("Virtual composite component doesn't have a widget of its own"); + } + + @Override + public boolean isVisible() { + return false; + } + + @Override + public void setVisible(boolean visibility) { + throw new RuntimeException("Virtual composite component doesn't know how to make itself visible"); + } + + @Override + public String getDependentCssClassName() { + return null; + } +} \ No newline at end of file diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeLifecycleTabbedSettingsDialog.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeLifecycleTabbedSettingsDialog.java new file mode 100644 index 00000000000..83b7872b262 --- /dev/null +++ b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeLifecycleTabbedSettingsDialog.java @@ -0,0 +1,24 @@ +package com.sap.sse.gwt.client.shared.perspective; + +import com.sap.sse.common.settings.Settings; +import com.sap.sse.gwt.client.StringMessages; +import com.sap.sse.gwt.client.shared.components.ComponentLifecycle; +import com.sap.sse.gwt.client.shared.components.SettingsDialog; + +/** + * A composite settings dialog that combines the settings of several {@link ComponentLifecycle}s, providing a tab + * for each setting. + * + * @author Frank Mittag (c5163874) + * + */ +public class PerspectiveCompositeLifecycleTabbedSettingsDialog

, S extends Settings> extends SettingsDialog> { + + public PerspectiveCompositeLifecycleTabbedSettingsDialog(StringMessages stringConstants, PerspectiveCompositeLifecycleSettings compositeLifecycleSettings, String title) { + super(new PerspectiveCompositeLifecycleTabbedSettingsComponent(compositeLifecycleSettings, title), stringConstants); + } + + public PerspectiveCompositeLifecycleTabbedSettingsDialog(StringMessages stringConstants, PerspectiveCompositeLifecycleSettings compositeLifecycleSettings, String title, DialogCallback> callback) { + super(new PerspectiveCompositeLifecycleTabbedSettingsComponent(compositeLifecycleSettings, title), stringConstants, callback); + } +} diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeLifecycleTabbedSettingsDialogComponent.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeLifecycleTabbedSettingsDialogComponent.java new file mode 100644 index 00000000000..0367b3bfb43 --- /dev/null +++ b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeLifecycleTabbedSettingsDialogComponent.java @@ -0,0 +1,128 @@ +package com.sap.sse.gwt.client.shared.perspective; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; + +import com.google.gwt.user.client.ui.FocusWidget; +import com.google.gwt.user.client.ui.TabPanel; +import com.google.gwt.user.client.ui.Widget; +import com.sap.sse.common.settings.Settings; +import com.sap.sse.gwt.client.dialog.DataEntryDialog; +import com.sap.sse.gwt.client.dialog.DataEntryDialog.Validator; +import com.sap.sse.gwt.client.shared.components.ComponentLifecycle; +import com.sap.sse.gwt.client.shared.components.ComponentLifecycleAndSettings; +import com.sap.sse.gwt.client.shared.components.CompositeLifecycleSettings; +import com.sap.sse.gwt.client.shared.components.SettingsDialogComponent; + +public class PerspectiveCompositeLifecycleTabbedSettingsDialogComponent

, PS extends Settings> + implements SettingsDialogComponent> { + + public static class ComponentLifecycleWithSettingsAndDialogComponent, SettingsType extends Settings> { + private ComponentLifecycleAndSettings componentLifecycleAndSettings; + private SettingsDialogComponent dialogComponent; + + public ComponentLifecycleWithSettingsAndDialogComponent(ComponentLifecycleAndSettings componentLifecycleAndSettings, SettingsDialogComponent dialogComponent) { + this.componentLifecycleAndSettings = componentLifecycleAndSettings; + this.dialogComponent = dialogComponent; + } + + public ComponentLifecycleAndSettings getComponentLifecycleAndSettings() { + return componentLifecycleAndSettings; + } + + public SettingsDialogComponent getDialogComponent() { + return dialogComponent; + } + } + + public static class PerspectiveLifecycleWithSettingsAndDialogComponent, SettingsType extends Settings> { + private PerspectiveLifecycleAndSettings perspectiveLifecycleAndSettings; + private SettingsDialogComponent dialogComponent; + + public PerspectiveLifecycleWithSettingsAndDialogComponent(PerspectiveLifecycleAndSettings perspectiveLifecycleAndSettings, SettingsDialogComponent dialogComponent) { + this.perspectiveLifecycleAndSettings = perspectiveLifecycleAndSettings; + this.dialogComponent = dialogComponent; + } + + public PerspectiveLifecycleAndSettings getPerspectiveLifecycleAndSettings() { + return perspectiveLifecycleAndSettings; + } + + public SettingsDialogComponent getDialogComponent() { + return dialogComponent; + } + } + + private final Collection> componentLifecycleAndDialogComponents; + private final PerspectiveLifecycleWithSettingsAndDialogComponent perspectiveLifecycleAndSettingsDialog; + + public PerspectiveCompositeLifecycleTabbedSettingsDialogComponent(PerspectiveCompositeLifecycleSettings componentLifecyclesSettings) { + this.componentLifecycleAndDialogComponents = new ArrayList<>(); + for (ComponentLifecycleAndSettings componentLifecycleAndSettings : componentLifecyclesSettings.getComponentLifecyclesAndSettings().getSettingsPerComponentLifecycle()) { + if (componentLifecycleAndSettings.getComponentLifecycle().hasSettings()) { + this.componentLifecycleAndDialogComponents.add(createComponentLifecycleAndDialogComponent(componentLifecycleAndSettings)); + } + } + perspectiveLifecycleAndSettingsDialog = createPerspectiveLifecycleAndDialogComponent(componentLifecyclesSettings.getPerspectiveLifecycleAndSettings()); + } + + private , S extends Settings> ComponentLifecycleWithSettingsAndDialogComponent createComponentLifecycleAndDialogComponent(ComponentLifecycleAndSettings componentLifecycleAndSettings) { + S settings = componentLifecycleAndSettings.getSettings(); + return new ComponentLifecycleWithSettingsAndDialogComponent(componentLifecycleAndSettings, componentLifecycleAndSettings.getComponentLifecycle().getSettingsDialogComponent(settings)); + } + + private PerspectiveLifecycleWithSettingsAndDialogComponent createPerspectiveLifecycleAndDialogComponent(PerspectiveLifecycleAndSettings perspectiveLifecycleAndSettings) { + PS settings = perspectiveLifecycleAndSettings.getSettings(); + return new PerspectiveLifecycleWithSettingsAndDialogComponent(perspectiveLifecycleAndSettings, perspectiveLifecycleAndSettings.getPerspectiveLifecycle().getSettingsDialogComponent(settings)); + } + + @Override + public Widget getAdditionalWidget(DataEntryDialog dialog) { + TabPanel result = new TabPanel(); + if(perspectiveLifecycleAndSettingsDialog != null) { + Widget w = perspectiveLifecycleAndSettingsDialog.getDialogComponent().getAdditionalWidget((DataEntryDialog) dialog); + result.add(w, perspectiveLifecycleAndSettingsDialog.getPerspectiveLifecycleAndSettings().getPerspectiveLifecycle().getLocalizedShortName()); + } + for (ComponentLifecycleWithSettingsAndDialogComponent component : componentLifecycleAndDialogComponents) { + Widget w = component.getDialogComponent().getAdditionalWidget((DataEntryDialog) dialog); + result.add(w, component.getComponentLifecycleAndSettings().getComponentLifecycle().getLocalizedShortName()); + } + result.selectTab(0); + return result; + } + + @Override + public PerspectiveCompositeLifecycleSettings getResult() { + PerspectiveLifecycleAndSettings perspectiveLifeycycleAndSettings = perspectiveLifecycleAndSettingsDialog != null ? getPerspectiveAndSettings(perspectiveLifecycleAndSettingsDialog) : null; + Collection> settings = new HashSet<>(); + for (ComponentLifecycleWithSettingsAndDialogComponent component : componentLifecycleAndDialogComponents) { + settings.add(getComponentAndSettings(component)); + } + return new PerspectiveCompositeLifecycleSettings(perspectiveLifeycycleAndSettings, new CompositeLifecycleSettings(settings)); + } + + private , S extends Settings> ComponentLifecycleAndSettings getComponentAndSettings(ComponentLifecycleWithSettingsAndDialogComponent component) { + return new ComponentLifecycleAndSettings(component.getComponentLifecycleAndSettings().getComponentLifecycle(), component.getDialogComponent().getResult()); + } + + private PerspectiveLifecycleAndSettings getPerspectiveAndSettings(PerspectiveLifecycleWithSettingsAndDialogComponent perspective) { + return new PerspectiveLifecycleAndSettings(perspective.getPerspectiveLifecycleAndSettings().getPerspectiveLifecycle(), perspective.getDialogComponent().getResult()); + } + + @Override + public Validator> getValidator() { + return new PerspectiveCompositeLifecycleValidator(perspectiveLifecycleAndSettingsDialog, componentLifecycleAndDialogComponents); + } + + @Override + public FocusWidget getFocusWidget() { + for (ComponentLifecycleWithSettingsAndDialogComponent component : componentLifecycleAndDialogComponents) { + FocusWidget fw = component.getDialogComponent().getFocusWidget(); + if (fw != null) { + return fw; + } + } + return null; + } +} diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeLifecycleValidator.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeLifecycleValidator.java new file mode 100644 index 00000000000..63ab8598868 --- /dev/null +++ b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeLifecycleValidator.java @@ -0,0 +1,65 @@ +package com.sap.sse.gwt.client.shared.perspective; + +import java.util.HashMap; +import java.util.Map; + +import com.sap.sse.common.settings.Settings; +import com.sap.sse.gwt.client.dialog.DataEntryDialog.Validator; +import com.sap.sse.gwt.client.shared.components.ComponentLifecycle; +import com.sap.sse.gwt.client.shared.components.ComponentLifecycleAndSettings; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveCompositeLifecycleTabbedSettingsDialogComponent.ComponentLifecycleWithSettingsAndDialogComponent; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveCompositeLifecycleTabbedSettingsDialogComponent.PerspectiveLifecycleWithSettingsAndDialogComponent; + +public class PerspectiveCompositeLifecycleValidator

, PS extends Settings> implements Validator> { + + private final Map, Validator> validatorsMappedByComponentLifecycle; + private final Validator perspectiveValidator; + + public PerspectiveCompositeLifecycleValidator(PerspectiveLifecycleWithSettingsAndDialogComponent perspectiveLifecycleAndDialogComponent, + Iterable> componentLifecycleAndDialogComponents) { + perspectiveValidator = perspectiveLifecycleAndDialogComponent.getDialogComponent().getValidator(); + validatorsMappedByComponentLifecycle = new HashMap<>(); + for (ComponentLifecycleWithSettingsAndDialogComponent component : componentLifecycleAndDialogComponents) { + validatorsMappedByComponentLifecycle.put(component.getComponentLifecycleAndSettings(), component.getDialogComponent().getValidator()); + } + } + + @Override + public String getErrorMessage(PerspectiveCompositeLifecycleSettings valueToValidate) { + StringBuilder result = new StringBuilder(); + for (ComponentLifecycleAndSettings componentAndSettings : valueToValidate.getComponentLifecyclesAndSettings().getSettingsPerComponentLifecycle()) { + final String errorMessage = getComponentErrorMessage(componentAndSettings); + if (errorMessage != null && !errorMessage.isEmpty()) { + result.append(errorMessage); + } + } + String perspectiveErrorMessage = getPerspectiveErrorMessage(valueToValidate.getPerspectiveLifecycleAndSettings()); + if (perspectiveErrorMessage != null && !perspectiveErrorMessage.isEmpty()) { + result.append(perspectiveErrorMessage); + } + return result.toString(); + } + + private String getPerspectiveErrorMessage(PerspectiveLifecycleAndSettings perspectiveAndSettings) { + String errorMessage = null; + @SuppressWarnings("unchecked") + Validator validator = (Validator) perspectiveValidator; + if (validator != null) { + errorMessage = validator.getErrorMessage(perspectiveAndSettings.getSettings()); + } + return errorMessage; + } + + private , S extends Settings> String getComponentErrorMessage(ComponentLifecycleAndSettings componentLifecycleAndSettings) { + String errorMessage = null; + @SuppressWarnings("unchecked") + Validator validator = (Validator) validatorsMappedByComponentLifecycle.get(componentLifecycleAndSettings.getComponentLifecycle()); + if (validator != null) { + errorMessage = validator.getErrorMessage(componentLifecycleAndSettings.getSettings()); + if (errorMessage != null && !errorMessage.isEmpty() && !getClass().equals(validator.getClass())) { + errorMessage += "; "; + } + } + return errorMessage; + } +} diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeValidator.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeValidator.java index 240223f4ebc..d052361ba5d 100644 --- a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeValidator.java +++ b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveCompositeValidator.java @@ -1,59 +1,65 @@ -package com.sap.sse.gwt.client.shared.perspective; - -import java.util.HashMap; -import java.util.Map; - -import com.sap.sse.common.settings.Settings; -import com.sap.sse.gwt.client.dialog.DataEntryDialog.Validator; -import com.sap.sse.gwt.client.shared.components.Component; -import com.sap.sse.gwt.client.shared.components.ComponentAndSettingsPair; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveCompositeTabbedSettingsDialogComponent.ComponentAndDialogComponent; -import com.sap.sse.gwt.client.shared.perspective.PerspectiveCompositeTabbedSettingsDialogComponent.PerspectiveAndDialogComponent; - -public class PerspectiveCompositeValidator implements Validator { - - private final Map, Validator> validatorsMappedByComponent; - private final PerspectiveAndDialogComponent perspectiveAndDialogComponent; - - public PerspectiveCompositeValidator(PerspectiveAndDialogComponent perspectiveAndDialogComponent, Iterable> componentsAndDialogComponents) { - this.perspectiveAndDialogComponent = perspectiveAndDialogComponent; - validatorsMappedByComponent = new HashMap<>(); - for (ComponentAndDialogComponent componentsAndSettingsDialog : componentsAndDialogComponents) { - validatorsMappedByComponent.put(componentsAndSettingsDialog.getComponent(), componentsAndSettingsDialog.getSettingsDialog().getValidator()); - } - } - - @Override - public String getErrorMessage(PerspectiveCompositeSettings valueToValidate) { - StringBuilder result = new StringBuilder(); - for (ComponentAndSettingsPair componentAndSettings : valueToValidate.getSettingsPerComponent()) { - final String errorMessage = getComponentErrorMessage(componentAndSettings); - if (errorMessage != null && !errorMessage.isEmpty()) { - result.append(errorMessage); - } - } - PerspectiveAndSettingsPair perspectiveSettings = valueToValidate.getPerspectiveSettings(); - @SuppressWarnings("unchecked") - Validator validator = (Validator) perspectiveAndDialogComponent.getSettingsDialog().getValidator(); - String perspectiveErrorMessage = validator.getErrorMessage(perspectiveSettings.getSettings()); - if (perspectiveErrorMessage != null && !perspectiveErrorMessage.isEmpty()) { - result.append(perspectiveErrorMessage); - } - - return result.toString(); - } - - private String getComponentErrorMessage(ComponentAndSettingsPair componentAndSettings) { - String errorMessage = null; - @SuppressWarnings("unchecked") - Validator validator = (Validator) validatorsMappedByComponent.get(componentAndSettings.getComponent()); - if (validator != null) { - errorMessage = validator.getErrorMessage(componentAndSettings.getSettings()); - if (errorMessage != null && !errorMessage.isEmpty() && !getClass().equals(validator.getClass())) { - errorMessage += "; "; - } - } - return errorMessage; - } - -} +package com.sap.sse.gwt.client.shared.perspective; + +import java.util.HashMap; +import java.util.Map; + +import com.sap.sse.common.settings.Settings; +import com.sap.sse.gwt.client.dialog.DataEntryDialog.Validator; +import com.sap.sse.gwt.client.shared.components.Component; +import com.sap.sse.gwt.client.shared.components.ComponentAndSettingsPair; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveCompositeTabbedSettingsDialogComponent.ComponentAndDialogComponent; +import com.sap.sse.gwt.client.shared.perspective.PerspectiveCompositeTabbedSettingsDialogComponent.PerspectiveAndDialogComponent; + +public class PerspectiveCompositeValidator implements Validator { + + private final Map, Validator> validatorsMappedByComponent; + private final Validator perspectiveValidator; + + public PerspectiveCompositeValidator(PerspectiveAndDialogComponent perspectiveAndDialogComponent, Iterable> componentsAndDialogComponents) { + this.perspectiveValidator = perspectiveAndDialogComponent.getSettingsDialog().getValidator(); + validatorsMappedByComponent = new HashMap<>(); + for (ComponentAndDialogComponent componentsAndSettingsDialog : componentsAndDialogComponents) { + validatorsMappedByComponent.put(componentsAndSettingsDialog.getComponent(), componentsAndSettingsDialog.getSettingsDialog().getValidator()); + } + } + + @Override + public String getErrorMessage(PerspectiveCompositeSettings valueToValidate) { + StringBuilder result = new StringBuilder(); + for (ComponentAndSettingsPair componentAndSettings : valueToValidate.getSettingsPerComponent()) { + final String errorMessage = getComponentErrorMessage(componentAndSettings); + if (errorMessage != null && !errorMessage.isEmpty()) { + result.append(errorMessage); + } + } + String perspectiveErrorMessage = getPerspectiveErrorMessage(valueToValidate.getPerspectiveSettings()); + if (perspectiveErrorMessage != null && !perspectiveErrorMessage.isEmpty()) { + result.append(perspectiveErrorMessage); + } + return result.toString(); + } + + private String getPerspectiveErrorMessage(PerspectiveAndSettingsPair perspectiveAndSettings) { + String errorMessage = null; + @SuppressWarnings("unchecked") + Validator validator = (Validator) perspectiveValidator; + if (validator != null) { + errorMessage = validator.getErrorMessage(perspectiveAndSettings.getSettings()); + } + return errorMessage; + } + + private String getComponentErrorMessage(ComponentAndSettingsPair componentAndSettings) { + String errorMessage = null; + @SuppressWarnings("unchecked") + Validator validator = (Validator) validatorsMappedByComponent.get(componentAndSettings.getComponent()); + if (validator != null) { + errorMessage = validator.getErrorMessage(componentAndSettings.getSettings()); + if (errorMessage != null && !errorMessage.isEmpty() && !getClass().equals(validator.getClass())) { + errorMessage += "; "; + } + } + return errorMessage; + } + +} diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveLifecycle.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveLifecycle.java index 06bed488027..0df2371c2d8 100644 --- a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveLifecycle.java +++ b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveLifecycle.java @@ -1,23 +1,24 @@ -package com.sap.sse.gwt.client.shared.perspective; - -import com.sap.sse.common.settings.Settings; -import com.sap.sse.gwt.client.shared.components.ComponentLifecycle; -import com.sap.sse.gwt.client.shared.components.CompositeLifecycleSettings; -import com.sap.sse.gwt.client.shared.components.SettingsDialogComponent; - -/** - * A lifecycle interface for perspectives - * @author Frank - * - * @param

the perspective type - * @param the settings type - * @param the settings dialog component type - */ -public interface PerspectiveLifecycle

, S extends Settings, SDP extends SettingsDialogComponent> - extends ComponentLifecycle { - Iterable> getComponentLifecycles(); - - CompositeLifecycleSettings getComponentLifecyclesAndDefaultSettings(); - - String getPerspectiveName(); -} +package com.sap.sse.gwt.client.shared.perspective; + +import com.sap.sse.common.settings.Settings; +import com.sap.sse.gwt.client.shared.components.ComponentLifecycle; +import com.sap.sse.gwt.client.shared.components.CompositeLifecycleSettings; +import com.sap.sse.gwt.client.shared.components.SettingsDialogComponent; + +/** + * A lifecycle interface for perspectives + * @author Frank + * + * @param

the perspective type + * @param the settings type + * @param the settings dialog component type + */ +public interface PerspectiveLifecycle

, S extends Settings, SDP extends SettingsDialogComponent> + extends ComponentLifecycle { + + Iterable> getComponentLifecycles(); + + CompositeLifecycleSettings getComponentLifecyclesAndDefaultSettings(); + + String getPerspectiveName(); +} diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveLifecycleAndComponentSettings.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveLifecycleAndComponentSettings.java deleted file mode 100644 index 9d6753284ae..00000000000 --- a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveLifecycleAndComponentSettings.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.sap.sse.gwt.client.shared.perspective; - -import com.sap.sse.gwt.client.shared.components.CompositeLifecycleSettings; - -public class PerspectiveLifecycleAndComponentSettings> { - private final PerspectiveLifecycleType perspectiveLifecycle; - private CompositeLifecycleSettings componentSettings; - - public PerspectiveLifecycleAndComponentSettings(PerspectiveLifecycleType perspectiveLifecycle, - CompositeLifecycleSettings settings) { - this.perspectiveLifecycle = perspectiveLifecycle; - this.componentSettings = settings; - } - - public PerspectiveLifecycleType getPerspectiveLifecycle() { - return perspectiveLifecycle; - } - - public CompositeLifecycleSettings getComponentSettings() { - return componentSettings; - } - - public void setComponentSettings(CompositeLifecycleSettings componentSettings) { - this.componentSettings = componentSettings; - } -} diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveLifecycleWithAllSettings.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveLifecycleWithAllSettings.java new file mode 100644 index 00000000000..bbb3006cb21 --- /dev/null +++ b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/perspective/PerspectiveLifecycleWithAllSettings.java @@ -0,0 +1,41 @@ +package com.sap.sse.gwt.client.shared.perspective; + +import com.sap.sse.common.settings.Settings; +import com.sap.sse.gwt.client.shared.components.CompositeLifecycleSettings; + +/** + * A class for keeping together all settings of a PerspectiveLifecycle including it's components + * @author Frank + * + * @param

the type of the perspective lifecycle + * @param the type of the perspective settings + */ +public class PerspectiveLifecycleWithAllSettings

, S extends Settings> { + private final P perspectiveLifecycle; + private PerspectiveCompositeLifecycleSettings allSettings; + + public PerspectiveLifecycleWithAllSettings(P perspectiveLifecycle, PerspectiveCompositeLifecycleSettings allSettings) { + this.perspectiveLifecycle = perspectiveLifecycle; + this.allSettings = allSettings; + } + + public P getPerspectiveLifecycle() { + return perspectiveLifecycle; + } + + public S getPerspectiveSettings() { + return allSettings.getPerspectiveLifecycleAndSettings().getSettings(); + } + + public CompositeLifecycleSettings getComponentSettings() { + return allSettings.getComponentLifecyclesAndSettings(); + } + + public PerspectiveCompositeLifecycleSettings getAllSettings() { + return allSettings; + } + + public void setAllSettings(PerspectiveCompositeLifecycleSettings allSettings) { + this.allSettings = allSettings; + } +}