Class: Glimmer::SWT::TableProxy
Constant Summary
Constants inherited
from WidgetProxy
WidgetProxy::DEFAULT_INITIALIZERS
Instance Attribute Summary collapse
Attributes inherited from WidgetProxy
#args, #background, #children, #enabled, #font, #foreground, #parent, #path
Instance Method Summary
collapse
Methods inherited from WidgetProxy
#add_css_class, #add_css_classes, #add_observer, #apply_property_type_converters, #build_dom, #can_handle_observation_request?, #clear_css_classes, #content, #css_classes, #dispose, #dom_element, for, #handle_observation_request, #has_style?, #id, #id=, #listener_dom_element, #listener_path, max_id_number_for, max_id_numbers, #name, next_id_number_for, #parent_dom_element, #parent_path, #property_type_converters, #remove_css_class, #remove_css_classes, #render, reset_max_id_numbers!, #set_attribute, #style_element, underscored_widget_name, widget_class, widget_exists?, #widget_property_listener_installers
#attribute_getter, #attribute_setter, #get_attribute, #set_attribute
Constructor Details
#initialize(parent, args) ⇒ TableProxy
Returns a new instance of TableProxy.
11
12
13
14
15
16
|
# File 'lib/glimmer/swt/table_proxy.rb', line 11
def initialize(parent, args)
super(parent, args)
@columns = []
@children = []
@selection = []
end
|
Instance Attribute Details
#column_properties ⇒ Object
Returns the value of attribute column_properties.
8
9
10
|
# File 'lib/glimmer/swt/table_proxy.rb', line 8
def column_properties
@column_properties
end
|
#columns ⇒ Object
Returns the value of attribute columns.
7
8
9
|
# File 'lib/glimmer/swt/table_proxy.rb', line 7
def columns
@columns
end
|
#selection ⇒ Object
Returns the value of attribute selection.
7
8
9
|
# File 'lib/glimmer/swt/table_proxy.rb', line 7
def selection
@selection
end
|
Instance Method Details
#add_child(child) ⇒ Object
Only table_columns may be added as children
19
20
21
22
23
24
25
26
|
# File 'lib/glimmer/swt/table_proxy.rb', line 19
def add_child(child)
if child.is_a?(TableColumnProxy)
@columns << child
else
@children << child
end
child.redraw
end
|
#columns_dom ⇒ Object
128
129
130
131
|
# File 'lib/glimmer/swt/table_proxy.rb', line 128
def columns_dom
tr {
}
end
|
#columns_dom_element ⇒ Object
116
117
118
|
# File 'lib/glimmer/swt/table_proxy.rb', line 116
def columns_dom_element
Document.find(columns_path)
end
|
#columns_path ⇒ Object
112
113
114
|
# File 'lib/glimmer/swt/table_proxy.rb', line 112
def columns_path
path + ' thead tr'
end
|
#dom ⇒ Object
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/glimmer/swt/table_proxy.rb', line 144
def dom
table_id = id
table_id_style = css
table_id_css_classes = css_classes
table_id_css_classes << 'table'
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_table_item(table_item, column_index) ⇒ Object
64
65
66
|
# File 'lib/glimmer/swt/table_proxy.rb', line 64
def edit_table_item(table_item, column_index)
table_item.edit(column_index)
end
|
#element ⇒ Object
108
109
110
|
# File 'lib/glimmer/swt/table_proxy.rb', line 108
def element
'table'
end
|
#index_of(item) ⇒ Object
48
49
50
|
# File 'lib/glimmer/swt/table_proxy.rb', line 48
def index_of(item)
items.index(item)
end
|
#items=(new_items) ⇒ Object
39
40
41
42
|
# File 'lib/glimmer/swt/table_proxy.rb', line 39
def items=(new_items)
@children = new_items
redraw
end
|
#items_dom ⇒ Object
139
140
141
142
|
# File 'lib/glimmer/swt/table_proxy.rb', line 139
def items_dom
tbody {
}
end
|
#items_dom_element ⇒ Object
124
125
126
|
# File 'lib/glimmer/swt/table_proxy.rb', line 124
def items_dom_element
Document.find(items_path)
end
|
#items_path ⇒ Object
120
121
122
|
# File 'lib/glimmer/swt/table_proxy.rb', line 120
def items_path
path + ' tbody'
end
|
#observation_request_to_event_mapping ⇒ Object
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
|
# File 'lib/glimmer/swt/table_proxy.rb', line 72
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)
}
}
{
'on_mouse_down' => {
event: 'mousedown',
event_handler: mouse_handler,
},
'on_mouse_up' => {
event: 'mouseup',
event_handler: mouse_handler,
}
}
end
|
#redraw ⇒ Object
103
104
105
106
|
# File 'lib/glimmer/swt/table_proxy.rb', line 103
def redraw
super()
@columns.to_a.each(&:redraw)
end
|
#remove_all ⇒ Object
28
29
30
31
|
# File 'lib/glimmer/swt/table_proxy.rb', line 28
def remove_all
items.clear
redraw
end
|
#search(&condition) ⇒ Object
44
45
46
|
# File 'lib/glimmer/swt/table_proxy.rb', line 44
def search(&condition)
items.select {|item| condition.nil? || condition.call(item)}
end
|
#select(index, meta = false) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/glimmer/swt/table_proxy.rb', line 52
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
68
69
70
|
# File 'lib/glimmer/swt/table_proxy.rb', line 68
def selector
super + ' tbody'
end
|
#thead_dom ⇒ Object
133
134
135
136
137
|
# File 'lib/glimmer/swt/table_proxy.rb', line 133
def thead_dom
thead {
columns_dom
}
end
|