From 15d4044df6461f655bb3198939aa594c51a4a3ee Mon Sep 17 00:00:00 2001 From: Dusan Petrovic Date: Fri, 16 Aug 2024 09:30:10 +0200 Subject: [PATCH] Suggest OCI resource creation when showing existing resources --- .../oracle/assets/AddNewAssetCommand.java | 30 +++--- .../oracle/assets/AddSuggestedItemAction.java | 11 +-- .../oracle/assets/CreateNewResourceItem.java | 35 +++++++ .../steps/ItemCreationDecisionStep.java | 96 ------------------- .../cloud/oracle/steps/SuggestedStep.java | 8 +- java/java.lsp.server/vscode/package.json | 5 +- 6 files changed, 58 insertions(+), 127 deletions(-) create mode 100644 enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/CreateNewResourceItem.java delete mode 100644 enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/steps/ItemCreationDecisionStep.java diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/AddNewAssetCommand.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/AddNewAssetCommand.java index 2bf970fca9a3..107b880aeb30 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/AddNewAssetCommand.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/AddNewAssetCommand.java @@ -36,7 +36,6 @@ import org.netbeans.modules.cloud.oracle.steps.ItemTypeStep; import org.netbeans.modules.cloud.oracle.items.OCIItem; import org.netbeans.modules.cloud.oracle.steps.DatabaseConnectionStep; -import org.netbeans.modules.cloud.oracle.steps.ItemCreationDecisionStep; import org.netbeans.modules.cloud.oracle.steps.TenancyStep; import org.netbeans.spi.lsp.CommandProvider; import org.openide.util.lookup.Lookups; @@ -78,14 +77,8 @@ public CompletableFuture runCommand(String command, List argumen } return new TenancyStep(); }).stepForClass(TenancyStep.class, (s) -> new CompartmentStep()) - .stepForClass(CompartmentStep.class, (s) -> new ItemCreationDecisionStep()) - .stepForClass(ItemCreationDecisionStep.class, (s) -> { - if (ItemCreationDecisionStep.CREATE_NEW_OPTION.equals(s.getValue())) { - return null; - } - return new SuggestedStep(null); - }) - .stepForClass(SuggestedStep.class, (s) -> new ProjectStep()) + .stepForClass(CompartmentStep.class, (s) -> new SuggestedStep(null)) + .stepForClass(SuggestedStep.class, (s) -> new ProjectStep()) .build(); Steps.getDefault() @@ -101,15 +94,6 @@ public CompletableFuture runCommand(String command, List argumen } else { item = CompletableFuture.completedFuture(i); } - } else if (ItemCreationDecisionStep.CREATE_NEW_OPTION.equals(values.getValueForStep(ItemCreationDecisionStep.class))) { //NOI18N - OCIItemCreator creator = OCIItemCreator.getCreator(itemType); - if (creator != null) { - CompletableFuture> vals = creator.steps(); - item = vals.thenCompose(params -> { - return creator.create(values, params); - }); - } - } else { OCIItem i = values.getValueForStep(SuggestedStep.class); if (i == null) { @@ -120,6 +104,16 @@ public CompletableFuture runCommand(String command, List argumen } } + if (values.getValueForStep(SuggestedStep.class) instanceof CreateNewResourceItem) { + OCIItemCreator creator = OCIItemCreator.getCreator(itemType); + if (creator != null) { + CompletableFuture> vals = creator.steps(); + item = vals.thenCompose(params -> { + return creator.create(values, params); + }); + } + } + item.thenAccept(i -> { CloudAssets.getDefault().addItem(i); String[] art = DEP_MAP.get(i.getKey().getPath()); diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/AddSuggestedItemAction.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/AddSuggestedItemAction.java index 35f4072c8f21..f8c092382d4e 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/AddSuggestedItemAction.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/AddSuggestedItemAction.java @@ -31,7 +31,6 @@ import org.netbeans.modules.cloud.oracle.steps.TenancyStep; import org.netbeans.modules.cloud.oracle.database.DatabaseItem; import org.netbeans.modules.cloud.oracle.items.OCIItem; -import org.netbeans.modules.cloud.oracle.steps.ItemCreationDecisionStep; import org.openide.awt.ActionID; import org.openide.awt.ActionRegistration; import org.openide.util.Lookup; @@ -85,18 +84,12 @@ public void actionPerformed(ActionEvent e) { } Steps.NextStepProvider nsProvider = Steps.NextStepProvider.builder() .stepForClass(TenancyStep.class, (s) -> new CompartmentStep()) - .stepForClass(CompartmentStep.class, (s) -> new ItemCreationDecisionStep(context.getPath())) - .stepForClass(ItemCreationDecisionStep.class, (s) -> { - if (ItemCreationDecisionStep.CREATE_NEW_OPTION.equals(s.getValue())) { - return null; - } - return new SuggestedStep(context.getPath()); - }) + .stepForClass(CompartmentStep.class, (s) -> new SuggestedStep(context.getPath())) .build(); Lookup lookup = Lookups.fixed(nsProvider); Steps.getDefault().executeMultistep(new TenancyStep(), lookup) .thenAccept(values -> { - if (ItemCreationDecisionStep.CREATE_NEW_OPTION.equals(values.getValueForStep(ItemCreationDecisionStep.class))) { //NOI18N + if (values.getValueForStep(SuggestedStep.class) instanceof CreateNewResourceItem) { OCIItemCreator creator = OCIItemCreator.getCreator(context.getPath()); if (creator != null) { CompletableFuture> vals = creator.steps(); diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/CreateNewResourceItem.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/CreateNewResourceItem.java new file mode 100644 index 000000000000..8e2e5e352e77 --- /dev/null +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/CreateNewResourceItem.java @@ -0,0 +1,35 @@ +/* + * 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.cloud.oracle.assets; + +import org.netbeans.modules.cloud.oracle.items.OCIItem; + +/** + * + * @author Dusan Petrovic + */ +public class CreateNewResourceItem extends OCIItem { + + private static final String DISPLAY_NAME = ""; + + public CreateNewResourceItem() { + super(null, null, DISPLAY_NAME); + } + +} diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/steps/ItemCreationDecisionStep.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/steps/ItemCreationDecisionStep.java deleted file mode 100644 index 9ccc43cc1c12..000000000000 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/steps/ItemCreationDecisionStep.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.cloud.oracle.steps; - -import java.util.ArrayList; -import java.util.List; -import org.netbeans.api.progress.ProgressHandle; -import org.netbeans.modules.cloud.oracle.assets.AbstractStep; -import org.netbeans.modules.cloud.oracle.assets.Steps; -import org.openide.NotifyDescriptor; -import org.openide.util.NbBundle; - -/** - * - * @author Dusan Petrovic - */ -@NbBundle.Messages({ - "ItemCreationDecission=Choose whether to create new or to add existing resource", -}) -public class ItemCreationDecisionStep extends AbstractStep { - - public static final String CREATE_NEW_OPTION = "Create new"; - private static final String ADD_EXISTING_OPTION = "Add existing"; - - private List showedOptions; - private String selected; - private String itemType; - - public ItemCreationDecisionStep() { - } - - public ItemCreationDecisionStep(String itemType) { - this.itemType = itemType; - } - - @Override - public void prepare(ProgressHandle h, Steps.Values values) { - showedOptions = new ArrayList<>(); - showedOptions.add(new NotifyDescriptor.QuickPick.Item(ADD_EXISTING_OPTION, "")); - if (itemType == null) { - itemType = values.getValueForStep(ItemTypeStep.class); - } - - if (creationEnabled(itemType)) { - showedOptions.add(new NotifyDescriptor.QuickPick.Item(CREATE_NEW_OPTION, "")); - } - } - - public String getItemType() { - return itemType; - } - - private static boolean creationEnabled(String itemType) { - return "ContainerRepository".equals(itemType); - } - - @Override - public NotifyDescriptor createInput() { - return new NotifyDescriptor.QuickPick(Bundle.ItemCreationDecission(), Bundle.ItemCreationDecission(), showedOptions, false); - } - - @Override - public boolean onlyOneChoice() { - return showedOptions.size() == 1; - } - - @Override - public void setValue(String selected) { - if (!CREATE_NEW_OPTION.equals(selected) && !ADD_EXISTING_OPTION.equals(selected)) - throw new IllegalArgumentException("Invalid argument: " + selected); - - this.selected = selected; - } - - @Override - public String getValue() { - return selected; - } - -} diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/steps/SuggestedStep.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/steps/SuggestedStep.java index 52a673cdacdf..082b0823c658 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/steps/SuggestedStep.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/steps/SuggestedStep.java @@ -19,6 +19,7 @@ package org.netbeans.modules.cloud.oracle.steps; import com.oracle.bmc.model.BmcException; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -28,6 +29,7 @@ import java.util.logging.Logger; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.modules.cloud.oracle.assets.AbstractStep; +import org.netbeans.modules.cloud.oracle.assets.CreateNewResourceItem; import org.netbeans.modules.cloud.oracle.assets.Steps; import org.netbeans.modules.cloud.oracle.assets.Steps.Values; import org.netbeans.modules.cloud.oracle.bucket.BucketNode; @@ -124,7 +126,7 @@ public boolean onlyOneChoice() { * @return List of items found */ protected static List getItemsByPath(CompartmentItem parent, String path) { - Map items = new HashMap<>(); + List items = new ArrayList<>(); try { switch (path) { case "Databases": //NOI18N @@ -138,7 +140,9 @@ protected static List getItemsByPath(CompartmentItem parent, case "ComputeInstance": //NOI18N return ComputeInstanceNode.getComputeInstances().apply(parent); case "ContainerRepository": //NOI18N - return ContainerRepositoryNode.getContainerRepositories().apply(parent); + items.add(new CreateNewResourceItem()); + items.addAll(ContainerRepositoryNode.getContainerRepositories().apply(parent)); + return items; default: return Collections.emptyList(); } diff --git a/java/java.lsp.server/vscode/package.json b/java/java.lsp.server/vscode/package.json index c77980d69112..159af73515d5 100644 --- a/java/java.lsp.server/vscode/package.json +++ b/java/java.lsp.server/vscode/package.json @@ -647,7 +647,8 @@ }, { "command": "nbls:Edit:org.openide.actions.DeleteAction", - "title": "Delete" + "title": "Delete", + "icon": "$(trash)" }, { "command": "nbls.project.run", @@ -1128,7 +1129,7 @@ }, { "command": "nbls:Edit:org.openide.actions.DeleteAction", - "when": "viewItem =~ /lifecycleState:ACTIVE*/ || (viewItem =~ /publicIp:.*/ && viewItem =~ /imageUrl:.*/)", + "when": "viewItem =~ /lifecycleState:ACTIVE*/ || viewItem =~ /ContainerTagItem/", "group": "inline@10" } ]