Skip to content

Commit

Permalink
Merge b1c430c
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanlm committed Jan 8, 2025
2 parents d9d4b1e + b1c430c commit 2924d7a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
33 changes: 31 additions & 2 deletions src/Spec2-Core/SpTableColumn.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Class {
'evaluation',
'expandable',
'sortFunction',
'width'
'width',
'formattingBlock'
],
#category : 'Spec2-Core-Widgets-Table',
#package : 'Spec2-Core',
Expand Down Expand Up @@ -92,6 +93,18 @@ SpTableColumn >> beNotExpandable [
expandable := false
]

{ #category : 'private' }
SpTableColumn >> evaluateObject: anObject [

"Apply the evaluation to the object of the table row.
If no evaluation is set, evaluate to the object itself.
IMPORTANT: Sorting happens on the results of evaluation and not formatting"

self evaluation ifNil: [ ^ anObject ].
^ self evaluation cull: anObject
]

{ #category : 'api' }
SpTableColumn >> evaluated: aBlock [
"Define how the column will evaluate the element of the table/tree model
Expand All @@ -111,6 +124,22 @@ SpTableColumn >> evaluation [
^ evaluation
]

{ #category : 'private' }
SpTableColumn >> formatObject: anObject [
"Returns the string representation of the argument to display in the table cell"

formattingBlock ifNil: [ ^ anObject ].
^ formattingBlock value: anObject
]

{ #category : 'api' }
SpTableColumn >> formatted: aBlock [
"Defines how each element is formatted to be shown.
By default items will be shown using #asString"

formattingBlock := aBlock
]

{ #category : 'testing' }
SpTableColumn >> hasFixedWidth [

Expand Down Expand Up @@ -161,7 +190,7 @@ SpTableColumn >> isSortable [
{ #category : 'private' }
SpTableColumn >> readObject: anObject [

^ self evaluation cull: anObject
^ self formatObject: (self evaluateObject: anObject)
]

{ #category : 'api' }
Expand Down
6 changes: 5 additions & 1 deletion src/Spec2-Examples/SpDemoTablePresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ SpDemoTablePresenter >> defaultLayout [

{ #category : 'initialization' }
SpDemoTablePresenter >> initialize [
selectedClasses := OrderedCollection with: ASTCache with: ASTEvaluationTest with: Abort.

selectedClasses := OrderedCollection
with: SpDemoTablePage
with: SpPresenter
with: Abort.
super initialize
]

Expand Down
28 changes: 28 additions & 0 deletions src/Spec2-Tests/SpStringTableColumnTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,34 @@ Class {
#tag : 'Core-Widgets'
}

{ #category : 'tests' }
SpStringTableColumnTest >> testDisplayObjectRespectsFormatting [

| column dateToShow |
column := SpStringTableColumn new.
column formatted: [ :e | e displayString ].

dateToShow := Date today.

self
assert: (column readObject: dateToShow)
equals: dateToShow displayString
]

{ #category : 'tests' }
SpStringTableColumnTest >> testDisplayObjectWithoutFormattingReturnsTheObjectItself [

| column dateToShow |
column := SpStringTableColumn new.

dateToShow := Date today.

"It's up to the table to stringify the object later"
self
assert: (column readObject: dateToShow)
equals: dateToShow
]

{ #category : 'tests' }
SpStringTableColumnTest >> testIsSortable [
|widget|
Expand Down

0 comments on commit 2924d7a

Please sign in to comment.