Lines 73-78
Link Here
|
73 |
import javax.swing.JTable; |
73 |
import javax.swing.JTable; |
74 |
import javax.swing.SwingConstants; |
74 |
import javax.swing.SwingConstants; |
75 |
import javax.swing.table.TableCellEditor; |
75 |
import javax.swing.table.TableCellEditor; |
|
|
76 |
import org.netbeans.api.progress.ProgressUtils; |
76 |
import org.netbeans.modules.db.dataview.util.FileBackedClob; |
77 |
import org.netbeans.modules.db.dataview.util.FileBackedClob; |
77 |
import org.openide.util.Exceptions; |
78 |
import org.openide.util.Exceptions; |
78 |
import org.openide.util.NbBundle; |
79 |
import org.openide.util.NbBundle; |
Lines 83-89
Link Here
|
83 |
|
84 |
|
84 |
private class CharsetSelector extends JPanel { |
85 |
private class CharsetSelector extends JPanel { |
85 |
private JComboBox charsetSelect; |
86 |
private JComboBox charsetSelect; |
86 |
|
87 |
|
87 |
CharsetSelector() { |
88 |
CharsetSelector() { |
88 |
List<Charset> charset = new ArrayList<Charset>(Charset.availableCharsets().values()); |
89 |
List<Charset> charset = new ArrayList<Charset>(Charset.availableCharsets().values()); |
89 |
Collections.sort(charset, new Comparator<Charset>() { |
90 |
Collections.sort(charset, new Comparator<Charset>() { |
Lines 106-112
Link Here
|
106 |
charsetSelect.setSelectedItem(selectedCharset); |
107 |
charsetSelect.setSelectedItem(selectedCharset); |
107 |
} |
108 |
} |
108 |
} |
109 |
} |
109 |
|
|
|
110 |
protected static final String EDIT = "edit"; |
110 |
protected static final String EDIT = "edit"; |
111 |
protected Clob currentValue; |
111 |
protected Clob currentValue; |
112 |
protected JButton button; |
112 |
protected JButton button; |
Lines 207-213
Link Here
|
207 |
} |
207 |
} |
208 |
return super.isCellEditable(anEvent); |
208 |
return super.isCellEditable(anEvent); |
209 |
} |
209 |
} |
210 |
|
210 |
|
211 |
private void saveLobToFile(Clob b) { |
211 |
private void saveLobToFile(Clob b) { |
212 |
CharsetSelector charset = new CharsetSelector(); |
212 |
CharsetSelector charset = new CharsetSelector(); |
213 |
JFileChooser c = new JFileChooser(); |
213 |
JFileChooser c = new JFileChooser(); |
Lines 220-249
Link Here
|
220 |
try { |
220 |
try { |
221 |
r = b.getCharacterStream(); |
221 |
r = b.getCharacterStream(); |
222 |
w = new OutputStreamWriter(new FileOutputStream(f), charset.getSelectedCharset()); |
222 |
w = new OutputStreamWriter(new FileOutputStream(f), charset.getSelectedCharset()); |
223 |
int read = 0; |
223 |
if(! doTransfer(r, w, (int) b.length(), "Save to file: " + f.toString(), false)) { |
224 |
char[] buffer = new char[1024]; |
224 |
f.delete(); |
225 |
while((read = r.read(buffer)) > 0) { |
|
|
226 |
w.write(buffer, 0, read); |
227 |
} |
225 |
} |
228 |
} catch (IOException ex) { |
226 |
} catch (IOException ex) { |
229 |
throw new RuntimeException(ex); |
227 |
throw new RuntimeException(ex); |
230 |
} catch (SQLException ex) { |
228 |
} catch (SQLException ex) { |
231 |
throw new RuntimeException(ex); |
229 |
throw new RuntimeException(ex); |
232 |
} finally { |
|
|
233 |
try { |
234 |
if(w != null) w.close(); |
235 |
} catch (IOException ex) { |
236 |
Exceptions.printStackTrace(ex); |
237 |
} |
238 |
try { |
239 |
if(r != null) r.close(); |
240 |
} catch (IOException ex) { |
241 |
Exceptions.printStackTrace(ex); |
242 |
} |
243 |
} |
230 |
} |
244 |
} |
231 |
} |
245 |
} |
232 |
} |
246 |
|
233 |
|
247 |
private Clob loadLobFromFile() { |
234 |
private Clob loadLobFromFile() { |
248 |
CharsetSelector charset = new CharsetSelector(); |
235 |
CharsetSelector charset = new CharsetSelector(); |
249 |
JFileChooser c = new JFileChooser(); |
236 |
JFileChooser c = new JFileChooser(); |
Lines 254-273
Link Here
|
254 |
File f = c.getSelectedFile(); |
241 |
File f = c.getSelectedFile(); |
255 |
Reader r = null; |
242 |
Reader r = null; |
256 |
try { |
243 |
try { |
|
|
244 |
result = new FileBackedClob(); |
257 |
r = new InputStreamReader(new FileInputStream(f), charset.getSelectedCharset()); |
245 |
r = new InputStreamReader(new FileInputStream(f), charset.getSelectedCharset()); |
258 |
result = new FileBackedClob(r); |
246 |
if(! doTransfer(r, result.setCharacterStream(1), (int) f.length() / 2, "Load from file: " + f.toString(), true)) { |
|
|
247 |
result = null; |
248 |
} |
259 |
} catch (IOException ex) { |
249 |
} catch (IOException ex) { |
260 |
throw new RuntimeException(ex); |
250 |
throw new RuntimeException(ex); |
261 |
} catch (SQLException ex) { |
251 |
} catch (SQLException ex) { |
262 |
throw new RuntimeException(ex); |
252 |
throw new RuntimeException(ex); |
263 |
} finally { |
|
|
264 |
try { |
265 |
if(r != null) r.close(); |
266 |
} catch (IOException ex) { |
267 |
Exceptions.printStackTrace(ex); |
268 |
} |
269 |
} |
253 |
} |
270 |
} |
254 |
} |
271 |
return result; |
255 |
return result; |
272 |
} |
256 |
} |
|
|
257 |
|
258 |
/** |
259 |
* @return true if transfer is complete and not iterrupted |
260 |
*/ |
261 |
private boolean doTransfer(Reader in, Writer out, Integer size, String title, boolean sizeEstimated) throws IOException { |
262 |
// Only pass size if it is _not_ estimated |
263 |
MonitorableCharacterStreamTransfer ft = new MonitorableCharacterStreamTransfer(in, out, sizeEstimated ? null : size); |
264 |
Throwable t = null; |
265 |
// Only show dialog, if the filesize is large enougth and has a use for the user |
266 |
if (size == null || size > (1024 * 1024)) { |
267 |
t = ProgressUtils.showProgressDialogAndRun(ft, title, false); |
268 |
} else { |
269 |
t = ft.run(null); |
270 |
} |
271 |
if (t != null && t instanceof RuntimeException) { |
272 |
throw (RuntimeException) t; |
273 |
} else if (t != null && t instanceof IOException) { |
274 |
throw (IOException) t; |
275 |
} else if (t != null) { |
276 |
throw new RuntimeException(t); |
277 |
} |
278 |
return ! ft.isCancel(); |
279 |
} |
273 |
} |
280 |
} |