Class: Glimmer::DataBinding::TableItemsBinding
- Inherits:
-
Object
- Object
- Glimmer::DataBinding::TableItemsBinding
- Includes:
- DataBinding::Observable, DataBinding::Observer
- Defined in:
- lib/glimmer/data_binding/table_items_binding.rb
Instance Method Summary collapse
- #call(new_model_collection = nil) ⇒ Object
-
#initialize(parent, model_binding, column_properties) ⇒ TableItemsBinding
constructor
A new instance of TableItemsBinding.
- #populate_table(model_collection, parent, column_properties) ⇒ Object
Constructor Details
#initialize(parent, model_binding, column_properties) ⇒ TableItemsBinding
Returns a new instance of TableItemsBinding.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/glimmer/data_binding/table_items_binding.rb', line 36 def initialize(parent, model_binding, column_properties) @table = parent @model_binding = model_binding @table..data = @model_binding @column_properties = column_properties if @table.respond_to?(:column_properties=) @table.column_properties = @column_properties else # assume custom widget @table.body_root.column_properties = @column_properties end call(@model_binding.evaluate_property) @table_observer_registration = observe(model_binding) @table. do |dispose_event| unregister_all_observables end end |
Instance Method Details
#call(new_model_collection = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/glimmer/data_binding/table_items_binding.rb', line 53 def call(new_model_collection=nil) new_model_collection = @model_binding.evaluate_property # this ensures applying converters (e.g. :on_read) table_cells = @table..items.map {|item| @table.column_properties.size.times.map {|i| item.get_text(i)} } model_cells = new_model_collection.to_a.map {|m| @table.cells_for(m)} return if table_cells == model_cells if new_model_collection and new_model_collection.is_a?(Array) @table_items_observer_registration&.unobserve @table_items_observer_registration = observe(new_model_collection, @column_properties) add_dependent(@table_observer_registration => @table_items_observer_registration) @model_collection = new_model_collection end populate_table(@model_collection, @table, @column_properties) end |
#populate_table(model_collection, parent, column_properties) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/glimmer/data_binding/table_items_binding.rb', line 67 def populate_table(model_collection, parent, column_properties) selected_table_item_models = parent..getSelection.map(&:getData) parent.finish_edit! parent..items.each(&:dispose) parent..removeAll model_collection.each do |model| table_item = TableItem.new(parent., SWT::SWTProxy[:none]) for index in 0..(column_properties.size-1) table_item.setText(index, model.send(column_properties[index]).to_s) end table_item.setData(model) end selected_table_items = parent.search {|item| selected_table_item_models.include?(item.getData) } selected_table_items = [parent..getItems.first].to_java(TableItem) if selected_table_items.empty? && !parent..getItems.empty? parent..setSelection(selected_table_items) unless selected_table_items.empty? parent.sort parent..redraw if parent&.&.respond_to?(:redraw) end |