mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2024-11-16 21:33:21 +00:00
Module Client : ajout de restrictions d'actions et de navigation en fonction du niveau de permission du compte actuellement connecté
This commit is contained in:
parent
2cbe949b03
commit
b46eeec815
@ -32,11 +32,12 @@ public class Main extends Application{
|
|||||||
StatService statService = new StatService();
|
StatService statService = new StatService();
|
||||||
|
|
||||||
MainFrame mainFrame = new MainFrame(accountService);
|
MainFrame mainFrame = new MainFrame(accountService);
|
||||||
mainFrame.addModule(new SaleScreen(accountService, stockService, saleService), true);
|
mainFrame.addModule(new SaleScreen(accountService, stockService, saleService));
|
||||||
mainFrame.addModule(new StockScreen(stockService));
|
mainFrame.addModule(new StockScreen(stockService, accountService));
|
||||||
mainFrame.addModule(new StatScreen(statService));
|
mainFrame.addModule(new StatScreen(statService));
|
||||||
mainFrame.addModule(new AccountScreen(accountService));
|
mainFrame.addModule(new AccountScreen(accountService));
|
||||||
|
|
||||||
|
|
||||||
Scene scene = new Scene(mainFrame.getPane(), 800, 600);
|
Scene scene = new Scene(mainFrame.getPane(), 800, 600);
|
||||||
scene.getStylesheets().clear();
|
scene.getStylesheets().clear();
|
||||||
scene.getStylesheets().addAll(getClass().getResource(GUICssTool.getCssFilePath()).toExternalForm());
|
scene.getStylesheets().addAll(getClass().getResource(GUICssTool.getCssFilePath()).toExternalForm());
|
||||||
|
@ -17,14 +17,11 @@ public class MainFrame implements IFXComponent {
|
|||||||
|
|
||||||
view = new MainFrameView(ctrl);
|
view = new MainFrameView(ctrl);
|
||||||
ctrl.setView(view);
|
ctrl.setView(view);
|
||||||
|
ctrl.updateView();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addModule(IGuiModule module){
|
public void addModule(IGuiModule module){
|
||||||
ctrl.addModule(module, false);
|
ctrl.addModule(module);
|
||||||
}
|
|
||||||
|
|
||||||
public void addModule(IGuiModule module, boolean setActive){
|
|
||||||
ctrl.addModule(module, setActive);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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.generics.validators.listeners.IValidatorComponentListener;
|
||||||
import com.pqt.client.gui.ressources.components.specifics.account.listeners.IAccountComponentListener;
|
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.Account;
|
||||||
|
import com.pqt.core.entities.user_account.AccountLevel;
|
||||||
import javafx.event.Event;
|
import javafx.event.Event;
|
||||||
|
|
||||||
class MainFrameController implements IMainFrameModelListener {
|
class MainFrameController implements IMainFrameModelListener {
|
||||||
@ -21,8 +22,17 @@ class MainFrameController implements IMainFrameModelListener {
|
|||||||
this.view = view;
|
this.view = view;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addModule(IGuiModule module, boolean setActive) {
|
void updateView(){
|
||||||
this.view.addGuiModule(module.getModuleName(),module.getPane(), setActive);
|
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() {
|
IValidatorComponentListener getAccountManagerValidatorListener() {
|
||||||
@ -71,11 +81,11 @@ class MainFrameController implements IMainFrameModelListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAccountStatusChangedEvent(boolean status) {
|
public void onAccountStatusChangedEvent(boolean status) {
|
||||||
view.setCurrentAccount(model.getCurrentAccount());
|
updateView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAccountCollectionChangedEvent() {
|
public void onAccountCollectionChangedEvent() {
|
||||||
view.feedAccountCollectionToManager(model.getAccounts());
|
updateView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.components.generics.others.listeners.ISideBarListener;
|
||||||
import com.pqt.client.gui.ressources.strings.GUIStringTool;
|
import com.pqt.client.gui.ressources.strings.GUIStringTool;
|
||||||
import com.pqt.core.entities.user_account.Account;
|
import com.pqt.core.entities.user_account.Account;
|
||||||
|
import com.pqt.core.entities.user_account.AccountLevel;
|
||||||
import javafx.application.Platform;
|
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.geometry.Orientation;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
@ -25,10 +29,11 @@ class MainFrameView implements IFXComponent{
|
|||||||
private BorderPane mainPane;
|
private BorderPane mainPane;
|
||||||
private AccountManager accountManager;
|
private AccountManager accountManager;
|
||||||
private VBox buttonHolder;
|
private VBox buttonHolder;
|
||||||
|
private ObjectProperty<AccountLevel> currentAccountLevel;
|
||||||
|
|
||||||
MainFrameView(MainFrameController ctrl) {
|
MainFrameView(MainFrameController ctrl) {
|
||||||
|
|
||||||
this.ctrl = ctrl;
|
this.ctrl = ctrl;
|
||||||
|
currentAccountLevel = new SimpleObjectProperty<>(AccountLevel.getLowest());
|
||||||
initGui();
|
initGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +87,7 @@ class MainFrameView implements IFXComponent{
|
|||||||
return mainPane;
|
return mainPane;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addGuiModule(String moduleName, Pane moduleContent, boolean setActive){
|
void addGuiModule(String moduleName, Pane moduleContent, AccountLevel requiredLevel){
|
||||||
Button button = new Button(moduleName);
|
Button button = new Button(moduleName);
|
||||||
button.getStyleClass().add("menu-button");
|
button.getStyleClass().add("menu-button");
|
||||||
button.setOnMouseClicked(event->{
|
button.setOnMouseClicked(event->{
|
||||||
@ -97,8 +102,8 @@ class MainFrameView implements IFXComponent{
|
|||||||
mainPane.setCenter(moduleContent);
|
mainPane.setCenter(moduleContent);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
if(setActive)
|
currentAccountLevel.addListener((obs, oldVal, newVal)->button.setDisable(requiredLevel.compareTo(newVal)>0));
|
||||||
button.getOnMouseClicked().handle(null);
|
button.setDisable(requiredLevel.compareTo(currentAccountLevel.get())>0);
|
||||||
buttonHolder.getChildren().add(button);
|
buttonHolder.getChildren().add(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,4 +122,8 @@ class MainFrameView implements IFXComponent{
|
|||||||
void feedAccountCollectionToManager(Collection<Account> accounts){
|
void feedAccountCollectionToManager(Collection<Account> accounts){
|
||||||
accountManager.display(accounts);
|
accountManager.display(accounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateModuleButtonLock(AccountLevel level) {
|
||||||
|
currentAccountLevel.setValue(level);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.pqt.client.gui.modules;
|
package com.pqt.client.gui.modules;
|
||||||
|
|
||||||
import com.pqt.client.gui.ressources.components.generics.IFXComponent;
|
import com.pqt.client.gui.ressources.components.generics.IFXComponent;
|
||||||
|
import com.pqt.core.entities.user_account.AccountLevel;
|
||||||
|
|
||||||
public interface IGuiModule extends IFXComponent{
|
public interface IGuiModule extends IFXComponent{
|
||||||
String getModuleName();
|
String getModuleName();
|
||||||
|
AccountLevel getLowestRequiredAccountLevel();
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.pqt.client.gui.modules.account_screen;
|
|||||||
import com.pqt.client.gui.modules.IGuiModule;
|
import com.pqt.client.gui.modules.IGuiModule;
|
||||||
import com.pqt.client.gui.ressources.strings.GUIStringTool;
|
import com.pqt.client.gui.ressources.strings.GUIStringTool;
|
||||||
import com.pqt.client.module.account.AccountService;
|
import com.pqt.client.module.account.AccountService;
|
||||||
|
import com.pqt.core.entities.user_account.AccountLevel;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
|
|
||||||
public class AccountScreen implements IGuiModule {
|
public class AccountScreen implements IGuiModule {
|
||||||
@ -23,6 +24,11 @@ public class AccountScreen implements IGuiModule {
|
|||||||
return GUIStringTool.getAccountGuiModuleName();
|
return GUIStringTool.getAccountGuiModuleName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AccountLevel getLowestRequiredAccountLevel() {
|
||||||
|
return AccountLevel.WAITER;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pane getPane() {
|
public Pane getPane() {
|
||||||
return view.getPane();
|
return view.getPane();
|
||||||
|
@ -28,9 +28,9 @@ class AccountScreenController {
|
|||||||
|
|
||||||
private void updateViewActionLock() {
|
private void updateViewActionLock() {
|
||||||
if (model.getCurrentAccount() != null) {
|
if (model.getCurrentAccount() != null) {
|
||||||
view.setAddAccountActionLocked(model.getCurrentAccount().getPermissionLevel().compareTo(AccountLevel.MASTER) >= 0);
|
view.setAddAccountActionLocked(AccountLevel.MASTER.compareTo(model.getCurrentAccount().getPermissionLevel()) > 0);
|
||||||
view.setDetailAccountActionLocked(view.isItemSelected() && model.getCurrentAccount().getPermissionLevel().compareTo(AccountLevel.MASTER) >= 0);
|
view.setDetailAccountActionLocked(!view.isItemSelected() || AccountLevel.MASTER.compareTo(model.getCurrentAccount().getPermissionLevel()) > 0);
|
||||||
view.setRemoveAccountActionLocked(view.isItemSelected() && model.getCurrentAccount().getPermissionLevel().compareTo(AccountLevel.MASTER) >= 0);
|
view.setRemoveAccountActionLocked(!view.isItemSelected() || AccountLevel.MASTER.compareTo(model.getCurrentAccount().getPermissionLevel()) > 0);
|
||||||
}else{
|
}else{
|
||||||
view.setAddAccountActionLocked(true);
|
view.setAddAccountActionLocked(true);
|
||||||
view.setDetailAccountActionLocked(true);
|
view.setDetailAccountActionLocked(true);
|
||||||
|
@ -59,7 +59,7 @@ class AccountManagerScreenView implements IFXComponent{
|
|||||||
if (event.getButton().equals(MouseButton.PRIMARY))
|
if (event.getButton().equals(MouseButton.PRIMARY))
|
||||||
ctrl.onValidationEvent();
|
ctrl.onValidationEvent();
|
||||||
});
|
});
|
||||||
Button cancelButton = new Button(GUIStringTool.getValidationButtonLabel());
|
Button cancelButton = new Button(GUIStringTool.getCancelButtonLabel());
|
||||||
cancelButton.setOnMouseClicked(event -> {
|
cancelButton.setOnMouseClicked(event -> {
|
||||||
if (event.getButton().equals(MouseButton.PRIMARY))
|
if (event.getButton().equals(MouseButton.PRIMARY))
|
||||||
ctrl.onCancelEvent();
|
ctrl.onCancelEvent();
|
||||||
|
@ -6,6 +6,7 @@ import com.pqt.client.gui.ressources.strings.GUIStringTool;
|
|||||||
import com.pqt.client.module.account.AccountService;
|
import com.pqt.client.module.account.AccountService;
|
||||||
import com.pqt.client.module.sale.SaleService;
|
import com.pqt.client.module.sale.SaleService;
|
||||||
import com.pqt.client.module.stock.StockService;
|
import com.pqt.client.module.stock.StockService;
|
||||||
|
import com.pqt.core.entities.user_account.AccountLevel;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
|
|
||||||
public class SaleScreen implements IGuiModule {
|
public class SaleScreen implements IGuiModule {
|
||||||
@ -30,4 +31,9 @@ public class SaleScreen implements IGuiModule {
|
|||||||
public String getModuleName() {
|
public String getModuleName() {
|
||||||
return GUIStringTool.getSaleGuiModuleName();
|
return GUIStringTool.getSaleGuiModuleName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AccountLevel getLowestRequiredAccountLevel() {
|
||||||
|
return AccountLevel.WAITER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ class SaleScreenController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaleNotValidatedEvent(SaleStatus status, Throwable cause) {
|
public void onSaleNotValidatedEvent(SaleStatus status, Throwable cause) {
|
||||||
SaleScreenController.this.onSaleValidationError(status, cause);
|
onSaleValidationError(status, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -38,10 +38,17 @@ class SaleScreenController {
|
|||||||
view.setProducts(model.getProductList());
|
view.setProducts(model.getProductList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAccountConnectedStateUpdatedEvent() {
|
||||||
|
updateActionLock();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAccountListUpdatedEvent() {
|
public void onAccountListUpdatedEvent() {
|
||||||
view.setAccounts(model.getAccountList());
|
view.setAccounts(model.getAccountList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +74,14 @@ class SaleScreenController {
|
|||||||
|
|
||||||
private void updateSale(){
|
private void updateSale(){
|
||||||
view.setSale(getCurrentSale());
|
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(){
|
private void updateData(){
|
||||||
|
@ -13,6 +13,7 @@ import com.pqt.core.entities.sale.Sale;
|
|||||||
import com.pqt.core.entities.sale.SaleStatus;
|
import com.pqt.core.entities.sale.SaleStatus;
|
||||||
import com.pqt.core.entities.sale.SaleType;
|
import com.pqt.core.entities.sale.SaleType;
|
||||||
import com.pqt.core.entities.user_account.Account;
|
import com.pqt.core.entities.user_account.Account;
|
||||||
|
import com.pqt.core.entities.user_account.AccountLevel;
|
||||||
|
|
||||||
import javax.swing.event.EventListenerList;
|
import javax.swing.event.EventListenerList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -100,7 +101,7 @@ class SaleScreenModel {
|
|||||||
accountService.addListener(new IAccountListener() {
|
accountService.addListener(new IAccountListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onAccountStatusChangedEvent(boolean status) {
|
public void onAccountStatusChangedEvent(boolean status) {
|
||||||
|
fireAccountConnectedStatusUpdateEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -132,6 +133,11 @@ class SaleScreenModel {
|
|||||||
.forEach(ISaleScreenModelListener::onAccountListUpdatedEvent);
|
.forEach(ISaleScreenModelListener::onAccountListUpdatedEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fireAccountConnectedStatusUpdateEvent() {
|
||||||
|
Arrays.stream(listeners.getListeners(ISaleScreenModelListener.class))
|
||||||
|
.forEach(ISaleScreenModelListener::onAccountConnectedStateUpdatedEvent);
|
||||||
|
}
|
||||||
|
|
||||||
List<Account> getAccountList() {
|
List<Account> getAccountList() {
|
||||||
return accountService.getAllAccounts();
|
return accountService.getAllAccounts();
|
||||||
}
|
}
|
||||||
@ -205,4 +211,15 @@ class SaleScreenModel {
|
|||||||
void removeListener(ISaleScreenModelListener listener){
|
void removeListener(ISaleScreenModelListener listener){
|
||||||
listeners.remove(ISaleScreenModelListener.class, 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();
|
||||||
|
}
|
||||||
}
|
}
|
@ -8,5 +8,6 @@ public interface ISaleScreenModelListener extends EventListener {
|
|||||||
void onSaleValidatedEvent();
|
void onSaleValidatedEvent();
|
||||||
void onSaleNotValidatedEvent(SaleStatus status, Throwable cause);
|
void onSaleNotValidatedEvent(SaleStatus status, Throwable cause);
|
||||||
void onStockUpdatedEvent();
|
void onStockUpdatedEvent();
|
||||||
|
void onAccountConnectedStateUpdatedEvent();
|
||||||
void onAccountListUpdatedEvent();
|
void onAccountListUpdatedEvent();
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.pqt.client.gui.modules.stat_screen;
|
|||||||
import com.pqt.client.gui.modules.IGuiModule;
|
import com.pqt.client.gui.modules.IGuiModule;
|
||||||
import com.pqt.client.gui.ressources.strings.GUIStringTool;
|
import com.pqt.client.gui.ressources.strings.GUIStringTool;
|
||||||
import com.pqt.client.module.stat.StatService;
|
import com.pqt.client.module.stat.StatService;
|
||||||
|
import com.pqt.core.entities.user_account.AccountLevel;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
|
|
||||||
public class StatScreen implements IGuiModule {
|
public class StatScreen implements IGuiModule {
|
||||||
@ -22,6 +23,11 @@ public class StatScreen implements IGuiModule {
|
|||||||
return GUIStringTool.getStatGuiModuleName();
|
return GUIStringTool.getStatGuiModuleName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AccountLevel getLowestRequiredAccountLevel() {
|
||||||
|
return AccountLevel.STAFF;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pane getPane() {
|
public Pane getPane() {
|
||||||
return view.getPane();
|
return view.getPane();
|
||||||
|
@ -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.IGuiModule;
|
||||||
import com.pqt.client.gui.modules.stock_screen.product_manager_screen.ProductManagerScreen;
|
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.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.client.module.stock.StockService;
|
||||||
|
import com.pqt.core.entities.user_account.AccountLevel;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
|
|
||||||
public class StockScreen implements IGuiModule {
|
public class StockScreen implements IGuiModule {
|
||||||
|
|
||||||
private StockScreenView view;
|
private StockScreenView view;
|
||||||
|
|
||||||
public StockScreen(StockService stockService) {
|
public StockScreen(StockService stockService, AccountService accountService) {
|
||||||
StockScreenModel model = new StockScreenModel(stockService);
|
StockScreenModel model = new StockScreenModel(stockService, accountService);
|
||||||
StockScreenController ctrl = new StockScreenController(model);
|
StockScreenController ctrl = new StockScreenController(model);
|
||||||
view = new StockScreenView(ctrl, new ProductManagerScreenFactory(stockService));
|
view = new StockScreenView(ctrl, new ProductManagerScreenFactory(stockService));
|
||||||
|
|
||||||
|
model.addListener(ctrl);
|
||||||
ctrl.setView(view);
|
ctrl.setView(view);
|
||||||
ctrl.refreshView();
|
ctrl.refreshView();
|
||||||
}
|
}
|
||||||
@ -24,6 +27,11 @@ public class StockScreen implements IGuiModule {
|
|||||||
return "Stock";
|
return "Stock";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AccountLevel getLowestRequiredAccountLevel() {
|
||||||
|
return AccountLevel.WAITER;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pane getPane() {
|
public Pane getPane() {
|
||||||
return view.getPane();
|
return view.getPane();
|
||||||
|
@ -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.components.generics.validators.listeners.IValidatorComponentListener;
|
||||||
import com.pqt.client.gui.ressources.strings.GUIStringTool;
|
import com.pqt.client.gui.ressources.strings.GUIStringTool;
|
||||||
import com.pqt.core.entities.product.Product;
|
import com.pqt.core.entities.product.Product;
|
||||||
|
import com.pqt.core.entities.user_account.AccountLevel;
|
||||||
|
|
||||||
class StockScreenController implements IStockScreenModelListener{
|
class StockScreenController implements IStockScreenModelListener{
|
||||||
|
|
||||||
@ -87,4 +88,25 @@ class StockScreenController implements IStockScreenModelListener{
|
|||||||
public void onStockUpdatedEvent() {
|
public void onStockUpdatedEvent() {
|
||||||
refreshView();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package com.pqt.client.gui.modules.stock_screen;
|
package com.pqt.client.gui.modules.stock_screen;
|
||||||
|
|
||||||
import com.pqt.client.gui.modules.stock_screen.listeners.IStockScreenModelListener;
|
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.Listeners.StockListenerAdapter;
|
||||||
import com.pqt.client.module.stock.StockService;
|
import com.pqt.client.module.stock.StockService;
|
||||||
import com.pqt.core.entities.product.Product;
|
import com.pqt.core.entities.product.Product;
|
||||||
|
import com.pqt.core.entities.user_account.AccountLevel;
|
||||||
|
|
||||||
import javax.swing.event.EventListenerList;
|
import javax.swing.event.EventListenerList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -12,9 +15,10 @@ import java.util.Collection;
|
|||||||
class StockScreenModel {
|
class StockScreenModel {
|
||||||
|
|
||||||
private StockService stockService;
|
private StockService stockService;
|
||||||
|
private AccountService accountService;
|
||||||
private EventListenerList listenerList;
|
private EventListenerList listenerList;
|
||||||
|
|
||||||
StockScreenModel(StockService stockService) {
|
StockScreenModel(StockService stockService, AccountService accountService) {
|
||||||
listenerList = new EventListenerList();
|
listenerList = new EventListenerList();
|
||||||
this.stockService = stockService;
|
this.stockService = stockService;
|
||||||
this.stockService.addListener(new StockListenerAdapter(){
|
this.stockService.addListener(new StockListenerAdapter(){
|
||||||
@ -23,6 +27,23 @@ class StockScreenModel {
|
|||||||
StockScreenModel.this.fireProductCollectionChanged();
|
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() {
|
private void fireProductCollectionChanged() {
|
||||||
@ -53,4 +74,15 @@ class StockScreenModel {
|
|||||||
void removeListener(IStockScreenModelListener l){
|
void removeListener(IStockScreenModelListener l){
|
||||||
listenerList.remove(IStockScreenModelListener.class, 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,9 @@ class StockScreenView implements IFXComponent {
|
|||||||
private TableView<Product> stockTableView;
|
private TableView<Product> stockTableView;
|
||||||
private ProductManagerScreenFactory productManagerScreenFactory;
|
private ProductManagerScreenFactory productManagerScreenFactory;
|
||||||
private ProductManagerScreen currentDetailScreen;
|
private ProductManagerScreen currentDetailScreen;
|
||||||
|
private Button addProductButton;
|
||||||
|
private Button detailProductButton;
|
||||||
|
private Button removeProductButton;
|
||||||
|
|
||||||
StockScreenView(StockScreenController ctrl, ProductManagerScreenFactory productManagerScreenFactory) {
|
StockScreenView(StockScreenController ctrl, ProductManagerScreenFactory productManagerScreenFactory) {
|
||||||
this.ctrl = ctrl;
|
this.ctrl = ctrl;
|
||||||
@ -49,12 +52,12 @@ class StockScreenView implements IFXComponent {
|
|||||||
mainPaneContent.prefWidthProperty().bind(mainPane.widthProperty());
|
mainPaneContent.prefWidthProperty().bind(mainPane.widthProperty());
|
||||||
mainPaneContent.prefHeightProperty().bind(mainPane.heightProperty());
|
mainPaneContent.prefHeightProperty().bind(mainPane.heightProperty());
|
||||||
|
|
||||||
Button addProductButton = new Button(GUIStringTool.getAddButtonLabel());
|
addProductButton = new Button(GUIStringTool.getAddButtonLabel());
|
||||||
addProductButton.setOnMouseClicked(event -> ctrl.onAddProductRequest());
|
addProductButton.setOnMouseClicked(event -> ctrl.onAddProductRequest());
|
||||||
Button detailProductButton = new Button(GUIStringTool.getDetailButtonLabel());
|
detailProductButton = new Button(GUIStringTool.getDetailButtonLabel());
|
||||||
detailProductButton.setOnMouseClicked(event -> ctrl.onDetailProductRequest());
|
detailProductButton.setOnMouseClicked(event -> ctrl.onDetailProductRequest());
|
||||||
detailProductButton.setDisable(true);
|
detailProductButton.setDisable(true);
|
||||||
Button removeProductButton = new Button(GUIStringTool.getRemoveButtonLabel());
|
removeProductButton = new Button(GUIStringTool.getRemoveButtonLabel());
|
||||||
removeProductButton.setDisable(true);
|
removeProductButton.setDisable(true);
|
||||||
removeProductButton.setOnMouseClicked(event -> ctrl.onDeleteProductRequest());
|
removeProductButton.setOnMouseClicked(event -> ctrl.onDeleteProductRequest());
|
||||||
Button refreshProductButton = new Button(GUIStringTool.getRefreshButtonLabel());
|
Button refreshProductButton = new Button(GUIStringTool.getRefreshButtonLabel());
|
||||||
@ -98,10 +101,7 @@ class StockScreenView implements IFXComponent {
|
|||||||
return row;
|
return row;
|
||||||
});
|
});
|
||||||
stockTableView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
|
stockTableView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
|
||||||
stockTableView.getSelectionModel().selectedItemProperty().addListener((obs, oldVal, newVal)->{
|
stockTableView.getSelectionModel().selectedItemProperty().addListener((obs, oldVal, newVal)->ctrl.onProductSelectedChange());
|
||||||
detailProductButton.setDisable(newVal==null);
|
|
||||||
removeProductButton.setDisable(newVal==null);
|
|
||||||
});
|
|
||||||
List<TableColumn<Product, ?>> columns = new ArrayList<>();
|
List<TableColumn<Product, ?>> columns = new ArrayList<>();
|
||||||
|
|
||||||
columns.add(createNewTableColumn(String.class,
|
columns.add(createNewTableColumn(String.class,
|
||||||
@ -227,4 +227,16 @@ class StockScreenView implements IFXComponent {
|
|||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setAddProductActionLocked(boolean locked){
|
||||||
|
addProductButton.setDisable(locked);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setRemoveProductActionLocked(boolean locked){
|
||||||
|
removeProductButton.setDisable(locked);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setEditProductActionLocked(boolean locked){
|
||||||
|
detailProductButton.setDisable(locked);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,4 +4,5 @@ import java.util.EventListener;
|
|||||||
|
|
||||||
public interface IStockScreenModelListener extends EventListener {
|
public interface IStockScreenModelListener extends EventListener {
|
||||||
void onStockUpdatedEvent();
|
void onStockUpdatedEvent();
|
||||||
|
void onAcccountConnectedStatusUpdatedEvent();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user