mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2024-12-22 23:41:09 +00:00
Module Client, écran AccountScreen : la liste des comptes affichées est désormais correctement mise à jour quand AccountService émet une notif de changement
This commit is contained in:
parent
253b463a97
commit
a179081501
@ -1,5 +1,6 @@
|
||||
package com.pqt.client.gui.modules.account_screen;
|
||||
|
||||
import com.pqt.client.gui.modules.account_screen.listeners.IAccountScreenModelListener;
|
||||
import com.pqt.client.gui.ressources.components.generics.validators.listeners.IValidatorComponentListener;
|
||||
import com.pqt.core.entities.user_account.Account;
|
||||
import com.pqt.core.entities.user_account.AccountLevel;
|
||||
@ -11,6 +12,12 @@ class AccountScreenController {
|
||||
|
||||
AccountScreenController(AccountScreenModel model) {
|
||||
this.model = model;
|
||||
model.addListener(new IAccountScreenModelListener() {
|
||||
@Override
|
||||
public void onAccountListChangedEvent() {
|
||||
updateView();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void setView(AccountScreenView view) {
|
||||
|
@ -1,9 +1,13 @@
|
||||
package com.pqt.client.gui.modules.account_screen;
|
||||
|
||||
import com.pqt.client.gui.modules.account_screen.listeners.IAccountScreenModelListener;
|
||||
import com.pqt.client.module.account.AccountService;
|
||||
import com.pqt.client.module.account.listeners.IAccountListener;
|
||||
import com.pqt.core.entities.user_account.Account;
|
||||
import com.pqt.core.entities.user_account.AccountLevel;
|
||||
|
||||
import javax.swing.event.EventListenerList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
|
||||
@ -11,9 +15,28 @@ import java.util.EnumSet;
|
||||
class AccountScreenModel {
|
||||
|
||||
private AccountService accountService;
|
||||
private EventListenerList listenerList;
|
||||
|
||||
AccountScreenModel(AccountService accountService) {
|
||||
this.accountService = accountService;
|
||||
listenerList = new EventListenerList();
|
||||
accountService.addListener(new IAccountListener() {
|
||||
@Override
|
||||
public void onAccountStatusChangedEvent(boolean status) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountStatusNotChangedEvent(Throwable cause) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountListChangedEvent() {
|
||||
Arrays.stream(listenerList.getListeners(IAccountScreenModelListener.class))
|
||||
.forEach(IAccountScreenModelListener::onAccountListChangedEvent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void modifyAccount(Account oldVal, Account newVal) {
|
||||
@ -39,4 +62,12 @@ class AccountScreenModel {
|
||||
Collection<AccountLevel> getLevels() {
|
||||
return EnumSet.allOf(AccountLevel.class);
|
||||
}
|
||||
|
||||
public void addListener(IAccountScreenModelListener l){
|
||||
listenerList.add(IAccountScreenModelListener.class, l);
|
||||
}
|
||||
|
||||
public void removeListener(IAccountScreenModelListener l){
|
||||
listenerList.remove(IAccountScreenModelListener.class, l);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.pqt.client.gui.modules.account_screen.listeners;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
public interface IAccountScreenModelListener extends EventListener {
|
||||
void onAccountListChangedEvent();
|
||||
}
|
Loading…
Reference in New Issue
Block a user