glimmer-dsl-swt 4.18.4.4 → 4.18.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +33 -5057
- data/VERSION +1 -1
- data/docs/reference/GLIMMER_COMMAND.md +591 -0
- data/docs/reference/GLIMMER_CONFIGURATION.md +183 -0
- data/docs/reference/GLIMMER_GIRB.md +30 -0
- data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +3251 -0
- data/docs/reference/GLIMMER_PACKAGING_AND_DISTRIBUTION.md +202 -0
- data/docs/reference/GLIMMER_SAMPLES.md +676 -0
- data/docs/reference/GLIMMER_STYLE_GUIDE.md +14 -0
- data/glimmer-dsl-swt.gemspec +9 -2
- data/lib/glimmer/dsl/swt/custom_widget_expression.rb +63 -63
- data/lib/glimmer/dsl/swt/exec_expression.rb +55 -55
- data/lib/glimmer/dsl/swt/observe_expression.rb +56 -53
- data/lib/glimmer/swt/custom/animation.rb +247 -243
- data/lib/glimmer/swt/custom/shape.rb +299 -297
- data/lib/glimmer/swt/display_proxy.rb +167 -166
- data/lib/glimmer/swt/widget_proxy.rb +964 -957
- data/lib/glimmer/ui/custom_widget.rb +332 -315
- data/samples/elaborate/tetris.rb +0 -13
- data/samples/elaborate/tetris/view/block.rb +1 -1
- data/samples/hello/hello_canvas_animation.rb +1 -1
- metadata +8 -1
@@ -1,315 +1,332 @@
|
|
1
|
-
# Copyright (c) 2007-2021 Andy Maleh
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
# a copy of this software and associated documentation files (the
|
5
|
-
# "Software"), to deal in the Software without restriction, including
|
6
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
# the following conditions:
|
10
|
-
#
|
11
|
-
# The above copyright notice and this permission notice shall be
|
12
|
-
# included in all copies or substantial portions of the Software.
|
13
|
-
#
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
-
|
22
|
-
require 'glimmer'
|
23
|
-
require 'glimmer/error'
|
24
|
-
require 'glimmer/swt/swt_proxy'
|
25
|
-
require 'glimmer/swt/display_proxy'
|
26
|
-
require 'glimmer/util/proc_tracker'
|
27
|
-
require 'glimmer/data_binding/observer'
|
28
|
-
require 'glimmer/data_binding/observable_model'
|
29
|
-
|
30
|
-
module Glimmer
|
31
|
-
module UI
|
32
|
-
module CustomWidget
|
33
|
-
include SuperModule
|
34
|
-
include DataBinding::ObservableModel
|
35
|
-
|
36
|
-
super_module_included do |klass|
|
37
|
-
# TODO clear memoization of WidgetProxy.swt_widget_class_for for a keyword if a custom widget was defined with that keyword
|
38
|
-
klass.include(Glimmer) unless klass.name.include?('Glimmer::UI::CustomShell')
|
39
|
-
Glimmer::UI::CustomWidget.add_custom_widget_namespaces_for(klass) unless klass.name.include?('Glimmer::UI::CustomShell')
|
40
|
-
end
|
41
|
-
|
42
|
-
class << self
|
43
|
-
def for(underscored_custom_widget_name)
|
44
|
-
unless flyweight_custom_widget_classes.keys.include?(underscored_custom_widget_name)
|
45
|
-
begin
|
46
|
-
extracted_namespaces = underscored_custom_widget_name.
|
47
|
-
to_s.
|
48
|
-
split(/__/).map do |namespace|
|
49
|
-
namespace.camelcase(:upper)
|
50
|
-
end
|
51
|
-
custom_widget_namespaces.each do |base|
|
52
|
-
extracted_namespaces.reduce(base) do |result, namespace|
|
53
|
-
if !result.constants.include?(namespace)
|
54
|
-
namespace = result.constants.detect {|c| c.to_s.upcase == namespace.to_s.upcase } || namespace
|
55
|
-
end
|
56
|
-
begin
|
57
|
-
flyweight_custom_widget_classes[underscored_custom_widget_name] = constant = result.const_get(namespace)
|
58
|
-
return constant if constant.ancestors.include?(Glimmer::UI::CustomWidget)
|
59
|
-
flyweight_custom_widget_classes[underscored_custom_widget_name] = constant
|
60
|
-
rescue => e
|
61
|
-
# Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
|
62
|
-
flyweight_custom_widget_classes[underscored_custom_widget_name] = result
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
raise "#{underscored_custom_widget_name} has no custom widget class!"
|
67
|
-
rescue => e
|
68
|
-
Glimmer::Config.logger.debug {e.message}
|
69
|
-
Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
|
70
|
-
flyweight_custom_widget_classes[underscored_custom_widget_name] = nil
|
71
|
-
end
|
72
|
-
end
|
73
|
-
flyweight_custom_widget_classes[underscored_custom_widget_name]
|
74
|
-
end
|
75
|
-
|
76
|
-
# Flyweight Design Pattern memoization cache. Can be cleared if memory is needed.
|
77
|
-
def flyweight_custom_widget_classes
|
78
|
-
@flyweight_custom_widget_classes ||= {}
|
79
|
-
end
|
80
|
-
|
81
|
-
# Returns keyword to use for this custom widget
|
82
|
-
def keyword
|
83
|
-
self.name.underscore.gsub('::', '__')
|
84
|
-
end
|
85
|
-
|
86
|
-
# Returns shortcut keyword to use for this custom widget (keyword minus namespace)
|
87
|
-
def shortcut_keyword
|
88
|
-
self.name.underscore.gsub('::', '__').split('__').last
|
89
|
-
end
|
90
|
-
|
91
|
-
def add_custom_widget_namespaces_for(klass)
|
92
|
-
Glimmer::UI::CustomWidget.namespaces_for_class(klass).drop(1).each do |namespace|
|
93
|
-
Glimmer::UI::CustomWidget.custom_widget_namespaces << namespace
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def namespaces_for_class(m)
|
98
|
-
return [m] if m.name.nil?
|
99
|
-
namespace_constants = m.name.split(/::/).map(&:to_sym)
|
100
|
-
namespace_constants.reduce([Object]) do |output, namespace_constant|
|
101
|
-
output += [output.last.const_get(namespace_constant)]
|
102
|
-
end[1..-1].uniq.reverse
|
103
|
-
end
|
104
|
-
|
105
|
-
def custom_widget_namespaces
|
106
|
-
@custom_widget_namespaces ||= reset_custom_widget_namespaces
|
107
|
-
end
|
108
|
-
|
109
|
-
def reset_custom_widget_namespaces
|
110
|
-
@custom_widget_namespaces = Set[Object, Glimmer::UI]
|
111
|
-
end
|
112
|
-
|
113
|
-
# Allows defining convenience option accessors for an array of option names
|
114
|
-
# Example: `options :color1, :color2` defines `#color1` and `#color2`
|
115
|
-
# where they return the instance values `options[:color1]` and `options[:color2]`
|
116
|
-
# respectively.
|
117
|
-
# Can be called multiple times to set more options additively.
|
118
|
-
# When passed no arguments, it returns list of all option names captured so far
|
119
|
-
def options(*new_options)
|
120
|
-
new_options = new_options.compact.map(&:to_s).map(&:to_sym)
|
121
|
-
if new_options.empty?
|
122
|
-
@options ||= {} # maps options to defaults
|
123
|
-
else
|
124
|
-
new_options = new_options.reduce({}) {|new_options_hash, new_option| new_options_hash.merge(new_option => nil)}
|
125
|
-
@options = options.merge(new_options)
|
126
|
-
def_option_attr_accessors(new_options)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def option(new_option, default: nil)
|
131
|
-
new_option = new_option.to_s.to_sym
|
132
|
-
new_options = {new_option => default}
|
133
|
-
@options = options.merge(new_options)
|
134
|
-
def_option_attr_accessors(new_options)
|
135
|
-
end
|
136
|
-
|
137
|
-
def def_option_attr_accessors(new_options)
|
138
|
-
new_options.each do |option, default|
|
139
|
-
class_eval <<-end_eval, __FILE__, __LINE__
|
140
|
-
def #{option}
|
141
|
-
options[:#{option}]
|
142
|
-
end
|
143
|
-
def #{option}=(option_value)
|
144
|
-
self.options[:#{option}] = option_value
|
145
|
-
end
|
146
|
-
end_eval
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def before_body(&block)
|
151
|
-
@before_body_block = block
|
152
|
-
end
|
153
|
-
|
154
|
-
def body(&block)
|
155
|
-
@body_block = block
|
156
|
-
end
|
157
|
-
|
158
|
-
def after_body(&block)
|
159
|
-
@after_body_block = block
|
160
|
-
end
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
@
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
if
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
end
|
223
|
-
|
224
|
-
def
|
225
|
-
if has_instance_method?(
|
226
|
-
|
227
|
-
else
|
228
|
-
@body_root.
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
end
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
1
|
+
# Copyright (c) 2007-2021 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'glimmer'
|
23
|
+
require 'glimmer/error'
|
24
|
+
require 'glimmer/swt/swt_proxy'
|
25
|
+
require 'glimmer/swt/display_proxy'
|
26
|
+
require 'glimmer/util/proc_tracker'
|
27
|
+
require 'glimmer/data_binding/observer'
|
28
|
+
require 'glimmer/data_binding/observable_model'
|
29
|
+
|
30
|
+
module Glimmer
|
31
|
+
module UI
|
32
|
+
module CustomWidget
|
33
|
+
include SuperModule
|
34
|
+
include DataBinding::ObservableModel
|
35
|
+
|
36
|
+
super_module_included do |klass|
|
37
|
+
# TODO clear memoization of WidgetProxy.swt_widget_class_for for a keyword if a custom widget was defined with that keyword
|
38
|
+
klass.include(Glimmer) unless klass.name.include?('Glimmer::UI::CustomShell')
|
39
|
+
Glimmer::UI::CustomWidget.add_custom_widget_namespaces_for(klass) unless klass.name.include?('Glimmer::UI::CustomShell')
|
40
|
+
end
|
41
|
+
|
42
|
+
class << self
|
43
|
+
def for(underscored_custom_widget_name)
|
44
|
+
unless flyweight_custom_widget_classes.keys.include?(underscored_custom_widget_name)
|
45
|
+
begin
|
46
|
+
extracted_namespaces = underscored_custom_widget_name.
|
47
|
+
to_s.
|
48
|
+
split(/__/).map do |namespace|
|
49
|
+
namespace.camelcase(:upper)
|
50
|
+
end
|
51
|
+
custom_widget_namespaces.each do |base|
|
52
|
+
extracted_namespaces.reduce(base) do |result, namespace|
|
53
|
+
if !result.constants.include?(namespace)
|
54
|
+
namespace = result.constants.detect {|c| c.to_s.upcase == namespace.to_s.upcase } || namespace
|
55
|
+
end
|
56
|
+
begin
|
57
|
+
flyweight_custom_widget_classes[underscored_custom_widget_name] = constant = result.const_get(namespace)
|
58
|
+
return constant if constant.ancestors.include?(Glimmer::UI::CustomWidget)
|
59
|
+
flyweight_custom_widget_classes[underscored_custom_widget_name] = constant
|
60
|
+
rescue => e
|
61
|
+
# Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
|
62
|
+
flyweight_custom_widget_classes[underscored_custom_widget_name] = result
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
raise "#{underscored_custom_widget_name} has no custom widget class!"
|
67
|
+
rescue => e
|
68
|
+
Glimmer::Config.logger.debug {e.message}
|
69
|
+
Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
|
70
|
+
flyweight_custom_widget_classes[underscored_custom_widget_name] = nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
flyweight_custom_widget_classes[underscored_custom_widget_name]
|
74
|
+
end
|
75
|
+
|
76
|
+
# Flyweight Design Pattern memoization cache. Can be cleared if memory is needed.
|
77
|
+
def flyweight_custom_widget_classes
|
78
|
+
@flyweight_custom_widget_classes ||= {}
|
79
|
+
end
|
80
|
+
|
81
|
+
# Returns keyword to use for this custom widget
|
82
|
+
def keyword
|
83
|
+
self.name.underscore.gsub('::', '__')
|
84
|
+
end
|
85
|
+
|
86
|
+
# Returns shortcut keyword to use for this custom widget (keyword minus namespace)
|
87
|
+
def shortcut_keyword
|
88
|
+
self.name.underscore.gsub('::', '__').split('__').last
|
89
|
+
end
|
90
|
+
|
91
|
+
def add_custom_widget_namespaces_for(klass)
|
92
|
+
Glimmer::UI::CustomWidget.namespaces_for_class(klass).drop(1).each do |namespace|
|
93
|
+
Glimmer::UI::CustomWidget.custom_widget_namespaces << namespace
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def namespaces_for_class(m)
|
98
|
+
return [m] if m.name.nil?
|
99
|
+
namespace_constants = m.name.split(/::/).map(&:to_sym)
|
100
|
+
namespace_constants.reduce([Object]) do |output, namespace_constant|
|
101
|
+
output += [output.last.const_get(namespace_constant)]
|
102
|
+
end[1..-1].uniq.reverse
|
103
|
+
end
|
104
|
+
|
105
|
+
def custom_widget_namespaces
|
106
|
+
@custom_widget_namespaces ||= reset_custom_widget_namespaces
|
107
|
+
end
|
108
|
+
|
109
|
+
def reset_custom_widget_namespaces
|
110
|
+
@custom_widget_namespaces = Set[Object, Glimmer::UI]
|
111
|
+
end
|
112
|
+
|
113
|
+
# Allows defining convenience option accessors for an array of option names
|
114
|
+
# Example: `options :color1, :color2` defines `#color1` and `#color2`
|
115
|
+
# where they return the instance values `options[:color1]` and `options[:color2]`
|
116
|
+
# respectively.
|
117
|
+
# Can be called multiple times to set more options additively.
|
118
|
+
# When passed no arguments, it returns list of all option names captured so far
|
119
|
+
def options(*new_options)
|
120
|
+
new_options = new_options.compact.map(&:to_s).map(&:to_sym)
|
121
|
+
if new_options.empty?
|
122
|
+
@options ||= {} # maps options to defaults
|
123
|
+
else
|
124
|
+
new_options = new_options.reduce({}) {|new_options_hash, new_option| new_options_hash.merge(new_option => nil)}
|
125
|
+
@options = options.merge(new_options)
|
126
|
+
def_option_attr_accessors(new_options)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def option(new_option, default: nil)
|
131
|
+
new_option = new_option.to_s.to_sym
|
132
|
+
new_options = {new_option => default}
|
133
|
+
@options = options.merge(new_options)
|
134
|
+
def_option_attr_accessors(new_options)
|
135
|
+
end
|
136
|
+
|
137
|
+
def def_option_attr_accessors(new_options)
|
138
|
+
new_options.each do |option, default|
|
139
|
+
class_eval <<-end_eval, __FILE__, __LINE__
|
140
|
+
def #{option}
|
141
|
+
options[:#{option}]
|
142
|
+
end
|
143
|
+
def #{option}=(option_value)
|
144
|
+
self.options[:#{option}] = option_value
|
145
|
+
end
|
146
|
+
end_eval
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def before_body(&block)
|
151
|
+
@before_body_block = block
|
152
|
+
end
|
153
|
+
|
154
|
+
def body(&block)
|
155
|
+
@body_block = block
|
156
|
+
end
|
157
|
+
|
158
|
+
def after_body(&block)
|
159
|
+
@after_body_block = block
|
160
|
+
end
|
161
|
+
|
162
|
+
# Current custom widgets being rendered. Useful to yoke all observers evaluated during rendering of their custom widgets for automatical disposal on_widget_disposed
|
163
|
+
def current_custom_widgets
|
164
|
+
@current_custom_widgets ||= []
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
attr_reader :body_root, :swt_widget, :parent, :parent_proxy, :swt_style, :options
|
169
|
+
|
170
|
+
def initialize(parent, *swt_constants, options, &content)
|
171
|
+
Glimmer::UI::CustomWidget.current_custom_widgets << self
|
172
|
+
@parent_proxy = @parent = parent
|
173
|
+
@parent_proxy = @parent&.get_data('proxy') if @parent.respond_to?(:get_data) && @parent.get_data('proxy')
|
174
|
+
@swt_style = SWT::SWTProxy[*swt_constants]
|
175
|
+
options ||= {}
|
176
|
+
@options = self.class.options.merge(options)
|
177
|
+
@content = Util::ProcTracker.new(content) if content
|
178
|
+
execute_hook('before_body')
|
179
|
+
body_block = self.class.instance_variable_get("@body_block")
|
180
|
+
raise Glimmer::Error, 'Invalid custom widget for having no body! Please define body block!' if body_block.nil?
|
181
|
+
@body_root = instance_exec(&body_block)
|
182
|
+
raise Glimmer::Error, 'Invalid custom widget for having an empty body! Please fill body block!' if @body_root.nil?
|
183
|
+
@swt_widget = @body_root.swt_widget
|
184
|
+
@swt_widget.set_data('custom_widget', self)
|
185
|
+
execute_hook('after_body')
|
186
|
+
@dispose_listener_registration = @body_root.on_widget_disposed do
|
187
|
+
observer_registrations.each(&:deregister)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# Subclasses may override to perform post initialization work on an added child
|
192
|
+
def post_initialize_child(child)
|
193
|
+
# No Op by default
|
194
|
+
end
|
195
|
+
|
196
|
+
def observer_registrations
|
197
|
+
@observer_registrations ||= []
|
198
|
+
end
|
199
|
+
|
200
|
+
def can_handle_observation_request?(observation_request)
|
201
|
+
observation_request = observation_request.to_s
|
202
|
+
result = false
|
203
|
+
if observation_request.start_with?('on_updated_')
|
204
|
+
property = observation_request.sub(/^on_updated_/, '')
|
205
|
+
result = can_add_observer?(property)
|
206
|
+
end
|
207
|
+
result || body_root&.can_handle_observation_request?(observation_request)
|
208
|
+
end
|
209
|
+
|
210
|
+
def handle_observation_request(observation_request, &block)
|
211
|
+
observation_request = observation_request.to_s
|
212
|
+
if observation_request.start_with?('on_updated_')
|
213
|
+
property = observation_request.sub(/^on_updated_/, '') # TODO look into eliminating duplication from above
|
214
|
+
add_observer(DataBinding::Observer.proc(&block), property) if can_add_observer?(property)
|
215
|
+
else
|
216
|
+
body_root.handle_observation_request(observation_request, &block)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
def can_add_observer?(attribute_name)
|
221
|
+
has_instance_method?(attribute_name) || has_instance_method?("#{attribute_name}?") || @body_root.can_add_observer?(attribute_name)
|
222
|
+
end
|
223
|
+
|
224
|
+
def add_observer(observer, attribute_name)
|
225
|
+
if has_instance_method?(attribute_name)
|
226
|
+
super
|
227
|
+
else
|
228
|
+
@body_root.add_observer(observer, attribute_name)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def has_attribute?(attribute_name, *args)
|
233
|
+
has_instance_method?(attribute_setter(attribute_name)) ||
|
234
|
+
@body_root.has_attribute?(attribute_name, *args)
|
235
|
+
end
|
236
|
+
|
237
|
+
def set_attribute(attribute_name, *args)
|
238
|
+
if has_instance_method?(attribute_setter(attribute_name))
|
239
|
+
send(attribute_setter(attribute_name), *args)
|
240
|
+
else
|
241
|
+
@body_root.set_attribute(attribute_name, *args)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
# This method ensures it has an instance method not coming from Glimmer DSL
|
246
|
+
def has_instance_method?(method_name)
|
247
|
+
respond_to?(method_name) and
|
248
|
+
!swt_widget&.respond_to?(method_name) and
|
249
|
+
(method(method_name) rescue nil) and
|
250
|
+
!method(method_name)&.source_location&.first&.include?('glimmer/dsl/engine.rb') and
|
251
|
+
!method(method_name)&.source_location&.first&.include?('glimmer/swt/widget_proxy.rb')
|
252
|
+
end
|
253
|
+
|
254
|
+
def get_attribute(attribute_name)
|
255
|
+
if has_instance_method?(attribute_name)
|
256
|
+
send(attribute_name)
|
257
|
+
else
|
258
|
+
@body_root.get_attribute(attribute_name)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
def attribute_setter(attribute_name)
|
263
|
+
"#{attribute_name}="
|
264
|
+
end
|
265
|
+
|
266
|
+
def disposed?
|
267
|
+
swt_widget.isDisposed
|
268
|
+
end
|
269
|
+
|
270
|
+
def has_style?(style)
|
271
|
+
(swt_style & SWT::SWTProxy[style]) == SWT::SWTProxy[style]
|
272
|
+
end
|
273
|
+
|
274
|
+
def pack(*args)
|
275
|
+
body_root.pack(*args)
|
276
|
+
end
|
277
|
+
|
278
|
+
# TODO see if it is worth it to eliminate duplication of async_exec/sync_exec
|
279
|
+
# delegation to DisplayProxy, via a module
|
280
|
+
|
281
|
+
def async_exec(&block)
|
282
|
+
SWT::DisplayProxy.instance.async_exec(&block)
|
283
|
+
end
|
284
|
+
|
285
|
+
def sync_exec(&block)
|
286
|
+
SWT::DisplayProxy.instance.sync_exec(&block)
|
287
|
+
end
|
288
|
+
|
289
|
+
def timer_exec(delay_in_millis, &block)
|
290
|
+
SWT::DisplayProxy.instance.timer_exec(delay_in_millis, &block)
|
291
|
+
end
|
292
|
+
|
293
|
+
# Returns content block if used as an attribute reader (no args)
|
294
|
+
# Otherwise, if a block is passed, it adds it as content to this custom widget
|
295
|
+
def content(&block)
|
296
|
+
if block_given?
|
297
|
+
body_root.content(&block)
|
298
|
+
else
|
299
|
+
@content
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
def method_missing(method, *args, &block)
|
304
|
+
# TODO Consider supporting a glimmer error silencing option for methods defined here
|
305
|
+
# but fail the glimmer DSL for the right reason to avoid seeing noise in the log output
|
306
|
+
if can_handle_observation_request?(method)
|
307
|
+
handle_observation_request(method, &block)
|
308
|
+
else
|
309
|
+
body_root.send(method, *args, &block)
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
alias local_respond_to? respond_to?
|
314
|
+
def respond_to?(method, *args, &block)
|
315
|
+
super or
|
316
|
+
can_handle_observation_request?(method) or
|
317
|
+
body_root.respond_to?(method, *args, &block)
|
318
|
+
end
|
319
|
+
|
320
|
+
private
|
321
|
+
|
322
|
+
def execute_hook(hook_name)
|
323
|
+
hook_block = self.class.instance_variable_get("@#{hook_name}_block")
|
324
|
+
return if hook_block.nil?
|
325
|
+
temp_method_name = "#{hook_name}_block_#{hook_block.hash.abs}_#{(Time.now.to_f * 1_000_000).to_i}"
|
326
|
+
singleton_class.define_method(temp_method_name, &hook_block)
|
327
|
+
send(temp_method_name)
|
328
|
+
singleton_class.send(:remove_method, temp_method_name)
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|