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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/glimmer/swt/proxy_properties.rb', line 113
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/glimmer/swt/proxy_properties.rb', line 88
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
result = if respond_to?(ruby_attribute_getter(attribute_name))
send(ruby_attribute_getter(attribute_name))
else
send(attribute_name)
end
end
result
end
|
#has_attribute?(attribute_name, *args) ⇒ Boolean
63
64
65
66
67
68
|
# File 'lib/glimmer/swt/proxy_properties.rb', line 63
def has_attribute?(attribute_name, *args)
Glimmer::SWT::DisplayProxy.instance.auto_exec do
proxy_source_object&.respond_to?(attribute_setter(attribute_name), args) ||
respond_to?(ruby_attribute_setter(attribute_name), args)
end
end
|
#has_attribute_getter?(attribute_getter_name, *args) ⇒ Boolean
49
50
51
52
53
|
# File 'lib/glimmer/swt/proxy_properties.rb', line 49
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
55
56
57
58
59
60
61
|
# File 'lib/glimmer/swt/proxy_properties.rb', line 55
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
|
# 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
133
134
135
136
137
138
139
|
# File 'lib/glimmer/swt/proxy_properties.rb', line 133
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/glimmer/swt/proxy_properties.rb', line 70
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)
end
result
end
|