| 230 | } |
| 231 | |
| 232 | func (bp *boolProperty) SetSource(source interface{}) error { |
| 233 | if bp.ReadOnly() { |
| 234 | return ErrPropertyReadOnly |
| 235 | } |
| 236 | |
| 237 | if source != nil { |
| 238 | switch source := source.(type) { |
| 239 | case string: |
| 240 | // nop |
| 241 | |
| 242 | case Condition: |
| 243 | if err := checkPropertySource(bp, source); err != nil { |
| 244 | return err |
| 245 | } |
| 246 | |
| 247 | if err := bp.Set(source.Satisfied()); err != nil { |
| 248 | return err |
| 249 | } |
| 250 | |
| 251 | bp.sourceChangedHandle = source.Changed().Attach(func() { |
| 252 | bp.Set(source.Satisfied()) |
| 253 | }) |
| 254 | |
| 255 | case Expression: |
| 256 | if err := checkPropertySource(bp, source); err != nil { |
| 257 | return err |
| 258 | } |
| 259 | |
| 260 | if satisfied, ok := source.Value().(bool); ok { |
| 261 | if err := bp.Set(satisfied); err != nil { |
| 262 | return err |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | bp.sourceChangedHandle = source.Changed().Attach(func() { |
| 267 | if satisfied, ok := source.Value().(bool); ok { |
| 268 | bp.Set(satisfied) |
| 269 | } |
| 270 | }) |
| 271 | |
| 272 | default: |
| 273 | return newError(fmt.Sprintf(`invalid source: "%s" of type %T`, source, source)) |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | if oldCond, ok := bp.source.(Condition); ok { |
| 278 | oldCond.Changed().Detach(bp.sourceChangedHandle) |
| 279 | } |
| 280 | |
| 281 | bp.source = source |
| 282 | |
| 283 | return nil |
| 284 | } |
| 285 | |
| 286 | func (bp *boolProperty) Validatable() bool { |
| 287 | return false |