From a62d7e0cc5a2f1c70df29a8297eb8e8eeab0aefb Mon Sep 17 00:00:00 2001 From: "Notmoo-PC\\Notmoo" Date: Thu, 26 Oct 2017 16:05:32 +0200 Subject: [PATCH] =?UTF-8?q?Module=20Client=20:=20ajout=20code=20transition?= =?UTF-8?q?=20frames=20startup<->main;=20bouton=20connexion=20d=C3=A9sorma?= =?UTF-8?q?is=20gris=C3=A9=20si=20saisie=20insuffisante(startup=20frame);?= =?UTF-8?q?=20Afficheur=20de=20compte=20d=C3=A9sormais=20=C3=A0=20un=20seu?= =?UTF-8?q?l=20=C3=A9tat=20(uniquement=20connect=C3=A9);=20Suppression=20d?= =?UTF-8?q?u=20composant=20graphique=20AccountManager=20(inutile);?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/pqt/client/Main.java | 43 ++++- .../pqt/client/gui/main_frame/MainFrame.java | 9 +- .../gui/main_frame/MainFrameController.java | 57 +----- .../client/gui/main_frame/MainFrameModel.java | 26 +-- .../client/gui/main_frame/MainFrameView.java | 32 +--- .../listeners/IMainFrameModelListener.java | 3 +- .../AccountManagerScreen.java | 1 - .../ressources/components/AccountManager.java | 162 ------------------ .../IFXAccountsDisplayerComponent.java | 11 -- .../listeners/IAccountComponentListener.java | 7 - .../SimpleAccountComponentFirerer.java | 10 -- .../gui/startup_frame/StartupFrame.java | 11 +- .../startup_frame/StartupFrameController.java | 15 +- .../gui/startup_frame/StartupFrameModel.java | 41 ++++- .../gui/startup_frame/StartupFrameView.java | 75 +++++--- .../StartupProcedureHandler.java | 26 ++- .../frame/IStartupFrameModelEventFirerer.java | 8 + .../IStartupFrameModelListener.java | 3 +- .../SimpleStartupFrameModelEventFirerer.java | 29 ++++ .../IStartupProcedureEventFirerer.java | 12 ++ .../procedure/IStartupProcedureListener.java | 11 ++ .../SimpleStartupProcedureEventFirerer.java | 47 +++++ .../module/ClientBackEndModuleManager.java | 2 +- 23 files changed, 300 insertions(+), 341 deletions(-) delete mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/AccountManager.java delete mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/specifics/account/IFXAccountsDisplayerComponent.java delete mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/specifics/account/listeners/IAccountComponentListener.java delete mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/specifics/account/listeners/SimpleAccountComponentFirerer.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/frame/IStartupFrameModelEventFirerer.java rename Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/{ => frame}/IStartupFrameModelListener.java (53%) create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/frame/SimpleStartupFrameModelEventFirerer.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/procedure/IStartupProcedureEventFirerer.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/procedure/IStartupProcedureListener.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/procedure/SimpleStartupProcedureEventFirerer.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 65ae061c..311fd517 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.main_frame.listeners.IMainFrameModelListener; 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; @@ -9,9 +10,12 @@ import com.pqt.client.gui.ressources.components.generics.toast.ToastFactory; import com.pqt.client.gui.ressources.css.GUICssTool; import com.pqt.client.gui.ressources.strings.GUIStringTool; import com.pqt.client.gui.startup_frame.StartupFrame; +import com.pqt.client.gui.startup_frame.listeners.frame.IStartupFrameModelListener; import com.pqt.client.module.ClientBackEndModuleManager; import javafx.application.Application; +import javafx.application.Platform; import javafx.scene.Scene; +import javafx.scene.layout.Pane; import javafx.stage.Stage; public class Main extends Application{ @@ -22,24 +26,53 @@ public class Main extends Application{ @Override public void start(Stage primaryStage) throws Exception { - //TODO ajouter écran de préloading : StartupFrame ClientBackEndModuleManager moduleManager = new ClientBackEndModuleManager(null); + MainFrame mainFrame = new MainFrame(moduleManager.getAccountService()); mainFrame.addModule(new SaleScreen(moduleManager.getAccountService(), moduleManager.getStockService(), moduleManager.getSaleService()), true); mainFrame.addModule(new StockScreen(moduleManager.getStockService(), moduleManager.getAccountService())); mainFrame.addModule(new StatScreen(moduleManager.getStatService())); mainFrame.addModule(new AccountScreen(moduleManager.getAccountService())); + Scene mainFrameScene = initScene(mainFrame.getPane()); StartupFrame startupFrame = new StartupFrame(moduleManager.getAccountService(), moduleManager.getNetworkService()); - Scene scene = new Scene(startupFrame.getPane()); - scene.getStylesheets().clear(); - scene.getStylesheets().addAll(getClass().getResource(GUICssTool.getCssFilePath()).toExternalForm()); + Scene startupFrameScene = initScene(startupFrame.getPane()); + + mainFrame.addFrameModelListener(getMainFrameListener(primaryStage, startupFrameScene)); + startupFrame.addFrameModelListener(getStartupFrameListener(primaryStage, mainFrameScene)); ToastFactory.init(primaryStage); primaryStage.setTitle(GUIStringTool.getAppTitle()); - primaryStage.setScene(scene); + primaryStage.setScene(startupFrameScene); primaryStage.show(); } + + private Scene initScene(Pane pane){ + Scene scene = new Scene(pane); + scene.getStylesheets().clear(); + scene.getStylesheets().addAll(getClass().getResource(GUICssTool.getCssFilePath()).toExternalForm()); + + return scene; + } + + private IStartupFrameModelListener getStartupFrameListener(Stage primaryStage, Scene sceneToDisplay){ + return () -> trySwitchScene(primaryStage, sceneToDisplay, true); + } + + private IMainFrameModelListener getMainFrameListener(Stage primaryStage, Scene sceneToDisplay){ + return () -> trySwitchScene(primaryStage, sceneToDisplay, false); + } + + private void trySwitchScene(Stage primaryStage, Scene sceneToDisplay, boolean maximize){ + if(sceneToDisplay!=null) { + primaryStage.hide(); + primaryStage.setScene(sceneToDisplay); + primaryStage.setMaximized(maximize); + primaryStage.show(); + }else{ + Platform.exit(); + } + } } 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 4ded52f6..bccfbce8 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 @@ -1,7 +1,9 @@ package com.pqt.client.gui.main_frame; +import com.pqt.client.gui.main_frame.listeners.IMainFrameModelListener; import com.pqt.client.gui.modules.IGuiModule; import com.pqt.client.gui.ressources.components.generics.IFXComponent; +import com.pqt.client.gui.startup_frame.listeners.frame.IStartupFrameModelListener; import com.pqt.client.module.account.AccountService; import javafx.scene.layout.Pane; @@ -9,9 +11,10 @@ public class MainFrame implements IFXComponent { private MainFrameView view; private MainFrameController ctrl; + private MainFrameModel model; public MainFrame(AccountService accountService) { - MainFrameModel model = new MainFrameModel(accountService); + model = new MainFrameModel(accountService); ctrl = new MainFrameController(model); model.addListener(ctrl); @@ -28,6 +31,10 @@ public class MainFrame implements IFXComponent { ctrl.addModule(module, false); } + public void addFrameModelListener(IMainFrameModelListener l){ + model.addListener(l); + } + @Override public Pane getPane() { return view.getPane(); 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 180f7802..15f43711 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 @@ -2,17 +2,12 @@ package com.pqt.client.gui.main_frame; import com.pqt.client.gui.main_frame.listeners.IMainFrameModelListener; 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 { private MainFrameModel model; private MainFrameView view; - private IValidatorComponentListener accountManagerAccountListener; MainFrameController(MainFrameModel model) { this.model = model; @@ -23,7 +18,6 @@ class MainFrameController implements IMainFrameModelListener { } void updateView(){ - view.feedAccountCollectionToManager(model.getAccounts()); view.setCurrentAccount(model.getCurrentAccount()); if(model.getCurrentAccount()!=null) view.updateModuleButtonLock(model.getCurrentAccount().getPermissionLevel()); @@ -38,57 +32,12 @@ class MainFrameController implements IMainFrameModelListener { this.view.addGuiModule(module.getModuleName(),module.getPane(), module.getLowestRequiredAccountLevel(), activate); } - IValidatorComponentListener getAccountManagerValidatorListener() { - return new IValidatorComponentListener() { - @Override - public void onValidationEvent() { - if(view.isAccountCreationPossible()) - model.connectAccount(view.create()); - } - - @Override - public void onCancelEvent() { - model.disconnectCurrentAccount(); - } - }; - } - - IAccountComponentListener getAccountManagerAccountListener() { - return new IAccountComponentListener() { - @Override - public void onRefreshContentRequestEvent() { - - } - - @Override - public void onContentClickEvent(Event event, Account eventTarget) { - - } - - @Override - public void onAddContentRequestEvent() { - - } - - @Override - public void onRemoveContentRequestEvent(Account content) { - - } - - @Override - public void onDetailContentRequestEvent(Account content) { - - } - }; + public void onAccountDisconnectionRequested() { + model.disconnectCurrentAccount(); } @Override - public void onAccountStatusChangedEvent(boolean status) { - updateView(); - } + public void onAccountDisconnectedEvent() { - @Override - public void onAccountCollectionChangedEvent() { - updateView(); } } diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrameModel.java b/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrameModel.java index 755269a1..4a0133a6 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrameModel.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrameModel.java @@ -20,7 +20,9 @@ class MainFrameModel { this.accountService.addListener(new IAccountListener() { @Override public void onAccountStatusChangedEvent(boolean status) { - MainFrameModel.this.fireAccountStatusChangedEvent(status); + if(!status){ + MainFrameModel.this.fireAccountDisconnectedEvent(); + } } @Override @@ -30,30 +32,20 @@ class MainFrameModel { @Override public void onAccountListChangedEvent() { - MainFrameModel.this.fireAccountCollectionChangedEvent(); } }); } - private void fireAccountCollectionChangedEvent() { - Arrays.stream(listenerList.getListeners(IMainFrameModelListener.class)).forEach(IMainFrameModelListener::onAccountCollectionChangedEvent); - } - - private void fireAccountStatusChangedEvent(boolean status) { - Arrays.stream(listenerList.getListeners(IMainFrameModelListener.class)).forEach(l->l.onAccountStatusChangedEvent(status)); - } - - void connectAccount(Account account) { - accountService.setCurrentAccount(account); - accountService.logInCurrentAccount(account.getPassword()); + private void fireAccountDisconnectedEvent() { + Arrays.stream(listenerList.getListeners(IMainFrameModelListener.class)).forEach(IMainFrameModelListener::onAccountDisconnectedEvent); } void disconnectCurrentAccount() { + fireAccountDisconnectedEvent(); + //TODO uncomment code when test are to be done + /* accountService.logOutCurrentAccount(); - } - - Collection getAccounts(){ - return accountService.getAllAccounts(); + */ } void addListener(IMainFrameModelListener listener){ 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 7b951581..fbe883b1 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 @@ -1,6 +1,5 @@ package com.pqt.client.gui.main_frame; -import com.pqt.client.gui.ressources.components.AccountManager; import com.pqt.client.gui.ressources.components.generics.IFXComponent; import com.pqt.client.gui.ressources.components.generics.others.SideBar; import com.pqt.client.gui.ressources.components.generics.others.listeners.ISideBarListener; @@ -10,11 +9,9 @@ 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; -import javafx.scene.control.ToolBar; +import javafx.scene.control.Label; import javafx.scene.input.KeyCode; import javafx.scene.input.MouseButton; import javafx.scene.layout.BorderPane; @@ -22,16 +19,14 @@ import javafx.scene.layout.Pane; import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; -import java.util.Collection; - class MainFrameView implements IFXComponent{ private final MainFrameController ctrl; private BorderPane mainPane; - private AccountManager accountManager; private VBox buttonHolder; private ObjectProperty currentAccountLevel; + private Label accountNameLabel; MainFrameView(MainFrameController ctrl) { this.ctrl = ctrl; @@ -51,11 +46,10 @@ class MainFrameView implements IFXComponent{ buttonHolder.prefWidthProperty().bind(sidebar.widthProperty()); sidebar.getChildren().add(buttonHolder); - accountManager = new AccountManager(); - accountManager.addListener(ctrl.getAccountManagerValidatorListener()); - accountManager.addListener(ctrl.getAccountManagerAccountListener()); - accountManager.getPane().prefWidthProperty().bind(sidebar.widthProperty()); - sidebar.getChildren().add(accountManager.getPane()); + accountNameLabel = new Label(); + Button disconnectionButton = new Button(GUIStringTool.getLogoutButtonLabel()); + disconnectionButton.setOnAction((event -> ctrl.onAccountDisconnectionRequested())); + sidebar.getChildren().addAll(accountNameLabel, disconnectionButton); mainPane.setLeft(sidebar); @@ -120,20 +114,8 @@ class MainFrameView implements IFXComponent{ buttonHolder.getChildren().add(button); } - boolean isAccountCreationPossible(){ - return accountManager.isCreationPossible(); - } - - Account create(){ - return accountManager.create(); - } - void setCurrentAccount(Account account){ - accountManager.setCurrentAccount(account); - } - - void feedAccountCollectionToManager(Collection accounts){ - accountManager.display(accounts); + accountNameLabel.setText(GUIStringTool.getAccountStringConverter().toString(account)); } void updateModuleButtonLock(AccountLevel level) { diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/listeners/IMainFrameModelListener.java b/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/listeners/IMainFrameModelListener.java index 5c876e26..d9c1229f 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/listeners/IMainFrameModelListener.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/listeners/IMainFrameModelListener.java @@ -3,6 +3,5 @@ package com.pqt.client.gui.main_frame.listeners; import java.util.EventListener; public interface IMainFrameModelListener extends EventListener{ - void onAccountStatusChangedEvent(boolean status); - void onAccountCollectionChangedEvent(); + void onAccountDisconnectedEvent(); } 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 index 26cd33e2..ae980085 100644 --- 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 @@ -9,7 +9,6 @@ import javafx.scene.layout.Pane; import java.util.Collection; -//TODO à faire public class AccountManagerScreen implements IFXValidatorComponent, IFXCreatorComponent{ private AccountManagerScreenModel model; diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/AccountManager.java b/Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/AccountManager.java deleted file mode 100644 index a88fb26c..00000000 --- a/Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/AccountManager.java +++ /dev/null @@ -1,162 +0,0 @@ -package com.pqt.client.gui.ressources.components; - -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.specifics.account.listeners.IAccountComponentListener; -import com.pqt.client.gui.ressources.components.generics.validators.listeners.IValidatorComponentListener; -import com.pqt.client.gui.ressources.components.generics.validators.listeners.SimpleValidatorComponentFirerer; -import com.pqt.client.gui.ressources.components.specifics.account.IFXAccountsDisplayerComponent; -import com.pqt.client.gui.ressources.components.specifics.account.listeners.SimpleAccountComponentFirerer; -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.collections.FXCollections; -import javafx.scene.control.Button; -import javafx.scene.control.ChoiceBox; -import javafx.scene.control.PasswordField; -import javafx.scene.control.TextField; -import javafx.scene.input.KeyCode; -import javafx.scene.layout.HBox; -import javafx.scene.layout.Pane; -import javafx.scene.layout.VBox; - -import java.util.Collection; - -public class AccountManager implements IFXAccountsDisplayerComponent, IFXValidatorComponent, IFXCreatorComponent { - - private Pane mainPane; - - private VBox mainDisconnectedPane, mainConnectedPane; - private TextField connectedUsernameField; - private ChoiceBox disconnectedUsernameField; - private PasswordField passwordField; - - private SimpleAccountComponentFirerer accountEventFirerer; - private SimpleValidatorComponentFirerer validatorEventFirerer; - - private Account currentAccount; - - public AccountManager() { - accountEventFirerer = new SimpleAccountComponentFirerer(); - validatorEventFirerer = new SimpleValidatorComponentFirerer(); - - currentAccount = null; - - init(); - } - - private void init() { - mainPane = new Pane(); - - mainConnectedPane = new VBox(); - mainDisconnectedPane = new VBox(); - - connectedUsernameField = new TextField(); - connectedUsernameField.setEditable(false); - - Button disconnectButton = new Button(GUIStringTool.getLogoutButtonLabel()); - disconnectButton.setOnMouseClicked(event->validatorEventFirerer.fireCancelEvent()); - disconnectButton.setOnKeyTyped(event->{if(event.getCode().equals(KeyCode.ENTER)) validatorEventFirerer.fireCancelEvent();}); - - mainConnectedPane.getChildren().addAll(connectedUsernameField, disconnectButton); - - - disconnectedUsernameField = new ChoiceBox<>(); - disconnectedUsernameField.setConverter(GUIStringTool.getAccountStringConverter()); - - passwordField = new PasswordField(); - passwordField.setPromptText(GUIStringTool.getPasswordFieldPromptText()); - - Button validationButton = new Button(GUIStringTool.getLoginButtonLabel()); - validationButton.setOnMouseClicked(event-> validatorEventFirerer.fireValidationEvent()); - validationButton.setOnKeyTyped(event->{if(event.getCode().equals(KeyCode.ENTER)) validatorEventFirerer.fireValidationEvent();}); - - mainDisconnectedPane.getChildren().addAll(disconnectedUsernameField, passwordField, validationButton); - - refreshMainPane(); - display(null); - } - - @Override - public void display(Collection content) { - Platform.runLater(()->{ - if(content!=null && content.size()>0) - disconnectedUsernameField.setItems(FXCollections.observableArrayList(content)); - else{ - disconnectedUsernameField.getItems().clear(); - disconnectedUsernameField.getItems().add(new Account("null", "", AccountLevel.getLowest())); - } - }); - } - - public void setCurrentAccount(Account account){ - currentAccount = account; - Platform.runLater(()->connectedUsernameField.setText(GUIStringTool.getAccountStringConverter().toString(currentAccount))); - refreshMainPane(); - } - - private void refreshMainPane() { - if(currentAccount!=null) - Platform.runLater( - ()->{ - mainPane.getChildren().clear(); - mainPane.getChildren().add(mainConnectedPane); - } - ); - else - Platform.runLater( - ()->{ - mainPane.getChildren().clear(); - mainPane.getChildren().add(mainDisconnectedPane); - } - ); - } - - public Account getCurrentAccount() { - return currentAccount; - } - - @Override - public void addListener(IAccountComponentListener l) { - accountEventFirerer.addListener(l); - } - - @Override - public void removeListener(IAccountComponentListener l) { - accountEventFirerer.removeListener(l); - } - - @Override - public Pane getPane() { - return mainPane; - } - - @Override - public void addListener(IValidatorComponentListener l) { - validatorEventFirerer.addListener(l); - } - - @Override - public void removeListener(IValidatorComponentListener l) { - validatorEventFirerer.removeListener(l); - } - - @Override - public Account create() { - if(!isCreationPossible()) - return null; - - return new Account(disconnectedUsernameField.getValue().getUsername(), passwordField.getText(), disconnectedUsernameField.getValue().getPermissionLevel()); - } - - @Override - public boolean isCreationPossible() { - return currentAccount==null - && disconnectedUsernameField.getAccessibleText()!=null - && !disconnectedUsernameField.getAccessibleText().isEmpty() - && passwordField.getText()!=null - && !passwordField.getText().isEmpty(); - - } -} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/specifics/account/IFXAccountsDisplayerComponent.java b/Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/specifics/account/IFXAccountsDisplayerComponent.java deleted file mode 100644 index 1c459115..00000000 --- a/Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/specifics/account/IFXAccountsDisplayerComponent.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.pqt.client.gui.ressources.components.specifics.account; - -import com.pqt.client.gui.ressources.components.generics.displayers.IFXDisplayerComponent; -import com.pqt.client.gui.ressources.components.specifics.account.listeners.IAccountComponentListener; -import com.pqt.core.entities.user_account.Account; - -import java.util.Collection; - -public interface IFXAccountsDisplayerComponent extends IFXDisplayerComponent, IAccountComponentListener> { - -} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/specifics/account/listeners/IAccountComponentListener.java b/Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/specifics/account/listeners/IAccountComponentListener.java deleted file mode 100644 index 9fe3ff70..00000000 --- a/Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/specifics/account/listeners/IAccountComponentListener.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.pqt.client.gui.ressources.components.specifics.account.listeners; - -import com.pqt.client.gui.ressources.components.generics.displayers.listeners.IDisplayerComponentListener; -import com.pqt.core.entities.user_account.Account; - -public interface IAccountComponentListener extends IDisplayerComponentListener{ -} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/specifics/account/listeners/SimpleAccountComponentFirerer.java b/Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/specifics/account/listeners/SimpleAccountComponentFirerer.java deleted file mode 100644 index 8f06f6a2..00000000 --- a/Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/specifics/account/listeners/SimpleAccountComponentFirerer.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.pqt.client.gui.ressources.components.specifics.account.listeners; - -import com.pqt.client.gui.ressources.components.generics.displayers.listeners.SimpleDisplayerComponentFirerer; -import com.pqt.core.entities.user_account.Account; - -public class SimpleAccountComponentFirerer extends SimpleDisplayerComponentFirerer { - public SimpleAccountComponentFirerer() { - super(IAccountComponentListener.class); - } -} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrame.java b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrame.java index 07721397..29e2c7e0 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrame.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrame.java @@ -1,6 +1,7 @@ package com.pqt.client.gui.startup_frame; import com.pqt.client.gui.ressources.components.generics.IFXComponent; +import com.pqt.client.gui.startup_frame.listeners.frame.IStartupFrameModelListener; import com.pqt.client.module.account.AccountService; import com.pqt.client.module.network.NetworkService; import javafx.scene.layout.Pane; @@ -8,11 +9,11 @@ import javafx.scene.layout.Pane; public class StartupFrame implements IFXComponent{ private StartupFrameView view; - private StartupFrameController ctrl; + private StartupFrameModel model; public StartupFrame(AccountService accountService, NetworkService networkService) { - StartupFrameModel model = new StartupFrameModel(accountService, networkService); - ctrl = new StartupFrameController(model); + model = new StartupFrameModel(accountService, networkService); + StartupFrameController ctrl = new StartupFrameController(model); model.addListener(ctrl); view = new StartupFrameView(ctrl); @@ -20,6 +21,10 @@ public class StartupFrame implements IFXComponent{ ctrl.updateView(); } + public void addFrameModelListener(IStartupFrameModelListener l){ + model.addListener(l); + } + @Override public Pane getPane() { return view.getPane(); diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameController.java b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameController.java index 8500064e..346335d4 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameController.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameController.java @@ -1,6 +1,6 @@ package com.pqt.client.gui.startup_frame; -import com.pqt.client.gui.startup_frame.listeners.IStartupFrameModelListener; +import com.pqt.client.gui.startup_frame.listeners.frame.IStartupFrameModelListener; public class StartupFrameController implements IStartupFrameModelListener { @@ -16,7 +16,13 @@ public class StartupFrameController implements IStartupFrameModelListener { } public void updateView() { - //TODO écrire corps méthd StartupFrameController.updateView() + view.setValidationButtonEnable(enableValidationButton()); + } + + private boolean enableValidationButton() { + return !view.getAccountUsernameTextFieldContent().isEmpty() + && !view.getServerPortTextFieldContent().isEmpty() + && !view.getServerPortTextFieldContent().isEmpty(); } public void onValidation() { @@ -31,4 +37,9 @@ public class StartupFrameController implements IStartupFrameModelListener { ); } } + + @Override + public void onStartupValidated() { + view.clearPasswordField(); + } } diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameModel.java b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameModel.java index daf3dc0a..998e931a 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameModel.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameModel.java @@ -1,31 +1,29 @@ package com.pqt.client.gui.startup_frame; -import com.pqt.client.gui.startup_frame.listeners.IStartupFrameModelListener; +import com.pqt.client.gui.startup_frame.listeners.frame.IStartupFrameModelEventFirerer; +import com.pqt.client.gui.startup_frame.listeners.frame.IStartupFrameModelListener; +import com.pqt.client.gui.startup_frame.listeners.frame.SimpleStartupFrameModelEventFirerer; +import com.pqt.client.gui.startup_frame.listeners.procedure.IStartupProcedureListener; import com.pqt.client.module.account.AccountService; -import com.pqt.client.module.account.listeners.AccountListenerAdapter; -import com.pqt.client.module.account.listeners.IAccountListener; import com.pqt.client.module.network.NetworkService; -import com.pqt.client.module.network.listeners.INetworkServiceListener; - -import javax.swing.event.EventListenerList; public class StartupFrameModel { private final AccountService accountService; private final NetworkService networkService; - private final EventListenerList listenerList; + private final IStartupFrameModelEventFirerer firerer; private boolean startupProcessBegan; public StartupFrameModel(AccountService accountService, NetworkService networkService) { this.accountService = accountService; this.networkService = networkService; - this.listenerList = new EventListenerList(); + firerer = new SimpleStartupFrameModelEventFirerer(); startupProcessBegan = false; } public void addListener(IStartupFrameModelListener ctrl) { - listenerList.add(IStartupFrameModelListener.class, ctrl); + firerer.addListener(ctrl); } public boolean isStartupProcessRunning() { @@ -33,6 +31,9 @@ public class StartupFrameModel { } public void beginStartupProcess(String requiredHost, String requiredPort, String username, String password) { + //TODO uncomment code when test are to be done + firerer.fireStartupValidated(); + /* if(!startupProcessBegan){ checkParameters(requiredHost, requiredPort, username, password); startupProcessBegan = true; @@ -41,8 +42,30 @@ public class StartupFrameModel { new StartupProcedureHandler(networkService, accountService) .init(requiredHost, requiredIntPort, username, password) + .addListener(new IStartupProcedureListener() { + @Override + public void onServerFoundEvent(String URL, Integer Port) { + + } + + @Override + public void onUserAccountUnknownEvent(String username) { + + } + + @Override + public void onUserAccountConnectedEvent(String username) { + firerer.fireStartupValidated(); + } + + @Override + public void onUserAccountDisconnectedEvent(String username) { + + } + }) .handle(); } + */ } private void checkParameters(String host, String port, String username, String password) { diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameView.java b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameView.java index 3cc5dcd4..b2d03caa 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameView.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameView.java @@ -15,47 +15,62 @@ public class StartupFrameView implements IFXComponent{ private TextField usernameTextField; private TextField passwordTextField; + private Button validationButton; + public StartupFrameView(StartupFrameController ctrl) { this.ctrl = ctrl; initGui(); } private void initGui() { - mainPane = new VBox(); + try { + mainPane = new VBox(); - Label serverHostLabel = new Label(GUIStringTool.getServerHostLabel()); - serverHostTextField = new TextField(); - Label serverPortLabel = new Label(GUIStringTool.getServerPortLabel()); - serverPortTextField = new TextField(); + Label serverHostLabel = new Label(GUIStringTool.getServerHostLabel()); + serverHostTextField = makeTextField(TextField.class); + Label serverPortLabel = new Label(GUIStringTool.getServerPortLabel()); + serverPortTextField = makeTextField(TextField.class); - GridPane serverFieldGridPane = new GridPane(); - serverFieldGridPane.add(serverHostLabel,0,0); - serverFieldGridPane.add(serverHostTextField,1,0); - serverFieldGridPane.add(serverPortLabel,0,1); - serverFieldGridPane.add(serverPortTextField,1,1); + GridPane serverFieldGridPane = new GridPane(); + serverFieldGridPane.add(serverHostLabel, 0, 0); + serverFieldGridPane.add(serverHostTextField, 1, 0); + serverFieldGridPane.add(serverPortLabel, 0, 1); + serverFieldGridPane.add(serverPortTextField, 1, 1); - TitledPane serverTitledPane = new TitledPane(GUIStringTool.getServerSectionTitleLabel(),serverFieldGridPane); + TitledPane serverTitledPane = new TitledPane(GUIStringTool.getServerSectionTitleLabel(), serverFieldGridPane); - Label usernameLabel = new Label(GUIStringTool.getUsernameLabel()); - usernameTextField = new TextField(); - Label passwordLabel = new Label(GUIStringTool.getPasswordLabel()); - passwordTextField = new PasswordField(); + Label usernameLabel = new Label(GUIStringTool.getUsernameLabel()); + usernameTextField = makeTextField(TextField.class); + Label passwordLabel = new Label(GUIStringTool.getPasswordLabel()); + passwordTextField = makeTextField(PasswordField.class); - GridPane accountFieldGridPane = new GridPane(); - accountFieldGridPane.add(usernameLabel,0,0); - accountFieldGridPane.add(usernameTextField,1,0); - accountFieldGridPane.add(passwordLabel,0,1); - accountFieldGridPane.add(passwordTextField,1,1); + GridPane accountFieldGridPane = new GridPane(); + accountFieldGridPane.add(usernameLabel, 0, 0); + accountFieldGridPane.add(usernameTextField, 1, 0); + accountFieldGridPane.add(passwordLabel, 0, 1); + accountFieldGridPane.add(passwordTextField, 1, 1); - TitledPane accountTitledPane = new TitledPane(GUIStringTool.getAccountSectionTitleLabel(),accountFieldGridPane); + TitledPane accountTitledPane = new TitledPane(GUIStringTool.getAccountSectionTitleLabel(), accountFieldGridPane); - Button validationButton = new Button(GUIStringTool.getValidationButtonLabel()); - validationButton.setOnAction((event)->{ - ctrl.onValidation(); + validationButton = new Button(GUIStringTool.getValidationButtonLabel()); + validationButton.setOnAction((event) -> { + ctrl.onValidation(); + }); + + mainPane.getChildren().addAll(serverTitledPane, accountTitledPane, validationButton); + }catch(Exception e){ + //TODO Shutdown software on exception + e.printStackTrace(); + } + } + + private T makeTextField(Class clazz) throws IllegalAccessException, InstantiationException { + T ntf = clazz.newInstance(); + ntf.textProperty().addListener((obs, oldVal, newVal)->{ + ctrl.updateView(); }); - - mainPane.getChildren().addAll(serverTitledPane, accountTitledPane, validationButton); + return ntf; } String getServerHostTextFieldContent(){ @@ -78,4 +93,12 @@ public class StartupFrameView implements IFXComponent{ public Pane getPane() { return mainPane; } + + public void setValidationButtonEnable(boolean enable) { + this.validationButton.setDisable(!enable); + } + + public void clearPasswordField() { + passwordTextField.setText(""); + } } diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupProcedureHandler.java b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupProcedureHandler.java index 7471d3cf..b79c9f22 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupProcedureHandler.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupProcedureHandler.java @@ -1,5 +1,7 @@ package com.pqt.client.gui.startup_frame; +import com.pqt.client.gui.startup_frame.listeners.procedure.IStartupProcedureEventFirerer; +import com.pqt.client.gui.startup_frame.listeners.procedure.IStartupProcedureListener; import com.pqt.client.module.account.AccountService; import com.pqt.client.module.account.listeners.AccountListenerAdapter; import com.pqt.client.module.account.listeners.IAccountListener; @@ -15,6 +17,8 @@ class StartupProcedureHandler { private String host, username, password; private Integer port; + private IStartupProcedureEventFirerer firerer; + StartupProcedureHandler(NetworkService networkService, AccountService accountService) { this.networkService = networkService; this.accountService = accountService; @@ -39,7 +43,8 @@ class StartupProcedureHandler { } private void useRequestedServer(){ - //TODO notify this + //Server found + firerer.fireServerFoundEvent(host, port); networkService.setActiveServer(host, port); accountService.addListener(getUpdateAccountListListener()); accountService.refreshAccounts(); @@ -52,7 +57,8 @@ class StartupProcedureHandler { .orElse(null); if(match==null){ - //TODO notify this + //Compte spécifié inconnu + firerer.fireUserAccountUnknownEvent(username); }else{ accountService.setCurrentAccount(match); accountService.addListener(getConnectAccountListener()); @@ -96,11 +102,23 @@ class StartupProcedureHandler { @Override public void onAccountStatusChangedEvent(boolean status) { if(status){ - //TODO notify this + //Compte connecté + firerer.fireUserAccountConnectedEvent(username); }else{ - //TODO notify this + //Compte non-connecté + firerer.fireUserAccountDisconnectedEvent(username); } } }; } + + public StartupProcedureHandler addListener(IStartupProcedureListener l){ + firerer.addListener(l); + return this; + } + + public StartupProcedureHandler removeListener(IStartupProcedureListener l){ + firerer.removeListener(l); + return this; + } } diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/frame/IStartupFrameModelEventFirerer.java b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/frame/IStartupFrameModelEventFirerer.java new file mode 100644 index 00000000..877df58f --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/frame/IStartupFrameModelEventFirerer.java @@ -0,0 +1,8 @@ +package com.pqt.client.gui.startup_frame.listeners.frame; + +public interface IStartupFrameModelEventFirerer { + void fireStartupValidated(); + + void addListener(IStartupFrameModelListener l); + void removeListener(IStartupFrameModelListener l); +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/IStartupFrameModelListener.java b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/frame/IStartupFrameModelListener.java similarity index 53% rename from Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/IStartupFrameModelListener.java rename to Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/frame/IStartupFrameModelListener.java index 154cfe07..5249ede1 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/IStartupFrameModelListener.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/frame/IStartupFrameModelListener.java @@ -1,6 +1,7 @@ -package com.pqt.client.gui.startup_frame.listeners; +package com.pqt.client.gui.startup_frame.listeners.frame; import java.util.EventListener; public interface IStartupFrameModelListener extends EventListener { + void onStartupValidated(); } diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/frame/SimpleStartupFrameModelEventFirerer.java b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/frame/SimpleStartupFrameModelEventFirerer.java new file mode 100644 index 00000000..1ada34ae --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/frame/SimpleStartupFrameModelEventFirerer.java @@ -0,0 +1,29 @@ +package com.pqt.client.gui.startup_frame.listeners.frame; + +import javax.swing.event.EventListenerList; +import java.util.Arrays; + +public class SimpleStartupFrameModelEventFirerer implements IStartupFrameModelEventFirerer { + + private final EventListenerList listenerList; + + public SimpleStartupFrameModelEventFirerer() { + this.listenerList = new EventListenerList(); + } + + @Override + public void fireStartupValidated() { + Arrays.stream(listenerList.getListeners(IStartupFrameModelListener.class)) + .forEach(IStartupFrameModelListener::onStartupValidated); + } + + @Override + public void addListener(IStartupFrameModelListener l) { + listenerList.add(IStartupFrameModelListener.class, l); + } + + @Override + public void removeListener(IStartupFrameModelListener l) { + listenerList.remove(IStartupFrameModelListener.class, l); + } +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/procedure/IStartupProcedureEventFirerer.java b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/procedure/IStartupProcedureEventFirerer.java new file mode 100644 index 00000000..e06829c7 --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/procedure/IStartupProcedureEventFirerer.java @@ -0,0 +1,12 @@ +package com.pqt.client.gui.startup_frame.listeners.procedure; + +public interface IStartupProcedureEventFirerer { + + void fireServerFoundEvent(String URL, Integer Port); + void fireUserAccountUnknownEvent(String username); + void fireUserAccountConnectedEvent(String username); + void fireUserAccountDisconnectedEvent(String username); + + void addListener(IStartupProcedureListener l ); + void removeListener(IStartupProcedureListener l ); +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/procedure/IStartupProcedureListener.java b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/procedure/IStartupProcedureListener.java new file mode 100644 index 00000000..cdf6f189 --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/procedure/IStartupProcedureListener.java @@ -0,0 +1,11 @@ +package com.pqt.client.gui.startup_frame.listeners.procedure; + +import java.util.EventListener; + +public interface IStartupProcedureListener extends EventListener{ + + void onServerFoundEvent(String URL, Integer Port); + void onUserAccountUnknownEvent(String username); + void onUserAccountConnectedEvent(String username); + void onUserAccountDisconnectedEvent(String username); +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/procedure/SimpleStartupProcedureEventFirerer.java b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/procedure/SimpleStartupProcedureEventFirerer.java new file mode 100644 index 00000000..f0cef5cb --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/listeners/procedure/SimpleStartupProcedureEventFirerer.java @@ -0,0 +1,47 @@ +package com.pqt.client.gui.startup_frame.listeners.procedure; + +import javax.swing.event.EventListenerList; +import java.util.Arrays; + +public class SimpleStartupProcedureEventFirerer implements IStartupProcedureEventFirerer { + + private final EventListenerList listenerList; + + public SimpleStartupProcedureEventFirerer() { + this.listenerList = new EventListenerList(); + } + + @Override + public void fireServerFoundEvent(String URL, Integer port) { + Arrays.stream(listenerList.getListeners(IStartupProcedureListener.class)) + .forEach(l->l.onServerFoundEvent(URL, port)); + } + + @Override + public void fireUserAccountUnknownEvent(String username) { + Arrays.stream(listenerList.getListeners(IStartupProcedureListener.class)) + .forEach(l->l.onUserAccountUnknownEvent(username)); + } + + @Override + public void fireUserAccountConnectedEvent(String username) { + Arrays.stream(listenerList.getListeners(IStartupProcedureListener.class)) + .forEach(l->l.onUserAccountConnectedEvent(username)); + } + + @Override + public void fireUserAccountDisconnectedEvent(String username) { + Arrays.stream(listenerList.getListeners(IStartupProcedureListener.class)) + .forEach(l->l.onUserAccountDisconnectedEvent(username)); + } + + @Override + public void addListener(IStartupProcedureListener l) { + listenerList.add(IStartupProcedureListener.class, l); + } + + @Override + public void removeListener(IStartupProcedureListener l) { + listenerList.remove(IStartupProcedureListener.class, l); + } +} diff --git a/Workspace/client/src/main/java/com/pqt/client/module/ClientBackEndModuleManager.java b/Workspace/client/src/main/java/com/pqt/client/module/ClientBackEndModuleManager.java index c2666208..d7c12a3b 100644 --- a/Workspace/client/src/main/java/com/pqt/client/module/ClientBackEndModuleManager.java +++ b/Workspace/client/src/main/java/com/pqt/client/module/ClientBackEndModuleManager.java @@ -23,7 +23,7 @@ public class ClientBackEndModuleManager { stockService = new StockService(queryExecutor); accountService = new AccountService(queryExecutor); statService = new StatService(queryExecutor); - networkService = new NetworkService(queryExecutor); + networkService = new NetworkService(queryExecutor, connectionService); } public SaleService getSaleService() {