2016-06-12 09:15:50 -04:00
|
|
|
package polling_station_dashboard.search;
|
|
|
|
|
|
|
|
import javafx.event.Event;
|
|
|
|
import javafx.event.EventHandler;
|
2016-06-18 08:13:04 -04:00
|
|
|
import javafx.scene.layout.GridPane;
|
|
|
|
import javafx.scene.layout.Pane;
|
2016-06-18 06:17:46 -04:00
|
|
|
import javafx.stage.Stage;
|
|
|
|
import polling_station_dashboard.search.VotersFetcher.VotersFetcher;
|
|
|
|
import polling_station_dashboard.search.addVoter.java.AddVoterLoader;
|
|
|
|
|
2016-06-18 08:13:04 -04:00
|
|
|
import javafx.scene.control.Button;
|
2016-06-18 06:17:46 -04:00
|
|
|
import java.io.IOException;
|
2016-06-18 08:13:04 -04:00
|
|
|
import java.util.ArrayList;
|
2016-06-18 06:17:46 -04:00
|
|
|
import java.util.List;
|
2016-06-12 09:15:50 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Vladimir Eliezer Tokarev on 12/06/2016.
|
|
|
|
* SearchHandler trying to fetch wanted users by given strings (VotersFetcher) and then
|
|
|
|
* Starts the eddit/add panel based on what the VotersFetcher Have fetched.
|
|
|
|
*/
|
2016-06-18 08:13:04 -04:00
|
|
|
public class SearchHandler implements EventHandler {
|
2016-06-12 09:15:50 -04:00
|
|
|
|
2016-06-18 06:17:46 -04:00
|
|
|
private Stage currentStage;
|
2016-06-18 08:13:04 -04:00
|
|
|
private VotersFetcher votersFetcher;
|
|
|
|
private Button AddVoterButton;
|
|
|
|
public SearchHandler(Stage primaryStage, VotersFetcher votersFetcher)
|
|
|
|
{
|
2016-06-18 06:17:46 -04:00
|
|
|
this.currentStage = primaryStage;
|
2016-06-18 08:13:04 -04:00
|
|
|
this.votersFetcher = votersFetcher;
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<String> GetFilters()
|
|
|
|
{
|
|
|
|
return new ArrayList<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void AddVoterPanel() throws IOException
|
|
|
|
{
|
|
|
|
((Pane)currentStage.getScene().lookup("#AddEditPane")).getChildren().remove(this.AddVoterButton);
|
|
|
|
new AddVoterLoader(currentStage);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void AddVoterAddButton() throws IOException {
|
|
|
|
this.AddVoterButton = new Button("Add New Voter");
|
|
|
|
this.AddVoterButton.setOnAction(e -> {
|
|
|
|
try {
|
|
|
|
AddVoterPanel();
|
|
|
|
} catch (IOException e1) {
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
((Pane)currentStage.getScene().lookup("#AddEditPane")).getChildren().add(AddVoterButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void VotersCheck() throws IOException {
|
|
|
|
List<String> filters = GetFilters();
|
|
|
|
|
|
|
|
List<Object> voters = votersFetcher.FetchVoters(filters);
|
|
|
|
|
|
|
|
if (voters.isEmpty())
|
|
|
|
{
|
|
|
|
AddVoterAddButton();
|
|
|
|
}
|
|
|
|
else if(1==1)
|
|
|
|
{
|
|
|
|
// founded the voter but he cant vote
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// founded the voter and he can vote
|
|
|
|
}
|
2016-06-18 06:17:46 -04:00
|
|
|
}
|
2016-06-12 09:15:50 -04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handle(Event event) {
|
2016-06-18 06:17:46 -04:00
|
|
|
try {
|
2016-06-18 08:13:04 -04:00
|
|
|
VotersCheck();
|
2016-06-18 06:17:46 -04:00
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2016-06-12 09:15:50 -04:00
|
|
|
}
|