This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 206233
Collapse All | Expand All

(-)a/db.dataview/src/org/netbeans/modules/db/dataview/table/celleditor/Bundle.properties (+1 lines)
Lines 41-46 Link Here
41
nullLob.title=Set to NULL
41
nullLob.title=Set to NULL
42
saveLob.title=Save to file
42
saveLob.title=Save to file
43
loadLob.title=Set from file
43
loadLob.title=Set from file
44
editClob.title=Edit data
44
loadLob.sourceNotReadable=Source file can't be read.\nCheck file/directory permissions.
45
loadLob.sourceNotReadable=Source file can't be read.\nCheck file/directory permissions.
45
saveLob.unknownFormat=Unknown Format for Lob-Handling
46
saveLob.unknownFormat=Unknown Format for Lob-Handling
46
saveLob.targetNotWriteable=Target file can't be written.\nCheck file/directory permissions.
47
saveLob.targetNotWriteable=Target file can't be written.\nCheck file/directory permissions.
(-)a/db.dataview/src/org/netbeans/modules/db/dataview/table/celleditor/ClobFieldTableCellEditor.java (-20 / +71 lines)
Lines 68-90 Link Here
68
import javax.swing.JComboBox;
68
import javax.swing.JComboBox;
69
import javax.swing.JFileChooser;
69
import javax.swing.JFileChooser;
70
import javax.swing.JMenuItem;
70
import javax.swing.JMenuItem;
71
import javax.swing.JOptionPane;
71
import javax.swing.JPanel;
72
import javax.swing.JPanel;
72
import javax.swing.JPopupMenu;
73
import javax.swing.JPopupMenu;
74
import javax.swing.JScrollPane;
73
import javax.swing.JTable;
75
import javax.swing.JTable;
76
import javax.swing.JTextArea;
74
import javax.swing.SwingConstants;
77
import javax.swing.SwingConstants;
75
import javax.swing.table.TableCellEditor;
78
import javax.swing.table.TableCellEditor;
76
import org.netbeans.api.progress.ProgressUtils;
79
import org.netbeans.api.progress.ProgressUtils;
77
import org.netbeans.modules.db.dataview.util.FileBackedClob;
80
import org.netbeans.modules.db.dataview.util.FileBackedClob;
78
import org.openide.util.Exceptions;
81
import org.openide.util.Exceptions;
79
import org.openide.util.NbBundle;
82
import org.openide.util.NbBundle;
83
import org.openide.windows.WindowManager;
80
84
81
public class ClobFieldTableCellEditor extends AbstractCellEditor
85
public class ClobFieldTableCellEditor extends AbstractCellEditor
82
        implements TableCellEditor,
86
        implements TableCellEditor,
83
        ActionListener {
87
        ActionListener {
84
88
    
85
    private class CharsetSelector extends JPanel {
89
    private class CharsetSelector extends JPanel {
86
        private JComboBox charsetSelect;
90
        private JComboBox charsetSelect;
87
91
        
88
        CharsetSelector() {
92
        CharsetSelector() {
89
            List<Charset> charset = new ArrayList<Charset>(Charset.availableCharsets().values());
93
            List<Charset> charset = new ArrayList<Charset>(Charset.availableCharsets().values());
90
            Collections.sort(charset, new Comparator<Charset>() {
94
            Collections.sort(charset, new Comparator<Charset>() {
Lines 98-108 Link Here
98
            charsetSelect.setSelectedItem(Charset.defaultCharset());
102
            charsetSelect.setSelectedItem(Charset.defaultCharset());
99
            this.add(charsetSelect);
103
            this.add(charsetSelect);
100
        }
104
        }
101
105
        
102
        public Charset getSelectedCharset() {
106
        public Charset getSelectedCharset() {
103
            return (Charset) charsetSelect.getSelectedItem();
107
            return (Charset) charsetSelect.getSelectedItem();
104
        }
108
        }
105
109
        
106
        public void setSelectedCharset(Charset selectedCharset) {
110
        public void setSelectedCharset(Charset selectedCharset) {
107
            charsetSelect.setSelectedItem(selectedCharset);
111
            charsetSelect.setSelectedItem(selectedCharset);
108
        }
112
        }
Lines 112-118 Link Here
112
    protected JButton button;
116
    protected JButton button;
113
    protected JPopupMenu popup;
117
    protected JPopupMenu popup;
114
    protected JTable table;
118
    protected JTable table;
115
119
    protected int currentRow;
120
    protected int currentColumn;
121
    
116
    public ClobFieldTableCellEditor() {
122
    public ClobFieldTableCellEditor() {
117
        button = new JButton();
123
        button = new JButton();
118
        button.setActionCommand(EDIT);
124
        button.setActionCommand(EDIT);
Lines 124-134 Link Here
124
        button.setAlignmentX(0);
130
        button.setAlignmentX(0);
125
        button.setHorizontalAlignment(SwingConstants.LEFT);
131
        button.setHorizontalAlignment(SwingConstants.LEFT);
126
        button.setFont(new Font(button.getFont().getFamily(), Font.ITALIC, 9));
132
        button.setFont(new Font(button.getFont().getFamily(), Font.ITALIC, 9));
127
133
        
128
        popup = new JPopupMenu();
134
        popup = new JPopupMenu();
129
        final JMenuItem miLobSaveAction = new JMenuItem(NbBundle.getMessage(BlobFieldTableCellEditor.class, "saveLob.title"));
135
        final JMenuItem miLobSaveAction = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "saveLob.title"));
130
        miLobSaveAction.addActionListener(new ActionListener() {
136
        miLobSaveAction.addActionListener(new ActionListener() {
131
137
            
132
            @Override
138
            @Override
133
            public void actionPerformed(ActionEvent e) {
139
            public void actionPerformed(ActionEvent e) {
134
                saveLobToFile(currentValue);
140
                saveLobToFile(currentValue);
Lines 136-144 Link Here
136
            }
142
            }
137
        });
143
        });
138
        popup.add(miLobSaveAction);
144
        popup.add(miLobSaveAction);
139
        final JMenuItem miLobLoadAction = new JMenuItem(NbBundle.getMessage(BlobFieldTableCellEditor.class, "loadLob.title"));
145
        final JMenuItem miLobEditAction = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "editClob.title"));
146
        miLobEditAction.addActionListener(new ActionListener() {
147
            
148
            @Override
149
            public void actionPerformed(ActionEvent e) {
150
                fireEditingStopped();
151
                editCell();
152
            }
153
        });
154
        popup.add(miLobEditAction);                
155
        final JMenuItem miLobLoadAction = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "loadLob.title"));
140
        miLobLoadAction.addActionListener(new ActionListener() {
156
        miLobLoadAction.addActionListener(new ActionListener() {
141
157
            
142
            @Override
158
            @Override
143
            public void actionPerformed(ActionEvent e) {
159
            public void actionPerformed(ActionEvent e) {
144
                Object newValue = loadLobFromFile();
160
                Object newValue = loadLobFromFile();
Lines 149-157 Link Here
149
            }
165
            }
150
        });
166
        });
151
        popup.add(miLobLoadAction);
167
        popup.add(miLobLoadAction);
152
        final JMenuItem miLobNullAction = new JMenuItem(NbBundle.getMessage(BlobFieldTableCellEditor.class, "nullLob.title"));
168
        final JMenuItem miLobNullAction = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "nullLob.title"));
153
        miLobNullAction.addActionListener(new ActionListener() {
169
        miLobNullAction.addActionListener(new ActionListener() {
154
170
            
155
            @Override
171
            @Override
156
            public void actionPerformed(ActionEvent e) {
172
            public void actionPerformed(ActionEvent e) {
157
                currentValue = null;
173
                currentValue = null;
Lines 159-173 Link Here
159
            }
175
            }
160
        });
176
        });
161
        popup.add(miLobNullAction);
177
        popup.add(miLobNullAction);
162
178
        
163
    }
179
    }
164
180
    
181
    @Override
165
    public void actionPerformed(ActionEvent e) {
182
    public void actionPerformed(ActionEvent e) {
166
        if (EDIT.equals(e.getActionCommand())) {
183
        if (EDIT.equals(e.getActionCommand())) {
167
            popup.show(button, 0, button.getHeight());
184
            popup.show(button, 0, button.getHeight());
168
        }
185
        }
169
    }
186
    }
170
187
    
171
    @Override
188
    @Override
172
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
189
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
173
        currentValue = (java.sql.Clob) value;
190
        currentValue = (java.sql.Clob) value;
Lines 191-205 Link Here
191
        } else {
208
        } else {
192
            button.setText("<NULL>");
209
            button.setText("<NULL>");
193
        }
210
        }
211
        this.currentColumn = column;
212
        this.currentRow = row;
194
        this.table = table;
213
        this.table = table;
195
        return button;
214
        return button;
196
    }
215
    }
197
216
    
198
    @Override
217
    @Override
199
    public Object getCellEditorValue() {
218
    public Object getCellEditorValue() {
200
        return currentValue;
219
        return currentValue;
201
    }
220
    }
202
221
    
203
    @Override
222
    @Override
204
    public boolean isCellEditable(EventObject anEvent) {
223
    public boolean isCellEditable(EventObject anEvent) {
205
        if (anEvent instanceof MouseEvent) {
224
        if (anEvent instanceof MouseEvent) {
Lines 207-213 Link Here
207
        }
226
        }
208
        return super.isCellEditable(anEvent);
227
        return super.isCellEditable(anEvent);
209
    }
228
    }
210
229
    
211
    private void saveLobToFile(Clob b) {
230
    private void saveLobToFile(Clob b) {
212
        CharsetSelector charset = new CharsetSelector();
231
        CharsetSelector charset = new CharsetSelector();
213
        JFileChooser c = new JFileChooser();
232
        JFileChooser c = new JFileChooser();
Lines 230-236 Link Here
230
            }
249
            }
231
        }
250
        }
232
    }
251
    }
233
252
    
234
    private Clob loadLobFromFile() {
253
    private Clob loadLobFromFile() {
235
        CharsetSelector charset = new CharsetSelector();
254
        CharsetSelector charset = new CharsetSelector();
236
        JFileChooser c = new JFileChooser();
255
        JFileChooser c = new JFileChooser();
Lines 275-280 Link Here
275
        } else if (t != null) {
294
        } else if (t != null) {
276
            throw new RuntimeException(t);
295
            throw new RuntimeException(t);
277
        }
296
        }
278
        return ! ft.isCancel();
297
        return !ft.isCancel();
298
    }
299
    
300
    protected void editCell() {
301
        String stringVal = "";
302
        if (currentValue != null) {
303
            try {
304
                stringVal = currentValue.getSubString(1, (int) currentValue.length());
305
            } catch (SQLException ex) {
306
            }
307
            
308
        }
309
        
310
        JTextArea textArea = new JTextArea(10, 50);
311
        textArea.setText(stringVal);
312
        textArea.setCaretPosition(0);
313
        textArea.setEditable(table.isCellEditable(currentRow, currentColumn));
314
        
315
        JScrollPane pane = new JScrollPane(textArea);
316
        Component parent = WindowManager.getDefault().getMainWindow();
317
        
318
        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);
320
            if (result == JOptionPane.OK_OPTION) {
321
                try {
322
                    table.setValueAt(new FileBackedClob(textArea.getText()), currentRow, currentColumn);
323
                } catch (SQLException ex) {
324
                    Exceptions.printStackTrace(ex);
325
                }
326
            }
327
        } else {
328
            JOptionPane.showMessageDialog(parent, pane, table.getColumnName(currentColumn), JOptionPane.PLAIN_MESSAGE, null);
329
        }
279
    }
330
    }
280
}
331
}

Return to bug 206233