Class: DataBindingCommandHandler
- Inherits:
-
Object
- Object
- DataBindingCommandHandler
- Extended by:
- Glimmer
- Includes:
- CommandHandler
- Defined in:
- lib/command_handlers/data_binding_command_handler.rb
Overview
Responsible for wiring two-way data-binding for text and selection properties on Text, Button, and Spinner widgets. Does so by using the output of the bind(model, property) command in the form of a ModelBinding, which is then connected to an anonymous widget observer (aka widget_data_binder as per widget_data_binders array)
Depends on BindCommandHandler
Constant Summary collapse
- @@widget_data_binders =
{ Java::OrgEclipseSwtWidgets::Text => { :text => Proc.new do |, model_binding| add_contents() { on_modify_text { |modify_event| model_binding.update(..getText) } } end, }, Java::OrgEclipseSwtWidgets::Button => { :selection => Proc.new do |, model_binding| add_contents() { { |selection_event| model_binding.update(..getSelection) } } end }, Java::OrgEclipseSwtWidgets::Spinner => { :selection => Proc.new do |, model_binding| add_contents() { { |selection_event| model_binding.update(..getSelection) } } end } }
Instance Method Summary collapse
- #can_handle?(parent, command_symbol, *args, &block) ⇒ Boolean
- #do_handle(parent, command_symbol, *args, &block) ⇒ Object
Methods included from Glimmer
add_contents, add_contents, dsl, dsl, extended, included, logger, method_missing, method_missing
Methods included from SwtPackages
Instance Method Details
#can_handle?(parent, command_symbol, *args, &block) ⇒ Boolean
50 51 52 53 54 |
# File 'lib/command_handlers/data_binding_command_handler.rb', line 50 def can_handle?(parent, command_symbol, *args, &block) (parent.is_a?(RWidget) and args.size == 1 and args[0].is_a?(ModelBinding)) end |
#do_handle(parent, command_symbol, *args, &block) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/command_handlers/data_binding_command_handler.rb', line 56 def do_handle(parent, command_symbol, *args, &block) model_binding = args[0] = [parent, command_symbol.to_s] = WidgetBinding.new(*) .update(model_binding.evaluate_property) .observe(model_binding) = @@widget_data_binders[parent..class] = [command_symbol.to_s.to_sym] if .call(parent, model_binding) if end |