package polling_station_dashboard.search; import javafx.event.Event; import javafx.event.EventHandler; import javafx.scene.layout.GridPane; import javafx.scene.layout.Pane; import javafx.stage.Stage; 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.List; /** * 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. */ public class SearchHandler implements EventHandler { private Stage currentStage; private VotersFetcher votersFetcher; private Button AddVoterButton; public SearchHandler(Stage primaryStage, VotersFetcher votersFetcher) { this.currentStage = primaryStage; this.votersFetcher = votersFetcher; } private List 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 filters = GetFilters(); List 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 } } @Override public void handle(Event event) { try { VotersCheck(); } catch (IOException e) { e.printStackTrace(); } } }