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.Shell

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.



16
17
18
19
20
21
# File 'lib/glimmer/swt/message_box_proxy.rb', line 16

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



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

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.



14
15
16
# File 'lib/glimmer/swt/message_box_proxy.rb', line 14

def swt_widget
  @swt_widget
end

Instance Method Details

#attribute_getter(attribute_name) ⇒ Object



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

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)



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

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

#content(&block) ⇒ Object



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

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

#get_attribute(attribute_name) ⇒ Object



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

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

#has_attribute?(attribute_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#openObject



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

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

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

Returns:

  • (Boolean)


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

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

#set_attribute(attribute_name, *args) ⇒ Object



47
48
49
# File 'lib/glimmer/swt/message_box_proxy.rb', line 47

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