From a179081501a20446f04daba878a08262fc4ec1e9 Mon Sep 17 00:00:00 2001 From: "Notmoo-PC\\Notmoo" Date: Thu, 2 Nov 2017 18:06:03 +0100 Subject: [PATCH] =?UTF-8?q?Module=20Client,=20=C3=A9cran=20AccountScreen?= =?UTF-8?q?=20:=20la=20liste=20des=20comptes=20affich=C3=A9es=20est=20d?= =?UTF-8?q?=C3=A9sormais=20correctement=20mise=20=C3=A0=20jour=20quand=20A?= =?UTF-8?q?ccountService=20=C3=A9met=20une=20notif=20de=20changement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AccountScreenController.java | 7 +++++ .../account_screen/AccountScreenModel.java | 31 +++++++++++++++++++ .../IAccountScreenModelListener.java | 7 +++++ 3 files changed, 45 insertions(+) create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/listeners/IAccountScreenModelListener.java diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenController.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenController.java index 4cb8f15f..ca41acc8 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenController.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenController.java @@ -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) { diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenModel.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenModel.java index 471b7506..d682efbc 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenModel.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/AccountScreenModel.java @@ -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 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); + } } diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/listeners/IAccountScreenModelListener.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/listeners/IAccountScreenModelListener.java new file mode 100644 index 00000000..5f7c3ef9 --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/account_screen/listeners/IAccountScreenModelListener.java @@ -0,0 +1,7 @@ +package com.pqt.client.gui.modules.account_screen.listeners; + +import java.util.EventListener; + +public interface IAccountScreenModelListener extends EventListener { + void onAccountListChangedEvent(); +}