diff -urb -x '*/build/*' -x apichanges.html nb.orig/db/libsrc/org/netbeans/lib/ddl/DBConnection.java nb/db/libsrc/org/netbeans/lib/ddl/DBConnection.java --- nb.orig/db/libsrc/org/netbeans/lib/ddl/DBConnection.java 2011-03-28 00:34:18.000000000 +0200 +++ nb/db/libsrc/org/netbeans/lib/ddl/DBConnection.java 2011-04-03 20:59:24.000000000 +0200 @@ -45,6 +45,7 @@ package org.netbeans.lib.ddl; import java.sql.Connection; +import java.util.Properties; /** * Connection information. @@ -143,4 +144,7 @@ * driver or database does not exist or is inaccessible. */ public Connection createJDBCConnection() throws DDLException; + + public void setConnectionProperties(Properties connectionProperties); + public Properties getConnectionProperties(); } diff -urb -x '*/build/*' -x apichanges.html nb.orig/db/src/org/netbeans/api/db/explorer/node/BaseNode.java nb/db/src/org/netbeans/api/db/explorer/node/BaseNode.java --- nb.orig/db/src/org/netbeans/api/db/explorer/node/BaseNode.java 2011-03-28 00:34:18.000000000 +0200 +++ nb/db/src/org/netbeans/api/db/explorer/node/BaseNode.java 2011-04-01 23:11:21.000000000 +0200 @@ -52,6 +52,7 @@ import javax.swing.event.ChangeListener; import org.netbeans.modules.db.explorer.action.ActionRegistry; import org.netbeans.modules.db.explorer.node.NodeDataLookup; +import org.netbeans.modules.db.explorer.node.NodePropertiesPropertySupport; import org.netbeans.modules.db.explorer.node.NodePropertySupport; import org.netbeans.modules.db.explorer.node.NodeRegistry; import org.openide.nodes.AbstractNode; @@ -117,6 +118,8 @@ protected static final String FKREFERREDTABLEDESC = "ReferredFKTable"; // NOI18N protected static final String FKREFERREDCOLUMN = "ReferredFKColumn"; // NOI18N protected static final String FKREFERREDCOLUMNDESC = "ReferredFKColumn"; // NOI18N + protected static final String CONNECTIONPROPERTIES = "ConnectionProperties"; + protected static final String CONNECTIONPROPERTIESDESC = "ConnectionPropertiesDescription"; private final NodeDataLookup dataLookup; private final ActionRegistry actionRegistry; @@ -290,7 +293,14 @@ } else { propDesc = NbBundle.getMessage (BaseNode.class, desc); } - PropertySupport ps = new NodePropertySupport(this, name, clazz, propName, propDesc, writeable); + + PropertySupport ps; + + if(java.util.Properties.class.isAssignableFrom(clazz)) { + ps = new NodePropertiesPropertySupport(this, name, clazz, propName, propDesc, writeable); + } else { + ps = new NodePropertySupport(this, name, clazz, propName, propDesc, writeable); + } props.add(ps); propMap.put(ps.getName(), value); diff -urb -x '*/build/*' -x apichanges.html nb.orig/db/src/org/netbeans/api/db/explorer/node/Bundle.properties nb/db/src/org/netbeans/api/db/explorer/node/Bundle.properties --- nb.orig/db/src/org/netbeans/api/db/explorer/node/Bundle.properties 2011-03-28 00:34:18.000000000 +0200 +++ nb/db/src/org/netbeans/api/db/explorer/node/Bundle.properties 2011-03-30 22:26:18.000000000 +0200 @@ -138,6 +138,8 @@ ForeignColumnDescription=Column KeySeq=Keyseq KeySeqDescription=Keyseq +ConnectionProperties=Connection properties +ConnectionPropertiesDescription=Connection properties # Booleans diff -urb -x '*/build/*' -x apichanges.html nb.orig/db/src/org/netbeans/modules/db/explorer/DatabaseConnectionConvertor.java nb/db/src/org/netbeans/modules/db/explorer/DatabaseConnectionConvertor.java --- nb.orig/db/src/org/netbeans/modules/db/explorer/DatabaseConnectionConvertor.java 2011-03-28 00:34:18.000000000 +0200 +++ nb/db/src/org/netbeans/modules/db/explorer/DatabaseConnectionConvertor.java 2011-04-03 20:27:33.000000000 +0200 @@ -60,6 +60,7 @@ import java.nio.charset.CoderResult; import java.util.LinkedList; import java.util.Map; +import java.util.Properties; import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -239,7 +240,8 @@ handler.driverName, handler.connectionUrl, handler.schema, - handler.user); + handler.user, + handler.connectionProperties); dbconn.setConnectionFileName(handler.connectionFileName); if (handler.displayName != null) { dbconn.setDisplayName(handler.displayName); @@ -408,6 +410,19 @@ LOGGER.log(Level.FINE, "Deleting password for " + name); Keyring.delete(name); } + if(instance.getConnectionProperties() != null) { + Properties p = instance.getConnectionProperties(); + for(String key: p.stringPropertyNames()) { + pw.println(" "); + pw.print(" "); + pw.print(XMLUtil.toElementContent(key)); + pw.println(""); + pw.print(" "); + pw.print(XMLUtil.toElementContent(p.getProperty(key))); + pw.println(""); + pw.println(" "); + } + } pw.println(""); //NOI18N } } @@ -424,19 +439,29 @@ private static final String ELEMENT_USER = "user"; // NOI18N private static final String ELEMENT_PASSWORD = "password"; // NOI18N private static final String ELEMENT_DISPLAY_NAME = "display-name"; // NOI18N + private static final String ELEMENT_CONNECTION_PROPERTY = "connection-property"; // NOI18N + private static final String ELEMENT_CONNECTION_PROPERTY_NAME = "name"; // NOI18N + private static final String ELEMENT_CONNECTION_PROPERTY_VALUE = "value"; // NOI18N private static final String ATTR_PROPERTY_VALUE = "value"; // NOI18N final String connectionFileName; + private boolean readingProperty = false; + private String propertyName; + private String propertyValue; + private StringBuilder buffer = new StringBuilder(); + String driverClass; String driverName; String connectionUrl; String schema; String user; String displayName; + Properties connectionProperties; public Handler(String connectionFileName) { this.connectionFileName = connectionFileName; + this.connectionProperties = new Properties(); } @Override @@ -447,6 +472,8 @@ public void endDocument() throws SAXException { } + + @Override @SuppressWarnings("deprecation") // Backward compatibility public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { @@ -463,6 +490,14 @@ user = value; } else if (ELEMENT_DISPLAY_NAME.equals(qName)) { displayName = value; + } else if (ELEMENT_CONNECTION_PROPERTY.equals(qName)) { + readingProperty = true; + propertyName = ""; + propertyValue = ""; + } else if (readingProperty && ELEMENT_CONNECTION_PROPERTY_NAME.equals(qName)) { + buffer.setLength(0); + } else if (readingProperty && ELEMENT_CONNECTION_PROPERTY_VALUE.equals(qName)) { + buffer.setLength(0); } else if (ELEMENT_PASSWORD.equals(qName)) { // reading old settings byte[] bytes = null; @@ -491,6 +526,35 @@ } } } + + @Override + public void ignorableWhitespace(char[] chars, int start, int length) throws SAXException { + if(readingProperty) { + buffer.append(chars, start, length); + } + } + + @Override + public void characters(char[] chars, int start, int length) throws SAXException { + if(readingProperty) { + buffer.append(chars, start, length); + } + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + if (readingProperty && ELEMENT_CONNECTION_PROPERTY.equals(qName)) { + connectionProperties.put(propertyName, propertyValue); + readingProperty = false; + propertyName = ""; + propertyValue = ""; + buffer.setLength(0); + } else if (readingProperty && ELEMENT_CONNECTION_PROPERTY_NAME.equals(qName)) { + propertyName = buffer.toString(); + } else if (readingProperty && ELEMENT_CONNECTION_PROPERTY_VALUE.equals(qName)) { + propertyValue = buffer.toString(); + } + } } private final class PCL implements PropertyChangeListener, Runnable { diff -urb -x '*/build/*' -x apichanges.html nb.orig/db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java nb/db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java --- nb.orig/db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java 2011-03-28 00:34:18.000000000 +0200 +++ nb/db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java 2011-04-03 20:58:30.000000000 +0200 @@ -164,6 +164,10 @@ */ private MetadataModel metadataModel = null; + /** Properties for connection + */ + private Properties connectionProperties = new Properties(); + /** * The API DatabaseConnection (delegates to this instance) */ @@ -181,6 +185,7 @@ public static final String PROP_DRIVERNAME = "drivername"; //NOI18N public static final String PROP_NAME = "name"; //NOI18N public static final String PROP_DISPLAY_NAME = "displayName"; //NOI18N + public static final String PROP_CONNECTIONPROPERTIES = "connectionProperties"; public static final String DRIVER_CLASS_NET = "org.apache.derby.jdbc.ClientDriver"; // NOI18N public static final int DERBY_UNICODE_ERROR_CODE = 20000; private OpenConnectionInterface openConnection = null; @@ -217,22 +222,34 @@ * @param password User password */ public DatabaseConnection(String driver, String database, String user, String password) { - this(driver, null, database, null, user, password, null); + this(driver, null, database, null, user, password, null, null); } public DatabaseConnection(String driver, String driverName, String database, String theschema, String user, String password) { - this(driver, driverName, database, theschema, user, password, null); + this(driver, driverName, database, theschema, user, password, null, null); } public DatabaseConnection(String driver, String driverName, String database, String theschema, String user) { - this(driver, driverName, database, theschema, user, null, null); + this(driver, driverName, database, theschema, user, null, null, null); + } + + public DatabaseConnection(String driver, String driverName, String database, + String theschema, String user, Properties connectionProperties) { + this(driver, driverName, database, theschema, user, null, null, connectionProperties); } public DatabaseConnection(String driver, String driverName, String database, String theschema, String user, String password, Boolean rememberPassword) { + this( driver, driverName, database, theschema, user, password, + rememberPassword, null); + } + + public DatabaseConnection(String driver, String driverName, String database, + String theschema, String user, String password, + Boolean rememberPassword, Properties connectionProperties) { this(); drv = driver; drvname = driverName; @@ -242,6 +259,7 @@ rpwd = rememberPassword == null ? null : Boolean.valueOf(rememberPassword); schema = theschema; name = getName(); + setConnectionProperties(connectionProperties); } public JDBCDriver findJDBCDriver() { @@ -511,6 +529,20 @@ } } + public Properties getConnectionProperties() { + return (Properties) connectionProperties.clone(); + } + + public void setConnectionProperties(Properties connectionProperties) { + Properties old = this.connectionProperties; + if(connectionProperties == null) { + this.connectionProperties = new Properties(); + } else { + this.connectionProperties = (Properties) connectionProperties.clone(); + } + propertySupport.firePropertyChange(PROP_CONNECTIONPROPERTIES, old, connectionProperties); + } + /** Returns user schema name */ @Override public String getSchema() { @@ -672,9 +704,16 @@ throw new DDLException(NbBundle.getMessage(DatabaseConnection.class, "EXC_InsufficientConnInfo")); // NOI18N } - Properties dbprops = new Properties(); + Properties dbprops = null; + if(connectionProperties != null) { + dbprops = getConnectionProperties(); + } else { + dbprops = new Properties(); + } if ((usr != null) && (usr.length() > 0)) { dbprops.put("user", usr); //NOI18N + } + if ((pwd != null) && (pwd.length() > 0)) { dbprops.put("password", pwd); //NOI18N } @@ -752,11 +791,16 @@ sendException(new DDLException(NbBundle.getMessage(DatabaseConnection.class, "EXC_InsufficientConnInfo"))); } - Properties dbprops = new Properties(); - if ( usr.length() > 0 ) { + Properties dbprops = null; + if(connectionProperties != null) { + dbprops = getConnectionProperties(); + } else { + dbprops = new Properties(); + } + if ((usr != null) && (usr.length() > 0)) { dbprops.put("user", usr); //NOI18N } - if ((pwd != null && pwd.length() > 0)) { + if ((pwd != null) && (pwd.length() > 0)) { dbprops.put("password", pwd); //NOI18N } @@ -945,9 +989,10 @@ */ @Override public boolean equals(Object obj) { - if (obj instanceof DBConnection) { - DBConnection conn = (DBConnection) obj; - return toString().equals(conn.toString()); + if (obj instanceof DatabaseConnection) { + DatabaseConnection conn = (DatabaseConnection) obj; + return toString().equals(conn.toString()) && + connectionProperties.equals(conn.getConnectionProperties()); } return false; @@ -969,6 +1014,11 @@ //IGNORE - drvname not stored in 3.6 and earlier //IGNORE - displayName not stored in 6.7 and earlier } + try { + connectionProperties = (Properties) in.readObject(); + } catch (Exception ex) { + //IGNORE - displayName not stored in 7.0 and earlier + } // boston setting/pilsen setting? if ((name != null) && (name.equals(DatabaseConnection.SUPPORT))) { @@ -992,6 +1042,7 @@ out.writeObject(DatabaseConnection.SUPPORT); out.writeObject(drvname); out.writeObject(displayName); + out.writeObject(connectionProperties); } @Override diff -urb -x '*/build/*' -x apichanges.html nb.orig/db/src/org/netbeans/modules/db/explorer/node/ConnectionNode.java nb/db/src/org/netbeans/modules/db/explorer/node/ConnectionNode.java --- nb.orig/db/src/org/netbeans/modules/db/explorer/node/ConnectionNode.java 2011-03-28 00:34:18.000000000 +0200 +++ nb/db/src/org/netbeans/modules/db/explorer/node/ConnectionNode.java 2011-04-01 22:43:18.000000000 +0200 @@ -48,6 +48,7 @@ import java.io.IOException; import java.sql.Connection; import java.sql.DatabaseMetaData; +import java.util.Properties; import org.netbeans.api.db.explorer.DatabaseException; import org.netbeans.api.db.explorer.DatabaseMetaDataTransfer; import org.netbeans.modules.db.explorer.DatabaseConnection; @@ -61,6 +62,8 @@ import org.netbeans.modules.db.explorer.DatabaseMetaDataTransferAccessor; import org.netbeans.modules.db.metadata.model.api.MetadataModel; import org.netbeans.modules.db.metadata.model.api.MetadataModels; +import org.openide.nodes.PropertySupport; +import org.openide.nodes.Sheet; import org.openide.util.Exceptions; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; @@ -149,6 +152,8 @@ connection.setDisplayName(val.toString()); setDisplayName(val.toString()); refreshNode = false; + } else if (nps.getName().equals(CONNECTIONPROPERTIES)) { + connection.setConnectionProperties((Properties) val); } if (refreshNode) { @@ -157,6 +162,7 @@ } private void updateLocalProperties() { + try { clearProperties(); boolean connected = !connection.getConnector().isDisconnected(); @@ -168,6 +174,7 @@ addProperty(USER, USERDESC, String.class, !connected, connection.getUser()); addProperty(REMEMBERPW, REMEMBERPWDESC, Boolean.class, !connected, connection.rememberPassword()); + addProperty(CONNECTIONPROPERTIES, CONNECTIONPROPERTIESDESC, Properties.class, ! connected, connection.getConnectionProperties()); if (connected) { Specification spec = connection.getConnector().getDatabaseSpecification(); diff -urb -x '*/build/*' -x apichanges.html nb.orig/db/src/org/netbeans/modules/db/explorer/node/NodePropertiesPropertySupport.java nb/db/src/org/netbeans/modules/db/explorer/node/NodePropertiesPropertySupport.java --- nb.orig/db/src/org/netbeans/modules/db/explorer/node/NodePropertiesPropertySupport.java 2011-04-02 17:25:54.000000000 +0200 +++ nb/db/src/org/netbeans/modules/db/explorer/node/NodePropertiesPropertySupport.java 2011-04-01 22:47:24.000000000 +0200 @@ -0,0 +1,66 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 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 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.db.explorer.node; + +import java.beans.PropertyEditor; +import java.lang.reflect.InvocationTargetException; +import org.netbeans.api.db.explorer.node.BaseNode; +import org.netbeans.modules.db.util.PropertiesEditor; + +public class NodePropertiesPropertySupport extends NodePropertySupport { + + public NodePropertiesPropertySupport(BaseNode node, String name, Class type, String displayName, String shortDescription, boolean writable) { + super(node, name, type, displayName, shortDescription, writable); + setValue("canEditAsText", Boolean.FALSE); + } + + @Override + public PropertyEditor getPropertyEditor() { + return new PropertiesEditor(); + } + + @Override + public Object getValue() throws IllegalAccessException, InvocationTargetException { + return super.getValue(); + } +} \ Kein Zeilenumbruch am Dateiende. diff -urb -x '*/build/*' -x apichanges.html nb.orig/db/src/org/netbeans/modules/db/util/Bundle.properties nb/db/src/org/netbeans/modules/db/util/Bundle.properties --- nb.orig/db/src/org/netbeans/modules/db/util/Bundle.properties 2011-03-28 00:34:18.000000000 +0200 +++ nb/db/src/org/netbeans/modules/db/util/Bundle.properties 2011-04-01 23:00:54.000000000 +0200 @@ -71,3 +71,9 @@ =TNS Name =Additional Properties ErrorInfoPanel.iconLabel.text= + +NoPropertiesSet=No properties set +PropertiesCustomEditor.addRowButton.text=Add Property +PropertiesCustomEditor.removeRowButton.text=Remove Property +PropertiesCustomEditor.propertyTable.columnModel.title0=Property +PropertiesCustomEditor.propertyTable.columnModel.title1=Value diff -urb -x '*/build/*' -x apichanges.html nb.orig/db/src/org/netbeans/modules/db/util/PropertiesCustomEditor.form nb/db/src/org/netbeans/modules/db/util/PropertiesCustomEditor.form --- nb.orig/db/src/org/netbeans/modules/db/util/PropertiesCustomEditor.form 2011-04-02 17:24:02.000000000 +0200 +++ nb/db/src/org/netbeans/modules/db/util/PropertiesCustomEditor.form 2011-04-03 20:38:29.000000000 +0200 @@ -0,0 +1,97 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <ResourceString bundle="org/netbeans/modules/db/util/Bundle.properties" key="PropertiesCustomEditor.propertyTable.columnModel.title0" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + + + + + + + <ResourceString bundle="org/netbeans/modules/db/util/Bundle.properties" key="PropertiesCustomEditor.propertyTable.columnModel.title1" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + + + + + + + + + + + + + + + + diff -urb -x '*/build/*' -x apichanges.html nb.orig/db/src/org/netbeans/modules/db/util/PropertiesCustomEditor.java nb/db/src/org/netbeans/modules/db/util/PropertiesCustomEditor.java --- nb.orig/db/src/org/netbeans/modules/db/util/PropertiesCustomEditor.java 2011-04-02 17:24:04.000000000 +0200 +++ nb/db/src/org/netbeans/modules/db/util/PropertiesCustomEditor.java 2011-04-03 20:38:29.000000000 +0200 @@ -0,0 +1,240 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 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 2011 Sun Microsystems, Inc. + */ + +/* + * PropertiesCustomEditor.java + * + * Created on 01.04.2011, 20:25:24 + */ +package org.netbeans.modules.db.util; + +import java.util.Arrays; +import java.util.Properties; +import java.util.Vector; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; + +/** + * Custom implentation for a property editor, as the build in doesn't work to + * well with international characters + * + * @author Matthias Bläsing + */ +public class PropertiesCustomEditor extends javax.swing.JPanel { + PropertiesEditor editor; + boolean updateing; + + public PropertiesCustomEditor(final PropertiesEditor editor) { + initComponents(); + this.editor = editor; + updateTableFromEditor(); + final TableModel tm = propertyTable.getModel(); + tm.addTableModelListener(new TableModelListener() { + @Override + public void tableChanged(TableModelEvent tme) { + synchronized (PropertiesCustomEditor.this) { + if (updateing) { + return; + } + updateing = true; + Properties p = new Properties(); + for(int i = 0; i < tm.getRowCount(); i++) { + p.setProperty((String) tm.getValueAt(i, 0), (String) tm.getValueAt(i, 1)); + } + editor.setValue(p); + updateing = false; + } + } + }); + propertyTable.getSelectionModel().addListSelectionListener( + new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent lse) { + updateRemoveButtonSensible(); + } + } + ); + updateAddButtonSensible(); + updateRemoveButtonSensible(); + } + + private void updateAddButtonSensible() { + if( editor.isEditable() ) { + addRowButton.setEnabled(true); + } else { + addRowButton.setEnabled(false); + } + } + + private void updateRemoveButtonSensible() { + if (editor.isEditable() && propertyTable.getSelectedRowCount() > 0) { + removeRowButton.setEnabled(true); + } else { + removeRowButton.setEnabled(false); + } + } + + @SuppressWarnings("unchecked") + private void updateTableFromEditor() { + synchronized (this) { + if (updateing) { + return; + } + updateing = true; + Properties p = (Properties) editor.getValue(); + DefaultTableModel dtm = (DefaultTableModel) propertyTable.getModel(); + Vector columns = new Vector(2); + Vector values = new Vector(); + columns.add(dtm.getColumnName(0)); + columns.add(dtm.getColumnName(1)); + for (String key : p.stringPropertyNames()) { + Vector row = new Vector(2); + row.add(key); + row.add(p.getProperty(key, "")); + values.add(row); + } + dtm.setDataVector(values, columns); + updateing = false; + } + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + buttonPanel = new javax.swing.JPanel(); + addRowButton = new javax.swing.JButton(); + removeRowButton = new javax.swing.JButton(); + propertyScrollPane = new javax.swing.JScrollPane(); + propertyTable = new javax.swing.JTable(); + + setLayout(new java.awt.BorderLayout()); + + buttonPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT)); + + addRowButton.setText(org.openide.util.NbBundle.getMessage(PropertiesCustomEditor.class, "PropertiesCustomEditor.addRowButton.text")); // NOI18N + addRowButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + addRowButtonActionPerformed(evt); + } + }); + buttonPanel.add(addRowButton); + + removeRowButton.setText(org.openide.util.NbBundle.getMessage(PropertiesCustomEditor.class, "PropertiesCustomEditor.removeRowButton.text")); // NOI18N + removeRowButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + removeRowButtonActionPerformed(evt); + } + }); + buttonPanel.add(removeRowButton); + + add(buttonPanel, java.awt.BorderLayout.PAGE_END); + + propertyTable.setAutoCreateRowSorter(true); + propertyTable.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + + }, + new String [] { + "Property", "Value" + } + ) { + Class[] types = new Class [] { + java.lang.String.class, java.lang.String.class + }; + + public Class getColumnClass(int columnIndex) { + return types [columnIndex]; + } + + public boolean isCellEditable(int rowIndex, int columnIndex) { + return PropertiesCustomEditor.this.editor.isEditable(); + } + }); + propertyTable.setColumnSelectionAllowed(true); + propertyScrollPane.setViewportView(propertyTable); + propertyTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + propertyTable.getColumnModel().getColumn(0).setHeaderValue(org.openide.util.NbBundle.getMessage(PropertiesCustomEditor.class, "PropertiesCustomEditor.propertyTable.columnModel.title0")); // NOI18N + propertyTable.getColumnModel().getColumn(1).setHeaderValue(org.openide.util.NbBundle.getMessage(PropertiesCustomEditor.class, "PropertiesCustomEditor.propertyTable.columnModel.title1")); // NOI18N + + add(propertyScrollPane, java.awt.BorderLayout.CENTER); + }// //GEN-END:initComponents + + private void addRowButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addRowButtonActionPerformed + DefaultTableModel dtm = (DefaultTableModel) propertyTable.getModel(); + dtm.addRow(new Object[] {"", ""}); + }//GEN-LAST:event_addRowButtonActionPerformed + + private void removeRowButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeRowButtonActionPerformed + int[] viewRows = propertyTable.getSelectedRows(); + int[] modelRows = new int[viewRows.length]; + + for(int i = 0; i < viewRows.length; i++) { + modelRows[i] = propertyTable.convertRowIndexToModel(viewRows[i]); + } + + Arrays.sort(modelRows); + + DefaultTableModel dtm = (DefaultTableModel) propertyTable.getModel(); + + for(int i = modelRows.length - 1; i >= 0; i--) { + dtm.removeRow(modelRows[i]); + } + }//GEN-LAST:event_removeRowButtonActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton addRowButton; + private javax.swing.JPanel buttonPanel; + private javax.swing.JScrollPane propertyScrollPane; + private javax.swing.JTable propertyTable; + private javax.swing.JButton removeRowButton; + // End of variables declaration//GEN-END:variables +} diff -urb -x '*/build/*' -x apichanges.html nb.orig/db/src/org/netbeans/modules/db/util/PropertiesEditor.java nb/db/src/org/netbeans/modules/db/util/PropertiesEditor.java --- nb.orig/db/src/org/netbeans/modules/db/util/PropertiesEditor.java 2011-04-02 17:24:09.000000000 +0200 +++ nb/db/src/org/netbeans/modules/db/util/PropertiesEditor.java 2011-04-03 20:37:57.000000000 +0200 @@ -0,0 +1,102 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 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 2011 Sun Microsystems, Inc. + */ +package org.netbeans.modules.db.util; + +import java.beans.FeatureDescriptor; +import java.beans.PropertyEditorSupport; +import java.util.Properties; +import org.openide.explorer.propertysheet.ExPropertyEditor; +import org.openide.explorer.propertysheet.PropertyEnv; +import org.openide.nodes.Node; +import org.openide.util.NbBundle; + +/** + * Custom editor for properties - mainly exists to call custom editor + * + * @author Matthias Bläsing + */ +public class PropertiesEditor extends PropertyEditorSupport implements ExPropertyEditor { + private boolean canWrite = true; + + @Override + public String getAsText() { + Properties value = (Properties) getValue(); + if(value == null || value.size() == 0) { + return NbBundle.getMessage(PropertiesEditor.class, "NoPropertiesSet"); + } else { + return value.toString(); + } + } + + /** Can't be called and throws IllegalArgumentException */ + @Override + public void setAsText(String text) throws IllegalArgumentException { + throw new IllegalArgumentException("Can't be set by setAsText"); + } + + @Override + public String getJavaInitializationString() { + return null; // does not generate any code + } + + @Override + public boolean supportsCustomEditor() { + return true; + } + + @Override + public java.awt.Component getCustomEditor() { + return new PropertiesCustomEditor(this); + } + + @Override + public void attachEnv(PropertyEnv env) { + FeatureDescriptor d = env.getFeatureDescriptor(); + if (d instanceof Node.Property) { + canWrite = ((Node.Property) d).canWrite(); + } + } + + public boolean isEditable() { + return canWrite; + } +} \ Kein Zeilenumbruch am Dateiende. diff -urb -x '*/build/*' -x apichanges.html nb.orig/db/test/unit/src/org/netbeans/modules/db/explorer/DatabaseConnectionConvertorTest.java nb/db/test/unit/src/org/netbeans/modules/db/explorer/DatabaseConnectionConvertorTest.java --- nb.orig/db/test/unit/src/org/netbeans/modules/db/explorer/DatabaseConnectionConvertorTest.java 2011-03-28 00:34:18.000000000 +0200 +++ nb/db/test/unit/src/org/netbeans/modules/db/explorer/DatabaseConnectionConvertorTest.java 2011-04-03 20:40:16.000000000 +0200 @@ -144,7 +144,7 @@ } public void testSaveOnPropertyChange() throws Exception { - DatabaseConnection dbconn = new DatabaseConnection("a", "b", "c", "d", "e", null); + DatabaseConnection dbconn = new DatabaseConnection("a", "b", "c", "d", "e", (String) null); FileObject fo = DatabaseConnectionConvertor.create(dbconn).getPrimaryFile(); class FCL extends FileChangeAdapter {