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.
 
 
 
 

36 lines
1.3 KiB

package app.navigation.regular.components.button;
import app.data.entity.Matchday;
import app.navigation.regular.RegularNavigation;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.icon.VaadinIcon;
import java.util.Optional;
public class PrevMatchdayButton extends Button {
private final RegularNavigation regularNavigation;
public PrevMatchdayButton(RegularNavigation regularNavigation) {
this.regularNavigation = regularNavigation;
if (!regularNavigation.matchdayEnabled())
throw new IllegalStateException("Cannot instantiate PrevMatchdayButton when Matchdays are not enabled!");
setIcon(VaadinIcon.ARROW_LEFT.create());
regularNavigation.addRunnableToBeRunAfterSelection(this::configure);
}
private void configure() {
Optional<Matchday> prevMatchday = getPrevMatchday();
setEnabled(prevMatchday.isPresent());
addClickListener(event -> prevMatchday.ifPresent(matchday -> regularNavigation.getMatchdaySelect().setValue(matchday)));
}
private Optional<Matchday> getPrevMatchday() {
int index = MatchdayButtonUtils.getMatchdayIndex(regularNavigation);
if (index > 0) return Optional.ofNullable(regularNavigation.getMatchdayList().get(index - 1));
return Optional.empty();
}
}