Skip to content

Commit

Permalink
Add location to Urne
Browse files Browse the repository at this point in the history
  • Loading branch information
HSZemi committed Dec 31, 2019
1 parent 9593dab commit d6b471b
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public class MainWindowController implements Initializable {
private TableColumn<Urne, String> columnUrnenName;
@FXML
private TableColumn<Urne, Integer> columnUrnenNummer;
@FXML
private TableColumn<Urne, String> columnUrnenStandort;

@FXML
private Button buttonListeAdd;
Expand Down Expand Up @@ -126,6 +128,7 @@ public void initializeGUI() {
// Initialisiere Tabelle und verbinde mit Model
columnUrnenName.setCellValueFactory(new PropertyValueFactory<Urne, String>("name"));
columnUrnenNummer.setCellValueFactory(new PropertyValueFactory<Urne, Integer>("nummer"));
columnUrnenStandort.setCellValueFactory(new PropertyValueFactory<Urne, String>("standort"));
tableUrnen.setItems(wahl.getUrnen());
// Nur einzelne Zeilen auswählen
tableUrnen.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class UrneAddDialogController implements Initializable {
private TextField inputName;
@FXML
private TextField inputNummer;
@FXML
private TextField inputStandort;

/**
* Initializes the controller class.
Expand All @@ -39,13 +41,14 @@ public class UrneAddDialogController implements Initializable {
public void initialize(URL url, ResourceBundle rb) {
inputName.setPromptText("Name der Urne eingeben");
inputNummer.setPromptText("Nummer der Urne eingeben");
inputStandort.setPromptText("Standort der Urne eingeben");
}

@FXML
private void handleButtonAdd(ActionEvent event) {
// Füge neue Urne zur Wahl hinzu
Wahl wahl = Wahl.getInstance();
Urne urne = new Urne(inputName.getText(), Integer.parseInt(inputNummer.getText()));
Urne urne = new Urne(inputName.getText(), Integer.parseInt(inputNummer.getText()), inputStandort.getText());
wahl.addUrne(urne);

// Schließe das Fenster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class UrneRenameDialogController implements Initializable {
private TextField inputName;
@FXML
private TextField inputNummer;
@FXML
private TextField inputStandort;

private Urne urne;

Expand All @@ -46,13 +48,15 @@ public void setUrne(Urne urne) {
this.urne = urne;
inputName.setText(this.urne.getName());
inputNummer.setText(Integer.toString(this.urne.getNummer()));
inputStandort.setText(this.urne.getStandort());
}

@FXML
private void handleButtonRename(ActionEvent event) {
// Ändere Name der Urne
this.urne.setName(inputName.getText());
this.urne.setNummer(Integer.parseInt(inputNummer.getText()));
this.urne.setStandort(inputStandort.getText());

// Pseudo-Update auf die Liste, damit Änderung in GUI sichtbar wird
int index = Wahl.getInstance().getUrnen().indexOf(this.urne);
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/net/cgro/votemanager/model/Urne.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ public class Urne {
private final SimpleIntegerProperty nummer;
private final SimpleStringProperty status;

private final SimpleStringProperty standort;

public Urne(String name, int nummer) {
this(name, nummer, "");
}

public Urne(String name, int nummer, String standort) {
this.name = new SimpleStringProperty(name);
this.nummer = new SimpleIntegerProperty(nummer);
this.status = new SimpleStringProperty();
this.standort = new SimpleStringProperty(standort);
this.updateStatus();
}

private Urne() {
this.name = new SimpleStringProperty();
this.nummer = new SimpleIntegerProperty();
this.status = new SimpleStringProperty();
this.standort = new SimpleStringProperty();
this.updateStatus();
}

Expand All @@ -46,6 +54,19 @@ public void setNummer(int nummer) {
this.nummer.set(nummer);
}

@XmlAttribute
public String getStandort() {
return standort.get();
}

public void setStandort(String standort) {
this.standort.set(standort);
}

public SimpleStringProperty standortProperty() {
return standort;
}

public void updateStatus() {
if (!Wahl.getInstance().existiertErgebnis(this)) {
status.set("Kein Ergebnis");
Expand Down
30 changes: 23 additions & 7 deletions src/main/resources/fxml/MainWindow.fxml
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.SeparatorMenuItem?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TreeTableColumn?>
<?import javafx.scene.control.TreeTableView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="net.cgro.votemanager.controller.MainWindowController">
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="net.cgro.votemanager.controller.MainWindowController">
<top>
<MenuBar BorderPane.alignment="CENTER">
<menus>
Expand Down Expand Up @@ -76,7 +91,8 @@
<TableView id="table_urnen" fx:id="tableUrnen" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<columns>
<TableColumn id="col_urne_nummer" fx:id="columnUrnenNummer" maxWidth="50.0" minWidth="50.0" prefWidth="50.0" text="#" />
<TableColumn id="col_urne_name" fx:id="columnUrnenName" editable="false" prefWidth="700.0" text="Name" />
<TableColumn id="col_urne_name" fx:id="columnUrnenName" editable="false" prefWidth="400.0" text="Name" />
<TableColumn id="col_urne_standort" fx:id="columnUrnenStandort" editable="false" prefWidth="250.0" text="Standort" />
</columns>
</TableView>
</center>
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/fxml/UrneAddDialog.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
<Insets top="10.0" />
</VBox.margin>
</TextField>
<Label text="Standort der Urne">
<padding>
<Insets top="20.0" />
</padding>
</Label>
<TextField id="input_urne_standort" fx:id="inputStandort">
<VBox.margin>
<Insets top="10.0" />
</VBox.margin>
</TextField>
<HBox prefHeight="25.0" prefWidth="200.0">
<children>
<Button id="btn_add_urne_confirm" fx:id="buttonAdd" defaultButton="true" mnemonicParsing="false" onAction="#handleButtonAdd" text="Hinzufügen">
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/fxml/UrneRenameDialog.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
<Insets top="10.0"/>
</VBox.margin>
</TextField>
<Label text="Standort der Urne">
<VBox.margin>
<Insets top="20.0"/>
</VBox.margin>
</Label>
<TextField fx:id="inputStandort">
<VBox.margin>
<Insets top="10.0"/>
</VBox.margin>
</TextField>
<HBox prefHeight="25.0" prefWidth="200.0">
<children>
<Button fx:id="buttonRename" defaultButton="true" mnemonicParsing="false" onAction="#handleButtonRename"
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/net/cgro/votemanager/util/WahlDeserializerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.cgro.votemanager.util;

import net.cgro.votemanager.model.*;
import org.junit.jupiter.api.Test;

import javax.xml.bind.JAXB;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;

import static net.cgro.votemanager.util.MergeHelper.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

class WahlDeserializerTest {

@Test
void testDeserializeOldWahl() throws Exception {
Wahl wahl = JAXB.unmarshal(Paths.get("src/test/resources/oldwahl.xml").toFile(), Wahl.class);
assertThat(wahl.getUrnen().size()).isEqualTo(2);
assertThat(wahl.getListen().size()).isEqualTo(2);
Urne urne1 = wahl.getUrnen().get(0);
Urne urne2 = wahl.getUrnen().get(1);
assertThat(urne1.getName()).isEqualTo("Urne 1");
assertThat(urne1.getNummer()).isEqualTo(1);
assertThat(urne1.getStandort()).isNull();
assertThat(urne2.getName()).isEqualTo("Urne 2");
assertThat(urne2.getNummer()).isEqualTo(2);
assertThat(urne2.getStandort()).isNull();
}
}
22 changes: 22 additions & 0 deletions src/test/resources/oldwahl.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<wahl>
<ergebnisse/>
<listen>
<liste kuerzel="L1" name="Liste 1" nummer="1">
<kandidaten>
<kandidat name="1 Kand 1" nummer="1"/>
<kandidat name="1 Kand 2" nummer="2"/>
</kandidaten>
</liste>
<liste kuerzel="L2" name="Liste 2" nummer="1">
<kandidaten>
<kandidat name="2 Kand 1" nummer="1"/>
<kandidat name="2 Kand 2" nummer="2"/>
</kandidaten>
</liste>
</listen>
<urnen>
<urne name="Urne 1" nummer="1"/>
<urne name="Urne 2" nummer="2"/>
</urnen>
</wahl>

0 comments on commit d6b471b

Please sign in to comment.