diff --git a/src/GToolkit-Pharo-Coder-Method-UI/GtFilterItemsElement.extension.st b/src/GToolkit-Pharo-Coder-Method-UI/GtFilterItemsElement.extension.st new file mode 100644 index 00000000..23bdb6b5 --- /dev/null +++ b/src/GToolkit-Pharo-Coder-Method-UI/GtFilterItemsElement.extension.st @@ -0,0 +1,6 @@ +Extension { #name : #GtFilterItemsElement } + +{ #category : #'*GToolkit-Pharo-Coder-Method-UI' } +GtFilterItemsElement >> filterUpdater [ + ^ GtPharoStreamingMethodsFiltersElementFromModelStencil new +] diff --git a/src/GToolkit-Pharo-Coder-Method-UI/GtFiltersElement.extension.st b/src/GToolkit-Pharo-Coder-Method-UI/GtFiltersElement.extension.st new file mode 100644 index 00000000..c8edbf5c --- /dev/null +++ b/src/GToolkit-Pharo-Coder-Method-UI/GtFiltersElement.extension.st @@ -0,0 +1,6 @@ +Extension { #name : #GtFiltersElement } + +{ #category : #'*GToolkit-Pharo-Coder-Method-UI' } +GtFiltersElement >> filterUpdater [ + ^ GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil new +] diff --git a/src/GToolkit-Pharo-Coder-Method-UI/GtPharoStreamingMethodsCoderElement.class.st b/src/GToolkit-Pharo-Coder-Method-UI/GtPharoStreamingMethodsCoderElement.class.st index 43259d6a..780aca58 100644 --- a/src/GToolkit-Pharo-Coder-Method-UI/GtPharoStreamingMethodsCoderElement.class.st +++ b/src/GToolkit-Pharo-Coder-Method-UI/GtPharoStreamingMethodsCoderElement.class.st @@ -21,26 +21,9 @@ GtPharoStreamingMethodsCoderElement >> asScrollableElement [ { #category : #'instance creation' } GtPharoStreamingMethodsCoderElement >> buildFilter [ - | filterElement filterDescriptors | - filterDescriptors := streamingCodersViewModel streamingCodersModel - filterDescriptors. - filterDescriptors isEmpty ifTrue: [ ^ self ]. - filterElement := GtFiltersElement new - padding: (BlInsets all: 2); - descriptors: filterDescriptors; - yourself. - filterElement - buildFilters: [ streamingCodersViewModel streamingCodersModel additionalFilters - do: [ :each | - (each class filterDescriptorFor: streamingCodersViewModel streamingCodersModel) - ifNotNil: [ :descriptor | - | label | - label := descriptor valueIsRequired ifTrue: [ each filterValueString ]. - filterElement addFilterForDescriptor: descriptor andValue: label ] ] ]. - filterElement - when: GtFiltersChangedEvent - do: [ :event | self updateCodersFilters: event ]. - ^ filterElement + ^ GtPharoStreamingMethodsFiltersElementStencil defaultStencil + streamingCodersViewModel: streamingCodersViewModel; + asElement. ] { #category : #'instance creation' } @@ -167,18 +150,9 @@ GtPharoStreamingMethodsCoderElement >> onFilterChanged: anAnnouncement [ self childWithId: #filter ifFound: [ :aFiltersElement | - aFiltersElement - buildFilters: [ - streamingCodersViewModel additionalFilters do: [ :each | - (each filterDescriptorFor: streamingCodersViewModel streamingCodersModel) - ifNotNil: [ :descriptor | - | label | - label := descriptor valueIsRequired - ifTrue: [ each filterValueString ]. - - aFiltersElement - addFilterForDescriptor: descriptor - andValue: label ] ] ] ] + aFiltersElement filterUpdater + streamingCodersViewModel: streamingCodersViewModel; + updateFiltersElement: aFiltersElement ] ifNone: [ ] ] @@ -270,7 +244,7 @@ GtPharoStreamingMethodsCoderElement >> unsubscribeFromStreamingCodersViewModel [ { #category : #'private - update' } GtPharoStreamingMethodsCoderElement >> updateCodersFilters: anEvent [ | filters | - + self flag: 'Can be deleted since it is moved to GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil>>#updateCodersFilters:'. filters := OrderedCollection new. anEvent filterElement filtersDo: [ :descriptor :value | diff --git a/src/GToolkit-Pharo-Coder-Method-UI/GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil.class.st b/src/GToolkit-Pharo-Coder-Method-UI/GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil.class.st new file mode 100644 index 00000000..f8cac98d --- /dev/null +++ b/src/GToolkit-Pharo-Coder-Method-UI/GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil.class.st @@ -0,0 +1,61 @@ +Class { + #name : #GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil, + #superclass : #GtPharoStreamingMethodsFiltersElementStencil, + #category : #'GToolkit-Pharo-Coder-Method-UI-Support' +} + +{ #category : #'api - instantiation' } +GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil >> create [ + + | 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 ] ] ] +] diff --git a/src/GToolkit-Pharo-Coder-Method-UI/GtPharoStreamingMethodsFiltersElementFromModelStencil.class.st b/src/GToolkit-Pharo-Coder-Method-UI/GtPharoStreamingMethodsFiltersElementFromModelStencil.class.st new file mode 100644 index 00000000..f2cf6580 --- /dev/null +++ b/src/GToolkit-Pharo-Coder-Method-UI/GtPharoStreamingMethodsFiltersElementFromModelStencil.class.st @@ -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. +] diff --git a/src/GToolkit-Pharo-Coder-Method-UI/GtPharoStreamingMethodsFiltersElementStencil.class.st b/src/GToolkit-Pharo-Coder-Method-UI/GtPharoStreamingMethodsFiltersElementStencil.class.st new file mode 100644 index 00000000..6907b6e7 --- /dev/null +++ b/src/GToolkit-Pharo-Coder-Method-UI/GtPharoStreamingMethodsFiltersElementStencil.class.st @@ -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 +]