Module: Glimmer::SWT::ProxyProperties
Overview
Provides a default implementation for proxy properties, that is properties that come from a proxy object source such as swt_widget having Java camelcase format
Instance Method Summary
collapse
-
#get_attribute(attribute_name) ⇒ Object
-
#has_attribute?(attribute_name, *args) ⇒ Boolean
-
#has_attribute_getter?(attribute_getter_name, *args) ⇒ Boolean
-
#has_attribute_setter?(attribute_setter_name, *args) ⇒ Boolean
-
#method_missing(method, *args, &block) ⇒ Object
-
#proxy_source_object ⇒ Object
Subclasses must override to privde a proxy source if they want to take advantage of default implementation of attribute setters/getters It tries swt_widget, swt_display, swt_image, and swt_dialog by default.
-
#respond_to?(method, *args, &block) ⇒ Boolean
-
#set_attribute(attribute_name, *args) ⇒ Object
Methods included from Properties
attribute_getter, #attribute_getter, attribute_setter, #attribute_setter, normalized_attribute, #normalized_attribute, ruby_attribute_getter, #ruby_attribute_setter, ruby_attribute_setter
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/glimmer/swt/proxy_properties.rb', line 114
def method_missing(method, *args, &block)
if has_attribute_setter?(method, *args)
set_attribute(method, *args)
elsif has_attribute_getter?(method, *args)
get_attribute(method, *args)
else
Glimmer::SWT::DisplayProxy.instance.auto_exec do
proxy_source_object&.send(method, *args, &block)
end
end
rescue => e
begin
super
rescue Exception => inner_error
Glimmer::Config.logger.error { "Neither self.class.name nor #{proxy_source_object&.class.name} can handle the method ##{method}" }
Glimmer::Config.logger.error { e.full_message }
raise inner_error
end
end
|
Instance Method Details
#get_attribute(attribute_name) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/glimmer/swt/proxy_properties.rb', line 89
def get_attribute(attribute_name)
swt_widget_operation = false
result = nil
Glimmer::SWT::DisplayProxy.instance.auto_exec do
result = if proxy_source_object&.respond_to?(attribute_getter(attribute_name))
swt_widget_operation = true
proxy_source_object&.send(attribute_getter(attribute_name))
elsif proxy_source_object&.respond_to?(ruby_attribute_getter(attribute_name))
swt_widget_operation = true
proxy_source_object&.send(ruby_attribute_getter(attribute_name))
elsif proxy_source_object&.respond_to?(attribute_name)
swt_widget_operation = true
proxy_source_object&.send(attribute_name)
end
end
unless swt_widget_operation
if respond_to?(ruby_attribute_getter(attribute_name))
result = send(ruby_attribute_getter(attribute_name))
elsif respond_to?(attribute_name)
result = send(attribute_name)
end
end
result
end
|
#has_attribute?(attribute_name, *args) ⇒ Boolean
64
65
66
67
68
69
|
# File 'lib/glimmer/swt/proxy_properties.rb', line 64
def has_attribute?(attribute_name, *args)
Glimmer::SWT::DisplayProxy.instance.auto_exec do
proxy_source_object&.respond_to?(attribute_setter(attribute_name), args) or
respond_to?(ruby_attribute_setter(attribute_name), args)
end
end
|
#has_attribute_getter?(attribute_getter_name, *args) ⇒ Boolean
50
51
52
53
54
|
# File 'lib/glimmer/swt/proxy_properties.rb', line 50
def has_attribute_getter?(attribute_getter_name, *args)
attribute_getter_name = attribute_getter_name.to_s.underscore
return false unless !attribute_getter_name.end_with?('=') && !attribute_getter_name.start_with?('set_')
args.empty? && proxy_source_object&.respond_to?(attribute_getter_name)
end
|
#has_attribute_setter?(attribute_setter_name, *args) ⇒ Boolean
56
57
58
59
60
61
62
|
# File 'lib/glimmer/swt/proxy_properties.rb', line 56
def has_attribute_setter?(attribute_setter_name, *args)
attribute_setter_name = attribute_setter_name.to_s
underscored_attribute_setter_name = attribute_setter_name.underscore
return false unless attribute_setter_name.end_with?('=') || (attribute_setter_name.start_with?('set_') && !args.empty?)
attribute_name = underscored_attribute_setter_name.sub(/^set_/, '').sub(/=$/, '')
has_attribute?(attribute_name, *args)
end
|
#proxy_source_object ⇒ Object
Subclasses must override to privde a proxy source if they want to take advantage of default implementation of attribute setters/getters It tries swt_widget, swt_display, swt_image, and swt_dialog by default.
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/glimmer/swt/proxy_properties.rb', line 35
def proxy_source_object
if respond_to?(:swt_widget)
swt_widget
elsif respond_to?(:swt_display)
swt_display
elsif respond_to?(:swt_image)
swt_image
elsif respond_to?(:swt_dialog)
swt_dialog
elsif respond_to?(:swt_transform)
swt_transform
end
end
|
#respond_to?(method, *args, &block) ⇒ Boolean
134
135
136
137
138
139
140
|
# File 'lib/glimmer/swt/proxy_properties.rb', line 134
def respond_to?(method, *args, &block)
result = super
return true if result
Glimmer::SWT::DisplayProxy.instance.auto_exec do
proxy_source_object&.respond_to?(method, *args, &block)
end
end
|
#set_attribute(attribute_name, *args) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/glimmer/swt/proxy_properties.rb', line 71
def set_attribute(attribute_name, *args)
swt_widget_operation = false
result = nil
Glimmer::SWT::DisplayProxy.instance.auto_exec do
result = if proxy_source_object&.respond_to?(attribute_setter(attribute_name))
swt_widget_operation = true
proxy_source_object&.send(attribute_setter(attribute_name), *args) unless (proxy_source_object&.respond_to?(attribute_getter(attribute_name)) && proxy_source_object&.send(attribute_getter(attribute_name))) == args.first
elsif proxy_source_object&.respond_to?(ruby_attribute_setter(attribute_name))
swt_widget_operation = true
proxy_source_object&.send(ruby_attribute_setter(attribute_name), args)
end
end
unless swt_widget_operation
result = send(ruby_attribute_setter(attribute_name), args) if respond_to?(ruby_attribute_setter(attribute_name), args)
end
result
end
|