| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
package org.homeunix.thecave.buddi.model.swing; |
| 5 | |
|
| 6 | |
import java.util.List; |
| 7 | |
|
| 8 | |
import javax.swing.table.AbstractTableModel; |
| 9 | |
|
| 10 | |
import org.homeunix.thecave.buddi.model.Document; |
| 11 | |
import org.homeunix.thecave.buddi.model.ScheduledTransaction; |
| 12 | |
import org.homeunix.thecave.buddi.plugin.api.exception.InvalidValueException; |
| 13 | |
import org.homeunix.thecave.buddi.plugin.api.exception.ModelException; |
| 14 | |
|
| 15 | |
public class ScheduledTransactionTableModel extends AbstractTableModel { |
| 16 | |
public static final long serialVersionUID = 0; |
| 17 | |
|
| 18 | |
private final Document model; |
| 19 | 0 | private int selectedIndex = -1; |
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | 0 | public ScheduledTransactionTableModel(Document model) { |
| 26 | 0 | this.model = model; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | 0 | } |
| 34 | |
|
| 35 | |
public int getColumnCount() { |
| 36 | 0 | return 1; |
| 37 | |
} |
| 38 | |
|
| 39 | |
@Override |
| 40 | |
public String getColumnName(int column) { |
| 41 | 0 | return null; |
| 42 | |
} |
| 43 | |
|
| 44 | |
public int getRowCount() { |
| 45 | 0 | return getScheduledTransactios().size(); |
| 46 | |
} |
| 47 | |
|
| 48 | |
public Object getValueAt(int rowIndex, int columnIndex) { |
| 49 | 0 | if (columnIndex == -1) |
| 50 | 0 | return getScheduledTransactios().get(rowIndex); |
| 51 | 0 | return getScheduledTransactios().get(rowIndex).getScheduleName(); |
| 52 | |
} |
| 53 | |
|
| 54 | |
@Override |
| 55 | |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
| 56 | 0 | ScheduledTransaction s = getScheduledTransactios().get(rowIndex); |
| 57 | |
try { |
| 58 | 0 | s.setScheduleName(aValue.toString()); |
| 59 | |
} |
| 60 | 0 | catch (InvalidValueException ive){} |
| 61 | 0 | } |
| 62 | |
|
| 63 | |
@Override |
| 64 | |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
| 65 | 0 | return true; |
| 66 | |
} |
| 67 | |
|
| 68 | |
public void add(ScheduledTransaction s){ |
| 69 | |
try { |
| 70 | 0 | model.addScheduledTransaction(s); |
| 71 | |
} |
| 72 | 0 | catch (ModelException me){} |
| 73 | |
|
| 74 | 0 | fireTableChanged(); |
| 75 | 0 | } |
| 76 | |
|
| 77 | |
public void remove(ScheduledTransaction s){ |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
try { |
| 82 | 0 | model.removeScheduledTransaction(s); |
| 83 | |
} |
| 84 | 0 | catch (ModelException me){} |
| 85 | |
|
| 86 | 0 | } |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
public List<ScheduledTransaction> getScheduledTransactios(){ |
| 95 | 0 | return model.getScheduledTransactions(); |
| 96 | |
} |
| 97 | |
|
| 98 | |
public void fireTableChanged(){ |
| 99 | 0 | fireTableStructureChanged(); |
| 100 | 0 | } |
| 101 | |
|
| 102 | |
public int getSelectedIndex() { |
| 103 | 0 | return selectedIndex; |
| 104 | |
} |
| 105 | |
|
| 106 | |
public void setSelectedScheduedTransaction(int selectedIndex) { |
| 107 | 0 | this.selectedIndex = selectedIndex; |
| 108 | 0 | } |
| 109 | |
} |