Clouseau/src/Clouseau/Dictionary.extension.st

43 lines
1.2 KiB
Smalltalk

Extension { #name : #Dictionary }
{ #category : #'*Clouseau' }
Dictionary >> asStringTablePresenter [
| tblRows |
tblRows := OrderedCollection new.
self keysAndValuesDo: [ :aKey :aValue | tblRows add: { aKey -> aValue } ].
^ SpTablePresenter new
addColumn: (SpStringTableColumn title: 'Key' evaluated: [ :anObject | (anObject at: 1) key ]);
addColumn: (SpStringTableColumn title: 'Value' evaluated: [ :anObject | (anObject at: 1) value ]);
items: tblRows;
alternateRowsColor;
yourself.
]
{ #category : #'*Clouseau' }
Dictionary >> asStringTreeTablePresenter [
^ SpTreeTablePresenter new
addColumn:
(SpStringTableColumn title: 'Key' evaluated: [ :anObject |
anObject isDictionary
ifTrue: [
anObject isEmpty
ifTrue: [ '' ]
ifFalse: [ anObject keys at: 1 ] ]
ifFalse: [ anObject key ] ]);
addColumn:
(SpStringTableColumn title: 'Value' evaluated: [ :anObject |
anObject isDictionary
ifTrue: [ '' ]
ifFalse: [ anObject value ] ]);
roots: self;
children: [ :anItem |
anItem value isDictionary
ifTrue: [
anItem value isEmpty
ifTrue: [ { } ]
ifFalse: [ anItem value ] ]
ifFalse: [ { } ] ];
yourself
]