/
FTFilterFunctionWithAction.class.st
108 lines (92 loc) · 3.2 KB
/
FTFilterFunctionWithAction.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
"
I am a Filter widget that also have an action button.
Description
-------------------------------------------------
I am use as a FilterFunction but I also have a Button. I am use by FTTableMorph.
Public API and Key Messages
-------------------------------------------------
- #table: aTableMorph action: aBlock named: aString
is my constructor. The block is the action to be executed by the button and the string is the name of the button.
Internal Representation and Key Implementation Points.
-------------------------------------------------
Instance Variables
actionBlock: I am a block that need to be executed when the user press the button
actionButton: I am the button of the widget
The action block can takes 3 parameters:
- The filtered data source
- The pattern on the filter field
- The selected element on the table
"
Class {
#name : #FTFilterFunctionWithAction,
#superclass : #FTFilterFunction,
#instVars : [
'actionButton',
'actionBlock'
],
#category : #'Morphic-Widgets-FastTable-Functions'
}
{ #category : #'instance creation' }
FTFilterFunctionWithAction class >> table: aFTTableMorph action: aBlockClosure named: aString [
^ (self table: aFTTableMorph)
action: aBlockClosure named: aString;
yourself
]
{ #category : #option }
FTFilterFunctionWithAction >> action: aBlockClosure named: aString [
actionBlock := aBlockClosure.
self initializeActionButtonNamed: aString
]
{ #category : #accessing }
FTFilterFunctionWithAction >> beExplicite [
super beExplicite.
table addMorph: actionButton.
table selectedIndex = 0
ifTrue: [ table selectIndex: 1 ]
]
{ #category : #execute }
FTFilterFunctionWithAction >> execute [
actionBlock
cull: table dataSource
cull: field getTextFromModel asString
cull:
(table selectedIndex = 0
ifFalse: [ table dataSource realElementAt: table selectedIndex ]
ifTrue: [ nil ])
]
{ #category : #initialization }
FTFilterFunctionWithAction >> initializeActionButtonNamed: aString [
actionButton := PluggableButtonMorph
newButtonFor: self
action: #execute
label: aString
help: nil
]
{ #category : #private }
FTFilterFunctionWithAction >> resizeButton [
| topLeft bottomRight |
self flag: #TODO. "Maybe it could be cool to let the user choose if the field need to be at the top or the bottom."
bottomRight := (table bounds right - table verticalScrollBarWidth) @ table bottom.
topLeft := (bottomRight x - actionButton width) @ (table bounds bottom - self fieldHeigh).
actionButton bounds: (topLeft corner: bottomRight)
]
{ #category : #private }
FTFilterFunctionWithAction >> resizeField [
| topLeft bottomRight |
self flag: #TODO. "Maybe it could be cool to let the user choose if the field need to be at the top or the bottom."
topLeft := table bounds left @ (table bounds bottom - self fieldHeigh).
bottomRight := (table bounds right - table verticalScrollBarWidth - (actionButton width + 5))
@ table bottom.
field bounds: (topLeft corner: bottomRight)
]
{ #category : #private }
FTFilterFunctionWithAction >> resizeWidget [
self resizeField.
self resizeButton
]
{ #category : #accessing }
FTFilterFunctionWithAction >> showWidget [
super showWidget.
table addMorph: actionButton.
table selectedIndex = 0 ifTrue: [ table selectIndex: 1 ]
]