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, internal_sort: false) ⇒ Object
-
#initialize(parent, model_binding, column_properties = nil) ⇒ TableItemsBinding
constructor
A new instance of TableItemsBinding.
- #populate_table(model_collection, parent, column_properties, internal_sort: false) ⇒ Object
Constructor Details
#initialize(parent, model_binding, column_properties = nil) ⇒ TableItemsBinding
Returns a new instance of TableItemsBinding.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/glimmer/data_binding/table_items_binding.rb', line 37 def initialize(parent, model_binding, column_properties = nil) @table = parent @model_binding = model_binding @read_only_sort = @model_binding.[:read_only_sort] @column_properties = @model_binding.[:column_properties] || @model_binding.[:column_attributes] || column_properties @table.editable = false if @model_binding.[:read_only] if @table.respond_to?(:column_properties=) @table.column_properties = @column_properties else # assume custom widget @table.body_root.column_properties = @column_properties end Glimmer::SWT::DisplayProxy.instance.auto_exec(override_sync_exec: @model_binding.[:sync_exec], override_async_exec: @model_binding.[:async_exec]) do @table..data = @model_binding @table..set_data('table_items_binding', self) @table. do |dispose_event| unregister_all_observables end @table_observer_registration = observe(model_binding) call end end |
Instance Method Details
#call(new_model_collection = nil, internal_sort: false) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/glimmer/data_binding/table_items_binding.rb', line 59 def call(new_model_collection=nil, internal_sort: false) Glimmer::SWT::DisplayProxy.instance.auto_exec(override_sync_exec: @model_binding.[:sync_exec], override_async_exec: @model_binding.[:async_exec]) do new_model_collection = model_binding_evaluated_property = @model_binding.evaluate_property unless internal_sort # 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, internal_sort: internal_sort) end end |
#populate_table(model_collection, parent, column_properties, internal_sort: false) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/glimmer/data_binding/table_items_binding.rb', line 75 def populate_table(model_collection, parent, column_properties, internal_sort: false) selected_table_item_models = parent..getSelection.map(&:get_data) 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.set_data(model) end selected_table_items = parent.search {|item| selected_table_item_models.include?(item.get_data) } parent..setSelection(selected_table_items) sorted_model_collection = parent.sort!(internal_sort: internal_sort) call(sorted_model_collection, internal_sort: true) if @read_only_sort && !internal_sort && !sorted_model_collection.nil? parent..redraw if parent&.&.respond_to?(:redraw) end |