Skip to content
Permalink
Browse files

Merge pull request #744 from CafeKrem/feature/component-list

Feature/component list
  • Loading branch information...
jecisc committed Sep 2, 2019
2 parents da86831 + 3df3e10 commit cb26690bbf2c49fbb2d8c79691bfc42e3b93079c
@@ -0,0 +1,114 @@
Class {
#name : #SpComponentListFastTableDataSource,
#superclass : #FTDataSource,
#instVars : [
'model'
],
#category : #'Spec2-Adapters-Morphic-ComponentList'
}

{ #category : #accessing }
SpComponentListFastTableDataSource >> cellColumn: column row: rowIndex [
| displayValue cell item |
item := self model presenters at: rowIndex.
cell := FTCellMorph new
cellInset: 5;
yourself.
cell addMorphBack: item buildWithSpec.
^ cell
]

{ #category : #accessing }
SpComponentListFastTableDataSource >> elementAt: rowIndex [

^ self listModel at: rowIndex
]

{ #category : #accessing }
SpComponentListFastTableDataSource >> elements [

^ self model items
]

{ #category : #accessing }
SpComponentListFastTableDataSource >> headerColumn: column [
column id ifNil: [ ^ nil ].
^ FTCellMorph new
listCentering: #center;
addMorph: column id asMorph asReadOnlyMorph;
yourself
]

{ #category : #accessing }
SpComponentListFastTableDataSource >> listModel [
^ model model
]

{ #category : #accessing }
SpComponentListFastTableDataSource >> menuColumn: column row: rowIndex [
| menuPresenter |

menuPresenter := self model contextMenu.
menuPresenter ifNil: [ ^ nil ].
^ SpBindings
value: self model application adapterBindings
during: [
| m |
m := menuPresenter value.
m isMorph
ifTrue: [ m ]
ifFalse: [ m buildWithSpec ] ]
]

{ #category : #accessing }
SpComponentListFastTableDataSource >> model [
^ model
]

{ #category : #accessing }
SpComponentListFastTableDataSource >> model: anObject [
model := anObject
]

{ #category : #accessing }
SpComponentListFastTableDataSource >> newDataSourceMatching: aFTFilter [
| newElements wrappedItem text newDataSource modelCopy |

newElements := self elements select: [ :each |
wrappedItem := self model displayValueOf: each.
table columns anySatisfy: [ :column |
text := column transform: wrappedItem.
aFTFilter matches: text]].

newDataSource := self copy.
modelCopy := self model copy.
modelCopy prepareForFilteredDataSourceWith: newElements.
newDataSource model: modelCopy.

^newDataSource
]

{ #category : #accessing }
SpComponentListFastTableDataSource >> numberOfRows [
^ model
ifNil: [ 0 ]
ifNotNil: [ model presenters size ]
]

{ #category : #accessing }
SpComponentListFastTableDataSource >> searchText: aString [
| search text result |
aString isEmptyOrNil ifTrue: [ ^ #() ].
result := OrderedCollection new.
search := aString trimBoth asLowercase.
1 to: self numberOfRows do: [ :rowIndex |
text := (self model displayValueAt: rowIndex) contents trimBoth asLowercase.
(text beginsWith: search)
ifTrue: [ result add: rowIndex ] ].
^ result asArray
]

{ #category : #'drag and drop' }
SpComponentListFastTableDataSource >> transferFor: passenger from: aMorph [
^(self model transferFor: passenger from: self table) buildWithSpec
]
@@ -0,0 +1,38 @@
Class {
#name : #SpMorphicComponentListAdapter,
#superclass : #SpAbstractMorphicAdapter,
#category : #'Spec2-Adapters-Morphic-ComponentList'
}

{ #category : #factory }
SpMorphicComponentListAdapter >> buildWidget [

| datasource |
datasource := SpComponentListFastTableDataSource new.
datasource model: self model.
widget := FTTableMorph new
dataSource: datasource;
hideColumnHeaders;
hResizing: #spaceFill;
vResizing: #spaceFill;
setBalloonText: self help;
yourself.
self presenter whenPresentersChangedDo: [ widget refresh ].
^ widget
]

{ #category : #accessing }
SpMorphicComponentListAdapter >> children [

^ self rows collect: [ :row | | cell |
cell := row submorphs first.
cell submorphs first ]
]

{ #category : #accessing }
SpMorphicComponentListAdapter >> rows [

| tableContainer |
tableContainer := self widget submorphs first.
^ tableContainer submorphs
]
@@ -0,0 +1,29 @@
Class {
#name : #SpComponentListAdapterTest,
#superclass : #SpAbstractWidgetAdapterTest,
#category : #'Spec2-Backend-Tests'
}

{ #category : #accessing }
SpComponentListAdapterTest >> classToTest [

^ SpComponentListPresenter
]

{ #category : #tests }
SpComponentListAdapterTest >> testAddPresenterAddsWidget [

| button |
button := SpButtonPresenter new.
presenter addPresenter: button.

backendForTest waitUntilUIRedrawed.
self assert: self adapter children first equals: button adapter widget
]

{ #category : #tests }
SpComponentListAdapterTest >> testEmptyPresenterHasEmptyAdapter [

backendForTest waitUntilUIRedrawed.
self assertEmpty: self adapter children
]
@@ -5,7 +5,8 @@ Class {
#name : #SpComponentListPresenter,
#superclass : #SpAbstractWidgetPresenter,
#instVars : [
'#presenters => SpObservableSlot'
'#presenters => SpObservableSlot',
'#presentersChangedBlock'
],
#category : #'Spec2-Core-Widgets'
}
@@ -23,13 +24,23 @@ SpComponentListPresenter >> addPresenter: aPresenter [
self notifyPropertyChanged: #presenters
]

{ #category : #testing }
SpComponentListPresenter >> includes: aPresenter [
^ presenters includes: aPresenter
]

{ #category : #initialization }
SpComponentListPresenter >> initialize [

super initialize.
presenters := OrderedCollection new
]

{ #category : #testing }
SpComponentListPresenter >> isEmpty [
^ presenters isEmpty
]

{ #category : #accessor }
SpComponentListPresenter >> presenters [
^ presenters
@@ -41,3 +52,9 @@ SpComponentListPresenter >> presenters: aCollection [
aCollection do: [ :each | each owner: self ].
presenters := aCollection
]

{ #category : #event }
SpComponentListPresenter >> whenPresentersChangedDo: aBlockClosure [

self property: #presenters whenChangedDo: aBlockClosure
]
@@ -0,0 +1,63 @@
Class {
#name : #SpComponentListPresenterTest,
#superclass : #SpTest,
#category : #'Spec2-Tests-Core-Widgets'
}

{ #category : #running }
SpComponentListPresenterTest >> classToTest [
^ SpComponentListPresenter
]

{ #category : #tests }
SpComponentListPresenterTest >> testAddNoPresenterToComponentListDoesNotRaiseEvent [
| raised |
raised := false.
presenter whenPresentersChangedDo: [ raised := true ].


self deny: raised
]

{ #category : #tests }
SpComponentListPresenterTest >> testAddPresenterToComponentListIsInPresenterCollection [
| button |
button := SpButtonPresenter new.
presenter addPresenter: button.
self assert: (presenter includes: button)
]

{ #category : #tests }
SpComponentListPresenterTest >> testAddPresenterToComponentListRaisesEvent [
| button raised |
raised := false.
button := SpButtonPresenter new.
presenter whenPresentersChangedDo: [ raised := true ].

presenter addPresenter: button.

self assert: raised
]

{ #category : #tests }
SpComponentListPresenterTest >> testAddPresenterToComponentListRaisesSingleEvent [
| button raised |
raised := 0.
button := SpButtonPresenter new.
presenter whenPresentersChangedDo: [ raised := raised + 1 ].

presenter addPresenter: button.

self assert: raised equals: 1
]

{ #category : #tests }
SpComponentListPresenterTest >> testAddPresenterToComponentListShouldNotBeEmpty [
presenter addPresenter: SpButtonPresenter new.
self deny: presenter isEmpty
]

{ #category : #tests }
SpComponentListPresenterTest >> testNewComponentListIsEmpty [
self assertEmpty: presenter
]

0 comments on commit cb26690

Please sign in to comment.
You can’t perform that action at this time.