--- a/db.dataview/src/org/netbeans/modules/db/dataview/table/ResultSetJXTable.java +++ a/db.dataview/src/org/netbeans/modules/db/dataview/table/ResultSetJXTable.java @@ -301,6 +301,9 @@ @Override public boolean isCellEditable(int row, int column) { + if(getCellEditor(row, column) instanceof AlwaysEnable) { + return true; + } if(getModel() != null) { int modelRow = convertRowIndexToModel(row); int modelColumn = convertColumnIndexToModel(column); --- a/db.dataview/src/org/netbeans/modules/db/dataview/table/celleditor/AlwaysEnable.java +++ a/db.dataview/src/org/netbeans/modules/db/dataview/table/celleditor/AlwaysEnable.java @@ -0,0 +1,54 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.db.dataview.table.celleditor; + +/** + * Marker interface for CellEditors that should be enabled even if TableModel is + * not editable. + * + * It is expected that the CellEditor handles unmodifiable models itself + * + * @author Matthias Bläsing + */ +public interface AlwaysEnable { + +} --- a/db.dataview/src/org/netbeans/modules/db/dataview/table/celleditor/BlobFieldTableCellEditor.java +++ a/db.dataview/src/org/netbeans/modules/db/dataview/table/celleditor/BlobFieldTableCellEditor.java @@ -71,7 +71,7 @@ public class BlobFieldTableCellEditor extends AbstractCellEditor implements TableCellEditor, - ActionListener { + ActionListener, AlwaysEnable { private static final Logger LOG = Logger.getLogger( BlobFieldTableCellEditor.class.getName()); @@ -82,6 +82,8 @@ protected JTable table; protected JMenuItem saveContentMenuItem; protected JMenuItem miOpenImageMenuItem; + protected JMenuItem miLobLoadAction; + protected JMenuItem miLobNullAction; @SuppressWarnings("LeakingThisInConstructor") public BlobFieldTableCellEditor() { @@ -97,8 +99,8 @@ button.setFont(new Font(button.getFont().getFamily(), Font.ITALIC, 9)); popup = new JPopupMenu(); - final JMenuItem miLobSaveAction = new JMenuItem(NbBundle.getMessage(BlobFieldTableCellEditor.class, "saveLob.title")); - miLobSaveAction.addActionListener(new ActionListener() { + saveContentMenuItem = new JMenuItem(NbBundle.getMessage(BlobFieldTableCellEditor.class, "saveLob.title")); + saveContentMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -106,11 +108,10 @@ fireEditingCanceled(); } }); - saveContentMenuItem = miLobSaveAction; - popup.add(miLobSaveAction); + popup.add(saveContentMenuItem); - final JMenuItem miOpenImageAction = new JMenuItem("Open as Image"); - miOpenImageAction.addActionListener(new ActionListener() { + miOpenImageMenuItem = new JMenuItem("Open as Image"); + miOpenImageMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -118,10 +119,9 @@ fireEditingCanceled(); } }); - miOpenImageMenuItem = miOpenImageAction; - popup.add(miOpenImageAction); + popup.add(miOpenImageMenuItem); - final JMenuItem miLobLoadAction = new JMenuItem(NbBundle.getMessage(BlobFieldTableCellEditor.class, "loadLob.title")); + miLobLoadAction = new JMenuItem(NbBundle.getMessage(BlobFieldTableCellEditor.class, "loadLob.title")); miLobLoadAction.addActionListener(new ActionListener() { @Override @@ -134,7 +134,7 @@ } }); popup.add(miLobLoadAction); - final JMenuItem miLobNullAction = new JMenuItem(NbBundle.getMessage(BlobFieldTableCellEditor.class, "nullLob.title")); + miLobNullAction = new JMenuItem(NbBundle.getMessage(BlobFieldTableCellEditor.class, "nullLob.title")); miLobNullAction.addActionListener(new ActionListener() { @Override @@ -157,6 +157,9 @@ @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { currentValue = (java.sql.Blob) value; + int modelRow = table.convertRowIndexToModel(row); + int modelColumn = table.convertColumnIndexToModel(column); + boolean editable = table.getModel().isCellEditable(modelRow, modelColumn); if (currentValue != null) { saveContentMenuItem.setEnabled(true); miOpenImageMenuItem.setEnabled(true); @@ -181,6 +184,8 @@ miOpenImageMenuItem.setEnabled(false); button.setText(""); } + miLobLoadAction.setEnabled(editable); + miLobNullAction.setEnabled(editable); this.table = table; return button; } --- a/db.dataview/src/org/netbeans/modules/db/dataview/table/celleditor/Bundle.properties +++ a/db.dataview/src/org/netbeans/modules/db/dataview/table/celleditor/Bundle.properties @@ -42,6 +42,7 @@ saveLob.title=Save to file loadLob.title=Read from file editClob.title=Edit data +editClobReadOnly.title=Show data loadLob.sourceNotReadable=Source file can't be read.\nCheck file/directory permissions. saveLob.unknownFormat=Unknown Format for Lob-Handling 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 +++ a/db.dataview/src/org/netbeans/modules/db/dataview/table/celleditor/ClobFieldTableCellEditor.java @@ -65,7 +65,7 @@ public class ClobFieldTableCellEditor extends AbstractCellEditor implements TableCellEditor, - ActionListener { + ActionListener, AlwaysEnable { private class CharsetSelector extends JPanel { private JComboBox charsetSelect; @@ -102,7 +102,12 @@ protected JTable table; protected int currentRow; protected int currentColumn; + protected int currentModelRow; + protected int currentModelColumn; protected JMenuItem saveContentMenuItem; + protected JMenuItem editContentMenuItem; + protected JMenuItem loadContentMenuItem; + protected JMenuItem nullContentMenuItem; @SuppressWarnings("LeakingThisInConstructor") public ClobFieldTableCellEditor() { @@ -118,8 +123,8 @@ button.setFont(new Font(button.getFont().getFamily(), Font.ITALIC, 9)); popup = new JPopupMenu(); - final JMenuItem miLobSaveAction = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "saveLob.title")); - miLobSaveAction.addActionListener(new ActionListener() { + saveContentMenuItem = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "saveLob.title")); + saveContentMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -127,10 +132,9 @@ fireEditingCanceled(); } }); - saveContentMenuItem = miLobSaveAction; - popup.add(miLobSaveAction); - final JMenuItem miLobEditAction = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "editClob.title")); - miLobEditAction.addActionListener(new ActionListener() { + popup.add(saveContentMenuItem); + editContentMenuItem = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "editClob.title")); + editContentMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -138,9 +142,9 @@ editCell(); } }); - popup.add(miLobEditAction); - final JMenuItem miLobLoadAction = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "loadLob.title")); - miLobLoadAction.addActionListener(new ActionListener() { + popup.add(editContentMenuItem); + loadContentMenuItem = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "loadLob.title")); + loadContentMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -151,9 +155,9 @@ fireEditingStopped(); } }); - popup.add(miLobLoadAction); - final JMenuItem miLobNullAction = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "nullLob.title")); - miLobNullAction.addActionListener(new ActionListener() { + popup.add(loadContentMenuItem); + nullContentMenuItem = new JMenuItem(NbBundle.getMessage(ClobFieldTableCellEditor.class, "nullLob.title")); + nullContentMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -161,7 +165,7 @@ fireEditingStopped(); } }); - popup.add(miLobNullAction); + popup.add(nullContentMenuItem); } @@ -175,6 +179,12 @@ @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { currentValue = (java.sql.Clob) value; + this.currentColumn = column; + this.currentRow = row; + this.table = table; + this.currentModelColumn = table.convertColumnIndexToModel(column); + this.currentModelRow = table.convertRowIndexToModel(row); + boolean editable = table.getModel().isCellEditable(currentModelRow, currentModelColumn); if (currentValue != null) { saveContentMenuItem.setEnabled(true); try { @@ -197,9 +207,15 @@ saveContentMenuItem.setEnabled(false); button.setText(""); } - this.currentColumn = column; - this.currentRow = row; - this.table = table; + loadContentMenuItem.setEnabled(editable); + nullContentMenuItem.setEnabled(editable); + if (editable) { + editContentMenuItem.setEnabled(true); + editContentMenuItem.setText(NbBundle.getMessage(ClobFieldTableCellEditor.class, "editClob.title")); + } else { + editContentMenuItem.setEnabled(currentValue != null); + editContentMenuItem.setText(NbBundle.getMessage(ClobFieldTableCellEditor.class, "editClobReadOnly.title")); + } return button; } @@ -354,9 +370,11 @@ } JTextArea textArea = new JTextArea(20, 80); + // Work around: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7100524 + textArea.setDropTarget(null); textArea.setText(stringVal); textArea.setCaretPosition(0); - textArea.setEditable(table.isCellEditable(currentRow, currentColumn)); + textArea.setEditable(table.getModel().isCellEditable(currentModelRow, currentModelColumn)); JScrollPane pane = new JScrollPane(textArea); pane.addHierarchyListener(