glimmer-dsl-opal 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +530 -13
- data/VERSION +1 -1
- 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_custom_widget.rb +3 -3
- data/lib/glimmer-dsl-opal/samples/hello/hello_group.rb +104 -0
- 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-swt.rb +1 -0
- data/lib/glimmer/data_binding/element_binding.rb +2 -1
- data/lib/glimmer/dsl/opal/checkbox_group_selection_data_binding_expression.rb +61 -0
- data/lib/glimmer/dsl/opal/custom_widget_expression.rb +7 -5
- data/lib/glimmer/dsl/opal/dsl.rb +4 -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/swt/button_proxy.rb +15 -1
- data/lib/glimmer/swt/checkbox_proxy.rb +80 -0
- data/lib/glimmer/swt/combo_proxy.rb +4 -4
- data/lib/glimmer/swt/custom/checkbox_group.rb +142 -0
- data/lib/glimmer/swt/custom/radio_group.rb +143 -0
- 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 +31 -13
- data/lib/glimmer/swt/list_proxy.rb +2 -2
- data/lib/glimmer/swt/radio_proxy.rb +81 -0
- data/lib/glimmer/swt/row_layout_proxy.rb +32 -9
- data/lib/glimmer/swt/scrolled_composite_proxy.rb +20 -0
- data/lib/glimmer/swt/shell_proxy.rb +21 -9
- data/lib/glimmer/swt/widget_proxy.rb +46 -30
- metadata +15 -2
@@ -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
|
@@ -3,6 +3,15 @@ require 'glimmer/swt/layout_proxy'
|
|
3
3
|
module Glimmer
|
4
4
|
module SWT
|
5
5
|
class GridLayoutProxy < LayoutProxy
|
6
|
+
STYLE = <<~CSS
|
7
|
+
.grid-layout {
|
8
|
+
display: grid;
|
9
|
+
grid-template-rows: min-content;
|
10
|
+
justify-content: start;
|
11
|
+
place-content: start;
|
12
|
+
align-items: stretch;
|
13
|
+
}
|
14
|
+
CSS
|
6
15
|
attr_reader :num_columns, :make_columns_equal_width, :horizontal_spacing, :vertical_spacing, :margin_width, :margin_height
|
7
16
|
|
8
17
|
def initialize(parent, args)
|
@@ -52,19 +61,21 @@ module Glimmer
|
|
52
61
|
end
|
53
62
|
|
54
63
|
def reapply
|
64
|
+
# TODO get rid of this method
|
55
65
|
layout_css = <<~CSS
|
56
|
-
display: grid;
|
57
66
|
grid-template-columns: #{'auto ' * @num_columns.to_i};
|
58
|
-
grid-template-rows: min-content;
|
59
67
|
grid-row-gap: #{@vertical_spacing}px;
|
60
68
|
grid-column-gap: #{@horizontal_spacing}px;
|
61
|
-
justify-content: start;
|
62
|
-
place-content: start;
|
63
|
-
align-items: stretch;
|
64
69
|
CSS
|
65
|
-
|
66
|
-
|
67
|
-
|
70
|
+
if @parent.css_classes.include?('grid-layout')
|
71
|
+
layout_css.split(";").map(&:strip).map {|l| l.split(':').map(&:strip)}.each do |key, value|
|
72
|
+
@parent.dom_element.css(key, value) unless key.nil?
|
73
|
+
end
|
74
|
+
else
|
75
|
+
layout_css.split(";").map(&:strip).map {|l| l.split(':').map(&:strip)}.each do |key, value|
|
76
|
+
@parent.dom_element.css(key, 'initial') unless key.nil?
|
77
|
+
end
|
78
|
+
end
|
68
79
|
end
|
69
80
|
end
|
70
81
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'glimmer/swt/widget_proxy'
|
2
|
+
|
3
|
+
module Glimmer
|
4
|
+
module SWT
|
5
|
+
# Adapter for org.eclipse.swt.widgets.Group
|
6
|
+
#
|
7
|
+
# Follows Adapter Pattern
|
8
|
+
class GroupProxy < CompositeProxy
|
9
|
+
attr_reader :text
|
10
|
+
|
11
|
+
def text=(value)
|
12
|
+
@text = value
|
13
|
+
if @text.nil?
|
14
|
+
legend_dom_element.add_class('hide')
|
15
|
+
else
|
16
|
+
legend_dom_element.remove_class('hide')
|
17
|
+
end
|
18
|
+
legend_dom_element.html(@text)
|
19
|
+
end
|
20
|
+
|
21
|
+
def element
|
22
|
+
'fieldset'
|
23
|
+
end
|
24
|
+
|
25
|
+
def legend_dom_element
|
26
|
+
dom_element.find('legend')
|
27
|
+
end
|
28
|
+
|
29
|
+
def dom
|
30
|
+
@dom ||= html {
|
31
|
+
fieldset(id: id, class: name) {
|
32
|
+
legend(class: 'hide') { text }
|
33
|
+
}
|
34
|
+
}.to_s
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,30 +1,50 @@
|
|
1
1
|
require 'glimmer/swt/widget_proxy'
|
2
|
+
# require 'glimmer/swt/image_proxy'
|
2
3
|
|
3
4
|
module Glimmer
|
4
5
|
module SWT
|
5
6
|
class LabelProxy < WidgetProxy
|
6
|
-
attr_reader :text
|
7
|
+
attr_reader :text, :background_image, :image, :alignment
|
8
|
+
|
9
|
+
def initialize(parent, args)
|
10
|
+
super(parent, args)
|
11
|
+
self.alignment = [:left, :center, :right].detect {|align| args.detect { |arg| SWTProxy[align] == arg } }
|
12
|
+
end
|
7
13
|
|
8
14
|
def text=(value)
|
9
15
|
@text = value
|
10
16
|
dom_element.html(value)
|
11
17
|
end
|
12
18
|
|
19
|
+
def background_image=(*image_options)
|
20
|
+
# TODO consider if there is a difference between background_image and image in label and to have one reuse the other
|
21
|
+
# TODO finish implementation
|
22
|
+
# @background_image = Glimmer::SWT::ImageProxy.create(*image_options)
|
23
|
+
# dom_element.css('background-image', @background_image.image_data.dom_element.src)
|
24
|
+
end
|
25
|
+
|
26
|
+
def image=(*image_options)
|
27
|
+
# TODO finish implementation
|
28
|
+
# @image = Glimmer::SWT::ImageProxy.create(*image_options)
|
29
|
+
# dom_element.css('background-image', @image.image_data.dom_element.src)
|
30
|
+
end
|
31
|
+
|
13
32
|
def element
|
14
33
|
'label'
|
15
34
|
end
|
16
|
-
|
17
|
-
def alignment
|
18
|
-
|
35
|
+
|
36
|
+
def alignment=(value)
|
37
|
+
# TODO consider storing swt value in the future instead
|
38
|
+
@alignment = value
|
39
|
+
dom_element.css('text-align', @alignment.to_s)
|
19
40
|
end
|
20
41
|
|
21
|
-
def dom
|
42
|
+
def dom
|
22
43
|
label_text = @text
|
23
44
|
label_id = id
|
24
|
-
label_style = "text-align: #{alignment};"
|
25
45
|
label_class = name
|
26
46
|
@dom ||= html {
|
27
|
-
label(id: label_id,
|
47
|
+
label(id: label_id, class: label_class) {
|
28
48
|
label_text
|
29
49
|
}
|
30
50
|
}.to_s
|
@@ -14,68 +14,86 @@ module Glimmer
|
|
14
14
|
:vertical_indent,
|
15
15
|
:grab_excess_horizontal_space,
|
16
16
|
:grab_excess_vertical_space,
|
17
|
+
:width_hint,
|
17
18
|
:height_hint
|
18
19
|
|
19
20
|
def initialize(parent, args)
|
20
21
|
@parent = parent
|
21
22
|
@args = args
|
22
|
-
|
23
|
+
self.horizontal_alignment = @args[0] if @args[0]
|
24
|
+
self.vertical_alignment = @args[1] if @args[1]
|
25
|
+
self.grab_excess_horizontal_space = @args[2] if @args[2]
|
26
|
+
self.grab_excess_vertical_space = @args[3] if @args[3]
|
27
|
+
# TODO spread args correctly as per SWT LayoutData API
|
23
28
|
# TODO avoid using reapply
|
24
|
-
|
29
|
+
# reapply
|
30
|
+
end
|
31
|
+
|
32
|
+
def width_hint=(width_hint)
|
33
|
+
@width_hint = width_hint
|
34
|
+
@parent.dom_element.css('width', "#{@width_hint}px")
|
35
|
+
# reapply
|
25
36
|
end
|
26
37
|
|
27
38
|
def height_hint=(height_hint)
|
28
39
|
@height_hint = height_hint
|
29
|
-
#
|
30
|
-
|
40
|
+
@parent.dom_element.css('height', "#{@height_hint}px")
|
41
|
+
# reapply
|
31
42
|
end
|
32
43
|
|
33
44
|
def horizontal_alignment=(horizontal_alignment)
|
34
45
|
@horizontal_alignment = horizontal_alignment
|
46
|
+
return if @horizontal_alignment.nil?
|
47
|
+
if @horizontal_alignment == 'fill'
|
48
|
+
@parent.dom_element.css('width', '100%') if width_hint.nil?
|
49
|
+
else
|
50
|
+
@parent.dom_element.css('text-align', @horizontal_alignment)
|
51
|
+
end
|
35
52
|
# TODO
|
36
|
-
|
53
|
+
# reapply
|
37
54
|
end
|
38
55
|
|
39
56
|
def vertical_alignment=(vertical_alignment)
|
40
57
|
@vertical_alignment = vertical_alignment
|
41
58
|
# TODO
|
42
|
-
|
59
|
+
# reapply
|
43
60
|
end
|
44
61
|
|
45
62
|
def horizontal_span=(value)
|
46
63
|
@horizontal_span = value
|
47
64
|
@parent.dom_element.css('grid-column-start', "span #{@horizontal_span}")
|
48
|
-
|
65
|
+
# reapply
|
49
66
|
end
|
50
67
|
|
51
68
|
def vertical_span=(value)
|
52
69
|
@vertical_span = value
|
53
70
|
@parent.dom_element.css('grid-row-start', "span #{@vertical_span}")
|
54
|
-
|
71
|
+
# reapply
|
55
72
|
end
|
56
73
|
|
57
74
|
def horizontal_indent=(value)
|
58
75
|
@horizontal_indent = value
|
59
76
|
@parent.dom_element.css('padding-left', @horizontal_indent)
|
60
|
-
|
77
|
+
# reapply
|
61
78
|
end
|
62
79
|
|
63
80
|
def vertical_indent=(value)
|
64
81
|
@vertical_indent = value
|
65
82
|
@parent.dom_element.css('padding-top', @vertical_indent)
|
66
|
-
|
83
|
+
# reapply
|
67
84
|
end
|
68
85
|
|
69
86
|
def grab_excess_horizontal_space=(grab_excess_horizontal_space)
|
70
87
|
@grab_excess_horizontal_space = grab_excess_horizontal_space
|
71
|
-
|
72
|
-
|
88
|
+
@parent.dom_element.css('width', "100%") if @grab_excess_horizontal_space && width_hint.nil?
|
89
|
+
# reapply
|
73
90
|
end
|
74
91
|
|
75
92
|
def grab_excess_vertical_space=(grab_excess_vertical_space)
|
76
93
|
@grab_excess_vertical_space = grab_excess_vertical_space
|
94
|
+
@parent.dom_element.css('height', "100%") if @grab_excess_vertical_space && height_hint.nil?
|
77
95
|
# TODO
|
78
|
-
|
96
|
+
# reapply
|
79
97
|
end
|
80
98
|
|
81
99
|
def reapply
|
@@ -6,7 +6,7 @@ module Glimmer
|
|
6
6
|
ITEM_EMPTY = '_____'
|
7
7
|
attr_reader :items, :selection
|
8
8
|
|
9
|
-
def initialize(parent, args)
|
9
|
+
def initialize(parent, args)
|
10
10
|
super(parent, args)
|
11
11
|
@selection = []
|
12
12
|
end
|
@@ -62,7 +62,7 @@ module Glimmer
|
|
62
62
|
if event.target.prop('nodeName') == 'LI'
|
63
63
|
selected_item = event.target.text
|
64
64
|
select(index_of(selected_item), event.meta_key)
|
65
|
-
event_listener.call(event)
|
65
|
+
event_listener.call(event)
|
66
66
|
end
|
67
67
|
}
|
68
68
|
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'glimmer/swt/widget_proxy'
|
2
|
+
|
3
|
+
module Glimmer
|
4
|
+
module SWT
|
5
|
+
class RadioProxy < WidgetProxy
|
6
|
+
STYLE=<<~CSS
|
7
|
+
.radio {
|
8
|
+
display: inline;
|
9
|
+
}
|
10
|
+
.radio-label {
|
11
|
+
display: inline;
|
12
|
+
}
|
13
|
+
.radio-container {
|
14
|
+
}
|
15
|
+
CSS
|
16
|
+
|
17
|
+
def text
|
18
|
+
label_dom_element.html
|
19
|
+
end
|
20
|
+
|
21
|
+
def text=(value)
|
22
|
+
label_dom_element.html(value)
|
23
|
+
end
|
24
|
+
|
25
|
+
def selection
|
26
|
+
dom_element.prop('checked')
|
27
|
+
end
|
28
|
+
|
29
|
+
def selection=(value)
|
30
|
+
dom_element.prop('checked', value)
|
31
|
+
end
|
32
|
+
|
33
|
+
def element
|
34
|
+
'input'
|
35
|
+
end
|
36
|
+
|
37
|
+
def label_id
|
38
|
+
"#{id}-label"
|
39
|
+
end
|
40
|
+
|
41
|
+
def label_name
|
42
|
+
"#{name}-label"
|
43
|
+
end
|
44
|
+
|
45
|
+
def label_path
|
46
|
+
"#{parent_path} ##{label_id}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def label_dom_element
|
50
|
+
Document.find(label_path)
|
51
|
+
end
|
52
|
+
|
53
|
+
def container_id
|
54
|
+
"#{id}-container"
|
55
|
+
end
|
56
|
+
|
57
|
+
def container_name
|
58
|
+
"#{name}-container"
|
59
|
+
end
|
60
|
+
|
61
|
+
def observation_request_to_event_mapping
|
62
|
+
{
|
63
|
+
'on_widget_selected' => {
|
64
|
+
event: 'change'
|
65
|
+
},
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def dom
|
70
|
+
@dom ||= html {
|
71
|
+
span(id: container_id, class: container_name) {
|
72
|
+
input(type: 'radio', id: id, class: name, name: parent&.id)
|
73
|
+
label(id: label_id, class: label_name, for: id) {
|
74
|
+
text
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}.to_s
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|