Class: Glimmer::SWT::WidgetListenerProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/glimmer/swt/widget_listener_proxy.rb

Overview

Proxy for widget listeners

Follows the Proxy Design Pattern

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(swt_widget: nil, swt_display: nil, swt_listener:, widget_add_listener_method: nil, swt_listener_class: nil, swt_listener_method: nil, event_type: nil, swt_constant: nil, filter: false) ⇒ WidgetListenerProxy

Returns a new instance of WidgetListenerProxy.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/glimmer/swt/widget_listener_proxy.rb', line 31

def initialize(swt_widget:nil, swt_display:nil, swt_listener:, widget_add_listener_method: nil, swt_listener_class: nil, swt_listener_method: nil, event_type: nil, swt_constant: nil, filter: false)
  @swt_widget = swt_widget
  @swt_display = swt_display
  @filter = filter
  @swt_listener = swt_listener
  @widget_add_listener_method = widget_add_listener_method
  @swt_listener_class = swt_listener_class
  @swt_listener_method = swt_listener_method
  @event_type = event_type
  @swt_constant = swt_constant
end

Instance Attribute Details

#event_typeObject (readonly)

Returns the value of attribute event_type.



29
30
31
# File 'lib/glimmer/swt/widget_listener_proxy.rb', line 29

def event_type
  @event_type
end

#swt_constantObject (readonly)

Returns the value of attribute swt_constant.



29
30
31
# File 'lib/glimmer/swt/widget_listener_proxy.rb', line 29

def swt_constant
  @swt_constant
end

#swt_displayObject (readonly)

Returns the value of attribute swt_display.



29
30
31
# File 'lib/glimmer/swt/widget_listener_proxy.rb', line 29

def swt_display
  @swt_display
end

#swt_listenerObject (readonly)

Returns the value of attribute swt_listener.



29
30
31
# File 'lib/glimmer/swt/widget_listener_proxy.rb', line 29

def swt_listener
  @swt_listener
end

#swt_listener_classObject (readonly)

Returns the value of attribute swt_listener_class.



29
30
31
# File 'lib/glimmer/swt/widget_listener_proxy.rb', line 29

def swt_listener_class
  @swt_listener_class
end

#swt_listener_methodObject (readonly)

Returns the value of attribute swt_listener_method.



29
30
31
# File 'lib/glimmer/swt/widget_listener_proxy.rb', line 29

def swt_listener_method
  @swt_listener_method
end

#swt_widgetObject (readonly)

Returns the value of attribute swt_widget.



29
30
31
# File 'lib/glimmer/swt/widget_listener_proxy.rb', line 29

def swt_widget
  @swt_widget
end

#widget_add_listener_methodObject (readonly)

Returns the value of attribute widget_add_listener_method.



29
30
31
# File 'lib/glimmer/swt/widget_listener_proxy.rb', line 29

def widget_add_listener_method
  @widget_add_listener_method
end

Instance Method Details

#deregisterObject Also known as: unregister



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/glimmer/swt/widget_listener_proxy.rb', line 47

def deregister
  return if @swt_widget&.is_disposed || @swt_display&.is_disposed
  if @swt_display
    if @filter
      @swt_display.removeFilter(@event_type, @swt_listener)
    else
      @swt_display.removeListener(@event_type, @swt_listener)
    end
  elsif @event_type
    DisplayProxy.instance.auto_exec do
      @swt_widget.removeListener(@event_type, @swt_listener)
    end
  else
    DisplayProxy.instance.auto_exec do
      @swt_widget.send(widget_remove_listener_method, @swt_listener)
    end
  end
end

#widget_remove_listener_methodObject



43
44
45
# File 'lib/glimmer/swt/widget_listener_proxy.rb', line 43

def widget_remove_listener_method
  @widget_add_listener_method.sub('add', 'remove')
end