mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2024-11-22 00:03:20 +00:00
Module Client, écran StartupFrame : ajout GUI + portion du code métier
This commit is contained in:
parent
20ac907c73
commit
0ed6d78cac
@ -331,6 +331,22 @@ public class GUIStringTool {
|
||||
public static String getAccountLevelColumnHeaderLabel() {
|
||||
return "Niveau d'accréditation";
|
||||
}
|
||||
|
||||
public static String getServerSectionTitleLabel() {
|
||||
return "Serveur";
|
||||
}
|
||||
|
||||
public static String getAccountSectionTitleLabel() {
|
||||
return "Compte";
|
||||
}
|
||||
|
||||
public static String getServerHostLabel() {
|
||||
return "Host : ";
|
||||
}
|
||||
|
||||
public static String getServerPortLabel() {
|
||||
return "Port : ";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,7 +21,7 @@ public class StartupFrame implements IFXComponent{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pane getMainPane() {
|
||||
return view.getMainPane();
|
||||
public Pane getPane() {
|
||||
return view.getPane();
|
||||
}
|
||||
}
|
||||
|
@ -18,4 +18,17 @@ public class StartupFrameController implements IStartupFrameModelListener {
|
||||
public void updateView() {
|
||||
//TODO écrire corps méthd StartupFrameController.updateView()
|
||||
}
|
||||
|
||||
public void onValidation() {
|
||||
if(!model.isStartupProcessRunning()){
|
||||
//TODO catch following exceptions and update GUI when needed :
|
||||
//NullPointerException && IllegalArgumentException
|
||||
model.beginStartupProcess(
|
||||
view.getServerHostTextFieldContent(),
|
||||
view.getServerPortTextFieldContent(),
|
||||
view.getAccountUsernameTextFieldContent(),
|
||||
view.getAccountPasswordTextFieldContent()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,10 @@ package com.pqt.client.gui.startup_frame;
|
||||
|
||||
import com.pqt.client.gui.startup_frame.listeners.IStartupFrameModelListener;
|
||||
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;
|
||||
|
||||
@ -12,13 +15,44 @@ public class StartupFrameModel {
|
||||
private final NetworkService networkService;
|
||||
private final EventListenerList listenerList;
|
||||
|
||||
private boolean startupProcessBegan;
|
||||
|
||||
public StartupFrameModel(AccountService accountService, NetworkService networkService) {
|
||||
this.accountService = accountService;
|
||||
this.networkService = networkService;
|
||||
this.listenerList = new EventListenerList();
|
||||
startupProcessBegan = false;
|
||||
}
|
||||
|
||||
public void addListener(IStartupFrameModelListener ctrl) {
|
||||
listenerList.add(IStartupFrameModelListener.class, ctrl);
|
||||
}
|
||||
|
||||
public boolean isStartupProcessRunning() {
|
||||
return startupProcessBegan;
|
||||
}
|
||||
|
||||
public void beginStartupProcess(String requiredHost, String requiredPort, String username, String password) {
|
||||
if(!startupProcessBegan){
|
||||
checkParameters(requiredHost, requiredPort, username, password);
|
||||
startupProcessBegan = true;
|
||||
|
||||
Integer requiredIntPort = Integer.parseInt(requiredPort);
|
||||
|
||||
new StartupProcedureHandler(networkService, accountService)
|
||||
.init(requiredHost, requiredIntPort, username, password)
|
||||
.handle();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkParameters(String host, String port, String username, String password) {
|
||||
if(host==null || port == null || username == null || password == null)
|
||||
throw new NullPointerException("Null parameters are not allowed on startup");
|
||||
|
||||
if(username.isEmpty() || host.isEmpty() || port.isEmpty())
|
||||
throw new IllegalArgumentException("The following parameters must be filled : host, port, username");
|
||||
|
||||
if(!port.matches("^\\d+$"))
|
||||
throw new IllegalArgumentException("Given port is not a positive integer");
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,81 @@
|
||||
package com.pqt.client.gui.startup_frame;
|
||||
|
||||
import com.pqt.client.gui.ressources.components.generics.IFXComponent;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import com.pqt.client.gui.ressources.strings.GUIStringTool;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.*;
|
||||
|
||||
public class StartupFrameView implements IFXComponent{
|
||||
|
||||
private BorderPane mainPane;
|
||||
private VBox mainPane;
|
||||
private final StartupFrameController ctrl;
|
||||
|
||||
private TextField serverHostTextField;
|
||||
private TextField serverPortTextField;
|
||||
private TextField usernameTextField;
|
||||
private TextField passwordTextField;
|
||||
|
||||
public StartupFrameView(StartupFrameController ctrl) {
|
||||
this.ctrl = ctrl;
|
||||
initGui();
|
||||
}
|
||||
|
||||
private void initGui() {
|
||||
mainPane = new BorderPane();
|
||||
//TODO ajouter GUI StartupFrameView
|
||||
mainPane = new VBox();
|
||||
|
||||
Label serverHostLabel = new Label(GUIStringTool.getServerHostLabel());
|
||||
serverHostTextField = new TextField();
|
||||
Label serverPortLabel = new Label(GUIStringTool.getServerPortLabel());
|
||||
serverPortTextField = new TextField();
|
||||
|
||||
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);
|
||||
|
||||
|
||||
Label usernameLabel = new Label(GUIStringTool.getUsernameLabel());
|
||||
usernameTextField = new TextField();
|
||||
Label passwordLabel = new Label(GUIStringTool.getPasswordLabel());
|
||||
passwordTextField = new PasswordField();
|
||||
|
||||
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);
|
||||
|
||||
Button validationButton = new Button(GUIStringTool.getValidationButtonLabel());
|
||||
validationButton.setOnAction((event)->{
|
||||
ctrl.onValidation();
|
||||
});
|
||||
|
||||
mainPane.getChildren().addAll(serverTitledPane, accountTitledPane, validationButton);
|
||||
}
|
||||
|
||||
String getServerHostTextFieldContent(){
|
||||
return serverHostTextField.getText();
|
||||
}
|
||||
|
||||
String getServerPortTextFieldContent(){
|
||||
return serverPortTextField.getText();
|
||||
}
|
||||
|
||||
String getAccountUsernameTextFieldContent(){
|
||||
return usernameTextField.getText();
|
||||
}
|
||||
|
||||
String getAccountPasswordTextFieldContent(){
|
||||
return passwordTextField.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pane getMainPane() {
|
||||
public Pane getPane() {
|
||||
return mainPane;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,106 @@
|
||||
package com.pqt.client.gui.startup_frame;
|
||||
|
||||
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 com.pqt.core.entities.user_account.Account;
|
||||
|
||||
class StartupProcedureHandler {
|
||||
|
||||
private NetworkService networkService;
|
||||
private AccountService accountService;
|
||||
|
||||
private String host, username, password;
|
||||
private Integer port;
|
||||
|
||||
StartupProcedureHandler(NetworkService networkService, AccountService accountService) {
|
||||
this.networkService = networkService;
|
||||
this.accountService = accountService;
|
||||
}
|
||||
|
||||
StartupProcedureHandler init(String host, Integer port, String username, String password){
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
void handle(){
|
||||
testConnection();
|
||||
}
|
||||
|
||||
private void testConnection(){
|
||||
networkService.addListener(getPingListener());
|
||||
networkService.sendPQTPing(host, port);
|
||||
}
|
||||
|
||||
private void useRequestedServer(){
|
||||
//TODO notify this
|
||||
networkService.setActiveServer(host, port);
|
||||
accountService.addListener(getUpdateAccountListListener());
|
||||
accountService.refreshAccounts();
|
||||
}
|
||||
|
||||
private void connectAccount(){
|
||||
Account match = accountService.getAllAccounts().stream()
|
||||
.filter(account -> account.getUsername().equals(username))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if(match==null){
|
||||
//TODO notify this
|
||||
}else{
|
||||
accountService.setCurrentAccount(match);
|
||||
accountService.addListener(getConnectAccountListener());
|
||||
accountService.logInCurrentAccount(StartupProcedureHandler.this.password);
|
||||
}
|
||||
}
|
||||
|
||||
private INetworkServiceListener getPingListener(){
|
||||
return new INetworkServiceListener() {
|
||||
@Override
|
||||
public void onPQTPingSuccessEvent(String host, Integer port) {
|
||||
if(StartupProcedureHandler.this.host.equals(host)
|
||||
&& StartupProcedureHandler.this.port.equals(port)){
|
||||
useRequestedServer();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPQTPingFailureEvent(String host, Integer port, Throwable cause) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewServerConfigData() {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private IAccountListener getUpdateAccountListListener(){
|
||||
return new AccountListenerAdapter(){
|
||||
@Override
|
||||
public void onAccountListChangedEvent(){
|
||||
connectAccount();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private IAccountListener getConnectAccountListener(){
|
||||
return new AccountListenerAdapter(){
|
||||
@Override
|
||||
public void onAccountStatusChangedEvent(boolean status) {
|
||||
if(status){
|
||||
//TODO notify this
|
||||
}else{
|
||||
//TODO notify this
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -27,7 +27,6 @@ public class AccountService {
|
||||
this.executor = executor;
|
||||
listenerList = new EventListenerList();
|
||||
accounts = new ArrayList<>();
|
||||
refreshAccounts();
|
||||
}
|
||||
|
||||
public Account getCurrentAccount() {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.pqt.client.module.network;
|
||||
|
||||
import com.pqt.client.module.connection.ConnectionService;
|
||||
import com.pqt.client.module.network.listeners.INetworkServiceListener;
|
||||
import com.pqt.client.module.query.QueryExecutor;
|
||||
import com.pqt.client.module.query.query_callback.IMapItemMessageCallback;
|
||||
@ -18,11 +19,13 @@ import java.util.*;
|
||||
public class NetworkService {
|
||||
|
||||
private final QueryExecutor queryExecutor;
|
||||
private final ConnectionService connectionService;
|
||||
private final EventListenerList listenerList;
|
||||
private final ServerConfigCache configCache;
|
||||
|
||||
public NetworkService(QueryExecutor queryExecutor) {
|
||||
public NetworkService(QueryExecutor queryExecutor, ConnectionService connectionService) {
|
||||
this.queryExecutor = queryExecutor;
|
||||
this.connectionService = connectionService;
|
||||
listenerList = new EventListenerList();
|
||||
configCache = new ServerConfigCache();
|
||||
}
|
||||
@ -59,11 +62,20 @@ public class NetworkService {
|
||||
});
|
||||
}
|
||||
|
||||
public boolean hasServerConfig(String host, Integer port){
|
||||
checkData(host, port);
|
||||
return configCache.hasConfig(host, port);
|
||||
}
|
||||
|
||||
public ServerConfig getServerConfig(String host, Integer port){
|
||||
checkData(host, port);
|
||||
return configCache.getConfig(host, port);
|
||||
}
|
||||
|
||||
public void setActiveServer(String host, Integer port){
|
||||
connectionService.setServerUrl(String.format("%s:%s", host, port));
|
||||
}
|
||||
|
||||
private void sendConfigRequest(String host, Integer port){
|
||||
queryExecutor.executeConfigListQuery(new IMapItemMessageCallback<String, String>(){
|
||||
|
||||
|
@ -2,13 +2,6 @@
|
||||
-fx-background-color: #1d1d1d;
|
||||
}
|
||||
|
||||
.label {
|
||||
-fx-font-size: 11pt;
|
||||
-fx-font-family: "Segoe UI Semibold";
|
||||
-fx-text-fill: white;
|
||||
-fx-opacity: 0.8;
|
||||
}
|
||||
|
||||
.label-bright {
|
||||
-fx-font-size: 11pt;
|
||||
-fx-font-family: "Segoe UI Semibold";
|
||||
@ -127,15 +120,29 @@
|
||||
.context-menu {
|
||||
-fx-background-color: derive(#1d1d1d,5%);
|
||||
}
|
||||
.text-field, .password-field, .choice-box, .text-area, .combo-box, .button {
|
||||
|
||||
.titled-pane, .titled-pane > .title, .titled-pane > *.content, .text-field,
|
||||
.password-field, .choice-box, .text-area, .combo-box, .button, .label {
|
||||
-fx-font-size: 12pt;
|
||||
-fx-font-family: "Segoe UI Semibold";
|
||||
-fx-background-color: #1d1d1d;
|
||||
-fx-text-fill: #d8d8d8;
|
||||
}
|
||||
|
||||
.titled-pane, .titled-pane > .title, .titled-pane > *.content {
|
||||
-fx-border-width: 0;
|
||||
}
|
||||
|
||||
.text-field, .password-field, .choice-box, .text-area, .combo-box, .button{
|
||||
-fx-pref-width: 150;
|
||||
-fx-pref-height: 30;
|
||||
-fx-background-color: #1d1d1d;
|
||||
-fx-border-color: #e2e2e2;
|
||||
-fx-border-width: 2;
|
||||
-fx-text-fill: #d8d8d8;
|
||||
}
|
||||
|
||||
.label{
|
||||
-fx-pref-width: 150;
|
||||
-fx-pref-height: 30;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
|
Loading…
Reference in New Issue
Block a user