1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
package tim.prune.save;
import javax.swing.table.AbstractTableModel;
import tim.prune.I18nManager;
/**
* Class to hold table model information for save dialog
*/
public class FieldSelectionTableModel extends AbstractTableModel
{
private FieldInfo[] _info = null;
/**
* Constructor giving list size
* @param inSize number of fields
*/
public FieldSelectionTableModel(int inSize)
{
_info = new FieldInfo[inSize];
}
/**
* Set the given FieldInfo object in the array
* @param inInfo FieldInfo object describing the field
* @param inIndex index to place in array
*/
public void addFieldInfo(FieldInfo inInfo, int inIndex)
{
_info[inIndex] = inInfo;
}
/**
* @see javax.swing.table.TableModel#getColumnCount()
*/
public int getColumnCount()
{
return 3;
}
/**
* @see javax.swing.table.TableModel#getRowCount()
*/
public int getRowCount()
{
return _info.length;
}
/**
* @see javax.swing.table.TableModel#getValueAt(int, int)
*/
public Object getValueAt(int inRowIndex, int inColumnIndex)
{
if (inColumnIndex == 0)
{
return _info[inRowIndex].getField().getName();
}
else if (inColumnIndex == 1)
{
return Boolean.valueOf(_info[inRowIndex].hasData());
}
return Boolean.valueOf(_info[inRowIndex].isSelected());
}
/**
* @return true if cell is editable
*/
public boolean isCellEditable(int inRowIndex, int inColumnIndex)
{
// only the select column is editable
return inColumnIndex == 2;
}
/**
* Set the given cell value
* @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
*/
public void setValueAt(Object inValue, int inRowIndex, int inColumnIndex)
{
// ignore edits to other columns
if (inColumnIndex == 2)
_info[inRowIndex].setSelected(((Boolean) inValue).booleanValue());
}
/**
* Swap the specified items in the array
* @param inIndex1 first index
* @param inIndex2 second index
*/
public void swapItems(int inIndex1, int inIndex2)
{
if (inIndex1 >= 0 && inIndex1 < _info.length && inIndex2 >= 0 && inIndex2 < _info.length)
{
FieldInfo temp = _info[inIndex1];
_info[inIndex1] = _info[inIndex2];
_info[inIndex2] = temp;
}
}
/**
* @return Class of cell data
*/
public Class<?> getColumnClass(int inColumnIndex)
{
if (inColumnIndex==0) return String.class;
return Boolean.class;
}
/**
* Get the name of the column
*/
public String getColumnName(int inColNum)
{
if (inColNum == 0) return I18nManager.getText("dialog.save.table.field");
else if (inColNum == 1) return I18nManager.getText("dialog.save.table.hasdata");
return I18nManager.getText("dialog.save.table.save");
}
/**
* Retrieve the FieldInfo object at the given index
* @param inIndex index, starting at 0
* @return FieldInfo object at this position
*/
public FieldInfo getFieldInfo(int inIndex)
{
if (inIndex < 0 || inIndex >= _info.length)
{
return null;
}
return _info[inIndex];
}
}
|