Sha256: 9c98cb3af6ff2dba5ccb0f6db6a9072be423b0fcfbfcd3adc8e98ec6cae7e4d7

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

require_relative 'observable_array'
require_relative 'observable_model'
require_relative 'observable'
require_relative 'observer'

class TableItemsBinding
  include Glimmer
  include Observable
  include Observer
  include_package 'org.eclipse.swt'
  include_package 'org.eclipse.swt.widgets'

  def initialize(parent, model_binding, column_properties)
    @table = parent
    @model_binding = model_binding
    @column_properties = column_properties
    update(@model_binding.evaluate_property)
    model = model_binding.base_model
    observe(model, model_binding.property_name_expression)
    add_contents(@table) {
      on_widget_disposed { |dispose_event|
        unregister_all_observables
      }
    }
  end
  def update(model_collection=nil)
    if model_collection and model_collection.is_a?(Array)
      observe(model_collection, @column_properties)
      @model_collection = model_collection
    end
    populate_table(@model_collection, @table, @column_properties)
  end
  def populate_table(model_collection, parent, column_properties)
    parent.widget.removeAll
    model_collection.each do |model|
      table_item = TableItem.new(parent.widget, SWT::NONE)
      for index in 0..(column_properties.size-1)
        table_item.setText(index, model.send(column_properties[index]).to_s)
      end
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
glimmer-0.3.4 lib/command_handlers/models/table_items_binding.rb
glimmer-0.3.3 lib/command_handlers/models/table_items_binding.rb
glimmer-0.3.2 lib/command_handlers/models/table_items_binding.rb