1 | public class DataTypeOther extends BaseDataTypeComponent↵ | | 1 | public class DataTypeUnknown extends BaseDataTypeComponent↵
|
2 | implements IDataTypeComponent↵ | | 2 | implements IDataTypeComponent↵
|
3 | {↵ | | 3 | {↵
|
4 | /* whether nulls are allowed or not */↵ | | 4 | /* whether nulls are allowed or not */↵
|
5 | private boolean _isNullable;↵ | | 5 | private boolean _isNullable;↵
|
|
6 | /* table of which we are part (needed for creating popup dialog) */↵ | | 6 | /* table of which we are part (needed for creating popup dialog) */↵
|
7 | private JTable _table;↵ | | 7 | private JTable _table;↵
|
8 | ↵ | | 8 | ↵
|
9 | /* The JTextComponent that is being used for editing */↵ | | 9 | /* The JTextComponent that is being used for editing */↵
|
10 | private IRestorableTextComponent _textComponent;↵ | | 10 | private IRestorableTextComponent _textComponent;↵
|
11 | ↵ | | 11 | ↵
|
12 | /** Internationalized strings for this class, shared/copied from ResultSetReader. */↵ | | 12 | /** Internationalized strings for this class, shared/copied from ResultSetReader. */↵
|
13 | private static final StringManager s_stringMgr =↵ | | 13 | private static final StringManager s_stringMgr =↵
|
14 | StringManagerFactory.getStringManager(DataTypeOther.class); ↵ | | 14 | StringManagerFactory.getStringManager(DataTypeUnknown.class);↵
|
| | | 15 | ↵
|
15 | /* The CellRenderer used for this data type */↵ | | 16 | /* The CellRenderer used for this data type */↵
|
16 | //??? For now, use the same renderer as everyone else.↵ | | 17 | //??? For now, use the same renderer as everyone else.↵
|
17 | //??↵ | | 18 | //??↵
|
18 | //?? IN FUTURE: change this to use a new instance of renederer↵ | | 19 | //?? IN FUTURE: change this to use a new instance of renederer↵
|
19 | //?? for this data type.↵ | | 20 | //?? for this data type.↵
|
20 | private DefaultColumnRenderer _renderer = DefaultColumnRenderer.getInstance(); ↵ | | 21 | private DefaultColumnRenderer _renderer = DefaultColumnRenderer.getInstance();↵
|
|
|
|
21 | /**↵ | | 22 | /**↵
|
22 | * Name of this class, which is needed because the class name is needed↵ | | 23 | * Name of this class, which is needed because the class name is needed↵
|
23 | * by the static method getControlPanel, so we cannot use something↵ | | 24 | * by the static method getControlPanel, so we cannot use something↵
|
24 | * like getClass() to find this name.↵ | | 25 | * like getClass() to find this name.↵
|
25 | */↵ | | 26 | */↵
|
26 | private static final String thisClassName =↵ | | 27 | private static final String thisClassName =↵
|
27 | "net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeOther";↵ | | 28 | "net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeUnknown";↵
|
|
28 | /*↵ | | 29 | /*↵
|
29 | * Properties settable by the user↵ | | 30 | * Properties settable by the user↵
|
30 | */↵ | | 31 | */↵
|
31 | // flag for whether we have already loaded the properties or not↵ | | 32 | // flag for whether we have already loaded the properties or not↵
|
32 | private static boolean propertiesAlreadyLoaded = false;↵ | | 33 | private static boolean propertiesAlreadyLoaded = false;↵
|
33 | ↵ | | 34 | ↵
|
34 | ↵ | | 35 | ↵
|
35 | /** Read the contents of Other from Result sets when first loading the tables. */↵ | | 36 | /** Read the contents of Other from Result sets when first loading the tables. */↵
|
36 | private static boolean _readSQLOther = false;↵ | | 37 | private static boolean _readUnknown = false;↵
|
37 | ↵ | | 38 | ↵
|
| | | 39 | ↵
|
|
38 | /**↵ | | 40 | /**↵
|
39 | * Constructor - save the data needed by this data type.↵ | | 41 | * Constructor - save the data needed by this data type.↵
|
40 | */↵ | | 42 | */↵
|
41 | public DataTypeOther(JTable table, ColumnDisplayDefinition colDef) {↵ | | 43 | public DataTypeUnknown(JTable table, ColumnDisplayDefinition colDef) {↵
|
42 | _table = table;↵ | | 44 | _table = table;↵
|
43 | _colDef = colDef;↵ | | 45 | _colDef = colDef;↵
|
44 | _isNullable = colDef.isNullable();↵ | | 46 | _isNullable = colDef.isNullable();↵
|
|
45 | loadProperties();↵ | | 47 | loadProperties();↵
|
46 | }↵ | | 48 | }↵
|
47 | ↵ | | 49 | ↵
|
48 | /** Internal function to get the user-settable properties from the DTProperties,↵ | | 50 | /** Internal function to get the user-settable properties from the DTProperties,↵
|
49 | * if they exist, and to ensure that defaults are set if the properties have↵ | | 51 | * if they exist, and to ensure that defaults are set if the properties have↵
|
50 | * not yet been created.↵ | | 52 | * not yet been created.↵
|
51 | * <P>↵ | | 53 | * <P>↵
|
52 | * This method may be called from different places depending on whether↵ | | 54 | * This method may be called from different places depending on whether↵
|
53 | * an instance of this class is created before the user brings up the Session↵ | | 55 | * an instance of this class is created before the user brings up the Session↵
|
54 | * Properties window. In either case, the data is static and is set only↵ | | 56 | * Properties window. In either case, the data is static and is set only↵
|
55 | * the first time we are called.↵ | | 57 | * the first time we are called.↵
|
56 | */↵ | | 58 | */↵
|
57 | private static void loadProperties() {↵ | | 59 | private static void loadProperties() {↵
|
58 | ↵ | | 60 | ↵
|
59 | //set the property values↵ | | 61 | //set the property values↵
|
60 | // Note: this may have already been done by another instance of↵ | | 62 | // Note: this may have already been done by another instance of↵
|
61 | // this DataType created to handle a different column.↵ | | 63 | // this DataType created to handle a different column.↵
|
62 | if (propertiesAlreadyLoaded == false) {↵ | | 64 | if (propertiesAlreadyLoaded == false) {↵
|
63 | // get parameters previously set by user, or set default values↵ | | 65 | // get parameters previously set by user, or set default values↵
|
64 | _readSQLOther = false; // set to the default↵ | | 66 | _readUnknown = false; // set to the default↵
|
65 | String readSQLOtherString = DTProperties.get(↵ | | 67 | String readUnknownString = DTProperties.get(↵
|
66 | thisClassName, "readSQLOther");↵ | | 68 | thisClassName, "readUnknown");↵
|
67 | if (readSQLOtherString != null && readSQLOtherString.equals("true"))↵ | | 69 | if (readUnknownString != null && readUnknownString.equals("true"))↵
|
68 | _readSQLOther = true;↵ | | 70 | _readUnknown = true;↵
|
|
69 | propertiesAlreadyLoaded = true;↵ | | 71 | propertiesAlreadyLoaded = true;↵
|
70 | }↵ | | 72 | }↵
|
71 | }↵ | | 73 | }↵
|
72 | ↵ | | 74 | ↵
|
73 | /**↵ | | 75 | /**↵
|
74 | * Return the name of the java class used to hold this data type.↵ | | 76 | * Return the name of the java class used to hold this data type.↵
|
75 | * For Other, this will always be a string.↵ | | 77 | * For Unknown, this will always be a string.↵
|
76 | */↵ | | 78 | */↵
|
77 | public String getClassName() {↵ | | 79 | public String getClassName() {↵
|
78 | return "java.lang.String";↵ | | 80 | return "java.lang.String";↵
|
79 | }↵ | | 81 | }↵
|
|
80 | /**↵ | | 82 | /**↵
|
81 | * Determine if two objects of this data type contain the same value.↵ | | 83 | * Determine if two objects of this data type contain the same value.↵
|
82 | * Neither of the objects is null↵ | | 84 | * Neither of the objects is null↵
|
83 | */↵ | | 85 | */↵
|
84 | public boolean areEqual(Object obj1, Object obj2) {↵ | | 86 | public boolean areEqual(Object obj1, Object obj2) {↵
|
85 | return ((String)obj1).equals(obj2);↵ | | 87 | return ((String)obj1).equals(obj2);↵
|
86 | }↵ | | 88 | }↵
|
87 | ↵ | | |
|
|
88 | /*↵ | | 89 | /*↵
|
89 | * First we have the cell-related and Text-table operations.↵ | | 90 | * First we have the methods for in-cell and Text-table operations↵
|
90 | */↵ | | 91 | */↵
|
91 | ↵ | | 92 | ↵
|
92 | ↵ | | 93 | ↵
|
93 | /**↵ | | 94 | /**↵
|
94 | * Render a value into text for this DataType.↵ | | 95 | * Render a value into text for this DataType.↵
|
95 | */↵ | | 96 | */↵
|
96 | public String renderObject(Object value) {↵ | | 97 | public String renderObject(Object value) {↵
|
97 | return (String)_renderer.renderObject(value);↵ | | 98 | return (String)_renderer.renderObject(value);↵
|
98 | }↵ | | 99 | }↵
|
99 | ↵ | | 100 | ↵
|
100 | /**↵ | | 101 | /**↵
|
101 | * This Data Type can be edited in a table cell.↵ | | 102 | * This Data Type can be edited in a table cell.↵
|
102 | */↵ | | 103 | */↵
|
103 | public boolean isEditableInCell(Object originalValue) {↵ | | 104 | public boolean isEditableInCell(Object originalValue) {↵
|
104 | return false;↵ | | 105 | return false; ↵
|
105 | }↵ | | 106 | }↵
|
|
106 | /**↵ | | 107 | /**↵
|
107 | * See if a value in a column has been limited in some way and↵ | | 108 | * See if a value in a column has been limited in some way and↵
|
108 | * needs to be re-read before being used for editing.↵ | | 109 | * needs to be re-read before being used for editing.↵
|
109 | * For read-only tables this may actually return true since we want↵ | | 110 | * For read-only tables this may actually return true since we want↵
|
110 | * to be able to view the entire contents of the cell even if it was not↵ | | 111 | * to be able to view the entire contents of the cell even if it was not↵
|
111 | * completely loaded during the initial table setup.↵ | | 112 | * completely loaded during the initial table setup.↵
|
112 | */↵ | | 113 | */↵
|
113 | public boolean needToReRead(Object originalValue) {↵ | | 114 | public boolean needToReRead(Object originalValue) {↵
|
114 | // this DataType does not limit the data read during the initial load of the table,↵ | | 115 | // this DataType does not limit the data read during the initial load of the table,↵
|
115 | // so there is no need to re-read the complete data later↵ | | 116 | // so there is no need to re-read the complete data later↵
|
116 | return false;↵ | | 117 | return false;↵
|
117 | }↵ | | 118 | }↵
|
118 | ↵ | | 119 | ↵
|
119 | /**↵ | | 120 | /**↵
|
120 | * Return a JTextField usable in a CellEditor.↵ | | 121 | * Return a JTextField usable in a CellEditor.↵
|
121 | */↵ | | 122 | */↵
|
122 | public JTextField getJTextField() {↵ | | 123 | public JTextField getJTextField() {↵
|
123 | _textComponent = new RestorableJTextField();↵ | | 124 | _textComponent = new RestorableJTextField();↵
|
124 | ↵ | | 125 | ↵
|
125 | // special handling of operations while editing this data type↵ | | 126 | // special handling of operations while editing this data type↵
|
126 | ((RestorableJTextField)_textComponent).addKeyListener(new KeyTextHandler());↵ | | 127 | ((RestorableJTextField)_textComponent).addKeyListener(new KeyTextHandler());↵
|
127 | ↵ | | 128 | ↵
|
128 | //↵ | | 129 | //↵
|
129 | // handle mouse events for double-click creation of popup dialog.↵ | | 130 | // handle mouse events for double-click creation of popup dialog.↵
|
130 | // This happens only in the JTextField, not the JTextArea, so we can↵ | | 131 | // This happens only in the JTextField, not the JTextArea, so we can↵
|
131 | // make this an inner class within this method rather than a separate↵ | | 132 | // make this an inner class within this method rather than a separate↵
|
132 | // inner class as is done with the KeyTextHandler class.↵ | | 133 | // inner class as is done with the KeyTextHandler class.↵
|
133 | //↵ | | 134 | //↵
|
134 | ((RestorableJTextField)_textComponent).addMouseListener(new MouseAdapter()↵ | | 135 | ((RestorableJTextField)_textComponent).addMouseListener(new MouseAdapter()↵
|
135 | {↵ | | 136 | {↵
|
136 | public void mousePressed(MouseEvent evt)↵ | | 137 | public void mousePressed(MouseEvent evt)↵
|
137 | {↵ | | 138 | {↵
|
138 | if (evt.getClickCount() == 2)↵ | | 139 | if (evt.getClickCount() == 2)↵
|
139 | {↵ | | 140 | {↵
|
140 | MouseEvent tableEvt = SwingUtilities.convertMouseEvent(↵ | | 141 | MouseEvent tableEvt = SwingUtilities.convertMouseEvent(↵
|
141 | (RestorableJTextField)DataTypeOther.this._textComponent,↵ | | 142 | (RestorableJTextField)DataTypeUnknown.this._textComponent,↵
|
142 | evt, DataTypeOther.this._table);↵ | | 143 | evt, DataTypeUnknown.this._table);↵
|
143 | CellDataPopup.showDialog(DataTypeOther.this._table,↵ | | 144 | CellDataPopup.showDialog(DataTypeUnknown.this._table,↵
|
144 | DataTypeOther.this._colDef, tableEvt, true);↵ | | 145 | DataTypeUnknown.this._colDef, tableEvt, true);↵
|
145 | }↵ | | 146 | }↵
|
146 | }↵ | | 147 | }↵
|
147 | }); // end of mouse listener↵ | | 148 | }); // end of mouse listener↵
|
|
148 | return (JTextField)_textComponent;↵ | | 149 | return (JTextField)_textComponent;↵
|
149 | }↵ | | 150 | }↵
|
150 | ↵ | | |
|
151 | /**↵ | | 151 | /**↵
|
152 | * Implement the interface for validating and converting to internal object.↵ | | 152 | * Implement the interface for validating and converting to internal object.↵
|
153 | * Since we do not know how to convert Other objects,↵ | | 153 | * Since we do not know how to convert Unknown objects,↵
|
154 | * just return null with no error in the messageBuffer↵ | | 154 | * just return null with no error in the messageBuffer↵
|
155 | */↵ | | 155 | */↵
|
156 | public Object validateAndConvert(String value, Object originalValue, StringBuffer messageBuffer) {↵ | | 156 | public Object validateAndConvert(String value, Object originalValue, StringBuffer messageBuffer) {↵
|
157 | return null;↵ | | 157 | return null;↵
|
158 | }↵ | | 158 | }↵
|
|
159 | /**↵ | | 159 | /**↵
|
160 | * If true, this tells the PopupEditableIOPanel to use the↵ | | 160 | * If true, this tells the PopupEditableIOPanel to use the↵
|
161 | * binary editing panel rather than a pure text panel.↵ | | 161 | * binary editing panel rather than a pure text panel.↵
|
162 | * The binary editing panel assumes the data is an array of bytes,↵ | | 162 | * The binary editing panel assumes the data is an array of bytes,↵
|
163 | * converts it into text form, allows the user to change how that↵ | | 163 | * converts it into text form, allows the user to change how that↵
|
164 | * data is displayed (e.g. Hex, Decimal, etc.), and converts↵ | | 164 | * data is displayed (e.g. Hex, Decimal, etc.), and converts↵
|
165 | * the data back from text to bytes when the user editing is completed.↵ | | 165 | * the data back from text to bytes when the user editing is completed.↵
|
166 | * If this returns false, this DataType class must↵ | | 166 | * If this returns false, this DataType class must↵
|
167 | * convert the internal data into a text string that↵ | | 167 | * convert the internal data into a text string that↵
|
168 | * can be displayed (and edited, if allowed) in a TextField↵ | | 168 | * can be displayed (and edited, if allowed) in a TextField↵
|
169 | * or TextArea, and must handle all↵ | | 169 | * or TextArea, and must handle all↵
|
170 | * user key strokes related to editing of that data.↵ | | 170 | * user key strokes related to editing of that data.↵
|
171 | */↵ | | 171 | */↵
|
172 | public boolean useBinaryEditingPanel() {↵ | | 172 | public boolean useBinaryEditingPanel() {↵
|
173 | return false;↵ | | 173 | return false;↵
|
174 | }↵ | | 174 | }↵
|
175 | ↵ | | 175 | ↵
|
176 | ↵ | | |
|
177 | ↵ | | |
|
178 | /*↵ | | 176 | /*↵
|
179 | * Now define the Popup-related operations.↵ | | 177 | * Now the functions for the Popup-related operations.↵
|
180 | */↵ | | 178 | */↵
|
|
181 | ↵ | | 179 | ↵
|
182 | /**↵ | | 180 | /**↵
|
183 | * Returns true if data type may be edited in the popup,↵ | | 181 | * Returns true if data type may be edited in the popup,↵
|
184 | * false if not.↵ | | 182 | * false if not.↵
|
185 | */↵ | | 183 | */↵
|
186 | public boolean isEditableInPopup(Object originalValue) {↵ | | 184 | public boolean isEditableInPopup(Object originalValue) {↵
|
187 | return false;↵ | | 185 | return false;↵
|
188 | }↵ | | 186 | }↵
|
189 | ↵ | | |
|
190 | /*↵ | | 187 | /*↵
|
191 | * Return a JTextArea usable in the CellPopupDialog↵ | | 188 | * Return a JTextArea usable in the CellPopupDialog↵
|
192 | .↵ | | 189 | * and fill in the value.↵
|
193 | */↵ | | 190 | */↵
|
194 | public JTextArea getJTextArea(Object value) {↵ | | 191 | public JTextArea getJTextArea(Object value) {↵
|
195 | _textComponent = new RestorableJTextArea();↵ | | 192 | _textComponent = new RestorableJTextArea();↵
|
196 | ↵ | | 193 | ↵
|
197 | // value is a simple string representation of the data,↵ | | 194 | // value is a simple string representation of the data,↵
|
198 | // the same one used in the Text and in-cell operations.↵ | | 195 | // the same one used in Text and in-cell operations.↵
|
199 | ((RestorableJTextArea)_textComponent).setText(renderObject(value));↵ | | 196 | ((RestorableJTextArea)_textComponent).setText(renderObject(value));↵
|
200 | ↵ | | 197 | ↵
|
201 | // special handling of operations while editing this data type↵ | | 198 | // special handling of operations while editing this data type↵
|
202 | ((RestorableJTextArea)_textComponent).addKeyListener(new KeyTextHandler());↵ | | 199 | ((RestorableJTextArea)_textComponent).addKeyListener(new KeyTextHandler());↵
|
203 | ↵ | | 200 | ↵
|
204 | return (RestorableJTextArea)_textComponent;↵ | | 201 | return (RestorableJTextArea)_textComponent;↵
|
205 | }↵ | | 202 | }↵
|
|
206 | /**↵ | | 203 | /**↵
|
207 | * Validating and converting in Popup is identical to cell-related operation.↵ | | 204 | * Validating and converting in Popup is identical to cell-related operation.↵
|
208 | */↵ | | 205 | */↵
|
209 | public Object validateAndConvertInPopup(String value, Object originalValue, StringBuffer messageBuffer) {↵ | | 206 | public Object validateAndConvertInPopup(String value, Object originalValue, StringBuffer messageBuffer) {↵
|
210 | return validateAndConvert(value, originalValue, messageBuffer);↵ | | 207 | return validateAndConvert(value, originalValue, messageBuffer);↵
|
211 | }↵ | | 208 | }↵
|
|
|
212 | /*↵ | | 209 | /*↵
|
213 | * The following is used by both in-cell and Popup operations.↵ | | 210 | * The following is used in both cell and popup operations.↵
|
214 | */↵ | | 211 | */↵
|
| | | 212 | ↵
|
215 | ↵ | | 213 | ↵
|
216 | /*↵ | | 214 | /*↵
|
217 | * Internal class for handling key events during editing↵ | | 215 | * Internal class for handling key events during editing↵
|
218 | * of both JTextField and JTextArea.↵ | | 216 | * of both JTextField and JTextArea.↵
|
219 | * Since neither cell nor popup are allowed to edit, just ignore↵ | | 217 | * Since the Unknown data type is not editable either in the Cell or ↵
|
220 | * anything seen her↵ | | 218 | in the Popup,↵
|
221 | e.↵ | | 219 | * we should never get here, but we have provided appropriate code just in case.↵
|
222 | */↵ | | 220 | */↵
|
223 | private class KeyTextHandler extends KeyAdapter {↵ | | 221 | private class KeyTextHandler extends KeyAdapter {↵
|
224 | // special handling of operations while editing Strings↵ | | 222 | ↵
|
225 | public void keyTyped(KeyEvent e) {↵ | | 223 | public void keyTyped(KeyEvent e) {↵
|
226 | // as a coding convenience, create a reference to the text component↵ | | 224 | // as a coding convenience, create a reference to the text component↵
|
227 | // that is typecast to JTextComponent. this is not essential, as we↵ | | 225 | // that is typecast to JTextComponent. this is not essential, as we↵
|
228 | // could typecast every reference, but this makes the code cleaner↵ | | 226 | // could typecast every reference, but this makes the code cleaner↵
|
229 | JTextComponent _theComponent = (JTextComponent)DataTypeOther.this._textComponent;↵ | | 227 | JTextComponent _theComponent = (JTextComponent)DataTypeUnknown.this._textComponent;↵
|
230 | e.consume();↵ | | 228 | ↵
|
231 | _beepHelper.beep(_theComponent);↵ | | 229 | _beepHelper.beep(_theComponent);↵
|
232 | ↵ | | 230 | e.consume();↵
|
233 | }↵ | | 231 | }↵
|
234 | }↵ | | 232 | }↵
|
|
|
235 | ↵ | | 233 | ↵
|
236 | ↵ | | 234 | ↵
|
237 | /*↵ | | 235 | /*↵
|
238 | * DataBase-related functions↵ | | 236 | * DataBase-related functions↵
|
239 | */↵ | | 237 | */↵
|
240 | ↵ | | 238 | ↵
|
241 | /**↵ | | 239 | /**↵
|
242 | * On input from the DB, read the data from the ResultSet into the appropriate↵ | | 240 | * On input from the DB, read the data from the ResultSet into the appropriate↵
|
243 | * type of object to be stored in the table cell.↵ | | 241 | * type of object to be stored in the table cell.↵
|
244 | */↵ | | 242 | */↵
|
245 | public Object readResultSet(ResultSet rs, int index, boolean limitDataRead)↵ | | 243 | public Object readResultSet(ResultSet rs, int index, boolean limitDataRead)↵
|
246 | throws java.sql.SQLException {↵ | | 244 | throws java.sql.SQLException {↵
|
|
247 | ↵ | | |
|
248 | String data = null;↵ | | 245 | String data = null;↵
|
249 | if (_readSQLOther)↵ | | 246 | if (_readUnknown)↵
|
250 | {↵ | | 247 | {↵
|
251 | // Running getObject on a java class attempts↵ | | 248 | // Running getObject on a java class attempts↵
|
252 | // to load the class in memory which we don't want.↵ | | 249 | // to load the class in memory which we don't want.↵
|
253 | // getString() just gets the value without loading↵ | | 250 | // getString() just gets the value without loading↵
|
254 | // the class (at least under PostgreSQL).↵ | | 251 | // the class (at least under PostgreSQL).↵
|
255 | //row[i] = _rs.getObject(index);↵ | | 252 | //row[i] = _rs.getObject(index);↵
|
256 | data = rs.getString(index);↵ | | 253 | data = rs.getString(index);↵
|
257 | }↵ | | 254 | }↵
|
258 | else↵ | | 255 | else↵
|
259 | {↵ | | 256 | {↵
|
260 | data = s_stringMgr.getString("DataTypeOther.other");↵ | | 257 | data = s_stringMgr.getString("DataType↵
|
261 | }↵ | | |
|
262 | ↵ | | |
|
263 | if (rs.wasNull())↵ | | |
|
264 | return null;↵ | | |
|
265 | else return data;↵ | | |
|
|
266 | ↵ | | |
|
267 | // String data = rs.getString(index);↵ | | |
|
268 | //↵ | | 258 | Unknown.unknown",↵
|
| | | 259 | _colDef.getSqlType() );↵
|
| | | 260 | }↵
|
| | | 261 | ↵
|
269 | if (rs.wasNull())↵ | | 262 | if (rs.wasNull())↵
|
270 | // return null;↵ | | 263 | return null;↵
|
271 | // else return data;↵ | | 264 | else return data;↵
|
272 | }↵ | | 265 | }↵
|
|
273 | /**↵ | | 266 | /**↵
|
274 | * When updating the database, generate a string form of this object value↵ | | 267 | * When updating the database, generate a string form of this object value↵
|
275 | * that can be used in the WHERE clause to match the value in the database.↵ | | 268 | * that can be used in the WHERE clause to match the value in the database.↵
|
276 | * A return value of null means that this column cannot be used in the WHERE↵ | | 269 | * A return value of null means that this column cannot be used in the WHERE↵
|
277 | * clause, while a return of "null" (or "is null", etc) means that the column↵ | | 270 | * clause, while a return of "null" (or "is null", etc) means that the column↵
|
278 | * can be used in the WHERE clause and the value is actually a null value.↵ | | 271 | * can be used in the WHERE clause and the value is actually a null value.↵
|
279 | * This function must also include the column label so that its output↵ | | 272 | * This function must also include the column label so that its output↵
|
280 | * is of the form:↵ | | 273 | * is of the form:↵
|
281 | * "columnName = value"↵ | | 274 | * "columnName = value"↵
|
282 | * or↵ | | 275 | * or↵
|
283 | * "columnName is null"↵ | | 276 | * "columnName is null"↵
|
284 | * or whatever is appropriate for this column in the database.↵ | | 277 | * or whatever is appropriate for this column in the database.↵
|
285 | */↵ | | 278 | */↵
|
286 | public String getWhereClauseValue(Object value, ISQLDatabaseMetaData md) {↵ | | 279 | public String getWhereClauseValue(Object value, ISQLDatabaseMetaData md) {↵
|
287 | if (value == null || value.toString() == null )↵ | | 280 | if (value == null || value.toString() == null || value.toString().length() == 0)↵
|
288 | return _colDef.getLabel() + " IS NULL";↵ | | 281 | return _colDef.getLabel() + " IS NULL";↵
|
289 | else↵ | | 282 | else↵
|
290 | return _colDef.getLabel() + "='" + value.toString() + "'";↵ | | 283 | return "";↵
|
291 | }↵ | | 284 | }↵
|
292 | ↵ | | 285 | ↵
|
293 | ↵ | | 286 | ↵
|
294 | /**↵ | | 287 | /**↵
|
295 | * When updating the database, insert the appropriate datatype into the↵ | | 288 | * When updating the database, insert the appropriate datatype into the↵
|
296 | * prepared statment at the given variable position.↵ | | 289 | * prepared statment at variable position 1.↵
|
297 | ↵ | | 290 | * This function should never be called for type Unknown↵
|
298 | */↵ | | 291 | */↵
|
299 | public void setPreparedStatementValue(PreparedStatement pstmt, Object value, int position)↵ | | 292 | public void setPreparedStatementValue(PreparedStatement pstmt, Object value, int position)↵
|
300 | throws java.sql.SQLException {↵ | | 293 | throws java.sql.SQLException {↵
|
|
301 | if (value == null) {↵ | | 294 | ↵
|
302 | pstmt.setNull(position, _colDef.getSqlType());↵ | | |
|
303 | }↵ | | |
|
304 | else {↵ | | |
|
305 | pstmt.setString(position, ((String)value));↵ | | |
|
306 | }↵ | | 295 | throw new java.sql.SQLException("Can not update data of type OTHER");↵
|
307 | }↵ | | 296 | }↵
|
308 | ↵ | | 297 | ↵
|
309 | /**↵ | | 298 | /**↵
|
310 | * Get a default value for the table used to input data for a new row↵ | | 299 | * Get a default value for the table used to input data for a new row↵
|
311 | * to be inserted into the DB.↵ | | 300 | * to be inserted into the DB.↵
|
312 | */↵ | | 301 | */↵
|
313 | public Object getDefaultValue(String dbDefaultValue) {↵ | | 302 | public Object getDefaultValue(String dbDefaultValue) {↵
|
314 | if (dbDefaultValue != null) {↵ | | 303 | if (dbDefaultValue != null) {↵
|
315 | // try to use the DB default value↵ | | 304 | // try to use the DB default value↵
|
316 | StringBuffer mbuf = new StringBuffer();↵ | | 305 | StringBuffer mbuf = new StringBuffer();↵
|
317 | Object newObject = validateAndConvert(dbDefaultValue, null, mbuf);↵ | | 306 | Object newObject = validateAndConvert(dbDefaultValue, null, mbuf);↵
|
318 | ↵ | | 307 | ↵
|
319 | // if there was a problem with converting, then just fall through↵ | | 308 | // if there was a problem with converting, then just fall through↵
|
320 | // and continue as if there was no default given in the DB.↵ | | 309 | // and continue as if there was no default given in the DB.↵
|
321 | // Otherwise, use the converted object↵ | | 310 | // Otherwise, use the converted object↵
|
322 | if (mbuf.length() == 0)↵ | | 311 | if (mbuf.length() == 0)↵
|
323 | return newObject;↵ | | 312 | return newObject;↵
|
324 | }↵ | | 313 | }↵
|
325 | ↵ | | 314 | ↵
|
326 | // no default in DB. If nullable, use null.↵ | | 315 | // no default in DB. If nullable, use null.↵
|
327 | if (_isNullable)↵ | | 316 | if (_isNullable)↵
|
328 | return null;↵ | | 317 | return null;↵
|
329 | ↵ | | 318 | ↵
|
330 | // field is not nullable, so create a reasonable default value↵ | | 319 | // field is not nullable, so create a reasonable default value↵
|
331 | // cannot create default value for unknown data type↵ | | 320 | // cannot create default value for unknown data type↵
|
332 | return null;↵ | | 321 | return null;↵
|
333 | }↵ | | 322 | }↵
|
334 | ↵ | | 323 | ↵
|
335 | ↵ | | 324 | ↵
|
336 | /*↵ | | 325 | /*↵
|
337 | * File IO related functions↵ | | 326 | * File IO related functions↵
|
338 | */↵ | | 327 | */↵
|
339 | ↵ | | 328 | ↵
|
340 | ↵ | | 329 | ↵
|
341 | /**↵ | | 330 | /**↵
|
342 | * Say whether or not object can be exported to and imported from↵ | | 331 | * Say whether or not object can be exported to and imported from↵
|
343 | * a file. We put both export and import together in one test↵ | | 332 | * a file. We put both export and import together in one test↵
|
344 | * on the assumption that all conversions can be done both ways.↵ | | 333 | * on the assumption that all conversions can be done both ways.↵
|
345 | ↵ | | 334 | * Since we do not understand data of type Unknown, we cannot safely↵
|
| | | 335 | * export or import it.↵
|
346 | */↵ | | 336 | */↵
|
347 | public boolean canDoFileIO() {↵ | | 337 | public boolean canDoFileIO() {↵
|
348 | return false;↵ | | 338 | return false;↵
|
349 | }↵ | | 339 | }↵
|
350 | ↵ | | 340 | ↵
|
351 | /**↵ | | 341 | /**↵
|
352 | * Read a file and construct a valid object from its contents.↵ | | 342 | * Read a file and construct a valid object from its contents.↵
|
353 | * Errors are returned by throwing an IOException containing the↵ | | 343 | * Errors are returned by throwing an IOException containing the↵
|
354 | * cause of the problem as its message.↵ | | 344 | * cause of the problem as its message.↵
|
355 | * <P>↵ | | 345 | * <P>↵
|
356 | * DataType is responsible for validating that the imported↵ | | 346 | * DataType is responsible for validating that the imported↵
|
357 | * data can be converted to an object, and then must return↵ | | 347 | * data can be converted to an object, and then must return↵
|
358 | * a text string that can be used in the Popup window text area.↵ | | 348 | * a text string that can be used in the Popup window text area.↵
|
359 | * This object-to-text conversion is the same as is done by↵ | | 349 | * This object-to-text conversion is the same as is done by↵
|
360 | * the DataType object internally in the getJTextArea() method.↵ | | 350 | * the DataType object internally in the getJTextArea() method.↵
|
361 | * ↵ | | 351 | * ↵
|
362 | * <P>↵ | | 352 | * <P>↵
|
363 | * File is assumed to be printable text characters,↵ | | 353 | * File is assumed to be ↵
|
364 | * possibly including newlines and tabs but not characters↵ | | |
|
365 | * that would require a binary representation to display↵ | | |
|
366 | * to user↵ | | 354 | and ASCII string of digits↵
|
367 | .↵ | | 355 | * representing a value of this data type.↵
|
368 | */↵ | | 356 | */↵
|
369 | public String importObject(FileInputStream inStream)↵ | | 357 | public String importObject(FileInputStream inStream)↵
|
370 | throws IOException {↵ | | 358 | throws IOException {↵
|
371 | ↵ | | 359 | ↵
|
372 | throw new IOException("Can not import data type OTHER");↵ | | 360 | throw new IOException("Can not import data type OTHER");↵
|
373 | }↵ | | 361 | }↵
|
|
374 | ↵ | | 362 | ↵
|
375 | /**↵ | | 363 | /**↵
|
376 | * Construct an appropriate external representation of the object↵ | | 364 | * Construct an appropriate external representation of the object↵
|
377 | * and write it to a file.↵ | | 365 | * and write it to a file.↵
|
378 | * Errors are returned by throwing an IOException containing the↵ | | 366 | * Errors are returned by throwing an IOException containing the↵
|
379 | * cause of the problem as its message.↵ | | 367 | * cause of the problem as its message.↵
|
380 | * <P>↵ | | 368 | * <P>↵
|
381 | * DataType is responsible for validating that the given text↵ | | 369 | * DataType is responsible for validating that the given text↵
|
382 | * text from a Popup JTextArea can be converted to an object.↵ | | 370 | * text from a Popup JTextArea can be converted to an object.↵
|
383 | * This text-to-object conversion is the same as validateAndConvertInPopup,↵ | | 371 | * This text-to-object conversion is the same as validateAndConvertInPopup,↵
|
384 | * which may be used internally by the object to do the validation.↵ | | 372 | * which may be used internally by the object to do the validation.↵
|
385 | * <P>↵ | | 373 | * <P>↵
|
386 | * The DataType object must flush and close the output stream before returning.↵ | | 374 | * The DataType object must flush and close the output stream before returning.↵
|
387 | * Typically it will create another object (e.g. an OutputWriter), and↵ | | 375 | * Typically it will create another object (e.g. an OutputWriter), and↵
|
388 | * that is the object that must be flushed and closed.↵ | | 376 | * that is the object that must be flushed and closed.↵
|
389 | * ↵ | | 377 | * ↵
|
390 | * <P>↵ | | 378 | * <P>↵
|
391 | * File is assumed to be printable text characters,↵ | | 379 | * File is assumed to be ↵
|
392 | * possibly including newlines and tabs but not characters↵ | | |
|
393 | * that would require a binary representation to display↵ | | |
|
394 | * to user↵ | | 380 | and ASCII string of digits↵
|
395 | .↵ | | 381 | * representing a value of this data type.↵
|
396 | */↵ | | 382 | */↵
|
397 | public void exportObject(FileOutputStream outStream, String text)↵ | | 383 | public void exportObject(FileOutputStream outStream, String text)↵
|
398 | throws IOException { ↵ | | 384 | throws IOException {↵
|
399 | ↵ | | 385 | ↵
|
400 | throw new IOException("Can not export data type OTHER");↵ | | 386 | throw new IOException("Can not export data type OTHER");↵
|
401 | } ↵ | | 387 | }↵
|
402 | ↵ | | |
|
|
|
|
403 | /*↵ | | 388 | /*↵
|
404 | * Property change control panel↵ | | 389 | * Property change control panel↵
|
405 | */ ↵ | | 390 | */ ↵
|
406 | ↵ | | 391 | ↵
|
407 | /**↵ | | 392 | /**↵
|
408 | * Generate a JPanel containing controls that allow the user↵ | | 393 | * Generate a JPanel containing controls that allow the user↵
|
409 | * to adjust the properties for this DataType.↵ | | 394 | * to adjust the properties for this DataType.↵
|
410 | * All properties are static accross all instances of this DataType. ↵ | | 395 | * All properties are static accross all instances of this DataType. ↵
|
411 | * However, the class may choose to apply the information differentially,↵ | | 396 | * However, the class may choose to apply the information differentially,↵
|
412 | * such as keeping a list (also entered by the user) of table/column names↵ | | 397 | * such as keeping a list (also entered by the user) of table/column names↵
|
413 | * for which certain properties should be used.↵ | | 398 | * for which certain properties should be used.↵
|
414 | * <P>↵ | | 399 | * <P>↵
|
415 | * This is called ONLY if there is at least one property entered into the DTProperties↵ | | 400 | * This is called ONLY if there is at least one property entered into the DTProperties↵
|
416 | * for this class.↵ | | 401 | * for this class.↵
|
417 | * <P>↵ | | 402 | * <P>↵
|
418 | * Since this method is called by reflection on the Method object derived from this class,↵ | | 403 | * Since this method is called by reflection on the Method object derived from this class,↵
|
419 | * it does not need to be included in the Interface.↵ | | 404 | * it does not need to be included in the Interface.↵
|
420 | * It would be nice to include this in the Interface for consistancy, documentation, etc,↵ | | 405 | * It would be nice to include this in the Interface for consistancy, documentation, etc,↵
|
421 | * but the Interface does not seem to like static methods.↵ | | 406 | * but the Interface does not seem to like static methods.↵
|
422 | */↵ | | 407 | */↵
|
423 | public static OkJPanel getControlPanel() {↵ | | 408 | public static OkJPanel getControlPanel() {↵
|
424 | ↵ | | 409 | ↵
|
425 | /*↵ | | 410 | /*↵
|
426 | * If you add this method to one of the standard DataTypes in the↵ | | 411 | * If you add this method to one of the standard DataTypes in the↵
|
427 | * fw/datasetviewer/cellcomponent directory, you must also add the name↵ | | 412 | * fw/datasetviewer/cellcomponent directory, you must also add the name↵
|
428 | * of that DataType class to the list in CellComponentFactory, method↵ | | 413 | * of that DataType class to the list in CellComponentFactory, method↵
|
429 | * getControlPanels, variable named initialClassNameList.↵ | | 414 | * getControlPanels, variable named initialClassNameList.↵
|
430 | * If the class is being registered with the factory using registerDataType,↵ | | 415 | * If the class is being registered with the factory using registerDataType,↵
|
431 | * then you should not include the class name in the list (it will be found↵ | | 416 | * then you should not include the class name in the list (it will be found↵
|
432 | * automatically), but if the DataType is part of the case statement in the↵ | | 417 | * automatically), but if the DataType is part of the case statement in the↵
|
433 | * factory method getDataTypeObject, then it does need to be explicitly listed↵ | | 418 | * factory method getDataTypeObject, then it does need to be explicitly listed↵
|
434 | * in the getControlPanels method also.↵ | | 419 | * in the getControlPanels method also.↵
|
435 | */↵ | | 420 | */↵
|
436 | ↵ | | 421 | ↵
|
437 | // if this panel is called before any instances of the class have been↵ | | 422 | // if this panel is called before any instances of the class have been↵
|
438 | // created, we need to load the properties from the DTProperties.↵ | | 423 | // created, we need to load the properties from the DTProperties.↵
|
439 | loadProperties();↵ | | 424 | loadProperties();↵
|
440 | ↵ | | 425 | ↵
|
441 | return new SQLOtherOkJPanel();↵ | | 426 | return new UnknownOkJPanel();↵
|
442 | }↵ | | 427 | }↵
|
443 | ↵ | | 428 | ↵
|
444 | ↵ | | 429 | ↵
|
445 | ↵ | | 430 | ↵
|
446 | /**↵ | | 431 | /**↵
|
447 | * Inner class that extends OkJPanel so that we can call the ok()↵ | | 432 | * Inner class that extends OkJPanel so that we can call the ok()↵
|
448 | * method to save the data when the user is happy with it.↵ | | 433 | * method to save the data when the user is happy with it.↵
|
449 | */↵ | | 434 | */↵
|
450 | private static class SQLOtherOkJPanel extends OkJPanel {↵ | | 435 | private static class UnknownOkJPanel extends OkJPanel {↵
|
|
451 | private static final long serialVersionUID = 9034966488591013288L;↵ | | 436 | private static final long serialVersionUID = ↵
|
452 | ↵ | | 437 | 1L;↵
|
453 | /*↵ | | 438 | /*↵
|
454 | * GUI components - need to be here because they need to be↵ | | 439 | * GUI components - need to be here because they need to be↵
|
455 | * accessible from the event handlers to alter each other's state.↵ | | 440 | * accessible from the event handlers to alter each other's state.↵
|
456 | */↵ | | 441 | ↵
|
457 | ↵ | | 442 | */↵
|
458 | // check box for whether to read contents during table load or not↵ | | 443 | // check box for whether to read contents during table load or not↵
|
459 | private JCheckBox _showSQLOtherChk = new JCheckBox(↵ | | 444 | private JCheckBox _showUnknownChk = new JCheckBox(↵
|
460 | // i18n[dataTypeOther.readContentsWhenLoaded=Read contents when table is first loaded and display as string]↵ | | 445 | // i18n[dataTypeUnknown.readContentsOnLoad=Read contents when table is first loaded and display as string]↵
|
461 | s_stringMgr.getString("dataTypeOther.readContentsWhenLoaded"));↵ | | 446 | s_stringMgr.getString("dataTypeUnknown.readContentsOnLoad"));↵
|
|
|
462 | public SQLOtherOkJPanel() {↵ | | 447 | public UnknownOkJPanel() {↵
|
463 | ↵ | | 448 | ↵
|
464 | /* set up the controls */↵ | | 449 | /* set up the controls */↵
|
465 | // checkbox for read/not-read on table load↵ | | 450 | // checkbox for read/not-read on table load↵
|
466 | _showSQLOtherChk.setSelected(_readSQLOther);↵ | | 451 | _showUnknownChk.setSelected(_readUnknown);↵
|
|
467 | /*↵ | | 452 | /*↵
|
468 | * Create the panel and add the GUI items to it↵ | | 453 | * Create the panel and add the GUI items to it↵
|
469 | */↵ | | 454 | */↵
|
470 | ↵ | | 455 | ↵
|
471 | ↵ | | 456 | setBorder(BorderFactory.createTitledBorder(↵
|
472 | // i18n[dataTypeOther.sqlOtherType=SQL Other (SQL type 1111)]↵ | | 457 | // i18n[dataTypeUnknown.unknownTypes=Unknown DataTypes (non-standard SQL type codes)]↵
|
473 | setBorder(BorderFactory.createTitledBorder(s_stringMgr.getString("dataTypeOther.sqlOtherType")));↵ | | 458 | s_stringMgr.getString("dataTypeUnknown.unknownTypes")));↵
|
|
474 | add(_showSQLOtherChk);↵ | | 459 | add(_showUnknownChk);↵
|
|
475 | } // end of constructor for inner class↵ | | 460 | } // end of constructor for inner class↵
|
476 | ↵ | | 461 | ↵
|
477 | ↵ | | 462 | ↵
|
478 | /**↵ | | 463 | /**↵
|
479 | * User has clicked OK in the surrounding JPanel,↵ | | 464 | * User has clicked OK in the surrounding JPanel,↵
|
480 | * so save the current state of all variables↵ | | 465 | * so save the current state of all variables↵
|
481 | */↵ | | 466 | */↵
|
482 | public void ok() {↵ | | 467 | public void ok() {↵
|
483 | // get the values from the controls and set them in the static properties↵ | | 468 | // get the values from the controls and set them in the static properties↵
|
484 | _readSQLOther = _showSQLOtherChk.isSelected();↵ | | 469 | _readUnknown = _showUnknownChk.isSelected();↵
|
485 | DTProperties.put(↵ | | 470 | DTProperties.put(↵
|
486 | thisClassName,↵ | | 471 | thisClassName,↵
|
487 | "readSQLOther", Boolean.valueOf(_readSQLOther).toString()) | | 472 | "readUnknown", Boolean.valueOf(_readUnknown).toString())
|