From 90985fbc467ab7a5b8050eb0f56128ae8128a609 Mon Sep 17 00:00:00 2001 From: Notmoo Date: Sat, 19 Aug 2017 19:22:14 +0200 Subject: [PATCH] =?UTF-8?q?Module=20Client=20:=20ajout=20=C3=A9cran=20de?= =?UTF-8?q?=20gestion=20des=20comptes=20utilisateurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/pqt/client/Main.java | 3 +- .../modules/account_screen/AccountScreen.java | 30 +++ .../AccountScreenController.java | 83 ++++++++ .../account_screen/AccountScreenModel.java | 44 +++++ .../account_screen/AccountScreenView.java | 178 ++++++++++++++++++ .../AccountManagerScreen.java | 56 ++++++ .../AccountManagerScreenController.java | 58 ++++++ .../AccountManagerScreenModel.java | 61 ++++++ .../AccountManagerScreenView.java | 104 ++++++++++ .../gui/ressources/strings/GUIStringTool.java | 47 +++++ 10 files changed, 663 insertions(+), 1 deletion(-) create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreen.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenController.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenModel.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenView.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreen.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreenController.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreenModel.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreenView.java 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 5e978bc4..c09ccd86 100644 --- a/Workspace/client/src/main/java/com/pqt/client/Main.java +++ b/Workspace/client/src/main/java/com/pqt/client/Main.java @@ -1,6 +1,7 @@ package com.pqt.client; 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.stat_screen.StatScreen; 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 StockScreen(stockService)); mainFrame.addModule(new StatScreen(statService)); - //TODO ajouter un module AccountScreen + mainFrame.addModule(new AccountScreen(accountService)); Scene scene = new Scene(mainFrame.getPane(), 800, 600); scene.getStylesheets().clear(); 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 new file mode 100644 index 00000000..2c5f4ea8 --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreen.java @@ -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(); + } +} 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 new file mode 100644 index 00000000..f27509ce --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenController.java @@ -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(); + } +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenModel.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenModel.java new file mode 100644 index 00000000..a1a129a0 --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenModel.java @@ -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 getAccountCollection() { + return accountService.getAllAccounts(); + } + + Account getCurrentAccount() { + return accountService.getCurrentAccount(); + } + + Collection getLevels() { + //TODO régler ça aussi + //return accountService.getAvailableLevels(); + return EnumSet.allOf(AccountLevel.class); + } +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenView.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenView.java new file mode 100644 index 00000000..71a067fc --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenView.java @@ -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 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 nameColumn = new TableColumn<>(GUIStringTool.getAccountNameColumnHeaderLabel()); + nameColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getUsername())); + tableView.getColumns().add(nameColumn); + + TableColumn 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 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 toRemove = mainPane.getChildren() + .stream() + .filter(node->!node.equals(mainPaneContent)) + .collect(Collectors.toList()); + + Platform.runLater(()->{ + mainPane.getChildren().removeAll(toRemove); + accountManagerScreen = null; + }); + + } + } + + void setAccountCollection(Collection 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); + } +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreen.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreen.java new file mode 100644 index 00000000..26cd33e2 --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreen.java @@ -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{ + + private AccountManagerScreenModel model; + private AccountManagerScreenView view; + private AccountManagerScreenController ctrl; + + public AccountManagerScreen(Account initialValue, Collection 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(); + } +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreenController.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreenController.java new file mode 100644 index 00000000..e3b6e000 --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreenController.java @@ -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); + } +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreenModel.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreenModel.java new file mode 100644 index 00000000..e0dd15d0 --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreenModel.java @@ -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 levels; + + AccountManagerScreenModel(Account initialValue, Collection 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 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; + } +} 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 new file mode 100644 index 00000000..722e54ef --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/account_manager_screen/AccountManagerScreenView.java @@ -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 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 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())); + } + }); + } +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/ressources/strings/GUIStringTool.java b/Workspace/client/src/main/java/com/pqt/client/gui/ressources/strings/GUIStringTool.java index 6fb4a0a4..af5f1781 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/ressources/strings/GUIStringTool.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/ressources/strings/GUIStringTool.java @@ -284,6 +284,53 @@ public class GUIStringTool { public static String getComponentListTitleLabel() { return "Composants"; } + + public static String getAccountGuiModuleName() { + return "Utilisateurs"; + } + + public static IObjectStringRenderer 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"; + } }