Compare commits

...
Author SHA1 Message Date
schrom01 3d13dbcb45 changed ParticipantFormular to change existing objects and don't replace them.
changed ParticipantFormular and PlacesFormular to clear textfields after saving.
solved #19
2022-05-07 11:53:10 +02:00
schrom01 02456bc5bf fixed participanFormular and placesFormular
#19
2022-05-06 09:23:19 +02:00
schrom01 f3495d28d6 fixed functionality Places Formular 2022-05-01 23:35:25 +02:00
10 changed files with 72 additions and 56 deletions
@@ -6,4 +6,5 @@ public interface Participant extends Serializable {
String getName();
void setName(String name);
boolean equals(Participant participant);
void change(Participant participant);
}
@@ -4,7 +4,7 @@ import java.io.Serializable;
public class Person implements Serializable {
private final String NAME_MATCHING_REGEX = "[a-zA-Z]{1,20}";
private final String PHONE_MATCHING_REGEX = "[\\+0-9]+";
private final String PHONE_MATCHING_REGEX = "[\\+]?[0-9]*";
private String name;
private String firstName;
@@ -1,6 +1,8 @@
package ch.zhaw.projekt2.turnierverwaltung;
public class Place {
import java.io.Serializable;
public class Place implements Serializable {
private final String NAME_MATCHING_REGEX = "[a-zA-Z0-9]{1,20}";
private String name;
@@ -18,4 +20,13 @@ public class Place {
public void setName(String name) {
this.name = name;
}
@Override
public String toString(){
return name;
}
public boolean equals(Place place){
return name.equals(place.getName());
}
}
@@ -29,12 +29,27 @@ public class Player extends Person implements Participant{
}
public void setDateOfBirth(String dateOfBirth) {
String[] date = dateOfBirth.split("\\.");
this.dateOfBirth = LocalDate.of(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0]));
if(dateOfBirth.length() > 0) {
String[] date = dateOfBirth.split("\\.");
this.dateOfBirth = LocalDate.of(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0]));
} else {
dateOfBirth = null;
}
}
public void setDateOfBirth(LocalDate dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
@Override
public boolean equals(Participant participant) {
return getClass().equals(participant.getClass()) && toString().toLowerCase().equals(participant.toString().toLowerCase());
}
@Override
public void change(Participant participant) {
Player player = (Player) participant;
setDateOfBirth(player.getDateOfBirth());
setPhoneNumber(player.getPhoneNumber());
}
}
@@ -27,11 +27,24 @@ public class Team implements Participant {
this.name = name;
}
public void setPlayers(List<Player> players) {
this.players = players;
}
public List<Player> getPlayers() {
return players;
}
@Override
public boolean equals(Participant participant) {
return getClass().equals(participant.getClass()) && toString().toLowerCase().equals(participant.toString().toLowerCase());
}
@Override
public void change(Participant participant) {
return;
}
public Person getContactPerson() {
return contactPerson;
}
@@ -7,6 +7,7 @@ import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
public class Tournament implements Serializable {
@@ -27,12 +28,14 @@ public class Tournament implements Serializable {
setName(name);
setType(type);
participants = new ArrayList<>();
places = new ArrayList<>();
}
public void addParticipant(Participant newParticipant) throws ParticipantExistsException {
for(Participant participant : participants){
public void saveParticipant(Participant newParticipant) throws ParticipantExistsException {
for(Participant participant: participants){
if(participant.equals(newParticipant)){
participants.remove(participant);
participant.change(newParticipant);
return;
}
}
participants.add(newParticipant);
@@ -52,11 +55,7 @@ public class Tournament implements Serializable {
}
public void addPlace(Place newPlace) throws PlaceExistsException {
for(Place place : places){
if(place.equals(newPlace)){
places.remove(place);
}
}
places.removeIf(place -> place.equals(newPlace));
places.add(newPlace);
}
@@ -2,7 +2,6 @@ package ch.zhaw.projekt2.turnierverwaltung;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class TournamentDecorator implements IsObservable{
@@ -81,7 +80,7 @@ public class TournamentDecorator implements IsObservable{
public void savePlayer(String firstName, String name, String phoneNumber, String dateOfBirth){
try {
tournament.addParticipant(new Player(firstName, name, phoneNumber, dateOfBirth));
tournament.saveParticipant(new Player(firstName, name, phoneNumber, dateOfBirth));
informListener();
} catch (Tournament.ParticipantExistsException e) {
e.printStackTrace(); //TODO handle and logging
@@ -79,6 +79,14 @@ public class ParticipantFormularController extends FXController {
@FXML
void saveParticipant(ActionEvent event) {
getTournamentDecorator().savePlayer(firstNameTextField.getText(), participantNameTextField.getText(), phoneNumberTextField.getText(), birthDateTextField.getText());
clearFormular();
}
private void clearFormular() {
firstNameTextField.clear();
participantNameTextField.clear();
phoneNumberTextField.clear();
birthDateTextField.clear();
}
@FXML
@@ -18,21 +18,9 @@ public class PlacesFormularController extends FXController {
@FXML
private Button addBtn;
@FXML
private Label birthDateLabel;
@FXML
private TextField birthDateTextField;
@FXML
private VBox changeBtn;
@FXML
private Label firstNameLabel;
@FXML
private TextField firstNameTextField;
@FXML
private GridPane grid;
@@ -58,12 +46,6 @@ public class PlacesFormularController extends FXController {
@FXML
private TextField placeNameTextField;
@FXML
private Label phoneNumberLabel;
@FXML
private TextField phoneNumberTextField;
@FXML
private Button saveBtn;
@@ -76,6 +58,11 @@ public class PlacesFormularController extends FXController {
@FXML
void savePlace(ActionEvent event) {
getTournamentDecorator().savePlace(placeNameTextField.getText());
clearFormular();
}
private void clearFormular() {
placeNameTextField.clear();
}
@FXML
@@ -1,18 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<HBox alignment="CENTER" VBox.vgrow="ALWAYS" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/17" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.placesAddFormular.PlacesFormularController">
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<HBox alignment="CENTER" VBox.vgrow="ALWAYS" xmlns="http://javafx.com/javafx/11.0.2" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.placesAddFormular.PlacesFormularController">
<children>
<VBox alignment="TOP_CENTER" prefHeight="331.0" prefWidth="308.0" HBox.hgrow="ALWAYS">
<children>
@@ -55,7 +48,7 @@
</Separator>
<VBox fx:id="changeBtn" alignment="TOP_CENTER" prefHeight="331.0" prefWidth="308.0" HBox.hgrow="ALWAYS">
<children>
<Label fx:id="newplaceFormularTitle" text="Teilnehmer ändern/erstellen">
<Label fx:id="newplaceFormularTitle" text="Ort ändern/erstellen">
<font>
<Font name="System Bold" size="21.0" />
</font>
@@ -86,16 +79,6 @@
<Insets />
</GridPane.margin>
</TextField>
<Label fx:id="firstNameLabel" styleClass="lableGrid" text="Vorname" GridPane.rowIndex="1">
<GridPane.margin>
<Insets />
</GridPane.margin>
</Label>
<TextField fx:id="firstNameTextField" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField fx:id="phoneNumberTextField" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField fx:id="birthDateTextField" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label fx:id="phoneNumberLabel" text="Telefonnummer" GridPane.rowIndex="2" />
<Label fx:id="birthDateLabel" text="Geb. Datum" GridPane.rowIndex="3" />
</children>
</GridPane>
<Separator prefWidth="200.0" />