You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2022/06/20 07:02:03 UTC
[groovy] 02/02: GROOVY-10661: Support column sorting by storing raw values in a hidden table column and other optimization.
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 fface1c9fe7f20a1d4c50b4cb00ead62bfaa31cb
Author: Sandip Chitale <sa...@gmail.com>
AuthorDate: Fri Jun 17 16:50:27 2022 -0700
GROOVY-10661: Support column sorting by storing raw values in a hidden table column and other optimization.
---
.../groovy/groovy/console/ui/ObjectBrowser.groovy | 51 ++++++++++++----------
1 file changed, 29 insertions(+), 22 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 8382ea18e6..5726bedda9 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
@@ -48,7 +48,7 @@ import static groovy.inspect.Inspector.MEMBER_RAW_VALUE_IDX
class ObjectBrowser {
def inspector
- def swing, frame, fieldTable, methodTable, itemTable, mapTable
+ def swing, frame, fieldTable, methodTable, arrayTable, collectionTable, mapTable
static void main(args) {
inspect('some String')
@@ -86,23 +86,25 @@ class ObjectBrowser {
tabbedPane(constraints: CENTER) {
if (inspector.object?.class?.array) {
scrollPane(name: ' Array data ') {
- def values
- itemTable = table {
- def list = Arrays.asList(inspector.object)
+ arrayTable = table {
int i = 0
- values = list
+ def list = Arrays.asList(inspector.object)
def data = list.collect { val -> [i++, val] }
tableModel(list: data) {
closureColumn(header: 'Index', read: { it[0] })
closureColumn(header: 'Value', read: { it[1] })
+ closureColumn(header: 'Raw Value', read: { it[1] }) // to support sorting
}
}
- itemTable.addMouseListener(new MouseAdapter() {
+ arrayTable.getColumnModel().getColumn(2).setMinWidth(0);
+ arrayTable.getColumnModel().getColumn(2).setMaxWidth(0);
+ arrayTable.getColumnModel().getColumn(2).setWidth(0);
+ arrayTable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
- def selectedRow = itemTable.selectedRow
+ def selectedRow = arrayTable.selectedRow
if (selectedRow != -1) {
- def value = values[selectedRow]
+ def value = arrayTable.getModel().getValueAt(selectedRow, 2)
if (value != null) {
ObjectBrowser.inspect(value)
}
@@ -114,22 +116,24 @@ class ObjectBrowser {
}
if (inspector.object instanceof Collection) {
scrollPane(name: ' Collection data ') {
- def values
- itemTable = table {
+ collectionTable = table {
int i = 0
- values = inspector.object.collect { val -> val }
def data = inspector.object.collect { val -> [i++, val] }
tableModel(list: data) {
closureColumn(header: 'Index', read: { it[0] })
closureColumn(header: 'Value', read: { it[1] })
+ closureColumn(header: 'Raw Value', read: { it[1] }) // to support sorting
}
}
- itemTable.addMouseListener(new MouseAdapter() {
+ collectionTable.getColumnModel().getColumn(2).setMinWidth(0);
+ collectionTable.getColumnModel().getColumn(2).setMaxWidth(0);
+ collectionTable.getColumnModel().getColumn(2).setWidth(0);
+ collectionTable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
- def selectedRow = itemTable.selectedRow
+ def selectedRow = collectionTable.selectedRow
if (selectedRow != -1) {
- def value = values[selectedRow]
+ def value = collectionTable.getModel().getValueAt(selectedRow, 2)
if (value != null) {
ObjectBrowser.inspect(value)
}
@@ -141,23 +145,25 @@ class ObjectBrowser {
}
if (inspector.object instanceof Map) {
scrollPane(name: ' Map data ') {
- def values
- itemTable = table {
+ mapTable = table {
int i = 0
- values = inspector.object.collect { key, val -> val }
def data = inspector.object.collect { key, val -> [i++, key, val] }
tableModel(list: data) {
closureColumn(header: 'Index', read: { it[0] })
closureColumn(header: 'Key', read: { it[1] })
closureColumn(header: 'Value', read: { it[2] })
+ closureColumn(header: 'Raw Value', read: { it[2] }) // to support sorting
}
}
- itemTable.addMouseListener(new MouseAdapter() {
+ mapTable.getColumnModel().getColumn(3).setMinWidth(0);
+ mapTable.getColumnModel().getColumn(3).setMaxWidth(0);
+ mapTable.getColumnModel().getColumn(3).setWidth(0);
+ mapTable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
- def selectedRow = itemTable.selectedRow
+ def selectedRow = mapTable.selectedRow
if (selectedRow != -1) {
- def value = values[selectedRow]
+ def value = mapTable.getModel().getValueAt(selectedRow, 2)
if (value != null) {
ObjectBrowser.inspect(value)
}
@@ -177,7 +183,7 @@ class ObjectBrowser {
closureColumn(header: 'Origin', read: { it[MEMBER_ORIGIN_IDX] })
closureColumn(header: 'Modifier', read: { it[MEMBER_MODIFIER_IDX] })
closureColumn(header: 'Declarer', read: { it[MEMBER_DECLARER_IDX] })
- closureColumn(header: 'Raw Value', read: { it[MEMBER_RAW_VALUE_IDX] })
+ closureColumn(header: 'Raw Value', read: { it[MEMBER_RAW_VALUE_IDX] }) // to support sorting
}
}
fieldTable.getColumnModel().getColumn(6).setMinWidth(0);
@@ -218,7 +224,8 @@ class ObjectBrowser {
}
// Add a bit of formatting
- addSorter(itemTable)
+ addSorter(arrayTable)
+ addSorter(collectionTable)
addSorter(mapTable)
addSorter(fieldTable)
addSorter(methodTable)