Sha256: 361aa2d0a0df4552e585747d81a4b4cf45bbe797089a940702a36435ceaf13f2

Contents?: true

Size: 1.43 KB

Versions: 43

Compression:

Stored size: 1.43 KB

Contents

require 'glimmer/dsl/expression'
require 'glimmer/data_binding/model_binding'
require 'glimmer/data_binding/widget_binding'

module Glimmer
  module DSL
    module SWT
      # 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
      class DataBindingExpression < Expression
        def can_interpret?(parent, keyword, *args, &block)
          args.size == 1 and
            args[0].is_a?(DataBinding::ModelBinding)
        end
  
        def interpret(parent, keyword, *args, &block)
          model_binding = args[0]
          widget_binding_parameters = [parent, keyword]
          widget_binding = DataBinding::WidgetBinding.new(*widget_binding_parameters)
          widget_binding.call(model_binding.evaluate_property)
          #TODO make this options observer dependent and all similar observers in widget specific data binding handlers
          widget_binding.observe(model_binding)
          # TODO simplify this logic and put it where it belongs
          parent.add_observer(model_binding, keyword) if parent.respond_to?(:add_observer, [model_binding, keyword])
        end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 2 rubygems

Version Path
glimmer-dsl-swt-0.3.0 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-dsl-swt-0.2.4 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-dsl-swt-0.2.3 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-dsl-swt-0.2.2 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-dsl-swt-0.2.1 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-dsl-swt-0.2.0 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-dsl-swt-0.1.3 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-dsl-swt-0.1.2 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-dsl-swt-0.1.1 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-dsl-swt-0.1.0 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-0.8.2 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-0.8.1 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-0.8.0 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-0.7.8 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-0.7.7 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-0.7.6 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-0.7.5 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-0.7.4 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-0.7.3 lib/glimmer/dsl/swt/data_binding_expression.rb
glimmer-0.7.2 lib/glimmer/dsl/swt/data_binding_expression.rb