1 package com.explosion.utilities.preferences.dialogs;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.awt.Component;
23
24 import javax.swing.JComponent;
25 import javax.swing.JTable;
26 import javax.swing.table.TableCellEditor;
27 import javax.swing.table.TableCellRenderer;
28
29 import com.explosion.utilities.preferences.Preference;
30
31 /***
32 * This table uses Preference objects to edit properties
33 * */
34 public class CollectionPreferenceTable extends JTable
35 {
36
37 private Component owner;
38 private Preference preference;
39
40 /***
41 * Constructor, give it the model it assumes that the model is a Vector
42 * filled with Preference objects in the second column The owner is
43 * required as the owner of any dialogs that get popped up from this table.
44 *
45 * @param model
46 */
47 public CollectionPreferenceTable(Preference preference, Component owner)
48 {
49 super();
50 this.owner = owner;
51 this.preference = preference;
52
53 }
54
55 /***
56 * Returns
57 */
58 public boolean isCellEditable(int row, int column)
59 {
60 return preference.isEditable();
61 }
62
63 /***
64 * Overrides TableInterface getCellRenederer. Bases it's decision on what
65 * renderer to return by looking at the property type for the Preference
66 * in the given row
67 *
68 * @param row
69 * @param column
70 * @return
71 */
72 public TableCellRenderer getCellRenderer(int row, int column)
73 {
74 TableCellRenderer renderer = PreferencesTable.getRendererForType(preference.getCollectionType(), null);
75 if (renderer == null)
76 renderer = super.getCellRenderer(row, column);
77
78 if (renderer instanceof JComponent)
79 ((JComponent) renderer).setToolTipText(preference.getDescription());
80
81 return renderer;
82 }
83
84 /***
85 * Overrides TableInterface getCellEditor. Bases it's decision on what
86 * editor to return by looking at the property type for the Preference in
87 * the given row
88 *
89 * @param row
90 * @param column
91 * @return
92 */
93 public TableCellEditor getCellEditor(int row, int column)
94 {
95 TableCellEditor editor = PreferencesTable.getEditorForType(preference.getCollectionType(), owner, preference);
96
97 if (editor != null)
98 return editor;
99
100 return super.getCellEditor(row, column);
101 }
102
103 /***
104 * Sets the value at the given index
105 * @see javax.swing.JTable#setValueAt(java.lang.Object, int, int)
106 * @param aValue
107 * @param row
108 * @param column
109 */
110 public void setValueAt(Object aValue, int row, int column)
111 {
112 try
113 {
114 preference.setValueAt(aValue, row);
115 }
116 catch (Exception e)
117 {
118 com.explosion.utilities.exception.ExceptionManagerFactory.getExceptionManager().manageException(e, null);
119 }
120
121 }
122
123
124 }
125