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 (+53 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 List<String> importantSchemas = null;
129
    
130
    private List<String> importantDatabases = 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 List<String> getImportantSchemas() {
1222
        if (importantSchemas == null) {
1223
            return Collections.emptyList();
1224
        } else {
1225
            return Collections.unmodifiableList(importantSchemas);
1217
}
1226
}
1227
    }
1228
1229
    public void addImportantSchema(String schema) {
1230
        if (importantSchemas == null) {
1231
            importantSchemas = new ArrayList<String>();
1232
        }
1233
        importantSchemas.add(schema);
1234
    }
1235
1236
    public void removeImportantSchema(String schema) {
1237
        if (importantSchemas != null) {
1238
            importantSchemas.remove(schema);
1239
        }
1240
    }
1241
1242
    public boolean isImportantSchema(String schema) {
1243
        return importantSchemas != null && importantSchemas.contains(schema);
1244
    }
1245
    
1246
    public List<String> getImportantDatabases() {
1247
        if (importantDatabases == null) {
1248
            return Collections.emptyList();
1249
        } else {
1250
            return Collections.unmodifiableList(importantDatabases);
1251
        }
1252
    }
1253
1254
    public void addImportantDatabase(String database) {
1255
        if (importantDatabases == null) {
1256
            importantDatabases = new ArrayList<String>();
1257
        }
1258
        importantDatabases.add(database);
1259
    }
1260
1261
    public void removeImportantDatabase(String database) {
1262
        if (importantDatabases != null) {
1263
            importantDatabases.remove(database);
1264
        }
1265
    }
1266
1267
    public boolean isImportantDatabase(String database) {
1268
        return importantDatabases != null && importantDatabases.contains(database);
1269
    }
1270
}
(-)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.addImportantDatabase(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.getImportantDatabases()) {
410
                pw.println("  <important-database 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_DATABASE = "important-database"; //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_DATABASE.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.removeImportantDatabase(name);
131
                } else if (! conn.isImportantDatabase(name)) {
132
                    conn.addImportantDatabase(name);
133
                    tii.setDefault(false);
134
                    tii.setImportant(true);
135
                } else {
136
                    conn.removeImportantDatabase(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.isImportantDatabase(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 (-3 / +9 lines)
Lines 81-96 Link Here
81
    private String htmlName = null;
81
    private String htmlName = null;
82
    private final DatabaseConnection connection;
82
    private final DatabaseConnection connection;
83
    private final MetadataElementHandle<Catalog> catalogHandle;
83
    private final MetadataElementHandle<Catalog> catalogHandle;
84
    private final ToggleImportantInfo toggleImportantInfo = new ToggleImportantInfo(
85
            Catalog.class
86
            );
84
87
85
    @SuppressWarnings("unchecked")
88
    @SuppressWarnings("unchecked")
86
    private CatalogNode(NodeDataLookup lookup, NodeProvider provider) {
89
    private CatalogNode(NodeDataLookup lookup, NodeProvider provider) {
87
        super(new ChildNodeFactory(lookup), lookup, FOLDER, provider);
90
        super(new ChildNodeFactory(lookup), lookup, FOLDER, provider);
88
        connection = getLookup().lookup(DatabaseConnection.class);
91
        connection = getLookup().lookup(DatabaseConnection.class);
89
        catalogHandle = getLookup().lookup(MetadataElementHandle.class);
92
        catalogHandle = getLookup().lookup(MetadataElementHandle.class);
93
        lookup.add(toggleImportantInfo);
90
    }
94
    }
91
95
92
    protected void initialize() {
96
    protected void initialize() {
93
        setupNames();
97
        refreshMetaData();
94
98
95
        connection.addPropertyChangeListener(
99
        connection.addPropertyChangeListener(
96
            new PropertyChangeListener() {
100
            new PropertyChangeListener() {
Lines 103-109 Link Here
103
        );
107
        );
104
    }
108
    }
105
109
106
    private void setupNames() {
110
    private void refreshMetaData() {
107
        MetadataModel metaDataModel = connection.getMetadataModel();
111
        MetadataModel metaDataModel = connection.getMetadataModel();
108
        boolean connected = !connection.getConnector().isDisconnected();
112
        boolean connected = !connection.getConnector().isDisconnected();
109
        if (connected && metaDataModel != null) {
113
        if (connected && metaDataModel != null) {
Lines 112-117 Link Here
112
                    new Action<Metadata>() {
116
                    new Action<Metadata>() {
113
                        public void run(Metadata metaData) {
117
                        public void run(Metadata metaData) {
114
                            Catalog catalog = catalogHandle.resolve(metaData);
118
                            Catalog catalog = catalogHandle.resolve(metaData);
119
                            toggleImportantInfo.setDefault(catalog.isDefault());
120
                            toggleImportantInfo.setImportant(connection.isImportantDatabase(name));
115
                            renderNames(catalog);
121
                            renderNames(catalog);
116
                        }
122
                        }
117
                    }
123
                    }
Lines 124-130 Link Here
124
130
125
    @Override
131
    @Override
126
    protected void updateProperties() {
132
    protected void updateProperties() {
127
        setupNames();
133
        refreshMetaData();
128
        super.updateProperties();
134
        super.updateProperties();
129
    }
135
    }
130
136
(-)db/src/org/netbeans/modules/db/explorer/node/CatalogNodeProvider.java (-18 / +79 lines)
Lines 55-62 Link Here
55
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle;
55
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle;
56
import org.netbeans.modules.db.metadata.model.api.MetadataModel;
56
import org.netbeans.modules.db.metadata.model.api.MetadataModel;
57
import org.netbeans.modules.db.metadata.model.api.MetadataModelException;
57
import org.netbeans.modules.db.metadata.model.api.MetadataModelException;
58
import org.netbeans.modules.db.metadata.model.api.Schema;
59
import org.openide.nodes.AbstractNode;
60
import org.openide.nodes.ChildFactory;
61
import org.openide.nodes.Children;
58
import org.openide.nodes.Node;
62
import org.openide.nodes.Node;
59
import org.openide.util.Lookup;
63
import org.openide.util.Lookup;
64
import org.openide.util.NbBundle;
60
65
61
/**
66
/**
62
 *
67
 *
Lines 89-94 Link Here
89
    @Override
94
    @Override
90
    protected synchronized void initialize() {
95
    protected synchronized void initialize() {
91
        final List<Node> newList = new ArrayList<Node>();
96
        final List<Node> newList = new ArrayList<Node>();
97
        final List<Node> otherList = new ArrayList<Node>();
92
98
93
        MetadataModel metaDataModel = connection.getMetadataModel();
99
        MetadataModel metaDataModel = connection.getMetadataModel();
94
        boolean isConnected = !connection.getConnector().isDisconnected();
100
        boolean isConnected = !connection.getConnector().isDisconnected();
Lines 100-129 Link Here
100
                        public void run(Metadata metaData) {
106
                        public void run(Metadata metaData) {
101
                            Collection<Catalog> catalogs = metaData.getCatalogs();
107
                            Collection<Catalog> catalogs = metaData.getCatalogs();
102
108
103
                            String defaultCatalog = metaData.getDefaultCatalog().getName();
104
105
                            for (Catalog catalog : catalogs) {
109
                            for (Catalog catalog : catalogs) {
106
                                boolean oneCatalog = catalogs.size() == 1;
110
                                boolean oneCatalog = catalogs.size() == 1;
107
                                if (catalog.getName() != null || oneCatalog) {
111
                                if (catalog.getName() != null || oneCatalog) {
108
112
                                    if(isDefaultCatalog(catalog, connection)) {
109
                                    boolean use = true;
113
                                        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 {
114
                                        } else {
120
                                            NodeDataLookup lookup = new NodeDataLookup();
115
                                        updateNode(otherList, catalog);
121
                                            lookup.add(connection);
122
                                            lookup.add(catalogHandle);
123
                                            newList.add(CatalogNode.create(lookup, CatalogNodeProvider.this));
124
                                        }
116
                                        }
125
                                    }
117
                                    }
126
                                }
118
                                }
119
120
                            if (!otherList.isEmpty()) {
121
                                newList.add(new CatalogNodeProvider.OtherCatalogsNode (
122
                                        otherList));
127
                            }
123
                            }
128
124
129
                            if (newList.size() == 1) {
125
                            if (newList.size() == 1) {
Lines 143-153 Link Here
143
139
144
    }
140
    }
145
141
146
    static class CatalogComparator implements Comparator<Node> {
142
    private boolean isDefaultCatalog(Catalog catalog,
143
            DatabaseConnection connection) {
147
144
145
        String def = connection.getDefaultCatalog();
146
        return (def == null && catalog.isDefault())
147
                || (def != null && def.equals(catalog.getName())
148
                || connection.isImportantDatabase(catalog.getName()));
149
    }
150
    
151
    private void updateNode(List<Node> newList, Catalog catalog) {
152
        MetadataElementHandle<Catalog> catalogHandle = MetadataElementHandle.create(catalog);
153
        Collection<Node> matches = getNodes(catalogHandle);
154
        if (matches != null && matches.size() > 0) {
155
            newList.addAll(matches);
156
        } else {
157
            NodeDataLookup lookup = new NodeDataLookup();
158
            lookup.add(connection);
159
            lookup.add(catalogHandle);
160
161
            newList.add(CatalogNode.create(lookup, this));
162
        }
163
    }
164
165
    static class CatalogComparator implements Comparator<Node> {
166
        @Override
148
        public int compare(Node node1, Node node2) {
167
        public int compare(Node node1, Node node2) {
168
            if(node1 instanceof OtherCatalogsNode) {
169
                return 1;
170
            }
171
            if(node2 instanceof OtherCatalogsNode) {
172
                return -1;
173
            }
149
            return node1.getDisplayName().compareToIgnoreCase(node2.getDisplayName());
174
            return node1.getDisplayName().compareToIgnoreCase(node2.getDisplayName());
150
        }
175
        }
151
176
152
    }
177
    }
178
    
179
    @NbBundle.Messages({
180
        "LBL_OtherDatabases=Other databases"
181
    })
182
    private static class OtherCatalogsNode extends AbstractNode {
183
184
        private static final String ICON_BASE =
185
                "org/netbeans/modules/db/resources/database.gif";         //NOI18N
186
187
        public OtherCatalogsNode(List<Node> otherList) {
188
            super(createChildren(otherList));
189
            setDisplayName(Bundle.LBL_OtherDatabases());
190
            setIconBaseWithExtension(ICON_BASE);
153
}
191
}
192
193
        @Override
194
        public String getName() {
195
            return "zzzzzz";                                            //NOI18N
196
        }
197
198
        private static Children createChildren(final List<Node> otherList) {
199
            Children c = Children.create(new ChildFactory<Node>() {
200
                @Override
201
                protected boolean createKeys(final List<Node> toPopulate) {
202
                    toPopulate.addAll(otherList);
203
                    return true;
204
                }
205
206
                @Override
207
                protected Node createNodeForKey(Node key) {
208
                    return key;
209
                }
210
            }, false);
211
            return c;
212
        }
213
    }
214
}
(-)db/src/org/netbeans/modules/db/explorer/node/SchemaNode.java (+7 lines)
Lines 49-54 Link Here
49
import org.netbeans.api.db.explorer.node.NodeProvider;
49
import org.netbeans.api.db.explorer.node.NodeProvider;
50
import org.netbeans.modules.db.explorer.DatabaseConnection;
50
import org.netbeans.modules.db.explorer.DatabaseConnection;
51
import org.netbeans.modules.db.metadata.model.api.Action;
51
import org.netbeans.modules.db.metadata.model.api.Action;
52
import org.netbeans.modules.db.metadata.model.api.Catalog;
52
import org.netbeans.modules.db.metadata.model.api.Metadata;
53
import org.netbeans.modules.db.metadata.model.api.Metadata;
53
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle;
54
import org.netbeans.modules.db.metadata.model.api.MetadataElementHandle;
54
import org.netbeans.modules.db.metadata.model.api.MetadataModel;
55
import org.netbeans.modules.db.metadata.model.api.MetadataModel;
Lines 82-93 Link Here
82
83
83
    private final MetadataElementHandle<Schema> schemaHandle;
84
    private final MetadataElementHandle<Schema> schemaHandle;
84
    private final DatabaseConnection connection;
85
    private final DatabaseConnection connection;
86
    private final ToggleImportantInfo toggleImportantInfo = new ToggleImportantInfo(
87
            Schema.class
88
            );
85
89
86
    @SuppressWarnings("unchecked")
90
    @SuppressWarnings("unchecked")
87
    private SchemaNode(NodeDataLookup lookup, NodeProvider provider) {
91
    private SchemaNode(NodeDataLookup lookup, NodeProvider provider) {
88
        super(new ChildNodeFactory(lookup), lookup, FOLDER, provider);
92
        super(new ChildNodeFactory(lookup), lookup, FOLDER, provider);
89
        connection = getLookup().lookup(DatabaseConnection.class);
93
        connection = getLookup().lookup(DatabaseConnection.class);
90
        schemaHandle = getLookup().lookup(MetadataElementHandle.class);
94
        schemaHandle = getLookup().lookup(MetadataElementHandle.class);
95
        lookup.add(toggleImportantInfo);
91
    }
96
    }
92
97
93
    @Override
98
    @Override
Lines 116-121 Link Here
116
                    @Override
121
                    @Override
117
                        public void run(Metadata metaData) {
122
                        public void run(Metadata metaData) {
118
                            Schema schema = schemaHandle.resolve(metaData);
123
                            Schema schema = schemaHandle.resolve(metaData);
124
                            toggleImportantInfo.setDefault(schema.isDefault());
125
                            toggleImportantInfo.setImportant(connection.isImportantSchema(name));
119
                            renderNames(schema);
126
                            renderNames(schema);
120
                        }
127
                        }
121
                    }
128
                    }
(-)db/src/org/netbeans/modules/db/explorer/node/SchemaNodeProvider.java (-5 / +66 lines)
Lines 39-45 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
45
import java.util.ArrayList;
44
import java.util.ArrayList;
Lines 56-63 Link Here
56
import org.netbeans.modules.db.metadata.model.api.MetadataModel;
55
import org.netbeans.modules.db.metadata.model.api.MetadataModel;
57
import org.netbeans.modules.db.metadata.model.api.MetadataModelException;
56
import org.netbeans.modules.db.metadata.model.api.MetadataModelException;
58
import org.netbeans.modules.db.metadata.model.api.Schema;
57
import org.netbeans.modules.db.metadata.model.api.Schema;
58
import org.openide.nodes.AbstractNode;
59
import org.openide.nodes.ChildFactory;
60
import org.openide.nodes.Children;
59
import org.openide.nodes.Node;
61
import org.openide.nodes.Node;
60
import org.openide.util.Lookup;
62
import org.openide.util.Lookup;
63
import org.openide.util.NbBundle;
61
64
62
/**
65
/**
63
 *
66
 *
Lines 72-77 Link Here
72
    }
75
    }
73
76
74
    private static class FactoryHolder {
77
    private static class FactoryHolder {
78
75
        static final NodeProviderFactory FACTORY = new NodeProviderFactory() {
79
        static final NodeProviderFactory FACTORY = new NodeProviderFactory() {
76
            @Override
80
            @Override
77
            public SchemaNodeProvider createInstance(Lookup lookup) {
81
            public SchemaNodeProvider createInstance(Lookup lookup) {
Lines 80-86 Link Here
80
            }
84
            }
81
        };
85
        };
82
    }
86
    }
83
84
    private final DatabaseConnection connection;
87
    private final DatabaseConnection connection;
85
    private final MetadataElementHandle<Catalog> catalogHandle;
88
    private final MetadataElementHandle<Catalog> catalogHandle;
86
89
Lines 93-98 Link Here
93
    @Override
96
    @Override
94
    protected synchronized void initialize() {
97
    protected synchronized void initialize() {
95
        final List<Node> newList = new ArrayList<Node>();
98
        final List<Node> newList = new ArrayList<Node>();
99
        final List<Node> otherList = new ArrayList<Node>();
96
100
97
        boolean connected = !connection.getConnector().isDisconnected();
101
        boolean connected = !connection.getConnector().isDisconnected();
98
        MetadataModel metaDataModel = connection.getMetadataModel();
102
        MetadataModel metaDataModel = connection.getMetadataModel();
Lines 111-119 Link Here
111
                                } else {
115
                                } else {
112
                                    Collection<Schema> schemas = cat.getSchemas();
116
                                    Collection<Schema> schemas = cat.getSchemas();
113
                                    for (Schema schema : schemas) {
117
                                    for (Schema schema : schemas) {
118
                                    if (isDefaultSchema(schema, connection)) {
114
                                        updateNode(newList, schema);
119
                                        updateNode(newList, schema);
120
                                    } else {
121
                                        updateNode(otherList, schema);
115
                                    }
122
                                    }
116
                                }
123
                                }
124
                                if (!otherList.isEmpty()) {
125
                                    newList.add(new OtherSchemasNode(
126
                                            otherList));
127
                                }
128
                            }
117
129
118
                                if (syntheticSchema != null) {
130
                                if (syntheticSchema != null) {
119
                                    setProxyNodes(newList);
131
                                    setProxyNodes(newList);
Lines 122-129 Link Here
122
                                }
134
                                }
123
                            }
135
                            }
124
                        }
136
                        }
125
                    }
137
                });
126
                );
127
            } catch (MetadataModelException e) {
138
            } catch (MetadataModelException e) {
128
                NodeRegistry.handleMetadataModelException(this.getClass(), connection, e, true);
139
                NodeRegistry.handleMetadataModelException(this.getClass(), connection, e, true);
129
            }
140
            }
Lines 132-141 Link Here
132
        }
143
        }
133
    }
144
    }
134
145
146
    private boolean isDefaultSchema(Schema schema,
147
            DatabaseConnection connection) {
148
149
        String def = connection.getDefaultSchema();
150
        return (def == null && schema.isDefault())
151
                || (def != null && def.equals(schema.getName())
152
                || connection.isImportantSchema(schema.getName()));
153
    }
154
135
    private void updateNode(List<Node> newList, Schema schema) {
155
    private void updateNode(List<Node> newList, Schema schema) {
136
        MetadataElementHandle<Schema> schemaHandle = MetadataElementHandle.create(schema);
156
        MetadataElementHandle<Schema> schemaHandle = MetadataElementHandle.create(schema);
137
        Collection<Node> matches = getNodes(schemaHandle);
157
        Collection<Node> matches = getNodes(schemaHandle);
138
        if (matches.size() > 0) {
158
        if (matches != null && matches.size() > 0) {
139
            newList.addAll(matches);
159
            newList.addAll(matches);
140
        } else {
160
        } else {
141
            NodeDataLookup lookup = new NodeDataLookup();
161
            NodeDataLookup lookup = new NodeDataLookup();
Lines 152-159 Link Here
152
        public int compare(Node node1, Node node2) {
172
        public int compare(Node node1, Node node2) {
153
            assert node1.getDisplayName() != null : node1 + " has display name.";
173
            assert node1.getDisplayName() != null : node1 + " has display name.";
154
            assert node2.getDisplayName() != null : node2 + " has display name.";
174
            assert node2.getDisplayName() != null : node2 + " has display name.";
175
            if(node1 instanceof OtherSchemasNode) {
176
                return 1;
177
            }
178
            if(node2 instanceof OtherSchemasNode) {
179
                return -1;
180
            }
155
            return node1.getDisplayName().compareToIgnoreCase(node2.getDisplayName());
181
            return node1.getDisplayName().compareToIgnoreCase(node2.getDisplayName());
156
        }
182
        }
183
    }
157
184
185
    @NbBundle.Messages({
186
        "LBL_OtherSchemas=Other schemas"
187
    })
188
    private static class OtherSchemasNode extends AbstractNode {
189
190
        private static final String ICON_BASE =
191
                "org/netbeans/modules/db/resources/schema.png";         //NOI18N
192
193
        public OtherSchemasNode(List<Node> otherList) {
194
            super(createChildren(otherList));
195
            setDisplayName(Bundle.LBL_OtherSchemas());
196
            setIconBaseWithExtension(ICON_BASE);
158
    }
197
    }
198
199
        @Override
200
        public String getName() {
201
            return "zzzzzz";                                            //NOI18N
159
}
202
}
203
204
        private static Children createChildren(final List<Node> otherList) {
205
            Children c = Children.create(new ChildFactory<Node>() {
206
                @Override
207
                protected boolean createKeys(final List<Node> toPopulate) {
208
                    toPopulate.addAll(otherList);
209
                    return true;
210
                }
211
212
                @Override
213
                protected Node createNodeForKey(Node key) {
214
                    return key;
215
                }
216
            }, false);
217
            return c;
218
        }
219
    }
220
}
(-)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