Sha256: ffa385bb1f530c88ea73d3f76ad22e31fadcfac74ad7864c28e7c569834e8e5e

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

require File.dirname(__FILE__) + "/../../command_handler"
require File.dirname(__FILE__) + "/../g_widget"
require File.dirname(__FILE__) + "/../custom_widget"
require File.dirname(__FILE__) + "/../list_selection_binding"

module Glimmer
  module SWT
    module CommandHandlers
      class ListSelectionDataBindingCommandHandler
        include CommandHandler
        include Glimmer

        include_package 'org.eclipse.swt.widgets'

        def can_handle?(parent, command_symbol, *args, &block)
          (parent.is_a?(GWidget) || parent.is_a?(CustomWidget)) and
          parent.widget.is_a?(List) and
          command_symbol.to_s == "selection" and
          args.size == 1 and
          args[0].is_a?(ModelBinding) and
          args[0].evaluate_options_property.is_a?(Array) and
          block == nil
        end

        def do_handle(parent, command_symbol, *args, &block)
          model_binding = args[0]
          widget_binding = WidgetBinding.new(parent, "items")
          widget_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 handlers
          widget_binding.observe(model, model_binding.options_property_name)

          property_type = :string
          property_type = :array if parent.has_style?(:multi)
          list_selection_binding = 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)

          add_contents(parent) {
            on_widget_selected {
              model_binding.call(list_selection_binding.evaluate_property)
            }
          }
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
glimmer-0.4.9 lib/glimmer/swt/command_handlers/list_selection_data_binding_command_handler.rb
glimmer-0.4.8 lib/glimmer/swt/command_handlers/list_selection_data_binding_command_handler.rb
glimmer-0.4.7 lib/glimmer/swt/command_handlers/list_selection_data_binding_command_handler.rb