From 1fa38ddb5fed36569f644e9d7f8a1f387b6fdc86 Mon Sep 17 00:00:00 2001 From: Vladimir Eliezer Tokarev Date: Sat, 2 Jul 2016 18:05:29 +0300 Subject: [PATCH] Removed the lodge appeal managment from event handler map the lodge appeal object is sub flow of the submit voter flow which means that polling station dashboard should not know about its existance. --- .../EventHandlerMap.java | 2 +- .../EventHandlerMapper.java | 6 ----- .../submitVoter/SubmitVoterController.java | 12 ++++++++++ .../search/submitVoter/SubmitVoterLoader.java | 5 ++++ .../lodgeAppeal/LodgeAppealController.java | 10 ++++++++ .../lodgeAppeal/LodgeAppealVisualUpdater.java | 24 ++++++++++--------- .../view/dashboard/lodge_appeal.fxml | 5 ++-- .../dashboard/polling_station_dashboard.fxml | 3 ++- .../view/dashboard/submit_voter.fxml | 2 +- 9 files changed, 46 insertions(+), 23 deletions(-) diff --git a/polling-station-gui/src/main/java/polling_station_dashboard/EventHandlerMap.java b/polling-station-gui/src/main/java/polling_station_dashboard/EventHandlerMap.java index 56bf4c3..17a2d98 100644 --- a/polling-station-gui/src/main/java/polling_station_dashboard/EventHandlerMap.java +++ b/polling-station-gui/src/main/java/polling_station_dashboard/EventHandlerMap.java @@ -34,7 +34,7 @@ public class EventHandlerMap { } catch (RuntimeException e) { System.out.println("The event map doesn't have this kind of event handler : " + e); - throw e; + // add logs ... } } } diff --git a/polling-station-gui/src/main/java/polling_station_dashboard/EventHandlerMapper.java b/polling-station-gui/src/main/java/polling_station_dashboard/EventHandlerMapper.java index b758ca3..16a54a8 100644 --- a/polling-station-gui/src/main/java/polling_station_dashboard/EventHandlerMapper.java +++ b/polling-station-gui/src/main/java/polling_station_dashboard/EventHandlerMapper.java @@ -39,12 +39,6 @@ public class EventHandlerMapper { map.Add("StatusLogButton", statusLogVisualUpdater); map.Add("StatusLog", statusLogVisualUpdater); - // maps lodge appeal object to lodge appeal visual updater - LodgeAppealLoader lodgeAppealLoader = new LodgeAppealLoader(primaryStage); - LodgeAppealVisualUpdater lodgeAppealVisualUpdater = new LodgeAppealVisualUpdater( - lodgeAppealLoader.GetSettingsInstance(), primaryStage); - map.Add("LodgeAppealButton", lodgeAppealVisualUpdater); - // map add voter to search button triggered SearchHandler searchHandler = new SearchHandler(primaryStage, new DummyVotersFetcher()); map.Add("SearchButton", searchHandler); diff --git a/polling-station-gui/src/main/java/polling_station_dashboard/search/submitVoter/SubmitVoterController.java b/polling-station-gui/src/main/java/polling_station_dashboard/search/submitVoter/SubmitVoterController.java index 9d1933e..bdbdf2a 100644 --- a/polling-station-gui/src/main/java/polling_station_dashboard/search/submitVoter/SubmitVoterController.java +++ b/polling-station-gui/src/main/java/polling_station_dashboard/search/submitVoter/SubmitVoterController.java @@ -1,8 +1,10 @@ package polling_station_dashboard.search.submitVoter; import javafx.fxml.FXML; +import javafx.scene.layout.GridPane; import javafx.scene.layout.Pane; import javafx.stage.Stage; +import polling_station_dashboard.search.submitVoter.lodgeAppeal.LodgeAppealVisualUpdater; /** * Created by Vladimir Eliezer Tokarev on 18/06/2016. @@ -11,12 +13,22 @@ import javafx.stage.Stage; */ public class SubmitVoterController { private Stage currentStage; + private LodgeAppealVisualUpdater lodgeAppealVisualUpdater; public void SetStage(Stage primaryStage) { this.currentStage = primaryStage; } + public void SetLodgeAppeal(GridPane lodgeAppeal){ + this.lodgeAppealVisualUpdater = new LodgeAppealVisualUpdater(lodgeAppeal, currentStage); + } + + @FXML + private void AddLodgeAppeal(){ + this.lodgeAppealVisualUpdater.UpdateLodgeAppeal(); + } + @FXML private void RemoveSubmitVoterPanel() { diff --git a/polling-station-gui/src/main/java/polling_station_dashboard/search/submitVoter/SubmitVoterLoader.java b/polling-station-gui/src/main/java/polling_station_dashboard/search/submitVoter/SubmitVoterLoader.java index dad7dd2..991a581 100644 --- a/polling-station-gui/src/main/java/polling_station_dashboard/search/submitVoter/SubmitVoterLoader.java +++ b/polling-station-gui/src/main/java/polling_station_dashboard/search/submitVoter/SubmitVoterLoader.java @@ -5,6 +5,7 @@ import javafx.scene.Parent; import javafx.scene.control.Label; import javafx.scene.layout.Pane; import javafx.stage.Stage; +import polling_station_dashboard.search.submitVoter.lodgeAppeal.LodgeAppealLoader; import java.io.IOException; import java.util.HashMap; @@ -39,9 +40,13 @@ public class SubmitVoterLoader { Parent root = this.fxmlLoader.load(); ResetVoterParams(voter, root); + LodgeAppealLoader lodgeAppealLoader = new LodgeAppealLoader(currentStage); + SubmitVoterController controller = fxmlLoader.getController(); Pane addEditPane = (Pane)currentStage.getScene().lookup("#AddEditPane"); addEditPane.getChildren().add(root); + controller.SetStage(currentStage); + controller.SetLodgeAppeal(lodgeAppealLoader.GetSettingsInstance()); } } diff --git a/polling-station-gui/src/main/java/polling_station_dashboard/search/submitVoter/lodgeAppeal/LodgeAppealController.java b/polling-station-gui/src/main/java/polling_station_dashboard/search/submitVoter/lodgeAppeal/LodgeAppealController.java index 60a4b23..3c6cdcc 100644 --- a/polling-station-gui/src/main/java/polling_station_dashboard/search/submitVoter/lodgeAppeal/LodgeAppealController.java +++ b/polling-station-gui/src/main/java/polling_station_dashboard/search/submitVoter/lodgeAppeal/LodgeAppealController.java @@ -1,5 +1,7 @@ package polling_station_dashboard.search.submitVoter.lodgeAppeal; +import javafx.fxml.FXML; +import javafx.scene.layout.Pane; import javafx.stage.Stage; /** @@ -13,4 +15,12 @@ public class LodgeAppealController { { this.currentStage = primaryStage; } + + @FXML + private void HandleCancel(){ + Pane addEditPane = (Pane) currentStage.getScene().lookup("#AddEditPane"); + // the add edit pane have only one child at a time which mean removing the child in index 0 will + // clean the add edit pane + addEditPane.getChildren().remove(0); + } } diff --git a/polling-station-gui/src/main/java/polling_station_dashboard/search/submitVoter/lodgeAppeal/LodgeAppealVisualUpdater.java b/polling-station-gui/src/main/java/polling_station_dashboard/search/submitVoter/lodgeAppeal/LodgeAppealVisualUpdater.java index 59f3dcc..2431d15 100644 --- a/polling-station-gui/src/main/java/polling_station_dashboard/search/submitVoter/lodgeAppeal/LodgeAppealVisualUpdater.java +++ b/polling-station-gui/src/main/java/polling_station_dashboard/search/submitVoter/lodgeAppeal/LodgeAppealVisualUpdater.java @@ -1,7 +1,5 @@ package polling_station_dashboard.search.submitVoter.lodgeAppeal; -import javafx.event.Event; -import javafx.event.EventHandler; import javafx.scene.layout.GridPane; import javafx.scene.layout.Pane; import javafx.stage.Stage; @@ -11,7 +9,7 @@ import javafx.stage.Stage; * LodgeAppealVisualUpdater is in response of add and remove the lodge appeal panel * to polling station dashboard */ -public class LodgeAppealVisualUpdater implements EventHandler { +public class LodgeAppealVisualUpdater { private Stage currentStage; private GridPane lodgeAppeal; @@ -23,22 +21,26 @@ public class LodgeAppealVisualUpdater implements EventHandler { this.currentStage = primalStage; } - private void UpdateLodgeAppeal() { + public void UpdateLodgeAppeal() { if (!lodgeAppealOpened) { - addLodgeAppeal(); + ClearAddEditPanel(); + AddLodgeAppeal(); } else { + ClearAddEditPanel(); } lodgeAppealOpened = !lodgeAppealOpened; } - private void addLodgeAppeal() { + private void ClearAddEditPanel(){ + Pane addEditPane = (Pane) currentStage.getScene().lookup("#AddEditPane"); + // the add edit pane have only one child at a time which mean removing the child in index 0 will + // clean the add edit pane + addEditPane.getChildren().remove(0); + } + + private void AddLodgeAppeal() { Pane addEditPane = (Pane)currentStage.getScene().lookup("#AddEditPane"); addEditPane.getChildren().add(lodgeAppeal); } - - @Override - public void handle(Event event) { - UpdateLodgeAppeal(); - } } diff --git a/polling-station-gui/src/main/resources/view/dashboard/lodge_appeal.fxml b/polling-station-gui/src/main/resources/view/dashboard/lodge_appeal.fxml index c5ea960..d647d79 100644 --- a/polling-station-gui/src/main/resources/view/dashboard/lodge_appeal.fxml +++ b/polling-station-gui/src/main/resources/view/dashboard/lodge_appeal.fxml @@ -7,8 +7,7 @@ - + @@ -429,7 +428,7 @@ -