| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
package org.homeunix.thecave.buddi.model.swing; |
| 5 | |
|
| 6 | |
import java.util.HashMap; |
| 7 | |
import java.util.Map; |
| 8 | |
|
| 9 | |
import org.homeunix.thecave.buddi.model.Document; |
| 10 | |
import org.homeunix.thecave.buddi.model.Source; |
| 11 | |
import org.homeunix.thecave.buddi.model.Transaction; |
| 12 | |
|
| 13 | |
import ca.digitalcave.moss.application.document.DocumentChangeEvent; |
| 14 | |
import ca.digitalcave.moss.application.document.DocumentChangeListener; |
| 15 | |
|
| 16 | 1 | public class AutoCompleteEntryModel { |
| 17 | |
private final Document model; |
| 18 | |
private final DocumentChangeListener listener; |
| 19 | |
private final Map<String, AutoCompleteEntry> autoCompleteEntries; |
| 20 | |
|
| 21 | 1165 | public AutoCompleteEntryModel(Document model) { |
| 22 | 1165 | this.model = model; |
| 23 | 1165 | this.autoCompleteEntries = new HashMap<String, AutoCompleteEntry>(); |
| 24 | 1165 | updateAutoCompleteList(); |
| 25 | 1165 | listener = new DocumentChangeListener(){ |
| 26 | |
public void documentChange(DocumentChangeEvent event) { |
| 27 | 1 | updateAutoCompleteList(); |
| 28 | 1 | } |
| 29 | |
}; |
| 30 | 1165 | model.addDocumentChangeListener(listener); |
| 31 | 1165 | } |
| 32 | |
|
| 33 | |
private void updateAutoCompleteList(){ |
| 34 | 1166 | for (Transaction t : model.getTransactions()) { |
| 35 | 0 | autoCompleteEntries.put(t.getDescription(), new AutoCompleteEntry(t.getAmount(), t.getFrom(), t.getTo())); |
| 36 | |
} |
| 37 | 1166 | } |
| 38 | |
|
| 39 | |
public AutoCompleteEntry getEntry(String description){ |
| 40 | 0 | return autoCompleteEntries.get(description); |
| 41 | |
} |
| 42 | |
|
| 43 | |
public static class AutoCompleteEntry { |
| 44 | |
private long amount; |
| 45 | |
private Source from; |
| 46 | |
private Source to; |
| 47 | |
|
| 48 | 0 | public AutoCompleteEntry(long amount, Source from, Source to) { |
| 49 | 0 | this.amount = amount; |
| 50 | 0 | this.from = from; |
| 51 | 0 | this.to = to; |
| 52 | 0 | } |
| 53 | |
|
| 54 | |
public long getAmount() { |
| 55 | 0 | return amount; |
| 56 | |
} |
| 57 | |
public void setAmount(long amount) { |
| 58 | 0 | this.amount = amount; |
| 59 | 0 | } |
| 60 | |
public Source getFrom() { |
| 61 | 0 | return from; |
| 62 | |
} |
| 63 | |
public void setFrom(Source from) { |
| 64 | 0 | this.from = from; |
| 65 | 0 | } |
| 66 | |
public Source getTo() { |
| 67 | 0 | return to; |
| 68 | |
} |
| 69 | |
public void setTo(Source to) { |
| 70 | 0 | this.to = to; |
| 71 | 0 | } |
| 72 | |
} |
| 73 | |
} |