Class: Glimmer::DSL::SWT::ComboSelectionDataBindingExpression

Inherits:
Expression
  • Object
show all
Defined in:
lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb

Instance Method Summary collapse

Instance Method Details

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

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
# File 'lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb', line 34

def can_interpret?(parent, keyword, *args, &block)
  keyword == 'selection' and
    block.nil? and
    parent.respond_to?(:swt_widget) and
    (parent.swt_widget.is_a?(Combo) || parent.swt_widget.is_a?(CCombo)) 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



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb', line 44

def interpret(parent, keyword, *args, &block)
  model_binding = args[0]
  
  #TODO make this options observer dependent and all similar observers in widget specific data binding handlers
  # TODO consider delegating some of this work
  widget_binding = DataBinding::WidgetBinding.new(parent, 'items', sync_exec: model_binding.binding_options[:sync_exec], async_exec: model_binding.binding_options[:async_exec])
  widget_binding.call(model_binding.evaluate_options_property)
  widget_binding.observe(model_binding.model, model_binding.options_property_name)
  
  widget_binding = DataBinding::WidgetBinding.new(parent, 'text', sync_exec: model_binding.binding_options[:sync_exec], async_exec: model_binding.binding_options[:async_exec])
  widget_binding.call(model_binding.evaluate_property)
  widget_binding.observe(model_binding)
  
  Glimmer::SWT::DisplayProxy.instance.auto_exec(override_sync_exec: model_binding.binding_options[:sync_exec], override_async_exec: model_binding.binding_options[:async_exec]) do
    parent.on_widget_selected do
      model_binding.call(widget_binding.evaluate_property)
    end
    
    parent.on_modify_text do
      model_binding.call(widget_binding.evaluate_property)
    end
  end
end