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

Instance Attribute Summary collapse

Attributes inherited from WidgetProxy

#args, #background, #children, #enabled, #focus, #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, #post_add_content, #post_initialize_child, #property_type_converters, #remove_css_class, #remove_css_classes, #render, reset_max_id_numbers!, #selector, #set_attribute, #set_focus, #style_element, underscored_widget_name, widget_class, widget_exists?, #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.



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

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

Instance Attribute Details

#editorObject (readonly)

Returns the value of attribute editor.



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

def editor
  @editor
end

#no_sortObject (readonly) Also known as: no_sort?

Returns the value of attribute no_sort.



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

def no_sort
  @no_sort
end

#sort_blockObject

Returns the value of attribute sort_block.



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

def sort_block
  @sort_block
end

#sort_by_blockObject

Returns the value of attribute sort_by_block.



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

def sort_by_block
  @sort_by_block
end

#sort_propertyObject

Returns the value of attribute sort_property.



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

def sort_property
  @sort_property
end

#textObject

Returns the value of attribute text.



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

def text
  @text
end

#widthObject

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#domObject



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/glimmer/swt/table_column_proxy.rb', line 91

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

#elementObject



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

def element
  'th'
end

#observation_request_to_event_mappingObject



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/glimmer/swt/table_column_proxy.rb', line 77

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



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

def parent_path
  parent.columns_path
end

#redraw_sort_directionObject



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

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

#sort_directionObject



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

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

#sort_icon_classObject



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

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



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

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