Class: Glimmer::SWT::MessageBoxProxy

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

Overview

Proxy for org.eclipse.swt.widgets.MessageBox

Follows the Proxy Design Pattern

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, style) ⇒ MessageBoxProxy

Returns a new instance of MessageBoxProxy.



37
38
39
40
41
42
# File 'lib/glimmer/swt/message_box_proxy.rb', line 37

def initialize(parent, style)
  if parent.nil?
    @temporary_parent = parent = Glimmer::SWT::ShellProxy.new.swt_widget
  end
  @swt_widget = MessageBox.new(parent, style)        
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



76
77
78
79
80
81
# File 'lib/glimmer/swt/message_box_proxy.rb', line 76

def method_missing(method, *args, &block)
  swt_widget.send(method, *args, &block)
rescue => e
  Glimmer::Config.logger.debug {"Neither MessageBoxProxy nor #{swt_widget.class.name} can handle the method ##{method}"}
  super
end

Instance Attribute Details

#swt_widgetObject (readonly)

Returns the value of attribute swt_widget.



35
36
37
# File 'lib/glimmer/swt/message_box_proxy.rb', line 35

def swt_widget
  @swt_widget
end

Instance Method Details

#attribute_getter(attribute_name) ⇒ Object



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

def attribute_getter(attribute_name)
  "get#{attribute_name.to_s.camelcase(:upper)}"
end

#attribute_setter(attribute_name) ⇒ Object

TODO refactor the following methods to put in a JavaBean mixin or somethin (perhaps contribute to OSS project too)



56
57
58
# File 'lib/glimmer/swt/message_box_proxy.rb', line 56

def attribute_setter(attribute_name)
  "set#{attribute_name.to_s.camelcase(:upper)}"
end

#content(&block) ⇒ Object



50
51
52
# File 'lib/glimmer/swt/message_box_proxy.rb', line 50

def content(&block)
  Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::MessageBoxExpression.new, &block)
end

#get_attribute(attribute_name) ⇒ Object



72
73
74
# File 'lib/glimmer/swt/message_box_proxy.rb', line 72

def get_attribute(attribute_name)
  @swt_widget.send(attribute_getter(attribute_name))
end

#has_attribute?(attribute_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


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

def has_attribute?(attribute_name, *args)
  @swt_widget.respond_to?(attribute_setter(attribute_name), args)
end

#openObject



44
45
46
47
48
# File 'lib/glimmer/swt/message_box_proxy.rb', line 44

def open
  @swt_widget.open.tap do |result|
    @temporary_parent&.dispose
  end
end

#respond_to?(method, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


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

def respond_to?(method, *args, &block)
  super || 
    swt_widget.respond_to?(method, *args, &block)
end

#set_attribute(attribute_name, *args) ⇒ Object



68
69
70
# File 'lib/glimmer/swt/message_box_proxy.rb', line 68

def set_attribute(attribute_name, *args)
  @swt_widget.send(attribute_setter(attribute_name), *args) unless @swt_widget.send(attribute_getter(attribute_name)) == args.first
end