Fix initialization dependency cycle & load files on init.
This commit is contained in:
parent
6b9e1b8cb8
commit
40fdc8d248
@ -51,8 +51,9 @@ public final class MasterPassword {
|
||||
private static final MasterPassword instance = new MasterPassword();
|
||||
|
||||
private final Collection<Listener> listeners = new CopyOnWriteArraySet<>();
|
||||
private final MasterPasswordFrame frame = new MasterPasswordFrame();
|
||||
|
||||
@Nullable
|
||||
private MasterPasswordFrame frame;
|
||||
@Nullable
|
||||
private MPUser<?> activeUser;
|
||||
|
||||
@ -60,12 +61,13 @@ public final class MasterPassword {
|
||||
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 );
|
||||
|
@ -114,9 +114,9 @@ public interface MPUser<S extends MPSite<?>> extends Comparable<MPUser<?>> {
|
||||
@Nonnull
|
||||
ImmutableCollection<S> findSites(@Nullable String query);
|
||||
|
||||
boolean addListener(Listener listener);
|
||||
void addListener(Listener listener);
|
||||
|
||||
boolean removeListener(Listener listener);
|
||||
void removeListener(Listener listener);
|
||||
|
||||
interface Listener {
|
||||
|
||||
|
@ -211,13 +211,13 @@ public abstract class MPBasicUser<S extends MPBasicSite<?, ?>> 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
|
||||
|
@ -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<MPFileUser> files = getFiles();
|
||||
|
||||
for (final Listener listener : listeners)
|
||||
listener.onFilesUpdated( files );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user