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 197408
Collapse All | Expand All

(-)a/db/libsrc/org/netbeans/lib/ddl/DBConnection.java (+4 lines)
Lines 45-50 Link Here
45
package org.netbeans.lib.ddl;
45
package org.netbeans.lib.ddl;
46
46
47
import java.sql.Connection;
47
import java.sql.Connection;
48
import java.util.Properties;
48
49
49
/**
50
/**
50
* Connection information.
51
* Connection information.
Lines 143-146 Link Here
143
    * driver or database does not exist or is inaccessible.
144
    * driver or database does not exist or is inaccessible.
144
    */
145
    */
145
    public Connection createJDBCConnection() throws DDLException;
146
    public Connection createJDBCConnection() throws DDLException;
147
148
    public void setConnectionProperties(Properties connectionProperties);
149
    public Properties getConnectionProperties();
146
}
150
}
(-)a/db/src/org/netbeans/api/db/explorer/node/Bundle.properties (+2 lines)
Lines 142-147 Link Here
142
ForeignColumnDescription=Column
142
ForeignColumnDescription=Column
143
KeySeq=Keyseq
143
KeySeq=Keyseq
144
KeySeqDescription=Keyseq
144
KeySeqDescription=Keyseq
145
ConnectionProperties=Connection properties
146
ConnectionPropertiesDescription=Connection properties
145
147
146
# Booleans
148
# Booleans
147
149
(-)a/db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java (-10 / +70 lines)
Lines 156-161 Link Here
156
     */
156
     */
157
    private MetadataModel metadataModel = null;
157
    private MetadataModel metadataModel = null;
158
158
159
    /** Properties for connection
160
     */
161
    private Properties connectionProperties = new Properties();
162
159
    /**
163
    /**
160
     * The API DatabaseConnection (delegates to this instance)
164
     * The API DatabaseConnection (delegates to this instance)
161
     */
165
     */
Lines 173-178 Link Here
173
    public static final String PROP_DRIVERNAME = "drivername"; //NOI18N
177
    public static final String PROP_DRIVERNAME = "drivername"; //NOI18N
174
    public static final String PROP_NAME = "name"; //NOI18N
178
    public static final String PROP_NAME = "name"; //NOI18N
175
    public static final String PROP_DISPLAY_NAME = "displayName"; //NOI18N
179
    public static final String PROP_DISPLAY_NAME = "displayName"; //NOI18N
180
    public static final String PROP_CONNECTIONPROPERTIES = "connectionProperties";
176
    public static final String DRIVER_CLASS_NET = "org.apache.derby.jdbc.ClientDriver"; // NOI18N
181
    public static final String DRIVER_CLASS_NET = "org.apache.derby.jdbc.ClientDriver"; // NOI18N
177
    public static final int DERBY_UNICODE_ERROR_CODE = 20000;
182
    public static final int DERBY_UNICODE_ERROR_CODE = 20000;
178
    private OpenConnectionInterface openConnection = null;
183
    private OpenConnectionInterface openConnection = null;
Lines 210-231 Link Here
210
     * @param password User password
215
     * @param password User password
211
     */
216
     */
212
    public DatabaseConnection(String driver, String database, String user, String password) {
217
    public DatabaseConnection(String driver, String database, String user, String password) {
213
        this(driver, null, database, null, user, password, null);
218
        this(driver, null, database, null, user, password, null, null);
214
    }
219
    }
215
220
216
    public DatabaseConnection(String driver, String driverName, String database,
221
    public DatabaseConnection(String driver, String driverName, String database,
217
            String theschema, String user, String password) {
222
            String theschema, String user, String password) {
218
        this(driver, driverName, database, theschema, user, password, null);
223
        this(driver, driverName, database, theschema, user, password, null, null);
219
    }
224
    }
220
225
221
    public DatabaseConnection(String driver, String driverName, String database, 
226
    public DatabaseConnection(String driver, String driverName, String database, 
222
            String theschema, String user) {
227
            String theschema, String user) {
223
        this(driver, driverName, database, theschema, user, null, null);
228
        this(driver, driverName, database, theschema, user, null, null, null);
229
    }
230
231
    public DatabaseConnection(String driver, String driverName, String database,
232
            String theschema, String user, Properties connectionProperties) {
233
        this(driver, driverName, database, theschema, user, null, null, connectionProperties);
224
    }
234
    }
225
235
226
    public DatabaseConnection(String driver, String driverName, String database,
236
    public DatabaseConnection(String driver, String driverName, String database,
227
            String theschema, String user, String password,
237
            String theschema, String user, String password,
228
            Boolean rememberPassword) {
238
            Boolean rememberPassword) {
239
        this(driver, driverName, database, theschema, user, password,
240
                rememberPassword, null);
241
    }
242
243
    public DatabaseConnection(String driver, String driverName, String database,
244
            String theschema, String user, String password,
245
            Boolean rememberPassword, Properties connectionProperties) {
229
        this();
246
        this();
230
        drv = driver;
247
        drv = driver;
231
        drvname = driverName;
248
        drvname = driverName;
Lines 235-240 Link Here
235
        rpwd = rememberPassword == null ? null : Boolean.valueOf(rememberPassword);
252
        rpwd = rememberPassword == null ? null : Boolean.valueOf(rememberPassword);
236
        schema = theschema;
253
        schema = theschema;
237
        name = getName();
254
        name = getName();
255
        setConnectionProperties(connectionProperties);
238
    }
256
    }
239
257
240
    public JDBCDriver findJDBCDriver() {
258
    public JDBCDriver findJDBCDriver() {
Lines 548-553 Link Here
548
        }
566
        }
549
    }
567
    }
550
568
569
    @Override
570
    public Properties getConnectionProperties() {
571
        return (Properties) connectionProperties.clone();
572
    }
573
574
    @Override
575
    public void setConnectionProperties(Properties connectionProperties) {
576
        Properties old = this.connectionProperties;
577
        if (connectionProperties == null) {
578
            this.connectionProperties = new Properties();
579
        } else {
580
            this.connectionProperties = (Properties) connectionProperties.clone();
581
        }
582
        propertySupport.firePropertyChange(PROP_CONNECTIONPROPERTIES, old, connectionProperties);
583
    }
584
551
    /** Returns user schema name */
585
    /** Returns user schema name */
552
    @Override
586
    @Override
553
    public String getSchema() {
587
    public String getSchema() {
Lines 732-740 Link Here
732
            throw new DDLException(NbBundle.getMessage(DatabaseConnection.class, "EXC_InsufficientConnInfo")); // NOI18N
766
            throw new DDLException(NbBundle.getMessage(DatabaseConnection.class, "EXC_InsufficientConnInfo")); // NOI18N
733
        }
767
        }
734
768
735
        Properties dbprops = new Properties();
769
        Properties dbprops;
770
        if (connectionProperties != null) {
771
            dbprops = getConnectionProperties();
772
        } else {
773
            dbprops = new Properties();
774
        }
736
        if ((usr != null) && (usr.length() > 0)) {
775
        if ((usr != null) && (usr.length() > 0)) {
737
            dbprops.put("user", usr); //NOI18N
776
            dbprops.put("user", usr); //NOI18N
777
        }
778
        if ((pwd != null) && (pwd.length() > 0)) {
738
            dbprops.put("password", pwd); //NOI18N
779
            dbprops.put("password", pwd); //NOI18N
739
        }
780
        }
740
781
Lines 812-822 Link Here
812
            sendException(new DDLException(NbBundle.getMessage(DatabaseConnection.class, "EXC_InsufficientConnInfo")));
853
            sendException(new DDLException(NbBundle.getMessage(DatabaseConnection.class, "EXC_InsufficientConnInfo")));
813
        }
854
        }
814
855
815
        Properties dbprops = new Properties();
856
        Properties dbprops;
816
        if ( usr.length() > 0 ) {
857
        if (connectionProperties != null) {
858
            dbprops = getConnectionProperties();
859
        } else {
860
            dbprops = new Properties();
861
        }
862
        if ((usr != null) && (usr.length() > 0)) {
817
            dbprops.put("user", usr); //NOI18N
863
            dbprops.put("user", usr); //NOI18N
818
        }
864
        }
819
        if ((pwd != null && pwd.length() > 0)) {
865
        if ((pwd != null) && (pwd.length() > 0)) {
820
            dbprops.put("password", pwd); //NOI18N
866
            dbprops.put("password", pwd); //NOI18N
821
        }
867
        }
822
868
Lines 1005-1013 Link Here
1005
     */
1051
     */
1006
    @Override
1052
    @Override
1007
    public boolean equals(Object obj) {
1053
    public boolean equals(Object obj) {
1008
        if (obj instanceof DBConnection) {
1054
        if (obj instanceof DatabaseConnection) {
1009
            DBConnection conn = (DBConnection) obj;
1055
            DatabaseConnection conn = (DatabaseConnection) obj;
1010
            return toString().equals(conn.toString());
1056
            if (toString().equals(conn.toString())) {
1057
                if ((connectionProperties == null
1058
                        && conn.getConnectionProperties() == null)) {
1059
                    return true;
1060
                } else if (connectionProperties != null) {
1061
                    return connectionProperties.equals(
1062
                            conn.getConnectionProperties());
1063
                }
1064
            }
1011
        }
1065
        }
1012
1066
1013
        return false;
1067
        return false;
Lines 1029-1034 Link Here
1029
            //IGNORE - drvname not stored in 3.6 and earlier
1083
            //IGNORE - drvname not stored in 3.6 and earlier
1030
            //IGNORE - displayName not stored in 6.7 and earlier
1084
            //IGNORE - displayName not stored in 6.7 and earlier
1031
        }
1085
        }
1086
        try {
1087
            connectionProperties = (Properties) in.readObject();
1088
        } catch (Exception ex) {
1089
            //IGNORE - connectionProperties not stored in 7.3 and earlier
1090
        }
1032
1091
1033
        // boston setting/pilsen setting?
1092
        // boston setting/pilsen setting?
1034
        if ((name != null) && (name.equals(DatabaseConnection.SUPPORT))) {
1093
        if ((name != null) && (name.equals(DatabaseConnection.SUPPORT))) {
Lines 1052-1057 Link Here
1052
        out.writeObject(DatabaseConnection.SUPPORT);
1111
        out.writeObject(DatabaseConnection.SUPPORT);
1053
        out.writeObject(drvname);
1112
        out.writeObject(drvname);
1054
        out.writeObject(displayName);
1113
        out.writeObject(displayName);
1114
        out.writeObject(connectionProperties);
1055
    }
1115
    }
1056
1116
1057
    @Override
1117
    @Override
(-)a/db/src/org/netbeans/modules/db/explorer/DatabaseConnectionConvertor.java (-1 / +63 lines)
Lines 60-65 Link Here
60
import java.nio.charset.CoderResult;
60
import java.nio.charset.CoderResult;
61
import java.util.LinkedList;
61
import java.util.LinkedList;
62
import java.util.Map;
62
import java.util.Map;
63
import java.util.Properties;
63
import java.util.WeakHashMap;
64
import java.util.WeakHashMap;
64
import java.util.concurrent.ConcurrentHashMap;
65
import java.util.concurrent.ConcurrentHashMap;
65
import java.util.logging.Level;
66
import java.util.logging.Level;
Lines 237-243 Link Here
237
                handler.driverName,
238
                handler.driverName,
238
                handler.connectionUrl,
239
                handler.connectionUrl,
239
                handler.schema,
240
                handler.schema,
240
                handler.user);
241
                handler.user,
242
                handler.connectionProperties);
241
        dbconn.setConnectionFileName(handler.connectionFileName);
243
        dbconn.setConnectionFileName(handler.connectionFileName);
242
        if (handler.displayName != null) {
244
        if (handler.displayName != null) {
243
            dbconn.setDisplayName(handler.displayName);
245
            dbconn.setDisplayName(handler.displayName);
Lines 402-407 Link Here
402
            } else {
404
            } else {
403
                DatabaseConnection.deletePassword(name);
405
                DatabaseConnection.deletePassword(name);
404
            }
406
            }
407
            if (instance.getConnectionProperties() != null) {
408
                Properties p = instance.getConnectionProperties();
409
                for (String key : p.stringPropertyNames()) {
410
                    pw.println("  <connection-property>");              //NOI18N
411
                    pw.print("    <name>");                             //NOI18N
412
                    pw.print(XMLUtil.toElementContent(key));
413
                    pw.println("</name>");                              //NOI18N
414
                    pw.print("    <value>");                            //NOI18N
415
                    pw.print(XMLUtil.toElementContent(p.getProperty(key)));
416
                    pw.println("</value>");                             //NOI18N
417
                    pw.println("  </connection-property>");             //NOI18N
418
                }
419
            }
405
            pw.println("</connection>"); //NOI18N
420
            pw.println("</connection>"); //NOI18N
406
        }        
421
        }        
407
    }
422
    }
Lines 418-436 Link Here
418
        private static final String ELEMENT_USER = "user"; // NOI18N
433
        private static final String ELEMENT_USER = "user"; // NOI18N
419
        private static final String ELEMENT_PASSWORD = "password"; // NOI18N
434
        private static final String ELEMENT_PASSWORD = "password"; // NOI18N
420
        private static final String ELEMENT_DISPLAY_NAME = "display-name"; // NOI18N
435
        private static final String ELEMENT_DISPLAY_NAME = "display-name"; // NOI18N
436
        private static final String ELEMENT_CONNECTION_PROPERTY = "connection-property"; // NOI18N
437
        private static final String ELEMENT_CONNECTION_PROPERTY_NAME = "name"; // NOI18N
438
        private static final String ELEMENT_CONNECTION_PROPERTY_VALUE = "value"; // NOI18N
421
        private static final String ATTR_PROPERTY_VALUE = "value"; // NOI18N
439
        private static final String ATTR_PROPERTY_VALUE = "value"; // NOI18N
422
        
440
        
423
        final String connectionFileName;
441
        final String connectionFileName;
424
        
442
        
443
        private boolean readingProperty = false;
444
        private String propertyName;
445
        private String propertyValue;
446
        private StringBuilder buffer = new StringBuilder();
447
425
        String driverClass;
448
        String driverClass;
426
        String driverName;
449
        String driverName;
427
        String connectionUrl;
450
        String connectionUrl;
428
        String schema;
451
        String schema;
429
        String user;
452
        String user;
430
        String displayName;
453
        String displayName;
454
        Properties connectionProperties;
431
        
455
        
432
        public Handler(String connectionFileName) {
456
        public Handler(String connectionFileName) {
433
            this.connectionFileName = connectionFileName;
457
            this.connectionFileName = connectionFileName;
458
            this.connectionProperties = new Properties();
434
        }
459
        }
435
460
436
        @Override
461
        @Override
Lines 457-462 Link Here
457
                user = value;
482
                user = value;
458
            } else if (ELEMENT_DISPLAY_NAME.equals(qName)) {
483
            } else if (ELEMENT_DISPLAY_NAME.equals(qName)) {
459
                displayName = value;
484
                displayName = value;
485
            } else if (ELEMENT_CONNECTION_PROPERTY.equals(qName)) {
486
                readingProperty = true;
487
                propertyName = "";                                      //NOI18N
488
                propertyValue = "";                                     //NOI18N
489
            } else if (readingProperty && ELEMENT_CONNECTION_PROPERTY_NAME.equals(qName)) {
490
                buffer.setLength(0);
491
            } else if (readingProperty && ELEMENT_CONNECTION_PROPERTY_VALUE.equals(qName)) {
492
                buffer.setLength(0);
460
            } else if (ELEMENT_PASSWORD.equals(qName)) {
493
            } else if (ELEMENT_PASSWORD.equals(qName)) {
461
                // reading old settings
494
                // reading old settings
462
                byte[] bytes = null;
495
                byte[] bytes = null;
Lines 482-487 Link Here
482
                }
515
                }
483
            }
516
            }
484
        }
517
        }
518
519
        @Override
520
        public void ignorableWhitespace(char[] chars, int start, int length) throws SAXException {
521
            if (readingProperty) {
522
                buffer.append(chars, start, length);
523
            }
524
        }
525
526
        @Override
527
        public void characters(char[] chars, int start, int length) throws SAXException {
528
            if (readingProperty) {
529
                buffer.append(chars, start, length);
530
            }
531
        }
532
533
        @Override
534
        public void endElement(String uri, String localName, String qName) throws SAXException {
535
            if (readingProperty && ELEMENT_CONNECTION_PROPERTY.equals(qName)) {
536
                connectionProperties.put(propertyName, propertyValue);
537
                readingProperty = false;
538
                propertyName = "";
539
                propertyValue = "";
540
                buffer.setLength(0);
541
            } else if (readingProperty && ELEMENT_CONNECTION_PROPERTY_NAME.equals(qName)) {
542
                propertyName = buffer.toString();
543
            } else if (readingProperty && ELEMENT_CONNECTION_PROPERTY_VALUE.equals(qName)) {
544
                propertyValue = buffer.toString();
545
            }
546
        }
485
    }
547
    }
486
    
548
    
487
    private final class PCL implements PropertyChangeListener, Runnable {
549
    private final class PCL implements PropertyChangeListener, Runnable {
(-)a/db/src/org/netbeans/modules/db/explorer/node/ConnectionNode.java (+12 lines)
Lines 48-53 Link Here
48
import java.io.IOException;
48
import java.io.IOException;
49
import java.sql.Connection;
49
import java.sql.Connection;
50
import java.sql.DatabaseMetaData;
50
import java.sql.DatabaseMetaData;
51
import java.util.Properties;
51
import javax.swing.Action;
52
import javax.swing.Action;
52
import org.netbeans.api.db.explorer.DatabaseException;
53
import org.netbeans.api.db.explorer.DatabaseException;
53
import org.netbeans.api.db.explorer.DatabaseMetaDataTransfer;
54
import org.netbeans.api.db.explorer.DatabaseMetaDataTransfer;
Lines 64-71 Link Here
64
import org.netbeans.modules.db.explorer.metadata.MetadataModelManager;
65
import org.netbeans.modules.db.explorer.metadata.MetadataModelManager;
65
import org.netbeans.modules.db.metadata.model.api.MetadataModel;
66
import org.netbeans.modules.db.metadata.model.api.MetadataModel;
66
import org.netbeans.modules.db.metadata.model.api.MetadataModels;
67
import org.netbeans.modules.db.metadata.model.api.MetadataModels;
68
import org.netbeans.modules.db.util.PropertiesEditor;
67
import org.openide.DialogDisplayer;
69
import org.openide.DialogDisplayer;
68
import org.openide.NotifyDescriptor;
70
import org.openide.NotifyDescriptor;
71
import org.openide.nodes.PropertySupport;
72
import org.openide.nodes.Sheet;
69
import org.openide.util.Exceptions;
73
import org.openide.util.Exceptions;
70
import org.openide.util.HelpCtx;
74
import org.openide.util.HelpCtx;
71
import org.openide.util.NbBundle;
75
import org.openide.util.NbBundle;
Lines 81-86 Link Here
81
    
85
    
82
    private static final String CONNECTEDICONBASE = "org/netbeans/modules/db/resources/connection.gif"; // NOI18N
86
    private static final String CONNECTEDICONBASE = "org/netbeans/modules/db/resources/connection.gif"; // NOI18N
83
    private static final String DISCONNECTEDICONBASE = "org/netbeans/modules/db/resources/connectionDisconnected.gif"; // NOI18N
87
    private static final String DISCONNECTEDICONBASE = "org/netbeans/modules/db/resources/connectionDisconnected.gif"; // NOI18N
88
    private static final String CONNECTIONPROPERTIES = "ConnectionProperties"; //NOI18N
89
    private static final String CONNECTIONPROPERTIESDESC = "ConnectionPropertiesDescription"; //NOI18N
84
    private static final String FOLDER = "Connection"; // NOI18N
90
    private static final String FOLDER = "Connection"; // NOI18N
85
    private static final RequestProcessor RP = new RequestProcessor(ConnectionNode.class.getName());
91
    private static final RequestProcessor RP = new RequestProcessor(ConnectionNode.class.getName());
86
    
92
    
Lines 160-165 Link Here
160
        } else if (nps.getName().equals(DISPLAYNAME)) {
166
        } else if (nps.getName().equals(DISPLAYNAME)) {
161
            setDisplayName(val.toString());
167
            setDisplayName(val.toString());
162
            refreshNode = false;
168
            refreshNode = false;
169
        } else if (nps.getName().equals(CONNECTIONPROPERTIES)) {
170
            connection.setConnectionProperties((Properties) val);
163
        }
171
        }
164
172
165
        super.setPropertyValue(nps, val);
173
        super.setPropertyValue(nps, val);
Lines 181-186 Link Here
181
            addProperty(USER, USERDESC, String.class, !connected, connection.getUser());
189
            addProperty(USER, USERDESC, String.class, !connected, connection.getUser());
182
            addProperty(REMEMBERPW, REMEMBERPWDESC,
190
            addProperty(REMEMBERPW, REMEMBERPWDESC,
183
                    Boolean.class, !connected, connection.rememberPassword());
191
                    Boolean.class, !connected, connection.rememberPassword());
192
            addProperty(CONNECTIONPROPERTIES, CONNECTIONPROPERTIESDESC, Properties.class, !connected, connection.getConnectionProperties());
193
            Property<?> ps = getSheet().get(Sheet.PROPERTIES).get(CONNECTIONPROPERTIES);
194
            ps.setValue("canEditAsText", Boolean.FALSE);                //NOI18N
195
            ps.setValue(NodePropertySupport.CUSTOM_EDITOR, PropertiesEditor.class);
184
196
185
            if (connected) {
197
            if (connected) {
186
                Specification spec = connection.getConnector().getDatabaseSpecification();
198
                Specification spec = connection.getConnector().getDatabaseSpecification();
(-)a/db/src/org/netbeans/modules/db/explorer/node/NodePropertySupport.java (+37 lines)
Lines 42-47 Link Here
42
42
43
package org.netbeans.modules.db.explorer.node;
43
package org.netbeans.modules.db.explorer.node;
44
44
45
import java.beans.PropertyEditor;
45
import java.lang.reflect.InvocationTargetException;
46
import java.lang.reflect.InvocationTargetException;
46
import org.netbeans.api.db.explorer.node.BaseNode;
47
import org.netbeans.api.db.explorer.node.BaseNode;
47
import org.openide.nodes.PropertySupport;
48
import org.openide.nodes.PropertySupport;
Lines 51-56 Link Here
51
 * @author Rob Englander
52
 * @author Rob Englander
52
 */
53
 */
53
public class NodePropertySupport extends PropertySupport {
54
public class NodePropertySupport extends PropertySupport {
55
    public static final String CUSTOM_EDITOR = "NodePropertySupport.customEditor"; //NOI18N
56
    public static final String NODE = "NodePropertySupport.Node";       //NOI18N
54
57
55
    private BaseNode node;
58
    private BaseNode node;
56
    private String key;
59
    private String key;
Lines 59-64 Link Here
59
        super(name, type, displayName, shortDescription, true, writable);
62
        super(name, type, displayName, shortDescription, true, writable);
60
        key = name;
63
        key = name;
61
        this.node = node;
64
        this.node = node;
65
        setValue(NODE, node);
62
    }
66
    }
63
67
64
    @Override
68
    @Override
Lines 76-79 Link Here
76
        node.setPropertyValue(this, val);
80
        node.setPropertyValue(this, val);
77
    }
81
    }
78
82
83
    /**
84
     * PropertyEditor can be set via setValue - it can be either instanciated or
85
     * a Class, that has a Default-Constructor and results in an object, that
86
     * implements PropertyEditor
87
     *
88
     * @return
89
     */
90
    @Override
91
    public PropertyEditor getPropertyEditor() {
92
        PropertyEditor result = null;
93
        Object potentialEditor = getValue(CUSTOM_EDITOR);
94
95
        if (potentialEditor instanceof PropertyEditor) {
96
            result = (PropertyEditor) potentialEditor;
97
        } else if (potentialEditor instanceof Class) {
98
            try {
99
                potentialEditor = ((Class) potentialEditor).newInstance();
100
                if (!(potentialEditor instanceof PropertyEditor)) {
101
                    throw new IllegalArgumentException(
102
                            "Editor class does not derive from property editor"); //NOI18N
103
                }
104
                return (PropertyEditor) potentialEditor;
105
            } catch (InstantiationException ex) {
106
                throw new RuntimeException(ex);
107
            } catch (IllegalAccessException ex) {
108
                throw new RuntimeException(ex);
109
            }
110
        }
111
        if (result == null) {
112
            result = super.getPropertyEditor();
113
        }
114
        return result;
115
    }
79
}
116
}
(-)a/db/src/org/netbeans/modules/db/util/Bundle.properties (+6 lines)
Lines 71-73 Link Here
71
<TNSNAME>=TNS Name
71
<TNSNAME>=TNS Name
72
<ADDITIONAL>=Additional Properties
72
<ADDITIONAL>=Additional Properties
73
ErrorInfoPanel.iconLabel.text=
73
ErrorInfoPanel.iconLabel.text=
74
75
NoPropertiesSet=No properties set
76
PropertiesCustomEditor.addRowButton.text=Add Property
77
PropertiesCustomEditor.removeRowButton.text=Remove Property
78
PropertiesCustomEditor.propertyTable.columnModel.title0=Property
79
PropertiesCustomEditor.propertyTable.columnModel.title1=Value
(-)a/db/src/org/netbeans/modules/db/util/PropertiesCustomEditor.form (+97 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AuxValues>
5
    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
6
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
7
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
8
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
9
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
10
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
11
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
12
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
13
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
14
    <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
15
  </AuxValues>
16
17
  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
18
  <SubComponents>
19
    <Container class="javax.swing.JPanel" name="buttonPanel">
20
      <Constraints>
21
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
22
          <BorderConstraints direction="Last"/>
23
        </Constraint>
24
      </Constraints>
25
26
      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
27
        <Property name="alignment" type="int" value="2"/>
28
      </Layout>
29
      <SubComponents>
30
        <Component class="javax.swing.JButton" name="addRowButton">
31
          <Properties>
32
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
33
              <ResourceString bundle="org/netbeans/modules/db/util/Bundle.properties" key="PropertiesCustomEditor.addRowButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
34
            </Property>
35
          </Properties>
36
          <Events>
37
            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addRowButtonActionPerformed"/>
38
          </Events>
39
        </Component>
40
        <Component class="javax.swing.JButton" name="removeRowButton">
41
          <Properties>
42
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
43
              <ResourceString bundle="org/netbeans/modules/db/util/Bundle.properties" key="PropertiesCustomEditor.removeRowButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
44
            </Property>
45
          </Properties>
46
          <Events>
47
            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="removeRowButtonActionPerformed"/>
48
          </Events>
49
        </Component>
50
      </SubComponents>
51
    </Container>
52
    <Container class="javax.swing.JScrollPane" name="propertyScrollPane">
53
      <AuxValues>
54
        <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
55
      </AuxValues>
56
      <Constraints>
57
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
58
          <BorderConstraints direction="Center"/>
59
        </Constraint>
60
      </Constraints>
61
62
      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
63
      <SubComponents>
64
        <Component class="javax.swing.JTable" name="propertyTable">
65
          <Properties>
66
            <Property name="autoCreateRowSorter" type="boolean" value="true"/>
67
            <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
68
              <Connection code="new javax.swing.table.DefaultTableModel(&#xa;    new Object [][] {&#xa;&#xa;    },&#xa;    new String [] {&#xa;        &quot;Property&quot;, &quot;Value&quot;&#xa;    }&#xa;) {&#xa;    Class[] types = new Class [] {&#xa;        java.lang.String.class, java.lang.String.class&#xa;    };&#xa;&#xa;    public Class getColumnClass(int columnIndex) {&#xa;        return types [columnIndex];&#xa;    }&#xa;&#xa;    public boolean isCellEditable(int rowIndex, int columnIndex) {&#xa;        return PropertiesCustomEditor.this.editor.isEditable();&#xa;    }&#xa;}" type="code"/>
69
            </Property>
70
            <Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
71
              <TableColumnModel selectionModel="3">
72
                <Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
73
                  <Title editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
74
                    <ResourceString bundle="org/netbeans/modules/db/util/Bundle.properties" key="PropertiesCustomEditor.propertyTable.columnModel.title0" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
75
                  </Title>
76
                  <Editor/>
77
                  <Renderer/>
78
                </Column>
79
                <Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
80
                  <Title editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
81
                    <ResourceString bundle="org/netbeans/modules/db/util/Bundle.properties" key="PropertiesCustomEditor.propertyTable.columnModel.title1" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
82
                  </Title>
83
                  <Editor/>
84
                  <Renderer/>
85
                </Column>
86
              </TableColumnModel>
87
            </Property>
88
            <Property name="columnSelectionAllowed" type="boolean" value="true"/>
89
            <Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
90
              <TableHeader reorderingAllowed="true" resizingAllowed="true"/>
91
            </Property>
92
          </Properties>
93
        </Component>
94
      </SubComponents>
95
    </Container>
96
  </SubComponents>
97
</Form>
(-)a/db/src/org/netbeans/modules/db/util/PropertiesCustomEditor.java (+239 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
43
/*
44
 * PropertiesCustomEditor.java
45
 *
46
 * Created on 01.04.2011, 20:25:24
47
 */
48
package org.netbeans.modules.db.util;
49
50
import java.util.Arrays;
51
import java.util.Properties;
52
import java.util.Vector;
53
import javax.swing.event.ListSelectionEvent;
54
import javax.swing.event.ListSelectionListener;
55
import javax.swing.event.TableModelEvent;
56
import javax.swing.event.TableModelListener;
57
import javax.swing.table.DefaultTableModel;
58
import javax.swing.table.TableModel;
59
60
/**
61
 * Custom implentation for a property editor, as the build in doesn't work to
62
 * well with international characters
63
 *
64
 * @author Matthias Bläsing
65
 */
66
public class PropertiesCustomEditor extends javax.swing.JPanel {
67
68
    PropertiesEditor editor;
69
    boolean updateing;
70
71
    public PropertiesCustomEditor(final PropertiesEditor editor) {
72
        initComponents();
73
        this.editor = editor;
74
        updateTableFromEditor();
75
        final TableModel tm = propertyTable.getModel();
76
        tm.addTableModelListener(new TableModelListener() {
77
            @Override
78
            public void tableChanged(TableModelEvent tme) {
79
                synchronized (PropertiesCustomEditor.this) {
80
                    if (updateing) {
81
                        return;
82
                    }
83
                    updateing = true;
84
                    Properties p = new Properties();
85
                    for (int i = 0; i < tm.getRowCount(); i++) {
86
                        p.setProperty((String) tm.getValueAt(i, 0), (String) tm.getValueAt(i, 1));
87
                    }
88
                    editor.setValue(p);
89
                    updateing = false;
90
                }
91
            }
92
        });
93
        propertyTable.getSelectionModel().addListSelectionListener(
94
                new ListSelectionListener() {
95
            @Override
96
            public void valueChanged(ListSelectionEvent lse) {
97
                updateRemoveButtonSensible();
98
            }
99
        });
100
        updateAddButtonSensible();
101
        updateRemoveButtonSensible();
102
    }
103
104
    private void updateAddButtonSensible() {
105
        if (editor.isEditable()) {
106
            addRowButton.setEnabled(true);
107
        } else {
108
            addRowButton.setEnabled(false);
109
        }
110
    }
111
112
    private void updateRemoveButtonSensible() {
113
        if (editor.isEditable() && propertyTable.getSelectedRowCount() > 0) {
114
            removeRowButton.setEnabled(true);
115
        } else {
116
            removeRowButton.setEnabled(false);
117
        }
118
    }
119
120
    @SuppressWarnings("unchecked")
121
    private void updateTableFromEditor() {
122
        synchronized (this) {
123
            if (updateing) {
124
                return;
125
            }
126
            updateing = true;
127
            Properties p = (Properties) editor.getValue();
128
            DefaultTableModel dtm = (DefaultTableModel) propertyTable.getModel();
129
            Vector columns = new Vector(2);
130
            Vector values = new Vector();
131
            columns.add(dtm.getColumnName(0));
132
            columns.add(dtm.getColumnName(1));
133
            for (String key : p.stringPropertyNames()) {
134
                Vector row = new Vector(2);
135
                row.add(key);
136
                row.add(p.getProperty(key, ""));
137
                values.add(row);
138
            }
139
            dtm.setDataVector(values, columns);
140
            updateing = false;
141
        }
142
    }
143
144
    /**
145
     * This method is called from within the constructor to initialize the form.
146
     * WARNING: Do NOT modify this code. The content of this method is always
147
     * regenerated by the Form Editor.
148
     */
149
    @SuppressWarnings("unchecked")
150
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
151
    private void initComponents() {
152
153
        buttonPanel = new javax.swing.JPanel();
154
        addRowButton = new javax.swing.JButton();
155
        removeRowButton = new javax.swing.JButton();
156
        propertyScrollPane = new javax.swing.JScrollPane();
157
        propertyTable = new javax.swing.JTable();
158
159
        setLayout(new java.awt.BorderLayout());
160
161
        buttonPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
162
163
        addRowButton.setText(org.openide.util.NbBundle.getMessage(PropertiesCustomEditor.class, "PropertiesCustomEditor.addRowButton.text")); // NOI18N
164
        addRowButton.addActionListener(new java.awt.event.ActionListener() {
165
            public void actionPerformed(java.awt.event.ActionEvent evt) {
166
                addRowButtonActionPerformed(evt);
167
            }
168
        });
169
        buttonPanel.add(addRowButton);
170
171
        removeRowButton.setText(org.openide.util.NbBundle.getMessage(PropertiesCustomEditor.class, "PropertiesCustomEditor.removeRowButton.text")); // NOI18N
172
        removeRowButton.addActionListener(new java.awt.event.ActionListener() {
173
            public void actionPerformed(java.awt.event.ActionEvent evt) {
174
                removeRowButtonActionPerformed(evt);
175
            }
176
        });
177
        buttonPanel.add(removeRowButton);
178
179
        add(buttonPanel, java.awt.BorderLayout.PAGE_END);
180
181
        propertyTable.setAutoCreateRowSorter(true);
182
        propertyTable.setModel(new javax.swing.table.DefaultTableModel(
183
            new Object [][] {
184
185
            },
186
            new String [] {
187
                "Property", "Value"
188
            }
189
        ) {
190
            Class[] types = new Class [] {
191
                java.lang.String.class, java.lang.String.class
192
            };
193
194
            public Class getColumnClass(int columnIndex) {
195
                return types [columnIndex];
196
            }
197
198
            public boolean isCellEditable(int rowIndex, int columnIndex) {
199
                return PropertiesCustomEditor.this.editor.isEditable();
200
            }
201
        });
202
        propertyTable.setColumnSelectionAllowed(true);
203
        propertyScrollPane.setViewportView(propertyTable);
204
        propertyTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
205
        propertyTable.getColumnModel().getColumn(0).setHeaderValue(org.openide.util.NbBundle.getMessage(PropertiesCustomEditor.class, "PropertiesCustomEditor.propertyTable.columnModel.title0")); // NOI18N
206
        propertyTable.getColumnModel().getColumn(1).setHeaderValue(org.openide.util.NbBundle.getMessage(PropertiesCustomEditor.class, "PropertiesCustomEditor.propertyTable.columnModel.title1")); // NOI18N
207
208
        add(propertyScrollPane, java.awt.BorderLayout.CENTER);
209
    }// </editor-fold>//GEN-END:initComponents
210
211
    private void addRowButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addRowButtonActionPerformed
212
        DefaultTableModel dtm = (DefaultTableModel) propertyTable.getModel();
213
        dtm.addRow(new Object[]{"", ""});
214
    }//GEN-LAST:event_addRowButtonActionPerformed
215
216
    private void removeRowButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeRowButtonActionPerformed
217
        int[] viewRows = propertyTable.getSelectedRows();
218
        int[] modelRows = new int[viewRows.length];
219
220
        for (int i = 0; i < viewRows.length; i++) {
221
            modelRows[i] = propertyTable.convertRowIndexToModel(viewRows[i]);
222
        }
223
224
        Arrays.sort(modelRows);
225
226
        DefaultTableModel dtm = (DefaultTableModel) propertyTable.getModel();
227
228
        for (int i = modelRows.length - 1; i >= 0; i--) {
229
            dtm.removeRow(modelRows[i]);
230
        }
231
    }//GEN-LAST:event_removeRowButtonActionPerformed
232
    // Variables declaration - do not modify//GEN-BEGIN:variables
233
    private javax.swing.JButton addRowButton;
234
    private javax.swing.JPanel buttonPanel;
235
    private javax.swing.JScrollPane propertyScrollPane;
236
    private javax.swing.JTable propertyTable;
237
    private javax.swing.JButton removeRowButton;
238
    // End of variables declaration//GEN-END:variables
239
}
(-)a/db/src/org/netbeans/modules/db/util/PropertiesEditor.java (+106 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.db.util;
43
44
import java.beans.FeatureDescriptor;
45
import java.beans.PropertyEditorSupport;
46
import java.util.Properties;
47
import org.openide.explorer.propertysheet.ExPropertyEditor;
48
import org.openide.explorer.propertysheet.PropertyEnv;
49
import org.openide.nodes.Node;
50
import org.openide.util.NbBundle;
51
52
/**
53
 * Custom editor for properties - mainly exists to call custom editor
54
 *
55
 * @author Matthias Bläsing
56
 */
57
public class PropertiesEditor extends PropertyEditorSupport implements ExPropertyEditor {
58
59
    private boolean canWrite = true;
60
61
    @Override
62
    public String getAsText() {
63
        Properties value = (Properties) getValue();
64
        if (value == null || value.size() == 0) {
65
            return NbBundle.getMessage(PropertiesEditor.class,
66
                    "NoPropertiesSet");                                 //NOI18N
67
        } else {
68
            return value.toString();
69
        }
70
    }
71
72
    /**
73
     * Can't be called and throws IllegalArgumentException
74
     */
75
    @Override
76
    public void setAsText(String text) throws IllegalArgumentException {
77
        throw new IllegalArgumentException("Can't be set by setAsText");//NOI18N
78
    }
79
80
    @Override
81
    public String getJavaInitializationString() {
82
        return null; // does not generate any code
83
    }
84
85
    @Override
86
    public boolean supportsCustomEditor() {
87
        return true;
88
    }
89
90
    @Override
91
    public java.awt.Component getCustomEditor() {
92
        return new PropertiesCustomEditor(this);
93
    }
94
95
    @Override
96
    public void attachEnv(PropertyEnv env) {
97
        FeatureDescriptor d = env.getFeatureDescriptor();
98
        if (d instanceof Node.Property) {
99
            canWrite = ((Node.Property) d).canWrite();
100
        }
101
    }
102
103
    public boolean isEditable() {
104
        return canWrite;
105
    }
106
}
(-)a/db/test/unit/src/org/netbeans/modules/db/explorer/DatabaseConnectionConvertorTest.java (-1 / +1 lines)
Lines 147-153 Link Here
147
    }
147
    }
148
    
148
    
149
    public void testSaveOnPropertyChange() throws Exception {
149
    public void testSaveOnPropertyChange() throws Exception {
150
        DatabaseConnection dbconn = new DatabaseConnection("a", "b", "c", "d", "e", null);
150
        DatabaseConnection dbconn = new DatabaseConnection("a", "b", "c", "d", "e", (String) null);
151
        FileObject fo = DatabaseConnectionConvertor.create(dbconn).getPrimaryFile();
151
        FileObject fo = DatabaseConnectionConvertor.create(dbconn).getPrimaryFile();
152
        
152
        
153
        class FCL extends FileChangeAdapter {
153
        class FCL extends FileChangeAdapter {

Return to bug 197408