|
| 1 | +Class { |
| 2 | + #name : 'ExReqExampleTODOApplication', |
| 3 | + #superclass : 'SpPresenter', |
| 4 | + #instVars : [ |
| 5 | + 'tasks', |
| 6 | + 'listPresenter', |
| 7 | + 'addButton', |
| 8 | + 'stateButton' |
| 9 | + ], |
| 10 | + #category : 'ExecutableRequirements-Examples-Example-TODO', |
| 11 | + #package : 'ExecutableRequirements-Examples', |
| 12 | + #tag : 'Example-TODO' |
| 13 | +} |
| 14 | + |
| 15 | +{ #category : 'as yet unclassified' } |
| 16 | +ExReqExampleTODOApplication >> actionAddTask [ |
| 17 | + |
| 18 | + | dialog | |
| 19 | + dialog := SpRequestDialog new. |
| 20 | + dialog |
| 21 | + title: 'Create new task'; |
| 22 | + label: 'Enter the text here:'; |
| 23 | + text: ''; |
| 24 | + acceptLabel: 'OK'; |
| 25 | + cancelLabel: 'Cancel'; |
| 26 | + onAccept: [ |
| 27 | + | task | |
| 28 | + task := ExReqExampleTODOTask new |
| 29 | + text: dialog text; |
| 30 | + yourself. |
| 31 | + tasks add: task. |
| 32 | + listPresenter items: tasks. |
| 33 | + listPresenter selectItem: task ]; |
| 34 | + onCancel: [ ]. |
| 35 | + dialog openModal |
| 36 | +] |
| 37 | + |
| 38 | +{ #category : 'as yet unclassified' } |
| 39 | +ExReqExampleTODOApplication >> actionChangeState [ |
| 40 | + |
| 41 | + | selected | |
| 42 | + selected := self selectedTask. |
| 43 | + listPresenter selectedItem state = #TODO |
| 44 | + ifTrue: [ selected isDone ] |
| 45 | + ifFalse: [ selected isTodo ]. |
| 46 | + listPresenter updateList. |
| 47 | + listPresenter selectItem: selected |
| 48 | +] |
| 49 | + |
| 50 | +{ #category : 'initialization - deprecated' } |
| 51 | +ExReqExampleTODOApplication >> defaultLayout [ |
| 52 | + |
| 53 | + ^ SpBoxLayout newVertical |
| 54 | + spacing: 4; |
| 55 | + add: addButton expand: false; |
| 56 | + add: listPresenter; |
| 57 | + add: stateButton expand: false; |
| 58 | + yourself |
| 59 | +] |
| 60 | + |
| 61 | +{ #category : 'initialization - deprecated' } |
| 62 | +ExReqExampleTODOApplication >> initializePresenter [ |
| 63 | + |
| 64 | + tasks := OrderedCollection new. |
| 65 | + addButton := SpButtonPresenter new |
| 66 | + label: 'Add new task'; |
| 67 | + action: [ self actionAddTask ]; |
| 68 | + yourself. |
| 69 | + stateButton := SpButtonPresenter new |
| 70 | + label: 'Change state of selected task'; |
| 71 | + enabled: false; |
| 72 | + action: [ self actionChangeState ]; |
| 73 | + yourself. |
| 74 | + listPresenter := SpListPresenter new |
| 75 | + whenSelectionChangedDo: [ :sel | |
| 76 | + stateButton enabled: sel isNotNil ]; |
| 77 | + display: [ :task | task text ]; |
| 78 | + displayIcon: [ :task | |
| 79 | + task state = #DONE |
| 80 | + ifTrue: [ |
| 81 | + Smalltalk ui icons iconNamed: #checkboxSelected ] |
| 82 | + ifFalse: [ |
| 83 | + Smalltalk ui icons iconNamed: |
| 84 | + #checkboxUnselected ] ]; |
| 85 | + yourself |
| 86 | +] |
| 87 | + |
| 88 | +{ #category : 'as yet unclassified' } |
| 89 | +ExReqExampleTODOApplication >> selectedTask [ |
| 90 | + |
| 91 | + ^ listPresenter selectedItem |
| 92 | +] |
0 commit comments