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); }