changed ParticipantFormular to change existing objects and don't replace them.
changed ParticipantFormular and PlacesFormular to clear textfields after saving. solved #19
This commit is contained in:
parent
02456bc5bf
commit
3d13dbcb45
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -31,8 +31,13 @@ public class Tournament implements Serializable {
|
|||
places = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addParticipant(Participant newParticipant) throws ParticipantExistsException {
|
||||
participants.removeIf(participant -> participant.equals(newParticipant));
|
||||
public void saveParticipant(Participant newParticipant) throws ParticipantExistsException {
|
||||
for(Participant participant: participants){
|
||||
if(participant.equals(newParticipant)){
|
||||
participant.change(newParticipant);
|
||||
return;
|
||||
}
|
||||
}
|
||||
participants.add(newParticipant);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -58,6 +58,11 @@ public class PlacesFormularController extends FXController {
|
|||
@FXML
|
||||
void savePlace(ActionEvent event) {
|
||||
getTournamentDecorator().savePlace(placeNameTextField.getText());
|
||||
clearFormular();
|
||||
}
|
||||
|
||||
private void clearFormular() {
|
||||
placeNameTextField.clear();
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
|
Loading…
Reference in New Issue