Sha256: 43d3016df19ca75e2e1f30e3d2b7899405c94d8f65e38fcbfccf7e7e69d2565b

Contents?: true

Size: 1.34 KB

Versions: 8

Compression:

Stored size: 1.34 KB

Contents

require File.dirname(__FILE__) + "/observable_array"
require File.dirname(__FILE__) + "/observable_model"
require File.dirname(__FILE__) + "/observer"

class TableItemsBinding
  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
    model.extend(ObservableModel) unless model.is_a?(ObservableModel)
    model.add_observer(model_binding.property_name_expression, self)
  end
  def update(model_collection=nil)
    if model_collection and model_collection.is_a?(Array)
      model_collection.extend(ObservableArray) unless model_collection.is_a?(ObservableArray)
      model_collection.add_observer(@column_properties, self)
      @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

8 entries across 8 versions & 1 rubygems

Version Path
glimmer-0.2.5 lib/command_handlers/models/table_items_binding.rb
glimmer-0.2.4 lib/command_handlers/models/table_items_binding.rb
glimmer-0.2.3 lib/command_handlers/models/table_items_binding.rb
glimmer-0.2.2 lib/command_handlers/models/table_items_binding.rb
glimmer-0.2.1 lib/command_handlers/models/table_items_binding.rb
glimmer-0.2.0 lib/command_handlers/models/table_items_binding.rb
glimmer-0.1.11.SWT4.14 lib/command_handlers/models/table_items_binding.rb
glimmer-0.1.11.470 lib/command_handlers/models/table_items_binding.rb