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
18 public FieldSelectionTableModel(int inSize)
20 _info = new FieldInfo[inSize];
25 * Set the given FieldInfo object in the array
26 * @param inInfo FieldInfo object describing the field
27 * @param inIndex index to place in array
29 public void addFieldInfo(FieldInfo inInfo, int inIndex)
31 _info[inIndex] = inInfo;
36 * @see javax.swing.table.TableModel#getColumnCount()
38 public int getColumnCount()
45 * @see javax.swing.table.TableModel#getRowCount()
47 public int getRowCount()
54 * @see javax.swing.table.TableModel#getValueAt(int, int)
56 public Object getValueAt(int inRowIndex, int inColumnIndex)
58 if (inColumnIndex == 0)
60 return _info[inRowIndex].getField().getName();
62 else if (inColumnIndex == 1)
64 return new Boolean(_info[inRowIndex].hasData());
66 return new Boolean(_info[inRowIndex].isSelected());
71 * @return true if cell is editable
73 public boolean isCellEditable(int inRowIndex, int inColumnIndex)
75 // only the select column is editable
76 return inColumnIndex == 2;
81 * Set the given cell value
82 * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
84 public void setValueAt(Object inValue, int inRowIndex, int inColumnIndex)
86 // ignore edits to other columns
87 if (inColumnIndex == 2)
88 _info[inRowIndex].setSelected(((Boolean) inValue).booleanValue());
93 * Swap the specified items in the array
94 * @param inIndex1 first index
95 * @param inIndex2 second index
97 public void swapItems(int inIndex1, int inIndex2)
99 if (inIndex1 >= 0 && inIndex1 < _info.length && inIndex2 >= 0 && inIndex2 < _info.length)
101 FieldInfo temp = _info[inIndex1];
102 _info[inIndex1] = _info[inIndex2];
103 _info[inIndex2] = temp;
109 * @return Class of cell data
111 public Class getColumnClass(int inColumnIndex)
113 if (inColumnIndex==0) return String.class;
114 return Boolean.class;
119 * Get the name of the column
121 public String getColumnName(int inColNum)
123 if (inColNum == 0) return I18nManager.getText("dialog.save.table.field");
124 else if (inColNum == 1) return I18nManager.getText("dialog.save.table.hasdata");
125 return I18nManager.getText("dialog.save.table.save");
130 * Retrieve the FieldInfo object at the given index
131 * @param inIndex index, starting at 0
132 * @return FieldInfo object at this position
134 public FieldInfo getFieldInfo(int inIndex)
136 if (inIndex < 0 || inIndex >= _info.length)
140 return _info[inIndex];