Class: Glimmer::SWT::Custom::RadioGroup

Inherits:
Object
  • Object
show all
Includes:
UI::CustomWidget
Defined in:
lib/glimmer/swt/custom/radio_group.rb

Overview

A custom widget rendering a group of radios generated via data-binding

Instance Attribute Summary

Attributes included from UI::CustomWidget

#body_root, #options, #parent, #swt_style

Instance Method Summary collapse

Methods included from UI::CustomWidget

add_custom_widget_namespaces_for, #add_observer, #async_exec, #attribute_setter, #can_add_observer?, #content, custom_widget_namespaces, for, #get_attribute, #has_instance_method?, #has_style?, included, #initialize, #local_respond_to?, #method_missing, namespaces_for_class, #post_initialize_child, reset_custom_widget_namespaces, #respond_to?, #sync_exec

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer::UI::CustomWidget

Instance Method Details

#can_handle_observation_request?(observation_request) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/glimmer/swt/custom/radio_group.rb', line 80

def can_handle_observation_request?(observation_request)
  radios.first&.can_handle_observation_request?(observation_request) || super(observation_request)
end

#delegate_observation_request_to_radios(observation_request, &block) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/glimmer/swt/custom/radio_group.rb', line 90

def delegate_observation_request_to_radios(observation_request, &block)
  if observation_request != 'on_widget_disposed'
    radios.count.times do |index|
    radio = radios[index]
    radio.handle_observation_request(observation_request, block) if radio.can_handle_observation_request?(observation_request)
    end
  end
end

#handle_observation_request(observation_request, block) ⇒ Object



84
85
86
87
88
# File 'lib/glimmer/swt/custom/radio_group.rb', line 84

def handle_observation_request(observation_request, block)
  observation_requests << [observation_request, block]
  delegate_observation_request_to_radios(observation_request, &block)
  super
end

#has_attribute?(attribute_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
106
107
108
# File 'lib/glimmer/swt/custom/radio_group.rb', line 103

def has_attribute?(attribute_name, *args)
  @radios.to_a.map do |widget_proxy|
    return true if widget_proxy.has_attribute?(attribute_name, *args)
  end
  super
end

#itemsObject



41
42
43
# File 'lib/glimmer/swt/custom/radio_group.rb', line 41

def items
  @items || []
end

#items=(text_array) ⇒ Object



35
36
37
38
39
# File 'lib/glimmer/swt/custom/radio_group.rb', line 35

def items=(text_array)
  selection_value = selection
  @items = Array[*text_array]
  build_radios
end

#observation_request_to_event_mappingObject



71
72
73
74
75
76
77
78
# File 'lib/glimmer/swt/custom/radio_group.rb', line 71

def observation_request_to_event_mapping
  # TODO method might not be needed
  {
    'on_widget_selected' => {
      event: 'change'
    },
  }
end

#observation_requestsObject



99
100
101
# File 'lib/glimmer/swt/custom/radio_group.rb', line 99

def observation_requests
  @observation_requests ||= Set.new
end

#radiosObject



67
68
69
# File 'lib/glimmer/swt/custom/radio_group.rb', line 67

def radios
  @radios ||= []
end

#selectionObject



53
54
55
56
# File 'lib/glimmer/swt/custom/radio_group.rb', line 53

def selection
  selection_value = radios[selection_index]&.text unless selection_index == -1
  selection_value.to_s
end

#selection=(text) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/glimmer/swt/custom/radio_group.rb', line 45

def selection=(text)
  radios.count.times do |index|
    radio = radios[index]
    item = items[index]
    radio.selection = item == text
  end
end

#selection_indexObject



63
64
65
# File 'lib/glimmer/swt/custom/radio_group.rb', line 63

def selection_index
  radios.index(radios.detect(&:selection)) || -1
end

#selection_index=(index) ⇒ Object Also known as: select



58
59
60
# File 'lib/glimmer/swt/custom/radio_group.rb', line 58

def selection_index=(index)
  self.selection=(items[index])
end

#set_attribute(attribute_name, *args) ⇒ Object



110
111
112
113
114
115
116
117
118
# File 'lib/glimmer/swt/custom/radio_group.rb', line 110

def set_attribute(attribute_name, *args)
  excluded_attributes = ['selection']
  unless excluded_attributes.include?(attribute_name.to_s)
    @radios.to_a.each do |widget_proxy|
      widget_proxy.set_attribute(attribute_name, *args) if widget_proxy.has_attribute?(attribute_name, *args)
    end
  end
  super
end