Class: Glimmer::SWT::Custom::CheckboxGroup

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

Overview

A custom widget rendering a group of checkboxes 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)


77
78
79
# File 'lib/glimmer/swt/custom/checkbox_group.rb', line 77

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

#checkboxesObject Also known as: checks



72
73
74
# File 'lib/glimmer/swt/custom/checkbox_group.rb', line 72

def checkboxes
  @checkboxes ||= []
end

#delegate_observation_request_to_checkboxes(observation_request, &block) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/glimmer/swt/custom/checkbox_group.rb', line 87

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

#handle_observation_request(observation_request, block) ⇒ Object



81
82
83
84
85
# File 'lib/glimmer/swt/custom/checkbox_group.rb', line 81

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

#has_attribute?(attribute_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
103
104
105
# File 'lib/glimmer/swt/custom/checkbox_group.rb', line 100

def has_attribute?(attribute_name, *args)
  @checkboxes.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/checkbox_group.rb', line 41

def items
  @items || []
end

#items=(text_array) ⇒ Object



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

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

#observation_requestsObject



96
97
98
# File 'lib/glimmer/swt/custom/checkbox_group.rb', line 96

def observation_requests
  @observation_requests ||= Set.new
end

#selectionObject



55
56
57
58
59
# File 'lib/glimmer/swt/custom/checkbox_group.rb', line 55

def selection
  selection_indices.map do |selection_index|
    checkboxes[selection_index]&.text
  end
end

#selection=(selection_texts) ⇒ Object



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

def selection=(selection_texts)
  items.count.times do |index|
    checkbox = checkboxes[index]
    item = items[index]
    checkbox_text = checkbox&.text
    checkbox.selection = selection_texts.to_a.include?(checkbox_text)
  end
  selection_texts
end

#selection_indicesObject



66
67
68
69
70
# File 'lib/glimmer/swt/custom/checkbox_group.rb', line 66

def selection_indices
  checkboxes.each_with_index.map do |checkbox, index|
    index if checkbox.selection
  end.to_a.compact
end

#selection_indices=(indices) ⇒ Object Also known as: select



61
62
63
# File 'lib/glimmer/swt/custom/checkbox_group.rb', line 61

def selection_indices=(indices)
  self.selection=(indices.to_a.map {|index| items[index]})
end

#set_attribute(attribute_name, *args) ⇒ Object



107
108
109
110
111
112
113
114
115
# File 'lib/glimmer/swt/custom/checkbox_group.rb', line 107

def set_attribute(attribute_name, *args)
  excluded_attributes = ['selection']
  unless excluded_attributes.include?(attribute_name.to_s)
    @checkboxes.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