This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit c02de25be9db6ca43a4cab65b1414049d79782bd
Author: Sandip Chitale <sandipchit...@gmail.com>
AuthorDate: Mon Jun 20 18:12:52 2022 -0700

    GROOVY-10661: Show path to current level object and support ALT-double click
---
 .../groovy/groovy/console/ui/ObjectBrowser.groovy  | 50 +++++++++++++++++-----
 1 file changed, 39 insertions(+), 11 deletions(-)

diff --git 
a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ObjectBrowser.groovy
 
b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ObjectBrowser.groovy
index 198ac3eb35..fcd4fda663 100644
--- 
a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ObjectBrowser.groovy
+++ 
b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ObjectBrowser.groovy
@@ -27,6 +27,8 @@ import java.awt.FlowLayout
 import java.awt.event.MouseAdapter
 import java.awt.event.MouseEvent
 
+import static javax.swing.ListSelectionModel.SINGLE_SELECTION
+
 import static groovy.inspect.Inspector.MEMBER_DECLARER_IDX
 import static groovy.inspect.Inspector.MEMBER_EXCEPTIONS_IDX
 import static groovy.inspect.Inspector.MEMBER_MODIFIER_IDX
@@ -48,15 +50,23 @@ import static groovy.inspect.Inspector.MEMBER_RAW_VALUE_IDX
 class ObjectBrowser {
 
     def inspector
+    def path
     def swing, frame, fieldTable, methodTable, arrayTable, collectionTable, 
mapTable
 
     static void main(args) {
         inspect('some String')
     }
 
-    static void inspect(objectUnderInspection) {
-        def browser = new ObjectBrowser()
+    public ObjectBrowser(String path = '') {
+        this.path = (path == null ? '' : path)
+    }
+
+    static void inspect(objectUnderInspection, String path = '') {
+        def browser = new ObjectBrowser(path)
         browser.inspector = new Inspector(objectUnderInspection)
+        if (objectUnderInspection != null && browser.path == '') {
+            browser.path = "${objectUnderInspection.getClass().name} instance"
+        }
         browser.run()
     }
 
@@ -86,7 +96,7 @@ class ObjectBrowser {
                 tabbedPane(constraints: CENTER) {
                     if (inspector.object?.class?.array) {
                         scrollPane(name: ' Array data ') {
-                            arrayTable = table {
+                            arrayTable = table(selectionMode: 
SINGLE_SELECTION) {
                                 tableModel(list: 
inspector.object.toList().withIndex()) {
                                     closureColumn(header: 'Index', read: { 
it[1] })
                                     closureColumn(header: 'Value', read: { 
it[0] })
@@ -105,7 +115,8 @@ class ObjectBrowser {
                                         if (selectedRow != -1) {
                                             def value = 
arrayTable.model.getValueAt(selectedRow, 2)
                                             if (value != null) {
-                                                ObjectBrowser.inspect(value)
+                                                closeFrameIfAltDoubleClick(e)
+                                                ObjectBrowser.inspect(value, 
path + "[${arrayTable.model.getValueAt(selectedRow, 0)}]")
                                             }
                                         }
                                     }
@@ -114,7 +125,7 @@ class ObjectBrowser {
                         }
                     } else if (inspector.object instanceof Collection) {
                         scrollPane(name: ' Collection data ') {
-                            collectionTable = table {
+                            collectionTable = table(selectionMode: 
SINGLE_SELECTION) {
                                 tableModel(list: inspector.object.withIndex()) 
{
                                     closureColumn(header: 'Index', read: { 
it[1] })
                                     closureColumn(header: 'Value', read: { 
it[0] })
@@ -133,7 +144,8 @@ class ObjectBrowser {
                                         if (selectedRow != -1) {
                                             def value = 
collectionTable.model.getValueAt(selectedRow, 2)
                                             if (value != null) {
-                                                ObjectBrowser.inspect(value)
+                                                closeFrameIfAltDoubleClick(e)
+                                                ObjectBrowser.inspect(value, 
path + "[${collectionTable.model.getValueAt(selectedRow, 0)}]")
                                             }
                                         }
                                     }
@@ -142,7 +154,7 @@ class ObjectBrowser {
                         }
                     } else if (inspector.object instanceof Map) {
                         scrollPane(name: ' Map data ') {
-                            mapTable = table {
+                            mapTable = table(selectionMode: SINGLE_SELECTION) {
                                 tableModel(list: 
inspector.object.entrySet().withIndex()) {
                                     closureColumn(header: 'Index', read: { 
it[1] })
                                     closureColumn(header: 'Key', read: { 
it[0].key })
@@ -162,7 +174,8 @@ class ObjectBrowser {
                                         if (selectedRow != -1) {
                                             def value = 
mapTable.model.getValueAt(selectedRow, 2)
                                             if (value != null) {
-                                                ObjectBrowser.inspect(value)
+                                                closeFrameIfAltDoubleClick(e)
+                                                ObjectBrowser.inspect(value, 
path + "[${mapTable.model.getValueAt(selectedRow, 1)}]")
                                             }
                                         }
                                     }
@@ -172,7 +185,7 @@ class ObjectBrowser {
                     }
                     scrollPane(name: ' Properties (includes public fields) ') {
                         def data = 
Inspector.sortWithRawValue(inspector.propertyInfoWithRawValue.toList())
-                        fieldTable = table {
+                        fieldTable = table(selectionMode: SINGLE_SELECTION) {
                             tableModel(list: data) {
                                 closureColumn(header: 'Name', read: { 
it[MEMBER_NAME_IDX] })
                                 closureColumn(header: 'Value', read: { 
it[MEMBER_VALUE_IDX] })
@@ -195,7 +208,8 @@ class ObjectBrowser {
                                     if (selectedRow != -1) {
                                         def value = 
fieldTable.model.getValueAt(selectedRow, MEMBER_RAW_VALUE_IDX)
                                         if (value != null) {
-                                            ObjectBrowser.inspect(value)
+                                            closeFrameIfAltDoubleClick(e)
+                                            ObjectBrowser.inspect(value, path 
+ (path.length() === 0 ? '' : '.') + 
"${fieldTable.model.getValueAt(selectedRow, 0)}")
                                         }
                                     }
                                 }
@@ -203,7 +217,7 @@ class ObjectBrowser {
                         })
                     }
                     scrollPane(name: ' (Meta) Methods ') {
-                        methodTable = table {
+                        methodTable = table(selectionMode: SINGLE_SELECTION) {
                             def data = 
Inspector.sort(inspector.methods.toList())
                             
data.addAll(Inspector.sort(inspector.metaMethods.toList()))
                             tableModel(list: data) {
@@ -218,6 +232,13 @@ class ObjectBrowser {
                         }
                     }
                 }
+                panel(name: 'Path',
+                        border: emptyBorder([5, 10, 5, 10]),
+                        constraints: SOUTH) {
+                    boxLayout(axis: 2)
+                    label('Path:  ')
+                    textField(editable: false, text: path)
+                }
             }
         }
 
@@ -239,6 +260,13 @@ class ObjectBrowser {
         }
     }
 
+    void closeFrameIfAltDoubleClick(MouseEvent e) {
+        if (e.altDown) {
+            frame.visible = false;
+            frame.dispose();
+        }
+    }
+
     void showAbout(EventObject evt) {
         def pane = swing.optionPane()
         // work around GROOVY-1048

Reply via email to