You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "sdedic (via GitHub)" <gi...@apache.org> on 2023/01/25 07:50:23 UTC

[GitHub] [netbeans] sdedic commented on a diff in pull request #5353: Use NotifyDescriptor.ComposedInput for Add ADB command

sdedic commented on code in PR #5353:
URL: https://github.com/apache/netbeans/pull/5353#discussion_r1086301644


##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/AddADBAction.java:
##########
@@ -65,80 +73,104 @@
     "AddADB=Add Oracle Autonomous DB",
     "SelectTenancy=Select Tenancy",
     "SelectCompartment=Select Compartment",
-    "SelectDatabase=Select Database"
+    "SelectDatabase=Select Compartment or Database",
+    "EnterUsername=Enter Username",
+    "EnterPassword=Enter Password"
 })
 public class AddADBAction implements ActionListener {
     private static final Logger LOGGER = Logger.getLogger(AddADBAction.class.getName());
     
+    private static final String DB = "db";
+    private static final String USERNAME = "username";
+    private static final String PASSWORD = "password";
 
     @Override
     public void actionPerformed(ActionEvent e) {
-        List<TenancyItem> tenancies = new ArrayList<>();
-        for (OCIProfile p : OCIManager.getDefault().getConnectedProfiles()) {
-           p.getTenancy().ifPresent(tenancies::add);
-        }
-        Optional<TenancyItem> selectedTenancy = chooseOneItem(tenancies, Bundle.SelectTenancy());
-        
-        Optional<CompartmentItem> selectedCompartment = Optional.empty();
-                
-        if (!selectedTenancy.isPresent()) {
-            return;
-        }
-        
-        List<CompartmentItem> compartments = CompartmentNode.getCompartments().apply(selectedTenancy.get());
-        selectedCompartment = chooseOneItem(compartments, Bundle.SelectCompartment());
-        DatabaseItem selectedDatabase = null;
+        Map<String, Object> result = new HashMap<> ();
         
-        if (selectedCompartment.isPresent()) {
-            while(selectedDatabase == null) {
-                OCIItem item = chooseCopartmentOrDb(selectedCompartment.get());
-                if (item == null) {
-                    return;
-                }
-                if (item instanceof DatabaseItem) {
-                    selectedDatabase = (DatabaseItem) item;
-                }
-                if (item instanceof CompartmentItem) {
-                    selectedCompartment = Optional.of((CompartmentItem) item);
+        NotifyDescriptor.ComposedInput ci = new NotifyDescriptor.ComposedInput(Bundle.AddADB(), 2, new Callback() {

Review Comment:
   There are at least 3 steps: database, username, password. In addition, each compartment selection should change the number of estimated steps.



##########
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/AddADBAction.java:
##########
@@ -65,80 +73,104 @@
     "AddADB=Add Oracle Autonomous DB",
     "SelectTenancy=Select Tenancy",
     "SelectCompartment=Select Compartment",
-    "SelectDatabase=Select Database"
+    "SelectDatabase=Select Compartment or Database",
+    "EnterUsername=Enter Username",
+    "EnterPassword=Enter Password"
 })
 public class AddADBAction implements ActionListener {
     private static final Logger LOGGER = Logger.getLogger(AddADBAction.class.getName());
     
+    private static final String DB = "db";
+    private static final String USERNAME = "username";
+    private static final String PASSWORD = "password";
 
     @Override
     public void actionPerformed(ActionEvent e) {
-        List<TenancyItem> tenancies = new ArrayList<>();
-        for (OCIProfile p : OCIManager.getDefault().getConnectedProfiles()) {
-           p.getTenancy().ifPresent(tenancies::add);
-        }
-        Optional<TenancyItem> selectedTenancy = chooseOneItem(tenancies, Bundle.SelectTenancy());
-        
-        Optional<CompartmentItem> selectedCompartment = Optional.empty();
-                
-        if (!selectedTenancy.isPresent()) {
-            return;
-        }
-        
-        List<CompartmentItem> compartments = CompartmentNode.getCompartments().apply(selectedTenancy.get());
-        selectedCompartment = chooseOneItem(compartments, Bundle.SelectCompartment());
-        DatabaseItem selectedDatabase = null;
+        Map<String, Object> result = new HashMap<> ();
         
-        if (selectedCompartment.isPresent()) {
-            while(selectedDatabase == null) {
-                OCIItem item = chooseCopartmentOrDb(selectedCompartment.get());
-                if (item == null) {
-                    return;
-                }
-                if (item instanceof DatabaseItem) {
-                    selectedDatabase = (DatabaseItem) item;
-                }
-                if (item instanceof CompartmentItem) {
-                    selectedCompartment = Optional.of((CompartmentItem) item);
+        NotifyDescriptor.ComposedInput ci = new NotifyDescriptor.ComposedInput(Bundle.AddADB(), 2, new Callback() {
+            Map<Integer, List> values = new HashMap<> ();
+            
+            @Override
+            public NotifyDescriptor createInput(NotifyDescriptor.ComposedInput input, int number) {
+                if (number == 1) {
+                    List<TenancyItem> tenancies = new ArrayList<>();
+                    for (OCIProfile p : OCIManager.getDefault().getConnectedProfiles()) {
+                        p.getTenancy().ifPresent(tenancies::add);
+                    }
+                    String title;
+                    if (tenancies.size() == 1) {
+                        values.put(1, getCompartmentsAndDbs(tenancies.get(0)));
+                        title = Bundle.SelectCompartment();
+                    } else {
+                        values.put(1, tenancies);
+                        title = Bundle.SelectTenancy();
+                    }
+                    return createQuickPick(values.get(1), title);
+                } else {
+                    NotifyDescriptor prev = input.getInputs()[number - 2];
+                    OCIItem prevItem = null;
+                    if (prev instanceof NotifyDescriptor.QuickPick) {
+                        Optional<String> selected = ((QuickPick) prev).getItems().stream().filter(item -> item.isSelected()).map(item -> item.getLabel()).findFirst();
+                        if (selected.isPresent()) {
+                            Optional<? extends OCIItem> ti = values.get(number -1).stream().filter(t -> ((OCIItem) t).getName().equals(selected.get())).findFirst();
+                            if (ti.isPresent()) {
+                                prevItem = ti.get();
+                            }
+                        }
+                        if (prevItem instanceof DatabaseItem) {
+                            result.put(DB, prevItem);
+                            return new NotifyDescriptor.InputLine(Bundle.EnterUsername(), Bundle.EnterUsername());
+                        }
+                        values.put(number, getCompartmentsAndDbs(prevItem));
+                        return createQuickPick(values.get(number), Bundle.SelectDatabase());
+                    } else if (prev instanceof NotifyDescriptor.PasswordLine) {
+                        result.put(PASSWORD, ((NotifyDescriptor.PasswordLine) prev).getInputText());
+                        return null;
+                    } else if (prev instanceof NotifyDescriptor.InputLine) {
+                        result.put(USERNAME, ((NotifyDescriptor.InputLine) prev).getInputText());

Review Comment:
   note that the received input may be empty. Is it valid, or should we repeat the step - or cancel the action ?



-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists