From b46eeec815620de3542fb4f38bc6143774e9b785 Mon Sep 17 00:00:00 2001 From: Notmoo Date: Sat, 19 Aug 2017 20:55:38 +0200 Subject: [PATCH] =?UTF-8?q?Module=20Client=20:=20ajout=20de=20restrictions?= =?UTF-8?q?=20d'actions=20et=20de=20navigation=20en=20fonction=20du=20nive?= =?UTF-8?q?au=20de=20permission=20du=20compte=20actuellement=20connect?= =?UTF-8?q?=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/pqt/client/Main.java | 5 +-- .../pqt/client/gui/main_frame/MainFrame.java | 7 ++-- .../gui/main_frame/MainFrameController.java | 18 +++++++--- .../client/gui/main_frame/MainFrameView.java | 17 +++++++--- .../pqt/client/gui/modules/IGuiModule.java | 2 ++ .../modules/account_screen/AccountScreen.java | 6 ++++ .../AccountScreenController.java | 6 ++-- .../AccountManagerScreenView.java | 2 +- .../gui/modules/sale_screen/SaleScreen.java | 6 ++++ .../sale_screen/SaleScreenController.java | 18 ++++++++-- .../modules/sale_screen/SaleScreenModel.java | 19 ++++++++++- .../listeners/ISaleScreenModelListener.java | 1 + .../gui/modules/stat_screen/StatScreen.java | 6 ++++ .../gui/modules/stock_screen/StockScreen.java | 12 +++++-- .../stock_screen/StockScreenController.java | 22 ++++++++++++ .../stock_screen/StockScreenModel.java | 34 ++++++++++++++++++- .../modules/stock_screen/StockScreenView.java | 26 ++++++++++---- .../listeners/IStockScreenModelListener.java | 1 + 18 files changed, 176 insertions(+), 32 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 c09ccd86..4780949d 100644 --- a/Workspace/client/src/main/java/com/pqt/client/Main.java +++ b/Workspace/client/src/main/java/com/pqt/client/Main.java @@ -32,11 +32,12 @@ public class Main extends Application{ StatService statService = new StatService(); MainFrame mainFrame = new MainFrame(accountService); - mainFrame.addModule(new SaleScreen(accountService, stockService, saleService), true); - mainFrame.addModule(new StockScreen(stockService)); + mainFrame.addModule(new SaleScreen(accountService, stockService, saleService)); + mainFrame.addModule(new StockScreen(stockService, accountService)); mainFrame.addModule(new StatScreen(statService)); mainFrame.addModule(new AccountScreen(accountService)); + Scene scene = new Scene(mainFrame.getPane(), 800, 600); scene.getStylesheets().clear(); scene.getStylesheets().addAll(getClass().getResource(GUICssTool.getCssFilePath()).toExternalForm()); 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 bc1674a6..73d9c53f 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 @@ -17,14 +17,11 @@ public class MainFrame implements IFXComponent { view = new MainFrameView(ctrl); ctrl.setView(view); + ctrl.updateView(); } public void addModule(IGuiModule module){ - ctrl.addModule(module, false); - } - - public void addModule(IGuiModule module, boolean setActive){ - ctrl.addModule(module, setActive); + ctrl.addModule(module); } @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 43686466..be3d474d 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 @@ -5,6 +5,7 @@ import com.pqt.client.gui.modules.IGuiModule; import com.pqt.client.gui.ressources.components.generics.validators.listeners.IValidatorComponentListener; import com.pqt.client.gui.ressources.components.specifics.account.listeners.IAccountComponentListener; import com.pqt.core.entities.user_account.Account; +import com.pqt.core.entities.user_account.AccountLevel; import javafx.event.Event; class MainFrameController implements IMainFrameModelListener { @@ -21,8 +22,17 @@ class MainFrameController implements IMainFrameModelListener { this.view = view; } - void addModule(IGuiModule module, boolean setActive) { - this.view.addGuiModule(module.getModuleName(),module.getPane(), setActive); + void updateView(){ + view.feedAccountCollectionToManager(model.getAccounts()); + view.setCurrentAccount(model.getCurrentAccount()); + if(model.getCurrentAccount()!=null) + view.updateModuleButtonLock(model.getCurrentAccount().getPermissionLevel()); + else + view.updateModuleButtonLock(AccountLevel.getLowest()); + } + + void addModule(IGuiModule module) { + this.view.addGuiModule(module.getModuleName(),module.getPane(), module.getLowestRequiredAccountLevel()); } IValidatorComponentListener getAccountManagerValidatorListener() { @@ -71,11 +81,11 @@ class MainFrameController implements IMainFrameModelListener { @Override public void onAccountStatusChangedEvent(boolean status) { - view.setCurrentAccount(model.getCurrentAccount()); + updateView(); } @Override public void onAccountCollectionChangedEvent() { - view.feedAccountCollectionToManager(model.getAccounts()); + updateView(); } } 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 5793fa3d..d76d2674 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 @@ -6,7 +6,11 @@ import com.pqt.client.gui.ressources.components.generics.others.SideBar; import com.pqt.client.gui.ressources.components.generics.others.listeners.ISideBarListener; import com.pqt.client.gui.ressources.strings.GUIStringTool; import com.pqt.core.entities.user_account.Account; +import com.pqt.core.entities.user_account.AccountLevel; import javafx.application.Platform; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.value.ObservableValue; import javafx.geometry.Orientation; import javafx.scene.Node; import javafx.scene.control.Button; @@ -25,10 +29,11 @@ class MainFrameView implements IFXComponent{ private BorderPane mainPane; private AccountManager accountManager; private VBox buttonHolder; + private ObjectProperty currentAccountLevel; MainFrameView(MainFrameController ctrl) { - this.ctrl = ctrl; + currentAccountLevel = new SimpleObjectProperty<>(AccountLevel.getLowest()); initGui(); } @@ -82,7 +87,7 @@ class MainFrameView implements IFXComponent{ return mainPane; } - void addGuiModule(String moduleName, Pane moduleContent, boolean setActive){ + void addGuiModule(String moduleName, Pane moduleContent, AccountLevel requiredLevel){ Button button = new Button(moduleName); button.getStyleClass().add("menu-button"); button.setOnMouseClicked(event->{ @@ -97,8 +102,8 @@ class MainFrameView implements IFXComponent{ mainPane.setCenter(moduleContent); }); }); - if(setActive) - button.getOnMouseClicked().handle(null); + currentAccountLevel.addListener((obs, oldVal, newVal)->button.setDisable(requiredLevel.compareTo(newVal)>0)); + button.setDisable(requiredLevel.compareTo(currentAccountLevel.get())>0); buttonHolder.getChildren().add(button); } @@ -117,4 +122,8 @@ class MainFrameView implements IFXComponent{ void feedAccountCollectionToManager(Collection accounts){ accountManager.display(accounts); } + + void updateModuleButtonLock(AccountLevel level) { + currentAccountLevel.setValue(level); + } } diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/IGuiModule.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/IGuiModule.java index a6a06023..e4dfa3d2 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/modules/IGuiModule.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/IGuiModule.java @@ -1,7 +1,9 @@ package com.pqt.client.gui.modules; import com.pqt.client.gui.ressources.components.generics.IFXComponent; +import com.pqt.core.entities.user_account.AccountLevel; public interface IGuiModule extends IFXComponent{ String getModuleName(); + AccountLevel getLowestRequiredAccountLevel(); } diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreen.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreen.java index 2c5f4ea8..ceee3d9e 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreen.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreen.java @@ -3,6 +3,7 @@ package com.pqt.client.gui.modules.account_screen; import com.pqt.client.gui.modules.IGuiModule; import com.pqt.client.gui.ressources.strings.GUIStringTool; import com.pqt.client.module.account.AccountService; +import com.pqt.core.entities.user_account.AccountLevel; import javafx.scene.layout.Pane; public class AccountScreen implements IGuiModule { @@ -23,6 +24,11 @@ public class AccountScreen implements IGuiModule { return GUIStringTool.getAccountGuiModuleName(); } + @Override + public AccountLevel getLowestRequiredAccountLevel() { + return AccountLevel.WAITER; + } + @Override public Pane getPane() { return view.getPane(); diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenController.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenController.java index f27509ce..4cb8f15f 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenController.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenController.java @@ -28,9 +28,9 @@ class AccountScreenController { private void updateViewActionLock() { if (model.getCurrentAccount() != null) { - view.setAddAccountActionLocked(model.getCurrentAccount().getPermissionLevel().compareTo(AccountLevel.MASTER) >= 0); - view.setDetailAccountActionLocked(view.isItemSelected() && model.getCurrentAccount().getPermissionLevel().compareTo(AccountLevel.MASTER) >= 0); - view.setRemoveAccountActionLocked(view.isItemSelected() && model.getCurrentAccount().getPermissionLevel().compareTo(AccountLevel.MASTER) >= 0); + view.setAddAccountActionLocked(AccountLevel.MASTER.compareTo(model.getCurrentAccount().getPermissionLevel()) > 0); + view.setDetailAccountActionLocked(!view.isItemSelected() || AccountLevel.MASTER.compareTo(model.getCurrentAccount().getPermissionLevel()) > 0); + view.setRemoveAccountActionLocked(!view.isItemSelected() || AccountLevel.MASTER.compareTo(model.getCurrentAccount().getPermissionLevel()) > 0); }else{ view.setAddAccountActionLocked(true); view.setDetailAccountActionLocked(true); diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreenView.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreenView.java index 722e54ef..94b85c53 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreenView.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreenView.java @@ -59,7 +59,7 @@ class AccountManagerScreenView implements IFXComponent{ if (event.getButton().equals(MouseButton.PRIMARY)) ctrl.onValidationEvent(); }); - Button cancelButton = new Button(GUIStringTool.getValidationButtonLabel()); + Button cancelButton = new Button(GUIStringTool.getCancelButtonLabel()); cancelButton.setOnMouseClicked(event -> { if (event.getButton().equals(MouseButton.PRIMARY)) ctrl.onCancelEvent(); diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/sale_screen/SaleScreen.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/sale_screen/SaleScreen.java index d9007117..c1e72268 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/modules/sale_screen/SaleScreen.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/sale_screen/SaleScreen.java @@ -6,6 +6,7 @@ import com.pqt.client.gui.ressources.strings.GUIStringTool; import com.pqt.client.module.account.AccountService; import com.pqt.client.module.sale.SaleService; import com.pqt.client.module.stock.StockService; +import com.pqt.core.entities.user_account.AccountLevel; import javafx.scene.layout.Pane; public class SaleScreen implements IGuiModule { @@ -30,4 +31,9 @@ public class SaleScreen implements IGuiModule { public String getModuleName() { return GUIStringTool.getSaleGuiModuleName(); } + + @Override + public AccountLevel getLowestRequiredAccountLevel() { + return AccountLevel.WAITER; + } } diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/sale_screen/SaleScreenController.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/sale_screen/SaleScreenController.java index b3abd1e8..6640d324 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/modules/sale_screen/SaleScreenController.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/sale_screen/SaleScreenController.java @@ -30,7 +30,7 @@ class SaleScreenController { @Override public void onSaleNotValidatedEvent(SaleStatus status, Throwable cause) { - SaleScreenController.this.onSaleValidationError(status, cause); + onSaleValidationError(status, cause); } @Override @@ -38,10 +38,17 @@ class SaleScreenController { view.setProducts(model.getProductList()); } + @Override + public void onAccountConnectedStateUpdatedEvent() { + updateActionLock(); + } + @Override public void onAccountListUpdatedEvent() { view.setAccounts(model.getAccountList()); } + + }); } @@ -67,7 +74,14 @@ class SaleScreenController { private void updateSale(){ view.setSale(getCurrentSale()); - view.setValidationButtonEnabled(model.checkValidity(getCurrentSale())); + updateActionLock(); + } + + private void updateActionLock() { + boolean validationButtonEnabled = model.checkValidity(getCurrentSale()) + && model.isCurrentAccountConnected() + && model.getCurrentAccountLevel().compareTo(AccountLevel.WAITER)>=0; + view.setValidationButtonEnabled(validationButtonEnabled); } private void updateData(){ diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/sale_screen/SaleScreenModel.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/sale_screen/SaleScreenModel.java index 94d59bf2..4cfc6d54 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/modules/sale_screen/SaleScreenModel.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/sale_screen/SaleScreenModel.java @@ -13,6 +13,7 @@ import com.pqt.core.entities.sale.Sale; import com.pqt.core.entities.sale.SaleStatus; import com.pqt.core.entities.sale.SaleType; import com.pqt.core.entities.user_account.Account; +import com.pqt.core.entities.user_account.AccountLevel; import javax.swing.event.EventListenerList; import java.util.Arrays; @@ -100,7 +101,7 @@ class SaleScreenModel { accountService.addListener(new IAccountListener() { @Override public void onAccountStatusChangedEvent(boolean status) { - + fireAccountConnectedStatusUpdateEvent(); } @Override @@ -132,6 +133,11 @@ class SaleScreenModel { .forEach(ISaleScreenModelListener::onAccountListUpdatedEvent); } + private void fireAccountConnectedStatusUpdateEvent() { + Arrays.stream(listeners.getListeners(ISaleScreenModelListener.class)) + .forEach(ISaleScreenModelListener::onAccountConnectedStateUpdatedEvent); + } + List getAccountList() { return accountService.getAllAccounts(); } @@ -205,4 +211,15 @@ class SaleScreenModel { void removeListener(ISaleScreenModelListener listener){ listeners.remove(ISaleScreenModelListener.class, listener); } + + boolean isCurrentAccountConnected() { + return accountService.isCurrentAccountLoggedIn(); + } + + AccountLevel getCurrentAccountLevel() { + if(accountService.getCurrentAccount()!=null) + return accountService.getCurrentAccount().getPermissionLevel(); + else + return AccountLevel.getLowest(); + } } \ No newline at end of file diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/sale_screen/listeners/ISaleScreenModelListener.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/sale_screen/listeners/ISaleScreenModelListener.java index bfec4762..02996c3e 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/modules/sale_screen/listeners/ISaleScreenModelListener.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/sale_screen/listeners/ISaleScreenModelListener.java @@ -8,5 +8,6 @@ public interface ISaleScreenModelListener extends EventListener { void onSaleValidatedEvent(); void onSaleNotValidatedEvent(SaleStatus status, Throwable cause); void onStockUpdatedEvent(); + void onAccountConnectedStateUpdatedEvent(); void onAccountListUpdatedEvent(); } diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreen.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreen.java index 3634cc8b..6ef1f98b 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreen.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreen.java @@ -3,6 +3,7 @@ package com.pqt.client.gui.modules.stat_screen; import com.pqt.client.gui.modules.IGuiModule; import com.pqt.client.gui.ressources.strings.GUIStringTool; import com.pqt.client.module.stat.StatService; +import com.pqt.core.entities.user_account.AccountLevel; import javafx.scene.layout.Pane; public class StatScreen implements IGuiModule { @@ -22,6 +23,11 @@ public class StatScreen implements IGuiModule { return GUIStringTool.getStatGuiModuleName(); } + @Override + public AccountLevel getLowestRequiredAccountLevel() { + return AccountLevel.STAFF; + } + @Override public Pane getPane() { return view.getPane(); diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/StockScreen.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/StockScreen.java index 64f4e145..4deb2d97 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/StockScreen.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/StockScreen.java @@ -3,18 +3,21 @@ package com.pqt.client.gui.modules.stock_screen; import com.pqt.client.gui.modules.IGuiModule; import com.pqt.client.gui.modules.stock_screen.product_manager_screen.ProductManagerScreen; import com.pqt.client.gui.modules.stock_screen.product_manager_screen.ProductManagerScreenFactory; +import com.pqt.client.module.account.AccountService; import com.pqt.client.module.stock.StockService; +import com.pqt.core.entities.user_account.AccountLevel; import javafx.scene.layout.Pane; public class StockScreen implements IGuiModule { private StockScreenView view; - public StockScreen(StockService stockService) { - StockScreenModel model = new StockScreenModel(stockService); + public StockScreen(StockService stockService, AccountService accountService) { + StockScreenModel model = new StockScreenModel(stockService, accountService); StockScreenController ctrl = new StockScreenController(model); view = new StockScreenView(ctrl, new ProductManagerScreenFactory(stockService)); + model.addListener(ctrl); ctrl.setView(view); ctrl.refreshView(); } @@ -24,6 +27,11 @@ public class StockScreen implements IGuiModule { return "Stock"; } + @Override + public AccountLevel getLowestRequiredAccountLevel() { + return AccountLevel.WAITER; + } + @Override public Pane getPane() { return view.getPane(); diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/StockScreenController.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/StockScreenController.java index 2d85f01d..7418e94f 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/StockScreenController.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/StockScreenController.java @@ -7,6 +7,7 @@ import com.pqt.client.gui.modules.stock_screen.product_manager_screen.ProductMan import com.pqt.client.gui.ressources.components.generics.validators.listeners.IValidatorComponentListener; import com.pqt.client.gui.ressources.strings.GUIStringTool; import com.pqt.core.entities.product.Product; +import com.pqt.core.entities.user_account.AccountLevel; class StockScreenController implements IStockScreenModelListener{ @@ -87,4 +88,25 @@ class StockScreenController implements IStockScreenModelListener{ public void onStockUpdatedEvent() { refreshView(); } + + @Override + public void onAcccountConnectedStatusUpdatedEvent() { + updateViewActionLock(); + } + + void updateViewActionLock(){ + if(model.isAccountConnected() && model.getConnectedAccountLevel().compareTo(AccountLevel.MASTER)>=0){ + view.setAddProductActionLocked(false); + view.setEditProductActionLocked(view.getSelectedProduct()==null); + view.setRemoveProductActionLocked(view.getSelectedProduct()==null); + }else{ + view.setAddProductActionLocked(true); + view.setEditProductActionLocked(true); + view.setRemoveProductActionLocked(true); + } + } + + void onProductSelectedChange(){ + updateViewActionLock(); + } } diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/StockScreenModel.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/StockScreenModel.java index cc5a39b1..365c0648 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/StockScreenModel.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/StockScreenModel.java @@ -1,9 +1,12 @@ package com.pqt.client.gui.modules.stock_screen; import com.pqt.client.gui.modules.stock_screen.listeners.IStockScreenModelListener; +import com.pqt.client.module.account.AccountService; +import com.pqt.client.module.account.listeners.IAccountListener; import com.pqt.client.module.stock.Listeners.StockListenerAdapter; import com.pqt.client.module.stock.StockService; import com.pqt.core.entities.product.Product; +import com.pqt.core.entities.user_account.AccountLevel; import javax.swing.event.EventListenerList; import java.util.Arrays; @@ -12,9 +15,10 @@ import java.util.Collection; class StockScreenModel { private StockService stockService; + private AccountService accountService; private EventListenerList listenerList; - StockScreenModel(StockService stockService) { + StockScreenModel(StockService stockService, AccountService accountService) { listenerList = new EventListenerList(); this.stockService = stockService; this.stockService.addListener(new StockListenerAdapter(){ @@ -23,6 +27,23 @@ class StockScreenModel { StockScreenModel.this.fireProductCollectionChanged(); } }); + this.accountService = accountService; + this.accountService.addListener(new IAccountListener() { + @Override + public void onAccountStatusChangedEvent(boolean status) { + StockScreenModel.this.fireConnectedStatusChanged(); + } + + @Override + public void onAccountListChangedEvent() { + + } + }); + } + + private void fireConnectedStatusChanged() { + Arrays.stream(listenerList.getListeners(IStockScreenModelListener.class)) + .forEach(IStockScreenModelListener::onAcccountConnectedStatusUpdatedEvent); } private void fireProductCollectionChanged() { @@ -53,4 +74,15 @@ class StockScreenModel { void removeListener(IStockScreenModelListener l){ listenerList.remove(IStockScreenModelListener.class, l); } + + boolean isAccountConnected() { + return accountService.isCurrentAccountLoggedIn(); + } + + AccountLevel getConnectedAccountLevel() { + if(accountService.getCurrentAccount()!=null) + return accountService.getCurrentAccount().getPermissionLevel(); + else + return AccountLevel.getLowest(); + } } diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/StockScreenView.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/StockScreenView.java index 5b2b3e26..83034d8d 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/StockScreenView.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/StockScreenView.java @@ -34,6 +34,9 @@ class StockScreenView implements IFXComponent { private TableView stockTableView; private ProductManagerScreenFactory productManagerScreenFactory; private ProductManagerScreen currentDetailScreen; + private Button addProductButton; + private Button detailProductButton; + private Button removeProductButton; StockScreenView(StockScreenController ctrl, ProductManagerScreenFactory productManagerScreenFactory) { this.ctrl = ctrl; @@ -49,12 +52,12 @@ class StockScreenView implements IFXComponent { mainPaneContent.prefWidthProperty().bind(mainPane.widthProperty()); mainPaneContent.prefHeightProperty().bind(mainPane.heightProperty()); - Button addProductButton = new Button(GUIStringTool.getAddButtonLabel()); + addProductButton = new Button(GUIStringTool.getAddButtonLabel()); addProductButton.setOnMouseClicked(event -> ctrl.onAddProductRequest()); - Button detailProductButton = new Button(GUIStringTool.getDetailButtonLabel()); + detailProductButton = new Button(GUIStringTool.getDetailButtonLabel()); detailProductButton.setOnMouseClicked(event -> ctrl.onDetailProductRequest()); detailProductButton.setDisable(true); - Button removeProductButton = new Button(GUIStringTool.getRemoveButtonLabel()); + removeProductButton = new Button(GUIStringTool.getRemoveButtonLabel()); removeProductButton.setDisable(true); removeProductButton.setOnMouseClicked(event -> ctrl.onDeleteProductRequest()); Button refreshProductButton = new Button(GUIStringTool.getRefreshButtonLabel()); @@ -98,10 +101,7 @@ class StockScreenView implements IFXComponent { return row; }); stockTableView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); - stockTableView.getSelectionModel().selectedItemProperty().addListener((obs, oldVal, newVal)->{ - detailProductButton.setDisable(newVal==null); - removeProductButton.setDisable(newVal==null); - }); + stockTableView.getSelectionModel().selectedItemProperty().addListener((obs, oldVal, newVal)->ctrl.onProductSelectedChange()); List> columns = new ArrayList<>(); columns.add(createNewTableColumn(String.class, @@ -227,4 +227,16 @@ class StockScreenView implements IFXComponent { else return null; } + + void setAddProductActionLocked(boolean locked){ + addProductButton.setDisable(locked); + } + + void setRemoveProductActionLocked(boolean locked){ + removeProductButton.setDisable(locked); + } + + void setEditProductActionLocked(boolean locked){ + detailProductButton.setDisable(locked); + } } diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/listeners/IStockScreenModelListener.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/listeners/IStockScreenModelListener.java index b4035570..54604eec 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/listeners/IStockScreenModelListener.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stock_screen/listeners/IStockScreenModelListener.java @@ -4,4 +4,5 @@ import java.util.EventListener; public interface IStockScreenModelListener extends EventListener { void onStockUpdatedEvent(); + void onAcccountConnectedStatusUpdatedEvent(); }