From 827451d665a3c978baa92ad51745b3e695d68d42 Mon Sep 17 00:00:00 2001 From: Notmoo Date: Sat, 19 Aug 2017 21:20:59 +0200 Subject: [PATCH] =?UTF-8?q?Module=20Client,=20packg=20main=5Fframe=20:=20i?= =?UTF-8?q?l=20est=20de=20nouveau=20possible=20de=20demander=20=C3=A0=20ce?= =?UTF-8?q?=20que=20un=20module=20donn=C3=A9=20soit=20actif=20lors=20de=20?= =?UTF-8?q?son=20ajout=20=C3=A0=20la=20main=20frame?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/pqt/client/Main.java | 2 +- .../pqt/client/gui/main_frame/MainFrame.java | 6 +++++- .../gui/main_frame/MainFrameController.java | 7 +++++-- .../client/gui/main_frame/MainFrameView.java | 17 +++++++++++++++-- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Workspace/client/src/main/java/com/pqt/client/Main.java b/Workspace/client/src/main/java/com/pqt/client/Main.java index 4780949d..c7240576 100644 --- a/Workspace/client/src/main/java/com/pqt/client/Main.java +++ b/Workspace/client/src/main/java/com/pqt/client/Main.java @@ -32,7 +32,7 @@ public class Main extends Application{ StatService statService = new StatService(); MainFrame mainFrame = new MainFrame(accountService); - mainFrame.addModule(new SaleScreen(accountService, stockService, saleService)); + mainFrame.addModule(new SaleScreen(accountService, stockService, saleService), true); mainFrame.addModule(new StockScreen(stockService, accountService)); mainFrame.addModule(new StatScreen(statService)); mainFrame.addModule(new AccountScreen(accountService)); diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrame.java b/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrame.java index 73d9c53f..4ded52f6 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrame.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrame.java @@ -20,8 +20,12 @@ public class MainFrame implements IFXComponent { ctrl.updateView(); } + public void addModule(IGuiModule module, boolean setActive){ + ctrl.addModule(module, setActive); + } + public void addModule(IGuiModule module){ - ctrl.addModule(module); + ctrl.addModule(module, false); } @Override diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrameController.java b/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrameController.java index be3d474d..180f7802 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrameController.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrameController.java @@ -31,8 +31,11 @@ class MainFrameController implements IMainFrameModelListener { view.updateModuleButtonLock(AccountLevel.getLowest()); } - void addModule(IGuiModule module) { - this.view.addGuiModule(module.getModuleName(),module.getPane(), module.getLowestRequiredAccountLevel()); + void addModule(IGuiModule module, boolean activationRequired) { + boolean activate = activationRequired + && model.getCurrentAccount()!=null + && model.getCurrentAccount().getPermissionLevel().compareTo(module.getLowestRequiredAccountLevel())>=0; + this.view.addGuiModule(module.getModuleName(),module.getPane(), module.getLowestRequiredAccountLevel(), activate); } IValidatorComponentListener getAccountManagerValidatorListener() { diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrameView.java b/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrameView.java index d76d2674..7b951581 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrameView.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrameView.java @@ -15,6 +15,8 @@ import javafx.geometry.Orientation; import javafx.scene.Node; import javafx.scene.control.Button; import javafx.scene.control.ToolBar; +import javafx.scene.input.KeyCode; +import javafx.scene.input.MouseButton; import javafx.scene.layout.BorderPane; import javafx.scene.layout.Pane; import javafx.scene.layout.Priority; @@ -87,10 +89,11 @@ class MainFrameView implements IFXComponent{ return mainPane; } - void addGuiModule(String moduleName, Pane moduleContent, AccountLevel requiredLevel){ + void addGuiModule(String moduleName, Pane moduleContent, AccountLevel requiredLevel, boolean setActive){ Button button = new Button(moduleName); button.getStyleClass().add("menu-button"); - button.setOnMouseClicked(event->{ + + Runnable buttonActivationCode = ()->{ buttonHolder.getChildren() .stream() .filter(Button.class::isInstance) @@ -101,9 +104,19 @@ class MainFrameView implements IFXComponent{ buttonHolder.getChildren().forEach(Node::applyCss); mainPane.setCenter(moduleContent); }); + }; + button.setOnMouseClicked(event-> { + if(event.getButton().equals(MouseButton.PRIMARY)) + buttonActivationCode.run(); + }); + button.setOnKeyTyped(event->{ + if (event.getCode().equals(KeyCode.ENTER)) + buttonActivationCode.run(); }); currentAccountLevel.addListener((obs, oldVal, newVal)->button.setDisable(requiredLevel.compareTo(newVal)>0)); button.setDisable(requiredLevel.compareTo(currentAccountLevel.get())>0); + if(setActive) + buttonActivationCode.run(); buttonHolder.getChildren().add(button); }