Class: Glimmer::SWT::Custom::RefinedTable

Inherits:
Object
  • Object
show all
Includes:
UI::CustomWidget
Defined in:
lib/glimmer/swt/custom/refined_table.rb

Overview

RefinedTable is a customization of Table with support for Filtering/Pagination

Instance Attribute Summary collapse

Attributes included from UI::CustomWidget

#body_root, #options, #parent, #parent_proxy, #swt_style_symbols

Instance Method Summary collapse

Methods included from UI::CustomWidget

add_custom_widget_namespaces_for, #add_observer, after_body, #async_exec, #attribute_setter, before_body, body, #can_add_observer?, #can_handle_observation_request?, #children_owner, #content, custom_widget_namespaces, def_option_attr_accessors, #disposed?, flyweight_custom_widget_classes, for, #get_attribute, #handle_observation_request, #has_attribute?, #has_instance_method?, #has_style?, #initialize, keyword, #local_respond_to?, #method_missing, namespaces_for_class, #observer_registrations, option, options, #post_add_content, #post_initialize_child, reset_custom_widget_namespaces, #respond_to?, #set_attribute, #shell_proxy, shortcut_keyword, #swt_style, #swt_widget, #sync_exec, #timer_exec

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer::UI::CustomWidget

Instance Attribute Details

#filtered_model_arrayObject

Returns the value of attribute filtered_model_array.



36
37
38
# File 'lib/glimmer/swt/custom/refined_table.rb', line 36

def filtered_model_array
  @filtered_model_array
end

#first_button_proxyObject (readonly)

Returns the value of attribute first_button_proxy.



38
39
40
# File 'lib/glimmer/swt/custom/refined_table.rb', line 38

def first_button_proxy
  @first_button_proxy
end

#last_button_proxyObject (readonly)

Returns the value of attribute last_button_proxy.



38
39
40
# File 'lib/glimmer/swt/custom/refined_table.rb', line 38

def last_button_proxy
  @last_button_proxy
end

#next_button_proxyObject (readonly)

Returns the value of attribute next_button_proxy.



38
39
40
# File 'lib/glimmer/swt/custom/refined_table.rb', line 38

def next_button_proxy
  @next_button_proxy
end

#page_text_proxyObject (readonly)

Returns the value of attribute page_text_proxy.



38
39
40
# File 'lib/glimmer/swt/custom/refined_table.rb', line 38

def page_text_proxy
  @page_text_proxy
end

#previous_button_proxyObject (readonly)

Returns the value of attribute previous_button_proxy.



38
39
40
# File 'lib/glimmer/swt/custom/refined_table.rb', line 38

def previous_button_proxy
  @previous_button_proxy
end

#refined_model_arrayObject

Returns the value of attribute refined_model_array.



37
38
39
# File 'lib/glimmer/swt/custom/refined_table.rb', line 37

def refined_model_array
  @refined_model_array
end

#table_proxyObject (readonly)

Returns the value of attribute table_proxy.



38
39
40
# File 'lib/glimmer/swt/custom/refined_table.rb', line 38

def table_proxy
  @table_proxy
end

Instance Method Details

#corrected_page(initial_page_value = nil) ⇒ Object



180
181
182
183
184
185
186
# File 'lib/glimmer/swt/custom/refined_table.rb', line 180

def corrected_page(initial_page_value = nil)
  correct_page = initial_page_value || page
  correct_page = [correct_page, page_count].min
  correct_page = [correct_page, 1].max
  correct_page = (filtered_model_array&.count.to_i > 0) ? (correct_page > 0 ? correct_page : 1) : 0
  correct_page
end

#filterObject



201
202
203
204
205
206
207
# File 'lib/glimmer/swt/custom/refined_table.rb', line 201

def filter
  self.filtered_model_array = model_array.select do |model|
    @table_proxy.cells_for(model).any? do |cell_text|
      cell_text.to_s.downcase.include?(query.to_s.downcase)
    end
  end
end

#filter_and_paginateObject



196
197
198
199
# File 'lib/glimmer/swt/custom/refined_table.rb', line 196

def filter_and_paginate
  filter
  paginate
end

#first_button_block=(block) ⇒ Object



160
161
162
# File 'lib/glimmer/swt/custom/refined_table.rb', line 160

def first_button_block=(block)
  @first_button_proxy.content(&block)
end

#first_pageObject



188
189
190
# File 'lib/glimmer/swt/custom/refined_table.rb', line 188

def first_page
  (filtered_model_array&.count.to_i > 0) ? 1 : 0
end

#last_button_block=(block) ⇒ Object



172
173
174
# File 'lib/glimmer/swt/custom/refined_table.rb', line 172

def last_button_block=(block)
  @last_button_proxy.content(&block)
end

#last_pageObject



192
193
194
# File 'lib/glimmer/swt/custom/refined_table.rb', line 192

def last_page
  page_count
end

#next_button_block=(block) ⇒ Object



168
169
170
# File 'lib/glimmer/swt/custom/refined_table.rb', line 168

def next_button_block=(block)
  @next_button_proxy.content(&block)
end

#page_countObject



176
177
178
# File 'lib/glimmer/swt/custom/refined_table.rb', line 176

def page_count
  (filtered_model_array && (filtered_model_array.count / per_page.to_f).ceil) || 0
end

#page_text_block=(block) ⇒ Object



156
157
158
# File 'lib/glimmer/swt/custom/refined_table.rb', line 156

def page_text_block=(block)
  @page_text_proxy.content(&block)
end

#paginateObject



209
210
211
212
# File 'lib/glimmer/swt/custom/refined_table.rb', line 209

def paginate
  self.page = corrected_page(page)
  self.refined_model_array = filtered_model_array[(page - 1) * per_page, per_page]
end

#paginationObject



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
# File 'lib/glimmer/swt/custom/refined_table.rb', line 81

def pagination
  composite {
    layout_data(:fill, :center, true, false)
    
    fill_layout(:horizontal) {
      margin_width 0
      margin_height 0
    }
    
    @first_button_proxy = button {
      text '<<'
      enabled <= [self, :page, on_read: ->(value) {value > first_page}]
      
      on_widget_selected do
        self.page = first_page
        filter_and_paginate
      end
    }
    
    @previous_button_proxy = button {
      text '<'
      enabled <= [self, :page, on_read: ->(value) {value > first_page}]
      
      on_widget_selected do
        self.page -= 1
        filter_and_paginate
      end
    }
    
    @page_text_proxy = text(:border, :center) {
      text <= [self, :page, on_read: ->(value) { "#{value} of #{page_count}" }]
      
      on_focus_gained do
        @page_text_proxy.select_all
      end
      
      on_focus_lost do
        self.page = @page_text_proxy.text.to_i
        filter_and_paginate
      end
      
      on_key_pressed do |key_event|
        if key_event.keyCode == swt(:cr)
          self.page = @page_text_proxy.text.to_i
          filter_and_paginate
        end
      end
    }
    
    @next_button_proxy = button {
      text '>'
      enabled <= [self, :page, on_read: ->(value) {value < last_page}]
      
      on_widget_selected do
        self.page += 1
        filter_and_paginate
      end
    }
    
    @last_button_proxy = button {
      text '>>'
      enabled <= [self, :page, on_read: ->(value) {value < last_page}]
      
      on_widget_selected do
        self.page = last_page
        filter_and_paginate
      end
    }
  }
end

#previous_button_block=(block) ⇒ Object



164
165
166
# File 'lib/glimmer/swt/custom/refined_table.rb', line 164

def previous_button_block=(block)
  @previous_button_proxy.content(&block)
end

#table_block=(block) ⇒ Object



152
153
154
# File 'lib/glimmer/swt/custom/refined_table.rb', line 152

def table_block=(block)
  @table_proxy.content(&block)
end