glimmer-dsl-swt 4.18.4.11 → 4.18.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -0
  3. data/README.md +7 -5
  4. data/VERSION +1 -1
  5. data/bin/glimmer +3 -3
  6. data/docs/reference/GLIMMER_CONFIGURATION.md +7 -3
  7. data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +121 -5
  8. data/docs/reference/GLIMMER_SAMPLES.md +17 -4
  9. data/glimmer-dsl-swt.gemspec +19 -9
  10. data/lib/ext/glimmer/config.rb +3 -7
  11. data/lib/glimmer/data_binding/list_selection_binding.rb +13 -7
  12. data/lib/glimmer/data_binding/table_items_binding.rb +22 -17
  13. data/lib/glimmer/data_binding/tree_items_binding.rb +19 -15
  14. data/lib/glimmer/data_binding/widget_binding.rb +9 -27
  15. data/lib/glimmer/dsl/swt/auto_exec_expression.rb +36 -0
  16. data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +9 -6
  17. data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +16 -14
  18. data/lib/glimmer/dsl/swt/data_binding_expression.rb +1 -2
  19. data/lib/glimmer/dsl/swt/exec_expression.rb +1 -1
  20. data/lib/glimmer/dsl/swt/image_expression.rb +8 -1
  21. data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +11 -8
  22. data/lib/glimmer/dsl/swt/pixel_expression.rb +1 -1
  23. data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +8 -5
  24. data/lib/glimmer/dsl/swt/shape_expression.rb +1 -1
  25. data/lib/glimmer/dsl/swt/widget_expression.rb +4 -3
  26. data/lib/glimmer/launcher.rb +3 -0
  27. data/lib/glimmer/rake_task/scaffold.rb +3 -0
  28. data/lib/glimmer/swt/custom/code_text.rb +11 -11
  29. data/lib/glimmer/swt/custom/drawable.rb +4 -0
  30. data/lib/glimmer/swt/custom/shape.rb +129 -20
  31. data/lib/glimmer/swt/custom/shape/arc.rb +43 -0
  32. data/lib/glimmer/swt/custom/shape/focus.rb +43 -0
  33. data/lib/glimmer/swt/custom/shape/image.rb +86 -0
  34. data/lib/glimmer/swt/custom/shape/line.rb +58 -0
  35. data/lib/glimmer/swt/custom/shape/oval.rb +43 -0
  36. data/lib/glimmer/swt/custom/shape/point.rb +52 -0
  37. data/lib/glimmer/swt/custom/shape/polygon.rb +73 -0
  38. data/lib/glimmer/swt/custom/shape/polyline.rb +73 -0
  39. data/lib/glimmer/swt/custom/shape/rectangle.rb +87 -0
  40. data/lib/glimmer/swt/custom/shape/text.rb +73 -0
  41. data/lib/glimmer/swt/date_time_proxy.rb +9 -3
  42. data/lib/glimmer/swt/directory_dialog_proxy.rb +20 -18
  43. data/lib/glimmer/swt/display_proxy.rb +62 -2
  44. data/lib/glimmer/swt/expand_item_proxy.rb +18 -12
  45. data/lib/glimmer/swt/file_dialog_proxy.rb +20 -18
  46. data/lib/glimmer/swt/font_proxy.rb +1 -1
  47. data/lib/glimmer/swt/image_proxy.rb +1 -1
  48. data/lib/glimmer/swt/layout_data_proxy.rb +21 -15
  49. data/lib/glimmer/swt/layout_proxy.rb +19 -15
  50. data/lib/glimmer/swt/menu_proxy.rb +2 -2
  51. data/lib/glimmer/swt/message_box_proxy.rb +20 -7
  52. data/lib/glimmer/swt/scrolled_composite_proxy.rb +6 -2
  53. data/lib/glimmer/swt/shell_proxy.rb +94 -80
  54. data/lib/glimmer/swt/swt_proxy.rb +16 -0
  55. data/lib/glimmer/swt/tab_item_proxy.rb +5 -3
  56. data/lib/glimmer/swt/table_proxy.rb +32 -11
  57. data/lib/glimmer/swt/tree_proxy.rb +11 -16
  58. data/lib/glimmer/swt/widget_listener_proxy.rb +6 -2
  59. data/lib/glimmer/swt/widget_proxy.rb +200 -117
  60. data/lib/glimmer/ui.rb +5 -0
  61. data/lib/glimmer/ui/custom_shell.rb +11 -5
  62. data/lib/glimmer/ui/custom_widget.rb +4 -5
  63. data/samples/elaborate/contact_manager.rb +7 -7
  64. data/samples/elaborate/login.rb +25 -21
  65. data/samples/elaborate/mandelbrot_fractal.rb +3 -5
  66. data/samples/elaborate/tetris.rb +1 -0
  67. data/samples/elaborate/tic_tac_toe.rb +16 -14
  68. data/samples/elaborate/tic_tac_toe/board.rb +5 -5
  69. data/samples/elaborate/tic_tac_toe/cell.rb +5 -5
  70. data/samples/hello/hello_button.rb +7 -7
  71. data/samples/hello/hello_canvas.rb +43 -2
  72. data/samples/hello/hello_checkbox.rb +16 -14
  73. data/samples/hello/hello_checkbox_group.rb +11 -9
  74. data/samples/hello/hello_combo.rb +14 -12
  75. data/samples/hello/hello_computed.rb +7 -7
  76. data/samples/hello/hello_cursor.rb +2 -1
  77. data/samples/hello/hello_custom_shell.rb +17 -21
  78. data/samples/hello/hello_custom_widget.rb +4 -6
  79. data/samples/hello/hello_date_time.rb +14 -12
  80. data/samples/hello/hello_directory_dialog.rb +7 -7
  81. data/samples/hello/hello_expand_bar.rb +8 -8
  82. data/samples/hello/hello_file_dialog.rb +7 -7
  83. data/samples/hello/hello_group.rb +18 -16
  84. data/samples/hello/hello_list_multi_selection.rb +13 -11
  85. data/samples/hello/hello_list_single_selection.rb +13 -11
  86. data/samples/hello/hello_progress_bar.rb +3 -7
  87. data/samples/hello/hello_radio.rb +18 -16
  88. data/samples/hello/hello_radio_group.rb +14 -12
  89. data/samples/hello/hello_spinner.rb +7 -7
  90. data/samples/hello/hello_tab.rb +5 -5
  91. data/samples/hello/hello_table.rb +10 -5
  92. data/samples/hello/hello_tree.rb +485 -0
  93. metadata +17 -18
@@ -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
- recursive_depth_first_search(swt_widget.getItems.first, found, &condition)
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
- tree_item.getItems.each do |child_tree_item|
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
- depth_first_search {|ti| ti.getData == value}
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
- @swt_widget.removeListener(@event_type, @swt_listener)
56
+ DisplayProxy.instance.auto_exec do
57
+ @swt_widget.removeListener(@event_type, @swt_listener)
58
+ end
57
59
  else
58
- @swt_widget.send(widget_remove_listener_method, @swt_listener)
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)
@@ -50,7 +50,7 @@ module Glimmer
50
50
  DEFAULT_STYLES = {
51
51
  'arrow' => [:arrow],
52
52
  'button' => [:push],
53
- 'canvas' => [:double_buffered],
53
+ 'canvas' => ([:double_buffered] if OS.windows?),
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
- return swt_widget.get_data('proxy') if swt_widget&.get_data('proxy')
116
- keyword, parent, args = init_args
117
- selected_widget_proxy_class = widget_proxy_class(keyword || underscored_widget_name(swt_widget))
118
- if init_args.empty?
119
- selected_widget_proxy_class.new(swt_widget: swt_widget)
120
- else
121
- selected_widget_proxy_class.new(*init_args)
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
- @image_double_buffered = !!(init_args&.last&.include?(:image_double_buffered) && init_args&.last&.delete(:image_double_buffered))
153
- if swt_widget.nil?
154
- underscored_widget_name, parent, args = init_args
155
- @parent_proxy = parent
156
- styles, extra_options = extract_args(underscored_widget_name, args)
157
- swt_widget_class = self.class.swt_widget_class_for(underscored_widget_name)
158
- @swt_widget = swt_widget_class.new(@parent_proxy.swt_widget, style(underscored_widget_name, styles), *extra_options)
159
- else
160
- @swt_widget = swt_widget
161
- underscored_widget_name = self.class.underscored_widget_name(@swt_widget)
162
- parent_proxy_class = self.class.widget_proxy_class(self.class.underscored_widget_name(@swt_widget.parent))
163
- parent = swt_widget.parent
164
- @parent_proxy = parent&.get_data('proxy') || parent_proxy_class.new(swt_widget: parent)
165
- end
166
- if @swt_widget&.get_data('proxy').nil?
167
- @swt_widget.set_data('proxy', self)
168
- DEFAULT_INITIALIZERS[underscored_widget_name.to_s.to_sym]&.call(@swt_widget)
169
- @parent_proxy.post_initialize_child(self)
170
- end
171
- @keyword = underscored_widget_name.to_s
172
- if respond_to?(:on_widget_disposed)
173
- on_widget_disposed {
174
- clear_shapes
175
- deregister_shape_painting
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
 
@@ -223,7 +227,9 @@ module Glimmer
223
227
  def has_attribute_getter?(attribute_getter_name, *args)
224
228
  attribute_getter_name = attribute_getter_name.to_s.underscore
225
229
  return false unless !attribute_getter_name.end_with?('=') && !attribute_getter_name.start_with?('set_')
226
- args.empty? && swt_widget.respond_to?(attribute_getter_name)
230
+ auto_exec do
231
+ args.empty? && swt_widget.respond_to?(attribute_getter_name)
232
+ end
227
233
  end
228
234
 
229
235
  def has_attribute_setter?(attribute_setter_name, *args)
@@ -237,61 +243,88 @@ module Glimmer
237
243
  def has_attribute?(attribute_name, *args)
238
244
  # TODO test that attribute getter responds too
239
245
  widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
240
- if widget_custom_attribute
241
- @swt_widget.respond_to?(widget_custom_attribute[:setter][:name])
242
- else
243
- @swt_widget.respond_to?(attribute_setter(attribute_name), args) || respond_to?(ruby_attribute_setter(attribute_name), args)
246
+ auto_exec do
247
+ if widget_custom_attribute
248
+ @swt_widget.respond_to?(widget_custom_attribute[:setter][:name])
249
+ else
250
+ @swt_widget.respond_to?(attribute_setter(attribute_name), args) || respond_to?(ruby_attribute_setter(attribute_name), args)
251
+ end
244
252
  end
245
253
  end
246
254
 
247
255
  def set_attribute(attribute_name, *args)
248
256
  # TODO Think about widget subclasses overriding set_attribute to add more attributes vs adding as Ruby attributes directly
249
257
  widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
250
- apply_property_type_converters(normalized_attribute(attribute_name), args)
251
- if widget_custom_attribute
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)
258
+ auto_exec do
259
+ apply_property_type_converters(normalized_attribute(attribute_name), args)
259
260
  end
261
+ swt_widget_operation = false
262
+ result = nil
263
+ auto_exec do
264
+ result = if widget_custom_attribute
265
+ swt_widget_operation = true
266
+ widget_custom_attribute[:setter][:invoker].call(@swt_widget, args)
267
+ elsif @swt_widget.respond_to?(attribute_setter(attribute_name))
268
+ swt_widget_operation = true
269
+ @swt_widget.send(attribute_setter(attribute_name), *args) unless @swt_widget.send(attribute_getter(attribute_name)) == args.first
270
+ elsif @swt_widget.respond_to?(ruby_attribute_setter(attribute_name))
271
+ swt_widget_operation = true
272
+ @swt_widget.send(ruby_attribute_setter(attribute_name), args)
273
+ end
274
+ end
275
+ unless swt_widget_operation
276
+ result = send(ruby_attribute_setter(attribute_name), args)
277
+ end
278
+ result
260
279
  end
261
280
 
262
281
  def get_attribute(attribute_name)
263
282
  widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
264
- if widget_custom_attribute
265
- if widget_custom_attribute[:getter][:invoker]
266
- widget_custom_attribute[:getter][:invoker].call(@swt_widget, [])
283
+ swt_widget_operation = false
284
+ result = nil
285
+ auto_exec do
286
+ result = if widget_custom_attribute
287
+ swt_widget_operation = true
288
+ if widget_custom_attribute[:getter][:invoker]
289
+ widget_custom_attribute[:getter][:invoker].call(@swt_widget, [])
290
+ else
291
+ @swt_widget.send(widget_custom_attribute[:getter][:name])
292
+ end
293
+ elsif @swt_widget.respond_to?(attribute_getter(attribute_name))
294
+ swt_widget_operation = true
295
+ @swt_widget.send(attribute_getter(attribute_name))
296
+ elsif @swt_widget.respond_to?(ruby_attribute_getter(attribute_name))
297
+ swt_widget_operation = true
298
+ @swt_widget.send(ruby_attribute_getter(attribute_name))
299
+ elsif @swt_widget.respond_to?(attribute_name)
300
+ swt_widget_operation = true
301
+ @swt_widget.send(attribute_name)
302
+ end
303
+ end
304
+ unless swt_widget_operation
305
+ result = if respond_to?(ruby_attribute_getter(attribute_name))
306
+ send(ruby_attribute_getter(attribute_name))
267
307
  else
268
- @swt_widget.send(widget_custom_attribute[:getter][:name])
308
+ send(attribute_name)
269
309
  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
310
  end
311
+ result
281
312
  end
282
313
 
283
314
  def pack_same_size
284
- bounds = @swt_widget.getBounds
285
- listener = on_control_resized {
286
- @swt_widget.setSize(bounds.width, bounds.height)
287
- @swt_widget.setLocation(bounds.x, bounds.y)
288
- }
289
- if @swt_widget.is_a?(Composite)
290
- @swt_widget.layout(true, true)
291
- else
292
- @swt_widget.pack(true)
315
+ auto_exec do
316
+ bounds = @swt_widget.getBounds
317
+ listener = on_control_resized {
318
+ @swt_widget.setSize(bounds.width, bounds.height)
319
+ @swt_widget.setLocation(bounds.x, bounds.y)
320
+ }
321
+ if @swt_widget.is_a?(Composite)
322
+ @swt_widget.layout(true, true)
323
+ else
324
+ @swt_widget.pack(true)
325
+ end
326
+ @swt_widget.removeControlListener(listener.swt_listener)
293
327
  end
294
- @swt_widget.removeControlListener(listener.swt_listener)
295
328
  end
296
329
 
297
330
  def widget_property_listener_installers
@@ -334,6 +367,17 @@ module Glimmer
334
367
  }
335
368
  end,
336
369
  },
370
+ Java::OrgEclipseSwtWidgets::Tree => {
371
+ :selection => lambda do |observer|
372
+ on_widget_selected { |selection_event|
373
+ if has_style?(:multi)
374
+ observer.call(@swt_widget.getSelection.map(&:get_data))
375
+ else
376
+ observer.call(@swt_widget.getSelection.first&.get_data)
377
+ end
378
+ }
379
+ end,
380
+ },
337
381
  Java::OrgEclipseSwtWidgets::Text => {
338
382
  :text => lambda do |observer|
339
383
  on_modify_text { |modify_event|
@@ -546,25 +590,37 @@ module Glimmer
546
590
  @flyweight_swt_widget_classes ||= {}
547
591
  end
548
592
 
593
+ # delegates to DisplayProxy
549
594
  def async_exec(&block)
550
595
  DisplayProxy.instance.async_exec(&block)
551
596
  end
552
597
 
598
+ # delegates to DisplayProxy
553
599
  def sync_exec(&block)
554
600
  DisplayProxy.instance.sync_exec(&block)
555
601
  end
556
602
 
603
+ # delegates to DisplayProxy
557
604
  def timer_exec(delay_in_millis, &block)
558
605
  DisplayProxy.instance.timer_exec(delay_in_millis, &block)
559
606
  end
560
607
 
608
+ # delegates to DisplayProxy
609
+ def auto_exec(override_sync_exec: nil, override_async_exec: nil, &block)
610
+ DisplayProxy.instance.auto_exec(override_sync_exec: override_sync_exec, override_async_exec: override_async_exec, &block)
611
+ end
612
+
561
613
  def has_style?(style)
562
614
  comparison = interpret_style(style)
563
- (@swt_widget.style & comparison) == comparison
615
+ auto_exec do
616
+ (@swt_widget.style & comparison) == comparison
617
+ end
564
618
  end
565
619
 
566
620
  def dispose
567
- @swt_widget.dispose
621
+ auto_exec do
622
+ @swt_widget.dispose
623
+ end
568
624
  end
569
625
 
570
626
  def disposed?
@@ -574,15 +630,19 @@ module Glimmer
574
630
  # TODO Consider renaming these methods as they are mainly used for data-binding
575
631
 
576
632
  def can_add_observer?(property_name)
577
- @swt_widget.class.ancestors.map {|ancestor| widget_property_listener_installers[ancestor]}.compact.map(&:keys).flatten.map(&:to_s).include?(property_name.to_s)
633
+ auto_exec do
634
+ @swt_widget.class.ancestors.map {|ancestor| widget_property_listener_installers[ancestor]}.compact.map(&:keys).flatten.map(&:to_s).include?(property_name.to_s)
635
+ end
578
636
  end
579
637
 
580
638
  # Used for data-binding only. Consider renaming or improving to avoid the confusion it causes
581
639
  def add_observer(observer, property_name)
582
640
  if !observer.respond_to?(:binding_options) || !observer.binding_options[:read_only]
583
- property_listener_installers = @swt_widget.class.ancestors.map {|ancestor| widget_property_listener_installers[ancestor]}.compact
584
- widget_listener_installers = property_listener_installers.map{|installer| installer[property_name.to_s.to_sym]}.compact if !property_listener_installers.empty?
585
- widget_listener_installers.to_a.first&.call(observer)
641
+ auto_exec do
642
+ property_listener_installers = @swt_widget.class.ancestors.map {|ancestor| widget_property_listener_installers[ancestor]}.compact
643
+ widget_listener_installers = property_listener_installers.map{|installer| installer[property_name.to_s.to_sym]}.compact if !property_listener_installers.empty?
644
+ widget_listener_installers.to_a.first&.call(observer)
645
+ end
586
646
  end
587
647
  end
588
648
 
@@ -619,13 +679,15 @@ module Glimmer
619
679
  end
620
680
 
621
681
  def can_handle_drag_observation_request?(observation_request)
622
- return false unless swt_widget.is_a?(Control)
623
- potential_drag_source = @drag_source_proxy.nil?
624
- ensure_drag_source_proxy
625
- @drag_source_proxy.can_handle_observation_request?(observation_request).tap do |result|
626
- if potential_drag_source && !result
627
- @drag_source_proxy.swt_widget.dispose
628
- @drag_source_proxy = nil
682
+ auto_exec do
683
+ return false unless swt_widget.is_a?(Control)
684
+ potential_drag_source = @drag_source_proxy.nil?
685
+ ensure_drag_source_proxy
686
+ @drag_source_proxy.can_handle_observation_request?(observation_request).tap do |result|
687
+ if potential_drag_source && !result
688
+ @drag_source_proxy.swt_widget.dispose
689
+ @drag_source_proxy = nil
690
+ end
629
691
  end
630
692
  end
631
693
  rescue => e
@@ -634,13 +696,15 @@ module Glimmer
634
696
  end
635
697
 
636
698
  def can_handle_drop_observation_request?(observation_request)
637
- return false unless swt_widget.is_a?(Control)
638
- potential_drop_target = @drop_target_proxy.nil?
639
- ensure_drop_target_proxy
640
- @drop_target_proxy.can_handle_observation_request?(observation_request).tap do |result|
641
- if potential_drop_target && !result
642
- @drop_target_proxy.swt_widget.dispose
643
- @drop_target_proxy = nil
699
+ auto_exec do
700
+ return false unless swt_widget.is_a?(Control)
701
+ potential_drop_target = @drop_target_proxy.nil?
702
+ ensure_drop_target_proxy
703
+ @drop_target_proxy.can_handle_observation_request?(observation_request).tap do |result|
704
+ if potential_drop_target && !result
705
+ @drop_target_proxy.swt_widget.dispose
706
+ @drop_target_proxy = nil
707
+ end
644
708
  end
645
709
  end
646
710
  end
@@ -664,7 +728,9 @@ module Glimmer
664
728
  end
665
729
 
666
730
  def content(&block)
667
- Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::WidgetExpression.new, &block)
731
+ auto_exec do
732
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::WidgetExpression.new, &block)
733
+ end
668
734
  end
669
735
 
670
736
  def method_missing(method, *args, &block)
@@ -675,19 +741,26 @@ module Glimmer
675
741
  elsif has_attribute_getter?(method, *args)
676
742
  get_attribute(method, *args)
677
743
  else
678
- swt_widget.send(method, *args, &block)
744
+ auto_exec do
745
+ swt_widget.send(method, *args, &block)
746
+ end
679
747
  end
680
748
  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
749
+ begin
750
+ super
751
+ rescue Exception => inner_error
752
+ Glimmer::Config.logger.error { "Neither WidgetProxy nor #{swt_widget.class.name} can handle the method ##{method}" }
753
+ Glimmer::Config.logger.error { e.full_message }
754
+ raise inner_error
755
+ end
685
756
  end
686
757
 
687
758
  def respond_to?(method, *args, &block)
688
- super ||
689
- can_handle_observation_request?(method) ||
690
- swt_widget.respond_to?(method, *args, &block)
759
+ result = super
760
+ return true if result
761
+ auto_exec do
762
+ can_handle_observation_request?(method) || swt_widget.respond_to?(method, *args, &block)
763
+ end
691
764
  end
692
765
 
693
766
  private
@@ -713,22 +786,26 @@ module Glimmer
713
786
  # add_listener knowing it will be called for sure afterwards
714
787
 
715
788
  def can_add_listener?(underscored_listener_name)
716
- !self.class.find_listener(@swt_widget.getClass, underscored_listener_name).empty?
789
+ auto_exec do
790
+ !self.class.find_listener(@swt_widget.getClass, underscored_listener_name).empty?
791
+ end
717
792
  end
718
793
 
719
794
  def add_listener(underscored_listener_name, &block)
720
- widget_add_listener_method, listener_class, listener_method = self.class.find_listener(@swt_widget.getClass, underscored_listener_name)
721
- widget_listener_proxy = nil
722
- safe_block = lambda do |*args|
723
- begin
724
- block.call(*args) unless @swt_widget.isDisposed
725
- rescue => e
726
- Glimmer::Config.logger.error {e}
795
+ auto_exec do
796
+ widget_add_listener_method, listener_class, listener_method = self.class.find_listener(@swt_widget.getClass, underscored_listener_name)
797
+ widget_listener_proxy = nil
798
+ safe_block = lambda do |*args|
799
+ begin
800
+ block.call(*args) unless @swt_widget.isDisposed
801
+ rescue => e
802
+ Glimmer::Config.logger.error {e}
803
+ end
727
804
  end
805
+ listener = listener_class.new(listener_method => safe_block)
806
+ @swt_widget.send(widget_add_listener_method, listener)
807
+ 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
808
  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
809
  end
733
810
 
734
811
  # Looks through SWT class add***Listener methods till it finds one for which
@@ -778,11 +855,13 @@ module Glimmer
778
855
  end
779
856
 
780
857
  def add_swt_event_listener(swt_constant, &block)
781
- event_type = SWTProxy[swt_constant]
782
- widget_listener_proxy = nil
783
- safe_block = lambda { |*args| block.call(*args) unless @swt_widget.isDisposed }
784
- @swt_widget.addListener(event_type, &safe_block)
785
- 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)
858
+ auto_exec do
859
+ event_type = SWTProxy[swt_constant]
860
+ widget_listener_proxy = nil
861
+ safe_block = lambda { |*args| block.call(*args) unless @swt_widget.isDisposed }
862
+ @swt_widget.addListener(event_type, &safe_block)
863
+ 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)
864
+ end
786
865
  end
787
866
 
788
867
  def widget_custom_attribute_mapping
@@ -905,7 +984,7 @@ module Glimmer
905
984
  while last_image_number != image_number
906
985
  last_image_number = image_number
907
986
  sync_exec {
908
- redraw
987
+ redraw unless disposed?
909
988
  }
910
989
  delayTime = loader.data[image_number].delayTime.to_f / 100.0
911
990
  sleep(delayTime)
@@ -954,6 +1033,10 @@ module Glimmer
954
1033
  items: lambda do |value|
955
1034
  value.to_java :string
956
1035
  end,
1036
+ selection: lambda do |value|
1037
+ value = value.to_f if swt_widget.is_a?(Spinner)
1038
+ value
1039
+ end,
957
1040
  text: lambda do |value|
958
1041
  value.to_s
959
1042
  end,