Class: Glimmer::DSL::Opal::ListSelectionDataBindingExpression

Inherits:
Expression
  • Object
show all
Defined in:
lib/glimmer/dsl/opal/list_selection_data_binding_expression.rb

Instance Method Summary collapse

Instance Method Details

#can_interpret?(parent, keyword, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
# File 'lib/glimmer/dsl/opal/list_selection_data_binding_expression.rb', line 11

def can_interpret?(parent, keyword, *args, &block)
  keyword == 'selection' and
    block.nil? and
    parent.is_a?(Glimmer::SWT::ListProxy) and
    args.size == 1 and
    args[0].is_a?(DataBinding::ModelBinding) and
    args[0].evaluate_options_property.is_a?(Array)
end

#interpret(parent, keyword, *args, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/glimmer/dsl/opal/list_selection_data_binding_expression.rb', line 20

def interpret(parent, keyword, *args, &block)
  model_binding = args[0]
  element_binding = DataBinding::ElementBinding.new(parent, 'items')
  element_binding.call(model_binding.evaluate_options_property)
  model = model_binding.base_model
  #TODO make this options observer dependent and all similar observers in widget specific data binding interpretrs
  element_binding.observe(model, model_binding.options_property_name)
  
  property_type = :string
  property_type = :array if parent.has_style?(:multi)
  list_selection_binding = DataBinding::ListSelectionBinding.new(parent, property_type)
  list_selection_binding.call(model_binding.evaluate_property)
  #TODO check if nested data binding works for list widget and other widgets that need custom data binding
  list_selection_binding.observe(model, model_binding.property_name_expression)
  parent.on_widget_selected do
    model_binding.call(list_selection_binding.evaluate_property)
  end
end