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.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +73 -0
  3. data/README.md +14 -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 +464 -149
  8. data/docs/reference/GLIMMER_SAMPLES.md +91 -4
  9. data/glimmer-dsl-swt.gemspec +24 -13
  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 +13 -15
  15. data/lib/glimmer/dsl/swt/{file_dialog_expression.rb → auto_exec_expression.rb} +6 -18
  16. data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +9 -6
  17. data/lib/glimmer/dsl/swt/color_expression.rb +1 -1
  18. data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +16 -14
  19. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +4 -1
  20. data/lib/glimmer/dsl/swt/data_binding_expression.rb +2 -2
  21. data/lib/glimmer/dsl/swt/dialog_expression.rb +18 -9
  22. data/lib/glimmer/dsl/swt/dsl.rb +1 -0
  23. data/lib/glimmer/dsl/swt/exec_expression.rb +1 -1
  24. data/lib/glimmer/dsl/swt/font_expression.rb +1 -1
  25. data/lib/glimmer/dsl/swt/image_expression.rb +16 -2
  26. data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +11 -8
  27. data/lib/glimmer/dsl/swt/pixel_expression.rb +1 -1
  28. data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +8 -5
  29. data/lib/glimmer/dsl/swt/shape_expression.rb +2 -2
  30. data/lib/glimmer/dsl/swt/shell_expression.rb +5 -2
  31. data/lib/glimmer/dsl/swt/widget_expression.rb +8 -4
  32. data/lib/glimmer/launcher.rb +3 -0
  33. data/lib/glimmer/rake_task/scaffold.rb +3 -0
  34. data/lib/glimmer/swt/color_proxy.rb +1 -1
  35. data/lib/glimmer/swt/custom/code_text.rb +33 -11
  36. data/lib/glimmer/swt/custom/drawable.rb +55 -0
  37. data/lib/glimmer/swt/custom/shape.rb +187 -43
  38. data/lib/glimmer/swt/custom/shape/arc.rb +60 -0
  39. data/lib/glimmer/{dsl/swt/directory_dialog_expression.rb → swt/custom/shape/focus.rb} +15 -20
  40. data/lib/glimmer/swt/custom/shape/image.rb +99 -0
  41. data/lib/glimmer/swt/custom/shape/line.rb +65 -0
  42. data/lib/glimmer/swt/custom/shape/oval.rb +61 -0
  43. data/lib/glimmer/swt/custom/shape/point.rb +54 -0
  44. data/lib/glimmer/swt/custom/shape/polygon.rb +73 -0
  45. data/lib/glimmer/swt/custom/shape/polyline.rb +74 -0
  46. data/lib/glimmer/swt/custom/shape/rectangle.rb +101 -0
  47. data/lib/glimmer/swt/custom/shape/text.rb +85 -0
  48. data/lib/glimmer/swt/date_time_proxy.rb +9 -3
  49. data/lib/glimmer/swt/dialog_proxy.rb +92 -0
  50. data/lib/glimmer/swt/display_proxy.rb +62 -2
  51. data/lib/glimmer/swt/expand_item_proxy.rb +18 -12
  52. data/lib/glimmer/swt/font_proxy.rb +13 -7
  53. data/lib/glimmer/swt/image_proxy.rb +15 -4
  54. data/lib/glimmer/swt/layout_data_proxy.rb +21 -15
  55. data/lib/glimmer/swt/layout_proxy.rb +19 -15
  56. data/lib/glimmer/swt/menu_proxy.rb +2 -2
  57. data/lib/glimmer/swt/message_box_proxy.rb +21 -7
  58. data/lib/glimmer/swt/properties.rb +3 -0
  59. data/lib/glimmer/swt/proxy_properties.rb +145 -0
  60. data/lib/glimmer/swt/scrolled_composite_proxy.rb +6 -2
  61. data/lib/glimmer/swt/shell_proxy.rb +96 -80
  62. data/lib/glimmer/swt/swt_proxy.rb +17 -0
  63. data/lib/glimmer/swt/tab_item_proxy.rb +5 -3
  64. data/lib/glimmer/swt/table_proxy.rb +32 -11
  65. data/lib/glimmer/swt/transform_proxy.rb +39 -35
  66. data/lib/glimmer/swt/tree_proxy.rb +11 -16
  67. data/lib/glimmer/swt/widget_listener_proxy.rb +6 -2
  68. data/lib/glimmer/swt/widget_proxy.rb +192 -141
  69. data/lib/glimmer/ui.rb +5 -0
  70. data/lib/glimmer/ui/custom_shell.rb +13 -7
  71. data/lib/glimmer/ui/custom_widget.rb +4 -5
  72. data/samples/elaborate/contact_manager.rb +7 -7
  73. data/samples/elaborate/login.rb +25 -21
  74. data/samples/elaborate/mandelbrot_fractal.rb +87 -31
  75. data/samples/elaborate/meta_sample.rb +1 -1
  76. data/samples/elaborate/tetris.rb +1 -0
  77. data/samples/elaborate/tic_tac_toe.rb +16 -14
  78. data/samples/elaborate/tic_tac_toe/board.rb +5 -5
  79. data/samples/elaborate/tic_tac_toe/cell.rb +5 -5
  80. data/samples/hello/hello_button.rb +7 -7
  81. data/samples/hello/hello_canvas.rb +143 -41
  82. data/samples/hello/hello_checkbox.rb +16 -14
  83. data/samples/hello/hello_checkbox_group.rb +11 -9
  84. data/samples/hello/hello_color_dialog.rb +66 -0
  85. data/samples/hello/hello_combo.rb +14 -12
  86. data/samples/hello/hello_computed.rb +7 -7
  87. data/samples/hello/hello_cursor.rb +2 -1
  88. data/samples/hello/hello_custom_shell.rb +17 -21
  89. data/samples/hello/hello_custom_widget.rb +4 -6
  90. data/samples/hello/hello_date_time.rb +14 -12
  91. data/samples/hello/hello_directory_dialog.rb +7 -7
  92. data/samples/hello/hello_expand_bar.rb +8 -8
  93. data/samples/hello/hello_file_dialog.rb +7 -7
  94. data/samples/hello/hello_font_dialog.rb +82 -0
  95. data/samples/hello/hello_group.rb +18 -16
  96. data/samples/hello/hello_list_multi_selection.rb +13 -11
  97. data/samples/hello/hello_list_single_selection.rb +13 -11
  98. data/samples/hello/hello_progress_bar.rb +125 -0
  99. data/samples/hello/hello_radio.rb +18 -16
  100. data/samples/hello/hello_radio_group.rb +14 -12
  101. data/samples/hello/hello_spinner.rb +7 -7
  102. data/samples/hello/hello_tab.rb +5 -5
  103. data/samples/hello/hello_table.rb +10 -5
  104. data/samples/hello/hello_tree.rb +485 -0
  105. metadata +22 -22
  106. data/lib/glimmer/swt/directory_dialog_proxy.rb +0 -65
  107. data/lib/glimmer/swt/file_dialog_proxy.rb +0 -66
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2021 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -52,15 +52,19 @@ module Glimmer
52
52
  layout.marginWidth = 0
53
53
  layout.marginHeight = 0
54
54
  layout.spacing = 0
55
- swt_widget.layout = layout
56
- @widget_proxy = SWT::WidgetProxy.new('expand_item', parent, style)
57
- @swt_expand_item = @widget_proxy.swt_widget
58
- @swt_expand_item.control = swt_widget
59
- @swt_expand_item.expanded = true
55
+ swt_widget.layout = layout
56
+ auto_exec do
57
+ @widget_proxy = SWT::WidgetProxy.new('expand_item', parent, style)
58
+ @swt_expand_item = @widget_proxy.swt_widget
59
+ @swt_expand_item.control = swt_widget
60
+ @swt_expand_item.expanded = true
61
+ end
60
62
  end
61
63
 
62
64
  def post_add_content
63
- @swt_expand_item.setHeight(swt_widget.computeSize(SWTProxy[:default], SWTProxy[:default]).y) unless @swt_expand_item.getHeight > 0
65
+ auto_exec do
66
+ @swt_expand_item.setHeight(swt_widget.computeSize(SWTProxy[:default], SWTProxy[:default]).y) unless @swt_expand_item.getHeight > 0
67
+ end
64
68
  end
65
69
 
66
70
  def has_attribute?(attribute_name, *args)
@@ -88,9 +92,11 @@ module Glimmer
88
92
  end
89
93
 
90
94
  def dispose
91
- swt_expand_item.setControl(nil)
92
- swt_widget.dispose
93
- swt_expand_item.dispose
95
+ auto_exec do
96
+ swt_expand_item.setControl(nil)
97
+ swt_widget.dispose
98
+ swt_expand_item.dispose
99
+ end
94
100
  end
95
101
  end
96
102
  end
@@ -54,13 +54,19 @@ module Glimmer
54
54
  # that is :normal, :bold, or :italic
55
55
  def initialize(widget_proxy = nil, font_properties)
56
56
  @widget_proxy = widget_proxy
57
- @font_properties = font_properties
58
- detect_invalid_font_property(font_properties)
59
- font_properties[:style] = SWTProxy[*font_properties[:style]]
60
- font_data_args = [:name, :height, :style].map do |font_property_name|
61
- font_properties[font_property_name] || send(font_property_name)
57
+ if font_properties.is_a?(FontData)
58
+ font_datum = font_properties
59
+ @font_properties = {name: font_properties.name, height: font_properties.height, style: font_properties.style}
60
+ elsif font_properties.is_a?(Hash)
61
+ @font_properties = font_properties
62
+ detect_invalid_font_property(font_properties)
63
+ font_properties[:style] = SWTProxy[*font_properties[:style]]
64
+ # TODO consider supporting other properties like locale in the future
65
+ font_data_args = [:name, :height, :style].map do |font_property_name|
66
+ font_properties[font_property_name] || send(font_property_name)
67
+ end
68
+ font_datum = FontData.new(*font_data_args)
62
69
  end
63
- font_datum = FontData.new(*font_data_args)
64
70
  @swt_font = Font.new(DisplayProxy.instance.swt_display, font_datum)
65
71
  end
66
72
 
@@ -79,7 +85,7 @@ module Glimmer
79
85
  private
80
86
 
81
87
  def font_datum
82
- @font_datum ||= @widget_proxy ? @widget_proxy.swt_widget.getFont.getFontData[0] : FontData.new
88
+ @font_datum ||= DisplayProxy.instance.auto_exec { @widget_proxy ? @widget_proxy.swt_widget.getFont.getFontData[0] : FontData.new }
83
89
  end
84
90
 
85
91
  def detect_invalid_font_property(font_properties)
@@ -34,13 +34,24 @@ module Glimmer
34
34
  include Properties
35
35
 
36
36
  class << self
37
- def create(*args)
37
+ include_package 'org.eclipse.swt.graphics'
38
+
39
+ def create(*args, &content)
38
40
  if args.size == 1 && args.first.is_a?(ImageProxy)
39
41
  args.first
40
42
  else
41
- new(*args)
43
+ new(*args, &content)
42
44
  end
43
45
  end
46
+
47
+ def create_pixel_by_pixel(*args, &each_pixel_color)
48
+ image_proxy = create(*args)
49
+ options = args.last.is_a?(Hash) ? args.pop : {}
50
+ height = args[-1]
51
+ width = args[-2]
52
+ image_proxy.paint_pixel_by_pixel(width, height, &each_pixel_color)
53
+ image_proxy
54
+ end
44
55
  end
45
56
 
46
57
  include_package 'org.eclipse.swt.widgets'
@@ -88,7 +99,7 @@ module Glimmer
88
99
  # TODO consider adding a get_data/set_data method to conform with other SWT widgets
89
100
  @swt_image.singleton_class.define_method(:dispose) do
90
101
  proxy.clear_shapes
91
- super
102
+ super()
92
103
  end
93
104
  post_add_content if content.nil?
94
105
  end
@@ -121,7 +132,7 @@ module Glimmer
121
132
  end
122
133
 
123
134
  def scale_to(width, height)
124
- return if @image_data.width == width && @image_data.height == height
135
+ return self if @image_data.width == width && @image_data.height == height
125
136
  scaled_image_data = @original_image_data.scaledTo(width, height)
126
137
  device = swt_image.device
127
138
  swt_image.dispose
@@ -47,15 +47,17 @@ module Glimmer
47
47
 
48
48
  # Inititalizes with owning widget proxy and layout data arguments
49
49
  def initialize(widget_proxy, args)
50
- @widget_proxy = widget_proxy
51
- args = SWTProxy.constantify_args(args)
52
- begin
53
- @swt_layout_data = swt_layout_data_class.new(*args)
54
- rescue => e
55
- Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
56
- @swt_layout_data = args.first if args.count == 1
50
+ DisplayProxy.instance.auto_exec do
51
+ @widget_proxy = widget_proxy
52
+ args = SWTProxy.constantify_args(args)
53
+ begin
54
+ @swt_layout_data = swt_layout_data_class.new(*args)
55
+ rescue => e
56
+ Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
57
+ @swt_layout_data = args.first if args.count == 1
58
+ end
59
+ @widget_proxy.swt_widget.setLayoutData(@swt_layout_data)
57
60
  end
58
- @widget_proxy.swt_widget.setLayoutData(@swt_layout_data)
59
61
  end
60
62
 
61
63
  # This figures out the right SWT layout data class name
@@ -72,9 +74,11 @@ module Glimmer
72
74
  # - org.eclipse.swt.layout.GridData for org.eclipse.swt.layout.GridLayout
73
75
  #
74
76
  def swt_layout_data_class
75
- parent_layout_class_name = @widget_proxy.swt_widget.getParent.getLayout.class.name
76
- layout_data_class_name = parent_layout_class_name.sub(/Layout$/, 'Data')
77
- eval(layout_data_class_name)
77
+ DisplayProxy.instance.auto_exec do
78
+ parent_layout_class_name = @widget_proxy.swt_widget.getParent.getLayout.class.name
79
+ layout_data_class_name = parent_layout_class_name.sub(/Layout$/, 'Data')
80
+ eval(layout_data_class_name)
81
+ end
78
82
  end
79
83
 
80
84
  def has_attribute?(attribute_name, *args)
@@ -82,10 +86,12 @@ module Glimmer
82
86
  end
83
87
 
84
88
  def set_attribute(attribute_name, *args)
85
- args = SWTProxy.constantify_args(args)
86
- if args.first != @swt_layout_data.send(attribute_getter(attribute_name))
87
- @swt_layout_data.send(attribute_setter(attribute_name), *args)
88
- @widget_proxy.swt_widget.getShell.pack
89
+ DisplayProxy.instance.auto_exec do
90
+ args = SWTProxy.constantify_args(args)
91
+ if args.first != @swt_layout_data.send(attribute_getter(attribute_name))
92
+ @swt_layout_data.send(attribute_setter(attribute_name), *args)
93
+ @widget_proxy.swt_widget.getShell.pack
94
+ end
89
95
  end
90
96
  end
91
97
 
@@ -62,19 +62,21 @@ module Glimmer
62
62
  end
63
63
 
64
64
  def initialize(underscored_layout_name, widget_proxy, args)
65
- @underscored_layout_name = underscored_layout_name
66
- @widget_proxy = widget_proxy
67
- args = SWTProxy.constantify_args(args)
68
- @swt_layout = self.class.swt_layout_class_for(underscored_layout_name).new(*args)
69
- @swt_layout.marginWidth = 15 if @swt_layout.respond_to?(:marginWidth)
70
- @swt_layout.marginHeight = 15 if @swt_layout.respond_to?(:marginHeight)
71
- @swt_layout.marginTop = 0 if @swt_layout.respond_to?(:marginTop)
72
- @swt_layout.marginRight = 0 if @swt_layout.respond_to?(:marginRight)
73
- @swt_layout.marginBottom = 0 if @swt_layout.respond_to?(:marginBottom)
74
- @swt_layout.marginLeft = 0 if @swt_layout.respond_to?(:marginLeft)
75
- old_layout = @widget_proxy.swt_widget.getLayout
76
- @widget_proxy.swt_widget.setLayout(@swt_layout)
77
- @widget_proxy.swt_widget.layout if old_layout
65
+ DisplayProxy.instance.auto_exec do
66
+ @underscored_layout_name = underscored_layout_name
67
+ @widget_proxy = widget_proxy
68
+ args = SWTProxy.constantify_args(args)
69
+ @swt_layout = self.class.swt_layout_class_for(underscored_layout_name).new(*args)
70
+ @swt_layout.marginWidth = 15 if @swt_layout.respond_to?(:marginWidth)
71
+ @swt_layout.marginHeight = 15 if @swt_layout.respond_to?(:marginHeight)
72
+ @swt_layout.marginTop = 0 if @swt_layout.respond_to?(:marginTop)
73
+ @swt_layout.marginRight = 0 if @swt_layout.respond_to?(:marginRight)
74
+ @swt_layout.marginBottom = 0 if @swt_layout.respond_to?(:marginBottom)
75
+ @swt_layout.marginLeft = 0 if @swt_layout.respond_to?(:marginLeft)
76
+ old_layout = @widget_proxy.swt_widget.getLayout
77
+ @widget_proxy.swt_widget.setLayout(@swt_layout)
78
+ @widget_proxy.swt_widget.layout if old_layout
79
+ end
78
80
  end
79
81
 
80
82
  def has_attribute?(attribute_name, *args)
@@ -82,11 +84,13 @@ module Glimmer
82
84
  end
83
85
 
84
86
  def set_attribute(attribute_name, *args)
85
- apply_property_type_converters(attribute_name, args)
86
- if args.first != @swt_layout.send(attribute_getter(attribute_name))
87
+ DisplayProxy.instance.auto_exec do
88
+ apply_property_type_converters(attribute_name, args)
89
+ if args.first != @swt_layout.send(attribute_getter(attribute_name))
87
90
  @swt_layout.send(attribute_setter(attribute_name), *args)
88
91
  @widget_proxy.swt_widget.layout
89
92
  @widget_proxy.swt_widget.getShell.layout
93
+ end
90
94
  end
91
95
  end
92
96
 
@@ -68,9 +68,9 @@ module Glimmer
68
68
  end
69
69
 
70
70
  if styles.include?(:bar)
71
- parent.swt_widget.setMenuBar(swt_widget)
71
+ DisplayProxy.instance.auto_exec { parent.swt_widget.setMenuBar(swt_widget) }
72
72
  elsif styles.include?(:pop_up)
73
- parent.swt_widget.setMenu(swt_widget)
73
+ DisplayProxy.instance.auto_exec { parent.swt_widget.setMenu(swt_widget) }
74
74
  end
75
75
  end
76
76
 
@@ -35,6 +35,7 @@ module Glimmer
35
35
  attr_reader :swt_widget
36
36
 
37
37
  def initialize(parent, style)
38
+ # TODO consider consolidating with DialogProxy if it makes sense
38
39
  if parent.nil?
39
40
  @temporary_parent = parent = Glimmer::SWT::ShellProxy.new.swt_widget
40
41
  end
@@ -42,8 +43,10 @@ module Glimmer
42
43
  end
43
44
 
44
45
  def open
45
- @swt_widget.open.tap do |result|
46
- @temporary_parent&.dispose
46
+ DisplayProxy.instance.auto_exec do
47
+ @swt_widget.open.tap do |result|
48
+ @temporary_parent&.dispose
49
+ end
47
50
  end
48
51
  end
49
52
 
@@ -66,18 +69,29 @@ module Glimmer
66
69
  end
67
70
 
68
71
  def set_attribute(attribute_name, *args)
69
- @swt_widget.send(attribute_setter(attribute_name), *args) unless @swt_widget.send(attribute_getter(attribute_name)) == args.first
72
+ DisplayProxy.instance.auto_exec do
73
+ @swt_widget.send(attribute_setter(attribute_name), *args) unless @swt_widget.send(attribute_getter(attribute_name)) == args.first
74
+ end
70
75
  end
71
76
 
72
77
  def get_attribute(attribute_name)
73
- @swt_widget.send(attribute_getter(attribute_name))
78
+ DisplayProxy.instance.auto_exec do
79
+ @swt_widget.send(attribute_getter(attribute_name))
80
+ end
74
81
  end
75
82
 
76
83
  def method_missing(method, *args, &block)
77
- swt_widget.send(method, *args, &block)
84
+ DisplayProxy.instance.auto_exec do
85
+ swt_widget.send(method, *args, &block)
86
+ end
78
87
  rescue => e
79
- Glimmer::Config.logger.debug {"Neither MessageBoxProxy nor #{swt_widget.class.name} can handle the method ##{method}"}
80
- super
88
+ begin
89
+ super
90
+ rescue Exception => inner_error
91
+ Glimmer::Config.logger.error {"Neither MessageBoxProxy nor #{swt_widget.class.name} can handle the method ##{method}"}
92
+ Glimmer::Config.logger.error {e.full_message}
93
+ raise inner_error
94
+ end
81
95
  end
82
96
 
83
97
  def respond_to?(method, *args, &block)
@@ -69,6 +69,9 @@ module Glimmer
69
69
  Glimmer::SWT::Properties.normalized_attribute(attribute_name)
70
70
  end
71
71
  alias ruby_attribute_getter normalized_attribute
72
+
72
73
  end
74
+
73
75
  end
76
+
74
77
  end
@@ -0,0 +1,145 @@
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/swt/properties'
23
+
24
+ module Glimmer
25
+ module SWT
26
+ # Provides a default implementation for proxy properties, that is
27
+ # properties that come from a proxy object source such as swt_widget
28
+ # having Java camelcase format
29
+ module ProxyProperties
30
+ include Properties
31
+
32
+ # Subclasses must override to privde a proxy source if they want to take advantage of
33
+ # default implementation of attribute setters/getters
34
+ # It tries swt_widget, swt_display, swt_image, and swt_dialog by default.
35
+ def proxy_source_object
36
+ if respond_to?(:swt_widget)
37
+ swt_widget
38
+ elsif respond_to?(:swt_display)
39
+ swt_display
40
+ elsif respond_to?(:swt_image)
41
+ swt_image
42
+ elsif respond_to?(:swt_dialog)
43
+ swt_dialog
44
+ elsif respond_to?(:swt_transform)
45
+ swt_transform
46
+ end
47
+ end
48
+
49
+ def has_attribute_getter?(attribute_getter_name, *args)
50
+ attribute_getter_name = attribute_getter_name.to_s.underscore
51
+ return false unless !attribute_getter_name.end_with?('=') && !attribute_getter_name.start_with?('set_')
52
+ args.empty? && proxy_source_object&.respond_to?(attribute_getter_name)
53
+ end
54
+
55
+ def has_attribute_setter?(attribute_setter_name, *args)
56
+ attribute_setter_name = attribute_setter_name.to_s
57
+ underscored_attribute_setter_name = attribute_setter_name.underscore
58
+ return false unless attribute_setter_name.end_with?('=') || (attribute_setter_name.start_with?('set_') && !args.empty?)
59
+ attribute_name = underscored_attribute_setter_name.sub(/^set_/, '').sub(/=$/, '')
60
+ has_attribute?(attribute_name, *args)
61
+ end
62
+
63
+ def has_attribute?(attribute_name, *args)
64
+ Glimmer::SWT::DisplayProxy.instance.auto_exec do
65
+ proxy_source_object&.respond_to?(attribute_setter(attribute_name), args) ||
66
+ respond_to?(ruby_attribute_setter(attribute_name), args)
67
+ end
68
+ end
69
+
70
+ def set_attribute(attribute_name, *args)
71
+ swt_widget_operation = false
72
+ result = nil
73
+ Glimmer::SWT::DisplayProxy.instance.auto_exec do
74
+ result = if proxy_source_object&.respond_to?(attribute_setter(attribute_name))
75
+ swt_widget_operation = true
76
+ proxy_source_object&.send(attribute_setter(attribute_name), *args) unless proxy_source_object&.send(attribute_getter(attribute_name)) == args.first
77
+ elsif proxy_source_object&.respond_to?(ruby_attribute_setter(attribute_name))
78
+ swt_widget_operation = true
79
+ proxy_source_object&.send(ruby_attribute_setter(attribute_name), args)
80
+ end
81
+ end
82
+ unless swt_widget_operation
83
+ result = send(ruby_attribute_setter(attribute_name), args)
84
+ end
85
+ result
86
+ end
87
+
88
+ def get_attribute(attribute_name)
89
+ swt_widget_operation = false
90
+ result = nil
91
+ Glimmer::SWT::DisplayProxy.instance.auto_exec do
92
+ result = if proxy_source_object&.respond_to?(attribute_getter(attribute_name))
93
+ swt_widget_operation = true
94
+ proxy_source_object&.send(attribute_getter(attribute_name))
95
+ elsif proxy_source_object&.respond_to?(ruby_attribute_getter(attribute_name))
96
+ swt_widget_operation = true
97
+ proxy_source_object&.send(ruby_attribute_getter(attribute_name))
98
+ elsif proxy_source_object&.respond_to?(attribute_name)
99
+ swt_widget_operation = true
100
+ proxy_source_object&.send(attribute_name)
101
+ end
102
+ end
103
+ unless swt_widget_operation
104
+ result = if respond_to?(ruby_attribute_getter(attribute_name))
105
+ send(ruby_attribute_getter(attribute_name))
106
+ else
107
+ send(attribute_name)
108
+ end
109
+ end
110
+ result
111
+ end
112
+
113
+ def method_missing(method, *args, &block)
114
+ if has_attribute_setter?(method, *args)
115
+ set_attribute(method, *args)
116
+ elsif has_attribute_getter?(method, *args)
117
+ get_attribute(method, *args)
118
+ else
119
+ Glimmer::SWT::DisplayProxy.instance.auto_exec do
120
+ proxy_source_object&.send(method, *args, &block)
121
+ end
122
+ end
123
+ rescue => e
124
+ begin
125
+ super
126
+ rescue Exception => inner_error
127
+ Glimmer::Config.logger.error { "Neither self.class.name nor #{proxy_source_object&.class.name} can handle the method ##{method}" }
128
+ Glimmer::Config.logger.error { e.full_message }
129
+ raise inner_error
130
+ end
131
+ end
132
+
133
+ def respond_to?(method, *args, &block)
134
+ result = super
135
+ return true if result
136
+ Glimmer::SWT::DisplayProxy.instance.auto_exec do
137
+ proxy_source_object&.respond_to?(method, *args, &block)
138
+ end
139
+ end
140
+
141
+ end
142
+
143
+ end
144
+
145
+ end