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