Class: Glimmer::SWT::TableItemProxy
Constant Summary
collapse
- STYLE =
<<~CSS
tr.table-item td {
padding-bottom: 0;
}
tr.table-item:nth-child(odd):not(.selected) {
background: white;
}
tr.table-item:nth-child(even):not(.selected) {
background: rgb(243, 244, 246);
}
CSS
Constants inherited
from WidgetProxy
WidgetProxy::DEFAULT_INITIALIZERS, WidgetProxy::JS_KEY_CODE_TO_SWT_KEY_CODE_MAP, WidgetProxy::JS_LOCATION_TO_SWT_KEY_LOCATION_MAP, WidgetProxy::SWT_CURSOR_TO_CSS_CURSOR_MAP
Instance Attribute Summary collapse
Attributes inherited from WidgetProxy
#args, #background, #children, #cursor, #disposed?, #enabled, #focus, #font, #foreground, #menu, #menu_requested, #menu_x, #menu_y, #parent, #path, #rendered
Instance Method Summary
collapse
Methods inherited from WidgetProxy
#add_content_on_render, #add_css_class, #add_css_classes, #add_observer, #apply_property_type_converters, #attach, #build_dom, #can_handle_observation_request?, #clear_css_classes, #content, #content_on_render_blocks, #css_classes, #default_observation_request_to_event_mapping, #dialog_ancestor, #dispose, #dom_element, #effective_observation_request_to_event_mapping, #event_handling_suspended?, #event_listener_proxies, for, #get_data, #handle_javascript_observation_request, #handle_observation_request, #has_style?, #id, #id=, #listener_dom_element, #listener_path, #listeners, #listeners_for, max_id_number_for, max_id_numbers, #method_missing, #name, next_id_number_for, #observation_requests, #parent_dom_element, #parents, #post_add_content, #post_dispose_child, #post_initialize_child, #print, #property_type_converters, #reattach, #remove_all_listeners, #remove_css_class, #remove_css_classes, #remove_event_listener_proxies, #render, reset_max_id_numbers!, #resume_event_handling, #selector, #set_attribute, #set_data, #set_focus, #shell, #skip_content_on_render_blocks?, #style_element, #suspend_event_handling, #swt_data, #swt_widget, underscored_widget_name, widget_class, widget_exists?, widget_handling_listener, #widget_property_listener_installers
#attribute_getter, #attribute_setter, #get_attribute, #set_attribute
Constructor Details
#initialize(parent, args, block) ⇒ TableItemProxy
Returns a new instance of TableItemProxy.
41
42
43
44
45
46
47
|
# File 'lib/glimmer/swt/table_item_proxy.rb', line 41
def initialize(parent, args, block)
super(parent, args, block)
on_widget_selected do |event|
parent.select(parent.index_of(self), (event.meta? if event.respond_to?(:meta?)))
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Glimmer::SWT::WidgetProxy
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
39
40
41
|
# File 'lib/glimmer/swt/table_item_proxy.rb', line 39
def data
@data
end
|
Instance Method Details
#cell_dom_element(column_index) ⇒ Object
70
71
72
|
# File 'lib/glimmer/swt/table_item_proxy.rb', line 70
def cell_dom_element(column_index)
dom_element.find("td:nth-child(#{column_index + 1})")
end
|
#dom ⇒ Object
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
|
# File 'lib/glimmer/swt/table_item_proxy.rb', line 145
def dom
table_item_id = id
table_item_id_style = css
table_item_css_classes = css_classes
table_item_css_classes << name
table_item_selection = parent.selection.include?(self)
if table_item_selection
table_item_css_classes << 'selected'
else
table_item_css_classes.delete('selected')
end
table_item_text_array = text_array
table_item_max_width = max_column_width(@edit_column_index) if @edit_column_index
@dom ||= html {
tr(id: table_item_id, style: table_item_id_style, class: table_item_css_classes.to_a.join(' ')) {
table_item_text_array.each_with_index do |table_item_text, column_index|
td('data-column-index' => column_index) {
if @edit_column_index == column_index
input(type: 'text', value: table_item_text, style: "max-width: #{table_item_max_width - 11}px;")
else
table_item_text
end
}
end
}
}.to_s
end
|
#edit(column_index) ⇒ Object
118
119
120
121
122
123
|
# File 'lib/glimmer/swt/table_item_proxy.rb', line 118
def edit(column_index)
return if @edit_column_index == column_index.to_i
parent.select(parent.index_of(self), false)
@edit_column_index = column_index.to_i
redraw
end
|
#element ⇒ Object
66
67
68
|
# File 'lib/glimmer/swt/table_item_proxy.rb', line 66
def element
'tr'
end
|
#get_text(index) ⇒ Object
49
50
51
|
# File 'lib/glimmer/swt/table_item_proxy.rb', line 49
def get_text(index)
text_array[index]
end
|
#max_column_width(column_index) ⇒ Object
141
142
143
|
# File 'lib/glimmer/swt/table_item_proxy.rb', line 141
def max_column_width(column_index)
parent_dom_element.find("tr td:nth-child(#{column_index + 1})").first.width
end
|
#observation_request_to_event_mapping ⇒ Object
133
134
135
136
137
138
139
|
# File 'lib/glimmer/swt/table_item_proxy.rb', line 133
def observation_request_to_event_mapping
{
'on_widget_selected' => {
event: 'mouseup',
}
}
end
|
#parent_path ⇒ Object
62
63
64
|
# File 'lib/glimmer/swt/table_item_proxy.rb', line 62
def parent_path
parent.items_path
end
|
#redraw ⇒ Object
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
|
# File 'lib/glimmer/swt/table_item_proxy.rb', line 74
def redraw
super()
table_item_edit_handler = lambda do |event, cancel = false|
Async::Task.new do
text_value = event.target.value
edit_property = parent.column_properties[@edit_column_index]
edit_model = get_data
if !cancel && edit_model.send(edit_property) != text_value
edit_model.send("#{edit_property}=", text_value)
set_text(@edit_column_index, text_value)
end
@edit_column_index = nil
redraw
end
end
table_item_edit_cancel_handler = lambda do |event|
Async::Task.new do
table_item_edit_handler.call(event, true)
end
end
table_item_edit_key_handler = lambda do |event|
Async::Task.new do
if event.key_code == 13
table_item_edit_handler.call(event)
elsif event.key_code == 27
table_item_edit_cancel_handler.call(event)
end
end
end
if @edit_column_index
table_item_input = dom_element.find("td:nth-child(#{@edit_column_index + 1}) input")
if !table_item_input.empty?
Async::Task.new do
table_item_input.focus
table_item_input.on('keyup', &table_item_edit_key_handler)
table_item_input.on('focusout', &table_item_edit_cancel_handler)
end
end
end
end
|
#redraw_selection ⇒ Object
125
126
127
128
129
130
131
|
# File 'lib/glimmer/swt/table_item_proxy.rb', line 125
def redraw_selection
if parent.selection.include?(self)
dom_element.add_class('selected')
else
dom_element.remove_class('selected')
end
end
|
#set_text(index, text_value) ⇒ Object
53
54
55
56
|
# File 'lib/glimmer/swt/table_item_proxy.rb', line 53
def set_text(index, text_value)
text_array[index] = text_value
redraw
end
|
#text_array ⇒ Object
58
59
60
|
# File 'lib/glimmer/swt/table_item_proxy.rb', line 58
def text_array
@text_array ||= []
end
|