You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

37 lines
1.2 KiB

package app.navigation.player.components.button;
import app.data.entity.Player;
import app.navigation.player.PlayerNavigation;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.icon.VaadinIcon;
import java.util.List;
import java.util.Optional;
public class PrevPlayerButton extends Button {
private final PlayerNavigation playerNavigation;
public PrevPlayerButton(PlayerNavigation playerNavigation) {
this.playerNavigation = playerNavigation;
setIcon(VaadinIcon.ARROW_LEFT.create());
playerNavigation.addRunnableToBeRunAfterSelection(this::configure);
}
private void configure() {
Optional<Player> prevPlayer = getPrevPlayer();
setEnabled(prevPlayer.isPresent());
addClickListener(event -> prevPlayer.ifPresent(player -> playerNavigation.getPlayerSelect().setValue(player)));
}
private Optional<Player> getPrevPlayer() {
int index = PlayerButtonUtils.getPlayerIndex(playerNavigation);
if (index < 0) return Optional.empty();
List<Player> playerList = playerNavigation.getPlayerList();
return Optional.ofNullable(playerList.get((index - 1) % playerList.size()));
}
}