Module Client, packg main_frame : il est de nouveau possible de demander à ce que un module donné soit actif lors de son ajout à la main frame

This commit is contained in:
Notmoo 2017-08-19 21:20:59 +02:00
parent b46eeec815
commit 827451d665
4 changed files with 26 additions and 6 deletions

View File

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

View File

@ -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

View File

@ -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() {

View File

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