/
GLMTreeMorphModel.class.st
438 lines (368 loc) · 11.5 KB
/
GLMTreeMorphModel.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
"
ClassTree new openOn: Collection
"
Class {
#name : #GLMTreeMorphModel,
#superclass : #PaginatedMorphTreeModel,
#instVars : [
'roots',
'glamourPresentation',
'childrenBlock',
'displayFormat',
'tagsToFilterBy',
'glmAnnouncer',
'inputText',
'amountToFilterBy',
'defaultPageSize',
'columnToSortBy',
'stopStepping'
],
#category : #'Glamour-Morphic-Widgets'
}
{ #category : #'drag and drop' }
GLMTreeMorphModel >> acceptDroppingMorph: transferMorph event: evt inMorph: listMorph [
| targetItem |
targetItem := (listMorph scrollerSubMorphFromPoint: evt position) complexContents item.
^ self glamourPresentation accept: transferMorph passenger droppedOnItem: targetItem
]
{ #category : #accessing }
GLMTreeMorphModel >> allKeystrokeActions [
^ (self glamourPresentation allActions, self glamourPresentation allSelectionActions) select: [ :action |
action hasShortcut ]
]
{ #category : #accessing }
GLMTreeMorphModel >> allMenuActions [
^ (self glamourPresentation allSelectionActions select: [:action | action hasTitle ])
]
{ #category : #accessing }
GLMTreeMorphModel >> amountToFilterBy [
^ nil "amountToFilterBy ifNil: [self glamourPresentation amountToShow]"
]
{ #category : #accessing }
GLMTreeMorphModel >> amountToFilterBy: aNumber [
amountToFilterBy := aNumber
]
{ #category : #announcements }
GLMTreeMorphModel >> announce: anAnnouncement [
self announcer announce: anAnnouncement
]
{ #category : #accessing }
GLMTreeMorphModel >> announcer [
^glmAnnouncer ifNil: [ glmAnnouncer := GLMAnnouncer new ]
]
{ #category : #accessing }
GLMTreeMorphModel >> childrenBlock [
^ childrenBlock ifNil: [ childrenBlock := self glamourPresentation children isNil
ifFalse: [self glamourPresentation children] ifTrue: [OrderedCollection new] ]
]
{ #category : #accessing }
GLMTreeMorphModel >> childrenBlock: aBlock [
childrenBlock := aBlock
]
{ #category : #accessing }
GLMTreeMorphModel >> defaultPageSize [
^ defaultPageSize
]
{ #category : #accessing }
GLMTreeMorphModel >> defaultPageSize: anInteger [
defaultPageSize := anInteger
]
{ #category : #accessing }
GLMTreeMorphModel >> displayFormat [
^ displayFormat ifNil: [displayFormat := self glamourPresentation format]
]
{ #category : #accessing }
GLMTreeMorphModel >> displayFormat: aBlock [
displayFormat := aBlock
]
{ #category : #accessing }
GLMTreeMorphModel >> displayValue [
^ columnToSortBy
ifNil: [self glamourPresentation displayValue]
ifNotNil: [self glamourPresentation displayValue sorted: self sortBlock]
]
{ #category : #'search and filtering' }
GLMTreeMorphModel >> doSearchOrFilter [
inputText isEmptyOrNil
ifTrue: [ self resetInput ]
ifFalse:[
self glamourPresentation allowsFilter
ifTrue: [ self executeFilter ]
ifFalse: [ self executeSearch ] ].
]
{ #category : #'drag and drop' }
GLMTreeMorphModel >> dragEnabled [
^ self glamourPresentation allowsItemDrag
]
{ #category : #'drag and drop' }
GLMTreeMorphModel >> dragPassengerFor: item inMorph: listMorph [
^ self glamourPresentation transformedDraggedItem: item complexContents item
]
{ #category : #'drag and drop' }
GLMTreeMorphModel >> dragTransferType [
^ #Glamour
]
{ #category : #'drag and drop' }
GLMTreeMorphModel >> dragTransferTypeForMorph: listMorph [
^ self dragTransferType
]
{ #category : #'drag and drop' }
GLMTreeMorphModel >> dropEnabled [
^ self glamourPresentation isDropTarget
]
{ #category : #'search and filtering' }
GLMTreeMorphModel >> executeFilter [
self updateRoots
]
{ #category : #'search and filtering' }
GLMTreeMorphModel >> executeSearch [
| newSelection check |
newSelection := OrderedCollection new.
roots do: [ :each |
check := self glamourPresentation searchStrategy value: self inputText value: each item.
check ifTrue: [newSelection add: each path]].
newSelection isEmpty
ifFalse: [ self selection: (MorphTreeMorphMultipleSelection new selectedNodePathList: newSelection) ]
ifTrue: [self selection: nil]
]
{ #category : #callbacks }
GLMTreeMorphModel >> explicitSelection: anObject [
"anObject is a domain object, not a Glamour related object"
self glamourPresentation isMultiple
ifTrue: [ self explicitlySelectMultipleItems: anObject ]
ifFalse: [ self explicitlySelectItem: anObject ]
]
{ #category : #'private selecting' }
GLMTreeMorphModel >> explicitlySelectItem: anObject [
( self selectedItem notNil and: [ self selectedItem = anObject ] )
ifTrue: [ ^ self ].
( self selectedItem isNil and: [ anObject isNil ] )
ifTrue: [ ^ self ].
anObject
ifNil: [ "we make sure to update the morph list by deselecting everything"
self selectNodePath: nil.
self selection: nil
].
self roots
do: [ :eachRoot |
eachRoot
withContentsDo: [ :each |
each item = anObject
ifTrue: [ each expandParentPath.
self selectNodePath: each path.
^ self
]
]
]
]
{ #category : #'private selecting' }
GLMTreeMorphModel >> explicitlySelectMultipleItems: aCollection [
| newSelection collection |
aCollection ifNil: [ ^ self ].
collection := aCollection isCollection
ifTrue: [ aCollection ]
ifFalse: [ aCollection asOrderedCollection ].
( self selection notNil
and: [ self selection selectedItemOrItemsOrNil = collection asOrderedCollection ] )
ifTrue: [ ^ self ].
newSelection := OrderedCollection new.
self roots
do: [ :eachRoot |
eachRoot
withContentsDo: [ :each |
( collection includes: each item )
ifTrue: [ newSelection add: each path ]
]
].
self selectAllNodePaths: newSelection
]
{ #category : #accessing }
GLMTreeMorphModel >> filteredRoots [
| filtered |
roots ifNil: [ self roots: self displayValue ].
filtered := roots select: [ :each | each shouldBeDisplayed ].
^ filtered
]
{ #category : #stepping }
GLMTreeMorphModel >> forceStopStepping [
stopStepping := true.
self changed.
]
{ #category : #accessing }
GLMTreeMorphModel >> glamourPresentation [
^ glamourPresentation
]
{ #category : #accessing }
GLMTreeMorphModel >> glamourPresentation: anObject [
glamourPresentation := anObject
]
{ #category : #accessing }
GLMTreeMorphModel >> inputText [
^ inputText ifNil: [inputText := '']
]
{ #category : #accessing }
GLMTreeMorphModel >> inputText: anObject [
inputText := anObject.
self doSearchOrFilter
]
{ #category : #accessing }
GLMTreeMorphModel >> inputTextEnabled [
^ true
]
{ #category : #callbacks }
GLMTreeMorphModel >> keyStroke: aKeyboardEvent from: aTreeMorph [
| action |
action := self allKeystrokeActions detect: [:a | a shortcut = aKeyboardEvent keyCharacter] ifNone: [nil].
action ifNotNil: [ self announce: (GLMKeyStroke action: action) ]
]
{ #category : #callbacks }
GLMTreeMorphModel >> menu: menu shifted: b [
"Set up the menu to apply to the receiver's, honoring the #shifted boolean"
self selectedNode ifNotNil: [:current | current menu: menu shifted: b].
^ menu
]
{ #category : #accessing }
GLMTreeMorphModel >> nodeModelFor: anObject [
^ (GLMTreeMorphNodeModel with: anObject) containerTree: self; yourself
]
{ #category : #callbacks }
GLMTreeMorphModel >> onDoubleClick [
self announcer announce: (GLMTreeMorphStrongSelectionChanged new strongSelectionValue:
(self selection ifNotNil: [self selection selectedItemOrItemsOrNil]))
]
{ #category : #actions }
GLMTreeMorphModel >> resetChildrenContents [
self roots do: [:each | each resetContentsRecursively]
]
{ #category : #'search and filtering' }
GLMTreeMorphModel >> resetInput [
self updateRoots
]
{ #category : #stepping }
GLMTreeMorphModel >> resetStopStepping [
stopStepping := false.
self changed.
]
{ #category : #callbacks }
GLMTreeMorphModel >> resetTagsToFilterBy [
tagsToFilterBy := OrderedCollection new.
self changed: #rootNodes.
]
{ #category : #accessing }
GLMTreeMorphModel >> rootNodes [
^self roots
]
{ #category : #accessing }
GLMTreeMorphModel >> roots [
| filtered |
roots ifNil: [ self roots: self displayValue ].
filtered := roots select: [ :each | each shouldBeDisplayed ].
((self shouldFilterByAmount and: [
self amountToFilterBy < filtered size]) and: [
filtered notEmpty]) ifTrue: [
filtered := filtered first: self amountToFilterBy ].
^ filtered
]
{ #category : #accessing }
GLMTreeMorphModel >> roots: anObjectOrCollection [
roots := anObjectOrCollection asOrderedCollection
collect: [:each | self nodeModelFor: each ]
]
{ #category : #callbacks }
GLMTreeMorphModel >> selection: aSelection [
self selection = aSelection ifTrue: [ ^ self ].
super selection: aSelection.
self announcer announce: (
GLMTreeMorphSelectionChanged new
selectionValue: (aSelection ifNotNil: [aSelection selectedItemOrItemsOrNil]);
selectionPathValue: self selectionPathItems;
yourself)
]
{ #category : #accessing }
GLMTreeMorphModel >> selectionPathItems [
^ self selectedNodePath ifNotNil: [ self selectedNodePath collect: [ :each | each item ] ]
]
{ #category : #stepping }
GLMTreeMorphModel >> shouldDoStep [
^ self glamourPresentation stepCondition cull: self
]
{ #category : #'search and filtering' }
GLMTreeMorphModel >> shouldFilterByAmount [
^ self amountToFilterBy notNil and: [self amountToFilterBy isZero not]
]
{ #category : #callbacks }
GLMTreeMorphModel >> shouldFilterByTag: aTag [
^ self tagsToFilterBy includes: aTag
]
{ #category : #'search and filtering' }
GLMTreeMorphModel >> shouldFilterByTextInput [
^ self glamourPresentation allowsFilter and: [ self inputText notEmpty ]
]
{ #category : #stepping }
GLMTreeMorphModel >> shouldStopStepping [
^ stopStepping ifNil: [ false ]
]
{ #category : #callbacks }
GLMTreeMorphModel >> sortBlock [
^ columnToSortBy sortBlock
ifNotNil: [ :aBlock | aBlock ]
ifNil: [
columnToSortBy defaultSortBlockForPresentation: self glamourPresentation ]
]
{ #category : #callbacks }
GLMTreeMorphModel >> sortByColumn: aGlamourColumn [
columnToSortBy := (columnToSortBy == aGlamourColumn
ifTrue: [ nil ]
ifFalse: [ aGlamourColumn ]).
self updateRoots
]
{ #category : #stepping }
GLMTreeMorphModel >> stepTime [
^ self glamourPresentation stepTime
]
{ #category : #callbacks }
GLMTreeMorphModel >> tagsToFilterBy [
^ tagsToFilterBy ifNil: [ tagsToFilterBy := OrderedCollection new ]
]
{ #category : #accessing }
GLMTreeMorphModel >> toggleAmountToFilterBy [
self amountToFilterBy notNil ifTrue:
[ self amountToFilterBy isZero
ifTrue: [ amountToFilterBy := self glamourPresentation amountToShow ]
ifFalse: [ amountToFilterBy := 0 ].
self changed: #rootNodes ]
]
{ #category : #callbacks }
GLMTreeMorphModel >> toggleFilteringByTag: aTag [
(self shouldFilterByTag: aTag)
ifTrue: [self tagsToFilterBy remove: aTag ]
ifFalse: [self tagsToFilterBy add: aTag].
self resetChildrenContents.
self changed: #rootNodes
]
{ #category : #accessing }
GLMTreeMorphModel >> updateRoots [
roots := nil.
self changed: #rootNodes
]
{ #category : #'drag and drop' }
GLMTreeMorphModel >> wantsDroppedMorph: transferMorph event: evt inMorph: listMorph [
| targetItem targetItemMorph |
(transferMorph isKindOf: TransferMorph) ifFalse: [ ^ false ].
transferMorph dragTransferType = self dragTransferType ifFalse: [ ^ false ].
targetItemMorph := (listMorph scrollerSubMorphFromPoint: evt position).
targetItemMorph ifNotNil: [
targetItem := targetItemMorph complexContents item.
^ self glamourPresentation allow: transferMorph passenger droppedOnItem: targetItem ].
self flag: 'we should ask the whole presentation if it wants to receive a dropped object'.
^ false
]
{ #category : #stepping }
GLMTreeMorphModel >> wantsSteps [
^ self shouldStopStepping not and: [
self glamourPresentation wantsSteps ]
]
{ #category : #announcements }
GLMTreeMorphModel >> when: anAnnouncement do: aBlock [
self announcer when: anAnnouncement do: aBlock
]