glimmer-dsl-swt 4.18.4.9 → 4.18.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +73 -0
- data/README.md +14 -5
- data/VERSION +1 -1
- data/bin/glimmer +3 -3
- data/docs/reference/GLIMMER_CONFIGURATION.md +7 -3
- data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +464 -149
- data/docs/reference/GLIMMER_SAMPLES.md +91 -4
- data/glimmer-dsl-swt.gemspec +24 -13
- data/lib/ext/glimmer/config.rb +3 -7
- data/lib/glimmer/data_binding/list_selection_binding.rb +13 -7
- data/lib/glimmer/data_binding/table_items_binding.rb +22 -17
- data/lib/glimmer/data_binding/tree_items_binding.rb +19 -15
- data/lib/glimmer/data_binding/widget_binding.rb +13 -15
- data/lib/glimmer/dsl/swt/{file_dialog_expression.rb → auto_exec_expression.rb} +6 -18
- data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +9 -6
- data/lib/glimmer/dsl/swt/color_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +16 -14
- data/lib/glimmer/dsl/swt/custom_widget_expression.rb +4 -1
- data/lib/glimmer/dsl/swt/data_binding_expression.rb +2 -2
- data/lib/glimmer/dsl/swt/dialog_expression.rb +18 -9
- data/lib/glimmer/dsl/swt/dsl.rb +1 -0
- data/lib/glimmer/dsl/swt/exec_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/font_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/image_expression.rb +16 -2
- data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +11 -8
- data/lib/glimmer/dsl/swt/pixel_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +8 -5
- data/lib/glimmer/dsl/swt/shape_expression.rb +2 -2
- data/lib/glimmer/dsl/swt/shell_expression.rb +5 -2
- data/lib/glimmer/dsl/swt/widget_expression.rb +8 -4
- data/lib/glimmer/launcher.rb +3 -0
- data/lib/glimmer/rake_task/scaffold.rb +3 -0
- data/lib/glimmer/swt/color_proxy.rb +1 -1
- data/lib/glimmer/swt/custom/code_text.rb +33 -11
- data/lib/glimmer/swt/custom/drawable.rb +55 -0
- data/lib/glimmer/swt/custom/shape.rb +187 -43
- data/lib/glimmer/swt/custom/shape/arc.rb +60 -0
- data/lib/glimmer/{dsl/swt/directory_dialog_expression.rb → swt/custom/shape/focus.rb} +15 -20
- data/lib/glimmer/swt/custom/shape/image.rb +99 -0
- data/lib/glimmer/swt/custom/shape/line.rb +65 -0
- data/lib/glimmer/swt/custom/shape/oval.rb +61 -0
- data/lib/glimmer/swt/custom/shape/point.rb +54 -0
- data/lib/glimmer/swt/custom/shape/polygon.rb +73 -0
- data/lib/glimmer/swt/custom/shape/polyline.rb +74 -0
- data/lib/glimmer/swt/custom/shape/rectangle.rb +101 -0
- data/lib/glimmer/swt/custom/shape/text.rb +85 -0
- data/lib/glimmer/swt/date_time_proxy.rb +9 -3
- data/lib/glimmer/swt/dialog_proxy.rb +92 -0
- data/lib/glimmer/swt/display_proxy.rb +62 -2
- data/lib/glimmer/swt/expand_item_proxy.rb +18 -12
- data/lib/glimmer/swt/font_proxy.rb +13 -7
- data/lib/glimmer/swt/image_proxy.rb +15 -4
- data/lib/glimmer/swt/layout_data_proxy.rb +21 -15
- data/lib/glimmer/swt/layout_proxy.rb +19 -15
- data/lib/glimmer/swt/menu_proxy.rb +2 -2
- data/lib/glimmer/swt/message_box_proxy.rb +21 -7
- data/lib/glimmer/swt/properties.rb +3 -0
- data/lib/glimmer/swt/proxy_properties.rb +145 -0
- data/lib/glimmer/swt/scrolled_composite_proxy.rb +6 -2
- data/lib/glimmer/swt/shell_proxy.rb +96 -80
- data/lib/glimmer/swt/swt_proxy.rb +17 -0
- data/lib/glimmer/swt/tab_item_proxy.rb +5 -3
- data/lib/glimmer/swt/table_proxy.rb +32 -11
- data/lib/glimmer/swt/transform_proxy.rb +39 -35
- data/lib/glimmer/swt/tree_proxy.rb +11 -16
- data/lib/glimmer/swt/widget_listener_proxy.rb +6 -2
- data/lib/glimmer/swt/widget_proxy.rb +192 -141
- data/lib/glimmer/ui.rb +5 -0
- data/lib/glimmer/ui/custom_shell.rb +13 -7
- data/lib/glimmer/ui/custom_widget.rb +4 -5
- data/samples/elaborate/contact_manager.rb +7 -7
- data/samples/elaborate/login.rb +25 -21
- data/samples/elaborate/mandelbrot_fractal.rb +87 -31
- data/samples/elaborate/meta_sample.rb +1 -1
- data/samples/elaborate/tetris.rb +1 -0
- data/samples/elaborate/tic_tac_toe.rb +16 -14
- data/samples/elaborate/tic_tac_toe/board.rb +5 -5
- data/samples/elaborate/tic_tac_toe/cell.rb +5 -5
- data/samples/hello/hello_button.rb +7 -7
- data/samples/hello/hello_canvas.rb +143 -41
- data/samples/hello/hello_checkbox.rb +16 -14
- data/samples/hello/hello_checkbox_group.rb +11 -9
- data/samples/hello/hello_color_dialog.rb +66 -0
- data/samples/hello/hello_combo.rb +14 -12
- data/samples/hello/hello_computed.rb +7 -7
- data/samples/hello/hello_cursor.rb +2 -1
- data/samples/hello/hello_custom_shell.rb +17 -21
- data/samples/hello/hello_custom_widget.rb +4 -6
- data/samples/hello/hello_date_time.rb +14 -12
- data/samples/hello/hello_directory_dialog.rb +7 -7
- data/samples/hello/hello_expand_bar.rb +8 -8
- data/samples/hello/hello_file_dialog.rb +7 -7
- data/samples/hello/hello_font_dialog.rb +82 -0
- data/samples/hello/hello_group.rb +18 -16
- data/samples/hello/hello_list_multi_selection.rb +13 -11
- data/samples/hello/hello_list_single_selection.rb +13 -11
- data/samples/hello/hello_progress_bar.rb +125 -0
- data/samples/hello/hello_radio.rb +18 -16
- data/samples/hello/hello_radio_group.rb +14 -12
- data/samples/hello/hello_spinner.rb +7 -7
- data/samples/hello/hello_tab.rb +5 -5
- data/samples/hello/hello_table.rb +10 -5
- data/samples/hello/hello_tree.rb +485 -0
- metadata +22 -22
- data/lib/glimmer/swt/directory_dialog_proxy.rb +0 -65
- data/lib/glimmer/swt/file_dialog_proxy.rb +0 -66
@@ -42,7 +42,8 @@ module Glimmer
|
|
42
42
|
# Returns a Java TreeItem array to easily set as selection on org.eclipse.swt.Tree if needed
|
43
43
|
def depth_first_search(&condition)
|
44
44
|
found = []
|
45
|
-
|
45
|
+
first_item = DisplayProxy.instance.auto_exec { swt_widget.getItems.first }
|
46
|
+
recursive_depth_first_search(first_item, found, &condition)
|
46
47
|
found.to_java(TreeItem)
|
47
48
|
end
|
48
49
|
|
@@ -51,18 +52,6 @@ module Glimmer
|
|
51
52
|
depth_first_search
|
52
53
|
end
|
53
54
|
|
54
|
-
def widget_property_listener_installers
|
55
|
-
super.merge({
|
56
|
-
Java::OrgEclipseSwtWidgets::Tree => {
|
57
|
-
selection: lambda do |observer|
|
58
|
-
on_widget_selected { |selection_event|
|
59
|
-
observer.call(@swt_widget.getSelection)
|
60
|
-
}
|
61
|
-
end
|
62
|
-
},
|
63
|
-
})
|
64
|
-
end
|
65
|
-
|
66
55
|
def edit_in_progress?
|
67
56
|
!!@edit_in_progress
|
68
57
|
end
|
@@ -127,8 +116,10 @@ module Glimmer
|
|
127
116
|
|
128
117
|
def recursive_depth_first_search(tree_item, found, &condition)
|
129
118
|
return if tree_item.nil?
|
130
|
-
found << tree_item if condition.nil? || condition.call(tree_item)
|
131
|
-
|
119
|
+
found << tree_item if condition.nil? || DisplayProxy.instance.auto_exec {condition.call(tree_item)}
|
120
|
+
# return if found.any? && !has_style?(:multi) # TODO inspect if this is a good optimization when needed
|
121
|
+
tree_items = DisplayProxy.instance.auto_exec {tree_item.getItems}
|
122
|
+
tree_items.each do |child_tree_item|
|
132
123
|
recursive_depth_first_search(child_tree_item, found, &condition)
|
133
124
|
end
|
134
125
|
end
|
@@ -136,7 +127,11 @@ module Glimmer
|
|
136
127
|
def property_type_converters
|
137
128
|
super.merge({
|
138
129
|
selection: lambda do |value|
|
139
|
-
|
130
|
+
if value.is_a?(Array)
|
131
|
+
depth_first_search {|ti| value.include?(ti.getData) }
|
132
|
+
else
|
133
|
+
depth_first_search {|ti| ti.getData == value}
|
134
|
+
end
|
140
135
|
end,
|
141
136
|
})
|
142
137
|
end
|
@@ -53,9 +53,13 @@ module Glimmer
|
|
53
53
|
@swt_display.removeListener(@event_type, @swt_listener)
|
54
54
|
end
|
55
55
|
elsif @event_type
|
56
|
-
|
56
|
+
DisplayProxy.instance.auto_exec do
|
57
|
+
@swt_widget.removeListener(@event_type, @swt_listener)
|
58
|
+
end
|
57
59
|
else
|
58
|
-
|
60
|
+
DisplayProxy.instance.auto_exec do
|
61
|
+
@swt_widget.send(widget_remove_listener_method, @swt_listener)
|
62
|
+
end
|
59
63
|
end
|
60
64
|
end
|
61
65
|
alias unregister deregister # TODO consider dropping unregister (and in Observer too)
|
@@ -26,7 +26,7 @@ require 'glimmer/swt/swt_proxy'
|
|
26
26
|
require 'glimmer/swt/display_proxy'
|
27
27
|
require 'glimmer/swt/dnd_proxy'
|
28
28
|
require 'glimmer/swt/image_proxy'
|
29
|
-
require 'glimmer/swt/
|
29
|
+
require 'glimmer/swt/proxy_properties'
|
30
30
|
require 'glimmer/swt/custom/drawable'
|
31
31
|
|
32
32
|
# TODO refactor to make file smaller and extract sub-widget-proxies out of this
|
@@ -44,13 +44,13 @@ module Glimmer
|
|
44
44
|
# Follows the Proxy Design Pattern
|
45
45
|
class WidgetProxy
|
46
46
|
include Packages
|
47
|
-
include
|
47
|
+
include ProxyProperties
|
48
48
|
include Custom::Drawable
|
49
49
|
|
50
50
|
DEFAULT_STYLES = {
|
51
51
|
'arrow' => [:arrow],
|
52
52
|
'button' => [:push],
|
53
|
-
'canvas' => [:double_buffered],
|
53
|
+
'canvas' => ([:double_buffered] unless OS.mac?),
|
54
54
|
'checkbox' => [:check],
|
55
55
|
'check' => [:check],
|
56
56
|
'drag_source' => [:drop_copy],
|
@@ -112,13 +112,15 @@ module Glimmer
|
|
112
112
|
# Instantiates the right WidgetProxy subclass for passed in keyword
|
113
113
|
# Args are: keyword, parent, swt_widget_args (including styles)
|
114
114
|
def create(*init_args, swt_widget: nil)
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
115
|
+
DisplayProxy.instance.auto_exec do
|
116
|
+
return swt_widget.get_data('proxy') if swt_widget&.get_data('proxy')
|
117
|
+
keyword, parent, args = init_args
|
118
|
+
selected_widget_proxy_class = widget_proxy_class(keyword || underscored_widget_name(swt_widget))
|
119
|
+
if init_args.empty?
|
120
|
+
selected_widget_proxy_class.new(swt_widget: swt_widget)
|
121
|
+
else
|
122
|
+
selected_widget_proxy_class.new(*init_args)
|
123
|
+
end
|
122
124
|
end
|
123
125
|
end
|
124
126
|
|
@@ -149,31 +151,33 @@ module Glimmer
|
|
149
151
|
#
|
150
152
|
# Styles is a comma separate list of symbols representing SWT styles in lower case
|
151
153
|
def initialize(*init_args, swt_widget: nil)
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
@swt_widget
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
on_widget_disposed
|
174
|
-
|
175
|
-
|
176
|
-
|
154
|
+
auto_exec do
|
155
|
+
@image_double_buffered = !!(init_args&.last&.include?(:image_double_buffered) && init_args&.last&.delete(:image_double_buffered))
|
156
|
+
if swt_widget.nil?
|
157
|
+
underscored_widget_name, parent, args = init_args
|
158
|
+
@parent_proxy = parent
|
159
|
+
styles, extra_options = extract_args(underscored_widget_name, args)
|
160
|
+
swt_widget_class = self.class.swt_widget_class_for(underscored_widget_name)
|
161
|
+
@swt_widget = swt_widget_class.new(@parent_proxy.swt_widget, style(underscored_widget_name, styles), *extra_options)
|
162
|
+
else
|
163
|
+
@swt_widget = swt_widget
|
164
|
+
underscored_widget_name = self.class.underscored_widget_name(@swt_widget)
|
165
|
+
parent_proxy_class = self.class.widget_proxy_class(self.class.underscored_widget_name(@swt_widget.parent))
|
166
|
+
parent = swt_widget.parent
|
167
|
+
@parent_proxy = parent&.get_data('proxy') || parent_proxy_class.new(swt_widget: parent)
|
168
|
+
end
|
169
|
+
if @swt_widget&.get_data('proxy').nil?
|
170
|
+
@swt_widget.set_data('proxy', self)
|
171
|
+
DEFAULT_INITIALIZERS[underscored_widget_name.to_s.to_sym]&.call(@swt_widget)
|
172
|
+
@parent_proxy.post_initialize_child(self)
|
173
|
+
end
|
174
|
+
@keyword = underscored_widget_name.to_s
|
175
|
+
if respond_to?(:on_widget_disposed)
|
176
|
+
on_widget_disposed {
|
177
|
+
clear_shapes
|
178
|
+
deregister_shape_painting
|
179
|
+
}
|
180
|
+
end
|
177
181
|
end
|
178
182
|
end
|
179
183
|
|
@@ -219,81 +223,77 @@ module Glimmer
|
|
219
223
|
[args, extra_options]
|
220
224
|
end
|
221
225
|
end
|
222
|
-
|
223
|
-
def has_attribute_getter?(attribute_getter_name, *args)
|
224
|
-
attribute_getter_name = attribute_getter_name.to_s.underscore
|
225
|
-
return false unless !attribute_getter_name.end_with?('=') && !attribute_getter_name.start_with?('set_')
|
226
|
-
args.empty? && swt_widget.respond_to?(attribute_getter_name)
|
227
|
-
end
|
228
226
|
|
229
|
-
def
|
230
|
-
|
231
|
-
underscored_attribute_setter_name = attribute_setter_name.underscore
|
232
|
-
return false unless attribute_setter_name.end_with?('=') || (attribute_setter_name.start_with?('set_') && !args.empty?)
|
233
|
-
attribute_name = underscored_attribute_setter_name.sub(/^set_/, '').sub(/=$/, '')
|
234
|
-
has_attribute?(attribute_name, *args)
|
227
|
+
def proxy_source_object
|
228
|
+
@swt_widget
|
235
229
|
end
|
236
|
-
|
230
|
+
|
237
231
|
def has_attribute?(attribute_name, *args)
|
238
232
|
# TODO test that attribute getter responds too
|
239
233
|
widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
234
|
+
auto_exec do
|
235
|
+
if widget_custom_attribute
|
236
|
+
@swt_widget.respond_to?(widget_custom_attribute[:setter][:name])
|
237
|
+
else
|
238
|
+
super
|
239
|
+
end
|
244
240
|
end
|
245
241
|
end
|
246
242
|
|
247
243
|
def set_attribute(attribute_name, *args)
|
248
244
|
# TODO Think about widget subclasses overriding set_attribute to add more attributes vs adding as Ruby attributes directly
|
249
245
|
widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
|
250
|
-
|
251
|
-
|
252
|
-
widget_custom_attribute[:setter][:invoker].call(@swt_widget, args)
|
253
|
-
elsif @swt_widget.respond_to?(attribute_setter(attribute_name))
|
254
|
-
@swt_widget.send(attribute_setter(attribute_name), *args) unless @swt_widget.send(attribute_getter(attribute_name)) == args.first
|
255
|
-
elsif @swt_widget.respond_to?(ruby_attribute_setter(attribute_name))
|
256
|
-
@swt_widget.send(ruby_attribute_setter(attribute_name), args)
|
257
|
-
else
|
258
|
-
send(ruby_attribute_setter(attribute_name), args)
|
246
|
+
auto_exec do
|
247
|
+
apply_property_type_converters(normalized_attribute(attribute_name), args)
|
259
248
|
end
|
249
|
+
swt_widget_operation = false
|
250
|
+
result = nil
|
251
|
+
auto_exec do
|
252
|
+
result = if widget_custom_attribute
|
253
|
+
swt_widget_operation = true
|
254
|
+
widget_custom_attribute[:setter][:invoker].call(@swt_widget, args)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
result = super unless swt_widget_operation
|
258
|
+
result
|
260
259
|
end
|
261
260
|
|
262
261
|
def get_attribute(attribute_name)
|
263
262
|
widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
263
|
+
swt_widget_operation = false
|
264
|
+
result = nil
|
265
|
+
auto_exec do
|
266
|
+
result = if widget_custom_attribute
|
267
|
+
swt_widget_operation = true
|
268
|
+
if widget_custom_attribute[:getter][:invoker]
|
269
|
+
widget_custom_attribute[:getter][:invoker].call(@swt_widget, [])
|
270
|
+
else
|
271
|
+
@swt_widget.send(widget_custom_attribute[:getter][:name])
|
272
|
+
end
|
269
273
|
end
|
270
|
-
elsif @swt_widget.respond_to?(attribute_getter(attribute_name))
|
271
|
-
@swt_widget.send(attribute_getter(attribute_name))
|
272
|
-
elsif @swt_widget.respond_to?(ruby_attribute_getter(attribute_name))
|
273
|
-
@swt_widget.send(ruby_attribute_getter(attribute_name))
|
274
|
-
elsif @swt_widget.respond_to?(attribute_name)
|
275
|
-
@swt_widget.send(attribute_name)
|
276
|
-
elsif respond_to?(ruby_attribute_getter(attribute_name))
|
277
|
-
send(ruby_attribute_getter(attribute_name))
|
278
|
-
else
|
279
|
-
send(attribute_name)
|
280
274
|
end
|
275
|
+
result = super unless swt_widget_operation
|
276
|
+
result
|
281
277
|
end
|
282
278
|
|
283
279
|
def pack_same_size
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
@swt_widget.
|
291
|
-
|
292
|
-
|
280
|
+
auto_exec do
|
281
|
+
bounds = @swt_widget.getBounds
|
282
|
+
listener = on_control_resized {
|
283
|
+
@swt_widget.setSize(bounds.width, bounds.height)
|
284
|
+
@swt_widget.setLocation(bounds.x, bounds.y)
|
285
|
+
}
|
286
|
+
if @swt_widget.is_a?(Composite)
|
287
|
+
@swt_widget.layout(true, true)
|
288
|
+
else
|
289
|
+
@swt_widget.pack(true)
|
290
|
+
end
|
291
|
+
@swt_widget.removeControlListener(listener.swt_listener)
|
293
292
|
end
|
294
|
-
@swt_widget.removeControlListener(listener.swt_listener)
|
295
293
|
end
|
296
294
|
|
295
|
+
# these work in tandem with the property_type_converters
|
296
|
+
# sometimes, they are specified in subclasses instead
|
297
297
|
def widget_property_listener_installers
|
298
298
|
@swt_widget_property_listener_installers ||= {
|
299
299
|
Java::OrgEclipseSwtWidgets::Control => {
|
@@ -334,6 +334,17 @@ module Glimmer
|
|
334
334
|
}
|
335
335
|
end,
|
336
336
|
},
|
337
|
+
Java::OrgEclipseSwtWidgets::Tree => {
|
338
|
+
:selection => lambda do |observer|
|
339
|
+
on_widget_selected { |selection_event|
|
340
|
+
if has_style?(:multi)
|
341
|
+
observer.call(@swt_widget.getSelection.map(&:get_data))
|
342
|
+
else
|
343
|
+
observer.call(@swt_widget.getSelection.first&.get_data)
|
344
|
+
end
|
345
|
+
}
|
346
|
+
end,
|
347
|
+
},
|
337
348
|
Java::OrgEclipseSwtWidgets::Text => {
|
338
349
|
:text => lambda do |observer|
|
339
350
|
on_modify_text { |modify_event|
|
@@ -546,25 +557,37 @@ module Glimmer
|
|
546
557
|
@flyweight_swt_widget_classes ||= {}
|
547
558
|
end
|
548
559
|
|
560
|
+
# delegates to DisplayProxy
|
549
561
|
def async_exec(&block)
|
550
562
|
DisplayProxy.instance.async_exec(&block)
|
551
563
|
end
|
552
564
|
|
565
|
+
# delegates to DisplayProxy
|
553
566
|
def sync_exec(&block)
|
554
567
|
DisplayProxy.instance.sync_exec(&block)
|
555
568
|
end
|
556
569
|
|
570
|
+
# delegates to DisplayProxy
|
557
571
|
def timer_exec(delay_in_millis, &block)
|
558
572
|
DisplayProxy.instance.timer_exec(delay_in_millis, &block)
|
559
573
|
end
|
560
574
|
|
575
|
+
# delegates to DisplayProxy
|
576
|
+
def auto_exec(override_sync_exec: nil, override_async_exec: nil, &block)
|
577
|
+
DisplayProxy.instance.auto_exec(override_sync_exec: override_sync_exec, override_async_exec: override_async_exec, &block)
|
578
|
+
end
|
579
|
+
|
561
580
|
def has_style?(style)
|
562
581
|
comparison = interpret_style(style)
|
563
|
-
|
582
|
+
auto_exec do
|
583
|
+
(@swt_widget.style & comparison) == comparison
|
584
|
+
end
|
564
585
|
end
|
565
586
|
|
566
587
|
def dispose
|
567
|
-
|
588
|
+
auto_exec do
|
589
|
+
@swt_widget.dispose
|
590
|
+
end
|
568
591
|
end
|
569
592
|
|
570
593
|
def disposed?
|
@@ -574,15 +597,19 @@ module Glimmer
|
|
574
597
|
# TODO Consider renaming these methods as they are mainly used for data-binding
|
575
598
|
|
576
599
|
def can_add_observer?(property_name)
|
577
|
-
|
600
|
+
auto_exec do
|
601
|
+
@swt_widget.class.ancestors.map {|ancestor| widget_property_listener_installers[ancestor]}.compact.map(&:keys).flatten.map(&:to_s).include?(property_name.to_s)
|
602
|
+
end
|
578
603
|
end
|
579
604
|
|
580
605
|
# Used for data-binding only. Consider renaming or improving to avoid the confusion it causes
|
581
606
|
def add_observer(observer, property_name)
|
582
607
|
if !observer.respond_to?(:binding_options) || !observer.binding_options[:read_only]
|
583
|
-
|
584
|
-
|
585
|
-
|
608
|
+
auto_exec do
|
609
|
+
property_listener_installers = @swt_widget.class.ancestors.map {|ancestor| widget_property_listener_installers[ancestor]}.compact
|
610
|
+
widget_listener_installers = property_listener_installers.map{|installer| installer[property_name.to_s.to_sym]}.compact if !property_listener_installers.empty?
|
611
|
+
widget_listener_installers.to_a.first&.call(observer)
|
612
|
+
end
|
586
613
|
end
|
587
614
|
end
|
588
615
|
|
@@ -597,7 +624,7 @@ module Glimmer
|
|
597
624
|
end
|
598
625
|
|
599
626
|
def ensure_drop_target_proxy(style=[])
|
600
|
-
@drop_target_proxy ||=
|
627
|
+
@drop_target_proxy ||= WidgetProxy.new('drop_target', self, style).tap do |proxy|
|
601
628
|
proxy.set_attribute(:transfer, :text)
|
602
629
|
proxy.on_drag_enter { |event|
|
603
630
|
event.detail = DNDProxy[:drop_copy]
|
@@ -608,7 +635,7 @@ module Glimmer
|
|
608
635
|
# TODO eliminate duplication in the following methods perhaps by relying on exceptions
|
609
636
|
|
610
637
|
def can_handle_observation_request?(observation_request)
|
611
|
-
observation_request = observation_request
|
638
|
+
observation_request = normalize_observation_request(observation_request)
|
612
639
|
if observation_request.start_with?('on_swt_')
|
613
640
|
constant_name = observation_request.sub(/^on_swt_/, '')
|
614
641
|
SWTProxy.has_constant?(constant_name)
|
@@ -619,13 +646,15 @@ module Glimmer
|
|
619
646
|
end
|
620
647
|
|
621
648
|
def can_handle_drag_observation_request?(observation_request)
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
649
|
+
auto_exec do
|
650
|
+
return false unless swt_widget.is_a?(Control)
|
651
|
+
potential_drag_source = @drag_source_proxy.nil?
|
652
|
+
ensure_drag_source_proxy
|
653
|
+
@drag_source_proxy.can_handle_observation_request?(observation_request).tap do |result|
|
654
|
+
if potential_drag_source && !result
|
655
|
+
@drag_source_proxy.swt_widget.dispose
|
656
|
+
@drag_source_proxy = nil
|
657
|
+
end
|
629
658
|
end
|
630
659
|
end
|
631
660
|
rescue => e
|
@@ -634,19 +663,21 @@ module Glimmer
|
|
634
663
|
end
|
635
664
|
|
636
665
|
def can_handle_drop_observation_request?(observation_request)
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
666
|
+
auto_exec do
|
667
|
+
return false unless swt_widget.is_a?(Control)
|
668
|
+
potential_drop_target = @drop_target_proxy.nil?
|
669
|
+
ensure_drop_target_proxy
|
670
|
+
@drop_target_proxy.can_handle_observation_request?(observation_request).tap do |result|
|
671
|
+
if potential_drop_target && !result
|
672
|
+
@drop_target_proxy.swt_widget.dispose
|
673
|
+
@drop_target_proxy = nil
|
674
|
+
end
|
644
675
|
end
|
645
676
|
end
|
646
677
|
end
|
647
678
|
|
648
679
|
def handle_observation_request(observation_request, &block)
|
649
|
-
observation_request = observation_request
|
680
|
+
observation_request = normalize_observation_request(observation_request)
|
650
681
|
if observation_request.start_with?('on_swt_')
|
651
682
|
constant_name = observation_request.sub(/^on_swt_/, '')
|
652
683
|
add_swt_event_listener(constant_name, &block)
|
@@ -664,30 +695,26 @@ module Glimmer
|
|
664
695
|
end
|
665
696
|
|
666
697
|
def content(&block)
|
667
|
-
|
698
|
+
auto_exec do
|
699
|
+
Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::WidgetExpression.new, &block)
|
700
|
+
end
|
668
701
|
end
|
669
702
|
|
670
703
|
def method_missing(method, *args, &block)
|
704
|
+
# TODO push most of this logic down to Properties (and perhaps create Listeners module as well)
|
671
705
|
if can_handle_observation_request?(method)
|
672
706
|
handle_observation_request(method, &block)
|
673
|
-
elsif has_attribute_setter?(method, *args)
|
674
|
-
set_attribute(method, *args)
|
675
|
-
elsif has_attribute_getter?(method, *args)
|
676
|
-
get_attribute(method, *args)
|
677
707
|
else
|
678
|
-
|
708
|
+
super
|
679
709
|
end
|
680
|
-
rescue => e
|
681
|
-
Glimmer::Config.logger.debug { "Neither WidgetProxy nor #{swt_widget.class.name} can handle the method ##{method}" }
|
682
|
-
Glimmer::Config.logger.debug { e.full_message }
|
683
|
-
super
|
684
|
-
# TODO consider get_attribute too
|
685
710
|
end
|
686
711
|
|
687
712
|
def respond_to?(method, *args, &block)
|
688
|
-
super
|
689
|
-
|
690
|
-
|
713
|
+
result = super
|
714
|
+
return true if result
|
715
|
+
auto_exec do
|
716
|
+
can_handle_observation_request?(method)
|
717
|
+
end
|
691
718
|
end
|
692
719
|
|
693
720
|
private
|
@@ -713,22 +740,26 @@ module Glimmer
|
|
713
740
|
# add_listener knowing it will be called for sure afterwards
|
714
741
|
|
715
742
|
def can_add_listener?(underscored_listener_name)
|
716
|
-
|
743
|
+
auto_exec do
|
744
|
+
!self.class.find_listener(@swt_widget.getClass, underscored_listener_name).empty?
|
745
|
+
end
|
717
746
|
end
|
718
747
|
|
719
748
|
def add_listener(underscored_listener_name, &block)
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
749
|
+
auto_exec do
|
750
|
+
widget_add_listener_method, listener_class, listener_method = self.class.find_listener(@swt_widget.getClass, underscored_listener_name)
|
751
|
+
widget_listener_proxy = nil
|
752
|
+
safe_block = lambda do |*args|
|
753
|
+
begin
|
754
|
+
block.call(*args) unless @swt_widget.isDisposed
|
755
|
+
rescue => e
|
756
|
+
Glimmer::Config.logger.error {e}
|
757
|
+
end
|
727
758
|
end
|
759
|
+
listener = listener_class.new(listener_method => safe_block)
|
760
|
+
@swt_widget.send(widget_add_listener_method, listener)
|
761
|
+
WidgetListenerProxy.new(swt_widget: @swt_widget, swt_listener: listener, widget_add_listener_method: widget_add_listener_method, swt_listener_class: listener_class, swt_listener_method: listener_method)
|
728
762
|
end
|
729
|
-
listener = listener_class.new(listener_method => safe_block)
|
730
|
-
@swt_widget.send(widget_add_listener_method, listener)
|
731
|
-
WidgetListenerProxy.new(swt_widget: @swt_widget, swt_listener: listener, widget_add_listener_method: widget_add_listener_method, swt_listener_class: listener_class, swt_listener_method: listener_method)
|
732
763
|
end
|
733
764
|
|
734
765
|
# Looks through SWT class add***Listener methods till it finds one for which
|
@@ -778,16 +809,22 @@ module Glimmer
|
|
778
809
|
end
|
779
810
|
|
780
811
|
def add_swt_event_listener(swt_constant, &block)
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
812
|
+
auto_exec do
|
813
|
+
event_type = SWTProxy[swt_constant]
|
814
|
+
widget_listener_proxy = nil
|
815
|
+
safe_block = lambda { |*args| block.call(*args) unless @swt_widget.isDisposed }
|
816
|
+
@swt_widget.addListener(event_type, &safe_block)
|
817
|
+
widget_listener_proxy = WidgetListenerProxy.new(swt_widget: @swt_widget, swt_listener: @swt_widget.getListeners(event_type).last, event_type: event_type, swt_constant: swt_constant)
|
818
|
+
end
|
786
819
|
end
|
787
820
|
|
788
821
|
def widget_custom_attribute_mapping
|
789
822
|
# TODO scope per widget class type just like other mappings
|
790
823
|
@swt_widget_custom_attribute_mapping ||= {
|
824
|
+
'window' => {
|
825
|
+
getter: {name: 'getShell'},
|
826
|
+
setter: {name: 'getShell', invoker: lambda { |widget, args| @swt_widget.getShell }}, # No Op
|
827
|
+
},
|
791
828
|
'focus' => {
|
792
829
|
getter: {name: 'isFocusControl'},
|
793
830
|
setter: {name: 'setFocus', invoker: lambda { |widget, args| @swt_widget.setFocus if args.first }},
|
@@ -840,6 +877,14 @@ module Glimmer
|
|
840
877
|
ensure_drop_target_proxy
|
841
878
|
@drop_target_proxy.set_attribute(:drop_target_effect, args)
|
842
879
|
end
|
880
|
+
|
881
|
+
def normalize_observation_request(observation_request)
|
882
|
+
observation_request = observation_request.to_s
|
883
|
+
if @swt_widget.is_a?(Shell) && observation_request.downcase.include?('window')
|
884
|
+
observation_request = observation_request.sub('window', 'shell').sub('Window', 'Shell')
|
885
|
+
end
|
886
|
+
observation_request
|
887
|
+
end
|
843
888
|
|
844
889
|
def apply_property_type_converters(attribute_name, args)
|
845
890
|
value = args
|
@@ -855,6 +900,8 @@ module Glimmer
|
|
855
900
|
color_converter = lambda do |value|
|
856
901
|
if value.is_a?(Symbol) || value.is_a?(String)
|
857
902
|
ColorProxy.new(value).swt_color
|
903
|
+
elsif value.is_a?(RGB)
|
904
|
+
ColorProxy.new(value.red, value.green, value.blue).swt_color
|
858
905
|
else
|
859
906
|
value
|
860
907
|
end
|
@@ -893,7 +940,7 @@ module Glimmer
|
|
893
940
|
while last_image_number != image_number
|
894
941
|
last_image_number = image_number
|
895
942
|
sync_exec {
|
896
|
-
redraw
|
943
|
+
redraw unless disposed?
|
897
944
|
}
|
898
945
|
delayTime = loader.data[image_number].delayTime.to_f / 100.0
|
899
946
|
sleep(delayTime)
|
@@ -924,7 +971,7 @@ module Glimmer
|
|
924
971
|
foreground: color_converter,
|
925
972
|
link_foreground: color_converter,
|
926
973
|
font: lambda do |value|
|
927
|
-
if value.is_a?(Hash)
|
974
|
+
if value.is_a?(Hash) || value.is_a?(FontData)
|
928
975
|
font_properties = value
|
929
976
|
FontProxy.new(self, font_properties).swt_font
|
930
977
|
else
|
@@ -942,6 +989,10 @@ module Glimmer
|
|
942
989
|
items: lambda do |value|
|
943
990
|
value.to_java :string
|
944
991
|
end,
|
992
|
+
selection: lambda do |value|
|
993
|
+
value = value.to_f if swt_widget.is_a?(Spinner)
|
994
|
+
value
|
995
|
+
end,
|
945
996
|
text: lambda do |value|
|
946
997
|
value.to_s
|
947
998
|
end,
|