Class: Glimmer::SWT::TableColumnProxy

Inherits:
WidgetProxy show all
Includes:
Glimmer
Defined in:
lib/glimmer/swt/table_column_proxy.rb

Constant Summary collapse

STYLE =
<<~CSS
  th.table-column {
    background: rgb(246, 246, 246);
    text-align: left;
    padding: 5px;
  }
  
  th.table-column .sort-direction {
    float: right;
  }
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

Methods included from PropertyOwner

#attribute_getter, #attribute_setter, #get_attribute, #set_attribute

Constructor Details

#initialize(parent, args, block) ⇒ TableColumnProxy

Returns a new instance of TableColumnProxy.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/glimmer/swt/table_column_proxy.rb', line 26

def initialize(parent, args, block)
  @no_sort = args.delete(:no_sort)
  super(parent, args, block)
  unless no_sort?
    content {
      on_widget_selected { |event|
        parent.sort_by_column!(self)
      }
    }
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer::SWT::WidgetProxy

Instance Attribute Details

#editorObject

Returns the value of attribute editor.



22
23
24
# File 'lib/glimmer/swt/table_column_proxy.rb', line 22

def editor
  @editor
end

#no_sortObject (readonly) Also known as: no_sort?

Returns the value of attribute no_sort.



22
23
24
# File 'lib/glimmer/swt/table_column_proxy.rb', line 22

def no_sort
  @no_sort
end

#sort_blockObject

Returns the value of attribute sort_block.



21
22
23
# File 'lib/glimmer/swt/table_column_proxy.rb', line 21

def sort_block
  @sort_block
end

#sort_by_blockObject

Returns the value of attribute sort_by_block.



21
22
23
# File 'lib/glimmer/swt/table_column_proxy.rb', line 21

def sort_by_block
  @sort_by_block
end

#sort_propertyObject

Returns the value of attribute sort_property.



22
23
24
# File 'lib/glimmer/swt/table_column_proxy.rb', line 22

def sort_property
  @sort_property
end

#textObject

Returns the value of attribute text.



22
23
24
# File 'lib/glimmer/swt/table_column_proxy.rb', line 22

def text
  @text
end

#widthObject

Returns the value of attribute width.



22
23
24
# File 'lib/glimmer/swt/table_column_proxy.rb', line 22

def width
  @width
end

Instance Method Details

#domObject



101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/glimmer/swt/table_column_proxy.rb', line 101

def dom
  table_column_text = text
  table_column_id = id
  table_column_id_style = "width: #{width}px;"
  table_column_css_classes = css_classes
  table_column_css_classes << name
  @dom ||= html {
    th(id: table_column_id, style: table_column_id_style, class: table_column_css_classes.to_a.join(' ')) {
      span {table_column_text}
      span(class: sort_icon_class)
    }
  }.to_s
end

#editable?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/glimmer/swt/table_column_proxy.rb', line 83

def editable?
  !@editor&.include?(:none)
end

#elementObject



64
65
66
# File 'lib/glimmer/swt/table_column_proxy.rb', line 64

def element
  'th'
end

#observation_request_to_event_mappingObject



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/glimmer/swt/table_column_proxy.rb', line 87

def observation_request_to_event_mapping
  {
    'on_widget_selected' => {
      event: 'click',
      event_handler: -> (event_listener) {
        -> (event) {
          event_listener.call(event)
          redraw_sort_direction
        }
      }
    },
  }
end

#parent_pathObject



60
61
62
# File 'lib/glimmer/swt/table_column_proxy.rb', line 60

def parent_path
  parent.columns_path
end

#redraw_sort_directionObject



46
47
48
# File 'lib/glimmer/swt/table_column_proxy.rb', line 46

def redraw_sort_direction
  sort_icon_dom_element.attr('class', sort_icon_class)
end

#sort_directionObject



42
43
44
# File 'lib/glimmer/swt/table_column_proxy.rb', line 42

def sort_direction
  parent.sort_direction if parent.sort_column == self
end

#sort_icon_classObject



68
69
70
71
72
# File 'lib/glimmer/swt/table_column_proxy.rb', line 68

def sort_icon_class
  @sort_icon_class = 'sort-direction'
  @sort_icon_class += (sort_direction == SWTProxy[:up] ? ' ui-icon ui-icon-caret-1-n' : ' ui-icon ui-icon-caret-1-s') unless sort_direction.nil?
  @sort_icon_class
end

#sort_icon_dom_elementObject



74
75
76
# File 'lib/glimmer/swt/table_column_proxy.rb', line 74

def sort_icon_dom_element
  dom_element.find('.sort-direction')
end