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

(-)db/src/org/netbeans/api/db/explorer/node/NodeProvider.java (-1 / +1 lines)
Lines 157-163 Link Here
157
        synchronized (nodeSet) {
157
        synchronized (nodeSet) {
158
            for (Node child : nodeSet) {
158
            for (Node child : nodeSet) {
159
                Object obj = child.getLookup().lookup(dataObject.getClass());
159
                Object obj = child.getLookup().lookup(dataObject.getClass());
160
                if (obj.hashCode() == dataObject.hashCode() && obj.equals(dataObject)) {
160
                if (obj != null && obj.hashCode() == dataObject.hashCode() && obj.equals(dataObject)) {
161
                    results.add(child);
161
                    results.add(child);
162
                }
162
                }
163
            }
163
            }
(-)db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java (+61 lines)
Lines 125-130 Link Here
125
    /** The default schema */
125
    /** The default schema */
126
    private String defaultSchema = null;
126
    private String defaultSchema = null;
127
127
128
    private Set<String> importantSchemas = null;
129
    
130
    private Set<String> importantCatalogs = null;
131
128
    /** Schema name */
132
    /** Schema name */
129
    private String schema;
133
    private String schema;
130
134
Lines 1214-1217 Link Here
1214
        return this;
1218
        return this;
1215
    }
1219
    }
1216
1220
1221
    public Set<String> getImportantSchemas() {
1222
        if (importantSchemas == null) {
1223
            return Collections.emptySet();
1224
        } else {
1225
            return Collections.unmodifiableSet(importantSchemas);
1217
}
1226
}
1227
    }
1228
1229
    public void addImportantSchema(String schema) {
1230
        if (importantSchemas == null) {
1231
            importantSchemas = new HashSet<String>();
1232
        }
1233
        List<String> oldList = new ArrayList<String>(importantSchemas);
1234
        importantSchemas.add(schema);
1235
        propertySupport.firePropertyChange("importantSchemas", oldList, importantSchemas);
1236
    }
1237
1238
    public void removeImportantSchema(String schema) {
1239
        if (importantSchemas != null) {
1240
            List<String> oldList = new ArrayList<String>(importantSchemas);
1241
            importantSchemas.remove(schema);
1242
            propertySupport.firePropertyChange("importantSchemas", oldList, importantSchemas);
1243
        }
1244
    }
1245
1246
    public boolean isImportantSchema(String schema) {
1247
        return importantSchemas != null && importantSchemas.contains(schema);
1248
    }
1249
    
1250
    public Set<String> getImportantCatalogs() {
1251
        if (importantCatalogs == null) {
1252
            return Collections.emptySet();
1253
        } else {
1254
            return Collections.unmodifiableSet(importantCatalogs);
1255
        }
1256
    }
1257
1258
    public void addImportantCatalog(String database) {
1259
        if (importantCatalogs == null) {
1260
            importantCatalogs = new HashSet<String>();
1261
        }
1262
        List<String> oldList = new ArrayList<String>(importantCatalogs);
1263
        importantCatalogs.add(database);
1264
        propertySupport.firePropertyChange("importantCatalogs", oldList, importantCatalogs);
1265
    }
1266
1267
    public void removeImportantCatalog(String database) {
1268
        if (importantCatalogs != null) {
1269
            List<String> oldList = new ArrayList<String>(importantCatalogs);
1270
            importantCatalogs.remove(database);
1271
            propertySupport.firePropertyChange("importantCatalogs", oldList, importantCatalogs);
1272
        }
1273
    }
1274
1275
    public boolean isImportantCatalog(String database) {
1276
        return importantCatalogs != null && importantCatalogs.contains(database);
1277
    }
1278
}
(-)db/src/org/netbeans/modules/db/explorer/DatabaseConnectionConvertor.java (+22 lines)
Lines 58-64 Link Here
58
import java.nio.charset.Charset;
58
import java.nio.charset.Charset;
59
import java.nio.charset.CharsetDecoder;
59
import java.nio.charset.CharsetDecoder;
60
import java.nio.charset.CoderResult;
60
import java.nio.charset.CoderResult;
61
import java.util.ArrayList;
61
import java.util.LinkedList;
62
import java.util.LinkedList;
63
import java.util.List;
62
import java.util.Map;
64
import java.util.Map;
63
import java.util.WeakHashMap;
65
import java.util.WeakHashMap;
64
import java.util.concurrent.ConcurrentHashMap;
66
import java.util.concurrent.ConcurrentHashMap;
Lines 242-247 Link Here
242
        if (handler.displayName != null) {
244
        if (handler.displayName != null) {
243
            dbconn.setDisplayName(handler.displayName);
245
            dbconn.setDisplayName(handler.displayName);
244
        }
246
        }
247
        for (String importantSchema : handler.importantSchemas) {
248
            dbconn.addImportantSchema(importantSchema);
249
        }
250
        for (String importantDatabase : handler.importantDatabases) {
251
            dbconn.addImportantCatalog(importantDatabase);
252
        }
245
        LOGGER.fine("Created DatabaseConnection[" + dbconn.toString() + "] from file: " + handler.connectionFileName);
253
        LOGGER.fine("Created DatabaseConnection[" + dbconn.toString() + "] from file: " + handler.connectionFileName);
246
254
247
        return dbconn;
255
        return dbconn;
Lines 395-400 Link Here
395
            if (!instance.getName().equals(instance.getDisplayName())) {
403
            if (!instance.getName().equals(instance.getDisplayName())) {
396
                pw.println("  <display-name value='" + XMLUtil.toAttributeValue(instance.getDisplayName()) + "'/>"); //NOI18N
404
                pw.println("  <display-name value='" + XMLUtil.toAttributeValue(instance.getDisplayName()) + "'/>"); //NOI18N
397
            }
405
            }
406
            for (String importantSchema : instance.getImportantSchemas()) {
407
                pw.println("  <important-schema value='" + XMLUtil.toAttributeValue(importantSchema) + "'/>"); //NOI18N
408
            }
409
            for (String importantDatabase : instance.getImportantCatalogs()) {
410
                pw.println("  <important-catalog value='" + XMLUtil.toAttributeValue(importantDatabase) + "'/>"); //NOI18N
411
            }
398
            if (instance.rememberPassword() ) {
412
            if (instance.rememberPassword() ) {
399
                char[] password = instance.getPassword() == null ? new char[0] : instance.getPassword().toCharArray();
413
                char[] password = instance.getPassword() == null ? new char[0] : instance.getPassword().toCharArray();
400
                
414
                
Lines 418-423 Link Here
418
        private static final String ELEMENT_USER = "user"; // NOI18N
432
        private static final String ELEMENT_USER = "user"; // NOI18N
419
        private static final String ELEMENT_PASSWORD = "password"; // NOI18N
433
        private static final String ELEMENT_PASSWORD = "password"; // NOI18N
420
        private static final String ELEMENT_DISPLAY_NAME = "display-name"; // NOI18N
434
        private static final String ELEMENT_DISPLAY_NAME = "display-name"; // NOI18N
435
        private static final String ELEMENT_IMPORTANT_SCHEMA = "important-schema"; //NOI18N
436
        private static final String ELEMENT_IMPORTANT_CATALOG = "important-catalog"; //NOI18N
421
        private static final String ATTR_PROPERTY_VALUE = "value"; // NOI18N
437
        private static final String ATTR_PROPERTY_VALUE = "value"; // NOI18N
422
        
438
        
423
        final String connectionFileName;
439
        final String connectionFileName;
Lines 428-433 Link Here
428
        String schema;
444
        String schema;
429
        String user;
445
        String user;
430
        String displayName;
446
        String displayName;
447
        List<String> importantSchemas = new ArrayList<String>();
448
        List<String> importantDatabases = new ArrayList<String>();
431
        
449
        
432
        public Handler(String connectionFileName) {
450
        public Handler(String connectionFileName) {
433
            this.connectionFileName = connectionFileName;
451
            this.connectionFileName = connectionFileName;
Lines 480-485 Link Here
480
                        // no password stored => this will require the user to re-enter the password
498
                        // no password stored => this will require the user to re-enter the password
481
                    }
499
                    }
482
                }
500
                }
501
            } else if (ELEMENT_IMPORTANT_SCHEMA.equals(qName)) {
502
                importantSchemas.add(value);
503
            } else if (ELEMENT_IMPORTANT_CATALOG.equals(qName)) {
504
                importantDatabases.add(value);
483
            }
505
            }
484
        }
506
        }
485
    }
507
    }
(-)db/src/org/netbeans/modules/db/explorer/action/Bundle.properties (+3 lines)
Lines 60-65 Link Here
60
ExecuteCommand=Execute Command...
60
ExecuteCommand=Execute Command...
61
MakeDefaultCatalog=Set As Default Catalog
61
MakeDefaultCatalog=Set As Default Catalog
62
MakeDefaultSchema=Set as Default Schema
62
MakeDefaultSchema=Set as Default Schema
63
ToggleImportantAdd=Mark as important
64
ToggleImportantRemove=Mark as unimportant
65
ToggleImportant=Toggle important
63
66
64
MSG_ViewsAreNotSupported={0} does not support views.
67
MSG_ViewsAreNotSupported={0} does not support views.
65
68
(-)db/src/org/netbeans/modules/db/explorer/action/ToggleImportantAction.java (+179 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 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 2009-2010 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.db.explorer.action;
43
44
import java.util.ArrayList;
45
import java.util.HashMap;
46
import java.util.HashSet;
47
import java.util.List;
48
import java.util.Map;
49
import java.util.Set;
50
import java.util.logging.Logger;
51
import org.netbeans.api.db.explorer.DatabaseException;
52
import org.netbeans.modules.db.explorer.DatabaseConnection;
53
import org.netbeans.modules.db.explorer.node.ToggleImportantInfo;
54
import org.netbeans.modules.db.metadata.model.api.Action;
55
import org.netbeans.modules.db.metadata.model.api.Catalog;
56
import org.netbeans.modules.db.metadata.model.api.Metadata;
57
import org.netbeans.modules.db.metadata.model.api.MetadataElement;
58
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle;
59
import org.netbeans.modules.db.metadata.model.api.MetadataModelException;
60
import org.netbeans.modules.db.metadata.model.api.Schema;
61
import org.openide.nodes.Node;
62
import org.openide.util.Exceptions;
63
import org.openide.util.HelpCtx;
64
import org.openide.util.NbBundle;
65
66
/**
67
 *
68
 * @author Jaroslav Havlin
69
 */
70
public class ToggleImportantAction extends BaseAction {
71
72
    private static final Logger LOGGER =
73
            Logger.getLogger(MakeDefaultCatalogAction.class.getName());
74
    private String name;
75
76
    @Override
77
    public String getName() {
78
        return name;
79
    }
80
81
    @Override
82
    protected boolean enable(Node[] activatedNodes) {
83
        boolean toggleImportant = false;
84
        boolean toggleUnImportant = false;
85
        
86
        for(Node node: activatedNodes) {
87
            ToggleImportantInfo tii = node.getLookup().lookup(ToggleImportantInfo.class);
88
            if(tii != null) {
89
                if(! tii.isDefault()) {
90
                    if(tii.isImportant()) {
91
                        toggleUnImportant = true;
92
                    } else {
93
                        toggleImportant = true;
94
                    }
95
                }
96
            }
97
        }
98
        
99
        if (toggleUnImportant && toggleImportant) {
100
            name = NbBundle.getMessage(ToggleImportantAction.class,
101
                    "ToggleImportant");                   //NOI18N
102
            return true;
103
        } else if (toggleUnImportant) {
104
            name = NbBundle.getMessage(ToggleImportantAction.class,
105
                    "ToggleImportantRemove");                   //NOI18N
106
            return true;
107
        } else if (toggleImportant) {
108
            name = name = NbBundle.getMessage(
109
                    ToggleImportantAction.class,
110
                    "ToggleImportantAdd");                      //NOI18N
111
            return true;
112
        }
113
114
        return false;
115
    }
116
117
    @Override
118
    protected void performAction(final Node[] activatedNodes) {
119
        Set<DatabaseConnection> connections = new HashSet<DatabaseConnection>();
120
        
121
        for (Node node : activatedNodes) {
122
            DatabaseConnection conn = node.getLookup().lookup(DatabaseConnection.class);
123
            ToggleImportantInfo tii = node.getLookup().lookup(ToggleImportantInfo.class);
124
            if (conn != null && tii != null &&
125
                    Catalog.class.isAssignableFrom(tii.getType())) {
126
                String name = node.getName();
127
                if(name.equals(conn.getDefaultCatalog())) {
128
                    tii.setDefault(true);
129
                    tii.setImportant(false);
130
                    conn.removeImportantCatalog(name);
131
                } else if (! conn.isImportantCatalog(name)) {
132
                    conn.addImportantCatalog(name);
133
                    tii.setDefault(false);
134
                    tii.setImportant(true);
135
                } else {
136
                    conn.removeImportantCatalog(name);
137
                    tii.setDefault(false);
138
                    tii.setImportant(false);
139
                }
140
                connections.add(conn);
141
            } else if (conn != null && tii != null &&
142
                    Schema.class.isAssignableFrom(tii.getType())) {
143
                String name = node.getName();
144
                if(name.equals(conn.getDefaultSchema())) {
145
                    tii.setDefault(true);
146
                    tii.setImportant(false);
147
                    conn.removeImportantSchema(name);
148
                } else if (! conn.isImportantSchema(name)) {
149
                    conn.addImportantSchema(name);
150
                    tii.setDefault(false);
151
                    tii.setImportant(true);
152
                } else {
153
                    conn.removeImportantSchema(name);
154
                    tii.setDefault(false);
155
                    tii.setImportant(false);
156
                }
157
                connections.add(conn);
158
            }
159
        }
160
//
161
//        for (DatabaseConnection conn : connections) {
162
//            try {
163
//                conn.refreshInExplorer();
164
//                conn.notifyChange();
165
//            } catch (DatabaseException ex) {
166
//                Exceptions.printStackTrace(ex);
167
//            }
168
//        }
169
    }
170
    
171
    @Override
172
    public HelpCtx getHelpCtx() {
173
        return null;
174
    }
175
    
176
    private static class ClassContainer {
177
        private Class klazz;
178
    }
179
}
(-)db/src/org/netbeans/modules/db/explorer/node/CatalogNode.java (-6 / +22 lines)
Lines 44-49 Link Here
44
44
45
import java.beans.PropertyChangeEvent;
45
import java.beans.PropertyChangeEvent;
46
import java.beans.PropertyChangeListener;
46
import java.beans.PropertyChangeListener;
47
import javax.swing.SwingWorker;
47
import org.netbeans.api.db.explorer.node.BaseNode;
48
import org.netbeans.api.db.explorer.node.BaseNode;
48
import org.netbeans.api.db.explorer.node.ChildNodeFactory;
49
import org.netbeans.api.db.explorer.node.ChildNodeFactory;
49
import org.netbeans.api.db.explorer.node.NodeProvider;
50
import org.netbeans.api.db.explorer.node.NodeProvider;
Lines 81-96 Link Here
81
    private String htmlName = null;
82
    private String htmlName = null;
82
    private final DatabaseConnection connection;
83
    private final DatabaseConnection connection;
83
    private final MetadataElementHandle<Catalog> catalogHandle;
84
    private final MetadataElementHandle<Catalog> catalogHandle;
85
    private final ToggleImportantInfo toggleImportantInfo = new ToggleImportantInfo(
86
            Catalog.class
87
            );
84
88
85
    @SuppressWarnings("unchecked")
89
    @SuppressWarnings("unchecked")
86
    private CatalogNode(NodeDataLookup lookup, NodeProvider provider) {
90
    private CatalogNode(NodeDataLookup lookup, NodeProvider provider) {
87
        super(new ChildNodeFactory(lookup), lookup, FOLDER, provider);
91
        super(new ChildNodeFactory(lookup), lookup, FOLDER, provider);
88
        connection = getLookup().lookup(DatabaseConnection.class);
92
        connection = getLookup().lookup(DatabaseConnection.class);
89
        catalogHandle = getLookup().lookup(MetadataElementHandle.class);
93
        catalogHandle = getLookup().lookup(MetadataElementHandle.class);
94
        lookup.add(toggleImportantInfo);
90
    }
95
    }
91
96
92
    protected void initialize() {
97
    protected void initialize() {
93
        setupNames();
98
        refreshMetaData();
94
99
95
        connection.addPropertyChangeListener(
100
        connection.addPropertyChangeListener(
96
            new PropertyChangeListener() {
101
            new PropertyChangeListener() {
Lines 103-130 Link Here
103
        );
108
        );
104
    }
109
    }
105
110
106
    private void setupNames() {
111
    private void refreshMetaData() {
107
        MetadataModel metaDataModel = connection.getMetadataModel();
112
        final MetadataModel metaDataModel = connection.getMetadataModel();
108
        boolean connected = !connection.getConnector().isDisconnected();
113
        boolean connected = !connection.getConnector().isDisconnected();
109
        if (connected && metaDataModel != null) {
114
        if (connected && metaDataModel != null) {
115
116
            new SwingWorker() {
117
                @Override
118
                protected Object doInBackground() throws Exception {
110
            try {
119
            try {
111
                metaDataModel.runReadAction(
120
                metaDataModel.runReadAction(
112
                    new Action<Metadata>() {
121
                    new Action<Metadata>() {
113
                        public void run(Metadata metaData) {
122
                        public void run(Metadata metaData) {
114
                            Catalog catalog = catalogHandle.resolve(metaData);
123
                            Catalog catalog = catalogHandle.resolve(metaData);
124
                                        toggleImportantInfo.setDefault(catalog.isDefault());
125
                                        toggleImportantInfo.setImportant(connection.isImportantCatalog(name));
115
                            renderNames(catalog);
126
                            renderNames(catalog);
116
                        }
127
                        }
117
                    }
128
                                });
118
                );
129
                        return null;
119
            } catch (MetadataModelException e) {
130
            } catch (MetadataModelException e) {
120
                NodeRegistry.handleMetadataModelException(this.getClass(), connection, e, true);
131
                NodeRegistry.handleMetadataModelException(this.getClass(), connection, e, true);
132
                        return null;
121
            }
133
            }
134
122
        }
135
        }
136
            }.run();
137
123
    }
138
    }
139
    }
124
140
125
    @Override
141
    @Override
126
    protected void updateProperties() {
142
    protected void updateProperties() {
127
        setupNames();
143
        refreshMetaData();
128
        super.updateProperties();
144
        super.updateProperties();
129
    }
145
    }
130
146
(-)db/src/org/netbeans/modules/db/explorer/node/CatalogNodeProvider.java (-19 / +114 lines)
Lines 42-51 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.PropertyChangeEvent;
46
import java.beans.PropertyChangeListener;
45
import java.util.ArrayList;
47
import java.util.ArrayList;
48
import java.util.Arrays;
46
import java.util.Collection;
49
import java.util.Collection;
50
import java.util.Collections;
47
import java.util.Comparator;
51
import java.util.Comparator;
48
import java.util.List;
52
import java.util.List;
53
import javax.swing.SwingWorker;
49
import org.netbeans.api.db.explorer.node.NodeProvider;
54
import org.netbeans.api.db.explorer.node.NodeProvider;
50
import org.netbeans.api.db.explorer.node.NodeProviderFactory;
55
import org.netbeans.api.db.explorer.node.NodeProviderFactory;
51
import org.netbeans.modules.db.explorer.DatabaseConnection;
56
import org.netbeans.modules.db.explorer.DatabaseConnection;
Lines 55-68 Link Here
55
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle;
60
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle;
56
import org.netbeans.modules.db.metadata.model.api.MetadataModel;
61
import org.netbeans.modules.db.metadata.model.api.MetadataModel;
57
import org.netbeans.modules.db.metadata.model.api.MetadataModelException;
62
import org.netbeans.modules.db.metadata.model.api.MetadataModelException;
63
import org.openide.nodes.AbstractNode;
64
import org.openide.nodes.ChildFactory;
65
import org.openide.nodes.Children;
58
import org.openide.nodes.Node;
66
import org.openide.nodes.Node;
59
import org.openide.util.Lookup;
67
import org.openide.util.Lookup;
68
import org.openide.util.NbBundle;
69
import org.openide.util.WeakListeners;
60
70
61
/**
71
/**
62
 *
72
 *
63
 * @author Rob Englander
73
 * @author Rob Englander
64
 */
74
 */
65
public class CatalogNodeProvider extends NodeProvider {
75
public class CatalogNodeProvider extends NodeProvider implements PropertyChangeListener {
66
76
67
    // lazy initialization holder class idiom for static fields is used
77
    // lazy initialization holder class idiom for static fields is used
68
    // for retrieving the factory
78
    // for retrieving the factory
Lines 79-84 Link Here
79
        };
89
        };
80
    }
90
    }
81
91
92
    private final List<Node> nodes = new ArrayList<Node>();
82
    private final DatabaseConnection connection;
93
    private final DatabaseConnection connection;
83
94
84
    private CatalogNodeProvider(Lookup lookup) {
95
    private CatalogNodeProvider(Lookup lookup) {
Lines 89-98 Link Here
89
    @Override
100
    @Override
90
    protected synchronized void initialize() {
101
    protected synchronized void initialize() {
91
        final List<Node> newList = new ArrayList<Node>();
102
        final List<Node> newList = new ArrayList<Node>();
103
        final List<Node> otherList = new ArrayList<Node>();
92
104
93
        MetadataModel metaDataModel = connection.getMetadataModel();
105
        MetadataModel metaDataModel = connection.getMetadataModel();
94
        boolean isConnected = !connection.getConnector().isDisconnected();
106
        boolean isConnected = !connection.getConnector().isDisconnected();
95
107
108
        nodes.clear();
109
        
96
        if (isConnected && metaDataModel != null) {
110
        if (isConnected && metaDataModel != null) {
97
            try {
111
            try {
98
                metaDataModel.runReadAction(
112
                metaDataModel.runReadAction(
Lines 100-129 Link Here
100
                        public void run(Metadata metaData) {
114
                        public void run(Metadata metaData) {
101
                            Collection<Catalog> catalogs = metaData.getCatalogs();
115
                            Collection<Catalog> catalogs = metaData.getCatalogs();
102
116
103
                            String defaultCatalog = metaData.getDefaultCatalog().getName();
104
105
                            for (Catalog catalog : catalogs) {
117
                            for (Catalog catalog : catalogs) {
106
                                boolean oneCatalog = catalogs.size() == 1;
118
                                boolean oneCatalog = catalogs.size() == 1;
107
                                if (catalog.getName() != null || oneCatalog) {
119
                                if (catalog.getName() != null || oneCatalog) {
108
120
                                    if(isDefaultCatalog(catalog, connection)) {
109
                                    boolean use = true;
121
                                        updateNode(newList, catalog);
110
                                    //if (defaultCatalog != null) {
111
                                    //    use = defaultCatalog.equals(catalog.getName());
112
                                    //}
113
114
                                    if (use) {
115
                                        MetadataElementHandle<Catalog> catalogHandle = MetadataElementHandle.create(catalog);
116
                                        Collection<Node> matches = getNodes(catalogHandle);
117
                                        if (matches.size() > 0) {
118
                                            newList.addAll(matches);
119
                                        } else {
122
                                        } else {
120
                                            NodeDataLookup lookup = new NodeDataLookup();
123
                                        updateNode(otherList, catalog);
121
                                            lookup.add(connection);
122
                                            lookup.add(catalogHandle);
123
                                            newList.add(CatalogNode.create(lookup, CatalogNodeProvider.this));
124
                                        }
124
                                        }
125
                                    }
125
                                    }
126
                                }
126
                                }
127
                            
128
                            nodes.addAll(newList);
129
                            nodes.addAll(otherList);
130
131
                            if (!otherList.isEmpty()) {
132
                                newList.add(new CatalogNodeProvider.OtherCatalogsNode (
133
                                        otherList));
127
                            }
134
                            }
128
135
129
                            if (newList.size() == 1) {
136
                            if (newList.size() == 1) {
Lines 141-153 Link Here
141
           setNodes(newList);
148
           setNodes(newList);
142
        }
149
        }
143
150
151
        connection.addPropertyChangeListener(WeakListeners.propertyChange(this, connection));
144
    }
152
    }
145
153
146
    static class CatalogComparator implements Comparator<Node> {
154
    private boolean isDefaultCatalog(Catalog catalog,
155
            DatabaseConnection connection) {
147
156
157
        String def = connection.getDefaultCatalog();
158
        return (def == null && catalog.isDefault())
159
                || (def != null && def.equals(catalog.getName())
160
                || connection.isImportantCatalog(catalog.getName()));
161
    }
162
    
163
    private void updateNode(List<Node> newList, Catalog catalog) {
164
        MetadataElementHandle<Catalog> catalogHandle = MetadataElementHandle.create(catalog);
165
        Collection<Node> matches = getNodes(catalogHandle);
166
        if (matches != null && matches.size() > 0) {
167
            newList.addAll(matches);
168
        } else {
169
            NodeDataLookup lookup = new NodeDataLookup();
170
            lookup.add(connection);
171
            lookup.add(catalogHandle);
172
173
            newList.add(CatalogNode.create(lookup, this));
174
        }
175
    }
176
177
    @Override
178
    public void propertyChange(PropertyChangeEvent pce) {
179
        if (this.initialized && "importantCatalogs".equals(pce.getPropertyName())) {
180
            final List<Node> mainList = new ArrayList<Node>();
181
            final List<Node> otherList = new ArrayList<Node>();
182
            
183
            for(Node node: new ArrayList<Node>(nodes)) {
184
                if(connection.isImportantCatalog(node.getName())) {
185
                    mainList.add(node.cloneNode());
186
                } else {
187
                    otherList.add(node.cloneNode());
188
                }
189
            }
190
            
191
            if(! otherList.isEmpty()) {
192
                mainList.add(new OtherCatalogsNode(otherList));
193
            }
194
            
195
            setNodes(mainList);
196
        }
197
    }
198
199
    static class CatalogComparator implements Comparator<Node> {
200
        @Override
148
        public int compare(Node node1, Node node2) {
201
        public int compare(Node node1, Node node2) {
202
            if(node1 instanceof OtherCatalogsNode) {
203
                return 1;
204
            }
205
            if(node2 instanceof OtherCatalogsNode) {
206
                return -1;
207
            }
149
            return node1.getDisplayName().compareToIgnoreCase(node2.getDisplayName());
208
            return node1.getDisplayName().compareToIgnoreCase(node2.getDisplayName());
150
        }
209
        }
151
210
152
    }
211
    }
212
    
213
    @NbBundle.Messages({
214
        "LBL_OtherDatabases=Other databases"
215
    })
216
    private static class OtherCatalogsNode extends AbstractNode {
217
218
        private static final String ICON_BASE =
219
                "org/netbeans/modules/db/resources/database.gif";         //NOI18N
220
221
        public OtherCatalogsNode(List<Node> otherList) {
222
            super(createChildren(otherList));
223
            setDisplayName(Bundle.LBL_OtherDatabases());
224
            setIconBaseWithExtension(ICON_BASE);
153
}
225
}
226
227
        @Override
228
        public String getName() {
229
            return "zzzzzz";                                            //NOI18N
230
        }
231
232
        private static Children createChildren(final List<Node> otherList) {
233
            Children c = Children.create(new ChildFactory<Node>() {
234
                @Override
235
                protected boolean createKeys(final List<Node> toPopulate) {
236
                    toPopulate.addAll(otherList);
237
                    return true;
238
                }
239
240
                @Override
241
                protected Node createNodeForKey(Node key) {
242
                    return key;
243
                }
244
            }, false);
245
            return c;
246
        }
247
    }
248
}
(-)db/src/org/netbeans/modules/db/explorer/node/SchemaNode.java (-4 / +18 lines)
Lines 44-54 Link Here
44
44
45
import java.beans.PropertyChangeEvent;
45
import java.beans.PropertyChangeEvent;
46
import java.beans.PropertyChangeListener;
46
import java.beans.PropertyChangeListener;
47
import javax.swing.SwingWorker;
47
import org.netbeans.api.db.explorer.node.BaseNode;
48
import org.netbeans.api.db.explorer.node.BaseNode;
48
import org.netbeans.api.db.explorer.node.ChildNodeFactory;
49
import org.netbeans.api.db.explorer.node.ChildNodeFactory;
49
import org.netbeans.api.db.explorer.node.NodeProvider;
50
import org.netbeans.api.db.explorer.node.NodeProvider;
50
import org.netbeans.modules.db.explorer.DatabaseConnection;
51
import org.netbeans.modules.db.explorer.DatabaseConnection;
51
import org.netbeans.modules.db.metadata.model.api.Action;
52
import org.netbeans.modules.db.metadata.model.api.Action;
53
import org.netbeans.modules.db.metadata.model.api.Catalog;
52
import org.netbeans.modules.db.metadata.model.api.Metadata;
54
import org.netbeans.modules.db.metadata.model.api.Metadata;
53
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle;
55
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle;
54
import org.netbeans.modules.db.metadata.model.api.MetadataModel;
56
import org.netbeans.modules.db.metadata.model.api.MetadataModel;
Lines 82-93 Link Here
82
84
83
    private final MetadataElementHandle<Schema> schemaHandle;
85
    private final MetadataElementHandle<Schema> schemaHandle;
84
    private final DatabaseConnection connection;
86
    private final DatabaseConnection connection;
87
    private final ToggleImportantInfo toggleImportantInfo = new ToggleImportantInfo(
88
            Schema.class
89
            );
85
90
86
    @SuppressWarnings("unchecked")
91
    @SuppressWarnings("unchecked")
87
    private SchemaNode(NodeDataLookup lookup, NodeProvider provider) {
92
    private SchemaNode(NodeDataLookup lookup, NodeProvider provider) {
88
        super(new ChildNodeFactory(lookup), lookup, FOLDER, provider);
93
        super(new ChildNodeFactory(lookup), lookup, FOLDER, provider);
89
        connection = getLookup().lookup(DatabaseConnection.class);
94
        connection = getLookup().lookup(DatabaseConnection.class);
90
        schemaHandle = getLookup().lookup(MetadataElementHandle.class);
95
        schemaHandle = getLookup().lookup(MetadataElementHandle.class);
96
        lookup.add(toggleImportantInfo);
91
    }
97
    }
92
98
93
    @Override
99
    @Override
Lines 108-130 Link Here
108
114
109
    private void setupNames() {
115
    private void setupNames() {
110
        boolean connected = !connection.getConnector().isDisconnected();
116
        boolean connected = !connection.getConnector().isDisconnected();
111
        MetadataModel metaDataModel = connection.getMetadataModel();
117
        final MetadataModel metaDataModel = connection.getMetadataModel();
112
        if (connected && metaDataModel != null) {
118
        if (connected && metaDataModel != null) {
119
            new SwingWorker() {
120
                @Override
121
                protected Object doInBackground() throws Exception {
113
            try {
122
            try {
114
                metaDataModel.runReadAction(
123
                metaDataModel.runReadAction(
115
                    new Action<Metadata>() {
124
                    new Action<Metadata>() {
116
                    @Override
117
                        public void run(Metadata metaData) {
125
                        public void run(Metadata metaData) {
118
                            Schema schema = schemaHandle.resolve(metaData);
126
                            Schema schema = schemaHandle.resolve(metaData);
127
                                        toggleImportantInfo.setDefault(schema.isDefault());
128
                                        toggleImportantInfo.setImportant(connection.isImportantSchema(name));
119
                            renderNames(schema);
129
                            renderNames(schema);
120
                        }
130
                        }
121
                    }
131
                                });
122
                );
132
                        return null;
123
            } catch (MetadataModelException e) {
133
            } catch (MetadataModelException e) {
124
                NodeRegistry.handleMetadataModelException(this.getClass(), connection, e, true);
134
                NodeRegistry.handleMetadataModelException(this.getClass(), connection, e, true);
135
                        return null;
125
            }
136
            }
137
126
        }
138
        }
139
            }.run();
127
    }
140
    }
141
    }
128
142
129
    @Override
143
    @Override
130
    protected void updateProperties() {
144
    protected void updateProperties() {
(-)db/src/org/netbeans/modules/db/explorer/node/SchemaNodeProvider.java (-5 / +104 lines)
Lines 39-51 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.modules.db.explorer.node;
42
package org.netbeans.modules.db.explorer.node;
44
43
44
import java.beans.PropertyChangeEvent;
45
import java.beans.PropertyChangeListener;
45
import java.util.ArrayList;
46
import java.util.ArrayList;
47
import java.util.Arrays;
46
import java.util.Collection;
48
import java.util.Collection;
47
import java.util.Comparator;
49
import java.util.Comparator;
48
import java.util.List;
50
import java.util.List;
51
import javax.swing.SwingWorker;
49
import org.netbeans.api.db.explorer.node.NodeProvider;
52
import org.netbeans.api.db.explorer.node.NodeProvider;
50
import org.netbeans.api.db.explorer.node.NodeProviderFactory;
53
import org.netbeans.api.db.explorer.node.NodeProviderFactory;
51
import org.netbeans.modules.db.explorer.DatabaseConnection;
54
import org.netbeans.modules.db.explorer.DatabaseConnection;
Lines 56-69 Link Here
56
import org.netbeans.modules.db.metadata.model.api.MetadataModel;
59
import org.netbeans.modules.db.metadata.model.api.MetadataModel;
57
import org.netbeans.modules.db.metadata.model.api.MetadataModelException;
60
import org.netbeans.modules.db.metadata.model.api.MetadataModelException;
58
import org.netbeans.modules.db.metadata.model.api.Schema;
61
import org.netbeans.modules.db.metadata.model.api.Schema;
62
import org.openide.nodes.AbstractNode;
63
import org.openide.nodes.ChildFactory;
64
import org.openide.nodes.Children;
59
import org.openide.nodes.Node;
65
import org.openide.nodes.Node;
60
import org.openide.util.Lookup;
66
import org.openide.util.Lookup;
67
import org.openide.util.NbBundle;
68
import org.openide.util.WeakListeners;
61
69
62
/**
70
/**
63
 *
71
 *
64
 * @author Rob Englander
72
 * @author Rob Englander
65
 */
73
 */
66
public class SchemaNodeProvider extends NodeProvider {
74
public class SchemaNodeProvider extends NodeProvider implements PropertyChangeListener {
67
75
68
    // lazy initialization holder class idiom for static fields is used
76
    // lazy initialization holder class idiom for static fields is used
69
    // for retrieving the factory
77
    // for retrieving the factory
Lines 72-77 Link Here
72
    }
80
    }
73
81
74
    private static class FactoryHolder {
82
    private static class FactoryHolder {
83
75
        static final NodeProviderFactory FACTORY = new NodeProviderFactory() {
84
        static final NodeProviderFactory FACTORY = new NodeProviderFactory() {
76
            @Override
85
            @Override
77
            public SchemaNodeProvider createInstance(Lookup lookup) {
86
            public SchemaNodeProvider createInstance(Lookup lookup) {
Lines 81-86 Link Here
81
        };
90
        };
82
    }
91
    }
83
92
93
    private final List<Node> nodes = new ArrayList<Node>();
84
    private final DatabaseConnection connection;
94
    private final DatabaseConnection connection;
85
    private final MetadataElementHandle<Catalog> catalogHandle;
95
    private final MetadataElementHandle<Catalog> catalogHandle;
86
96
Lines 93-101 Link Here
93
    @Override
103
    @Override
94
    protected synchronized void initialize() {
104
    protected synchronized void initialize() {
95
        final List<Node> newList = new ArrayList<Node>();
105
        final List<Node> newList = new ArrayList<Node>();
106
        final List<Node> otherList = new ArrayList<Node>();
96
107
97
        boolean connected = !connection.getConnector().isDisconnected();
108
        boolean connected = !connection.getConnector().isDisconnected();
98
        MetadataModel metaDataModel = connection.getMetadataModel();
109
        MetadataModel metaDataModel = connection.getMetadataModel();
110
        
111
        nodes.clear();
112
        
99
        if (connected && metaDataModel != null) {
113
        if (connected && metaDataModel != null) {
100
            try {
114
            try {
101
                metaDataModel.runReadAction(
115
                metaDataModel.runReadAction(
Lines 111-120 Link Here
111
                                } else {
125
                                } else {
112
                                    Collection<Schema> schemas = cat.getSchemas();
126
                                    Collection<Schema> schemas = cat.getSchemas();
113
                                    for (Schema schema : schemas) {
127
                                    for (Schema schema : schemas) {
128
                                    if (isDefaultSchema(schema, connection)) {
114
                                        updateNode(newList, schema);
129
                                        updateNode(newList, schema);
130
                                    } else {
131
                                        updateNode(otherList, schema);
115
                                    }
132
                                    }
116
                                }
133
                                }
117
134
135
                                nodes.addAll(newList);
136
                                nodes.addAll(otherList);
137
138
                                if (!otherList.isEmpty()) {
139
                                    newList.add(new OtherSchemasNode(
140
                                            otherList));
141
                                }
142
                            }
143
118
                                if (syntheticSchema != null) {
144
                                if (syntheticSchema != null) {
119
                                    setProxyNodes(newList);
145
                                    setProxyNodes(newList);
120
                                } else {
146
                                } else {
Lines 122-141 Link Here
122
                                }
148
                                }
123
                            }
149
                            }
124
                        }
150
                        }
125
                    }
151
                });
126
                );
127
            } catch (MetadataModelException e) {
152
            } catch (MetadataModelException e) {
128
                NodeRegistry.handleMetadataModelException(this.getClass(), connection, e, true);
153
                NodeRegistry.handleMetadataModelException(this.getClass(), connection, e, true);
129
            }
154
            }
130
        } else {
155
        } else {
131
            setNodes(newList);
156
            setNodes(newList);
132
        }
157
        }
158
        
159
        connection.addPropertyChangeListener(WeakListeners.propertyChange(this, connection));
133
    }
160
    }
134
161
162
    private boolean isDefaultSchema(Schema schema,
163
            DatabaseConnection connection) {
164
165
        String def = connection.getDefaultSchema();
166
        return (def == null && schema.isDefault())
167
                || (def != null && def.equals(schema.getName())
168
                || connection.isImportantSchema(schema.getName()));
169
    }
170
135
    private void updateNode(List<Node> newList, Schema schema) {
171
    private void updateNode(List<Node> newList, Schema schema) {
136
        MetadataElementHandle<Schema> schemaHandle = MetadataElementHandle.create(schema);
172
        MetadataElementHandle<Schema> schemaHandle = MetadataElementHandle.create(schema);
137
        Collection<Node> matches = getNodes(schemaHandle);
173
        Collection<Node> matches = getNodes(schemaHandle);
138
        if (matches.size() > 0) {
174
        if (matches != null && matches.size() > 0) {
139
            newList.addAll(matches);
175
            newList.addAll(matches);
140
        } else {
176
        } else {
141
            NodeDataLookup lookup = new NodeDataLookup();
177
            NodeDataLookup lookup = new NodeDataLookup();
Lines 146-159 Link Here
146
        }
182
        }
147
    }
183
    }
148
184
185
    @Override
186
    public void propertyChange(PropertyChangeEvent pce) {
187
        if (this.initialized && "importantSchemas".equals(pce.getPropertyName())) {
188
            final List<Node> mainList = new ArrayList<Node>();
189
            final List<Node> otherList = new ArrayList<Node>();
190
            
191
            for(Node node: new ArrayList<Node>(nodes)) {
192
                if(connection.isImportantSchema(node.getName())) {
193
                    mainList.add(node.cloneNode());
194
                } else {
195
                    otherList.add(node.cloneNode());
196
                }
197
            }
198
            
199
            if(! otherList.isEmpty()) {
200
                mainList.add(new OtherSchemasNode(otherList));
201
            }
202
            
203
            setNodes(mainList);
204
        }
205
    }
206
149
    static class SchemaComparator implements Comparator<Node> {
207
    static class SchemaComparator implements Comparator<Node> {
150
208
151
        @Override
209
        @Override
152
        public int compare(Node node1, Node node2) {
210
        public int compare(Node node1, Node node2) {
153
            assert node1.getDisplayName() != null : node1 + " has display name.";
211
            assert node1.getDisplayName() != null : node1 + " has display name.";
154
            assert node2.getDisplayName() != null : node2 + " has display name.";
212
            assert node2.getDisplayName() != null : node2 + " has display name.";
213
            if(node1 instanceof OtherSchemasNode) {
214
                return 1;
215
            }
216
            if(node2 instanceof OtherSchemasNode) {
217
                return -1;
218
            }
155
            return node1.getDisplayName().compareToIgnoreCase(node2.getDisplayName());
219
            return node1.getDisplayName().compareToIgnoreCase(node2.getDisplayName());
156
        }
220
        }
221
    }
157
222
223
    @NbBundle.Messages({
224
        "LBL_OtherSchemas=Other schemas"
225
    })
226
    private static class OtherSchemasNode extends AbstractNode {
227
228
        private static final String ICON_BASE =
229
                "org/netbeans/modules/db/resources/schema.png";         //NOI18N
230
231
        public OtherSchemasNode(List<Node> otherList) {
232
            super(createChildren(otherList));
233
            setDisplayName(Bundle.LBL_OtherSchemas());
234
            setIconBaseWithExtension(ICON_BASE);
158
    }
235
    }
236
237
        @Override
238
        public String getName() {
239
            return "zzzzzz";                                            //NOI18N
159
}
240
}
241
242
        private static Children createChildren(final List<Node> otherList) {
243
            Children c = Children.create(new ChildFactory<Node>() {
244
                @Override
245
                protected boolean createKeys(final List<Node> toPopulate) {
246
                    toPopulate.addAll(otherList);
247
                    return true;
248
                }
249
250
                @Override
251
                protected Node createNodeForKey(Node key) {
252
                    return key;
253
                }
254
            }, false);
255
            return c;
256
        }
257
    }
258
}
(-)db/src/org/netbeans/modules/db/explorer/node/ToggleImportantInfo.java (+85 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 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 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.db.explorer.node;
43
44
import org.netbeans.modules.db.metadata.model.api.Metadata;
45
import org.netbeans.modules.db.metadata.model.api.MetadataElement;
46
47
/**
48
 * Represent "important" state for catalogs and schemas
49
 * 
50
 * @author matthias
51
 */
52
public class ToggleImportantInfo {
53
    private Class<? extends MetadataElement> type;
54
    private boolean important;
55
    private boolean isDefault;
56
57
    public ToggleImportantInfo(Class type) {
58
        this.type = type;
59
    }
60
61
    public Class getType() {
62
        return type;
63
    }
64
65
    public void setType(Class type) {
66
        this.type = type;
67
    }
68
69
    public boolean isImportant() {
70
        return important;
71
    }
72
73
    public void setImportant(boolean important) {
74
        this.important = important;
75
    }
76
77
    public boolean isDefault() {
78
        return isDefault;
79
    }
80
81
    public void setDefault(boolean dflt) {
82
        this.isDefault = dflt;
83
    }
84
85
}
(-)db/src/org/netbeans/modules/db/resources/mf-layer.xml (+6 lines)
Lines 177-182 Link Here
177
                    <file name="org-netbeans-modules-db-explorer-action-RefreshAction.instance">
177
                    <file name="org-netbeans-modules-db-explorer-action-RefreshAction.instance">
178
                        <attr name="position" intvalue="350"/>
178
                        <attr name="position" intvalue="350"/>
179
                    </file>
179
                    </file>
180
                    <file name="org-netbeans-modules-db-explorer-action-ToggleImportantAction.instance">
181
                        <attr name="position" intvalue="450"/>
182
                    </file>
180
                </folder>
183
                </folder>
181
            </folder>
184
            </folder>
182
            <folder name="Schema">
185
            <folder name="Schema">
Lines 204-209 Link Here
204
                    <file name="org-netbeans-modules-db-explorer-action-RefreshAction.instance">
207
                    <file name="org-netbeans-modules-db-explorer-action-RefreshAction.instance">
205
                        <attr name="position" intvalue="350"/>
208
                        <attr name="position" intvalue="350"/>
206
                    </file>
209
                    </file>
210
                    <file name="org-netbeans-modules-db-explorer-action-ToggleImportantAction.instance">
211
                        <attr name="position" intvalue="450"/>
212
                    </file>
207
                </folder>
213
                </folder>
208
            </folder>
214
            </folder>
209
            <folder name="TableList">
215
            <folder name="TableList">

Return to bug 202833