Lines 85-94
Link Here
|
85 |
public class ClobFieldTableCellEditor extends AbstractCellEditor |
85 |
public class ClobFieldTableCellEditor extends AbstractCellEditor |
86 |
implements TableCellEditor, |
86 |
implements TableCellEditor, |
87 |
ActionListener { |
87 |
ActionListener { |
88 |
|
88 |
|
89 |
private class CharsetSelector extends JPanel { |
89 |
private class CharsetSelector extends JPanel { |
90 |
private JComboBox charsetSelect; |
90 |
private JComboBox charsetSelect; |
91 |
|
91 |
|
92 |
CharsetSelector() { |
92 |
CharsetSelector() { |
93 |
List<Charset> charset = new ArrayList<Charset>(Charset.availableCharsets().values()); |
93 |
List<Charset> charset = new ArrayList<Charset>(Charset.availableCharsets().values()); |
94 |
Collections.sort(charset, new Comparator<Charset>() { |
94 |
Collections.sort(charset, new Comparator<Charset>() { |
Lines 102-112
Link Here
|
102 |
charsetSelect.setSelectedItem(Charset.defaultCharset()); |
102 |
charsetSelect.setSelectedItem(Charset.defaultCharset()); |
103 |
this.add(charsetSelect); |
103 |
this.add(charsetSelect); |
104 |
} |
104 |
} |
105 |
|
105 |
|
106 |
public Charset getSelectedCharset() { |
106 |
public Charset getSelectedCharset() { |
107 |
return (Charset) charsetSelect.getSelectedItem(); |
107 |
return (Charset) charsetSelect.getSelectedItem(); |
108 |
} |
108 |
} |
109 |
|
109 |
|
110 |
public void setSelectedCharset(Charset selectedCharset) { |
110 |
public void setSelectedCharset(Charset selectedCharset) { |
111 |
charsetSelect.setSelectedItem(selectedCharset); |
111 |
charsetSelect.setSelectedItem(selectedCharset); |
112 |
} |
112 |
} |
Lines 118-124
Link Here
|
118 |
protected JTable table; |
118 |
protected JTable table; |
119 |
protected int currentRow; |
119 |
protected int currentRow; |
120 |
protected int currentColumn; |
120 |
protected int currentColumn; |
121 |
|
121 |
protected JMenuItem saveContentMenuItem; |
|
|
122 |
|
122 |
public ClobFieldTableCellEditor() { |
123 |
public ClobFieldTableCellEditor() { |
123 |
button = new JButton(); |
124 |
button = new JButton(); |
124 |
button.setActionCommand(EDIT); |
125 |
button.setActionCommand(EDIT); |
Lines 130-160
Link Here
|
130 |
button.setAlignmentX(0); |
131 |
button.setAlignmentX(0); |
131 |
button.setHorizontalAlignment(SwingConstants.LEFT); |
132 |
button.setHorizontalAlignment(SwingConstants.LEFT); |
132 |
button.setFont(new Font(button.getFont().getFamily(), Font.ITALIC, 9)); |
133 |
button.setFont(new Font(button.getFont().getFamily(), Font.ITALIC, 9)); |
133 |
|
134 |
|
134 |
popup = new JPopupMenu(); |
135 |
popup = new JPopupMenu(); |
135 |
final JMenuItem miLobSaveAction = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "saveLob.title")); |
136 |
final JMenuItem miLobSaveAction = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "saveLob.title")); |
136 |
miLobSaveAction.addActionListener(new ActionListener() { |
137 |
miLobSaveAction.addActionListener(new ActionListener() { |
137 |
|
138 |
|
138 |
@Override |
139 |
@Override |
139 |
public void actionPerformed(ActionEvent e) { |
140 |
public void actionPerformed(ActionEvent e) { |
140 |
saveLobToFile(currentValue); |
141 |
saveLobToFile(currentValue); |
141 |
fireEditingCanceled(); |
142 |
fireEditingCanceled(); |
142 |
} |
143 |
} |
143 |
}); |
144 |
}); |
|
|
145 |
saveContentMenuItem = miLobSaveAction; |
144 |
popup.add(miLobSaveAction); |
146 |
popup.add(miLobSaveAction); |
145 |
final JMenuItem miLobEditAction = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "editClob.title")); |
147 |
final JMenuItem miLobEditAction = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "editClob.title")); |
146 |
miLobEditAction.addActionListener(new ActionListener() { |
148 |
miLobEditAction.addActionListener(new ActionListener() { |
147 |
|
149 |
|
148 |
@Override |
150 |
@Override |
149 |
public void actionPerformed(ActionEvent e) { |
151 |
public void actionPerformed(ActionEvent e) { |
150 |
fireEditingStopped(); |
152 |
fireEditingStopped(); |
151 |
editCell(); |
153 |
editCell(); |
152 |
} |
154 |
} |
153 |
}); |
155 |
}); |
154 |
popup.add(miLobEditAction); |
156 |
popup.add(miLobEditAction); |
155 |
final JMenuItem miLobLoadAction = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "loadLob.title")); |
157 |
final JMenuItem miLobLoadAction = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "loadLob.title")); |
156 |
miLobLoadAction.addActionListener(new ActionListener() { |
158 |
miLobLoadAction.addActionListener(new ActionListener() { |
157 |
|
159 |
|
158 |
@Override |
160 |
@Override |
159 |
public void actionPerformed(ActionEvent e) { |
161 |
public void actionPerformed(ActionEvent e) { |
160 |
Object newValue = loadLobFromFile(); |
162 |
Object newValue = loadLobFromFile(); |
Lines 167-173
Link Here
|
167 |
popup.add(miLobLoadAction); |
169 |
popup.add(miLobLoadAction); |
168 |
final JMenuItem miLobNullAction = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "nullLob.title")); |
170 |
final JMenuItem miLobNullAction = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "nullLob.title")); |
169 |
miLobNullAction.addActionListener(new ActionListener() { |
171 |
miLobNullAction.addActionListener(new ActionListener() { |
170 |
|
172 |
|
171 |
@Override |
173 |
@Override |
172 |
public void actionPerformed(ActionEvent e) { |
174 |
public void actionPerformed(ActionEvent e) { |
173 |
currentValue = null; |
175 |
currentValue = null; |
Lines 175-194
Link Here
|
175 |
} |
177 |
} |
176 |
}); |
178 |
}); |
177 |
popup.add(miLobNullAction); |
179 |
popup.add(miLobNullAction); |
178 |
|
180 |
|
179 |
} |
181 |
} |
180 |
|
182 |
|
181 |
@Override |
183 |
@Override |
182 |
public void actionPerformed(ActionEvent e) { |
184 |
public void actionPerformed(ActionEvent e) { |
183 |
if (EDIT.equals(e.getActionCommand())) { |
185 |
if (EDIT.equals(e.getActionCommand())) { |
184 |
popup.show(button, 0, button.getHeight()); |
186 |
popup.show(button, 0, button.getHeight()); |
185 |
} |
187 |
} |
186 |
} |
188 |
} |
187 |
|
189 |
|
188 |
@Override |
190 |
@Override |
189 |
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
191 |
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
190 |
currentValue = (java.sql.Clob) value; |
192 |
currentValue = (java.sql.Clob) value; |
191 |
if (currentValue != null) { |
193 |
if (currentValue != null) { |
|
|
194 |
saveContentMenuItem.setEnabled(true); |
192 |
try { |
195 |
try { |
193 |
long size = currentValue.length(); |
196 |
long size = currentValue.length(); |
194 |
StringBuilder stringValue = new StringBuilder(); |
197 |
StringBuilder stringValue = new StringBuilder(); |
Lines 206-211
Link Here
|
206 |
button.setText("<CLOB of unknown size>"); |
209 |
button.setText("<CLOB of unknown size>"); |
207 |
} |
210 |
} |
208 |
} else { |
211 |
} else { |
|
|
212 |
saveContentMenuItem.setEnabled(false); |
209 |
button.setText("<NULL>"); |
213 |
button.setText("<NULL>"); |
210 |
} |
214 |
} |
211 |
this.currentColumn = column; |
215 |
this.currentColumn = column; |
Lines 213-224
Link Here
|
213 |
this.table = table; |
217 |
this.table = table; |
214 |
return button; |
218 |
return button; |
215 |
} |
219 |
} |
216 |
|
220 |
|
217 |
@Override |
221 |
@Override |
218 |
public Object getCellEditorValue() { |
222 |
public Object getCellEditorValue() { |
219 |
return currentValue; |
223 |
return currentValue; |
220 |
} |
224 |
} |
221 |
|
225 |
|
222 |
@Override |
226 |
@Override |
223 |
public boolean isCellEditable(EventObject anEvent) { |
227 |
public boolean isCellEditable(EventObject anEvent) { |
224 |
if (anEvent instanceof MouseEvent) { |
228 |
if (anEvent instanceof MouseEvent) { |
Lines 226-233
Link Here
|
226 |
} |
230 |
} |
227 |
return super.isCellEditable(anEvent); |
231 |
return super.isCellEditable(anEvent); |
228 |
} |
232 |
} |
229 |
|
233 |
|
230 |
private void saveLobToFile(Clob b) { |
234 |
private void saveLobToFile(Clob b) { |
|
|
235 |
if (b == null) { |
236 |
return; |
237 |
} |
231 |
CharsetSelector charset = new CharsetSelector(); |
238 |
CharsetSelector charset = new CharsetSelector(); |
232 |
JFileChooser c = new JFileChooser(); |
239 |
JFileChooser c = new JFileChooser(); |
233 |
c.setAccessory(charset); |
240 |
c.setAccessory(charset); |
Lines 239-245
Link Here
|
239 |
try { |
246 |
try { |
240 |
r = b.getCharacterStream(); |
247 |
r = b.getCharacterStream(); |
241 |
w = new OutputStreamWriter(new FileOutputStream(f), charset.getSelectedCharset()); |
248 |
w = new OutputStreamWriter(new FileOutputStream(f), charset.getSelectedCharset()); |
242 |
if(! doTransfer(r, w, (int) b.length(), "Save to file: " + f.toString(), false)) { |
249 |
if (!doTransfer(r, w, (int) b.length(), "Save to file: " + f.toString(), false)) { |
243 |
f.delete(); |
250 |
f.delete(); |
244 |
} |
251 |
} |
245 |
} catch (IOException ex) { |
252 |
} catch (IOException ex) { |
Lines 249-255
Link Here
|
249 |
} |
256 |
} |
250 |
} |
257 |
} |
251 |
} |
258 |
} |
252 |
|
259 |
|
253 |
private Clob loadLobFromFile() { |
260 |
private Clob loadLobFromFile() { |
254 |
CharsetSelector charset = new CharsetSelector(); |
261 |
CharsetSelector charset = new CharsetSelector(); |
255 |
JFileChooser c = new JFileChooser(); |
262 |
JFileChooser c = new JFileChooser(); |
Lines 262-268
Link Here
|
262 |
try { |
269 |
try { |
263 |
result = new FileBackedClob(); |
270 |
result = new FileBackedClob(); |
264 |
r = new InputStreamReader(new FileInputStream(f), charset.getSelectedCharset()); |
271 |
r = new InputStreamReader(new FileInputStream(f), charset.getSelectedCharset()); |
265 |
if(! doTransfer(r, result.setCharacterStream(1), (int) f.length() / 2, "Load from file: " + f.toString(), true)) { |
272 |
if (!doTransfer(r, result.setCharacterStream(1), (int) f.length() / 2, "Load from file: " + f.toString(), true)) { |
266 |
result = null; |
273 |
result = null; |
267 |
} |
274 |
} |
268 |
} catch (IOException ex) { |
275 |
} catch (IOException ex) { |
Lines 275-281
Link Here
|
275 |
} |
282 |
} |
276 |
|
283 |
|
277 |
/** |
284 |
/** |
278 |
* @return true if transfer is complete and not iterrupted |
285 |
* @return true if transfer is complete and not iterrupted |
279 |
*/ |
286 |
*/ |
280 |
private boolean doTransfer(Reader in, Writer out, Integer size, String title, boolean sizeEstimated) throws IOException { |
287 |
private boolean doTransfer(Reader in, Writer out, Integer size, String title, boolean sizeEstimated) throws IOException { |
281 |
// Only pass size if it is _not_ estimated |
288 |
// Only pass size if it is _not_ estimated |
Lines 296-302
Link Here
|
296 |
} |
303 |
} |
297 |
return !ft.isCancel(); |
304 |
return !ft.isCancel(); |
298 |
} |
305 |
} |
299 |
|
306 |
|
300 |
protected void editCell() { |
307 |
protected void editCell() { |
301 |
String stringVal = ""; |
308 |
String stringVal = ""; |
302 |
if (currentValue != null) { |
309 |
if (currentValue != null) { |
Lines 304-320
Link Here
|
304 |
stringVal = currentValue.getSubString(1, (int) currentValue.length()); |
311 |
stringVal = currentValue.getSubString(1, (int) currentValue.length()); |
305 |
} catch (SQLException ex) { |
312 |
} catch (SQLException ex) { |
306 |
} |
313 |
} |
307 |
|
314 |
|
308 |
} |
315 |
} |
309 |
|
316 |
|
310 |
JTextArea textArea = new JTextArea(10, 50); |
317 |
JTextArea textArea = new JTextArea(10, 50); |
311 |
textArea.setText(stringVal); |
318 |
textArea.setText(stringVal); |
312 |
textArea.setCaretPosition(0); |
319 |
textArea.setCaretPosition(0); |
313 |
textArea.setEditable(table.isCellEditable(currentRow, currentColumn)); |
320 |
textArea.setEditable(table.isCellEditable(currentRow, currentColumn)); |
314 |
|
321 |
|
315 |
JScrollPane pane = new JScrollPane(textArea); |
322 |
JScrollPane pane = new JScrollPane(textArea); |
316 |
Component parent = WindowManager.getDefault().getMainWindow(); |
323 |
Component parent = WindowManager.getDefault().getMainWindow(); |
317 |
|
324 |
|
318 |
if (table.isCellEditable(currentRow, currentColumn)) { |
325 |
if (table.isCellEditable(currentRow, currentColumn)) { |
319 |
int result = JOptionPane.showOptionDialog(parent, pane, table.getColumnName(currentColumn), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); |
326 |
int result = JOptionPane.showOptionDialog(parent, pane, table.getColumnName(currentColumn), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); |
320 |
if (result == JOptionPane.OK_OPTION) { |
327 |
if (result == JOptionPane.OK_OPTION) { |