1 package tim.prune.save;
3 import javax.swing.table.AbstractTableModel;
5 import tim.prune.I18nManager;
8 * Class to hold table model information for save dialog
10 public class FieldSelectionTableModel extends AbstractTableModel
12 private FieldInfo[] _info = null;
16 * Constructor giving list size
17 * @param inSize number of fields
19 public FieldSelectionTableModel(int inSize)
21 _info = new FieldInfo[inSize];
26 * Set the given FieldInfo object in the array
27 * @param inInfo FieldInfo object describing the field
28 * @param inIndex index to place in array
30 public void addFieldInfo(FieldInfo inInfo, int inIndex)
32 _info[inIndex] = inInfo;
37 * @see javax.swing.table.TableModel#getColumnCount()
39 public int getColumnCount()
46 * @see javax.swing.table.TableModel#getRowCount()
48 public int getRowCount()
55 * @see javax.swing.table.TableModel#getValueAt(int, int)
57 public Object getValueAt(int inRowIndex, int inColumnIndex)
59 if (inColumnIndex == 0)
61 return _info[inRowIndex].getField().getName();
63 else if (inColumnIndex == 1)
65 return Boolean.valueOf(_info[inRowIndex].hasData());
67 return Boolean.valueOf(_info[inRowIndex].isSelected());
72 * @return true if cell is editable
74 public boolean isCellEditable(int inRowIndex, int inColumnIndex)
76 // only the select column is editable
77 return inColumnIndex == 2;
82 * Set the given cell value
83 * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
85 public void setValueAt(Object inValue, int inRowIndex, int inColumnIndex)
87 // ignore edits to other columns
88 if (inColumnIndex == 2)
89 _info[inRowIndex].setSelected(((Boolean) inValue).booleanValue());
94 * Swap the specified items in the array
95 * @param inIndex1 first index
96 * @param inIndex2 second index
98 public void swapItems(int inIndex1, int inIndex2)
100 if (inIndex1 >= 0 && inIndex1 < _info.length && inIndex2 >= 0 && inIndex2 < _info.length)
102 FieldInfo temp = _info[inIndex1];
103 _info[inIndex1] = _info[inIndex2];
104 _info[inIndex2] = temp;
110 * @return Class of cell data
112 public Class<?> getColumnClass(int inColumnIndex)
114 if (inColumnIndex==0) return String.class;
115 return Boolean.class;
120 * Get the name of the column
122 public String getColumnName(int inColNum)
124 if (inColNum == 0) return I18nManager.getText("dialog.save.table.field");
125 else if (inColNum == 1) return I18nManager.getText("dialog.save.table.hasdata");
126 return I18nManager.getText("dialog.save.table.save");
131 * Retrieve the FieldInfo object at the given index
132 * @param inIndex index, starting at 0
133 * @return FieldInfo object at this position
135 public FieldInfo getFieldInfo(int inIndex)
137 if (inIndex < 0 || inIndex >= _info.length)
141 return _info[inIndex];