Skip to content

Commit

Permalink
Merge pull request apache#6786 from thurka/GCN-3756
Browse files Browse the repository at this point in the history
"Copy OCID" action added
  • Loading branch information
thurka authored Dec 5, 2023
2 parents ca7b58b + 264f11a commit 3cc6d77
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 13 deletions.
24 changes: 16 additions & 8 deletions java/java.lsp.server/nbcode/integration/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@
<specification-version>9.24.0.8</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.project.dependency</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<implementation-version/>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.projectapi</code-name-base>
<build-prerequisite/>
Expand Down Expand Up @@ -191,35 +199,35 @@
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util</code-name-base>
<code-name-base>org.openide.nodes</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>9.18</specification-version>
<specification-version>7.68</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util.lookup</code-name-base>
<code-name-base>org.openide.util</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>8.44</specification-version>
<specification-version>9.18</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util.ui</code-name-base>
<code-name-base>org.openide.util.lookup</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>9.24</specification-version>
<specification-version>8.44</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.project.dependency</code-name-base>
<code-name-base>org.openide.util.ui</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<implementation-version/>
<specification-version>9.24</specification-version>
</run-dependency>
</dependency>
</module-dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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.nbcode.integration.commands;

import com.google.gson.JsonPrimitive;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.modules.cloud.oracle.items.OCIItem;
import org.netbeans.modules.java.lsp.server.explorer.TreeNodeRegistry;
import org.netbeans.modules.java.lsp.server.explorer.TreeViewProvider;
import org.netbeans.spi.lsp.CommandProvider;
import org.openide.nodes.Node;
import org.openide.util.Lookup;
import org.openide.util.lookup.ServiceProvider;

/**
*
* @author Tomas Hurka
*/
@ServiceProvider(service = CommandProvider.class)
public class OCIDCommand implements CommandProvider {

private static final Logger LOG = Logger.getLogger(OCIDCommand.class.getName());

private static final String COMMAND_CLOUD_OCID_GET = "nbls.cloud.ocid.get"; // NOI18N

public OCIDCommand() {
}

@Override
public Set<String> getCommands() {
return Collections.singleton(COMMAND_CLOUD_OCID_GET);
}

@Override
public CompletableFuture<Object> runCommand(String command, List<Object> arguments) {
if (arguments.size() < 1) {
throw new IllegalArgumentException("Expected nodeid"); // NOI18N
}
TreeNodeRegistry r = Lookup.getDefault().lookup(TreeNodeRegistry.class);
if (r == null) {
return CompletableFuture.completedFuture(null);
}
int nodeId = ((JsonPrimitive) arguments.get(0)).getAsInt();
LOG.log(Level.FINE, "Running OCID command with context: {0}", nodeId); // NOI18N

TreeViewProvider nodeProvider = r.providerOf(nodeId);
Node node = null;
if (nodeProvider != null) {
node = nodeProvider.findNode(nodeId);
}
if (node == null) {
return CompletableFuture.completedFuture(null);
}
OCIItem item = node.getLookup().lookup(OCIItem.class);
if (item != null) {
return CompletableFuture.completedFuture(item.getKey().getValue());
}
return CompletableFuture.completedFuture(null);
}
}
27 changes: 22 additions & 5 deletions java/java.lsp.server/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,10 @@
"command": "nbls.node.properties.edit",
"title": "Properties"
},
{
"command": "nbls.cloud.ocid.copy",
"title": "Copy OCID"
},
{
"command": "nbls.workspace.compile",
"title": "Compile Workspace",
Expand Down Expand Up @@ -681,6 +685,10 @@
"command": "nbls.node.properties.edit",
"when": "false"
},
{
"command": "nbls.cloud.ocid.copy",
"when": "false"
},
{
"command": "nbls:Database:netbeans.db.explorer.action.Connect",
"when": "false"
Expand Down Expand Up @@ -845,19 +853,28 @@
},
{
"command": "nbls:Tools:org.netbeans.modules.cloud.oracle.actions.DownloadWalletAction",
"when": "viewItem =~ /class:oracle.database.DatabaseItem/"
"when": "viewItem =~ /class:oracle.database.DatabaseItem/",
"group": "oci@200"
},
{
"command": "nbls:Tools:org.netbeans.modules.cloud.oracle.actions.OpenServiceConsoleAction",
"when": "viewItem =~ /class:oracle.database.DatabaseItem/"
"when": "viewItem =~ /class:oracle.database.DatabaseItem/",
"group": "oci@300"
},
{
"command": "nbls:Tools:org.netbeans.modules.cloud.oracle.actions.AddDbConnectionToVault",
"when": "viewItem =~ /class:org.netbeans.api.db.explorer.DatabaseConnection/"
"when": "viewItem =~ /class:org.netbeans.api.db.explorer.DatabaseConnection/",
"group": "oci@400"
},
{
"command": "nbls:Tools:org.netbeans.modules.cloud.oracle.actions.CreateAutonomousDBAction",
"when": "viewItem =~ /class:oracle.compartment.CompartmentItem/"
"when": "viewItem =~ /class:oracle.compartment.CompartmentItem/",
"group": "oci@100"
},
{
"command": "nbls.cloud.ocid.copy",
"when": "viewItem =~ /class:oracle.items.OCIItem/",
"group": "oci@1000"
},
{
"command": "nbls:Tools:org.netbeans.modules.cloud.oracle.actions.AddRepository",
Expand Down Expand Up @@ -965,7 +982,7 @@
"uriExpression": "nbres:/org/netbeans/modules/cloud/oracle/resources/vault.svg",
"codeicon": "lock"
},
{
{
"uriExpression": "nbres:/org/netbeans/modules/cloud/oracle/resources/key.svg",
"codeicon": "gist-secret"
},
Expand Down
7 changes: 7 additions & 0 deletions java/java.lsp.server/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,13 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
context.subscriptions.push(commands.registerCommand('nbls.node.properties.edit',
async (node) => await PropertiesView.createOrShow(context, node, (await client).findTreeViewService())));

context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.cloud.ocid.copy',
async (node) => {
const ocid : string = await commands.executeCommand(COMMAND_PREFIX + '.cloud.ocid.get', node.id);
vscode.env.clipboard.writeText(ocid);
}
));

const archiveFileProvider = <vscode.TextDocumentContentProvider> {
provideTextDocumentContent: async (uri: vscode.Uri, token: vscode.CancellationToken): Promise<string> => {
return await commands.executeCommand('nbls.get.archive.file.content', uri.toString());
Expand Down

0 comments on commit 3cc6d77

Please sign in to comment.