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(); +}