Class: Glimmer::SWT::ListProxy
- Inherits:
-
WidgetProxy
- Object
- WidgetProxy
- Glimmer::SWT::ListProxy
- Defined in:
- lib/glimmer/swt/list_proxy.rb
Constant Summary collapse
- ITEM_EMPTY =
'_____'
Constants inherited from WidgetProxy
WidgetProxy::DEFAULT_INITIALIZERS
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
-
#selection ⇒ Object
Returns the value of attribute selection.
Attributes inherited from WidgetProxy
#args, #background, #children, #disposed?, #enabled, #focus, #font, #foreground, #parent, #path, #rendered
Instance Method Summary collapse
- #dom ⇒ Object
- #element ⇒ Object
- #index_of(item) ⇒ Object
-
#initialize(parent, args, block) ⇒ ListProxy
constructor
A new instance of ListProxy.
- #observation_request_to_event_mapping ⇒ Object
-
#select(index, meta = false) ⇒ Object
used for single selection taking an index.
Methods inherited from WidgetProxy
#add_content_on_render, #add_css_class, #add_css_classes, #add_observer, #apply_property_type_converters, #build_dom, #can_handle_observation_request?, #clear_css_classes, #content, #content_on_render_blocks, #css_classes, #default_observation_request_to_event_mapping, #dispose, #dom_element, #effective_observation_request_to_event_mapping, for, #get_data, #handle_observation_request, #has_style?, #id, #id=, #listener_dom_element, #listener_path, max_id_number_for, max_id_numbers, #method_missing, #name, next_id_number_for, #observation_requests, #parent_dom_element, #parent_path, #post_add_content, #post_dispose_child, #post_initialize_child, #property_type_converters, #remove_all_listeners, #remove_css_class, #remove_css_classes, #render, reset_max_id_numbers!, #selector, #set_attribute, #set_data, #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) ⇒ ListProxy
Returns a new instance of ListProxy.
9 10 11 12 |
# File 'lib/glimmer/swt/list_proxy.rb', line 9 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
#items ⇒ Object
Returns the value of attribute items.
7 8 9 |
# File 'lib/glimmer/swt/list_proxy.rb', line 7 def items @items end |
#selection ⇒ Object
Returns the value of attribute selection.
7 8 9 |
# File 'lib/glimmer/swt/list_proxy.rb', line 7 def selection @selection end |
Instance Method Details
#dom ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/glimmer/swt/list_proxy.rb', line 77 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 |
#element ⇒ Object
73 74 75 |
# File 'lib/glimmer/swt/list_proxy.rb', line 73 def element 'ul' end |
#index_of(item) ⇒ Object
30 31 32 |
# File 'lib/glimmer/swt/list_proxy.rb', line 30 def index_of(item) @items.index(item) end |
#observation_request_to_event_mapping ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/glimmer/swt/list_proxy.rb', line 56 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.) event_listener.call(event) end } } } } end |
#select(index, meta = false) ⇒ Object
used for single selection taking an index
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/glimmer/swt/list_proxy.rb', line 45 def select(index, = false) selected_item = @items[index] if @selection.include?(selected_item) @selection.delete(selected_item) if else @selection = [] if ! || (!has_style?(:multi) && @selection.to_a.size >= 1) @selection << selected_item end self.selection = @selection end |