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, #swt_widget

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?, namespaces_for_class, #observer_registrations, option, options, #post_add_content, #post_initialize_child, reset_custom_widget_namespaces, #set_attribute, #shell_proxy, shortcut_keyword, #sync_exec, #timer_exec

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
# File 'lib/glimmer/swt/custom/refined_table.rb', line 173

def method_missing(method_name, *args, &block)
  dsl_mode = @dsl_mode || args.last.is_a?(Hash) && args.last[:dsl]
  if dsl_mode
    args.pop if args.last.is_a?(Hash) && args.last[:dsl]
    super(method_name, *args, &block)
  elsif @table_proxy&.respond_to?(method_name, *args, &block)
    @table_proxy&.send(method_name, *args, &block)
  else
    super
  end
end

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



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

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



220
221
222
223
224
225
226
# File 'lib/glimmer/swt/custom/refined_table.rb', line 220

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



215
216
217
218
# File 'lib/glimmer/swt/custom/refined_table.rb', line 215

def filter_and_paginate
  filter
  paginate
end

#first_button_block=(block) ⇒ Object



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

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

#first_pageObject



207
208
209
# File 'lib/glimmer/swt/custom/refined_table.rb', line 207

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

#last_button_block=(block) ⇒ Object



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

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

#last_pageObject



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

def last_page
  page_count
end

#next_button_block=(block) ⇒ Object



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

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

#page_countObject



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

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

#page_text_block=(block) ⇒ Object



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

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

#paginateObject



228
229
230
231
# File 'lib/glimmer/swt/custom/refined_table.rb', line 228

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

def pagination
  composite {
    layout_data(:fill, :center, true, false)
    
    fill_layout(:horizontal)
    
    @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



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

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

#respond_to?(method_name, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


185
186
187
188
189
190
191
192
193
# File 'lib/glimmer/swt/custom/refined_table.rb', line 185

def respond_to?(method_name, *args, &block)
  dsl_mode = @dsl_mode || args.last.is_a?(Hash) && args.last[:dsl]
  if dsl_mode
    args = args[0...-1] if args.last.is_a?(Hash) && args.last[:dsl]
    super(method_name, *args, &block)
  else
    super || @table_proxy&.respond_to?(method_name, *args, &block)
  end
end

#table_block=(block) ⇒ Object



149
150
151
# File 'lib/glimmer/swt/custom/refined_table.rb', line 149

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