class Glimmer::SWT::Custom::CheckboxGroup

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

Public Instance Methods

can_handle_observation_request?(observation_request) click to toggle source
# 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
checkboxes() click to toggle source
# File lib/glimmer/swt/custom/checkbox_group.rb, line 72
def checkboxes
  @checkboxes ||= []
end
Also aliased as: checks
checks()
Alias for: checkboxes
delegate_observation_request_to_checkboxes(observation_request, &block) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
items() click to toggle source
# File lib/glimmer/swt/custom/checkbox_group.rb, line 41
def items
  @items || []
end
items=(text_array) click to toggle source
# 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_requests() click to toggle source
# File lib/glimmer/swt/custom/checkbox_group.rb, line 96
def observation_requests
  @observation_requests ||= Set.new
end
select(indices)
Alias for: selection_indices=
selection() click to toggle source
# 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) click to toggle source
# 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_indices() click to toggle source
# 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) click to toggle source
# File lib/glimmer/swt/custom/checkbox_group.rb, line 61
def selection_indices=(indices)
  self.selection=(indices.to_a.map {|index| items[index]})
end
Also aliased as: select
set_attribute(attribute_name, *args) click to toggle source
Calls superclass method Glimmer::UI::CustomWidget#set_attribute
# 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

Private Instance Methods

build_checkboxes() click to toggle source
# File lib/glimmer/swt/custom/checkbox_group.rb, line 119
def build_checkboxes
  current_selection = selection
  @checkboxes = []
  items.each do |item|
    body_root.content {
      checkboxes << checkbox { |checkbox_proxy|
        text item
        on_widget_selected {
          self.selection_indices = checkboxes.each_with_index.map {|cb, i| i if cb.selection}.to_a.compact
        }
      }
    }
  end
  observation_requests.to_a.each do |observation_request, block|
    delegate_observation_request_to_checkboxes(observation_request, &block)
  end
  self.selection = current_selection
end