Added the submit voter logic to PSD

Now all the search flow works, if the users dont find any users hi is
given the option to add one, if it found then the submit voter panel is
open.
voting-station-gui
Vladimir ELazar Tokarev 2016-06-18 19:00:02 +03:00
parent f813c11edd
commit 36e1f6ea20
8 changed files with 68 additions and 30 deletions

View File

@ -2,7 +2,6 @@
<!-- Created By Vladimir Eliezer Tokarev !-->
<?import java.lang.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
@ -38,7 +37,7 @@
</ImageView>
</left>
<center>
<TextField prefHeight="56.0" prefWidth="536.0" BorderPane.alignment="CENTER" />
<TextField fx:id="SearchValue" prefHeight="56.0" prefWidth="536.0" BorderPane.alignment="CENTER" text="IDNumber: 123123123, FilterName2: value2 ..." />
</center>
</BorderPane>
</children>

View File

@ -2,16 +2,17 @@ package polling_station_dashboard.search;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import polling_station_dashboard.search.submitVoter.java.SubmitVoterLoader;
import polling_station_dashboard.search.votersFetcher.VotersFetcher;
import polling_station_dashboard.search.addVoter.java.AddVoterLoader;
import javafx.scene.control.Button;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.lang.reflect.Array;
import java.util.*;
/**
* Created by Vladimir Eliezer Tokarev on 12/06/2016.
@ -31,13 +32,15 @@ public class SearchHandler implements EventHandler {
private List<String> GetFilters()
{
return new ArrayList<>();
String unSeparatedFilters = ((TextField)this.currentStage.getScene().lookup("#SearchValue")).getText();
String[] filters = unSeparatedFilters.split(" -|\\:|\\,");
return Arrays.asList(filters);
}
private void AddVoterPanel() throws IOException
{
((Pane)currentStage.getScene().lookup("#AddEditPane")).getChildren().remove(this.AddVoterButton);
new AddVoterLoader(currentStage);
((Pane)this.currentStage.getScene().lookup("#AddEditPane")).getChildren().remove(this.AddVoterButton);
new AddVoterLoader(this.currentStage);
}
private void AddVoterAddButton() throws IOException {
@ -52,6 +55,12 @@ public class SearchHandler implements EventHandler {
((Pane)currentStage.getScene().lookup("#AddEditPane")).getChildren().add(AddVoterButton);
}
private void AddSubmitVoterPanel(HashMap<String, String> voter) throws IOException
{
SubmitVoterLoader submitVoterLoader = new SubmitVoterLoader(this.currentStage);
submitVoterLoader.GenerateVoterSubmit(voter);
}
private void VotersCheck() throws IOException {
List<String> filters = GetFilters();
@ -61,13 +70,9 @@ public class SearchHandler implements EventHandler {
{
AddVoterAddButton();
}
else if(voters.get(0).get("EligibleToVote").equals("no"))
else if(voters.get(0).get("EligibleToVote").equals("no") || voters.get(0).get("EligibleToVote").equals("yes"))
{
// founded the voter but he cant vote
}
else if(voters.get(0).get("EligibleToVote").equals("yes"))
{
// founded the voter and he can vote
AddSubmitVoterPanel(voters.get(0));
}
else
{
@ -75,10 +80,16 @@ public class SearchHandler implements EventHandler {
}
}
private void CleanSearchLine()
{
((TextField)this.currentStage.getScene().lookup("#SearchValue")).setText(" ");
}
@Override
public void handle(Event event) {
try {
VotersCheck();
CleanSearchLine();
} catch (IOException e) {
e.printStackTrace();
}

View File

@ -2,12 +2,11 @@
<?import javafx.scene.image.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="250.0" prefWidth="753.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="polling_station_dashboard.search.addVoter.java.AddVoterController">
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="250.0" prefWidth="753.0"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="polling_station_dashboard.search.addVoter.java.AddVoterController">
<columnConstraints>
<ColumnConstraints />
<ColumnConstraints />

View File

@ -25,6 +25,7 @@ public class AddVoterController {
{
// when this button pressed (the cancel button) only the add voter panel is in list of children of AddEditPane
// this why removing the element at index 0 will remove this panel
System.out.println(((Pane)this.currentStage.getScene().lookup("#AddEditPane")).getChildren());
((Pane)this.currentStage.getScene().lookup("#AddEditPane")).getChildren().remove(0);
}
}

View File

@ -13,7 +13,7 @@ import java.io.IOException;
*/
public class AddVoterLoader {
private static final String ADD_VOTER_FXML_PATH = "../fxml/submit_voter.fxml";
private static final String ADD_VOTER_FXML_PATH = "../fxml/add_voter.fxml";
private Stage currentStage;

View File

@ -1,13 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.image.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="250.0" prefWidth="753.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="polling_station_dashboard.search.addVoter.java.AddVoterController">
<GridPane fx:id="SubmitVoterPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="250.0" prefWidth="753.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="polling_station_dashboard.search.submitVoter.java.SubmitVoterController">
<columnConstraints>
<ColumnConstraints />
<ColumnConstraints />
@ -87,10 +86,13 @@
</Label>
</center>
</BorderPane>
<Label prefHeight="29.0" prefWidth="107.0" text="234234234" GridPane.columnIndex="1" />
<Label prefHeight="23.0" prefWidth="107.0" text="YES" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label prefHeight="38.0" prefWidth="107.0" text="Has Not Voted" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label prefHeight="60.0" prefWidth="107.0" text="IDC Maths" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label fx:id="IDNumberValue" prefHeight="29.0" prefWidth="107.0" text="234234234" GridPane.columnIndex="1" />
<Label fx:id="EligibleToVoteValue" prefHeight="23.0" prefWidth="107.0" text="YES" GridPane.columnIndex="1" GridPane.rowIndex="1">
<padding>
<Insets left="3.0" />
</padding></Label>
<Label fx:id="StatusValue" prefHeight="38.0" prefWidth="107.0" text="Has Not Voted" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label fx:id="ChannelValue" prefHeight="60.0" prefWidth="107.0" text="IDC Maths" GridPane.columnIndex="1" GridPane.rowIndex="3" />
</children>
</GridPane>
</children>
@ -133,7 +135,7 @@
<children>
<BorderPane prefHeight="200.0" prefWidth="200.0">
<center>
<Button mnemonicParsing="false" onMousePressed="#RemoveAddVoterPanel" text="Cancel" BorderPane.alignment="CENTER" />
<Button mnemonicParsing="false" onMousePressed="#RemoveSubmitVoterPanel" text="Cancel" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1">

View File

@ -1,5 +1,7 @@
package polling_station_dashboard.search.submitVoter.java;
import javafx.fxml.FXML;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
/**
@ -14,4 +16,12 @@ public class SubmitVoterController {
{
this.currentStage = primaryStage;
}
@FXML
private void RemoveSubmitVoterPanel()
{
// when this button pressed (the cancel button) only the add voter panel is in list of children of AddEditPane
// this why removing the element at index 0 will remove this panel
((Pane)this.currentStage.getScene().lookup("#AddEditPane")).getChildren().remove(0);
}
}

View File

@ -2,10 +2,12 @@ package polling_station_dashboard.search.submitVoter.java;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import java.io.IOException;
import java.util.HashMap;
/**
* Created by Vladimir Eliezer Tokarev on 18/06/2016.
@ -16,16 +18,30 @@ public class SubmitVoterLoader {
private static final String SUBMIT_VOTER_FXML_PATH = "../fxml/submit_voter.fxml";
private Stage currentStage;
private FXMLLoader fxmlLoader;
private void ResetVoterParams(HashMap<String, String> voter, Parent root)
{
((Label)root.lookup("#IDNumberValue")).setText(voter.get("IDNumber"));
((Label)root.lookup("#EligibleToVoteValue")).setText(voter.get("EligibleToVote"));
((Label)root.lookup("#StatusValue")).setText(voter.get("Status"));
((Label)root.lookup("#ChannelValue")).setText(voter.get("Channel"));
}
public SubmitVoterLoader (Stage primaryStage) throws IOException
{
currentStage = primaryStage;
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(SUBMIT_VOTER_FXML_PATH));
Parent root = fxmlLoader.load();
SubmitVoterController controller = fxmlLoader.getController();
this.fxmlLoader = new FXMLLoader(getClass().getResource(SUBMIT_VOTER_FXML_PATH));
}
public void GenerateVoterSubmit(HashMap<String, String> voter) throws IOException
{
Parent root = this.fxmlLoader.load();
ResetVoterParams(voter, root);
SubmitVoterController controller = fxmlLoader.getController();
Pane addEditPane = (Pane)currentStage.getScene().lookup("#AddEditPane");
addEditPane.getChildren().add(root);
controller.SetStage(primaryStage);
controller.SetStage(currentStage);
}
}