mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2024-11-22 08:13:20 +00:00
Module Client : ajout code transition frames startup<->main; bouton connexion désormais grisé si saisie insuffisante(startup frame); Afficheur de compte désormais à un seul état (uniquement connecté); Suppression du composant graphique AccountManager (inutile);
This commit is contained in:
parent
82c6a6684c
commit
a62d7e0cc5
@ -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.main_frame.listeners.IMainFrameModelListener;
|
||||||
import com.pqt.client.gui.modules.account_screen.AccountScreen;
|
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;
|
||||||
@ -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.css.GUICssTool;
|
||||||
import com.pqt.client.gui.ressources.strings.GUIStringTool;
|
import com.pqt.client.gui.ressources.strings.GUIStringTool;
|
||||||
import com.pqt.client.gui.startup_frame.StartupFrame;
|
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 com.pqt.client.module.ClientBackEndModuleManager;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
public class Main extends Application{
|
public class Main extends Application{
|
||||||
@ -22,24 +26,53 @@ public class Main extends Application{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) throws Exception {
|
||||||
//TODO ajouter écran de préloading : StartupFrame
|
|
||||||
|
|
||||||
ClientBackEndModuleManager moduleManager = new ClientBackEndModuleManager(null);
|
ClientBackEndModuleManager moduleManager = new ClientBackEndModuleManager(null);
|
||||||
|
|
||||||
|
|
||||||
MainFrame mainFrame = new MainFrame(moduleManager.getAccountService());
|
MainFrame mainFrame = new MainFrame(moduleManager.getAccountService());
|
||||||
mainFrame.addModule(new SaleScreen(moduleManager.getAccountService(), moduleManager.getStockService(), moduleManager.getSaleService()), true);
|
mainFrame.addModule(new SaleScreen(moduleManager.getAccountService(), moduleManager.getStockService(), moduleManager.getSaleService()), true);
|
||||||
mainFrame.addModule(new StockScreen(moduleManager.getStockService(), moduleManager.getAccountService()));
|
mainFrame.addModule(new StockScreen(moduleManager.getStockService(), moduleManager.getAccountService()));
|
||||||
mainFrame.addModule(new StatScreen(moduleManager.getStatService()));
|
mainFrame.addModule(new StatScreen(moduleManager.getStatService()));
|
||||||
mainFrame.addModule(new AccountScreen(moduleManager.getAccountService()));
|
mainFrame.addModule(new AccountScreen(moduleManager.getAccountService()));
|
||||||
|
Scene mainFrameScene = initScene(mainFrame.getPane());
|
||||||
|
|
||||||
StartupFrame startupFrame = new StartupFrame(moduleManager.getAccountService(), moduleManager.getNetworkService());
|
StartupFrame startupFrame = new StartupFrame(moduleManager.getAccountService(), moduleManager.getNetworkService());
|
||||||
Scene scene = new Scene(startupFrame.getPane());
|
Scene startupFrameScene = initScene(startupFrame.getPane());
|
||||||
scene.getStylesheets().clear();
|
|
||||||
scene.getStylesheets().addAll(getClass().getResource(GUICssTool.getCssFilePath()).toExternalForm());
|
mainFrame.addFrameModelListener(getMainFrameListener(primaryStage, startupFrameScene));
|
||||||
|
startupFrame.addFrameModelListener(getStartupFrameListener(primaryStage, mainFrameScene));
|
||||||
|
|
||||||
ToastFactory.init(primaryStage);
|
ToastFactory.init(primaryStage);
|
||||||
primaryStage.setTitle(GUIStringTool.getAppTitle());
|
primaryStage.setTitle(GUIStringTool.getAppTitle());
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(startupFrameScene);
|
||||||
primaryStage.show();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.pqt.client.gui.main_frame;
|
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.modules.IGuiModule;
|
||||||
import com.pqt.client.gui.ressources.components.generics.IFXComponent;
|
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.account.AccountService;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
|
|
||||||
@ -9,9 +11,10 @@ public class MainFrame implements IFXComponent {
|
|||||||
|
|
||||||
private MainFrameView view;
|
private MainFrameView view;
|
||||||
private MainFrameController ctrl;
|
private MainFrameController ctrl;
|
||||||
|
private MainFrameModel model;
|
||||||
|
|
||||||
public MainFrame(AccountService accountService) {
|
public MainFrame(AccountService accountService) {
|
||||||
MainFrameModel model = new MainFrameModel(accountService);
|
model = new MainFrameModel(accountService);
|
||||||
ctrl = new MainFrameController(model);
|
ctrl = new MainFrameController(model);
|
||||||
model.addListener(ctrl);
|
model.addListener(ctrl);
|
||||||
|
|
||||||
@ -28,6 +31,10 @@ public class MainFrame implements IFXComponent {
|
|||||||
ctrl.addModule(module, false);
|
ctrl.addModule(module, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addFrameModelListener(IMainFrameModelListener l){
|
||||||
|
model.addListener(l);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pane getPane() {
|
public Pane getPane() {
|
||||||
return view.getPane();
|
return view.getPane();
|
||||||
|
@ -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.main_frame.listeners.IMainFrameModelListener;
|
||||||
import com.pqt.client.gui.modules.IGuiModule;
|
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 com.pqt.core.entities.user_account.AccountLevel;
|
||||||
import javafx.event.Event;
|
|
||||||
|
|
||||||
class MainFrameController implements IMainFrameModelListener {
|
class MainFrameController implements IMainFrameModelListener {
|
||||||
|
|
||||||
private MainFrameModel model;
|
private MainFrameModel model;
|
||||||
private MainFrameView view;
|
private MainFrameView view;
|
||||||
private IValidatorComponentListener accountManagerAccountListener;
|
|
||||||
|
|
||||||
MainFrameController(MainFrameModel model) {
|
MainFrameController(MainFrameModel model) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
@ -23,7 +18,6 @@ class MainFrameController implements IMainFrameModelListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateView(){
|
void updateView(){
|
||||||
view.feedAccountCollectionToManager(model.getAccounts());
|
|
||||||
view.setCurrentAccount(model.getCurrentAccount());
|
view.setCurrentAccount(model.getCurrentAccount());
|
||||||
if(model.getCurrentAccount()!=null)
|
if(model.getCurrentAccount()!=null)
|
||||||
view.updateModuleButtonLock(model.getCurrentAccount().getPermissionLevel());
|
view.updateModuleButtonLock(model.getCurrentAccount().getPermissionLevel());
|
||||||
@ -38,57 +32,12 @@ class MainFrameController implements IMainFrameModelListener {
|
|||||||
this.view.addGuiModule(module.getModuleName(),module.getPane(), module.getLowestRequiredAccountLevel(), activate);
|
this.view.addGuiModule(module.getModuleName(),module.getPane(), module.getLowestRequiredAccountLevel(), activate);
|
||||||
}
|
}
|
||||||
|
|
||||||
IValidatorComponentListener getAccountManagerValidatorListener() {
|
public void onAccountDisconnectionRequested() {
|
||||||
return new IValidatorComponentListener() {
|
|
||||||
@Override
|
|
||||||
public void onValidationEvent() {
|
|
||||||
if(view.isAccountCreationPossible())
|
|
||||||
model.connectAccount(view.create());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCancelEvent() {
|
|
||||||
model.disconnectCurrentAccount();
|
model.disconnectCurrentAccount();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
IAccountComponentListener getAccountManagerAccountListener() {
|
|
||||||
return new IAccountComponentListener() {
|
|
||||||
@Override
|
|
||||||
public void onRefreshContentRequestEvent() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onContentClickEvent(Event event, Account eventTarget) {
|
public void onAccountDisconnectedEvent() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAddContentRequestEvent() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRemoveContentRequestEvent(Account content) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDetailContentRequestEvent(Account content) {
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAccountStatusChangedEvent(boolean status) {
|
|
||||||
updateView();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAccountCollectionChangedEvent() {
|
|
||||||
updateView();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,9 @@ class MainFrameModel {
|
|||||||
this.accountService.addListener(new IAccountListener() {
|
this.accountService.addListener(new IAccountListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onAccountStatusChangedEvent(boolean status) {
|
public void onAccountStatusChangedEvent(boolean status) {
|
||||||
MainFrameModel.this.fireAccountStatusChangedEvent(status);
|
if(!status){
|
||||||
|
MainFrameModel.this.fireAccountDisconnectedEvent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -30,30 +32,20 @@ class MainFrameModel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAccountListChangedEvent() {
|
public void onAccountListChangedEvent() {
|
||||||
MainFrameModel.this.fireAccountCollectionChangedEvent();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireAccountCollectionChangedEvent() {
|
private void fireAccountDisconnectedEvent() {
|
||||||
Arrays.stream(listenerList.getListeners(IMainFrameModelListener.class)).forEach(IMainFrameModelListener::onAccountCollectionChangedEvent);
|
Arrays.stream(listenerList.getListeners(IMainFrameModelListener.class)).forEach(IMainFrameModelListener::onAccountDisconnectedEvent);
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void disconnectCurrentAccount() {
|
void disconnectCurrentAccount() {
|
||||||
|
fireAccountDisconnectedEvent();
|
||||||
|
//TODO uncomment code when test are to be done
|
||||||
|
/*
|
||||||
accountService.logOutCurrentAccount();
|
accountService.logOutCurrentAccount();
|
||||||
}
|
*/
|
||||||
|
|
||||||
Collection<Account> getAccounts(){
|
|
||||||
return accountService.getAllAccounts();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void addListener(IMainFrameModelListener listener){
|
void addListener(IMainFrameModelListener listener){
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.pqt.client.gui.main_frame;
|
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.IFXComponent;
|
||||||
import com.pqt.client.gui.ressources.components.generics.others.SideBar;
|
import com.pqt.client.gui.ressources.components.generics.others.SideBar;
|
||||||
import com.pqt.client.gui.ressources.components.generics.others.listeners.ISideBarListener;
|
import com.pqt.client.gui.ressources.components.generics.others.listeners.ISideBarListener;
|
||||||
@ -10,11 +9,9 @@ import com.pqt.core.entities.user_account.AccountLevel;
|
|||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.property.ObjectProperty;
|
import javafx.beans.property.ObjectProperty;
|
||||||
import javafx.beans.property.SimpleObjectProperty;
|
import javafx.beans.property.SimpleObjectProperty;
|
||||||
import javafx.beans.value.ObservableValue;
|
|
||||||
import javafx.geometry.Orientation;
|
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.ToolBar;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.input.MouseButton;
|
import javafx.scene.input.MouseButton;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
@ -22,16 +19,14 @@ import javafx.scene.layout.Pane;
|
|||||||
import javafx.scene.layout.Priority;
|
import javafx.scene.layout.Priority;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
class MainFrameView implements IFXComponent{
|
class MainFrameView implements IFXComponent{
|
||||||
|
|
||||||
private final MainFrameController ctrl;
|
private final MainFrameController ctrl;
|
||||||
|
|
||||||
private BorderPane mainPane;
|
private BorderPane mainPane;
|
||||||
private AccountManager accountManager;
|
|
||||||
private VBox buttonHolder;
|
private VBox buttonHolder;
|
||||||
private ObjectProperty<AccountLevel> currentAccountLevel;
|
private ObjectProperty<AccountLevel> currentAccountLevel;
|
||||||
|
private Label accountNameLabel;
|
||||||
|
|
||||||
MainFrameView(MainFrameController ctrl) {
|
MainFrameView(MainFrameController ctrl) {
|
||||||
this.ctrl = ctrl;
|
this.ctrl = ctrl;
|
||||||
@ -51,11 +46,10 @@ class MainFrameView implements IFXComponent{
|
|||||||
buttonHolder.prefWidthProperty().bind(sidebar.widthProperty());
|
buttonHolder.prefWidthProperty().bind(sidebar.widthProperty());
|
||||||
sidebar.getChildren().add(buttonHolder);
|
sidebar.getChildren().add(buttonHolder);
|
||||||
|
|
||||||
accountManager = new AccountManager();
|
accountNameLabel = new Label();
|
||||||
accountManager.addListener(ctrl.getAccountManagerValidatorListener());
|
Button disconnectionButton = new Button(GUIStringTool.getLogoutButtonLabel());
|
||||||
accountManager.addListener(ctrl.getAccountManagerAccountListener());
|
disconnectionButton.setOnAction((event -> ctrl.onAccountDisconnectionRequested()));
|
||||||
accountManager.getPane().prefWidthProperty().bind(sidebar.widthProperty());
|
sidebar.getChildren().addAll(accountNameLabel, disconnectionButton);
|
||||||
sidebar.getChildren().add(accountManager.getPane());
|
|
||||||
|
|
||||||
mainPane.setLeft(sidebar);
|
mainPane.setLeft(sidebar);
|
||||||
|
|
||||||
@ -120,20 +114,8 @@ class MainFrameView implements IFXComponent{
|
|||||||
buttonHolder.getChildren().add(button);
|
buttonHolder.getChildren().add(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isAccountCreationPossible(){
|
|
||||||
return accountManager.isCreationPossible();
|
|
||||||
}
|
|
||||||
|
|
||||||
Account create(){
|
|
||||||
return accountManager.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setCurrentAccount(Account account){
|
void setCurrentAccount(Account account){
|
||||||
accountManager.setCurrentAccount(account);
|
accountNameLabel.setText(GUIStringTool.getAccountStringConverter().toString(account));
|
||||||
}
|
|
||||||
|
|
||||||
void feedAccountCollectionToManager(Collection<Account> accounts){
|
|
||||||
accountManager.display(accounts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateModuleButtonLock(AccountLevel level) {
|
void updateModuleButtonLock(AccountLevel level) {
|
||||||
|
@ -3,6 +3,5 @@ package com.pqt.client.gui.main_frame.listeners;
|
|||||||
import java.util.EventListener;
|
import java.util.EventListener;
|
||||||
|
|
||||||
public interface IMainFrameModelListener extends EventListener{
|
public interface IMainFrameModelListener extends EventListener{
|
||||||
void onAccountStatusChangedEvent(boolean status);
|
void onAccountDisconnectedEvent();
|
||||||
void onAccountCollectionChangedEvent();
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import javafx.scene.layout.Pane;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
//TODO à faire
|
|
||||||
public class AccountManagerScreen implements IFXValidatorComponent, IFXCreatorComponent<Account>{
|
public class AccountManagerScreen implements IFXValidatorComponent, IFXCreatorComponent<Account>{
|
||||||
|
|
||||||
private AccountManagerScreenModel model;
|
private AccountManagerScreenModel model;
|
||||||
|
@ -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<Account> {
|
|
||||||
|
|
||||||
private Pane mainPane;
|
|
||||||
|
|
||||||
private VBox mainDisconnectedPane, mainConnectedPane;
|
|
||||||
private TextField connectedUsernameField;
|
|
||||||
private ChoiceBox<Account> 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<Account> 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();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<Collection<Account>, IAccountComponentListener> {
|
|
||||||
|
|
||||||
}
|
|
@ -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<Account>{
|
|
||||||
}
|
|
@ -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<Account, IAccountComponentListener> {
|
|
||||||
public SimpleAccountComponentFirerer() {
|
|
||||||
super(IAccountComponentListener.class);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,7 @@
|
|||||||
package com.pqt.client.gui.startup_frame;
|
package com.pqt.client.gui.startup_frame;
|
||||||
|
|
||||||
import com.pqt.client.gui.ressources.components.generics.IFXComponent;
|
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.account.AccountService;
|
||||||
import com.pqt.client.module.network.NetworkService;
|
import com.pqt.client.module.network.NetworkService;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
@ -8,11 +9,11 @@ import javafx.scene.layout.Pane;
|
|||||||
public class StartupFrame implements IFXComponent{
|
public class StartupFrame implements IFXComponent{
|
||||||
|
|
||||||
private StartupFrameView view;
|
private StartupFrameView view;
|
||||||
private StartupFrameController ctrl;
|
private StartupFrameModel model;
|
||||||
|
|
||||||
public StartupFrame(AccountService accountService, NetworkService networkService) {
|
public StartupFrame(AccountService accountService, NetworkService networkService) {
|
||||||
StartupFrameModel model = new StartupFrameModel(accountService, networkService);
|
model = new StartupFrameModel(accountService, networkService);
|
||||||
ctrl = new StartupFrameController(model);
|
StartupFrameController ctrl = new StartupFrameController(model);
|
||||||
model.addListener(ctrl);
|
model.addListener(ctrl);
|
||||||
|
|
||||||
view = new StartupFrameView(ctrl);
|
view = new StartupFrameView(ctrl);
|
||||||
@ -20,6 +21,10 @@ public class StartupFrame implements IFXComponent{
|
|||||||
ctrl.updateView();
|
ctrl.updateView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addFrameModelListener(IStartupFrameModelListener l){
|
||||||
|
model.addListener(l);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pane getPane() {
|
public Pane getPane() {
|
||||||
return view.getPane();
|
return view.getPane();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.pqt.client.gui.startup_frame;
|
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 {
|
public class StartupFrameController implements IStartupFrameModelListener {
|
||||||
|
|
||||||
@ -16,7 +16,13 @@ public class StartupFrameController implements IStartupFrameModelListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateView() {
|
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() {
|
public void onValidation() {
|
||||||
@ -31,4 +37,9 @@ public class StartupFrameController implements IStartupFrameModelListener {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartupValidated() {
|
||||||
|
view.clearPasswordField();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,29 @@
|
|||||||
package com.pqt.client.gui.startup_frame;
|
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.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.NetworkService;
|
||||||
import com.pqt.client.module.network.listeners.INetworkServiceListener;
|
|
||||||
|
|
||||||
import javax.swing.event.EventListenerList;
|
|
||||||
|
|
||||||
public class StartupFrameModel {
|
public class StartupFrameModel {
|
||||||
|
|
||||||
private final AccountService accountService;
|
private final AccountService accountService;
|
||||||
private final NetworkService networkService;
|
private final NetworkService networkService;
|
||||||
private final EventListenerList listenerList;
|
private final IStartupFrameModelEventFirerer firerer;
|
||||||
|
|
||||||
private boolean startupProcessBegan;
|
private boolean startupProcessBegan;
|
||||||
|
|
||||||
public StartupFrameModel(AccountService accountService, NetworkService networkService) {
|
public StartupFrameModel(AccountService accountService, NetworkService networkService) {
|
||||||
this.accountService = accountService;
|
this.accountService = accountService;
|
||||||
this.networkService = networkService;
|
this.networkService = networkService;
|
||||||
this.listenerList = new EventListenerList();
|
firerer = new SimpleStartupFrameModelEventFirerer();
|
||||||
startupProcessBegan = false;
|
startupProcessBegan = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addListener(IStartupFrameModelListener ctrl) {
|
public void addListener(IStartupFrameModelListener ctrl) {
|
||||||
listenerList.add(IStartupFrameModelListener.class, ctrl);
|
firerer.addListener(ctrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isStartupProcessRunning() {
|
public boolean isStartupProcessRunning() {
|
||||||
@ -33,6 +31,9 @@ public class StartupFrameModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void beginStartupProcess(String requiredHost, String requiredPort, String username, String password) {
|
public void beginStartupProcess(String requiredHost, String requiredPort, String username, String password) {
|
||||||
|
//TODO uncomment code when test are to be done
|
||||||
|
firerer.fireStartupValidated();
|
||||||
|
/*
|
||||||
if(!startupProcessBegan){
|
if(!startupProcessBegan){
|
||||||
checkParameters(requiredHost, requiredPort, username, password);
|
checkParameters(requiredHost, requiredPort, username, password);
|
||||||
startupProcessBegan = true;
|
startupProcessBegan = true;
|
||||||
@ -41,8 +42,30 @@ public class StartupFrameModel {
|
|||||||
|
|
||||||
new StartupProcedureHandler(networkService, accountService)
|
new StartupProcedureHandler(networkService, accountService)
|
||||||
.init(requiredHost, requiredIntPort, username, password)
|
.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();
|
.handle();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkParameters(String host, String port, String username, String password) {
|
private void checkParameters(String host, String port, String username, String password) {
|
||||||
|
@ -15,18 +15,21 @@ public class StartupFrameView implements IFXComponent{
|
|||||||
private TextField usernameTextField;
|
private TextField usernameTextField;
|
||||||
private TextField passwordTextField;
|
private TextField passwordTextField;
|
||||||
|
|
||||||
|
private Button validationButton;
|
||||||
|
|
||||||
public StartupFrameView(StartupFrameController ctrl) {
|
public StartupFrameView(StartupFrameController ctrl) {
|
||||||
this.ctrl = ctrl;
|
this.ctrl = ctrl;
|
||||||
initGui();
|
initGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initGui() {
|
private void initGui() {
|
||||||
|
try {
|
||||||
mainPane = new VBox();
|
mainPane = new VBox();
|
||||||
|
|
||||||
Label serverHostLabel = new Label(GUIStringTool.getServerHostLabel());
|
Label serverHostLabel = new Label(GUIStringTool.getServerHostLabel());
|
||||||
serverHostTextField = new TextField();
|
serverHostTextField = makeTextField(TextField.class);
|
||||||
Label serverPortLabel = new Label(GUIStringTool.getServerPortLabel());
|
Label serverPortLabel = new Label(GUIStringTool.getServerPortLabel());
|
||||||
serverPortTextField = new TextField();
|
serverPortTextField = makeTextField(TextField.class);
|
||||||
|
|
||||||
GridPane serverFieldGridPane = new GridPane();
|
GridPane serverFieldGridPane = new GridPane();
|
||||||
serverFieldGridPane.add(serverHostLabel, 0, 0);
|
serverFieldGridPane.add(serverHostLabel, 0, 0);
|
||||||
@ -38,9 +41,9 @@ public class StartupFrameView implements IFXComponent{
|
|||||||
|
|
||||||
|
|
||||||
Label usernameLabel = new Label(GUIStringTool.getUsernameLabel());
|
Label usernameLabel = new Label(GUIStringTool.getUsernameLabel());
|
||||||
usernameTextField = new TextField();
|
usernameTextField = makeTextField(TextField.class);
|
||||||
Label passwordLabel = new Label(GUIStringTool.getPasswordLabel());
|
Label passwordLabel = new Label(GUIStringTool.getPasswordLabel());
|
||||||
passwordTextField = new PasswordField();
|
passwordTextField = makeTextField(PasswordField.class);
|
||||||
|
|
||||||
GridPane accountFieldGridPane = new GridPane();
|
GridPane accountFieldGridPane = new GridPane();
|
||||||
accountFieldGridPane.add(usernameLabel, 0, 0);
|
accountFieldGridPane.add(usernameLabel, 0, 0);
|
||||||
@ -50,12 +53,24 @@ public class StartupFrameView implements IFXComponent{
|
|||||||
|
|
||||||
TitledPane accountTitledPane = new TitledPane(GUIStringTool.getAccountSectionTitleLabel(), accountFieldGridPane);
|
TitledPane accountTitledPane = new TitledPane(GUIStringTool.getAccountSectionTitleLabel(), accountFieldGridPane);
|
||||||
|
|
||||||
Button validationButton = new Button(GUIStringTool.getValidationButtonLabel());
|
validationButton = new Button(GUIStringTool.getValidationButtonLabel());
|
||||||
validationButton.setOnAction((event) -> {
|
validationButton.setOnAction((event) -> {
|
||||||
ctrl.onValidation();
|
ctrl.onValidation();
|
||||||
});
|
});
|
||||||
|
|
||||||
mainPane.getChildren().addAll(serverTitledPane, accountTitledPane, validationButton);
|
mainPane.getChildren().addAll(serverTitledPane, accountTitledPane, validationButton);
|
||||||
|
}catch(Exception e){
|
||||||
|
//TODO Shutdown software on exception
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T extends TextField> T makeTextField(Class<T> clazz) throws IllegalAccessException, InstantiationException {
|
||||||
|
T ntf = clazz.newInstance();
|
||||||
|
ntf.textProperty().addListener((obs, oldVal, newVal)->{
|
||||||
|
ctrl.updateView();
|
||||||
|
});
|
||||||
|
return ntf;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getServerHostTextFieldContent(){
|
String getServerHostTextFieldContent(){
|
||||||
@ -78,4 +93,12 @@ public class StartupFrameView implements IFXComponent{
|
|||||||
public Pane getPane() {
|
public Pane getPane() {
|
||||||
return mainPane;
|
return mainPane;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setValidationButtonEnable(boolean enable) {
|
||||||
|
this.validationButton.setDisable(!enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearPasswordField() {
|
||||||
|
passwordTextField.setText("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.pqt.client.gui.startup_frame;
|
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.AccountService;
|
||||||
import com.pqt.client.module.account.listeners.AccountListenerAdapter;
|
import com.pqt.client.module.account.listeners.AccountListenerAdapter;
|
||||||
import com.pqt.client.module.account.listeners.IAccountListener;
|
import com.pqt.client.module.account.listeners.IAccountListener;
|
||||||
@ -15,6 +17,8 @@ class StartupProcedureHandler {
|
|||||||
private String host, username, password;
|
private String host, username, password;
|
||||||
private Integer port;
|
private Integer port;
|
||||||
|
|
||||||
|
private IStartupProcedureEventFirerer firerer;
|
||||||
|
|
||||||
StartupProcedureHandler(NetworkService networkService, AccountService accountService) {
|
StartupProcedureHandler(NetworkService networkService, AccountService accountService) {
|
||||||
this.networkService = networkService;
|
this.networkService = networkService;
|
||||||
this.accountService = accountService;
|
this.accountService = accountService;
|
||||||
@ -39,7 +43,8 @@ class StartupProcedureHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void useRequestedServer(){
|
private void useRequestedServer(){
|
||||||
//TODO notify this
|
//Server found
|
||||||
|
firerer.fireServerFoundEvent(host, port);
|
||||||
networkService.setActiveServer(host, port);
|
networkService.setActiveServer(host, port);
|
||||||
accountService.addListener(getUpdateAccountListListener());
|
accountService.addListener(getUpdateAccountListListener());
|
||||||
accountService.refreshAccounts();
|
accountService.refreshAccounts();
|
||||||
@ -52,7 +57,8 @@ class StartupProcedureHandler {
|
|||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
|
||||||
if(match==null){
|
if(match==null){
|
||||||
//TODO notify this
|
//Compte spécifié inconnu
|
||||||
|
firerer.fireUserAccountUnknownEvent(username);
|
||||||
}else{
|
}else{
|
||||||
accountService.setCurrentAccount(match);
|
accountService.setCurrentAccount(match);
|
||||||
accountService.addListener(getConnectAccountListener());
|
accountService.addListener(getConnectAccountListener());
|
||||||
@ -96,11 +102,23 @@ class StartupProcedureHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void onAccountStatusChangedEvent(boolean status) {
|
public void onAccountStatusChangedEvent(boolean status) {
|
||||||
if(status){
|
if(status){
|
||||||
//TODO notify this
|
//Compte connecté
|
||||||
|
firerer.fireUserAccountConnectedEvent(username);
|
||||||
}else{
|
}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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
@ -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;
|
import java.util.EventListener;
|
||||||
|
|
||||||
public interface IStartupFrameModelListener extends EventListener {
|
public interface IStartupFrameModelListener extends EventListener {
|
||||||
|
void onStartupValidated();
|
||||||
}
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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 );
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -23,7 +23,7 @@ public class ClientBackEndModuleManager {
|
|||||||
stockService = new StockService(queryExecutor);
|
stockService = new StockService(queryExecutor);
|
||||||
accountService = new AccountService(queryExecutor);
|
accountService = new AccountService(queryExecutor);
|
||||||
statService = new StatService(queryExecutor);
|
statService = new StatService(queryExecutor);
|
||||||
networkService = new NetworkService(queryExecutor);
|
networkService = new NetworkService(queryExecutor, connectionService);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SaleService getSaleService() {
|
public SaleService getSaleService() {
|
||||||
|
Loading…
Reference in New Issue
Block a user