mirror of
				https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
				synced 2025-10-31 00:53:10 +00:00 
			
		
		
		
	Module Client : ajout écran de gestion des comptes utilisateurs
This commit is contained in:
		| @@ -1,6 +1,7 @@ | |||||||
| package com.pqt.client; | package com.pqt.client; | ||||||
|  |  | ||||||
| import com.pqt.client.gui.main_frame.MainFrame; | import com.pqt.client.gui.main_frame.MainFrame; | ||||||
|  | import com.pqt.client.gui.modules.account_screen.AccountScreen; | ||||||
| import com.pqt.client.gui.modules.sale_screen.SaleScreen; | import com.pqt.client.gui.modules.sale_screen.SaleScreen; | ||||||
| import com.pqt.client.gui.modules.stat_screen.StatScreen; | import com.pqt.client.gui.modules.stat_screen.StatScreen; | ||||||
| import com.pqt.client.gui.modules.stock_screen.StockScreen; | import com.pqt.client.gui.modules.stock_screen.StockScreen; | ||||||
| @@ -34,7 +35,7 @@ public class Main extends Application{ | |||||||
|         mainFrame.addModule(new SaleScreen(accountService, stockService, saleService), true); |         mainFrame.addModule(new SaleScreen(accountService, stockService, saleService), true); | ||||||
|         mainFrame.addModule(new StockScreen(stockService)); |         mainFrame.addModule(new StockScreen(stockService)); | ||||||
|         mainFrame.addModule(new StatScreen(statService)); |         mainFrame.addModule(new StatScreen(statService)); | ||||||
|         //TODO ajouter un module AccountScreen |         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(); | ||||||
|   | |||||||
| @@ -0,0 +1,30 @@ | |||||||
|  | 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 javafx.scene.layout.Pane; | ||||||
|  |  | ||||||
|  | public class AccountScreen implements IGuiModule { | ||||||
|  |  | ||||||
|  |     private AccountScreenView view; | ||||||
|  |  | ||||||
|  |     public AccountScreen(AccountService accountService) { | ||||||
|  |         AccountScreenModel model = new AccountScreenModel(accountService); | ||||||
|  |         AccountScreenController ctrl = new AccountScreenController(model); | ||||||
|  |         view = new AccountScreenView(ctrl); | ||||||
|  |  | ||||||
|  |         ctrl.setView(view); | ||||||
|  |         ctrl.updateView(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public String getModuleName() { | ||||||
|  |         return GUIStringTool.getAccountGuiModuleName(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public Pane getPane() { | ||||||
|  |         return view.getPane(); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,83 @@ | |||||||
|  | package com.pqt.client.gui.modules.account_screen; | ||||||
|  |  | ||||||
|  | import com.pqt.client.gui.ressources.components.generics.validators.listeners.IValidatorComponentListener; | ||||||
|  | import com.pqt.core.entities.user_account.Account; | ||||||
|  | import com.pqt.core.entities.user_account.AccountLevel; | ||||||
|  |  | ||||||
|  | class AccountScreenController { | ||||||
|  |  | ||||||
|  |     private AccountScreenModel model; | ||||||
|  |     private AccountScreenView view; | ||||||
|  |  | ||||||
|  |     AccountScreenController(AccountScreenModel model) { | ||||||
|  |         this.model = model; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void setView(AccountScreenView view) { | ||||||
|  |         this.view = view; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void updateView() { | ||||||
|  |         updateViewAccountCollection(); | ||||||
|  |         updateViewActionLock(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private void updateViewAccountCollection(){ | ||||||
|  |         view.setAccountCollection(model.getAccountCollection()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     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); | ||||||
|  |         }else{ | ||||||
|  |             view.setAddAccountActionLocked(true); | ||||||
|  |             view.setDetailAccountActionLocked(true); | ||||||
|  |             view.setRemoveAccountActionLocked(true); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     IValidatorComponentListener getDetailScreenValidationListener(){ | ||||||
|  |         return new IValidatorComponentListener() { | ||||||
|  |             @Override | ||||||
|  |             public void onValidationEvent() { | ||||||
|  |                 if(view.isDetailCreationPossible()){ | ||||||
|  |                     if(view.getDetailScreenInitialValue()!=null){ | ||||||
|  |                         model.modifyAccount(view.getDetailScreenInitialValue(), view.getDetailScreenCreatedValue()); | ||||||
|  |                     }else{ | ||||||
|  |                         model.addAccount(view.getDetailScreenCreatedValue()); | ||||||
|  |                     } | ||||||
|  |                     view.hideDetailScreen(); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             @Override | ||||||
|  |             public void onCancelEvent() { | ||||||
|  |                 view.hideDetailScreen(); | ||||||
|  |             } | ||||||
|  |         }; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void onAddAccountRequested() { | ||||||
|  |         view.showDetailScreen(null, model.getLevels()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void onDetailAccountRequested() { | ||||||
|  |         if(view.isItemSelected()) | ||||||
|  |             view.showDetailScreen(view.getSelectedItem(), model.getLevels()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void onRemoveAccountRequested() { | ||||||
|  |         if(view.isItemSelected()) | ||||||
|  |             model.removeAccount(view.getSelectedItem()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void onRefreshAccountRequested() { | ||||||
|  |         this.updateView(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void onSelectedAccountChanged(Account oldVal, Account newVal) { | ||||||
|  |         updateViewActionLock(); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,44 @@ | |||||||
|  | package com.pqt.client.gui.modules.account_screen; | ||||||
|  |  | ||||||
|  | import com.pqt.client.module.account.AccountService; | ||||||
|  | import com.pqt.core.entities.user_account.Account; | ||||||
|  | import com.pqt.core.entities.user_account.AccountLevel; | ||||||
|  |  | ||||||
|  | import java.util.Collection; | ||||||
|  | import java.util.EnumSet; | ||||||
|  |  | ||||||
|  | //TODO MAJ les méthds modif, add et remove une fois que l'accountService prend en compte les modifs | ||||||
|  | class AccountScreenModel { | ||||||
|  |  | ||||||
|  |     private AccountService accountService; | ||||||
|  |  | ||||||
|  |     AccountScreenModel(AccountService accountService) { | ||||||
|  |         this.accountService = accountService; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void modifyAccount(Account oldVal, Account newVal) { | ||||||
|  |         //accountService.submitAccountUpdate(oldVal, newVal); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void addAccount(Account newVal) { | ||||||
|  |         //accountService.submitAccountUpdate(null, newVal); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void removeAccount(Account oldVal) { | ||||||
|  |         //accountService.submitAccountUpdate(oldVal, null); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     Collection<Account> getAccountCollection() { | ||||||
|  |         return accountService.getAllAccounts(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     Account getCurrentAccount() { | ||||||
|  |         return accountService.getCurrentAccount(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     Collection<AccountLevel> getLevels() { | ||||||
|  |         //TODO régler ça aussi | ||||||
|  |         //return accountService.getAvailableLevels(); | ||||||
|  |         return EnumSet.allOf(AccountLevel.class); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,178 @@ | |||||||
|  | package com.pqt.client.gui.modules.account_screen; | ||||||
|  |  | ||||||
|  | import com.pqt.client.gui.modules.account_screen.account_manager_screen.AccountManagerScreen; | ||||||
|  | import com.pqt.client.gui.ressources.components.generics.IFXComponent; | ||||||
|  | import com.pqt.client.gui.ressources.css.GUICssTool; | ||||||
|  | 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.SimpleStringProperty; | ||||||
|  | import javafx.scene.Node; | ||||||
|  | import javafx.scene.control.*; | ||||||
|  | import javafx.scene.input.MouseButton; | ||||||
|  | import javafx.scene.layout.*; | ||||||
|  |  | ||||||
|  | import java.util.Collection; | ||||||
|  | import java.util.List; | ||||||
|  | import java.util.stream.Collectors; | ||||||
|  |  | ||||||
|  | class AccountScreenView implements IFXComponent{ | ||||||
|  |  | ||||||
|  |     private AccountScreenController ctrl; | ||||||
|  |     private StackPane mainPane; | ||||||
|  |     private BorderPane mainPaneContent; | ||||||
|  |     private TableView<Account> tableView; | ||||||
|  |     private AccountManagerScreen accountManagerScreen; | ||||||
|  |  | ||||||
|  |     private Button addAccountButton, detailAccountButton, removeAccountButton; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     AccountScreenView(AccountScreenController ctrl) { | ||||||
|  |         this.ctrl = ctrl; | ||||||
|  |         initGui(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private void initGui() { | ||||||
|  |         mainPane = new StackPane(); | ||||||
|  |         mainPane.getStyleClass().add(GUICssTool.getMainModulePaneCssClass()); | ||||||
|  |  | ||||||
|  |         mainPaneContent = new BorderPane(); | ||||||
|  |  | ||||||
|  |         tableView = new TableView<>(); | ||||||
|  |  | ||||||
|  |         tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); | ||||||
|  |         tableView.getSelectionModel().selectedItemProperty().addListener((obs, oldVal, newVal)-> ctrl.onSelectedAccountChanged(oldVal, newVal)); | ||||||
|  |         TableColumn<Account, String> nameColumn = new TableColumn<>(GUIStringTool.getAccountNameColumnHeaderLabel()); | ||||||
|  |         nameColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getUsername())); | ||||||
|  |         tableView.getColumns().add(nameColumn); | ||||||
|  |  | ||||||
|  |         TableColumn<Account, String> levelColumn = new TableColumn<>(GUIStringTool.getAccountLevelColumnHeaderLabel()); | ||||||
|  |         levelColumn.setCellValueFactory(param -> new SimpleStringProperty( | ||||||
|  |                             GUIStringTool.getAccountLevelStringRenderer().render(param.getValue().getPermissionLevel()) | ||||||
|  |         )); | ||||||
|  |         tableView.getColumns().add(levelColumn); | ||||||
|  |         mainPaneContent.setCenter(tableView); | ||||||
|  |  | ||||||
|  |         HBox mainPaneTopContent = new HBox(); | ||||||
|  |         mainPaneTopContent.setFillHeight(true); | ||||||
|  |  | ||||||
|  |         Label label = new Label(GUIStringTool.getAccountListTitleLabel()); | ||||||
|  |         label.getStyleClass().add(GUICssTool.getTitleTextStyleClass()); | ||||||
|  |         mainPaneTopContent.getChildren().add(label); | ||||||
|  |  | ||||||
|  |         HBox separator = new HBox(); | ||||||
|  |         ToolBar buttonToolbar = new ToolBar(); | ||||||
|  |         addAccountButton = new Button(GUIStringTool.getAddButtonLabel()); | ||||||
|  |         addAccountButton.setOnMouseClicked(event->{ | ||||||
|  |             if (event.getButton().equals(MouseButton.PRIMARY)) | ||||||
|  |                 ctrl.onAddAccountRequested(); | ||||||
|  |         }); | ||||||
|  |         buttonToolbar.getItems().add(addAccountButton); | ||||||
|  |         detailAccountButton = new Button(GUIStringTool.getDetailButtonLabel()); | ||||||
|  |         detailAccountButton.setOnMouseClicked(event->{ | ||||||
|  |             if (event.getButton().equals(MouseButton.PRIMARY)) | ||||||
|  |                 ctrl.onDetailAccountRequested(); | ||||||
|  |         }); | ||||||
|  |         buttonToolbar.getItems().add(detailAccountButton); | ||||||
|  |         removeAccountButton = new Button(GUIStringTool.getRemoveButtonLabel()); | ||||||
|  |         removeAccountButton.setOnMouseClicked(event->{ | ||||||
|  |             if (event.getButton().equals(MouseButton.PRIMARY)) | ||||||
|  |                 ctrl.onRemoveAccountRequested(); | ||||||
|  |         }); | ||||||
|  |         buttonToolbar.getItems().add(removeAccountButton); | ||||||
|  |         Button refreshAccountButton = new Button(GUIStringTool.getRefreshButtonLabel()); | ||||||
|  |         refreshAccountButton.setOnMouseClicked(event->{ | ||||||
|  |             if (event.getButton().equals(MouseButton.PRIMARY)) | ||||||
|  |                 ctrl.onRefreshAccountRequested(); | ||||||
|  |         }); | ||||||
|  |         buttonToolbar.getItems().add(refreshAccountButton); | ||||||
|  |  | ||||||
|  |         mainPaneTopContent.getChildren().addAll(separator, buttonToolbar); | ||||||
|  |         HBox.setHgrow(separator, Priority.ALWAYS); | ||||||
|  |  | ||||||
|  |         mainPaneContent.setTop(mainPaneTopContent); | ||||||
|  |         mainPane.getChildren().add(mainPaneContent); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     boolean isItemSelected(){ | ||||||
|  |         return tableView.getSelectionModel().getSelectedItem()!=null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     Account getSelectedItem(){ | ||||||
|  |         return tableView.getSelectionModel().getSelectedItem(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public Pane getPane() { | ||||||
|  |         return mainPane; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     boolean isDetailCreationPossible() { | ||||||
|  |         return accountManagerScreen!=null && accountManagerScreen.isCreationPossible(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     Account getDetailScreenInitialValue() { | ||||||
|  |         if(accountManagerScreen!=null) | ||||||
|  |             return accountManagerScreen.getInitialValue(); | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     Account getDetailScreenCreatedValue() { | ||||||
|  |         if(accountManagerScreen!=null) | ||||||
|  |             return accountManagerScreen.create(); | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     boolean isDetailScreenShown(){ | ||||||
|  |         return accountManagerScreen!=null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void showDetailScreen(Account initialValue, Collection<AccountLevel> availableLevels){ | ||||||
|  |         if(!isDetailScreenShown()){ | ||||||
|  |             Pane separator = new Pane(); | ||||||
|  |             separator.getStyleClass().add(GUICssTool.getIntermediaryPaneStyleClass()); | ||||||
|  |             accountManagerScreen = new AccountManagerScreen(initialValue, availableLevels); | ||||||
|  |             accountManagerScreen.addListener(ctrl.getDetailScreenValidationListener()); | ||||||
|  |  | ||||||
|  |             Platform.runLater(()->{ | ||||||
|  |                 mainPane.getChildren().addAll(separator, accountManagerScreen.getPane()); | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void hideDetailScreen(){ | ||||||
|  |         if(isDetailScreenShown()){ | ||||||
|  |             List<Node> toRemove = mainPane.getChildren() | ||||||
|  |                     .stream() | ||||||
|  |                     .filter(node->!node.equals(mainPaneContent)) | ||||||
|  |                     .collect(Collectors.toList()); | ||||||
|  |  | ||||||
|  |             Platform.runLater(()->{ | ||||||
|  |                 mainPane.getChildren().removeAll(toRemove); | ||||||
|  |                 accountManagerScreen = null; | ||||||
|  |             }); | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void setAccountCollection(Collection<Account> accountCollection) { | ||||||
|  |         Platform.runLater(()->{ | ||||||
|  |             tableView.getItems().clear(); | ||||||
|  |             if(accountCollection!=null) | ||||||
|  |                 tableView.getItems().addAll(accountCollection); | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void setAddAccountActionLocked(boolean locked) { | ||||||
|  |         addAccountButton.setDisable(locked); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void setDetailAccountActionLocked(boolean locked) { | ||||||
|  |         detailAccountButton.setDisable(locked); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void setRemoveAccountActionLocked(boolean locked) { | ||||||
|  |         removeAccountButton.setDisable(locked); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,56 @@ | |||||||
|  | package com.pqt.client.gui.modules.account_screen.account_manager_screen; | ||||||
|  |  | ||||||
|  | import com.pqt.client.gui.ressources.components.generics.creators.IFXCreatorComponent; | ||||||
|  | import com.pqt.client.gui.ressources.components.generics.validators.IFXValidatorComponent; | ||||||
|  | import com.pqt.client.gui.ressources.components.generics.validators.listeners.IValidatorComponentListener; | ||||||
|  | import com.pqt.core.entities.user_account.Account; | ||||||
|  | import com.pqt.core.entities.user_account.AccountLevel; | ||||||
|  | import javafx.scene.layout.Pane; | ||||||
|  |  | ||||||
|  | import java.util.Collection; | ||||||
|  |  | ||||||
|  | //TODO à faire | ||||||
|  | public class AccountManagerScreen implements IFXValidatorComponent, IFXCreatorComponent<Account>{ | ||||||
|  |  | ||||||
|  |     private AccountManagerScreenModel model; | ||||||
|  |     private AccountManagerScreenView view; | ||||||
|  |     private AccountManagerScreenController ctrl; | ||||||
|  |  | ||||||
|  |     public AccountManagerScreen(Account initialValue, Collection<AccountLevel> availableLevels) { | ||||||
|  |         model = new AccountManagerScreenModel(initialValue, availableLevels); | ||||||
|  |         ctrl = new AccountManagerScreenController(model); | ||||||
|  |         view = new AccountManagerScreenView(ctrl); | ||||||
|  |  | ||||||
|  |         ctrl.setView(view); | ||||||
|  |         ctrl.updateView(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public Account getInitialValue(){ | ||||||
|  |         return model.getInitialValue(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public Account create() { | ||||||
|  |         return model.getCurrentValue(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public boolean isCreationPossible() { | ||||||
|  |         return model.isCurrentValueValid(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public void addListener(IValidatorComponentListener l) { | ||||||
|  |         ctrl.addListener(l); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public void removeListener(IValidatorComponentListener l) { | ||||||
|  |         ctrl.removeListener(l); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public Pane getPane() { | ||||||
|  |         return view.getPane(); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,58 @@ | |||||||
|  | package com.pqt.client.gui.modules.account_screen.account_manager_screen; | ||||||
|  |  | ||||||
|  | import com.pqt.client.gui.ressources.components.generics.validators.listeners.IValidatorComponentListener; | ||||||
|  | import com.pqt.core.entities.user_account.AccountLevel; | ||||||
|  |  | ||||||
|  | import javax.swing.event.EventListenerList; | ||||||
|  | import java.util.Arrays; | ||||||
|  |  | ||||||
|  | class AccountManagerScreenController { | ||||||
|  |  | ||||||
|  |     private EventListenerList listenerList; | ||||||
|  |     private AccountManagerScreenView view; | ||||||
|  |     private AccountManagerScreenModel model; | ||||||
|  |  | ||||||
|  |     AccountManagerScreenController(AccountManagerScreenModel model) { | ||||||
|  |         listenerList = new EventListenerList(); | ||||||
|  |         this.model = model; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void setView(AccountManagerScreenView view) { | ||||||
|  |         this.view = view; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void updateView() { | ||||||
|  |         view.setLevelCollection(model.getAccountLevelCollection()); | ||||||
|  |         view.setData(model.getCurrentValue()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void addListener(IValidatorComponentListener l) { | ||||||
|  |         listenerList.add(IValidatorComponentListener.class, l); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void removeListener(IValidatorComponentListener l) { | ||||||
|  |         listenerList.remove(IValidatorComponentListener.class, l); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void onNameChanged(String oldVal, String newVal) { | ||||||
|  |         model.changeName(newVal); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void onPasswordChanged(String oldVal, String newVal) { | ||||||
|  |         model.changePassword(newVal); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void onLevelChanged(AccountLevel oldVal, AccountLevel newVal) { | ||||||
|  |         model.changeLevel(newVal); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void onValidationEvent() { | ||||||
|  |         Arrays.stream(listenerList.getListeners(IValidatorComponentListener.class)) | ||||||
|  |                 .forEach(IValidatorComponentListener::onValidationEvent); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void onCancelEvent() { | ||||||
|  |         Arrays.stream(listenerList.getListeners(IValidatorComponentListener.class)) | ||||||
|  |                 .forEach(IValidatorComponentListener::onCancelEvent); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,61 @@ | |||||||
|  | package com.pqt.client.gui.modules.account_screen.account_manager_screen; | ||||||
|  |  | ||||||
|  | import com.pqt.core.entities.user_account.Account; | ||||||
|  | import com.pqt.core.entities.user_account.AccountLevel; | ||||||
|  |  | ||||||
|  | import java.util.Collection; | ||||||
|  | import java.util.HashSet; | ||||||
|  | import java.util.Set; | ||||||
|  |  | ||||||
|  | class AccountManagerScreenModel { | ||||||
|  |     private Account currentValue; | ||||||
|  |     private Account initialValue; | ||||||
|  |     private Set<AccountLevel> levels; | ||||||
|  |  | ||||||
|  |     AccountManagerScreenModel(Account initialValue, Collection<AccountLevel> availableLevels) { | ||||||
|  |         levels = new HashSet<>(); | ||||||
|  |         if(availableLevels!=null) | ||||||
|  |             levels.addAll(availableLevels); | ||||||
|  |         this.initialValue = initialValue; | ||||||
|  |         this.currentValue = (initialValue!=null?new Account(initialValue):getNewAccount()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     Account getCurrentValue() { | ||||||
|  |         return currentValue; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     Account getInitialValue() { | ||||||
|  |         return initialValue; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     boolean isCurrentValueValid() { | ||||||
|  |         return !currentValue.equals(initialValue) | ||||||
|  |                 && currentValue.getUsername()!=null | ||||||
|  |                 && !currentValue.getUsername().isEmpty() | ||||||
|  |                 && currentValue.getPermissionLevel()!=null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     Collection<AccountLevel> getAccountLevelCollection(){ | ||||||
|  |         return levels; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void changeName(String username) { | ||||||
|  |         currentValue.setUsername(username); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void changePassword(String password) { | ||||||
|  |         currentValue.setPassword(password); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void changeLevel(AccountLevel level) { | ||||||
|  |         currentValue.setPermissionLevel(level); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private Account getNewAccount() { | ||||||
|  |         Account account = new Account(); | ||||||
|  |         account.setUsername(""); | ||||||
|  |         account.setPassword(""); | ||||||
|  |         account.setPermissionLevel(levels.stream().min(Enum::compareTo).orElse(AccountLevel.getLowest())); | ||||||
|  |         return account; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,104 @@ | |||||||
|  | package com.pqt.client.gui.modules.account_screen.account_manager_screen; | ||||||
|  |  | ||||||
|  | import com.pqt.client.gui.ressources.components.generics.IFXComponent; | ||||||
|  | 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.scene.control.*; | ||||||
|  | import javafx.scene.input.MouseButton; | ||||||
|  | import javafx.scene.layout.*; | ||||||
|  |  | ||||||
|  | import java.util.Collection; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class AccountManagerScreenView implements IFXComponent{ | ||||||
|  |  | ||||||
|  |     private Pane mainPane; | ||||||
|  |     private AccountManagerScreenController ctrl; | ||||||
|  |  | ||||||
|  |     private ChoiceBox<AccountLevel> levelChoiceBox; | ||||||
|  |     private TextField nameTextField; | ||||||
|  |     private PasswordField passwordField; | ||||||
|  |  | ||||||
|  |     AccountManagerScreenView(AccountManagerScreenController ctrl) { | ||||||
|  |         this.ctrl = ctrl; | ||||||
|  |         initGui(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private void initGui() { | ||||||
|  |         mainPane = new Pane(); | ||||||
|  |  | ||||||
|  |         BorderPane mainPaneContent = new BorderPane(); | ||||||
|  |  | ||||||
|  |         GridPane mainPaneCenterContent = new GridPane(); | ||||||
|  |         Label nameLabel = new Label(GUIStringTool.getUsernameLabel()); | ||||||
|  |         nameTextField = new TextField(); | ||||||
|  |         nameTextField.textProperty().addListener((obs, oldVal, newVal)->ctrl.onNameChanged(oldVal, newVal)); | ||||||
|  |         mainPaneCenterContent.add(nameLabel, 0, 0); | ||||||
|  |         mainPaneCenterContent.add(nameTextField, 1,0); | ||||||
|  |  | ||||||
|  |         Label passwordLabel = new Label(GUIStringTool.getPasswordLabel()); | ||||||
|  |         passwordField = new PasswordField(); | ||||||
|  |         passwordField.textProperty().addListener((obs, oldVal, newVal)->ctrl.onPasswordChanged(oldVal, newVal)); | ||||||
|  |         mainPaneCenterContent.add(passwordLabel, 0, 1); | ||||||
|  |         mainPaneCenterContent.add(passwordField, 1,1); | ||||||
|  |  | ||||||
|  |         Label levelLabel = new Label(GUIStringTool.getUserLevelLabel()); | ||||||
|  |         levelChoiceBox = new ChoiceBox<>(); | ||||||
|  |         levelChoiceBox.valueProperty().addListener((obs, oldVal, newVal)->ctrl.onLevelChanged(oldVal, newVal)); | ||||||
|  |         mainPaneCenterContent.add(levelLabel, 0, 2); | ||||||
|  |         mainPaneCenterContent.add(levelChoiceBox, 1,2); | ||||||
|  |  | ||||||
|  |         mainPaneContent.setCenter(mainPaneCenterContent); | ||||||
|  |  | ||||||
|  |         HBox mainPaneBottomContent = new HBox(); | ||||||
|  |         mainPaneBottomContent.setFillHeight(true); | ||||||
|  |         Button validationButton = new Button(GUIStringTool.getValidationButtonLabel()); | ||||||
|  |         validationButton.setOnMouseClicked(event -> { | ||||||
|  |             if (event.getButton().equals(MouseButton.PRIMARY)) | ||||||
|  |                 ctrl.onValidationEvent(); | ||||||
|  |         }); | ||||||
|  |         Button cancelButton = new Button(GUIStringTool.getValidationButtonLabel()); | ||||||
|  |         cancelButton.setOnMouseClicked(event -> { | ||||||
|  |             if (event.getButton().equals(MouseButton.PRIMARY)) | ||||||
|  |                 ctrl.onCancelEvent(); | ||||||
|  |         }); | ||||||
|  |         HBox separator = new HBox(); | ||||||
|  |  | ||||||
|  |         mainPaneBottomContent.getChildren().addAll(separator, validationButton, cancelButton); | ||||||
|  |         HBox.setHgrow(separator, Priority.ALWAYS); | ||||||
|  |  | ||||||
|  |         mainPaneContent.setBottom(mainPaneBottomContent); | ||||||
|  |         mainPane.getChildren().add(mainPaneContent); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public Pane getPane() { | ||||||
|  |         return mainPane; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void setLevelCollection(Collection<AccountLevel> levelCollection) { | ||||||
|  |         Platform.runLater(()->{ | ||||||
|  |             levelChoiceBox.getItems().clear(); | ||||||
|  |             levelChoiceBox.getItems().addAll(levelCollection); | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     void setData(Account data) { | ||||||
|  |         Platform.runLater(()->{ | ||||||
|  |             if(data!=null){ | ||||||
|  |                 nameTextField.setText(data.getUsername()); | ||||||
|  |                 passwordField.setText(data.getPassword()); | ||||||
|  |                 levelChoiceBox.setValue(data.getPermissionLevel()); | ||||||
|  |             }else{ | ||||||
|  |                 nameTextField.setText(""); | ||||||
|  |                 passwordField.setText(""); | ||||||
|  |                 levelChoiceBox.setValue(levelChoiceBox.getItems() | ||||||
|  |                         .stream() | ||||||
|  |                         .min(Enum::compareTo) | ||||||
|  |                         .orElse(AccountLevel.getLowest())); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -284,6 +284,53 @@ public class GUIStringTool { | |||||||
|     public static String getComponentListTitleLabel() { |     public static String getComponentListTitleLabel() { | ||||||
|         return "Composants"; |         return "Composants"; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public static String getAccountGuiModuleName() { | ||||||
|  |         return "Utilisateurs"; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static IObjectStringRenderer<AccountLevel> getAccountLevelStringRenderer() { | ||||||
|  |         return level->{ | ||||||
|  |             switch (level){ | ||||||
|  |                 case LOWEST: | ||||||
|  |                     return "autre"; | ||||||
|  |                 case GUEST: | ||||||
|  |                     return "Invité"; | ||||||
|  |                 case STAFF: | ||||||
|  |                     return "Staff"; | ||||||
|  |                 case WAITER: | ||||||
|  |                     return "Caissier"; | ||||||
|  |                 case MASTER: | ||||||
|  |                     return "Chef"; | ||||||
|  |                 default: | ||||||
|  |                     return "unknown"; | ||||||
|  |             } | ||||||
|  |         }; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static String getAccountListTitleLabel() { | ||||||
|  |         return "Utilisateurs"; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static String getUsernameLabel() { | ||||||
|  |         return "Nom :"; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static String getPasswordLabel() { | ||||||
|  |         return "Mot de passe : "; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static String getUserLevelLabel() { | ||||||
|  |         return "Niveau d'accréditation : "; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static String getAccountNameColumnHeaderLabel() { | ||||||
|  |         return "Nom d'utilisateur"; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static String getAccountLevelColumnHeaderLabel() { | ||||||
|  |         return "Niveau d'accréditation"; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user