Skip to content

Commit

Permalink
remove ToObservableCollectionFilterResultEvent, replaced by a resultA…
Browse files Browse the repository at this point in the history
…ction in ToObservableCollectionFilter
  • Loading branch information
plantec committed Oct 25, 2024
1 parent e235ab5 commit 5e9469e
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 139 deletions.
18 changes: 9 additions & 9 deletions src/Toplo-Examples/ToSandBox.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,9 @@ ToSandBox class >> example_EditorWithoutSoftLine [
{ #category : #list }
ToSandBox class >> example_FilterOnList2WithStatesOfAmerica [

" When filtered, update the primary selection with filtered items
- the contents of the list remains unchanged"

| listElement pane filterField data selector |
pane := ToPane new
beVertical;
Expand All @@ -939,6 +942,8 @@ ToSandBox class >> example_FilterOnList2WithStatesOfAmerica [
filterField margin: (BlInsets all: 2).

selector := ToObservableCollectionFilter new.
selector applicationResultAction: [
listElement selecter selectOnlyIndexes: selector selectedIndexes ].
listElement dataAccessor addAll: data.

selector onInstalledIn: listElement dataAccessor.
Expand All @@ -950,16 +955,12 @@ ToSandBox class >> example_FilterOnList2WithStatesOfAmerica [
pattern := filterField text asString.
selector pattern: pattern ]).

listElement dataAccessor addEventHandler: (BlEventHandler
on: ToObservableCollectionFilterResultEvent
do: [ :event |
listElement selecter selectOnlyIndexes:
event filter selectedIndexes ]).

listElement placeholderBuilder: [ :ph :e |
| lab |
lab := (ToLabel text: 'No Data') foreground: Color lightGray;
fontSize: 24; yourself.
lab := (ToLabel text: 'No Data')
foreground: Color lightGray;
fontSize: 24;
yourself.
lab matchParent.
ph addChild: lab ].

Expand Down Expand Up @@ -1904,7 +1905,6 @@ ToSandBox class >> example_SelectMultiFiltrable [

| select innerWindow newTagFactory |
select := ToMultiSelectElement new.
select inspect.
select nodeWrapping: true.
select keepPickOrder: true.
select popupListElement selectionOption grouped: false.
Expand Down
29 changes: 29 additions & 0 deletions src/Toplo-Widget-DropdownButton/ToDropdownEventHandler.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Class {
#name : #ToDropdownEventHandler,
#superclass : #ToElementWithPopupEventHandler,
#category : #'Toplo-Widget-DropdownButton'
}

{ #category : #'event handling' }
ToDropdownEventHandler >> elementAddedToSceneGraphEvent: anEvent [

| select |
select := anEvent currentTarget.
select refresh
]

{ #category : #'element handlers' }
ToDropdownEventHandler >> elementExtentChangedEvent: anEvent [

windowManager currentWindow ifNil: [ ^ self ].
windowManager applyPositionHookFromEvent: anEvent.
windowManager applySizeHookFromEvent: anEvent
]

{ #category : #'api - accessing' }
ToDropdownEventHandler >> eventsToHandle [

^ super eventsToHandle , {
BlElementAddedToSceneGraphEvent.
BlElementExtentChangedEvent }
]
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ ToDropdownPopupWindowManager >> defaultAutoClosePickOutsideEventClass [
^ BlMouseDownOutsideEvent
]

{ #category : #'api - hooks' }
ToDropdownPopupWindowManager >> defaultListElementEventHandler [

^ ToSelectListElementEventHandler new
]

{ #category : #initialization }
ToDropdownPopupWindowManager >> defaultMaxHeight [

Expand All @@ -47,7 +41,7 @@ ToDropdownPopupWindowManager >> defaultSizeHook [
{ #category : #accessing }
ToDropdownPopupWindowManager >> elementEventHandlerClass [

^ ToSelectEventHandler
^ ToDropdownEventHandler
]

{ #category : #accessing }
Expand Down Expand Up @@ -107,11 +101,6 @@ ToDropdownPopupWindowManager >> onInstalledIn: anElement [
listElement := self newListElement.
listElement selectElement: self element.
listElement focusability: BlFocusability none.

listElement addEventHandler: (self defaultListElementEventHandler
select: self element;
yourself).

self builder: [ :selectWin :request |
selectWin root hMatchParent.
selectWin root vFitContent.
Expand Down
13 changes: 7 additions & 6 deletions src/Toplo-Widget-List/ToAbstractListElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@ ToAbstractListElement >> offsetPositionRecordsForFilter: aStartPosition itemCoun
ToAbstractListElement >> onScrolled: aPoint [
]

{ #category : #'private - commands' }
ToAbstractListElement >> onSievedWith: aSieve [

self dataAccessor onSievedWith: aSieve.
self requestLayout
]

{ #category : #'t - element with placeholder' }
ToAbstractListElement >> placeholderElevation [

Expand Down Expand Up @@ -511,12 +518,6 @@ ToAbstractListElement >> selectionOption [
^ self primarySelectionMode selectionOption
]

{ #category : #'private - commands' }
ToAbstractListElement >> sieveResultWith: aSieve [

self dataAccessor sieveResultWith: aSieve
]

{ #category : #'accessing selecters' }
ToAbstractListElement >> unselectableSelecter [

Expand Down
24 changes: 10 additions & 14 deletions src/Toplo-Widget-List/ToListElementSieve.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Class {
'selectionModel',
'selecter',
'selectionHandler',
'sharedHandler',
'eventDispatcher',
'originalIndexMap',
'sieveEventHandler',
Expand Down Expand Up @@ -64,34 +63,34 @@ ToListElementSieve >> onInstalledIn: aListElement [
selectionModel := aListElement selectionModel copy.

originalData := aListElement dataAccessor newMirror.

queryRunner := ToObservableCollectionFilter new.
" When a query has occured (because the query pattern has changed), update the list element accordingly then
ask the list to process the appropiate data source command and to update the selection model "
queryRunner applicationResultAction: [
self updateCurrentData.
aListElement onSievedWith: self ].
queryRunner onInstalledIn: originalData.

" initialization of the current result with the current pattern "
self updateCurrentData.
sharedHandler := BlSharedEventDistributor new.
sharedHandler shareEvents:
{ ToObservableCollectionFilterResultEvent }.
originalData addEventHandler: sharedHandler.
aListElement addEventHandler: sharedHandler.

selectionHandler := ToSievedListElementEventHandler new.
selectionHandler sieve: self.
aListElement addEventHandler: selectionHandler.

sieveEventHandler := ToSieveEventHandler new
listElement: aListElement;
yourself.
" selectionChangedEventClass: is needed to update the selection
of the list when the selecter is used programmatically.
This is the case when a tag in a ToSelect is removed from its remove button"
selecter := ToSieveSelecter new
selectionModel: self selectionModel;
selectionChangedEventClass:
ToListPrimarySelectionChangedEvent;
multiple: aListElement isMultipleSelection;
yourself.
selecter onInstalledIn: self.
selecter
enabled: true;
multiple: aListElement isMultipleSelection.

self addEventHandler: sieveEventHandler
]

Expand All @@ -101,13 +100,10 @@ ToListElementSieve >> onUninstalledIn: aListElement [

aListElement removeEventHandler: selectionHandler.
queryRunner onUninstalledIn: originalData.
originalData removeEventHandler: sharedHandler.
aListElement removeEventHandler: sharedHandler.
self removeEventHandler: sieveEventHandler.
self removeEventHandler: commandEventHandler.
sieveEventHandler := nil.
commandEventHandler := nil.
sharedHandler := nil.
originalData unmirrored.
originalData := nil.
currentData := nil.
Expand Down
41 changes: 21 additions & 20 deletions src/Toplo-Widget-List/ToListSelecter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ToListSelecter >> applyCommand: aCommand [
previousModel := selectionModel copy.
aCommand applyWithOperator: operator.
previousModel = aCommand selectionModel ifTrue: [ ^ self ].
self commandApplied: aCommand
self onCommandApplied: aCommand
]

{ #category : #accessing }
Expand All @@ -53,25 +53,6 @@ ToListSelecter >> commandApplicationStrategy: aCommandApplicationStrategy [
commandApplicationStrategy := aCommandApplicationStrategy
]

{ #category : #'command application' }
ToListSelecter >> commandApplied: aCommand [

| req |
selectionChangedEventClass ifNil: [ ^ self ].

req := ToListSelectionCommandAppliedEvent new
command: aCommand;
requestedAction: [
element dispatchEvent: (selectionChangedEventClass new
selectionModel: aCommand selectionModel;
touchedIntervals: aCommand intervals;
selectionOption: self selectionOption;
yourself) ];
yourself.

element dispatchAuthorisationRequest: req
]

{ #category : #testing }
ToListSelecter >> containsIndex: anIndex [

Expand Down Expand Up @@ -260,6 +241,25 @@ ToListSelecter >> nextSelectableIndexToScrollTo [
ifFalse: [ 0 ] ]
]

{ #category : #'command application' }
ToListSelecter >> onCommandApplied: aCommand [

| req |
selectionChangedEventClass ifNil: [ ^ self ].

req := ToListSelectionCommandAppliedEvent new
command: aCommand;
requestedAction: [
element dispatchEvent: (selectionChangedEventClass new
selectionModel: aCommand selectionModel;
touchedIntervals: aCommand intervals;
selectionOption: self selectionOption;
yourself) ];
yourself.

element dispatchAuthorisationRequest: req
]

{ #category : #'api - hooks' }
ToListSelecter >> onInstalledIn: anElement [

Expand Down Expand Up @@ -514,5 +514,6 @@ ToListSelecter >> switchIndexSelection: anIndex [
ToListSelecter >> updateSelection [

self selectionModel deselectAll.
element ifNil: [ ^ self ].
element updateAllSelections
]
16 changes: 1 addition & 15 deletions src/Toplo-Widget-List/ToSievedListElementEventHandler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ToSievedListElementEventHandler >> buildOriginalIndexMapFrom: aListElement [
ToSievedListElementEventHandler >> eventsToHandle [

^ {
ToObservableCollectionFilterResultEvent.
" ToObservableCollectionFilterResultEvent."
BlInfiniteDataSourceChanged.
BlInfiniteDataSourceItemRangeChanged.
BlInfiniteDataSourceItemRangeInserted.
Expand Down Expand Up @@ -103,20 +103,6 @@ ToSievedListElementEventHandler >> listSelectionCommandAppliedEvent: aPreNotific
yourself)
]

{ #category : #'element handlers' }
ToSievedListElementEventHandler >> observableCollectionFilterResultEvent: anEvent [


| listElement |
listElement := anEvent currentTarget.

" a query has occured (because the query pattern has changed), update the list element accordingly "
sieve updateCurrentData.

" ask the list to process the appropiate data source command and to update the selection model"
listElement sieveResultWith: sieve
]

{ #category : #'api - hooks' }
ToSievedListElementEventHandler >> onInstalledIn: aListElement [

Expand Down
16 changes: 8 additions & 8 deletions src/Toplo-Widget-Select/ToSelectListElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Class {
#category : #'Toplo-Widget-Select-List'
}

{ #category : #'as yet unclassified' }
{ #category : #'private - commands' }
ToSelectListElement >> applyDataSourceSieveCommand: aDataSourceCommand [
" update the selection according to the sieve selection model"

Expand All @@ -19,19 +19,19 @@ ToSelectListElement >> applyDataSourceSieveCommand: aDataSourceCommand [
w visibility: BlVisibility visible ]
]

{ #category : #'as yet unclassified' }
{ #category : #accessing }
ToSelectListElement >> groupSelecter [

^ self groupSelectionMode selecter
]

{ #category : #'as yet unclassified' }
{ #category : #accessing }
ToSelectListElement >> groupSelectionMode [

^ self selectionModeWithEventClass: ToSelectGroupSelectionChangedEvent
]

{ #category : #'as yet unclassified' }
{ #category : #accessing }
ToSelectListElement >> groupSelectionModel [

^ self groupSelecter selectionModel
Expand All @@ -47,7 +47,7 @@ ToSelectListElement >> initialize [
self primarySelectionMode makeDisabledUnselectable: true
]

{ #category : #'as yet unclassified' }
{ #category : #accessing }
ToSelectListElement >> newGroupSelectionMode [

^ ToSelectListGroupSelectionMode parentMode: self primarySelectionMode
Expand All @@ -59,19 +59,19 @@ ToSelectListElement >> newRawSkin [
^ ToBasicListElementSkin new
]

{ #category : #'as yet unclassified' }
{ #category : #accessing }
ToSelectListElement >> selectElement [

^ selectElement
]

{ #category : #'as yet unclassified' }
{ #category : #accessing }
ToSelectListElement >> selectElement: aSelectElement [

selectElement := aSelectElement
]

{ #category : #'as yet unclassified' }
{ #category : #accessing }
ToSelectListElement >> sieve [

^ selectElement sieve
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,17 @@ ToSingleSelectInnerContainerElement >> refreshFromPopupListSelection [

" No data to select from, just do nothing here "
selectElement popupListElement dataAccessor ifEmpty: [ ^ self ].

selectionModel := self popupWindowManager sieve selectionModel.
originalData := self popupWindowManager sieve originalData.
selectedIndex := selectionModel isEmpty
ifTrue: [ 0 ]
ifFalse: [ selectionModel firstIndex ].

selectedIndex isZero ifFalse: [
self filterTextField text: '' asRopedText ].
currentSelectedIndex = selectedIndex ifTrue: [ ^ self ].
currentSelectedIndex := selectedIndex.
self filterTextField text: '' asRopedText.

dataView removeChildren.

Expand Down
Loading

0 comments on commit 5e9469e

Please sign in to comment.