mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2024-11-26 02:54:15 +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;
|
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.client.gui.ressources.components.generics.validators.listeners.IValidatorComponentListener;
|
||||||
import com.pqt.core.entities.user_account.Account;
|
import com.pqt.core.entities.user_account.Account;
|
||||||
import com.pqt.core.entities.user_account.AccountLevel;
|
import com.pqt.core.entities.user_account.AccountLevel;
|
||||||
@ -11,6 +12,12 @@ class AccountScreenController {
|
|||||||
|
|
||||||
AccountScreenController(AccountScreenModel model) {
|
AccountScreenController(AccountScreenModel model) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
|
model.addListener(new IAccountScreenModelListener() {
|
||||||
|
@Override
|
||||||
|
public void onAccountListChangedEvent() {
|
||||||
|
updateView();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void setView(AccountScreenView view) {
|
void setView(AccountScreenView view) {
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
package com.pqt.client.gui.modules.account_screen;
|
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.AccountService;
|
||||||
|
import com.pqt.client.module.account.listeners.IAccountListener;
|
||||||
import com.pqt.core.entities.user_account.Account;
|
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 javax.swing.event.EventListenerList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
@ -11,9 +15,28 @@ import java.util.EnumSet;
|
|||||||
class AccountScreenModel {
|
class AccountScreenModel {
|
||||||
|
|
||||||
private AccountService accountService;
|
private AccountService accountService;
|
||||||
|
private EventListenerList listenerList;
|
||||||
|
|
||||||
AccountScreenModel(AccountService accountService) {
|
AccountScreenModel(AccountService accountService) {
|
||||||
this.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) {
|
void modifyAccount(Account oldVal, Account newVal) {
|
||||||
@ -39,4 +62,12 @@ class AccountScreenModel {
|
|||||||
Collection<AccountLevel> getLevels() {
|
Collection<AccountLevel> getLevels() {
|
||||||
return EnumSet.allOf(AccountLevel.class);
|
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