-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor filter widget creation to `GtPharoStreamingMethodsFiltersEle…
…mentStencil` [feenkcom/gtoolkit#3983]
- Loading branch information
1 parent
a5e00e7
commit 9f7eb2c
Showing
6 changed files
with
183 additions
and
33 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
src/GToolkit-Pharo-Coder-Method-UI/GtFilterItemsElement.extension.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Extension { #name : #GtFilterItemsElement } | ||
|
||
{ #category : #'*GToolkit-Pharo-Coder-Method-UI' } | ||
GtFilterItemsElement >> filterUpdater [ | ||
^ GtPharoStreamingMethodsFiltersElementFromModelStencil new | ||
] |
6 changes: 6 additions & 0 deletions
6
src/GToolkit-Pharo-Coder-Method-UI/GtFiltersElement.extension.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Extension { #name : #GtFiltersElement } | ||
|
||
{ #category : #'*GToolkit-Pharo-Coder-Method-UI' } | ||
GtFiltersElement >> filterUpdater [ | ||
^ GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil new | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...haro-Coder-Method-UI/GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
Class { | ||
#name : #GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil, | ||
#superclass : #GtPharoStreamingMethodsFiltersElementStencil, | ||
#category : #'GToolkit-Pharo-Coder-Method-UI-Support' | ||
} | ||
|
||
{ #category : #'api - instantiation' } | ||
GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil >> create [ | ||
<return: #GtFiltersElement> | ||
| aFilterDescriptors aFiltersElement | | ||
self | ||
assert: [ streamingCodersViewModel isNotNil ] | ||
description: [ 'Streaming coders view model must be initialized' ]. | ||
|
||
aFilterDescriptors := streamingCodersViewModel streamingCodersModel | ||
filterDescriptors. | ||
|
||
aFiltersElement := GtFiltersElement new | ||
padding: (BlInsets all: 2); | ||
descriptors: aFilterDescriptors; | ||
yourself. | ||
self updateFiltersElement: aFiltersElement. | ||
aFiltersElement | ||
when: GtFiltersChangedEvent | ||
do: [ :anEvent | self updateCodersFilters: anEvent ]. | ||
|
||
^ aFiltersElement | ||
] | ||
|
||
{ #category : #'event handling' } | ||
GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil >> updateCodersFilters: anEvent [ | ||
| filters | | ||
|
||
filters := OrderedCollection new. | ||
|
||
anEvent filterElement filtersDo: [ :descriptor :value | | ||
filters add: (descriptor newFilterWithValue: value) ]. | ||
|
||
streamingCodersViewModel streamingCodersModel additionalFilters: filters | ||
] | ||
|
||
{ #category : #'api - updating' } | ||
GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil >> updateFiltersElement: aFiltersElement [ | ||
self | ||
assert: [ aFiltersElement isKindOf: GtFiltersElement ] | ||
description: [ '{1} must be kind of {2}' | ||
format: {aFiltersElement. | ||
GtFiltersElement} ]. | ||
self | ||
assert: [ streamingCodersViewModel isNotNil ] | ||
description: [ 'Streaming coders view model must be initialized' ]. | ||
|
||
aFiltersElement | ||
buildFilters: [ streamingCodersViewModel streamingCodersModel additionalFilters | ||
do: [ :eachFilter | | ||
(eachFilter class filterDescriptorFor: streamingCodersViewModel streamingCodersModel) | ||
ifNotNil: [ :aDescriptor | | ||
| aLabel | | ||
aLabel := aDescriptor valueIsRequired ifTrue: [ eachFilter filterValueString ]. | ||
aFiltersElement addFilterForDescriptor: aDescriptor andValue: aLabel ] ] ] | ||
] |
49 changes: 49 additions & 0 deletions
49
...lkit-Pharo-Coder-Method-UI/GtPharoStreamingMethodsFiltersElementFromModelStencil.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Class { | ||
#name : #GtPharoStreamingMethodsFiltersElementFromModelStencil, | ||
#superclass : #GtPharoStreamingMethodsFiltersElementStencil, | ||
#category : #'GToolkit-Pharo-Coder-Method-UI-Support' | ||
} | ||
|
||
{ #category : #'api - instantiation' } | ||
GtPharoStreamingMethodsFiltersElementFromModelStencil >> create [ | ||
| aModel aMethodsCoder aBuilder anUpdater aFiltersElement | | ||
aModel := GtFilterItemsModel new. | ||
aFiltersElement := aModel asFiltersElement. | ||
aMethodsCoder := streamingCodersViewModel streamingCodersModel. | ||
self updateFiltersElement: aFiltersElement. | ||
aBuilder := GtFilterMethodsCoderAvailableFiltersBuilder new | ||
coders: aMethodsCoder. | ||
aModel availableFiltersBuilder: aBuilder. | ||
anUpdater := GtFilterMethodCodersAdditionalFiltersUpdater new | ||
coders: aMethodsCoder; | ||
filtersModel: aModel. | ||
aModel weak | ||
when: GtFiltersModelUpdated | ||
send: #onFiltersUpdated: | ||
to: anUpdater. | ||
aFiltersElement userData at: GtFilterMethodCodersAdditionalFiltersUpdater put: anUpdater. | ||
|
||
^ aFiltersElement | ||
] | ||
|
||
{ #category : #'api - updating' } | ||
GtPharoStreamingMethodsFiltersElementFromModelStencil >> updateFiltersElement: aFiltersElement [ | ||
| aFiltersModel someFilterModels | | ||
self | ||
assert: [ streamingCodersViewModel isNotNil ] | ||
description: [ 'Streaming coders view model must be initialized' ]. | ||
|
||
aFiltersElement hasFiltersViewModel ifFalse: [ ^ self ]. | ||
aFiltersModel := aFiltersElement filtersViewModel filtersModel. | ||
|
||
"aFiltersModel items ifNotEmpty: [ ^ self ]." | ||
|
||
someFilterModels := streamingCodersViewModel streamingCodersModel | ||
additionalFilters | ||
collect: [ :eachFilter | | ||
eachFilter class | ||
filterDescriptor2For: streamingCodersViewModel streamingCodersModel ] | ||
thenReject: #isNil. | ||
|
||
aFiltersModel items: someFilterModels. | ||
] |
54 changes: 54 additions & 0 deletions
54
src/GToolkit-Pharo-Coder-Method-UI/GtPharoStreamingMethodsFiltersElementStencil.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
Class { | ||
#name : #GtPharoStreamingMethodsFiltersElementStencil, | ||
#superclass : #BrStencil, | ||
#instVars : [ | ||
'streamingCodersViewModel' | ||
], | ||
#classVars : [ | ||
'DefaultBuilderClass' | ||
], | ||
#category : #'GToolkit-Pharo-Coder-Method-UI-Support' | ||
} | ||
|
||
{ #category : #defaults } | ||
GtPharoStreamingMethodsFiltersElementStencil class >> beDescriptorsStencilDefault [ | ||
DefaultBuilderClass := GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil | ||
] | ||
|
||
{ #category : #defaults } | ||
GtPharoStreamingMethodsFiltersElementStencil class >> beModelStencilDefault [ | ||
DefaultBuilderClass := GtPharoStreamingMethodsFiltersElementFromModelStencil | ||
] | ||
|
||
{ #category : #defaults } | ||
GtPharoStreamingMethodsFiltersElementStencil class >> defaultStencil [ | ||
^ self defaultStencilClass new | ||
] | ||
|
||
{ #category : #defaults } | ||
GtPharoStreamingMethodsFiltersElementStencil class >> defaultStencilClass [ | ||
^ DefaultBuilderClass | ||
ifNil: [ DefaultBuilderClass := GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil ] | ||
] | ||
|
||
{ #category : #accessing } | ||
GtPharoStreamingMethodsFiltersElementStencil >> streamingCodersViewModel [ | ||
^ streamingCodersViewModel | ||
] | ||
|
||
{ #category : #accessing } | ||
GtPharoStreamingMethodsFiltersElementStencil >> streamingCodersViewModel: aViewModel [ | ||
self | ||
assert: [ aViewModel isNotNil ] | ||
description: [ 'Streaming coders view model must be non-nil' ]. | ||
self | ||
assert: [ streamingCodersViewModel isNil ] | ||
description: [ 'Streaming coders view model can be set only once' ]. | ||
|
||
streamingCodersViewModel := aViewModel | ||
] | ||
|
||
{ #category : #'api - updating' } | ||
GtPharoStreamingMethodsFiltersElementStencil >> updateFiltersElement: aFilterElement [ | ||
self subclassResponsibility | ||
] |