Browse Source

WIP further restructuring

master
GAM 4 years ago
parent
commit
eefdc45633
12 changed files with 134 additions and 102 deletions
  1. +22
    -0
      src/main/java/app/navigation/AbstractNavigationHeader.java
  2. +53
    -0
      src/main/java/app/navigation/Navigation.java
  3. +5
    -0
      src/main/java/app/navigation/NavigationService.java
  4. +4
    -26
      src/main/java/app/navigation/player/PlayerNavigation.java
  5. +2
    -1
      src/main/java/app/navigation/player/PlayerNavigationService.java
  6. +5
    -43
      src/main/java/app/navigation/regular/RegularNavigation.java
  7. +3
    -1
      src/main/java/app/navigation/regular/RegularNavigationService.java
  8. +13
    -15
      src/main/java/app/navigation/regular/components/RegularNavigationHeader.java
  9. +1
    -1
      src/main/java/app/views/match/MatchView.java
  10. +1
    -1
      src/main/java/app/views/matchday/MatchdayView.java
  11. +23
    -12
      src/main/java/app/views/navigation/NavigationViewBase.java
  12. +2
    -2
      src/main/java/app/views/table/TableView.java

+ 22
- 0
src/main/java/app/navigation/AbstractNavigationHeader.java View File

@ -0,0 +1,22 @@
package app.navigation;
import com.vaadin.flow.component.orderedlayout.FlexComponent;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
public abstract class AbstractNavigationHeader<T extends Navigation> extends HorizontalLayout {
protected final T navigation;
public AbstractNavigationHeader(T navigation) {
this.navigation = navigation;
defineLayout();
defineChildren();
}
private void defineLayout() {
setWidthFull();
setAlignItems(FlexComponent.Alignment.CENTER);
setJustifyContentMode(FlexComponent.JustifyContentMode.END);
}
protected abstract void defineChildren();
}

+ 53
- 0
src/main/java/app/navigation/Navigation.java View File

@ -0,0 +1,53 @@
package app.navigation;
import app.components.label.ValidationLabel;
import com.vaadin.flow.router.HasUrlParameter;
import java.util.ArrayList;
import java.util.List;
public abstract class Navigation implements HasUrlParameter<String> {
protected String route;
protected final List<Runnable> runnablesToBeRunAfterSelection = new ArrayList<>();
protected final ValidationLabel validationLabel = new ValidationLabel();
protected boolean editFlag = false;
public final void setRoute(String route) {
this.route = route;
}
public final ValidationLabel getValidationLabel() {
return validationLabel;
}
public abstract String getWildcardParam();
protected final String getRoute() {
if (route != null) return route;
throw new IllegalStateException("Route must be set!");
}
protected void doPostSelectionStuff() {
validationLabel.setValid(true);
updateUrl();
runnablesToBeRunAfterSelection.forEach(Runnable::run);
}
protected abstract void updateUrl();
public boolean editFlag() {
return editFlag;
}
public void setEditFlag(boolean editFlag) {
if (editFlag != this.editFlag) {
this.editFlag = editFlag;
updateUrl();
runnablesToBeRunAfterSelection.forEach(Runnable::run);
}
}
}

+ 5
- 0
src/main/java/app/navigation/NavigationService.java View File

@ -0,0 +1,5 @@
package app.navigation;
public interface NavigationService<T extends Navigation> {
T getNewNavigation();
}

+ 4
- 26
src/main/java/app/navigation/player/PlayerNavigation.java View File

@ -5,6 +5,7 @@ import app.data.entity.Player;
import app.data.entity.Season; import app.data.entity.Season;
import app.data.service.PlayerService; import app.data.service.PlayerService;
import app.data.service.SeasonService; import app.data.service.SeasonService;
import app.navigation.Navigation;
import app.navigation.NavigationUtils; import app.navigation.NavigationUtils;
import app.utils.EntityStringUtils; import app.utils.EntityStringUtils;
import com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent; import com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent;
@ -12,7 +13,6 @@ import com.vaadin.flow.component.HasValue.ValueChangeListener;
import com.vaadin.flow.component.UI; import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.select.Select; import com.vaadin.flow.component.select.Select;
import com.vaadin.flow.router.BeforeEvent; import com.vaadin.flow.router.BeforeEvent;
import com.vaadin.flow.router.HasUrlParameter;
import com.vaadin.flow.router.WildcardParameter; import com.vaadin.flow.router.WildcardParameter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -22,11 +22,8 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") @SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public class PlayerNavigation implements HasUrlParameter<String> {
public class PlayerNavigation extends Navigation {
private String route;
private final List<Runnable> runnablesToBeRunAfterSelection = new ArrayList<>();
private final PlayerService playerService; private final PlayerService playerService;
private final SeasonService seasonService; private final SeasonService seasonService;
@ -37,7 +34,6 @@ public class PlayerNavigation implements HasUrlParameter<String> {
private final Select<Player> playerSelect = new Select<>(); private final Select<Player> playerSelect = new Select<>();
private final Select<Season> seasonSelect = new Select<>(); private final Select<Season> seasonSelect = new Select<>();
private final ValidationLabel validationLabel = new ValidationLabel();
public PlayerNavigation(@Autowired PlayerService playerService, public PlayerNavigation(@Autowired PlayerService playerService,
@Autowired SeasonService seasonService) { @Autowired SeasonService seasonService) {
@ -53,20 +49,11 @@ public class PlayerNavigation implements HasUrlParameter<String> {
seasonSelect.setItemLabelGenerator(EntityStringUtils::getSeasonString); seasonSelect.setItemLabelGenerator(EntityStringUtils::getSeasonString);
} }
public void setRoute(String route) {
this.route = route;
}
public void addRunnableToBeRunAfterSelection(Runnable runnable) { public void addRunnableToBeRunAfterSelection(Runnable runnable) {
runnablesToBeRunAfterSelection.add(runnable); runnablesToBeRunAfterSelection.add(runnable);
} }
private String getRoute() {
if (route != null) return route;
throw new IllegalStateException("Route must be set!");
}
private void updateUrl() {
protected void updateUrl() {
String playerParam = null; String playerParam = null;
String seasonParam = null; String seasonParam = null;
if (playerSelect.getOptionalValue().isPresent()) if (playerSelect.getOptionalValue().isPresent())
@ -89,12 +76,6 @@ public class PlayerNavigation implements HasUrlParameter<String> {
return event -> doPostSelectionStuff(); return event -> doPostSelectionStuff();
} }
private void doPostSelectionStuff() {
validationLabel.setValid(true);
updateUrl();
runnablesToBeRunAfterSelection.forEach(Runnable::run);
}
private void autoselectPlayer() { private void autoselectPlayer() {
if (playerList.isEmpty()) { if (playerList.isEmpty()) {
validationLabel.setText("No Players in List!"); validationLabel.setText("No Players in List!");
@ -141,10 +122,6 @@ public class PlayerNavigation implements HasUrlParameter<String> {
else autoselectSeason(); else autoselectSeason();
} }
public ValidationLabel getValidationLabel() {
return validationLabel;
}
public List<Player> getPlayerList() { public List<Player> getPlayerList() {
return playerList; return playerList;
} }
@ -177,6 +154,7 @@ public class PlayerNavigation implements HasUrlParameter<String> {
return seasonService; return seasonService;
} }
@Override
public String getWildcardParam() { public String getWildcardParam() {
return NavigationUtils.getWildcardParam( return NavigationUtils.getWildcardParam(
false, false,


+ 2
- 1
src/main/java/app/navigation/player/PlayerNavigationService.java View File

@ -2,11 +2,12 @@ package app.navigation.player;
import app.data.service.PlayerService; import app.data.service.PlayerService;
import app.data.service.SeasonService; import app.data.service.SeasonService;
import app.navigation.NavigationService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class PlayerNavigationService {
public class PlayerNavigationService implements NavigationService<PlayerNavigation> {
private final SeasonService seasonService; private final SeasonService seasonService;
private final PlayerService playerService; private final PlayerService playerService;


+ 5
- 43
src/main/java/app/navigation/regular/RegularNavigation.java View File

@ -1,12 +1,12 @@
package app.navigation.regular; package app.navigation.regular;
import app.components.label.ValidationLabel;
import app.data.entity.Match; import app.data.entity.Match;
import app.data.entity.Matchday; import app.data.entity.Matchday;
import app.data.entity.Season; import app.data.entity.Season;
import app.data.service.MatchService; import app.data.service.MatchService;
import app.data.service.MatchdayService; import app.data.service.MatchdayService;
import app.data.service.SeasonService; import app.data.service.SeasonService;
import app.navigation.Navigation;
import app.navigation.NavigationUtils; import app.navigation.NavigationUtils;
import app.utils.EntityStringUtils; import app.utils.EntityStringUtils;
import com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent; import com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent;
@ -14,7 +14,6 @@ import com.vaadin.flow.component.HasValue.ValueChangeListener;
import com.vaadin.flow.component.UI; import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.select.Select; import com.vaadin.flow.component.select.Select;
import com.vaadin.flow.router.BeforeEvent; import com.vaadin.flow.router.BeforeEvent;
import com.vaadin.flow.router.HasUrlParameter;
import com.vaadin.flow.router.WildcardParameter; import com.vaadin.flow.router.WildcardParameter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
@ -25,13 +24,10 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") @SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public class RegularNavigation implements HasUrlParameter<String> {
public class RegularNavigation extends Navigation {
private String route;
private boolean onlyMatchdaysWithActivity; private boolean onlyMatchdaysWithActivity;
private final List<Runnable> runnablesToBeRunAfterSelection = new ArrayList<>();
private final SeasonService seasonService; private final SeasonService seasonService;
private final MatchdayService matchdayService; private final MatchdayService matchdayService;
private final MatchService matchService; private final MatchService matchService;
@ -46,10 +42,6 @@ public class RegularNavigation implements HasUrlParameter<String> {
private RegularNavigationLevel regularNavigationLevel = RegularNavigationLevel.SEASON; private RegularNavigationLevel regularNavigationLevel = RegularNavigationLevel.SEASON;
private final ValidationLabel validationLabel = new ValidationLabel();
private boolean editFlag = false;
public RegularNavigation(@Autowired SeasonService seasonService, public RegularNavigation(@Autowired SeasonService seasonService,
@Autowired MatchdayService matchdayService, @Autowired MatchdayService matchdayService,
@Autowired MatchService matchService) { @Autowired MatchService matchService) {
@ -68,10 +60,6 @@ public class RegularNavigation implements HasUrlParameter<String> {
matchSelect.setItemLabelGenerator(EntityStringUtils::getMatchString); matchSelect.setItemLabelGenerator(EntityStringUtils::getMatchString);
} }
public void setRoute(String route) {
this.route = route;
}
public void setOnlyMatchdaysWithActivity(boolean onlyMatchdaysWithActivity) { public void setOnlyMatchdaysWithActivity(boolean onlyMatchdaysWithActivity) {
this.onlyMatchdaysWithActivity = onlyMatchdaysWithActivity; this.onlyMatchdaysWithActivity = onlyMatchdaysWithActivity;
} }
@ -96,12 +84,7 @@ public class RegularNavigation implements HasUrlParameter<String> {
return this.regularNavigationLevel.compareTo(RegularNavigationLevel.MATCH) >= 0; return this.regularNavigationLevel.compareTo(RegularNavigationLevel.MATCH) >= 0;
} }
private String getRoute() {
if (route != null) return route;
throw new IllegalStateException("Route must be set!");
}
private void updateUrl() {
protected void updateUrl() {
String seasonParam = null; String seasonParam = null;
String matchdayParam = null; String matchdayParam = null;
String matchParam = null; String matchParam = null;
@ -147,12 +130,6 @@ public class RegularNavigation implements HasUrlParameter<String> {
}; };
} }
private void doPostSelectionStuff() {
validationLabel.setValid(true);
updateUrl();
runnablesToBeRunAfterSelection.forEach(Runnable::run);
}
private void autoselectSeason() { private void autoselectSeason() {
if (!seasonEnabled()) if (!seasonEnabled())
throw new IllegalStateException("This method should not be called when season is not enabled!"); throw new IllegalStateException("This method should not be called when season is not enabled!");
@ -164,7 +141,7 @@ public class RegularNavigation implements HasUrlParameter<String> {
seasonSelect.setValue(seasonList.get(seasonList.size() - 1)); seasonSelect.setValue(seasonList.get(seasonList.size() - 1));
} }
private void autoselectMatchday() { // TODO: choose depending on date instead!
private void autoselectMatchday() {
if (!matchdayEnabled()) if (!matchdayEnabled())
throw new IllegalStateException("This method should not be called when matchday is not enabled!"); throw new IllegalStateException("This method should not be called when matchday is not enabled!");
if (matchdayList.isEmpty()) { if (matchdayList.isEmpty()) {
@ -232,10 +209,6 @@ public class RegularNavigation implements HasUrlParameter<String> {
else autoselectMatch(); else autoselectMatch();
} }
public ValidationLabel getValidationLabel() {
return validationLabel;
}
public List<Season> getSeasonList() { public List<Season> getSeasonList() {
return seasonList; return seasonList;
} }
@ -284,18 +257,7 @@ public class RegularNavigation implements HasUrlParameter<String> {
return matchService; return matchService;
} }
public boolean editFlag() {
return editFlag;
}
public void setEditFlag(boolean editFlag) {
if (editFlag != this.editFlag) {
this.editFlag = editFlag;
updateUrl();
runnablesToBeRunAfterSelection.forEach(Runnable::run);
}
}
@Override
public String getWildcardParam() { public String getWildcardParam() {
return NavigationUtils.getWildcardParam( return NavigationUtils.getWildcardParam(
editFlag, editFlag,


+ 3
- 1
src/main/java/app/navigation/regular/RegularNavigationService.java View File

@ -3,11 +3,12 @@ package app.navigation.regular;
import app.data.service.MatchService; import app.data.service.MatchService;
import app.data.service.MatchdayService; import app.data.service.MatchdayService;
import app.data.service.SeasonService; import app.data.service.SeasonService;
import app.navigation.NavigationService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class RegularNavigationService {
public class RegularNavigationService implements NavigationService<RegularNavigation> {
private final SeasonService seasonService; private final SeasonService seasonService;
private final MatchdayService matchdayService; private final MatchdayService matchdayService;
@ -21,6 +22,7 @@ public class RegularNavigationService {
this.matchService = matchService; this.matchService = matchService;
} }
@Override
public RegularNavigation getNewNavigation() { public RegularNavigation getNewNavigation() {
return new RegularNavigation(seasonService, matchdayService, matchService); return new RegularNavigation(seasonService, matchdayService, matchService);
} }


+ 13
- 15
src/main/java/app/navigation/regular/components/RegularNavigationHeader.java View File

@ -1,22 +1,19 @@
package app.navigation.regular.components; package app.navigation.regular.components;
import app.navigation.AbstractNavigationHeader;
import app.navigation.Navigation;
import app.navigation.regular.RegularNavigation; import app.navigation.regular.RegularNavigation;
import com.vaadin.flow.component.html.Label; import com.vaadin.flow.component.html.Label;
import com.vaadin.flow.component.orderedlayout.FlexComponent; import com.vaadin.flow.component.orderedlayout.FlexComponent;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
public class RegularNavigationHeader extends HorizontalLayout {
private final RegularNavigation regularNavigation;
public class RegularNavigationHeader extends AbstractNavigationHeader<RegularNavigation> {
private final Label seasonLabel = new Label("Season:"); private final Label seasonLabel = new Label("Season:");
private final Label matchdayLabel = new Label("Matchday:"); private final Label matchdayLabel = new Label("Matchday:");
private final Label matchLabel = new Label("Match:"); private final Label matchLabel = new Label("Match:");
public RegularNavigationHeader(RegularNavigation regularNavigation) {
this.regularNavigation = regularNavigation;
defineLayout();
configureChildren();
public RegularNavigationHeader(Navigation navigation) {
super(navigation);
} }
private void defineLayout() { private void defineLayout() {
@ -25,16 +22,17 @@ public class RegularNavigationHeader extends HorizontalLayout {
setJustifyContentMode(FlexComponent.JustifyContentMode.END); setJustifyContentMode(FlexComponent.JustifyContentMode.END);
} }
private void configureChildren() {
@Override
protected void defineChildren() {
removeAll(); removeAll();
if (regularNavigation.seasonEnabled()) {
add(seasonLabel, regularNavigation.getSeasonSelect());
if (navigation.seasonEnabled()) {
add(seasonLabel, navigation.getSeasonSelect());
} }
if (regularNavigation.matchdayEnabled()) {
add(matchdayLabel, regularNavigation.getMatchdaySelect());
if (navigation.matchdayEnabled()) {
add(matchdayLabel, navigation.getMatchdaySelect());
} }
if (regularNavigation.matchEnabled()) {
add(matchLabel, regularNavigation.getMatchSelect());
if (navigation.matchEnabled()) {
add(matchLabel, navigation.getMatchSelect());
} }
} }
} }

+ 1
- 1
src/main/java/app/views/match/MatchView.java View File

@ -43,7 +43,7 @@ public class MatchView extends NavigationViewBase {
//////////// ////////////
private void configureLayout() { private void configureLayout() {
matchComponent = new MatchComponent(regularNavigation, chessComService, gameImageService);
matchComponent = new MatchComponent(navigation, chessComService, gameImageService);
add(matchComponent); add(matchComponent);
} }


+ 1
- 1
src/main/java/app/views/matchday/MatchdayView.java View File

@ -30,7 +30,7 @@ public class MatchdayView extends NavigationViewBase {
//////////// ////////////
private void configureLayout() { private void configureLayout() {
matchdayCard = new MatchdayCard(regularNavigation);
matchdayCard = new MatchdayCard(navigation);
add(matchdayCard); add(matchdayCard);
} }


+ 23
- 12
src/main/java/app/views/navigation/NavigationViewBase.java View File

@ -1,39 +1,50 @@
package app.views.navigation; package app.views.navigation;
import app.navigation.AbstractNavigationHeader;
import app.navigation.Navigation;
import app.navigation.NavigationService;
import app.navigation.regular.RegularNavigation; import app.navigation.regular.RegularNavigation;
import app.navigation.regular.RegularNavigationLevel; import app.navigation.regular.RegularNavigationLevel;
import app.navigation.regular.RegularNavigationService; import app.navigation.regular.RegularNavigationService;
import app.navigation.regular.components.RegularNavigationHeader; import app.navigation.regular.components.RegularNavigationHeader;
import com.vaadin.flow.component.orderedlayout.FlexComponent; import com.vaadin.flow.component.orderedlayout.FlexComponent;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout; import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.BeforeEvent; import com.vaadin.flow.router.BeforeEvent;
import com.vaadin.flow.router.HasUrlParameter; import com.vaadin.flow.router.HasUrlParameter;
import com.vaadin.flow.router.WildcardParameter; import com.vaadin.flow.router.WildcardParameter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
public abstract class NavigationViewBase extends VerticalLayout implements HasUrlParameter<String> {
public abstract class NavigationViewBase<T extends Navigation> extends VerticalLayout implements HasUrlParameter<String> {
protected final RegularNavigation regularNavigation;
protected final RegularNavigationHeader regularNavigationHeader;
protected final Navigation navigation;
protected final AbstractNavigationHeader<T> navigationHeader;
protected NavigationViewBase(@Autowired RegularNavigationService regularNavigationService,
protected NavigationViewBase(@Autowired NavigationService<T> navigationService,
String route, String route,
RegularNavigationLevel regularNavigationLevel) { RegularNavigationLevel regularNavigationLevel) {
this.regularNavigation = regularNavigationService.getNewNavigation();
regularNavigation.setRoute(route);
regularNavigation.setNavigationLevel(regularNavigationLevel);
this.navigation = navigationService.getNewNavigation();
navigation.setRoute(route);
if (navigation instanceof RegularNavigation) {
((RegularNavigation) navigation).setNavigationLevel(regularNavigationLevel);
}
this.regularNavigationHeader = new RegularNavigationHeader(regularNavigation);
this.navigationHeader = new RegularNavigationHeader(navigation);
define(); define();
} }
protected NavigationViewBase(@Autowired RegularNavigationService regularNavigationService,
String route) {
this(regularNavigationService, route, null);
}
private void define() { private void define() {
add(regularNavigationHeader);
add(navigationHeader);
addClassName("content"); addClassName("content");
setAlignItems(FlexComponent.Alignment.CENTER); setAlignItems(FlexComponent.Alignment.CENTER);
regularNavigation.addRunnableToBeRunAfterSelection(this::configureContent);
navigation.addRunnableToBeRunAfterSelection(this::configureContent);
} }
///////////// /////////////
@ -49,11 +60,11 @@ public abstract class NavigationViewBase extends VerticalLayout implements HasUr
@Override @Override
public void removeAll() { public void removeAll() {
super.removeAll(); super.removeAll();
add(regularNavigationHeader);
add(navigationHeader);
} }
@Override @Override
public void setParameter(BeforeEvent event, @WildcardParameter String param) { public void setParameter(BeforeEvent event, @WildcardParameter String param) {
regularNavigation.setParameter(event, param);
navigation.setParameter(event, param);
} }
} }

+ 2
- 2
src/main/java/app/views/table/TableView.java View File

@ -27,7 +27,7 @@ public class TableView extends NavigationViewBase {
super(regularNavigationService, "table", RegularNavigationLevel.MATCHDAY); super(regularNavigationService, "table", RegularNavigationLevel.MATCHDAY);
this.playerService = playerService; this.playerService = playerService;
this.regularNavigation.setOnlyMatchdaysWithActivity(true);
this.navigation.setOnlyMatchdaysWithActivity(true);
addClassName("table-view"); addClassName("table-view");
@ -39,7 +39,7 @@ public class TableView extends NavigationViewBase {
//////////// ////////////
private void defineLayout() { private void defineLayout() {
tableCard = new TableCard(regularNavigation, playerService);
tableCard = new TableCard(navigation, playerService);
add(tableCard); add(tableCard);
} }


Loading…
Cancel
Save