glimmer-dsl-swt 4.18.4.10 → 4.18.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +71 -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 +451 -112
- data/docs/reference/GLIMMER_SAMPLES.md +76 -3
- data/glimmer-dsl-swt.gemspec +23 -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 +12 -27
- 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 +1 -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 +1 -1
- 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 +57 -1
- data/lib/glimmer/swt/custom/shape.rb +332 -48
- 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 +112 -0
- data/lib/glimmer/swt/custom/shape/line.rb +111 -0
- data/lib/glimmer/swt/custom/shape/oval.rb +61 -0
- data/lib/glimmer/swt/custom/shape/point.rb +49 -0
- data/lib/glimmer/swt/custom/shape/polygon.rb +114 -0
- data/lib/glimmer/swt/custom/shape/polyline.rb +115 -0
- data/lib/glimmer/swt/custom/shape/rectangle.rb +105 -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 +94 -80
- data/lib/glimmer/swt/swt_proxy.rb +16 -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 +193 -138
- data/lib/glimmer/ui.rb +5 -0
- data/lib/glimmer/ui/custom_shell.rb +11 -5
- data/lib/glimmer/ui/custom_widget.rb +4 -5
- data/samples/elaborate/contact_manager.rb +9 -7
- data/samples/elaborate/login.rb +27 -21
- data/samples/elaborate/mandelbrot_fractal.rb +20 -25
- data/samples/elaborate/meta_sample.rb +2 -1
- data/samples/elaborate/tetris.rb +3 -1
- data/samples/elaborate/tic_tac_toe.rb +18 -14
- data/samples/elaborate/tic_tac_toe/board.rb +5 -5
- data/samples/elaborate/tic_tac_toe/cell.rb +5 -5
- data/samples/elaborate/user_profile.rb +10 -8
- data/samples/hello/hello_browser.rb +2 -0
- data/samples/hello/hello_button.rb +9 -7
- data/samples/hello/hello_canvas.rb +144 -40
- data/samples/hello/hello_canvas_animation.rb +2 -0
- data/samples/hello/hello_canvas_transform.rb +2 -0
- data/samples/hello/hello_checkbox.rb +18 -14
- data/samples/hello/hello_checkbox_group.rb +13 -9
- data/samples/hello/hello_code_text.rb +2 -0
- data/samples/hello/hello_color_dialog.rb +68 -0
- data/samples/hello/hello_combo.rb +16 -12
- data/samples/hello/hello_computed.rb +9 -7
- data/samples/hello/hello_cursor.rb +4 -1
- data/samples/hello/hello_custom_shell.rb +18 -21
- data/samples/hello/hello_custom_widget.rb +6 -6
- data/samples/hello/hello_date_time.rb +16 -12
- data/samples/hello/hello_dialog.rb +2 -0
- data/samples/hello/hello_directory_dialog.rb +9 -7
- data/samples/hello/hello_drag_and_drop.rb +5 -3
- data/samples/hello/hello_expand_bar.rb +10 -8
- data/samples/hello/hello_file_dialog.rb +9 -7
- data/samples/hello/hello_font_dialog.rb +84 -0
- data/samples/hello/hello_group.rb +20 -16
- data/samples/hello/hello_link.rb +2 -0
- data/samples/hello/hello_list_multi_selection.rb +15 -11
- data/samples/hello/hello_list_single_selection.rb +15 -11
- data/samples/hello/hello_menu_bar.rb +2 -0
- data/samples/hello/hello_message_box.rb +2 -0
- data/samples/hello/hello_pop_up_context_menu.rb +2 -0
- data/samples/hello/hello_progress_bar.rb +5 -5
- data/samples/hello/hello_radio.rb +20 -16
- data/samples/hello/hello_radio_group.rb +16 -12
- data/samples/hello/hello_sash_form.rb +2 -0
- data/samples/hello/hello_spinner.rb +9 -7
- data/samples/hello/hello_styled_text.rb +19 -17
- data/samples/hello/hello_tab.rb +7 -5
- data/samples/hello/hello_table.rb +12 -5
- data/samples/hello/hello_tree.rb +485 -0
- data/samples/hello/hello_world.rb +2 -0
- metadata +21 -22
- data/lib/glimmer/swt/directory_dialog_proxy.rb +0 -65
- 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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
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
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
font_properties
|
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
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
86
|
-
|
87
|
-
@swt_layout_data.send(
|
88
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
86
|
-
|
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
|
-
|
46
|
-
@
|
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
|
-
|
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
|
-
|
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
|
-
|
84
|
+
DisplayProxy.instance.auto_exec do
|
85
|
+
swt_widget.send(method, *args, &block)
|
86
|
+
end
|
78
87
|
rescue => e
|
79
|
-
|
80
|
-
|
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)
|
@@ -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
|