glimmer-dsl-opal 0.4.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +56 -0
- data/README.md +892 -16
- data/VERSION +1 -1
- data/app/assets/images/glimmer/images/calendar.gif +0 -0
- data/app/assets/images/glimmer/images/ui-icons_222222_256x240.png +0 -0
- data/app/assets/images/glimmer/images/ui-icons_444444_256x240.png +0 -0
- data/app/assets/images/glimmer/images/ui-icons_555555_256x240.png +0 -0
- data/app/assets/images/glimmer/images/ui-icons_777620_256x240.png +0 -0
- data/app/assets/images/glimmer/images/ui-icons_777777_256x240.png +0 -0
- data/app/assets/images/glimmer/images/ui-icons_cc0000_256x240.png +0 -0
- data/app/assets/images/glimmer/images/ui-icons_ffffff_256x240.png +0 -0
- data/app/assets/stylesheets/glimmer/glimmer.css +15 -0
- data/app/assets/stylesheets/glimmer/jquery-ui.css +1312 -0
- data/app/assets/stylesheets/glimmer/jquery-ui.structure.css +886 -0
- data/app/assets/stylesheets/glimmer/jquery-ui.theme.css +443 -0
- data/app/assets/stylesheets/glimmer/jquery.ui.timepicker.css +57 -0
- data/lib/glimmer-dsl-opal.rb +16 -9
- data/lib/glimmer-dsl-opal/ext/date.rb +49 -3
- data/lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb +23 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox.rb +85 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox_group.rb +68 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_combo.rb +5 -5
- data/lib/glimmer-dsl-opal/samples/hello/hello_custom_widget.rb +3 -3
- data/lib/glimmer-dsl-opal/samples/hello/hello_date_time.rb +63 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_group.rb +104 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_list_single_selection.rb +1 -1
- data/lib/glimmer-dsl-opal/samples/hello/hello_radio.rb +108 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_radio_group.rb +84 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_table.rb +283 -0
- data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/GPL-LICENSE.txt +278 -0
- data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/MIT-LICENSE.txt +20 -0
- data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/jquery.ui.timepicker.css +57 -0
- data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/jquery.ui.timepicker.js +1496 -0
- data/lib/glimmer-dsl-opal/vendor/jquery-ui/AUTHORS.txt +333 -0
- data/lib/glimmer-dsl-opal/vendor/jquery-ui/LICENSE.txt +43 -0
- data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_444444_256x240.png +0 -0
- data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_555555_256x240.png +0 -0
- data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_777620_256x240.png +0 -0
- data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_777777_256x240.png +0 -0
- data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_cc0000_256x240.png +0 -0
- data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_ffffff_256x240.png +0 -0
- data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.min.css +7 -0
- data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.min.js +13 -0
- data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.structure.min.css +5 -0
- data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.theme.min.css +5 -0
- data/lib/glimmer-dsl-opal/vendor/jquery-ui/package.json +74 -0
- data/lib/glimmer-dsl-swt.rb +1 -0
- data/lib/glimmer/data_binding/element_binding.rb +2 -1
- data/lib/glimmer/data_binding/table_items_binding.rb +29 -18
- data/lib/glimmer/dsl/opal/block_property_expression.rb +41 -0
- data/lib/glimmer/dsl/opal/checkbox_group_selection_data_binding_expression.rb +61 -0
- data/lib/glimmer/dsl/opal/custom_widget_expression.rb +8 -6
- data/lib/glimmer/dsl/opal/dsl.rb +6 -0
- data/lib/glimmer/dsl/opal/property_expression.rb +4 -3
- data/lib/glimmer/dsl/opal/radio_group_selection_data_binding_expression.rb +61 -0
- data/lib/glimmer/dsl/opal/shell_expression.rb +7 -2
- data/lib/glimmer/dsl/opal/widget_expression.rb +6 -1
- data/lib/glimmer/engine.rb +9 -0
- data/lib/glimmer/swt.rb +3 -3
- data/lib/glimmer/swt/button_proxy.rb +16 -2
- data/lib/glimmer/swt/checkbox_proxy.rb +81 -0
- data/lib/glimmer/swt/color_proxy.rb +45 -45
- data/lib/glimmer/swt/combo_proxy.rb +6 -6
- data/lib/glimmer/swt/composite_proxy.rb +2 -2
- data/lib/glimmer/swt/custom/checkbox_group.rb +142 -0
- data/lib/glimmer/swt/custom/radio_group.rb +143 -0
- data/lib/glimmer/swt/date_time_proxy.rb +145 -0
- data/lib/glimmer/swt/display_proxy.rb +6 -2
- data/lib/glimmer/swt/fill_layout_proxy.rb +1 -1
- data/lib/glimmer/swt/grid_layout_proxy.rb +19 -8
- data/lib/glimmer/swt/group_proxy.rb +38 -0
- data/lib/glimmer/swt/label_proxy.rb +27 -7
- data/lib/glimmer/swt/layout_data_proxy.rb +39 -21
- data/lib/glimmer/swt/layout_proxy.rb +4 -4
- data/lib/glimmer/swt/list_proxy.rb +3 -3
- data/lib/glimmer/swt/make_shift_shell_proxy.rb +4 -4
- data/lib/glimmer/swt/message_box_proxy.rb +10 -8
- data/lib/glimmer/swt/property_owner.rb +2 -2
- data/lib/glimmer/swt/radio_proxy.rb +82 -0
- data/lib/glimmer/swt/row_layout_proxy.rb +33 -10
- data/lib/glimmer/swt/scrolled_composite_proxy.rb +20 -0
- data/lib/glimmer/swt/shell_proxy.rb +29 -9
- data/lib/glimmer/swt/tab_folder_proxy.rb +5 -5
- data/lib/glimmer/swt/tab_item_proxy.rb +7 -7
- data/lib/glimmer/swt/table_column_proxy.rb +62 -12
- data/lib/glimmer/swt/table_item_proxy.rb +14 -7
- data/lib/glimmer/swt/table_proxy.rb +225 -16
- data/lib/glimmer/swt/text_proxy.rb +50 -2
- data/lib/glimmer/swt/widget_proxy.rb +88 -39
- data/lib/glimmer/ui/custom_widget.rb +8 -8
- data/lib/net/http.rb +1 -5
- data/lib/uri.rb +3 -3
- metadata +56 -9
- data/lib/glimmer/data_binding/ext/observable_model.rb +0 -40
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'glimmer/swt/widget_proxy'
|
2
|
+
|
3
|
+
module Glimmer
|
4
|
+
module SWT
|
5
|
+
class CheckboxProxy < WidgetProxy
|
6
|
+
# TODO add a create method that ensures passing :check style in if not there
|
7
|
+
STYLE=<<~CSS
|
8
|
+
.checkbox {
|
9
|
+
display: inline;
|
10
|
+
}
|
11
|
+
.checkbox-label {
|
12
|
+
display: inline;
|
13
|
+
}
|
14
|
+
CSS
|
15
|
+
# TODO consider reuse of logic in Radioproxy
|
16
|
+
attr_reader :text
|
17
|
+
|
18
|
+
def text=(value)
|
19
|
+
@text = value
|
20
|
+
dom_element.val(@text)
|
21
|
+
label_dom_element.html(@text)
|
22
|
+
end
|
23
|
+
|
24
|
+
def selection
|
25
|
+
dom_element.prop('checked')
|
26
|
+
end
|
27
|
+
|
28
|
+
def selection=(value)
|
29
|
+
@selection = value
|
30
|
+
dom_element.prop('checked', @selection)
|
31
|
+
end
|
32
|
+
|
33
|
+
def element
|
34
|
+
'input'
|
35
|
+
end
|
36
|
+
|
37
|
+
def observation_request_to_event_mapping
|
38
|
+
{
|
39
|
+
'on_widget_selected' => {
|
40
|
+
event: 'change'
|
41
|
+
},
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def label_id
|
46
|
+
"#{id}-label"
|
47
|
+
end
|
48
|
+
|
49
|
+
def label_class
|
50
|
+
"#{name}-label"
|
51
|
+
end
|
52
|
+
|
53
|
+
def label_dom_element
|
54
|
+
Element.find("##{label_id}")
|
55
|
+
end
|
56
|
+
|
57
|
+
def dom
|
58
|
+
check_text = @text
|
59
|
+
check_id = id
|
60
|
+
check_style = css
|
61
|
+
check_class = name
|
62
|
+
check_selection = @selection
|
63
|
+
options = {type: 'checkbox', id: check_id, name: parent.id, style: check_style, class: check_class, value: check_text, style: 'min-width: 27px;'}
|
64
|
+
options[checked: 'checked'] if check_selection
|
65
|
+
@dom ||= html {
|
66
|
+
span {
|
67
|
+
input(options) {
|
68
|
+
}
|
69
|
+
label(id: label_id, class: label_class, for: check_id) {
|
70
|
+
check_text
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}.to_s
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
CheckProxy = CheckboxProxy # alias
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Copyright (c) 2020 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
|
@@ -28,44 +28,44 @@ module Glimmer
|
|
28
28
|
# Follows the Proxy Design Pattern
|
29
29
|
class ColorProxy
|
30
30
|
SWT_COLOR_TRANSLATION = {
|
31
|
-
"widget_foreground" => [0, 0, 0],
|
32
|
-
"blue" => [0, 0, 255],
|
33
|
-
"widget_dark_shadow" => [0, 0, 0],
|
34
|
-
"title_foreground" => [0, 0, 0],
|
35
|
-
"yellow" => [255, 255, 0],
|
36
|
-
"widget_highlight_shadow" => [255, 255, 255],
|
37
|
-
"dark_cyan" => [0, 128, 128],
|
38
|
-
"list_foreground" => [0, 0, 0],
|
39
|
-
"dark_blue" => [0, 0, 128],
|
40
|
-
"dark_yellow" => [128, 128, 0],
|
41
|
-
"cyan" => [0, 255, 255],
|
42
|
-
"info_background" => [236, 235, 236],
|
43
|
-
"link_foreground" => [0, 104, 218],
|
44
|
-
"title_inactive_foreground" => [0, 0, 0],
|
45
|
-
"title_background_gradient" => [179, 215, 255],
|
46
|
-
"red" => [255, 0, 0],
|
47
|
-
"title_inactive_background_gradient" => [220, 220, 220],
|
48
|
-
"transparent" => [255, 255, 255],
|
49
|
-
"widget_light_shadow" => [232, 232, 232],
|
50
|
-
"dark_magenta" => [128, 0, 128],
|
51
|
-
"white" => [255, 255, 255],
|
52
|
-
"list_selection" => [179, 215, 255],
|
53
|
-
"gray" => [192, 192, 192],
|
54
|
-
"widget_border" => [0, 0, 0],
|
55
|
-
"widget_background" => [236, 236, 236],
|
56
|
-
"info_foreground" => [0, 0, 0],
|
57
|
-
"title_inactive_background" => [220, 220, 220],
|
58
|
-
"widget_disabled_foreground" => [220, 220, 220],
|
59
|
-
"list_background" => [255, 255, 255],
|
60
|
-
"magenta" => [255, 0, 255],
|
61
|
-
"title_background" => [0, 99, 225],
|
62
|
-
"text_disabled_background" => [255, 255, 255],
|
63
|
-
"black" => [0, 0, 0],
|
64
|
-
"dark_gray" => [128, 128, 128],
|
65
|
-
"list_selection_text" => [0, 0, 0],
|
66
|
-
"dark_red" => [128, 0, 0],
|
67
|
-
"widget_normal_shadow" => [159, 159, 159],
|
68
|
-
"dark_green" => [0, 128, 0],
|
31
|
+
"widget_foreground" => [0, 0, 0],
|
32
|
+
"blue" => [0, 0, 255],
|
33
|
+
"widget_dark_shadow" => [0, 0, 0],
|
34
|
+
"title_foreground" => [0, 0, 0],
|
35
|
+
"yellow" => [255, 255, 0],
|
36
|
+
"widget_highlight_shadow" => [255, 255, 255],
|
37
|
+
"dark_cyan" => [0, 128, 128],
|
38
|
+
"list_foreground" => [0, 0, 0],
|
39
|
+
"dark_blue" => [0, 0, 128],
|
40
|
+
"dark_yellow" => [128, 128, 0],
|
41
|
+
"cyan" => [0, 255, 255],
|
42
|
+
"info_background" => [236, 235, 236],
|
43
|
+
"link_foreground" => [0, 104, 218],
|
44
|
+
"title_inactive_foreground" => [0, 0, 0],
|
45
|
+
"title_background_gradient" => [179, 215, 255],
|
46
|
+
"red" => [255, 0, 0],
|
47
|
+
"title_inactive_background_gradient" => [220, 220, 220],
|
48
|
+
"transparent" => [255, 255, 255],
|
49
|
+
"widget_light_shadow" => [232, 232, 232],
|
50
|
+
"dark_magenta" => [128, 0, 128],
|
51
|
+
"white" => [255, 255, 255],
|
52
|
+
"list_selection" => [179, 215, 255],
|
53
|
+
"gray" => [192, 192, 192],
|
54
|
+
"widget_border" => [0, 0, 0],
|
55
|
+
"widget_background" => [236, 236, 236],
|
56
|
+
"info_foreground" => [0, 0, 0],
|
57
|
+
"title_inactive_background" => [220, 220, 220],
|
58
|
+
"widget_disabled_foreground" => [220, 220, 220],
|
59
|
+
"list_background" => [255, 255, 255],
|
60
|
+
"magenta" => [255, 0, 255],
|
61
|
+
"title_background" => [0, 99, 225],
|
62
|
+
"text_disabled_background" => [255, 255, 255],
|
63
|
+
"black" => [0, 0, 0],
|
64
|
+
"dark_gray" => [128, 128, 128],
|
65
|
+
"list_selection_text" => [0, 0, 0],
|
66
|
+
"dark_red" => [128, 0, 0],
|
67
|
+
"widget_normal_shadow" => [159, 159, 159],
|
68
|
+
"dark_green" => [0, 128, 0],
|
69
69
|
"green" => [0, 255, 0]
|
70
70
|
}
|
71
71
|
|
@@ -87,19 +87,19 @@ module Glimmer
|
|
87
87
|
# rgba is 4 arguments representing Red, Green, Blue, and Alpha numeric values
|
88
88
|
#
|
89
89
|
def initialize(*args)
|
90
|
-
@args = args
|
90
|
+
@args = args
|
91
91
|
case @args.size
|
92
92
|
when 1
|
93
93
|
@alpha = nil
|
94
|
-
if @args.first.is_a?(String) || @args.first.is_a?(Symbol)
|
95
|
-
standard_color = @args.first.to_s.downcase.sub('COLOR_', '')
|
94
|
+
if @args.first.is_a?(String) || @args.first.is_a?(Symbol)
|
95
|
+
standard_color = @args.first.to_s.downcase.sub('COLOR_', '')
|
96
96
|
@red, @green, @blue = SWT_COLOR_TRANSLATION[standard_color]
|
97
97
|
else
|
98
98
|
@red, @green, @blue = [0, 0, 0]
|
99
99
|
end
|
100
100
|
when 3..4
|
101
101
|
@red, @green, @blue, @alpha = @args
|
102
|
-
end
|
102
|
+
end
|
103
103
|
end
|
104
104
|
|
105
105
|
def to_css
|
@@ -7,8 +7,8 @@ module Glimmer
|
|
7
7
|
include Glimmer::DataBinding::ObservableElement
|
8
8
|
attr_reader :text, :items
|
9
9
|
|
10
|
-
def initialize(parent, args)
|
11
|
-
super(parent, args)
|
10
|
+
def initialize(parent, args, block)
|
11
|
+
super(parent, args, block)
|
12
12
|
@items = []
|
13
13
|
end
|
14
14
|
|
@@ -29,20 +29,20 @@ module Glimmer
|
|
29
29
|
html {
|
30
30
|
option(option_hash) {
|
31
31
|
item
|
32
|
-
}
|
32
|
+
}
|
33
33
|
}.to_s
|
34
34
|
end
|
35
35
|
dom_element.html(items_dom)
|
36
36
|
end
|
37
37
|
|
38
|
-
def observation_request_to_event_mapping
|
38
|
+
def observation_request_to_event_mapping
|
39
39
|
{
|
40
40
|
'on_widget_selected' => {
|
41
41
|
event: 'change',
|
42
42
|
event_handler: -> (event_listener) {
|
43
|
-
-> (event) {
|
43
|
+
-> (event) {
|
44
44
|
@text = event.target.value
|
45
|
-
event_listener.call(event)
|
45
|
+
event_listener.call(event)
|
46
46
|
}
|
47
47
|
}
|
48
48
|
}
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# Copyright (c) 2020 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/ui/custom_widget'
|
23
|
+
|
24
|
+
module Glimmer
|
25
|
+
module SWT
|
26
|
+
module Custom
|
27
|
+
# A custom widget rendering a group of checkboxes generated via data-binding
|
28
|
+
class CheckboxGroup
|
29
|
+
include Glimmer::UI::CustomWidget
|
30
|
+
|
31
|
+
body {
|
32
|
+
composite # just an empty composite to hold checkboxs upon data-binding `selection`
|
33
|
+
}
|
34
|
+
|
35
|
+
def items=(text_array)
|
36
|
+
selection_value = selection
|
37
|
+
@items = Array[*text_array]
|
38
|
+
build_checkboxes
|
39
|
+
end
|
40
|
+
|
41
|
+
def items
|
42
|
+
@items || []
|
43
|
+
end
|
44
|
+
|
45
|
+
def selection=(selection_texts)
|
46
|
+
items.count.times do |index|
|
47
|
+
checkbox = checkboxes[index]
|
48
|
+
item = items[index]
|
49
|
+
checkbox_text = checkbox&.text
|
50
|
+
checkbox.selection = selection_texts.to_a.include?(checkbox_text)
|
51
|
+
end
|
52
|
+
selection_texts
|
53
|
+
end
|
54
|
+
|
55
|
+
def selection
|
56
|
+
selection_indices.map do |selection_index|
|
57
|
+
checkboxes[selection_index]&.text
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def selection_indices=(indices)
|
62
|
+
self.selection=(indices.to_a.map {|index| items[index]})
|
63
|
+
end
|
64
|
+
alias select selection_indices=
|
65
|
+
|
66
|
+
def selection_indices
|
67
|
+
checkboxes.each_with_index.map do |checkbox, index|
|
68
|
+
index if checkbox.selection
|
69
|
+
end.to_a.compact
|
70
|
+
end
|
71
|
+
|
72
|
+
def checkboxes
|
73
|
+
@checkboxes ||= []
|
74
|
+
end
|
75
|
+
alias checks checkboxes
|
76
|
+
|
77
|
+
def can_handle_observation_request?(observation_request)
|
78
|
+
checkboxes.first&.can_handle_observation_request?(observation_request) || super(observation_request)
|
79
|
+
end
|
80
|
+
|
81
|
+
def handle_observation_request(observation_request, &block)
|
82
|
+
observation_requests << [observation_request, block]
|
83
|
+
delegate_observation_request_to_checkboxes(observation_request, &block)
|
84
|
+
super
|
85
|
+
end
|
86
|
+
|
87
|
+
def delegate_observation_request_to_checkboxes(observation_request, &block)
|
88
|
+
if observation_request != 'on_widget_disposed'
|
89
|
+
checkboxes.count.times do |index|
|
90
|
+
checkbox = checkboxes[index]
|
91
|
+
checkbox.handle_observation_request(observation_request, &block) if checkbox.can_handle_observation_request?(observation_request)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def observation_requests
|
97
|
+
@observation_requests ||= Set.new
|
98
|
+
end
|
99
|
+
|
100
|
+
def has_attribute?(attribute_name, *args)
|
101
|
+
@checkboxes.to_a.map do |widget_proxy|
|
102
|
+
return true if widget_proxy.has_attribute?(attribute_name, *args)
|
103
|
+
end
|
104
|
+
super
|
105
|
+
end
|
106
|
+
|
107
|
+
def set_attribute(attribute_name, *args)
|
108
|
+
excluded_attributes = ['selection']
|
109
|
+
unless excluded_attributes.include?(attribute_name.to_s)
|
110
|
+
@checkboxes.to_a.each do |widget_proxy|
|
111
|
+
widget_proxy.set_attribute(attribute_name, *args) if widget_proxy.has_attribute?(attribute_name, *args)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
super
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def build_checkboxes
|
120
|
+
current_selection = selection
|
121
|
+
@checkboxes = []
|
122
|
+
items.each do |item|
|
123
|
+
body_root.content {
|
124
|
+
checkboxes << checkbox { |checkbox_proxy|
|
125
|
+
text item
|
126
|
+
on_widget_selected {
|
127
|
+
self.selection_indices = checkboxes.each_with_index.map {|cb, i| i if cb.selection}.to_a.compact
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
end
|
132
|
+
observation_requests.to_a.each do |observation_request, block|
|
133
|
+
delegate_observation_request_to_checkboxes(observation_request, &block)
|
134
|
+
end
|
135
|
+
self.selection = current_selection
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
CheckGroup = CheckboxGroup # alias
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# Copyright (c) 2020 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/ui/custom_widget'
|
23
|
+
|
24
|
+
module Glimmer
|
25
|
+
module SWT
|
26
|
+
module Custom
|
27
|
+
# A custom widget rendering a group of radios generated via data-binding
|
28
|
+
class RadioGroup
|
29
|
+
include Glimmer::UI::CustomWidget
|
30
|
+
|
31
|
+
body {
|
32
|
+
composite # just an empty composite to hold radios upon data-binding `selection`
|
33
|
+
}
|
34
|
+
|
35
|
+
def items=(text_array)
|
36
|
+
selection_value = selection
|
37
|
+
@items = Array[*text_array]
|
38
|
+
build_radios
|
39
|
+
end
|
40
|
+
|
41
|
+
def items
|
42
|
+
@items || []
|
43
|
+
end
|
44
|
+
|
45
|
+
def selection=(text)
|
46
|
+
radios.count.times do |index|
|
47
|
+
radio = radios[index]
|
48
|
+
item = items[index]
|
49
|
+
radio.selection = item == text
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def selection
|
54
|
+
selection_value = radios[selection_index]&.text unless selection_index == -1
|
55
|
+
selection_value.to_s
|
56
|
+
end
|
57
|
+
|
58
|
+
def selection_index=(index)
|
59
|
+
self.selection=(items[index])
|
60
|
+
end
|
61
|
+
alias select selection_index=
|
62
|
+
|
63
|
+
def selection_index
|
64
|
+
radios.index(radios.detect(&:selection)) || -1
|
65
|
+
end
|
66
|
+
|
67
|
+
def radios
|
68
|
+
@radios ||= []
|
69
|
+
end
|
70
|
+
|
71
|
+
def observation_request_to_event_mapping
|
72
|
+
# TODO method might not be needed
|
73
|
+
{
|
74
|
+
'on_widget_selected' => {
|
75
|
+
event: 'change'
|
76
|
+
},
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
def can_handle_observation_request?(observation_request)
|
81
|
+
radios.first&.can_handle_observation_request?(observation_request) || super(observation_request)
|
82
|
+
end
|
83
|
+
|
84
|
+
def handle_observation_request(observation_request, &block)
|
85
|
+
observation_requests << [observation_request, block]
|
86
|
+
delegate_observation_request_to_radios(observation_request, &block)
|
87
|
+
super
|
88
|
+
end
|
89
|
+
|
90
|
+
def delegate_observation_request_to_radios(observation_request, &block)
|
91
|
+
if observation_request != 'on_widget_disposed'
|
92
|
+
radios.count.times do |index|
|
93
|
+
radio = radios[index]
|
94
|
+
radio.handle_observation_request(observation_request, &block) if radio.can_handle_observation_request?(observation_request)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def observation_requests
|
100
|
+
@observation_requests ||= Set.new
|
101
|
+
end
|
102
|
+
|
103
|
+
def has_attribute?(attribute_name, *args)
|
104
|
+
@radios.to_a.map do |widget_proxy|
|
105
|
+
return true if widget_proxy.has_attribute?(attribute_name, *args)
|
106
|
+
end
|
107
|
+
super
|
108
|
+
end
|
109
|
+
|
110
|
+
def set_attribute(attribute_name, *args)
|
111
|
+
excluded_attributes = ['selection']
|
112
|
+
unless excluded_attributes.include?(attribute_name.to_s)
|
113
|
+
@radios.to_a.each do |widget_proxy|
|
114
|
+
widget_proxy.set_attribute(attribute_name, *args) if widget_proxy.has_attribute?(attribute_name, *args)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
super
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def build_radios
|
123
|
+
current_selection = selection
|
124
|
+
@radios = []
|
125
|
+
items.each do |item|
|
126
|
+
body_root.content {
|
127
|
+
radios << radio { |radio_proxy|
|
128
|
+
text item
|
129
|
+
on_widget_selected {
|
130
|
+
self.selection = items[radios.index(radio_proxy)]
|
131
|
+
}
|
132
|
+
}
|
133
|
+
}
|
134
|
+
end
|
135
|
+
observation_requests.to_a.each do |observation_request, block|
|
136
|
+
delegate_observation_request_to_radios(observation_request, &block)
|
137
|
+
end
|
138
|
+
self.selection = current_selection
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|