Class: Glimmer::SWT::Custom::RadioGroup
- Inherits:
-
Object
- Object
- Glimmer::SWT::Custom::RadioGroup
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
#body_root, #options, #parent, #parent_proxy, #swt_style, #swt_widget
Instance Method Summary
collapse
add_custom_widget_namespaces_for, #add_observer, after_body, #async_exec, #attribute_setter, before_body, body, #can_add_observer?, #content, current_custom_widgets, custom_widget_namespaces, def_option_attr_accessors, #disposed?, flyweight_custom_widget_classes, for, #get_attribute, #has_instance_method?, #has_style?, #initialize, keyword, #local_respond_to?, #method_missing, namespaces_for_class, #observer_registrations, option, options, #post_initialize_child, reset_custom_widget_namespaces, #respond_to?, shortcut_keyword, #sync_exec, #timer_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
76
77
78
79
|
# File 'lib/glimmer/swt/custom/radio_group.rb', line 76
def can_handle_observation_request?(observation_request)
radios.first&.can_handle_observation_request?(observation_request) or
super(observation_request)
end
|
#delegate_observation_request_to_radios(observation_request, &block) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/glimmer/swt/custom/radio_group.rb', line 87
def delegate_observation_request_to_radios(observation_request, &block)
if observation_request != 'on_widget_disposed'
radios.count.times do |index|
radio = radios[index]
label = labels[index]
if observation_request == 'on_widget_selected'
radio_block = lambda do |event|
if event.widget.selection || selection_index == -1
event.widget = self.swt_widget
block.call(event)
end
end
label_block = lambda do |event|
self.selection_index = index
block.call(event)
end
radio.handle_observation_request(observation_request, &radio_block) if radio.can_handle_observation_request?(observation_request)
label.handle_observation_request('on_mouse_up', &label_block)
else
listener_block = lambda do |event|
event.widget = self.swt_widget
block.call(event)
end
radio.handle_observation_request(observation_request, &listener_block) if radio.can_handle_observation_request?(observation_request)
label.handle_observation_request(observation_request, &listener_block) if label.can_handle_observation_request?(observation_request)
end
end
end
end
|
#handle_observation_request(observation_request, &block) ⇒ Object
81
82
83
84
85
|
# File 'lib/glimmer/swt/custom/radio_group.rb', line 81
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
121
122
123
124
125
126
|
# File 'lib/glimmer/swt/custom/radio_group.rb', line 121
def has_attribute?(attribute_name, *args)
(@composites.to_a + @radios.to_a + @labels.to_a).map do |widget_proxy|
return true if widget_proxy.has_attribute?(attribute_name, *args)
end
super
end
|
#items ⇒ Object
Also known as:
get_items
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
|
#labels ⇒ Object
72
73
74
|
# File 'lib/glimmer/swt/custom/radio_group.rb', line 72
def labels
@labels ||= []
end
|
#observation_requests ⇒ Object
117
118
119
|
# File 'lib/glimmer/swt/custom/radio_group.rb', line 117
def observation_requests
@observation_requests ||= Set.new
end
|
#radios ⇒ Object
68
69
70
|
# File 'lib/glimmer/swt/custom/radio_group.rb', line 68
def radios
@radios ||= []
end
|
#selection ⇒ Object
54
55
56
57
|
# File 'lib/glimmer/swt/custom/radio_group.rb', line 54
def selection
selection_value = labels[selection_index]&.text unless selection_index == -1
selection_value.to_s
end
|
#selection=(text) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/glimmer/swt/custom/radio_group.rb', line 46
def selection=(text)
radios.count.times do |index|
radio = radios[index]
item = items[index]
radio.selection = item == text
end
end
|
#selection_index ⇒ Object
64
65
66
|
# File 'lib/glimmer/swt/custom/radio_group.rb', line 64
def selection_index
radios.index(radios.detect(&:selection)) || -1
end
|
#selection_index=(index) ⇒ Object
Also known as:
select
59
60
61
|
# File 'lib/glimmer/swt/custom/radio_group.rb', line 59
def selection_index=(index)
self.selection=(items[index])
end
|
#set_attribute(attribute_name, *args) ⇒ Object
128
129
130
131
132
133
134
135
136
|
# File 'lib/glimmer/swt/custom/radio_group.rb', line 128
def set_attribute(attribute_name, *args)
excluded_attributes = ['selection']
unless excluded_attributes.include?(attribute_name.to_s)
(@composites.to_a + @radios.to_a + @labels.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
|