forked from lxn/walk
/
databinder.go
47 lines (36 loc) · 873 Bytes
/
databinder.go
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
// Copyright 2012 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package declarative
import (
"github.com/lxn/walk"
)
type DataBinder struct {
AssignTo **walk.DataBinder
DataSource interface{}
ErrorPresenter ErrorPresenter
AutoSubmit bool
OnSubmitted walk.EventHandler
}
func (db DataBinder) create() (*walk.DataBinder, error) {
if db.DataSource == nil {
return nil, nil
}
b := walk.NewDataBinder()
if db.ErrorPresenter != nil {
ep, err := db.ErrorPresenter.Create()
if err != nil {
return nil, err
}
b.SetErrorPresenter(ep)
}
b.SetDataSource(db.DataSource)
b.SetAutoSubmit(db.AutoSubmit)
if db.OnSubmitted != nil {
b.Submitted().Attach(db.OnSubmitted)
}
if db.AssignTo != nil {
*db.AssignTo = b
}
return b, nil
}