glimmer-dsl-swt 0.1.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -8
- data/RUBY_VERSION +1 -1
- data/VERSION +1 -1
- data/icons/scaffold_app.icns +0 -0
- data/lib/ext/glimmer.rb +8 -1
- data/lib/ext/glimmer/config.rb +12 -4
- data/lib/glimmer-dsl-swt.rb +8 -3
- data/lib/glimmer/data_binding/list_selection_binding.rb +0 -1
- data/lib/glimmer/data_binding/table_items_binding.rb +5 -4
- data/lib/glimmer/data_binding/widget_binding.rb +7 -6
- data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +4 -0
- data/lib/glimmer/dsl/swt/dnd_expression.rb +25 -0
- data/lib/glimmer/dsl/swt/message_box_expression.rb +0 -4
- data/lib/glimmer/package.rb +2 -0
- data/lib/glimmer/rake_task.rb +22 -0
- data/lib/glimmer/rake_task/list.rb +73 -0
- data/lib/glimmer/scaffold.rb +3 -1
- data/lib/glimmer/swt/dnd_proxy.rb +34 -0
- data/lib/glimmer/swt/packages.rb +9 -6
- data/lib/glimmer/swt/style_constantizable.rb +120 -0
- data/lib/glimmer/swt/swt_proxy.rb +20 -88
- data/lib/glimmer/swt/table_proxy.rb +34 -11
- data/lib/glimmer/swt/widget_proxy.rb +147 -13
- metadata +72 -11
- data/lib/glimmer/data_binding/model_binding.rb +0 -248
- data/lib/glimmer/data_binding/observable.rb +0 -21
- data/lib/glimmer/data_binding/observable_array.rb +0 -107
- data/lib/glimmer/data_binding/observable_model.rb +0 -108
- data/lib/glimmer/data_binding/observer.rb +0 -124
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'glimmer/error'
|
2
|
+
|
3
|
+
module Glimmer
|
4
|
+
module SWT
|
5
|
+
# Mixin for all proxy classes that manage style constants (e.g. SWT, DND, etc...)
|
6
|
+
module StyleConstantizable
|
7
|
+
include SuperModule
|
8
|
+
|
9
|
+
class << self
|
10
|
+
REGEX_SYMBOL_NEGATIVITY = /^([^!]+)(!)?$/
|
11
|
+
|
12
|
+
def constant_java_import
|
13
|
+
raise 'Not implemented! Mixer must implement!'
|
14
|
+
end
|
15
|
+
|
16
|
+
def constant_source_class
|
17
|
+
raise 'Not implemented! Mixer must implement!'
|
18
|
+
end
|
19
|
+
|
20
|
+
def constant_value_none
|
21
|
+
raise 'Not implemented! Mixer must implement!'
|
22
|
+
end
|
23
|
+
|
24
|
+
# hash of extra styles (i.e. new style combinations)
|
25
|
+
def extra_styles
|
26
|
+
raise 'Not implemented! Mixer must implement!'
|
27
|
+
end
|
28
|
+
|
29
|
+
def error_message_invalid_style
|
30
|
+
" is an invalid #{constant_source_class.name.split(':').last} style! Please choose a style from #{constant_java_import} class constants." # TODO parameterize
|
31
|
+
end
|
32
|
+
|
33
|
+
# Gets constants (e.g. SWT::CONSTANT) where constant is
|
34
|
+
# passed in as a lower case symbol
|
35
|
+
def [](*symbols)
|
36
|
+
symbols = symbols.first if symbols.size == 1 && symbols.first.is_a?(Array)
|
37
|
+
result = symbols.compact.map do |symbol|
|
38
|
+
constant(symbol).tap do |constant_value|
|
39
|
+
raise Glimmer::Error, symbol.to_s + error_message_invalid_style unless constant_value.is_a?(Integer)
|
40
|
+
end
|
41
|
+
end.reduce do |output, constant_value|
|
42
|
+
if constant_value < 0
|
43
|
+
output & constant_value
|
44
|
+
else
|
45
|
+
output | constant_value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
result.nil? ? constant_value_none : result
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns style integer value for passed in symbol or allows
|
52
|
+
# passed in object to pass through (e.g. Integer). This makes is convenient
|
53
|
+
# to use symbols or actual style integers in Glimmer
|
54
|
+
# Does not raise error for invalid values. Just lets them pass as is.
|
55
|
+
# (look into [] operator if you want an error raised on invalid values)
|
56
|
+
def constant(symbol)
|
57
|
+
return symbol unless symbol.is_a?(Symbol) || symbol.is_a?(String)
|
58
|
+
symbol_string, negative = extract_symbol_string_negativity(symbol)
|
59
|
+
swt_constant_symbol = symbol_string.downcase == symbol_string ? symbol_string.upcase.to_sym : symbol_string.to_sym
|
60
|
+
bit_value = constant_source_class.const_get(swt_constant_symbol)
|
61
|
+
negative ? ~bit_value : bit_value
|
62
|
+
rescue => e
|
63
|
+
begin
|
64
|
+
# Glimmer::Config.logger&.debug(e.full_message)
|
65
|
+
alternative_swt_constant_symbol = constant_source_class.constants.find {|c| c.to_s.upcase == swt_constant_symbol.to_s.upcase}
|
66
|
+
bit_value = constant_source_class.const_get(alternative_swt_constant_symbol)
|
67
|
+
negative ? ~bit_value : bit_value
|
68
|
+
rescue => e
|
69
|
+
# Glimmer::Config.logger&.debug(e.full_message)
|
70
|
+
bit_value = extra_styles[swt_constant_symbol]
|
71
|
+
if bit_value
|
72
|
+
negative ? ~bit_value : bit_value
|
73
|
+
else
|
74
|
+
symbol
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def extract_symbol_string_negativity(symbol)
|
80
|
+
if symbol.is_a?(Symbol) || symbol.is_a?(String)
|
81
|
+
symbol_negativity_match = symbol.to_s.match(REGEX_SYMBOL_NEGATIVITY)
|
82
|
+
symbol = symbol_negativity_match[1]
|
83
|
+
negative = !!symbol_negativity_match[2]
|
84
|
+
[symbol, negative]
|
85
|
+
else
|
86
|
+
negative = symbol < 0
|
87
|
+
[symbol, negative]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def negative?(symbol)
|
92
|
+
extract_symbol_string_negativity(symbol)[1]
|
93
|
+
end
|
94
|
+
|
95
|
+
def has_constant?(symbol)
|
96
|
+
return false unless symbol.is_a?(Symbol) || symbol.is_a?(String)
|
97
|
+
constant(symbol).is_a?(Integer)
|
98
|
+
end
|
99
|
+
|
100
|
+
def constantify_args(args)
|
101
|
+
args.map {|arg| constant(arg)}
|
102
|
+
end
|
103
|
+
|
104
|
+
# Deconstructs a style integer into symbols
|
105
|
+
# Useful for debugging
|
106
|
+
def deconstruct(integer)
|
107
|
+
constant_source_class.constants.reduce([]) do |found, c|
|
108
|
+
constant_value = constant_source_class.const_get(c) rescue -1
|
109
|
+
is_found = constant_value.is_a?(Integer) && (constant_value & integer) == constant_value
|
110
|
+
is_found ? found += [c] : found
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def include?(swt_constant, *symbols)
|
115
|
+
swt_constant & self[symbols] == self[symbols]
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -1,106 +1,38 @@
|
|
1
|
-
require 'glimmer/
|
1
|
+
require 'glimmer/swt/style_constantizable'
|
2
2
|
|
3
3
|
module Glimmer
|
4
|
-
module SWT
|
4
|
+
module SWT
|
5
5
|
# Proxy for org.eclipse.swt.SWT
|
6
6
|
#
|
7
7
|
# Follows the Proxy Design Pattern
|
8
|
-
class SWTProxy
|
9
|
-
|
10
|
-
java_import 'org.eclipse.swt.SWT'
|
11
|
-
|
12
|
-
ERROR_INVALID_STYLE = " is an invalid SWT style! Please choose a style from org.eclipse.swt.SWT class constants."
|
13
|
-
REGEX_SYMBOL_NEGATIVITY = /^([^!]+)(!)?$/
|
14
|
-
|
15
|
-
# Gets SWT constants as if calling SWT::CONSTANT where constant is
|
16
|
-
# passed in as a lower case symbol
|
17
|
-
def [](*symbols)
|
18
|
-
symbols = symbols.first if symbols.size == 1 && symbols.first.is_a?(Array)
|
19
|
-
result = symbols.compact.map do |symbol|
|
20
|
-
constant(symbol).tap do |constant_value|
|
21
|
-
raise Error, symbol.to_s + ERROR_INVALID_STYLE unless constant_value.is_a?(Integer)
|
22
|
-
end
|
23
|
-
end.reduce do |output, constant_value|
|
24
|
-
if constant_value < 0
|
25
|
-
output & constant_value
|
26
|
-
else
|
27
|
-
output | constant_value
|
28
|
-
end
|
29
|
-
end
|
30
|
-
result.nil? ? SWT::NONE : result
|
31
|
-
end
|
32
|
-
|
33
|
-
# Returns SWT style integer value for passed in symbol or allows
|
34
|
-
# passed in object to pass through (e.g. Integer). This makes is convenient
|
35
|
-
# to use symbols or actual SWT style integers in Glimmer
|
36
|
-
# Does not raise error for invalid values. Just lets them pass as is.
|
37
|
-
# (look into [] operator if you want an error raised on invalid values)
|
38
|
-
def constant(symbol)
|
39
|
-
return symbol unless symbol.is_a?(Symbol) || symbol.is_a?(String)
|
40
|
-
symbol_string, negative = extract_symbol_string_negativity(symbol)
|
41
|
-
swt_constant_symbol = symbol_string.downcase == symbol_string ? symbol_string.upcase.to_sym : symbol_string.to_sym
|
42
|
-
bit_value = SWT.const_get(swt_constant_symbol)
|
43
|
-
negative ? ~bit_value : bit_value
|
44
|
-
rescue => e
|
45
|
-
begin
|
46
|
-
# Glimmer::Config.logger&.debug(e.full_message)
|
47
|
-
alternative_swt_constant_symbol = SWT.constants.find {|c| c.to_s.upcase == swt_constant_symbol.to_s.upcase}
|
48
|
-
bit_value = SWT.const_get(alternative_swt_constant_symbol)
|
49
|
-
negative ? ~bit_value : bit_value
|
50
|
-
rescue => e
|
51
|
-
# Glimmer::Config.logger&.debug(e.full_message)
|
52
|
-
bit_value = Glimmer::SWT::SWTProxy::EXTRA_STYLES[swt_constant_symbol]
|
53
|
-
if bit_value
|
54
|
-
negative ? ~bit_value : bit_value
|
55
|
-
else
|
56
|
-
symbol
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
8
|
+
class SWTProxy
|
9
|
+
include StyleConstantizable
|
60
10
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
negative = symbol < 0
|
69
|
-
[symbol, negative]
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def negative?(symbol)
|
74
|
-
extract_symbol_string_negativity(symbol)[1]
|
75
|
-
end
|
76
|
-
|
77
|
-
def has_constant?(symbol)
|
78
|
-
return false unless symbol.is_a?(Symbol) || symbol.is_a?(String)
|
79
|
-
constant(symbol).is_a?(Integer)
|
11
|
+
class << self
|
12
|
+
JAVA_IMPORT = 'org.eclipse.swt.SWT'
|
13
|
+
|
14
|
+
java_import JAVA_IMPORT
|
15
|
+
|
16
|
+
def constant_java_import
|
17
|
+
JAVA_IMPORT
|
80
18
|
end
|
81
19
|
|
82
|
-
def
|
83
|
-
|
20
|
+
def constant_source_class
|
21
|
+
SWT
|
84
22
|
end
|
85
23
|
|
86
|
-
|
87
|
-
|
88
|
-
def deconstruct(integer)
|
89
|
-
SWT.constants.reduce([]) do |found, c|
|
90
|
-
constant_value = SWT.const_get(c) rescue -1
|
91
|
-
is_found = constant_value.is_a?(Integer) && (constant_value & integer) == constant_value
|
92
|
-
is_found ? found += [c] : found
|
93
|
-
end
|
24
|
+
def constant_value_none
|
25
|
+
SWT::NONE
|
94
26
|
end
|
95
|
-
|
96
|
-
def
|
97
|
-
|
27
|
+
|
28
|
+
def extra_styles
|
29
|
+
EXTRA_STYLES
|
98
30
|
end
|
99
31
|
end
|
100
|
-
|
32
|
+
|
101
33
|
EXTRA_STYLES = {
|
102
34
|
NO_RESIZE: self[:shell_trim, :resize!, :max!]
|
103
|
-
}
|
35
|
+
}
|
104
36
|
end
|
105
37
|
end
|
106
38
|
end
|
@@ -68,6 +68,21 @@ module Glimmer
|
|
68
68
|
})
|
69
69
|
end
|
70
70
|
|
71
|
+
# Indicates if table is in edit mode, thus displaying a text widget for a table item cell
|
72
|
+
def edit_mode?
|
73
|
+
!!@edit_mode
|
74
|
+
end
|
75
|
+
|
76
|
+
def cancel_edit!
|
77
|
+
@cancel_edit&.call if @edit_mode
|
78
|
+
end
|
79
|
+
|
80
|
+
def finish_edit!
|
81
|
+
@finish_edit&.call if @edit_mode
|
82
|
+
end
|
83
|
+
|
84
|
+
# Indicates if table is editing a table item because the user hit ENTER or focused out after making a change in edit mode to a table item cell.
|
85
|
+
# It is set to false once change is saved to model
|
71
86
|
def edit_in_progress?
|
72
87
|
!!@edit_in_progress
|
73
88
|
end
|
@@ -78,24 +93,32 @@ module Glimmer
|
|
78
93
|
|
79
94
|
def edit_table_item(table_item, column_index, before_write: nil, after_write: nil, after_cancel: nil)
|
80
95
|
return if table_item.nil?
|
96
|
+
@cancel_edit&.call if @edit_mode
|
97
|
+
@edit_mode = true
|
81
98
|
content {
|
82
99
|
@table_editor_text_proxy = text {
|
83
100
|
focus true
|
84
101
|
text table_item.getText(column_index)
|
85
102
|
action_taken = false
|
86
|
-
|
87
|
-
@
|
103
|
+
@cancel_edit = lambda do
|
104
|
+
@cancel_in_progress = true
|
105
|
+
@table_editor_text_proxy&.swt_widget&.dispose
|
88
106
|
@table_editor_text_proxy = nil
|
89
107
|
after_cancel&.call
|
90
108
|
@edit_in_progress = false
|
91
|
-
|
92
|
-
|
93
|
-
|
109
|
+
@cancel_in_progress = false
|
110
|
+
@cancel_edit = nil
|
111
|
+
@edit_mode = false
|
112
|
+
end
|
113
|
+
@finish_edit = lambda do |event=nil|
|
114
|
+
if table_item.isDisposed
|
115
|
+
@cancel_edit.call
|
116
|
+
elsif !action_taken && !@edit_in_progress && !@cancel_in_progress
|
94
117
|
action_taken = true
|
95
118
|
@edit_in_progress = true
|
96
119
|
new_text = @table_editor_text_proxy.swt_widget.getText
|
97
120
|
if new_text == table_item.getText(column_index)
|
98
|
-
|
121
|
+
@cancel_edit.call
|
99
122
|
else
|
100
123
|
before_write&.call
|
101
124
|
table_item.setText(column_index, new_text)
|
@@ -103,19 +126,19 @@ module Glimmer
|
|
103
126
|
model.send("#{column_properties[column_index]}=", new_text) # makes table update itself, so must search for selected table item again
|
104
127
|
edited_table_item = search { |ti| ti.getData == model }.first
|
105
128
|
swt_widget.showItem(edited_table_item)
|
106
|
-
@table_editor_text_proxy
|
129
|
+
@table_editor_text_proxy&.swt_widget&.dispose
|
107
130
|
@table_editor_text_proxy = nil
|
108
131
|
after_write&.call(edited_table_item)
|
109
132
|
@edit_in_progress = false
|
110
133
|
end
|
111
134
|
end
|
112
|
-
|
113
|
-
on_focus_lost(
|
135
|
+
end
|
136
|
+
on_focus_lost(&@finish_edit)
|
114
137
|
on_key_pressed { |key_event|
|
115
138
|
if key_event.keyCode == swt(:cr)
|
116
|
-
|
139
|
+
@finish_edit.call(key_event)
|
117
140
|
elsif key_event.keyCode == swt(:esc)
|
118
|
-
|
141
|
+
@cancel_edit.call
|
119
142
|
end
|
120
143
|
}
|
121
144
|
}
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'glimmer'
|
2
1
|
require 'glimmer/swt/widget_listener_proxy'
|
3
2
|
require 'glimmer/swt/color_proxy'
|
4
3
|
require 'glimmer/swt/font_proxy'
|
5
4
|
require 'glimmer/swt/swt_proxy'
|
5
|
+
require 'glimmer/swt/dnd_proxy'
|
6
6
|
require 'glimmer/data_binding/observable_widget'
|
7
7
|
|
8
8
|
# TODO refactor to make file smaller and extract sub-widget-proxies out of this
|
@@ -31,6 +31,8 @@ module Glimmer
|
|
31
31
|
"list" => [:border, :v_scroll],
|
32
32
|
"button" => [:push],
|
33
33
|
"menu_item" => [:push],
|
34
|
+
"drag_source" => [:drop_copy],
|
35
|
+
"drop_target" => [:drop_copy],
|
34
36
|
}
|
35
37
|
|
36
38
|
DEFAULT_INITIALIZERS = {
|
@@ -49,7 +51,7 @@ module Glimmer
|
|
49
51
|
end,
|
50
52
|
}
|
51
53
|
|
52
|
-
attr_reader :swt_widget
|
54
|
+
attr_reader :swt_widget, :drag_source_proxy, :drop_target_proxy, :drag_source_style, :drag_source_transfer, :drop_target_transfer
|
53
55
|
|
54
56
|
# Initializes a new SWT Widget
|
55
57
|
#
|
@@ -73,7 +75,18 @@ module Glimmer
|
|
73
75
|
if @arg_extractor_mapping[underscored_widget_name]
|
74
76
|
@arg_extractor_mapping[underscored_widget_name].call(args)
|
75
77
|
else
|
76
|
-
|
78
|
+
extra_options = []
|
79
|
+
style_args = args.select {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}
|
80
|
+
if style_args.any?
|
81
|
+
style_arg_start_index = args.index(style_args.first)
|
82
|
+
style_arg_last_index = args.index(style_args.last)
|
83
|
+
extra_options = args[style_arg_last_index+1..-1]
|
84
|
+
args = args[style_arg_start_index..style_arg_last_index]
|
85
|
+
elsif args.first.is_a?(Integer)
|
86
|
+
extra_options = args[1..-1]
|
87
|
+
args = args[0..0]
|
88
|
+
end
|
89
|
+
[args, extra_options]
|
77
90
|
end
|
78
91
|
end
|
79
92
|
|
@@ -82,7 +95,7 @@ module Glimmer
|
|
82
95
|
if widget_custom_attribute
|
83
96
|
@swt_widget.respond_to?(widget_custom_attribute[:setter][:name])
|
84
97
|
else
|
85
|
-
@swt_widget.respond_to?(attribute_setter(attribute_name), args)
|
98
|
+
@swt_widget.respond_to?(attribute_setter(attribute_name), args) || respond_to?(ruby_attribute_setter(attribute_name), args)
|
86
99
|
end
|
87
100
|
end
|
88
101
|
|
@@ -90,9 +103,11 @@ module Glimmer
|
|
90
103
|
widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
|
91
104
|
if widget_custom_attribute
|
92
105
|
widget_custom_attribute[:setter][:invoker].call(@swt_widget, args)
|
93
|
-
|
106
|
+
elsif @swt_widget.respond_to?(attribute_setter(attribute_name), args)
|
94
107
|
apply_property_type_converters(attribute_name, args)
|
95
108
|
@swt_widget.send(attribute_setter(attribute_name), *args) unless @swt_widget.send(attribute_getter(attribute_name)) == args.first
|
109
|
+
else
|
110
|
+
send(ruby_attribute_setter(attribute_name), args)
|
96
111
|
end
|
97
112
|
end
|
98
113
|
|
@@ -131,6 +146,13 @@ module Glimmer
|
|
131
146
|
}
|
132
147
|
end,
|
133
148
|
},
|
149
|
+
Java::OrgEclipseSwtWidgets::Combo => {
|
150
|
+
:text => lambda do |observer|
|
151
|
+
on_modify_text { |modify_event|
|
152
|
+
observer.call(@swt_widget.getText)
|
153
|
+
}
|
154
|
+
end,
|
155
|
+
},
|
134
156
|
Java::OrgEclipseSwtWidgets::Text => {
|
135
157
|
:text => lambda do |observer|
|
136
158
|
on_modify_text { |modify_event|
|
@@ -252,7 +274,12 @@ module Glimmer
|
|
252
274
|
end
|
253
275
|
|
254
276
|
def has_style?(style)
|
255
|
-
|
277
|
+
begin
|
278
|
+
comparison = SWTProxy[style]
|
279
|
+
rescue
|
280
|
+
comparison = DNDProxy[style]
|
281
|
+
end
|
282
|
+
(@swt_widget.style & comparison) == comparison
|
256
283
|
end
|
257
284
|
|
258
285
|
def dispose
|
@@ -278,6 +305,21 @@ module Glimmer
|
|
278
305
|
# TODO consider implementing if remove_observer is needed (consumers can remove listener via SWT API)
|
279
306
|
end
|
280
307
|
|
308
|
+
def ensure_drag_source_proxy(style=[])
|
309
|
+
@drag_source_proxy ||= self.class.new('drag_source', self, style).tap do |proxy|
|
310
|
+
proxy.set_attribute(:transfer, :text)
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
def ensure_drop_target_proxy(style=[])
|
315
|
+
@drop_target_proxy ||= self.class.new('drop_target', self, style).tap do |proxy|
|
316
|
+
proxy.set_attribute(:transfer, :text)
|
317
|
+
proxy.on_drag_enter { |event|
|
318
|
+
event.detail = DNDProxy[:drop_copy]
|
319
|
+
}
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
281
323
|
# TODO eliminate duplication in the following methods perhaps by relying on exceptions
|
282
324
|
|
283
325
|
def can_handle_observation_request?(observation_request)
|
@@ -287,9 +329,31 @@ module Glimmer
|
|
287
329
|
SWTProxy.has_constant?(constant_name)
|
288
330
|
elsif observation_request.start_with?('on_')
|
289
331
|
event = observation_request.sub(/^on_/, '')
|
290
|
-
can_add_listener?(event)
|
291
|
-
|
292
|
-
|
332
|
+
can_add_listener?(event) || can_handle_drag_observation_request?(observation_request) || can_handle_drop_observation_request?(observation_request)
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
def can_handle_drag_observation_request?(observation_request)
|
337
|
+
return false unless swt_widget.is_a?(Control)
|
338
|
+
potential_drag_source = @drag_source_proxy.nil?
|
339
|
+
ensure_drag_source_proxy
|
340
|
+
@drag_source_proxy.can_handle_observation_request?(observation_request).tap do |result|
|
341
|
+
if potential_drag_source && !result
|
342
|
+
@drag_source_proxy.swt_widget.dispose
|
343
|
+
@drag_source_proxy = nil
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
def can_handle_drop_observation_request?(observation_request)
|
349
|
+
return false unless swt_widget.is_a?(Control)
|
350
|
+
potential_drop_target = @drop_target_proxy.nil?
|
351
|
+
ensure_drop_target_proxy
|
352
|
+
@drop_target_proxy.can_handle_observation_request?(observation_request).tap do |result|
|
353
|
+
if potential_drop_target && !result
|
354
|
+
@drop_target_proxy.swt_widget.dispose
|
355
|
+
@drop_target_proxy = nil
|
356
|
+
end
|
293
357
|
end
|
294
358
|
end
|
295
359
|
|
@@ -299,7 +363,14 @@ module Glimmer
|
|
299
363
|
add_swt_event_listener(constant_name, &block)
|
300
364
|
elsif observation_request.start_with?('on_')
|
301
365
|
event = observation_request.sub(/^on_/, '')
|
302
|
-
|
366
|
+
if can_add_listener?(event)
|
367
|
+
event = observation_request.sub(/^on_/, '')
|
368
|
+
add_listener(event, &block)
|
369
|
+
elsif can_handle_drag_observation_request?(observation_request)
|
370
|
+
@drag_source_proxy&.handle_observation_request(observation_request, &block)
|
371
|
+
elsif can_handle_drop_observation_request?(observation_request)
|
372
|
+
@drop_target_proxy&.handle_observation_request(observation_request, &block)
|
373
|
+
end
|
303
374
|
end
|
304
375
|
end
|
305
376
|
|
@@ -311,12 +382,24 @@ module Glimmer
|
|
311
382
|
|
312
383
|
def style(underscored_widget_name, styles)
|
313
384
|
styles = [styles].flatten.compact
|
314
|
-
styles.empty?
|
385
|
+
if styles.empty?
|
386
|
+
default_style(underscored_widget_name)
|
387
|
+
else
|
388
|
+
begin
|
389
|
+
SWTProxy[*styles]
|
390
|
+
rescue
|
391
|
+
DNDProxy[*styles]
|
392
|
+
end
|
393
|
+
end
|
315
394
|
end
|
316
395
|
|
317
396
|
def default_style(underscored_widget_name)
|
318
397
|
styles = DEFAULT_STYLES[underscored_widget_name] || [:none]
|
319
|
-
SWTProxy[styles]
|
398
|
+
SWTProxy[styles] rescue DNDProxy[styles]
|
399
|
+
end
|
400
|
+
|
401
|
+
def ruby_attribute_setter(attribute_name)
|
402
|
+
"#{attribute_name}="
|
320
403
|
end
|
321
404
|
|
322
405
|
def attribute_setter(attribute_name)
|
@@ -340,7 +423,7 @@ module Glimmer
|
|
340
423
|
def add_listener(underscored_listener_name, &block)
|
341
424
|
widget_add_listener_method, listener_class, listener_method = self.class.find_listener(@swt_widget.getClass, underscored_listener_name)
|
342
425
|
widget_listener_proxy = nil
|
343
|
-
safe_block = lambda { |event| block.call(event) unless @swt_widget.isDisposed }
|
426
|
+
safe_block = lambda { |event| block.call(event) unless @swt_widget.isDisposed }
|
344
427
|
listener = listener_class.new(listener_method => safe_block)
|
345
428
|
@swt_widget.send(widget_add_listener_method, listener)
|
346
429
|
widget_listener_proxy = 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)
|
@@ -417,6 +500,38 @@ module Glimmer
|
|
417
500
|
}
|
418
501
|
end
|
419
502
|
|
503
|
+
def drag_source_style=(style)
|
504
|
+
ensure_drag_source_proxy(style)
|
505
|
+
end
|
506
|
+
|
507
|
+
def drop_target_style=(style)
|
508
|
+
ensure_drop_target_proxy(style)
|
509
|
+
end
|
510
|
+
|
511
|
+
def drag_source_transfer=(args)
|
512
|
+
args = args.first if !args.empty? && args.first.is_a?(ArrayJavaProxy)
|
513
|
+
ensure_drag_source_proxy
|
514
|
+
@drag_source_proxy.set_attribute(:transfer, args)
|
515
|
+
end
|
516
|
+
|
517
|
+
def drop_target_transfer=(args)
|
518
|
+
args = args.first if !args.empty? && args.first.is_a?(ArrayJavaProxy)
|
519
|
+
ensure_drop_target_proxy
|
520
|
+
@drop_target_proxy.set_attribute(:transfer, args)
|
521
|
+
end
|
522
|
+
|
523
|
+
def drag_source_effect=(args)
|
524
|
+
args = args.first if args.is_a?(Array)
|
525
|
+
ensure_drag_source_proxy
|
526
|
+
@drag_source_proxy.set_attribute(:drag_source_effect, args)
|
527
|
+
end
|
528
|
+
|
529
|
+
def drop_target_effect=(args)
|
530
|
+
args = args.first if args.is_a?(Array)
|
531
|
+
ensure_drop_target_proxy
|
532
|
+
@drop_target_proxy.set_attribute(:drop_target_effect, args)
|
533
|
+
end
|
534
|
+
|
420
535
|
def apply_property_type_converters(attribute_name, args)
|
421
536
|
if args.count == 1
|
422
537
|
value = args.first
|
@@ -479,6 +594,25 @@ module Glimmer
|
|
479
594
|
value.to_s
|
480
595
|
end
|
481
596
|
end,
|
597
|
+
:transfer => lambda do |value|
|
598
|
+
value = value.first if value.is_a?(Array) && value.size == 1 && value.first.is_a?(Array)
|
599
|
+
transfer_object_extrapolator = lambda do |transfer_name|
|
600
|
+
transfer_type = "#{transfer_name.to_s.camelcase(:upper)}Transfer".to_sym
|
601
|
+
transfer_type_alternative = "#{transfer_name.to_s.upcase}Transfer".to_sym
|
602
|
+
transfer_class = org.eclipse.swt.dnd.const_get(transfer_type) rescue org.eclipse.swt.dnd.const_get(transfer_type_alternative)
|
603
|
+
transfer_class.getInstance
|
604
|
+
end
|
605
|
+
result = value
|
606
|
+
if value.is_a?(Symbol) || value.is_a?(String)
|
607
|
+
result = [transfer_object_extrapolator.call(value)]
|
608
|
+
elsif value.is_a?(Array)
|
609
|
+
result = value.map do |transfer_name|
|
610
|
+
transfer_object_extrapolator.call(transfer_name)
|
611
|
+
end
|
612
|
+
end
|
613
|
+
result = result.to_java(Transfer) unless result.is_a?(ArrayJavaProxy)
|
614
|
+
result
|
615
|
+
end,
|
482
616
|
:visible => lambda do |value|
|
483
617
|
!!value
|
484
618
|
end,
|