Merge pull request #13 from PM2-IT21bWIN-ruiz-mach-krea/Participant_List

Participant list
This commit is contained in:
Roman Schenk 2022-05-01 21:44:27 +02:00 committed by GitHub Enterprise
commit 594299f3b2
5 changed files with 64 additions and 16 deletions

View File

@ -1,23 +1,36 @@
package ch.zhaw.projekt2.turnierverwaltung;
import java.util.GregorianCalendar;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class Player extends Person implements Participant{
private GregorianCalendar dateOfBirth;
private LocalDate dateOfBirth;
public Player(String firstName, String name, String phoneNumber, String dateOfBirth) throws InvalidNameException, InvalidPhoneNumberException {
super(firstName, name, phoneNumber);
setDateOfBirth(dateOfBirth);
}
public GregorianCalendar getDateOfBirth() {
public LocalDate getDateOfBirth() {
return dateOfBirth;
}
public String getFormatedDateOfBirth(){
try{
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
return dateOfBirth.format(formatter);
} catch (Exception e) {
//todo handle and logging
return "";
}
}
public void setDateOfBirth(String dateOfBirth) {
String[] date = dateOfBirth.split("\\.");
this.dateOfBirth = new GregorianCalendar(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0]));
this.dateOfBirth = LocalDate.of(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0]));
}
@Override

View File

@ -31,7 +31,7 @@ public class Tournament implements Serializable {
public void addParticipant(Participant newParticipant) throws ParticipantExistsException {
for(Participant participant : participants){
if(participant.equals(newParticipant)){
throw new ParticipantExistsException("A Participant with the same Name exists already.");
participants.remove(participant);
}
}
participants.add(newParticipant);
@ -41,6 +41,7 @@ public class Tournament implements Serializable {
if(!participants.contains(participant)){
throw new ParticipantNotExistsException("The given Participant is not part of this Tournament");
}
participants.remove(participant);
}
public ObservableList<Participant> getParticipants() {

View File

@ -79,7 +79,7 @@ public class TournamentDecorator implements IsObservable{
}
}
public void addPlayer(String firstName, String name, String phoneNumber, String dateOfBirth){
public void savePlayer(String firstName, String name, String phoneNumber, String dateOfBirth){
try {
tournament.addParticipant(new Player(firstName, name, phoneNumber, dateOfBirth));
informListener();
@ -92,6 +92,15 @@ public class TournamentDecorator implements IsObservable{
}
}
public void deleteParticipant(Participant participant){
try {
tournament.removeParticipant(participant);
informListener();
} catch (Tournament.ParticipantNotExistsException e) {
e.printStackTrace(); //TODO handle and logging
}
}
public void informListener() {
for(IsObserver observer : listener) {
observer.update();

View File

@ -2,6 +2,7 @@ package ch.zhaw.projekt2.turnierverwaltung.main.participantAddFormular;
import ch.zhaw.projekt2.turnierverwaltung.FXController;
import ch.zhaw.projekt2.turnierverwaltung.Participant;
import ch.zhaw.projekt2.turnierverwaltung.Player;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
@ -39,7 +40,11 @@ public class ParticipantFormularController extends FXController {
private Label newParticipantFormularTitle;
@FXML
private Button openBtn;
private Button closeBtn;
@FXML
private Button deleteBtn;
@FXML
private Label participantListTitle;
@ -63,8 +68,12 @@ public class ParticipantFormularController extends FXController {
private Button saveBtn;
@FXML
void addParticipant(ActionEvent event) {
getTournamentDecorator().addPlayer(firstNameTextField.getText(), participantNameTextField.getText(), phoneNumberTextField.getText(), birthDateTextField.getText());
void changedSelection(MouseEvent event){
Player participant = (Player) participantListView.getSelectionModel().getSelectedItems().get(0);
participantNameTextField.setText(participant.getName());
firstNameTextField.setText(participant.getFirstName());
phoneNumberTextField.setText(participant.getPhoneNumber());
birthDateTextField.setText(participant.getFormatedDateOfBirth());
}
@FXML
@ -73,7 +82,20 @@ public class ParticipantFormularController extends FXController {
}
@FXML
void save(ActionEvent event) {
void saveParticipant(ActionEvent event) {
getTournamentDecorator().savePlayer(firstNameTextField.getText(), participantNameTextField.getText(), phoneNumberTextField.getText(), birthDateTextField.getText());
}
@FXML
void delete(ActionEvent event) {
System.out.println("delete");
Participant participant = participantListView.getSelectionModel().getSelectedItems().get(0);
getTournamentDecorator().deleteParticipant(participant);
}
@FXML
void close(ActionEvent event) {
}

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
@ -25,19 +24,23 @@
<Insets bottom="20.0" />
</VBox.margin>
</Label>
<ListView fx:id="participantListView" prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
<ListView fx:id="participantListView" onMouseClicked="#changedSelection" prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets />
</VBox.margin>
</ListView>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
<children>
<Button fx:id="saveBtn" mnemonicParsing="false" onAction="#save" text="Speichern">
<Button fx:id="closeBtn" mnemonicParsing="false" onAction="#close" text="Schliessen">
<HBox.margin>
<Insets right="40.0" />
</HBox.margin>
</Button>
<Button fx:id="deleteBtn" mnemonicParsing="false" onAction="#delete" text="Löschen">
<HBox.margin>
<Insets right="40.0" />
</HBox.margin>
</Button>
<Button fx:id="openBtn" mnemonicParsing="false" text="Bearbeiten" />
</children>
</HBox>
</children>
@ -52,7 +55,7 @@
</Separator>
<VBox fx:id="changeBtn" alignment="TOP_CENTER" onDragDetected="#changeParticipant" prefHeight="331.0" prefWidth="308.0" HBox.hgrow="ALWAYS">
<children>
<Label fx:id="newParticipantFormularTitle" text="Neuer Teilnehmer">
<Label fx:id="newParticipantFormularTitle" text="Teilnehmer ändern/erstellen">
<font>
<Font name="System Bold" size="21.0" />
</font>
@ -96,7 +99,7 @@
</children>
</GridPane>
<Separator prefWidth="200.0" />
<Button fx:id="addBtn" alignment="TOP_LEFT" mnemonicParsing="false" onAction="#addParticipant" text="Erstellen" VBox.vgrow="ALWAYS">
<Button fx:id="saveBtn" alignment="TOP_LEFT" mnemonicParsing="false" onAction="#saveParticipant" text="Speichern" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="10.0" top="30.0" />
</VBox.margin>