Class: Glimmer::SWT::TableProxy
Constant Summary
collapse
- STYLE =
<<~CSS
table {
border-spacing: 0;
}
table tr th,td {
cursor: default;
}
CSS
Constants inherited
from WidgetProxy
WidgetProxy::DEFAULT_INITIALIZERS
Instance Attribute Summary collapse
#layout
Attributes inherited from WidgetProxy
#args, #background, #children, #disposed?, #enabled, #focus, #font, #foreground, #menu, #menu_requested, #parent, #path, #rendered
Class Method Summary
collapse
Instance Method Summary
collapse
-
#add_listener(underscored_listener_name, &block) ⇒ Object
-
#cancel_edit! ⇒ Object
-
#cells_for(model) ⇒ Object
-
#column_sort_properties ⇒ Object
-
#columns_dom ⇒ Object
-
#columns_dom_element ⇒ Object
-
#columns_path ⇒ Object
-
#default_layout ⇒ Object
-
#detect_sort_type ⇒ Object
-
#dom ⇒ Object
-
#edit_in_progress? ⇒ Boolean
Indicates if table is editing a table item because the user hit ENTER or focused out after making a change in edit mode to a table item cell.
-
#edit_mode? ⇒ Boolean
Indicates if table is in edit mode, thus displaying a text widget for a table item cell.
-
#edit_selected_table_item(column_index, before_write: nil, after_write: nil, after_cancel: nil) ⇒ Object
-
#edit_table_item(table_item, column_index, before_write: nil, after_write: nil, after_cancel: nil) ⇒ Object
def edit_table_item(table_item, column_index) table_item&.edit(column_index) unless column_index.nil? end.
-
#editable? ⇒ Boolean
(also: #editable)
-
#element ⇒ Object
-
#finish_edit! ⇒ Object
-
#get_data(key = nil) ⇒ Object
-
#header_visible ⇒ Object
-
#header_visible=(value) ⇒ Object
-
#index_of(item) ⇒ Object
-
#initial_sort! ⇒ Object
-
#initialize(parent, args, block) ⇒ TableProxy
constructor
A new instance of TableProxy.
-
#items=(new_items) ⇒ Object
-
#items_dom ⇒ Object
-
#items_dom_element ⇒ Object
-
#items_path ⇒ Object
-
#observation_request_to_event_mapping ⇒ Object
-
#post_add_content ⇒ Object
-
#post_dispose_child(child) ⇒ Object
Executes for the parent of a child that just got disposed.
-
#post_initialize_child(child) ⇒ Object
Only table_columns may be added as children.
-
#redraw ⇒ Object
-
#redraw_empty_items ⇒ Object
-
#remove_all ⇒ Object
-
#search(&condition) ⇒ Object
-
#select(index, meta = false) ⇒ Object
-
#selector ⇒ Object
-
#show_item(table_item) ⇒ Object
-
#sort! ⇒ Object
-
#sort_by_column!(table_column_proxy = nil) ⇒ Object
Sorts by specified TableColumnProxy object.
-
#sort_direction ⇒ Object
-
#sort_direction=(value) ⇒ Object
-
#thead_dom ⇒ Object
-
#thead_dom_element ⇒ Object
Methods inherited from WidgetProxy
#add_content_on_render, #add_css_class, #add_css_classes, #add_observer, #apply_property_type_converters, #build_dom, #can_handle_observation_request?, #clear_css_classes, #content, #content_on_render_blocks, #css_classes, #default_observation_request_to_event_mapping, #dispose, #dom_element, #effective_observation_request_to_event_mapping, #event_listener_proxies, for, #handle_observation_request, #has_style?, #id, #id=, #layout, #listener_dom_element, #listener_path, max_id_number_for, max_id_numbers, #method_missing, #name, next_id_number_for, #observation_requests, #pack, #parent_dom_element, #parent_path, #remove_all_listeners, #remove_css_class, #remove_css_classes, #remove_event_listener_proxies, #render, reset_max_id_numbers!, #set_attribute, #set_data, #set_focus, #skip_content_on_render_blocks?, #style_element, #swt_widget, underscored_widget_name, widget_class, widget_exists?, #widget_property_listener_installers
#attribute_getter, #attribute_setter, #get_attribute, #set_attribute
Constructor Details
#initialize(parent, args, block) ⇒ TableProxy
Returns a new instance of TableProxy.
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
# File 'lib/glimmer/swt/table_proxy.rb', line 248
def initialize(parent, args, block)
super(parent, args, block)
@columns = []
@children = []
@editors = []
@selection = []
@table_editor = TableEditor.new(self)
@table_editor.horizontalAlignment = SWTProxy[:left]
@table_editor.grabHorizontal = true
@table_editor.minimumWidth = 90
@table_editor.minimumHeight = 20
if editable?
on_mouse_up { |event|
edit_table_item(event.table_item, event.column_index)
}
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Glimmer::SWT::WidgetProxy
Instance Attribute Details
#additional_sort_properties ⇒ Object
Returns the value of attribute additional_sort_properties.
40
41
42
|
# File 'lib/glimmer/swt/table_proxy.rb', line 40
def additional_sort_properties
@additional_sort_properties
end
|
#column_properties ⇒ Object
Returns the value of attribute column_properties.
43
44
45
|
# File 'lib/glimmer/swt/table_proxy.rb', line 43
def column_properties
@column_properties
end
|
#columns ⇒ Object
Returns the value of attribute columns.
40
41
42
|
# File 'lib/glimmer/swt/table_proxy.rb', line 40
def columns
@columns
end
|
#data ⇒ Object
Also known as:
model_binding
Returns the value of attribute data.
43
44
45
|
# File 'lib/glimmer/swt/table_proxy.rb', line 43
def data
@data
end
|
#editor ⇒ Object
Returns the value of attribute editor.
40
41
42
|
# File 'lib/glimmer/swt/table_proxy.rb', line 40
def editor
@editor
end
|
#item_count ⇒ Object
Returns the value of attribute item_count.
43
44
45
|
# File 'lib/glimmer/swt/table_proxy.rb', line 43
def item_count
@item_count
end
|
#selection ⇒ Object
Returns the value of attribute selection.
40
41
42
|
# File 'lib/glimmer/swt/table_proxy.rb', line 40
def selection
@selection
end
|
#sort_block ⇒ Object
Returns the value of attribute sort_block.
40
41
42
|
# File 'lib/glimmer/swt/table_proxy.rb', line 40
def sort_block
@sort_block
end
|
#sort_by_block ⇒ Object
Returns the value of attribute sort_by_block.
40
41
42
|
# File 'lib/glimmer/swt/table_proxy.rb', line 40
def sort_by_block
@sort_by_block
end
|
#sort_column ⇒ Object
Returns the value of attribute sort_column.
40
41
42
|
# File 'lib/glimmer/swt/table_proxy.rb', line 40
def sort_column
@sort_column
end
|
#sort_property ⇒ Object
Returns the value of attribute sort_property.
40
41
42
|
# File 'lib/glimmer/swt/table_proxy.rb', line 40
def sort_property
@sort_property
end
|
#sort_type ⇒ Object
Returns the value of attribute sort_type.
40
41
42
|
# File 'lib/glimmer/swt/table_proxy.rb', line 40
def sort_type
@sort_type
end
|
#table_editor ⇒ Object
Returns the value of attribute table_editor.
40
41
42
|
# File 'lib/glimmer/swt/table_proxy.rb', line 40
def table_editor
@table_editor
end
|
Class Method Details
.editors ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
# File 'lib/glimmer/swt/table_proxy.rb', line 50
def editors
@editors ||= {
text: {
widget_value_property: :text,
editor_gui: lambda do |args, model, property, table_proxy|
table_proxy.table_editor.minimumWidth = 90
table_proxy.table_editor.minimumHeight = 10
table_editor_widget_proxy = text(*args) {
text model.send(property)
focus true
on_focus_lost {
table_proxy.finish_edit!
}
on_key_pressed { |key_event|
if key_event.keyCode == swt(:cr)
table_proxy.finish_edit!
elsif key_event.keyCode == swt(:esc)
table_proxy.cancel_edit!
end
}
}
table_editor_widget_proxy
end,
},
combo: {
widget_value_property: :text,
editor_gui: lambda do |args, model, property, table_proxy|
first_time = true
table_proxy.table_editor.minimumWidth = 90
table_proxy.table_editor.minimumHeight = 18
table_editor_widget_proxy = combo(*args) {
items model.send("#{property}_options")
text model.send(property)
focus true
on_focus_lost {
table_proxy.finish_edit!
}
on_key_pressed { |key_event|
if key_event.keyCode == swt(:cr)
table_proxy.finish_edit!
elsif key_event.keyCode == swt(:esc)
table_proxy.cancel_edit!
end
}
on_widget_selected {
if !OS.windows? || !first_time || first_time && model.send(property) != table_editor_widget_proxy.text
table_proxy.finish_edit!
end
}
}
table_editor_widget_proxy
end,
},
checkbox: {
widget_value_property: :selection,
editor_gui: lambda do |args, model, property, table_proxy|
first_time = true
table_proxy.table_editor.minimumHeight = 25
checkbox(*args) {
selection model.send(property)
focus true
on_widget_selected {
table_proxy.finish_edit!
}
on_focus_lost {
table_proxy.finish_edit!
}
on_key_pressed { |key_event|
if key_event.keyCode == swt(:cr)
table_proxy.finish_edit!
elsif key_event.keyCode == swt(:esc)
table_proxy.cancel_edit!
end
}
}
end,
},
date: {
widget_value_property: :date_time,
editor_gui: lambda do |args, model, property, table_proxy|
first_time = true
table_proxy.table_editor.minimumWidth = 90
table_proxy.table_editor.minimumHeight = 15
date(*args) {
date_time model.send(property)
focus true
on_widget_selected {
table_proxy.finish_edit!
}
on_key_pressed { |key_event|
if key_event.keyCode == swt(:cr)
table_proxy.finish_edit!
elsif key_event.keyCode == swt(:esc)
table_proxy.cancel_edit!
end
}
}
end,
},
date_drop_down: {
widget_value_property: :date_time,
editor_gui: lambda do |args, model, property, table_proxy|
first_time = true
table_proxy.table_editor.minimumWidth = 80
table_proxy.table_editor.minimumHeight = 15
date_drop_down(*args) {
date_time model.send(property)
focus true
on_widget_selected {
table_proxy.finish_edit!
}
on_key_pressed { |key_event|
if key_event.keyCode == swt(:cr)
table_proxy.finish_edit!
elsif key_event.keyCode == swt(:esc)
table_proxy.cancel_edit!
end
}
}
end,
},
time: {
widget_value_property: :date_time,
editor_gui: lambda do |args, model, property, table_proxy|
first_time = true
table_proxy.table_editor.minimumWidth = 80
table_proxy.table_editor.minimumHeight = 15
time(*args) {
date_time model.send(property)
focus true
on_widget_selected {
table_proxy.finish_edit!
}
on_focus_lost {
table_proxy.finish_edit!
}
on_key_pressed { |key_event|
if key_event.keyCode == swt(:cr)
table_proxy.finish_edit!
elsif key_event.keyCode == swt(:esc)
table_proxy.cancel_edit!
end
}
}
end,
},
radio: {
widget_value_property: :selection,
editor_gui: lambda do |args, model, property, table_proxy|
first_time = true
table_proxy.table_editor.minimumHeight = 25
radio(*args) {
selection model.send(property)
focus true
on_widget_selected {
table_proxy.finish_edit!
}
on_focus_lost {
table_proxy.finish_edit!
}
on_key_pressed { |key_event|
if key_event.keyCode == swt(:cr)
table_proxy.finish_edit!
elsif key_event.keyCode == swt(:esc)
table_proxy.cancel_edit!
end
}
}
end,
},
spinner: {
widget_value_property: :selection,
editor_gui: lambda do |args, model, property, table_proxy|
first_time = true
table_proxy.table_editor.minimumHeight = 25
table_editor_widget_proxy = spinner(*args) {
selection model.send(property)
focus true
on_focus_lost {
table_proxy.finish_edit!
}
on_key_pressed { |key_event|
if key_event.keyCode == swt(:cr)
table_proxy.finish_edit!
elsif key_event.keyCode == swt(:esc)
table_proxy.cancel_edit!
end
}
}
table_editor_widget_proxy
end,
},
}
end
|
Instance Method Details
#add_listener(underscored_listener_name, &block) ⇒ Object
586
587
588
589
590
591
592
|
# File 'lib/glimmer/swt/table_proxy.rb', line 586
def add_listener(underscored_listener_name, &block)
enhanced_block = lambda do |event|
event.extend(TableListenerEvent)
block.call(event)
end
super(underscored_listener_name, &enhanced_block)
end
|
#cancel_edit! ⇒ Object
491
492
493
|
# File 'lib/glimmer/swt/table_proxy.rb', line 491
def cancel_edit!
@cancel_edit&.call if @edit_mode
end
|
#cells_for(model) ⇒ Object
336
337
338
|
# File 'lib/glimmer/swt/table_proxy.rb', line 336
def cells_for(model)
column_properties.map {|property| model.send(property)}
end
|
#column_sort_properties ⇒ Object
388
389
390
391
392
|
# File 'lib/glimmer/swt/table_proxy.rb', line 388
def column_sort_properties
column_properties.zip(columns.map(&:sort_property)).map do |pair|
pair.compact.last.to_collection
end
end
|
#columns_dom ⇒ Object
683
684
685
686
|
# File 'lib/glimmer/swt/table_proxy.rb', line 683
def columns_dom
tr {
}
end
|
#columns_dom_element ⇒ Object
671
672
673
|
# File 'lib/glimmer/swt/table_proxy.rb', line 671
def columns_dom_element
Document.find(columns_path)
end
|
#columns_path ⇒ Object
667
668
669
|
# File 'lib/glimmer/swt/table_proxy.rb', line 667
def columns_path
path + ' thead tr'
end
|
#default_layout ⇒ Object
296
297
298
|
# File 'lib/glimmer/swt/table_proxy.rb', line 296
def default_layout
nil
end
|
#detect_sort_type ⇒ Object
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
# File 'lib/glimmer/swt/table_proxy.rb', line 372
def detect_sort_type
@sort_type = sort_property.size.times.map { String }
array = model_binding.evaluate_property
sort_property.each_with_index do |a_sort_property, i|
values = array.map { |object| object.send(a_sort_property) }
value_classes = values.map(&:class).uniq
if value_classes.size == 1
@sort_type[i] = value_classes.first
elsif value_classes.include?(Integer)
@sort_type[i] = Integer
elsif value_classes.include?(Float)
@sort_type[i] = Float
end
end
end
|
#dom ⇒ Object
703
704
705
706
707
708
709
710
711
712
713
714
715
716
|
# File 'lib/glimmer/swt/table_proxy.rb', line 703
def dom
table_id = id
table_id_style = css
table_id_css_classes = css_classes
table_id_css_classes << 'table' unless table_id_css_classes.include?('table')
table_id_css_classes << 'editable' if editable? && !table_id_css_classes.include?('editable')
table_id_css_classes_string = table_id_css_classes.to_a.join(' ')
@dom ||= html {
table(id: table_id, style: table_id_style, class: table_id_css_classes_string) {
thead_dom
items_dom
}
}.to_s
end
|
#edit_in_progress? ⇒ Boolean
Indicates if table is editing a table item because the user hit ENTER or focused out after making a change in edit mode to a table item cell. It is set to false once change is saved to model
501
502
503
|
# File 'lib/glimmer/swt/table_proxy.rb', line 501
def edit_in_progress?
!!@edit_in_progress
end
|
#edit_mode? ⇒ Boolean
Indicates if table is in edit mode, thus displaying a text widget for a table item cell
487
488
489
|
# File 'lib/glimmer/swt/table_proxy.rb', line 487
def edit_mode?
!!@edit_mode
end
|
#edit_selected_table_item(column_index, before_write: nil, after_write: nil, after_cancel: nil) ⇒ Object
505
506
507
|
# File 'lib/glimmer/swt/table_proxy.rb', line 505
def edit_selected_table_item(column_index, before_write: nil, after_write: nil, after_cancel: nil)
edit_table_item(selection.first, column_index, before_write: before_write, after_write: after_write, after_cancel: after_cancel)
end
|
#edit_table_item(table_item, column_index, before_write: nil, after_write: nil, after_cancel: nil) ⇒ Object
def edit_table_item(table_item, column_index)
table_item&.edit(column_index) unless column_index.nil?
end
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
|
# File 'lib/glimmer/swt/table_proxy.rb', line 514
def edit_table_item(table_item, column_index, before_write: nil, after_write: nil, after_cancel: nil)
return if table_item.nil? || (@edit_mode && @edit_table_item == table_item && @edit_column_index == column_index)
@edit_column_index = column_index
@edit_table_item = table_item
column_index = column_index.to_i
model = table_item.data
property = column_properties[column_index]
cancel_edit!
return unless columns[column_index].editable?
action_taken = false
@edit_mode = true
editor_config = columns[column_index].editor || editor
editor_config = editor_config.to_collection
editor_widget_options = editor_config.last.is_a?(Hash) ? editor_config.last : {}
editor_widget_arg_last_index = editor_config.last.is_a?(Hash) ? -2 : -1
editor_widget = (editor_config[0] || :text).to_sym
editor_widget_args = editor_config[1..editor_widget_arg_last_index]
model_editing_property = editor_widget_options[:property] || property
widget_value_property = TableProxy::editors.symbolize_keys[editor_widget][:widget_value_property]
@cancel_edit = lambda do |event=nil|
@cancel_in_progress = true
@table_editor.cancel!
@table_editor_widget_proxy&.dispose
@table_editor_widget_proxy = nil
after_cancel&.call
@edit_in_progress = false
@cancel_in_progress = false
@cancel_edit = nil
@edit_table_item = @edit_column_index = nil if (@edit_mode && @edit_table_item == table_item && @edit_column_index == column_index)
@edit_mode = false
end
@finish_edit = lambda do |event=nil|
new_value = @table_editor_widget_proxy&.send(widget_value_property)
if table_item.disposed?
@cancel_edit.call
elsif !new_value.nil? && !action_taken && !@edit_in_progress && !@cancel_in_progress
action_taken = true
@edit_in_progress = true
if new_value == model.send(model_editing_property)
@cancel_edit.call
else
before_write&.call
@table_editor.save!(widget_value_property: widget_value_property)
model.send("#{model_editing_property}=", new_value) edited_table_item = search { |ti| ti.data == model }.first
show_item(edited_table_item)
@table_editor_widget_proxy&.dispose
@table_editor_widget_proxy = nil
after_write&.call(edited_table_item)
@edit_in_progress = false
@edit_table_item = @edit_column_index = nil
end
end
end
content {
@table_editor_widget_proxy = TableProxy::editors.symbolize_keys[editor_widget][:editor_gui].call(editor_widget_args, model, model_editing_property, self)
}
@table_editor.set_editor(@table_editor_widget_proxy, table_item, column_index)
rescue => e
Glimmer::Config.logger.error {e.full_message}
raise e
end
|
#editable? ⇒ Boolean
Also known as:
editable
309
310
311
|
# File 'lib/glimmer/swt/table_proxy.rb', line 309
def editable?
args.include?(:editable)
end
|
#element ⇒ Object
663
664
665
|
# File 'lib/glimmer/swt/table_proxy.rb', line 663
def element
'table'
end
|
#finish_edit! ⇒ Object
495
496
497
|
# File 'lib/glimmer/swt/table_proxy.rb', line 495
def finish_edit!
@finish_edit&.call if @edit_mode
end
|
#get_data(key = nil) ⇒ Object
300
301
302
|
# File 'lib/glimmer/swt/table_proxy.rb', line 300
def get_data(key=nil)
data
end
|
604
605
606
|
# File 'lib/glimmer/swt/table_proxy.rb', line 604
def
@header_visible
end
|
595
596
597
598
599
600
601
602
|
# File 'lib/glimmer/swt/table_proxy.rb', line 595
def (value)
@header_visible = value
if @header_visible
thead_dom_element.remove_class('hide')
else
thead_dom_element.add_class('hide')
end
end
|
#index_of(item) ⇒ Object
344
345
346
|
# File 'lib/glimmer/swt/table_proxy.rb', line 344
def index_of(item)
items.index(item)
end
|
#initial_sort! ⇒ Object
445
446
447
|
# File 'lib/glimmer/swt/table_proxy.rb', line 445
def initial_sort!
sort_by_column!
end
|
#items=(new_items) ⇒ Object
325
326
327
328
329
|
# File 'lib/glimmer/swt/table_proxy.rb', line 325
def items=(new_items)
@children = new_items
redraw
end
|
#items_dom ⇒ Object
698
699
700
701
|
# File 'lib/glimmer/swt/table_proxy.rb', line 698
def items_dom
tbody {
}
end
|
#items_dom_element ⇒ Object
679
680
681
|
# File 'lib/glimmer/swt/table_proxy.rb', line 679
def items_dom_element
Document.find(items_path)
end
|
#items_path ⇒ Object
675
676
677
|
# File 'lib/glimmer/swt/table_proxy.rb', line 675
def items_path
path + ' tbody'
end
|
#observation_request_to_event_mapping ⇒ Object
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
|
# File 'lib/glimmer/swt/table_proxy.rb', line 612
def observation_request_to_event_mapping
mouse_handler = -> (event_listener) {
-> (event) {
event.singleton_class.send(:define_method, :table_item=) do |item|
@table_item = item
end
event.singleton_class.send(:define_method, :table_item) do
@table_item
end
table_row = event.target.parents('tr').first
table_data = event.target.parents('td').first
event.table_item = items.detect {|item| item.id == table_row.attr('id')}
event.singleton_class.send(:define_method, :column_index) do
(table_data || event.target).attr('data-column-index')
end
event_listener.call(event) unless event.table_item.nil? && event.column_index.nil?
}
}
{
'on_mouse_down' => {
event: 'mousedown',
event_handler: mouse_handler,
},
'on_mouse_up' => {
event: 'mouseup',
event_handler: mouse_handler,
},
'on_widget_selected' => {
event: 'mouseup',
event_handler: mouse_handler,
},
}
end
|
#post_add_content ⇒ Object
290
291
292
293
294
|
# File 'lib/glimmer/swt/table_proxy.rb', line 290
def post_add_content
return if @initially_sorted
initial_sort!
@initially_sorted = true
end
|
#post_dispose_child(child) ⇒ Object
Executes for the parent of a child that just got disposed
280
281
282
283
284
285
286
287
288
|
# File 'lib/glimmer/swt/table_proxy.rb', line 280
def post_dispose_child(child)
if child.is_a?(TableColumnProxy)
@columns&.delete(child)
elsif child.is_a?(TableItemProxy)
@children&.delete(child)
else
@editors&.delete(child)
end
end
|
#post_initialize_child(child) ⇒ Object
Only table_columns may be added as children
267
268
269
270
271
272
273
274
275
276
277
|
# File 'lib/glimmer/swt/table_proxy.rb', line 267
def post_initialize_child(child)
if child.is_a?(TableColumnProxy)
@columns << child
child.render
elsif child.is_a?(TableItemProxy)
@children << child
child.render
else
@editors << child
end
end
|
#redraw ⇒ Object
648
649
650
651
652
|
# File 'lib/glimmer/swt/table_proxy.rb', line 648
def redraw
super()
@columns.to_a.each(&:redraw)
redraw_empty_items
end
|
#redraw_empty_items ⇒ Object
654
655
656
657
658
659
660
661
|
# File 'lib/glimmer/swt/table_proxy.rb', line 654
def redraw_empty_items
if @children&.size.to_i < item_count.to_i
item_count.to_i.times do
empty_columns = column_properties&.size.to_i.times.map { |i| "<td data-column-index='#{i}'></td>" }
items_dom_element.append("<tr class='table-item empty-table-item'>#{empty_columns}</tr>")
end
end
end
|
#remove_all ⇒ Object
304
305
306
307
|
# File 'lib/glimmer/swt/table_proxy.rb', line 304
def remove_all
items.clear
redraw
end
|
#search(&condition) ⇒ Object
340
341
342
|
# File 'lib/glimmer/swt/table_proxy.rb', line 340
def search(&condition)
items.select {|item| condition.nil? || condition.call(item)}
end
|
#select(index, meta = false) ⇒ Object
348
349
350
351
352
353
354
355
356
357
358
|
# File 'lib/glimmer/swt/table_proxy.rb', line 348
def select(index, meta = false)
new_selection = @selection.clone
selected_item = items[index]
if @selection.include?(selected_item)
new_selection.delete(selected_item) if meta
else
new_selection = [] if !meta || (!has_style?(:multi) && @selection.to_a.size >= 1)
new_selection << selected_item
end
self.selection = new_selection
end
|
#selector ⇒ Object
608
609
610
|
# File 'lib/glimmer/swt/table_proxy.rb', line 608
def selector
super + ' tbody'
end
|
#show_item(table_item) ⇒ Object
582
583
584
|
# File 'lib/glimmer/swt/table_proxy.rb', line 582
def show_item(table_item)
table_item.dom_element.focus
end
|
#sort! ⇒ Object
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
|
# File 'lib/glimmer/swt/table_proxy.rb', line 449
def sort!
return unless sort_property && (sort_type || sort_block || sort_by_block)
array = model_binding.evaluate_property
array = array.sort_by(&:hash) if sort_block
sorted_array = array.sort(&sort_block)
elsif sort_by_block
sorted_array = array.sort_by(&sort_by_block)
else
sorted_array = array.sort_by do |object|
sort_property.each_with_index.map do |a_sort_property, i|
value = object.send(a_sort_property)
if sort_type[i] == Integer
value = value.to_i
elsif sort_type[i] == Float
value = value.to_f
elsif sort_type[i] == String
value = value.to_s
end
value
end
end
end
sorted_array = sorted_array.reverse if @sort_direction == :descending
model_binding.call(sorted_array)
end
|
#sort_by_column!(table_column_proxy = nil) ⇒ Object
Sorts by specified TableColumnProxy object. If nil, it uses the table default sort instead.
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
|
# File 'lib/glimmer/swt/table_proxy.rb', line 403
def sort_by_column!(table_column_proxy=nil)
index = columns.to_a.index(table_column_proxy) unless table_column_proxy.nil?
new_sort_property = table_column_proxy.nil? ? @sort_property : table_column_proxy.sort_property || [column_properties[index]]
return if table_column_proxy.nil? && new_sort_property.nil? && @sort_block.nil? && @sort_by_block.nil?
if new_sort_property && table_column_proxy.nil? && new_sort_property.size == 1 && (index = column_sort_properties.index(new_sort_property))
table_column_proxy = columns[index]
end
if new_sort_property && new_sort_property.size == 1 && !additional_sort_properties.to_a.empty?
selected_additional_sort_properties = additional_sort_properties.clone
if selected_additional_sort_properties.include?(new_sort_property.first)
selected_additional_sort_properties.delete(new_sort_property.first)
new_sort_property += selected_additional_sort_properties
else
new_sort_property += additional_sort_properties
end
end
new_sort_property = new_sort_property.to_collection unless new_sort_property.is_a?(Array)
@sort_direction = @sort_direction.nil? || @sort_property.first != new_sort_property.first || @sort_direction == :descending ? :ascending : :descending
@sort_property = new_sort_property
table_column_index = column_properties.index(new_sort_property.to_s.to_sym)
table_column_proxy ||= columns[table_column_index] if table_column_index
@sort_column = table_column_proxy if table_column_proxy
if table_column_proxy
@sort_by_block = nil
@sort_block = nil
end
@sort_type = nil
if table_column_proxy&.sort_by_block
@sort_by_block = table_column_proxy.sort_by_block
elsif table_column_proxy&.sort_block
@sort_block = table_column_proxy.sort_block
else
detect_sort_type
end
sort!
end
|
#sort_direction ⇒ Object
394
395
396
|
# File 'lib/glimmer/swt/table_proxy.rb', line 394
def sort_direction
@sort_direction == :ascending ? SWTProxy[:up] : SWTProxy[:down]
end
|
#sort_direction=(value) ⇒ Object
398
399
400
|
# File 'lib/glimmer/swt/table_proxy.rb', line 398
def sort_direction=(value)
@sort_direction = value == SWTProxy[:up] ? :ascending : :descending
end
|
#thead_dom ⇒ Object
688
689
690
691
692
|
# File 'lib/glimmer/swt/table_proxy.rb', line 688
def thead_dom
thead {
columns_dom
}
end
|
#thead_dom_element ⇒ Object
694
695
696
|
# File 'lib/glimmer/swt/table_proxy.rb', line 694
def thead_dom_element
dom_element.find('thead')
end
|