Skip to content

Commit

Permalink
Allow description to be edited.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcz committed Jul 5, 2024
1 parent 8335844 commit 866c3f5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/tomczarniecki/jpasskeep/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,24 @@
*/
package com.tomczarniecki.jpasskeep;

import java.util.List;
import java.util.UUID;

import org.apache.commons.lang.builder.EqualsBuilder;

public class Entry implements Comparable<Entry> {

private final String key = UUID.randomUUID().toString();
private String description = "";
private Category category = Category.Home;
private String username = "";
private String password = "";
private String notes = "";

public String getKey() {
return key;
}

public String getDescription() {
return description;
}
Expand Down Expand Up @@ -77,6 +85,11 @@ public void setPassword(String password) {
this.password = password;
}

public List<String> getNotesAsLines() {
String[] lines = notes.split("\\r?\\n");
return List.of(lines);
}

public String getNotes() {
return notes;
}
Expand Down
45 changes: 20 additions & 25 deletions src/main/java/com/tomczarniecki/jpasskeep/MainListModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,25 @@

import javax.swing.AbstractListModel;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Map;

public class MainListModel extends AbstractListModel<Object> {

private final List<Entry> filtered;
private final SortedMap<String, Entry> entries;
private final Map<String, Entry> entries;

private boolean showHome = true;
private boolean showWork = true;
private boolean showOther = true;

public MainListModel(List<Entry> entries) {
this.filtered = new ArrayList<>();
this.entries = new TreeMap<>();
this.entries = new HashMap<>();
for (Entry entry : entries) {
String key = entry.getDescription();
if (this.entries.containsKey(key)) {
Entry current = this.entries.get(key);
String notes = current.getNotes();
notes += "\n--Merged--\n" + entry.getUsername();
notes += "\n" + entry.getPassword();
notes += "\n" + entry.getNotes();
current.setNotes(notes);
} else {
this.entries.put(key, entry);
}
this.entries.put(entry.getKey(), entry);
}
filter();
}
Expand All @@ -74,18 +65,20 @@ public Entry getEntry(int index) {
}

public void setEntry(Entry entry) {
entries.put(entry.getDescription(), entry);
entries.put(entry.getKey(), entry);
filter();
}

public void removeEntry(int index) {
Entry entry = filtered.get(index);
entries.remove(entry.getDescription());
entries.remove(entry.getKey());
filter();
}

public List<Entry> getEntries() {
return List.copyOf(entries.values());
List<Entry> values = new ArrayList<>(entries.values());
Collections.sort(values);
return values;
}

public void setShowHome(boolean showHome) {
Expand Down Expand Up @@ -122,6 +115,7 @@ private void filter() {
filtered.add(entry);
}
}
Collections.sort(filtered);
fireContentsChanged(this, 0, filtered.size());
}

Expand All @@ -134,13 +128,14 @@ private boolean show(Entry entry) {
}

public ImportState stateForEntry(Entry otherEntry) {
Entry currentEntry = entries.get(otherEntry.getDescription());
if (currentEntry == null) {
return ImportState.New;
}
if (currentEntry.equals(otherEntry)) {
return ImportState.Equal;
for (Entry entry : entries.values()) {
if (entry.getDescription().equals(otherEntry.getDescription())) {
if (entry.equals(otherEntry)) {
return ImportState.Equal;
}
return ImportState.Changed;
}
}
return ImportState.Changed;
return ImportState.New;
}
}

0 comments on commit 866c3f5

Please sign in to comment.