This is an automated email from the ASF dual-hosted git repository.
sdedic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 5934827e80 LSP: Database connection context menu cleanup (#5586)
5934827e80 is described below
commit 5934827e80797ec9b93ff28635ce7fca12627a70
Author: Tomas Hurka <[email protected]>
AuthorDate: Mon Mar 6 13:52:24 2023 +0100
LSP: Database connection context menu cleanup (#5586)
* LSP: Database connection context menu cleanup - actions renamed and
reordered, display only appropriate connect/disconnect action
* logging removed
---
.../java/lsp/server/db/DBDecorationProvider.java | 75 ++++++++++++++++++++++
java/java.lsp.server/vscode/package.json | 19 ++++--
2 files changed, 87 insertions(+), 7 deletions(-)
diff --git
a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/db/DBDecorationProvider.java
b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/db/DBDecorationProvider.java
new file mode 100644
index 0000000000..e057526173
--- /dev/null
+++
b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/db/DBDecorationProvider.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.lsp.server.db;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.netbeans.api.db.explorer.DatabaseConnection;
+import org.netbeans.modules.java.lsp.server.explorer.api.TreeDataListener;
+import org.netbeans.modules.java.lsp.server.explorer.api.TreeDataProvider;
+import org.netbeans.modules.java.lsp.server.explorer.api.TreeItemData;
+import org.openide.nodes.Node;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Provides decorations (connection status) for the Database node.
+ *
+ * @author Tomas Hurka
+ */
+@ServiceProvider(service = TreeDataProvider.Factory.class, path =
"Explorers/database.connections")
+public class DBDecorationProvider implements TreeDataProvider.Factory {
+
+ private static final String CONNECTED = "is:connected"; //
NOI18N
+ private static final String DISCONNECTED = "is:disconnected"; //
NOI18N
+ private static final Logger LOG =
Logger.getLogger(DBDecorationProvider.class.getName());
+
+ @Override
+ public TreeDataProvider createProvider(String treeId) {
+ LOG.log(Level.FINE, "Creating default DBDecorationProvider for {0}",
treeId); // NOI18N
+ return new DBDataProvider();
+ }
+
+ private static class DBDataProvider implements TreeDataProvider {
+
+ @Override
+ public TreeItemData createDecorations(Node n, boolean expanded) {
+ DatabaseConnection conn =
n.getLookup().lookup(DatabaseConnection.class);
+
+ if (conn != null) {
+ String status = conn.getJDBCConnection() != null ? CONNECTED :
DISCONNECTED;
+ TreeItemData data = new TreeItemData();
+ data.setContextValues(status);
+ return data;
+ }
+ return null;
+ }
+
+ @Override
+ public void addTreeItemDataListener(TreeDataListener l) {
+ }
+
+ @Override
+ public void removeTreeItemDataListener(TreeDataListener l) {
+ }
+
+ @Override
+ public void nodeReleased(Node n) {
+ }
+ }
+}
diff --git a/java/java.lsp.server/vscode/package.json
b/java/java.lsp.server/vscode/package.json
index 59eaea0505..5635055415 100644
--- a/java/java.lsp.server/vscode/package.json
+++ b/java/java.lsp.server/vscode/package.json
@@ -498,7 +498,7 @@
},
{
"command":
"nbls:Database:netbeans.db.explorer.action.Disconnect",
- "title": "Disconnect"
+ "title": "Disconnect from Database"
},
{
"command":
"nbls:Database:netbeans.db.explorer.action.Refresh",
@@ -568,7 +568,7 @@
},
{
"command":
"java.local.db.set.preferred.connection",
- "title": "Make Default Connection"
+ "title": "Set as Default Connection"
},
{
"command":
"java.workspace.configureRunSettings",
@@ -758,19 +758,23 @@
},
{
"command":
"nbls:Database:netbeans.db.explorer.action.Connect",
- "when": "viewItem =~
/class:org.netbeans.api.db.explorer.DatabaseConnection/"
+ "when": "viewItem =~
/class:org.netbeans.api.db.explorer.DatabaseConnection/ && viewItem =~
/is:disconnected/",
+ "group": "db@10"
},
{
"command":
"nbls:Database:netbeans.db.explorer.action.Disconnect",
- "when": "viewItem =~
/class:org.netbeans.api.db.explorer.DatabaseConnection/"
+ "when": "viewItem =~
/class:org.netbeans.api.db.explorer.DatabaseConnection/ && viewItem =~
/is:connected/",
+ "group": "db@20"
},
{
"command":
"nbls:Database:netbeans.db.explorer.action.Refresh",
- "when": "viewItem =~
/class:ddl.DBConnection/"
+ "when": "viewItem =~
/class:org.netbeans.api.db.explorer.DatabaseConnection/",
+ "group": "db@30"
},
{
"command":
"nbls:Edit:org.openide.actions.DeleteAction",
- "when": "viewItem =~ /cap:delete/"
+ "when": "viewItem =~ /cap:delete/",
+ "group": "db@50"
},
{
"command": "java.workspace.new",
@@ -804,7 +808,8 @@
},
{
"command":
"java.local.db.set.preferred.connection",
- "when": "viewItem =~
/class:org.netbeans.api.db.explorer.DatabaseConnection/"
+ "when": "viewItem =~
/class:org.netbeans.api.db.explorer.DatabaseConnection/",
+ "group": "db@40"
},
{
"command":
"nbls:Tools:org.netbeans.modules.cloud.oracle.actions.DownloadWalletAction",
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists