Class: Glimmer::DataBinding::ListSelectionBinding

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

Overview

SWT List element selection binding

Constant Summary collapse

PROPERTY_TYPE_UPDATERS =
{
  :string => lambda { |element_proxy, value| element_proxy.select(element_proxy.index_of(value.to_s)) },
  :array => lambda { |element_proxy, value| element_proxy.selection=(value || []) }
}
PROPERTY_EVALUATORS =
{
  :string => lambda do |selection_array|
    return nil if selection_array.empty?
    selection_array[0]
  end,
  :array => lambda do |selection_array|
    selection_array
  end
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element_proxy, property_type) ⇒ ListSelectionBinding

Initialize with list element and property_type property_type :string represents default list single selection property_type :array represents list multi selection



32
33
34
35
36
37
38
39
# File 'lib/glimmer/data_binding/list_selection_binding.rb', line 32

def initialize(element_proxy, property_type)
  property_type = :string if property_type.nil? or property_type == :undefined
  @element_proxy = element_proxy
  @property_type = property_type
  @element_proxy.on_widget_disposed do |dispose_event|
    unregister_all_observables
  end
end

Instance Attribute Details

#element_proxyObject (readonly)

Returns the value of attribute element_proxy.



12
13
14
# File 'lib/glimmer/data_binding/list_selection_binding.rb', line 12

def element_proxy
  @element_proxy
end

Instance Method Details

#call(value) ⇒ Object



41
42
43
# File 'lib/glimmer/data_binding/list_selection_binding.rb', line 41

def call(value)
  PROPERTY_TYPE_UPDATERS[@property_type].call(@element_proxy, value) unless !evaluate_property.is_a?(Array) && evaluate_property == value
end

#evaluate_propertyObject



45
46
47
48
# File 'lib/glimmer/data_binding/list_selection_binding.rb', line 45

def evaluate_property
  selection_array = @element_proxy.selection.to_a #TODO refactor send('selection') into proper method invocation
  PROPERTY_EVALUATORS[@property_type].call(selection_array)
end