sdedic commented on code in PR #7161:
URL: https://github.com/apache/netbeans/pull/7161#discussion_r1526229696
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/OCIProfile.java:
##########
@@ -136,6 +154,17 @@ public String getId() {
public boolean isValid() {
return configProvider != null && fileStamp ==
configPath.toFile().lastModified(); // avoid IOE
}
+
+ public void setRegionCode(String regionCode) {
+ setRegion(Region.valueOf(regionCode));
+ }
+
+ public void setRegion(Region region) {
Review Comment:
Would it be possible to use `null` to reset to the provider-defaul region ?
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/OCIProfile.java:
##########
@@ -136,6 +154,17 @@ public String getId() {
public boolean isValid() {
return configProvider != null && fileStamp ==
configPath.toFile().lastModified(); // avoid IOE
}
+
+ public void setRegionCode(String regionCode) {
+ setRegion(Region.valueOf(regionCode));
+ }
+
+ public void setRegion(Region region) {
+ Preferences prefs = NbPreferences.forModule(OCIProfile.class);
+ prefs.put(PROP_ACTIVE_REGION_CODE + "/" + id, region.getRegionCode());
+ listeners.firePropertyChange(PROP_ACTIVE_REGION_CODE, this.region,
region);
Review Comment:
Question: each OCIItem has `ChangeListener` support already; it may be too
coarse-grained (if many state changes trigger it), is it why it was not used
here ?
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionAction.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.actions;
+
+import com.oracle.bmc.identity.Identity;
+import com.oracle.bmc.identity.IdentityClient;
+import com.oracle.bmc.identity.requests.ListRegionsRequest;
+import com.oracle.bmc.identity.responses.ListRegionsResponse;
+import java.awt.Dialog;
+import java.awt.GraphicsEnvironment;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.netbeans.modules.cloud.oracle.OCIManager;
+import org.netbeans.modules.cloud.oracle.OCIProfile;
+import org.netbeans.modules.cloud.oracle.OCISessionInitiator;
+import org.openide.DialogDescriptor;
+import org.openide.DialogDisplayer;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+import org.openide.awt.ActionRegistration;
+import org.openide.util.NbBundle;
+
+/**
+ * This action lets user select an Oracle Cloud region. This region will be
used for all subsequent requests.
+ *
+ * @author Jan Horvath
+ */
+@ActionID(
+ category = "Tools",
+ id = "org.netbeans.modules.cloud.oracle.actions.SetDefaultRegionAction"
+)
+@ActionRegistration(
+ displayName = "#SetDefaultRegion",
+ asynchronous = true
+)
+@ActionReferences(value = {
+ @ActionReference(path = "Cloud/Oracle/Tenancy/Actions", position = 250)
+})
[email protected]({
+ "SetDefaultRegion=Set OCI Region",
+ "SelectRegion=Select a Region"
+})
+public class SetRegionAction implements ActionListener {
+
+ private final OCIProfile context;
+
+ public SetRegionAction(OCIProfile context) {
+ this.context = context;
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ OCISessionInitiator session =
OCIManager.getDefault().getActiveSession();
Review Comment:
Maybe I'd suggest to dig up `OCIProfile` from the active node; there can be
multiple sessions for different profiles, I think. Look at
`CreateAutonomousDBAction` for example.
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionCommand.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.actions;
+
+import com.oracle.bmc.identity.Identity;
+import com.oracle.bmc.identity.IdentityClient;
+import com.oracle.bmc.identity.model.Region;
+import com.oracle.bmc.identity.requests.ListRegionsRequest;
+import com.oracle.bmc.identity.responses.ListRegionsResponse;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+import org.netbeans.modules.cloud.oracle.OCIManager;
+import org.netbeans.modules.cloud.oracle.OCIProfile;
+import org.netbeans.spi.lsp.CommandProvider;
+import org.openide.DialogDisplayer;
+import org.openide.NotifyDescriptor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * This command lets user select an Oracle Cloud region. This region will be
used for all subsequent requests.
+ *
+ * @author Jan Horvath
+ */
+@ServiceProvider(service = CommandProvider.class)
+public class SetRegionCommand implements CommandProvider {
+
+ private static final String SET_REGION_COMMAND = "nbls.oci.setRegion";
//NOI18N
+ private static final String GET_REGION_COMMAND = "nbls.oci.getRegion";
//NOI18N
+
+ private static Set<String> commands = new HashSet<String>(){{
+ add(SET_REGION_COMMAND);
+ add(GET_REGION_COMMAND);
+ }};
+
+ @Override
+ public Set<String> getCommands() {
+ return commands;
+ }
+
+ @Override
+ public CompletableFuture<Object> runCommand(String command, List<Object>
arguments) {
+ CompletableFuture result = new CompletableFuture();
+ if (GET_REGION_COMMAND.equals(command)) {
+
result.complete(OCIManager.getDefault().getActiveSession().getRegion().getRegionCode());
+ return result;
+ }
+ if (SET_REGION_COMMAND.equals(command)) {
+ OCIProfile session = (OCIProfile)
OCIManager.getDefault().getActiveSession();
+ Identity identityClient = session.newClient(IdentityClient.class);
+ ListRegionsRequest request = ListRegionsRequest.builder().build();
+
+ ListRegionsResponse response
Review Comment:
Looks like this call could block -- if so, pls. run in RequestProcessor
complete the Future from within the offloaded task.
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionAction.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.actions;
+
+import com.oracle.bmc.identity.Identity;
+import com.oracle.bmc.identity.IdentityClient;
+import com.oracle.bmc.identity.requests.ListRegionsRequest;
+import com.oracle.bmc.identity.responses.ListRegionsResponse;
+import java.awt.Dialog;
+import java.awt.GraphicsEnvironment;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.netbeans.modules.cloud.oracle.OCIManager;
+import org.netbeans.modules.cloud.oracle.OCIProfile;
+import org.netbeans.modules.cloud.oracle.OCISessionInitiator;
+import org.openide.DialogDescriptor;
+import org.openide.DialogDisplayer;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+import org.openide.awt.ActionRegistration;
+import org.openide.util.NbBundle;
+
+/**
+ * This action lets user select an Oracle Cloud region. This region will be
used for all subsequent requests.
+ *
+ * @author Jan Horvath
+ */
+@ActionID(
+ category = "Tools",
+ id = "org.netbeans.modules.cloud.oracle.actions.SetDefaultRegionAction"
+)
+@ActionRegistration(
+ displayName = "#SetDefaultRegion",
+ asynchronous = true
+)
+@ActionReferences(value = {
+ @ActionReference(path = "Cloud/Oracle/Tenancy/Actions", position = 250)
+})
[email protected]({
+ "SetDefaultRegion=Set OCI Region",
+ "SelectRegion=Select a Region"
+})
+public class SetRegionAction implements ActionListener {
+
+ private final OCIProfile context;
+
+ public SetRegionAction(OCIProfile context) {
+ this.context = context;
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ OCISessionInitiator session =
OCIManager.getDefault().getActiveSession();
+ Identity identityClient =
IdentityClient.builder().build(session.getAuthenticationProvider());
+ ListRegionsRequest request = ListRegionsRequest.builder().build();
+
+ ListRegionsResponse response = identityClient.listRegions(request);
+
+ List<String> items = response.getItems().stream()
+ .map(region -> region.getName())
+ .sorted((r1, r2) -> r1.compareTo(r2))
+ .collect(Collectors.toList());
+
+ if (!GraphicsEnvironment.isHeadless()) {
Review Comment:
Question: could we eventually use `NotifyDescriptor.QuickPick` for a
headless environment (LSP client) ? Not sure about the use-case validity.
##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/SetRegionCommand.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.actions;
+
+import com.oracle.bmc.identity.Identity;
+import com.oracle.bmc.identity.IdentityClient;
+import com.oracle.bmc.identity.model.Region;
+import com.oracle.bmc.identity.requests.ListRegionsRequest;
+import com.oracle.bmc.identity.responses.ListRegionsResponse;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+import org.netbeans.modules.cloud.oracle.OCIManager;
+import org.netbeans.modules.cloud.oracle.OCIProfile;
+import org.netbeans.spi.lsp.CommandProvider;
+import org.openide.DialogDisplayer;
+import org.openide.NotifyDescriptor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * This command lets user select an Oracle Cloud region. This region will be
used for all subsequent requests.
+ *
+ * @author Jan Horvath
+ */
+@ServiceProvider(service = CommandProvider.class)
+public class SetRegionCommand implements CommandProvider {
+
+ private static final String SET_REGION_COMMAND = "nbls.oci.setRegion";
//NOI18N
+ private static final String GET_REGION_COMMAND = "nbls.oci.getRegion";
//NOI18N
+
+ private static Set<String> commands = new HashSet<String>(){{
+ add(SET_REGION_COMMAND);
+ add(GET_REGION_COMMAND);
+ }};
+
+ @Override
+ public Set<String> getCommands() {
+ return commands;
+ }
+
+ @Override
+ public CompletableFuture<Object> runCommand(String command, List<Object>
arguments) {
+ CompletableFuture result = new CompletableFuture();
+ if (GET_REGION_COMMAND.equals(command)) {
+
result.complete(OCIManager.getDefault().getActiveSession().getRegion().getRegionCode());
+ return result;
+ }
+ if (SET_REGION_COMMAND.equals(command)) {
+ OCIProfile session = (OCIProfile)
OCIManager.getDefault().getActiveSession();
Review Comment:
Would it be possible to pass (optional) profile ID to the command to enable
to work with non-default profiles ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
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