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:
Notmoo-PC\Notmoo 2017-11-02 18:06:03 +01:00
parent 253b463a97
commit a179081501
3 changed files with 45 additions and 0 deletions

View File

@ -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) {

View File

@ -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);
}
}

View File

@ -0,0 +1,7 @@
package com.pqt.client.gui.modules.account_screen.listeners;
import java.util.EventListener;
public interface IAccountScreenModelListener extends EventListener {
void onAccountListChangedEvent();
}