-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentity-list-editor.ss
90 lines (69 loc) · 2.71 KB
/
entity-list-editor.ss
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
#lang scheme/base
(require "base.ss")
(require "entity-editor.ss"
"editor-internal.ss")
(define entity-list-editor-mixin
(mixin/cells (html-element<%> editor<%>) ()
(inherit core-html-attributes
get-editors
set-editors!)
; Fields -------------------------------------
; (cell (listof entity-editor%))
(cell to-delete null #:accessor #:mutator)
; (cell (snooze-struct -> entity-editor<%>))
(init-field editor-maker
(lambda (struct)
(let ([ans (new entity-editor% [entity (snooze-struct-entity struct)])])
(send ans set-value! struct)
ans))
#:accessor)
; Constructor --------------------------------
(init [classes null])
(super-new [classes (list* 'smoke-entity-list-editor 'ui-widget classes)])
; Methods ------------------------------------
; -> (listof snooze-struct)
(define/public (get-initial-structs)
(map (cut send <> get-initial-struct)
(get-editors)))
; -> (listof snooze-struct)
(define/public (get-values)
(map (cut send <> get-value)
(get-editors)))
; -> (listof snooze-struct)
(define/public (set-values! structs)
(set-editors! (map editor-maker structs)))
; seed -> xml
(define/override (render seed)
(let ([editors (get-editors)])
(if (null? editors)
(xml (div (@ ,(core-html-attributes seed))
"No editors"))
(xml (div (@ ,(core-html-attributes seed))
,@(for/list ([editor (in-list (get-editors))])
(send editor render seed)))))))
; -> (listof check-result)
(define/override (parse)
(apply check-problems
(for/list ([editor (in-list (get-editors))])
(send editor parse))))
; -> (listof check-result)
(define/override (validate)
(apply check-problems
(for/list ([editor (in-list (get-editors))])
(send editor validate))))
; [any] -> snooze-struct
(define/override (commit-changes #:restructure [restructure (lambda (x) x)])
(for/list ([editor (in-list (get-editors))])
(send editor commit-changes
#:delete? #f
#:restructure restructure))
(for/list ([editor (in-list (get-to-delete))])
(send editor commit-changes
#:delete? #t
#:restructure restructure)))))
; Classes ----------------------------------------
(define entity-list-editor%
(entity-list-editor-mixin simple-editor%))
; Provide statements -----------------------------
(provide entity-list-editor-mixin
entity-list-editor%)