Participant list #13
|
@ -1,23 +1,36 @@
|
||||||
package ch.zhaw.projekt2.turnierverwaltung;
|
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{
|
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 {
|
public Player(String firstName, String name, String phoneNumber, String dateOfBirth) throws InvalidNameException, InvalidPhoneNumberException {
|
||||||
super(firstName, name, phoneNumber);
|
super(firstName, name, phoneNumber);
|
||||||
setDateOfBirth(dateOfBirth);
|
setDateOfBirth(dateOfBirth);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GregorianCalendar getDateOfBirth() {
|
public LocalDate getDateOfBirth() {
|
||||||
return dateOfBirth;
|
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) {
|
public void setDateOfBirth(String dateOfBirth) {
|
||||||
String[] date = dateOfBirth.split("\\.");
|
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
|
@Override
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class Tournament implements Serializable {
|
||||||
public void addParticipant(Participant newParticipant) throws ParticipantExistsException {
|
public void addParticipant(Participant newParticipant) throws ParticipantExistsException {
|
||||||
for(Participant participant : participants){
|
for(Participant participant : participants){
|
||||||
if(participant.equals(newParticipant)){
|
if(participant.equals(newParticipant)){
|
||||||
throw new ParticipantExistsException("A Participant with the same Name exists already.");
|
participants.remove(participant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
participants.add(newParticipant);
|
participants.add(newParticipant);
|
||||||
|
@ -41,6 +41,7 @@ public class Tournament implements Serializable {
|
||||||
if(!participants.contains(participant)){
|
if(!participants.contains(participant)){
|
||||||
throw new ParticipantNotExistsException("The given Participant is not part of this Tournament");
|
throw new ParticipantNotExistsException("The given Participant is not part of this Tournament");
|
||||||
}
|
}
|
||||||
|
participants.remove(participant);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableList<Participant> getParticipants() {
|
public ObservableList<Participant> getParticipants() {
|
||||||
|
|
|
@ -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 {
|
try {
|
||||||
tournament.addParticipant(new Player(firstName, name, phoneNumber, dateOfBirth));
|
tournament.addParticipant(new Player(firstName, name, phoneNumber, dateOfBirth));
|
||||||
informListener();
|
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() {
|
public void informListener() {
|
||||||
for(IsObserver observer : listener) {
|
for(IsObserver observer : listener) {
|
||||||
observer.update();
|
observer.update();
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ch.zhaw.projekt2.turnierverwaltung.main.participantAddFormular;
|
||||||
|
|
||||||
import ch.zhaw.projekt2.turnierverwaltung.FXController;
|
import ch.zhaw.projekt2.turnierverwaltung.FXController;
|
||||||
import ch.zhaw.projekt2.turnierverwaltung.Participant;
|
import ch.zhaw.projekt2.turnierverwaltung.Participant;
|
||||||
|
import ch.zhaw.projekt2.turnierverwaltung.Player;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
|
@ -39,7 +40,11 @@ public class ParticipantFormularController extends FXController {
|
||||||
private Label newParticipantFormularTitle;
|
private Label newParticipantFormularTitle;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button openBtn;
|
private Button closeBtn;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button deleteBtn;
|
||||||
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Label participantListTitle;
|
private Label participantListTitle;
|
||||||
|
@ -63,8 +68,12 @@ public class ParticipantFormularController extends FXController {
|
||||||
private Button saveBtn;
|
private Button saveBtn;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void addParticipant(ActionEvent event) {
|
void changedSelection(MouseEvent event){
|
||||||
getTournamentDecorator().addPlayer(firstNameTextField.getText(), participantNameTextField.getText(), phoneNumberTextField.getText(), birthDateTextField.getText());
|
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
|
@FXML
|
||||||
|
@ -73,7 +82,20 @@ public class ParticipantFormularController extends FXController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@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) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,11 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.geometry.Insets?>
|
<?import javafx.geometry.*?>
|
||||||
<?import javafx.scene.control.Button?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.layout.*?>
|
||||||
<?import javafx.scene.control.ListView?>
|
<?import javafx.scene.text.*?>
|
||||||
<?import javafx.scene.control.Menu?>
|
|
||||||
<?import javafx.scene.control.MenuBar?>
|
|
||||||
<?import javafx.scene.control.MenuItem?>
|
|
||||||
<?import javafx.scene.control.Separator?>
|
|
||||||
<?import javafx.scene.control.TextField?>
|
|
||||||
|
|
||||||
<?import javafx.scene.layout.ColumnConstraints?>
|
<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.participantAddFormular.ParticipantFormularController">
|
||||||
<?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" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.participantAddFormular.ParticipantFormularController">
|
|
||||||
<children>
|
<children>
|
||||||
<VBox alignment="TOP_CENTER" prefHeight="331.0" prefWidth="308.0" HBox.hgrow="ALWAYS">
|
<VBox alignment="TOP_CENTER" prefHeight="331.0" prefWidth="308.0" HBox.hgrow="ALWAYS">
|
||||||
<children>
|
<children>
|
||||||
|
@ -29,19 +17,23 @@
|
||||||
<Insets bottom="20.0" />
|
<Insets bottom="20.0" />
|
||||||
</VBox.margin>
|
</VBox.margin>
|
||||||
</Label>
|
</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>
|
<VBox.margin>
|
||||||
<Insets />
|
<Insets />
|
||||||
</VBox.margin>
|
</VBox.margin>
|
||||||
</ListView>
|
</ListView>
|
||||||
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
|
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
|
||||||
<children>
|
<children>
|
||||||
<Button fx:id="saveBtn" mnemonicParsing="false" onAction="#save" text="Save">
|
<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>
|
<HBox.margin>
|
||||||
<Insets right="40.0" />
|
<Insets right="40.0" />
|
||||||
</HBox.margin>
|
</HBox.margin>
|
||||||
</Button>
|
</Button>
|
||||||
<Button fx:id="openBtn" mnemonicParsing="false" text="Bearbeiten" />
|
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
</children>
|
</children>
|
||||||
|
@ -56,7 +48,7 @@
|
||||||
</Separator>
|
</Separator>
|
||||||
<VBox fx:id="changeBtn" alignment="TOP_CENTER" onDragDetected="#changeParticipant" prefHeight="331.0" prefWidth="308.0" HBox.hgrow="ALWAYS">
|
<VBox fx:id="changeBtn" alignment="TOP_CENTER" onDragDetected="#changeParticipant" prefHeight="331.0" prefWidth="308.0" HBox.hgrow="ALWAYS">
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="newParticipantFormularTitle" text="Neuer Teilnehmer">
|
<Label fx:id="newParticipantFormularTitle" text="Teilnehmer ändern/erstellen">
|
||||||
<font>
|
<font>
|
||||||
<Font name="System Bold" size="21.0" />
|
<Font name="System Bold" size="21.0" />
|
||||||
</font>
|
</font>
|
||||||
|
@ -100,7 +92,7 @@
|
||||||
</children>
|
</children>
|
||||||
</GridPane>
|
</GridPane>
|
||||||
<Separator prefWidth="200.0" />
|
<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>
|
<VBox.margin>
|
||||||
<Insets bottom="10.0" top="30.0" />
|
<Insets bottom="10.0" top="30.0" />
|
||||||
</VBox.margin>
|
</VBox.margin>
|
||||||
|
|
Loading…
Reference in New Issue