Class: Glimmer::SWT::ListSelectionBinding

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

Overview

SWT List widget selection binding

Constant Summary collapse

@@property_type_updaters =
{
  :string => lambda { |widget, value| widget.widget.select(widget.widget.index_of(value.to_s)) },
  :array => lambda { |widget, value| widget.widget.selection=((value or []).to_java :string) }
}
@@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

Methods included from Observer

#add_dependent, #dependents, #dependents_for, proc, #register, #registrations, #registrations_for, #remove_dependent, #unregister, #unregister_all_observables, #unregister_dependents_with_observable

Methods included from Observable

#add_observer, #remove_observer

Methods included from Glimmer

#add_contents, add_contents, dsl, #dsl, extended, included, logger, #method_missing, method_missing

Methods included from Glimmer::SwtPackages

included

Constructor Details

#initialize(widget, property_type) ⇒ ListSelectionBinding

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



29
30
31
32
33
34
35
36
37
38
# File 'lib/glimmer/swt/list_selection_binding.rb', line 29

def initialize(widget, property_type)
  property_type = :string if property_type.nil? or property_type == :undefined
  @widget = widget
  @property_type = property_type
  add_contents(@widget) {
    on_widget_disposed { |dispose_event|
      unregister_all_observables
    }
  }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer

Instance Attribute Details

#widgetObject (readonly)

Returns the value of attribute widget.



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

def widget
  @widget
end

Instance Method Details

#call(value) ⇒ Object



39
40
41
# File 'lib/glimmer/swt/list_selection_binding.rb', line 39

def call(value)
  @@property_type_updaters[@property_type].call(@widget, value) unless evaluate_property == value
end

#evaluate_propertyObject



42
43
44
45
46
# File 'lib/glimmer/swt/list_selection_binding.rb', line 42

def evaluate_property
  selection_array = @widget.widget.send("selection").to_a
  property_value = @@property_evaluators[@property_type].call(selection_array)
  return property_value
end