2
0

New user fixes.

This commit is contained in:
Maarten Billemont 2018-07-28 19:56:20 -04:00
parent 38f09021b3
commit 978b758079
8 changed files with 93 additions and 92 deletions

View File

@ -90,7 +90,7 @@ public class CollectionListModel<E> extends AbstractListModel<E>
@Override @Override
@SuppressWarnings({ "unchecked", "SuspiciousMethodCalls" }) @SuppressWarnings({ "unchecked", "SuspiciousMethodCalls" })
public synchronized void setSelectedItem(@Nullable final Object newSelectedItem) { public synchronized void setSelectedItem(@Nullable final Object newSelectedItem) {
if (!Objects.equals( selectedItem, newSelectedItem ) && model.contains( newSelectedItem )) { if (!Objects.equals( selectedItem, newSelectedItem )) {
selectedItem = (E) newSelectedItem; selectedItem = (E) newSelectedItem;
fireContentsChanged( this, -1, -1 ); fireContentsChanged( this, -1, -1 );

View File

@ -431,7 +431,8 @@ public class UserContentPanel extends JPanel implements FilesPanel.Listener, MPU
Toolkit.getDefaultToolkit().getSystemClipboard().setContents( clipboardContents, null ); Toolkit.getDefaultToolkit().getSystemClipboard().setContents( clipboardContents, null );
Res.ui( () -> { Res.ui( () -> {
Window window = SwingUtilities.windowForComponent( this ); Window window = SwingUtilities.windowForComponent( UserContentPanel.this );
if (window != null)
window.dispatchEvent( new WindowEvent( window, WindowEvent.WINDOW_CLOSING ) ); window.dispatchEvent( new WindowEvent( window, WindowEvent.WINDOW_CLOSING ) );
} ); } );
} ); } );

View File

@ -88,7 +88,7 @@ public abstract class MPBasicQuestion extends Changeable implements MPQuestion {
@Override @Override
public boolean equals(final Object obj) { public boolean equals(final Object obj) {
return (this == obj) || ((obj instanceof MPQuestion) && Objects.equals( getKeyword(), ((MPQuestion) obj).getKeyword() )); return this == obj;
} }
@Override @Override

View File

@ -204,7 +204,7 @@ public abstract class MPBasicSite<U extends MPUser<?>, Q extends MPQuestion> ext
@Override @Override
public boolean equals(final Object obj) { public boolean equals(final Object obj) {
return (this == obj) || ((obj instanceof MPSite) && Objects.equals( getSiteName(), ((MPSite<?>) obj).getSiteName() )); return obj == this;
} }
@Override @Override

View File

@ -226,7 +226,7 @@ public abstract class MPBasicUser<S extends MPBasicSite<?, ?>> extends Changeabl
@Override @Override
public boolean equals(final Object obj) { public boolean equals(final Object obj) {
return (this == obj) || ((obj instanceof MPUser) && Objects.equals( getFullName(), ((MPUser<?>) obj).getFullName() )); return this == obj;
} }
@Override @Override

View File

@ -104,6 +104,7 @@ public class MPFlatUnmarshaller implements MPUnmarshaller {
throws IOException, MPMarshalException, MPIncorrectMasterPasswordException, MPKeyUnavailableException, MPAlgorithmException { throws IOException, MPMarshalException, MPIncorrectMasterPasswordException, MPKeyUnavailableException, MPAlgorithmException {
user.ignoreChanges(); user.ignoreChanges();
if (user.getFile().exists())
try (Reader reader = new InputStreamReader( new FileInputStream( user.getFile() ), Charsets.UTF_8 )) { try (Reader reader = new InputStreamReader( new FileInputStream( user.getFile() ), Charsets.UTF_8 )) {
byte[] keyID = null; byte[] keyID = null;
String fullName = null; String fullName = null;

View File

@ -60,10 +60,10 @@ public class MPJSONFile extends MPJSONAnyObject {
objectMapper.setVisibility( PropertyAccessor.FIELD, JsonAutoDetect.Visibility.NON_PRIVATE ); objectMapper.setVisibility( PropertyAccessor.FIELD, JsonAutoDetect.Visibility.NON_PRIVATE );
} }
public MPJSONFile() { MPJSONFile() {
} }
public MPJSONFile(final MPFileUser modelUser) MPJSONFile(final MPFileUser modelUser)
throws MPAlgorithmException, MPKeyUnavailableException { throws MPAlgorithmException, MPKeyUnavailableException {
// Section: "export" // Section: "export"
@ -135,7 +135,7 @@ public class MPJSONFile extends MPJSONAnyObject {
} }
} }
public MPFileUser readUser(final File file) { MPFileUser readUser(final File file) {
MPAlgorithm algorithm = ifNotNullElse( user.algorithm, MPAlgorithm.Version.CURRENT ).getAlgorithm(); MPAlgorithm algorithm = ifNotNullElse( user.algorithm, MPAlgorithm.Version.CURRENT ).getAlgorithm();
return new MPFileUser( return new MPFileUser(
@ -147,10 +147,8 @@ public class MPJSONFile extends MPJSONAnyObject {
); );
} }
public void readSites(final MPFileUser user) void readSites(final MPFileUser user)
throws MPIncorrectMasterPasswordException, MPKeyUnavailableException, MPAlgorithmException { throws MPIncorrectMasterPasswordException, MPKeyUnavailableException, MPAlgorithmException {
user.ignoreChanges();
for (final Map.Entry<String, Site> siteEntry : sites.entrySet()) { for (final Map.Entry<String, Site> siteEntry : sites.entrySet()) {
String siteName = siteEntry.getKey(); String siteName = siteEntry.getKey();
Site fileSite = siteEntry.getValue(); Site fileSite = siteEntry.getValue();
@ -184,9 +182,6 @@ public class MPJSONFile extends MPJSONAnyObject {
user.addSite( site ); user.addSite( site );
} }
user.setComplete();
user.endChanges();
} }
// -- Data // -- Data

View File

@ -56,7 +56,11 @@ public class MPJSONUnmarshaller implements MPUnmarshaller {
throws IOException, MPMarshalException, MPIncorrectMasterPasswordException, MPKeyUnavailableException, MPAlgorithmException { throws IOException, MPMarshalException, MPIncorrectMasterPasswordException, MPKeyUnavailableException, MPAlgorithmException {
try { try {
user.ignoreChanges();
if (user.getFile().exists())
objectMapper.readValue( user.getFile(), MPJSONFile.class ).readSites( user ); objectMapper.readValue( user.getFile(), MPJSONFile.class ).readSites( user );
user.setComplete();
user.endChanges();
} }
catch (final JsonParseException e) { catch (final JsonParseException e) {
throw new MPMarshalException( "Couldn't parse JSON.", e ); throw new MPMarshalException( "Couldn't parse JSON.", e );