Class: Glimmer::DataBinding::WidgetBinding

Inherits:
Object
  • Object
show all
Includes:
Glimmer, Observable, Observer
Defined in:
lib/glimmer/data_binding/widget_binding.rb

Constant Summary

Constants included from Glimmer

GUI

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Glimmer

included

Constructor Details

#initialize(widget, property, sync_exec: nil, async_exec: nil) ⇒ WidgetBinding

Returns a new instance of WidgetBinding.


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/glimmer/data_binding/widget_binding.rb', line 35

def initialize(widget, property, sync_exec: nil, async_exec: nil)
  @widget = widget
  @property = property
  @sync_exec = sync_exec
  @async_exec = async_exec
  SWT::DisplayProxy.instance.auto_exec(override_sync_exec: @sync_exec, override_async_exec: @async_exec) do
    if @widget.respond_to?(:on_widget_disposed)
      @widget.on_widget_disposed do |dispose_event|
        unregister_all_observables
      end
    end
  end
end

Instance Attribute Details

#propertyObject (readonly)

Returns the value of attribute property.


34
35
36
# File 'lib/glimmer/data_binding/widget_binding.rb', line 34

def property
  @property
end

#widgetObject (readonly)

Returns the value of attribute widget.


34
35
36
# File 'lib/glimmer/data_binding/widget_binding.rb', line 34

def widget
  @widget
end

Instance Method Details

#call(value) ⇒ Object


49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/glimmer/data_binding/widget_binding.rb', line 49

def call(value)
  SWT::DisplayProxy.instance.auto_exec(override_sync_exec: @sync_exec, override_async_exec: @async_exec) do
    if @widget.respond_to?(:disposed?) && @widget.disposed?
      unregister_all_observables
      return
    end
    # need the rescue false for a scenario with tree items not being equal to model objects raising an exception
    if @async_exec || !((value == evaluate_property) rescue false) # need the rescue false for a scenario with tree items not being equal to model objects raising an exception
      @widget.set_attribute(@property, value)
    end
  end
end

#evaluate_propertyObject


62
63
64
65
66
67
68
# File 'lib/glimmer/data_binding/widget_binding.rb', line 62

def evaluate_property
  if @widget.respond_to?(:disposed?) && @widget.disposed?
    unregister_all_observables
    return
  end
  @widget.get_attribute(@property)
end