Class: Glimmer::SWT::ListProxy

Inherits:
WidgetProxy show all
Defined in:
lib/glimmer/swt/list_proxy.rb

Constant Summary collapse

STYLE =
<<~CSS
  ul {
    list-style: none;
    padding: 0;
  }
  li {
    cursor: default;
    padding-left: 10px;
    padding-right: 10px;
  }
  li.empty-list-item {
    color: transparent;
  }
CSS
ITEM_EMPTY =
'_____'

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, #parent_path, #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) ⇒ ListProxy

Returns a new instance of ListProxy.



24
25
26
27
# File 'lib/glimmer/swt/list_proxy.rb', line 24

def initialize(parent, args, block)
  super(parent, args, block)
  @selection = []
end

Dynamic Method Handling

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

Instance Attribute Details

#itemsObject

Returns the value of attribute items.



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

def items
  @items
end

#selectionObject

Returns the value of attribute selection.



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

def selection
  @selection
end

Instance Method Details

#domObject



92
93
94
95
96
97
98
99
100
# File 'lib/glimmer/swt/list_proxy.rb', line 92

def dom
  list_id = id
  list_style = css
  list_selection = selection
  @dom ||= html {
    ul(id: list_id, class: name, style: list_style) {
    }
  }.to_s
end

#elementObject



88
89
90
# File 'lib/glimmer/swt/list_proxy.rb', line 88

def element
  'ul'
end

#index_of(item) ⇒ Object



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

def index_of(item)
  @items.index(item)
end

#observation_request_to_event_mappingObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/glimmer/swt/list_proxy.rb', line 71

def observation_request_to_event_mapping
  {
    'on_widget_selected' => {
      event: 'click',
      event_handler: -> (event_listener) {
        -> (event) {
          if event.target.prop('nodeName') == 'LI'
            selected_item = event.target.text
            select(index_of(selected_item), event.meta_key)
            event_listener.call(event)
          end
        }
      }
    }
  }
end

#select(index, meta = false) ⇒ Object

used for single selection taking an index



60
61
62
63
64
65
66
67
68
69
# File 'lib/glimmer/swt/list_proxy.rb', line 60

def select(index, meta = false)
  selected_item = @items[index]
  if @selection.include?(selected_item)
    @selection.delete(selected_item) if meta
  else
    @selection = [] if !meta || (!has_style?(:multi) && @selection.to_a.size >= 1)
    @selection << selected_item
  end
  self.selection = @selection
end