File: FieldSelectionTableModel.java

package info (click to toggle)
gpsprune 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: java: 52,154; sh: 25; makefile: 21; python: 15
file content (123 lines) | stat: -rw-r--r-- 2,717 bytes parent folder | download | duplicates (4)
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
package tim.prune.save;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import tim.prune.I18nManager;

/**
 * Class to hold table model information for save dialog
 */
public class FieldSelectionTableModel extends AbstractTableModel
{
	private final FieldInfo[] _info;


	/**
	 * Constructor
	 * @param inFields list of fields
	 */
	public FieldSelectionTableModel(List<FieldInfo> inFields) {
		_info = inFields.toArray(new FieldInfo[0]);
	}

	/**
	 * @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)
	{
		final FieldInfo field = _info[inRowIndex];
		if (inColumnIndex == 0) {
			return field.getField().getName();
		}
		else if (inColumnIndex == 1) {
			return field.hasData();
		}
		return field.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) {
		return inColumnIndex == 0 ? String.class : 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];
	}
}