diff --git a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/MasterPassword.java b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/MasterPassword.java index bd1d6751..f64c181e 100644 --- a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/MasterPassword.java +++ b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/MasterPassword.java @@ -51,21 +51,23 @@ public final class MasterPassword { private static final MasterPassword instance = new MasterPassword(); private final Collection listeners = new CopyOnWriteArraySet<>(); - private final MasterPasswordFrame frame = new MasterPasswordFrame(); @Nullable - private MPUser activeUser; + private MasterPasswordFrame frame; + @Nullable + private MPUser activeUser; public static MasterPassword get() { return instance; } - public boolean addListener(final Listener listener) { - return listeners.add( listener ); + public void addListener(final Listener listener) { + if (listeners.add( listener )) + listener.onUserSelected( activeUser ); } - public boolean removeListener(final Listener listener) { - return listeners.remove( listener ); + public void removeListener(final Listener listener) { + listeners.remove( listener ); } public void activateUser(final MPUser user) { @@ -84,6 +86,9 @@ public final class MasterPassword { public void open() { Res.ui( () -> { + if (frame == null) + frame = new MasterPasswordFrame(); + frame.setAlwaysOnTop( true ); frame.setVisible( true ); frame.setExtendedState( Frame.NORMAL ); diff --git a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/MPUser.java b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/MPUser.java index ae3b6fd5..8753742a 100644 --- a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/MPUser.java +++ b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/MPUser.java @@ -114,9 +114,9 @@ public interface MPUser> extends Comparable> { @Nonnull ImmutableCollection findSites(@Nullable String query); - boolean addListener(Listener listener); + void addListener(Listener listener); - boolean removeListener(Listener listener); + void removeListener(Listener listener); interface Listener { diff --git a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicUser.java b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicUser.java index 9f40c02c..557a3a2d 100755 --- a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicUser.java +++ b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicUser.java @@ -211,13 +211,13 @@ public abstract class MPBasicUser> extends Changeabl } @Override - public boolean addListener(final Listener listener) { - return listeners.add( listener ); + public void addListener(final Listener listener) { + listeners.add( listener ); } @Override - public boolean removeListener(final Listener listener) { - return listeners.remove( listener ); + public void removeListener(final Listener listener) { + listeners.remove( listener ); } @Override diff --git a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileUserManager.java b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileUserManager.java index 544b1631..edb58c41 100644 --- a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileUserManager.java +++ b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileUserManager.java @@ -66,6 +66,7 @@ public class MPFileUserManager { protected MPFileUserManager(final File path) { this.path = path; + reload(); } public void reload() { @@ -128,12 +129,13 @@ public class MPFileUserManager { return ImmutableSortedSet.copyOf( userByName.values() ); } - public boolean addListener(final Listener listener) { - return listeners.add( listener ); + public void addListener(final Listener listener) { + if (listeners.add( listener )) + listener.onFilesUpdated( getFiles() ); } - public boolean removeListener(final Listener listener) { - return listeners.remove( listener ); + public void removeListener(final Listener listener) { + listeners.remove( listener ); } private void fireUpdated() { @@ -141,7 +143,6 @@ public class MPFileUserManager { return; ImmutableSortedSet files = getFiles(); - for (final Listener listener : listeners) listener.onFilesUpdated( files ); }