glimmer-dsl-opal 0.6.0 → 0.7.3
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 +51 -0
- data/README.md +428 -18
- data/VERSION +1 -1
- data/app/assets/stylesheets/{glimmer.css → glimmer/glimmer.css} +1 -1
- data/lib/display.rb +31 -0
- data/lib/file.rb +29 -0
- data/lib/glimmer-dsl-opal.rb +33 -5
- data/lib/glimmer-dsl-opal/ext/date.rb +11 -0
- data/lib/glimmer-dsl-opal/ext/struct.rb +37 -0
- data/lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb +23 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_table.rb +283 -0
- data/lib/glimmer-dsl-swt.rb +20 -35
- data/lib/glimmer/data_binding/table_items_binding.rb +32 -19
- data/lib/glimmer/dsl/opal/block_property_expression.rb +41 -0
- data/lib/glimmer/dsl/opal/custom_widget_expression.rb +1 -1
- data/lib/glimmer/dsl/opal/dsl.rb +2 -0
- data/lib/glimmer/dsl/opal/widget_expression.rb +7 -3
- data/lib/glimmer/engine.rb +1 -1
- data/lib/glimmer/swt/button_proxy.rb +5 -5
- data/lib/glimmer/swt/color_proxy.rb +45 -45
- data/lib/glimmer/swt/combo_proxy.rb +42 -3
- data/lib/glimmer/swt/composite_proxy.rb +7 -3
- data/lib/glimmer/swt/control_editor.rb +54 -0
- data/lib/glimmer/swt/date_time_proxy.rb +71 -5
- data/lib/glimmer/swt/display_proxy.rb +6 -2
- data/lib/glimmer/swt/fill_layout_proxy.rb +1 -1
- data/lib/glimmer/swt/font_proxy.rb +4 -4
- data/lib/glimmer/swt/label_proxy.rb +2 -2
- data/lib/glimmer/swt/layout_data_proxy.rb +13 -10
- data/lib/glimmer/swt/layout_proxy.rb +5 -5
- data/lib/glimmer/swt/list_proxy.rb +2 -2
- data/lib/glimmer/swt/message_box_proxy.rb +4 -2
- data/lib/glimmer/swt/property_owner.rb +2 -2
- data/lib/glimmer/swt/shell_proxy.rb +8 -0
- data/lib/glimmer/swt/tab_folder_proxy.rb +2 -2
- data/lib/glimmer/swt/tab_item_proxy.rb +7 -7
- data/lib/glimmer/swt/table_column_proxy.rb +71 -12
- data/lib/glimmer/swt/table_editor.rb +65 -0
- data/lib/glimmer/swt/table_item_proxy.rb +50 -7
- data/lib/glimmer/swt/table_proxy.rb +581 -14
- data/lib/glimmer/swt/text_proxy.rb +49 -1
- data/lib/glimmer/swt/widget_proxy.rb +120 -22
- data/lib/glimmer/ui/custom_widget.rb +8 -8
- data/lib/net/http.rb +1 -5
- data/lib/os.rb +36 -0
- data/lib/uri.rb +3 -3
- metadata +31 -10
- data/lib/glimmer/data_binding/ext/observable_model.rb +0 -40
@@ -6,9 +6,13 @@ module Glimmer
|
|
6
6
|
class CompositeProxy < WidgetProxy
|
7
7
|
attr_reader :layout
|
8
8
|
|
9
|
-
def initialize(parent, args)
|
10
|
-
super(parent, args)
|
11
|
-
@layout =
|
9
|
+
def initialize(parent, args, block)
|
10
|
+
super(parent, args, block)
|
11
|
+
@layout = default_layout
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_layout
|
15
|
+
GridLayoutProxy.new(self, [])
|
12
16
|
end
|
13
17
|
|
14
18
|
def dom
|
@@ -0,0 +1,54 @@
|
|
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
|
+
module Glimmer
|
23
|
+
module SWT
|
24
|
+
# Emulates SWT's native org.eclipse.swt.custom.ControlEditor
|
25
|
+
class ControlEditor
|
26
|
+
# TODO implement behavior for all these attributes
|
27
|
+
ATTRIBUTES = [:grabHorizontal, :grabVertical, :horizontalAlignment, :verticalAlignment, :minimumWidth, :minimumHeight]
|
28
|
+
attr_accessor(*ATTRIBUTES)
|
29
|
+
ATTRIBUTES.each do |attribute|
|
30
|
+
alias_method attribute.underscore, attribute
|
31
|
+
alias_method "#{attribute.underscore}=", "#{attribute}="
|
32
|
+
end
|
33
|
+
|
34
|
+
# TODO consider supporting a java_attr_accessor to get around having to generate all the aliases manually
|
35
|
+
attr_accessor :editor
|
36
|
+
alias getEditor editor
|
37
|
+
alias get_editor editor
|
38
|
+
alias setEditor editor=
|
39
|
+
alias set_editor editor=
|
40
|
+
|
41
|
+
# TODO implement `#layout` method if needed
|
42
|
+
|
43
|
+
attr_reader :composite
|
44
|
+
|
45
|
+
def initialize(composite)
|
46
|
+
@composite = composite
|
47
|
+
end
|
48
|
+
|
49
|
+
# TODO implement showing editor for composite or canvas
|
50
|
+
# def editor=(widget)
|
51
|
+
# end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -4,7 +4,7 @@ module Glimmer
|
|
4
4
|
module SWT
|
5
5
|
class DateTimeProxy < WidgetProxy
|
6
6
|
class << self
|
7
|
-
def create(keyword, parent, args)
|
7
|
+
def create(keyword, parent, args, block)
|
8
8
|
case keyword
|
9
9
|
when 'date'
|
10
10
|
args += [:date]
|
@@ -15,12 +15,13 @@ module Glimmer
|
|
15
15
|
when 'calendar'
|
16
16
|
args += [:calendar]
|
17
17
|
end
|
18
|
-
new(parent, args)
|
18
|
+
new(parent, args, block)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def initialize(parent, args)
|
23
|
-
super(parent, args)
|
22
|
+
def initialize(parent, args, block)
|
23
|
+
super(parent, args, block)
|
24
|
+
post_add_content if block.nil?
|
24
25
|
end
|
25
26
|
|
26
27
|
def post_add_content
|
@@ -30,7 +31,13 @@ module Glimmer
|
|
30
31
|
showPeriod: true,
|
31
32
|
showLeadingZero: true,
|
32
33
|
showOn: 'both',
|
34
|
+
showNowButton: true,
|
35
|
+
showCloseButton: true,
|
33
36
|
button: "##{time_button_id}",
|
37
|
+
onClose: ->(v) {
|
38
|
+
@timepicker_done = true
|
39
|
+
dom_element.trigger('change')
|
40
|
+
},
|
34
41
|
})
|
35
42
|
else
|
36
43
|
options = {}
|
@@ -104,9 +111,68 @@ module Glimmer
|
|
104
111
|
{
|
105
112
|
'on_widget_selected' => [
|
106
113
|
{
|
107
|
-
event: 'change'
|
114
|
+
event: 'change',
|
115
|
+
event_handler: -> (event_listener) {
|
116
|
+
-> (event) {
|
117
|
+
if date? || (time? && @timepicker_done)
|
118
|
+
@timepicker_done = false if time?
|
119
|
+
event_listener.call(event)
|
120
|
+
end
|
121
|
+
}
|
122
|
+
}
|
108
123
|
},
|
109
124
|
],
|
125
|
+
'on_focus_lost' => [
|
126
|
+
{
|
127
|
+
event: 'blur',
|
128
|
+
event_handler: -> (event_listener) {
|
129
|
+
-> (event) {
|
130
|
+
# TODO support blur event for date?
|
131
|
+
if time? && @timepicker_done
|
132
|
+
@timepicker_done = false if time?
|
133
|
+
event_listener.call(event)
|
134
|
+
end
|
135
|
+
}
|
136
|
+
}
|
137
|
+
},
|
138
|
+
],
|
139
|
+
'on_key_pressed' => {
|
140
|
+
event: 'keydown',
|
141
|
+
event_handler: -> (event_listener) {
|
142
|
+
-> (event) {
|
143
|
+
# TODO generalize this solution to all widgets that support key presses
|
144
|
+
# TODO support event.location once DOM3 is supported by opal-jquery
|
145
|
+
event.define_singleton_method(:keyCode) {event.which}
|
146
|
+
event.define_singleton_method(:key_code, &event.method(:keyCode))
|
147
|
+
event.define_singleton_method(:character) {event.which.chr}
|
148
|
+
event.define_singleton_method(:stateMask) do
|
149
|
+
state_mask = 0
|
150
|
+
state_mask |= SWTProxy[:alt] if event.alt_key
|
151
|
+
state_mask |= SWTProxy[:ctrl] if event.ctrl_key
|
152
|
+
state_mask |= SWTProxy[:shift] if event.shift_key
|
153
|
+
state_mask |= SWTProxy[:command] if event.meta_key
|
154
|
+
state_mask
|
155
|
+
end
|
156
|
+
event.define_singleton_method(:state_mask, &event.method(:stateMask))
|
157
|
+
doit = true
|
158
|
+
event.define_singleton_method(:doit=) do |value|
|
159
|
+
doit = value
|
160
|
+
end
|
161
|
+
event.define_singleton_method(:doit) { doit }
|
162
|
+
event_listener.call(event)
|
163
|
+
|
164
|
+
# TODO Fix doit false, it's not stopping input
|
165
|
+
unless doit
|
166
|
+
event.prevent
|
167
|
+
event.prevent_default
|
168
|
+
event.stop_propagation
|
169
|
+
event.stop_immediate_propagation
|
170
|
+
end
|
171
|
+
|
172
|
+
doit
|
173
|
+
}
|
174
|
+
}
|
175
|
+
},
|
110
176
|
}
|
111
177
|
end
|
112
178
|
|
@@ -24,6 +24,10 @@ module Glimmer
|
|
24
24
|
Document
|
25
25
|
end
|
26
26
|
|
27
|
+
def shells
|
28
|
+
@shells ||= []
|
29
|
+
end
|
30
|
+
|
27
31
|
def render
|
28
32
|
# No rendering as body is rendered as part of ShellProxy.. this class only serves as an SWT Display utility
|
29
33
|
end
|
@@ -66,10 +70,10 @@ module Glimmer
|
|
66
70
|
event_listener.call(event) if event.key_code != 13 && (event.key_code == 127 || event.key_code <= 31)
|
67
71
|
}
|
68
72
|
}
|
69
|
-
}
|
73
|
+
}
|
70
74
|
]
|
71
75
|
}
|
72
|
-
end
|
76
|
+
end
|
73
77
|
|
74
78
|
def shells
|
75
79
|
@shells ||= []
|
@@ -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
|
@@ -68,7 +68,7 @@ module Glimmer
|
|
68
68
|
private
|
69
69
|
|
70
70
|
def detect_invalid_font_property(font_properties)
|
71
|
-
|
71
|
+
font_properties[:style].to_collection(false).select do |style|
|
72
72
|
style.is_a?(Symbol) || style.is_a?(String)
|
73
73
|
end.each do |style|
|
74
74
|
raise Error, style.to_s + ERROR_INVALID_FONT_STYLE if !FONT_STYLES.include?(style.to_sym)
|
@@ -6,8 +6,8 @@ module Glimmer
|
|
6
6
|
class LabelProxy < WidgetProxy
|
7
7
|
attr_reader :text, :background_image, :image, :alignment
|
8
8
|
|
9
|
-
def initialize(parent, args)
|
10
|
-
super(parent, args)
|
9
|
+
def initialize(parent, args, block)
|
10
|
+
super(parent, args, block)
|
11
11
|
self.alignment = [:left, :center, :right].detect {|align| args.detect { |arg| SWTProxy[align] == arg } }
|
12
12
|
end
|
13
13
|
|
@@ -3,15 +3,16 @@ require 'glimmer/swt/property_owner'
|
|
3
3
|
module Glimmer
|
4
4
|
module SWT
|
5
5
|
class LayoutDataProxy
|
6
|
+
# TODO make this polymorphic as GridData or RowData subclasses
|
6
7
|
include Glimmer::SWT::PropertyOwner
|
7
|
-
attr_reader :parent,
|
8
|
-
:args,
|
9
|
-
:horizontal_alignment,
|
10
|
-
:vertical_alignment,
|
11
|
-
:horizontal_span,
|
12
|
-
:vertical_span,
|
13
|
-
:horizontal_indent,
|
14
|
-
:vertical_indent,
|
8
|
+
attr_reader :parent,
|
9
|
+
:args,
|
10
|
+
:horizontal_alignment,
|
11
|
+
:vertical_alignment,
|
12
|
+
:horizontal_span,
|
13
|
+
:vertical_span,
|
14
|
+
:horizontal_indent,
|
15
|
+
:vertical_indent,
|
15
16
|
:grab_excess_horizontal_space,
|
16
17
|
:grab_excess_vertical_space,
|
17
18
|
:width_hint,
|
@@ -48,6 +49,8 @@ module Glimmer
|
|
48
49
|
@parent.dom_element.css('width', '100%') if width_hint.nil?
|
49
50
|
else
|
50
51
|
@parent.dom_element.css('text-align', @horizontal_alignment)
|
52
|
+
@parent.dom_element.css('margin-left', 'auto') if ['right', 'center'].include?(@horizontal_alignment.to_s)
|
53
|
+
@parent.dom_element.css('margin-right', 'auto') if ['left', 'center'].include?(@horizontal_alignment.to_s)
|
51
54
|
end
|
52
55
|
# TODO
|
53
56
|
# reapply
|
@@ -85,13 +88,13 @@ module Glimmer
|
|
85
88
|
|
86
89
|
def grab_excess_horizontal_space=(grab_excess_horizontal_space)
|
87
90
|
@grab_excess_horizontal_space = grab_excess_horizontal_space
|
88
|
-
@parent.dom_element.css('width', "100%") if @grab_excess_horizontal_space && width_hint.nil?
|
91
|
+
@parent.dom_element.css('width', "100%") if @grab_excess_horizontal_space && @horizontal_alignment == 'fill' && width_hint.nil?
|
89
92
|
# reapply
|
90
93
|
end
|
91
94
|
|
92
95
|
def grab_excess_vertical_space=(grab_excess_vertical_space)
|
93
96
|
@grab_excess_vertical_space = grab_excess_vertical_space
|
94
|
-
@parent.dom_element.css('height', "100%") if @grab_excess_vertical_space && height_hint.nil?
|
97
|
+
@parent.dom_element.css('height', "100%") if @grab_excess_vertical_space && @vertical_alignment == 'fill' && height_hint.nil?
|
95
98
|
# TODO
|
96
99
|
# reapply
|
97
100
|
end
|
@@ -18,28 +18,28 @@ module Glimmer
|
|
18
18
|
a_layout_class = Glimmer::SWT.const_get(class_name_main.to_sym) rescue Glimmer::SWT.const_get(class_name_alternative.to_sym)
|
19
19
|
a_layout_class if a_layout_class.ancestors.include?(Glimmer::SWT::LayoutProxy)
|
20
20
|
rescue => e
|
21
|
-
|
21
|
+
Glimmer::Config.logger.debug "Layout #{keyword} was not found!"
|
22
22
|
nil
|
23
23
|
end
|
24
24
|
|
25
25
|
def layout_exists?(keyword)
|
26
26
|
!!layout_class(keyword)
|
27
27
|
end
|
28
|
-
end
|
28
|
+
end
|
29
29
|
|
30
30
|
attr_reader :parent, :args
|
31
31
|
|
32
|
-
def initialize(parent, args)
|
32
|
+
def initialize(parent, args)
|
33
33
|
@parent = parent
|
34
34
|
@parent = parent.body_root if @parent.is_a?(Glimmer::UI::CustomWidget)
|
35
35
|
@parent.css_classes.each do |css_class|
|
36
36
|
@parent.remove_css_class(css_class) if css_class.include?('layout')
|
37
37
|
end
|
38
|
-
@args = args
|
38
|
+
@args = args
|
39
39
|
@parent.add_css_class(css_class)
|
40
40
|
@parent.layout = self
|
41
41
|
self.margin_width = 15 if respond_to?(:margin_width=)
|
42
|
-
self.margin_height = 15 if respond_to?(:margin_height=)
|
42
|
+
self.margin_height = 15 if respond_to?(:margin_height=)
|
43
43
|
end
|
44
44
|
|
45
45
|
def css_class
|
@@ -1,14 +1,16 @@
|
|
1
1
|
require 'glimmer/swt/widget_proxy'
|
2
|
+
require 'glimmer/swt/display_proxy'
|
2
3
|
|
3
4
|
module Glimmer
|
4
5
|
module SWT
|
5
6
|
class MessageBoxProxy < WidgetProxy
|
6
7
|
attr_reader :text, :message
|
7
8
|
|
8
|
-
def initialize(parent, args)
|
9
|
+
def initialize(parent, args, block)
|
9
10
|
i = 0
|
10
|
-
@parent = parent
|
11
|
+
@parent = parent || DisplayProxy.instance.shells.first
|
11
12
|
@args = args
|
13
|
+
@block = block
|
12
14
|
@children = Set.new
|
13
15
|
@enabled = true
|
14
16
|
content do
|
@@ -7,7 +7,7 @@ module Glimmer
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def set_attribute(attribute_name, *args)
|
10
|
-
send(attribute_setter(attribute_name), *args) unless send(attribute_getter(attribute_name)) == args.first
|
10
|
+
send(attribute_setter(attribute_name), *args) unless args.size == 1 && send(attribute_getter(attribute_name)) == args.first
|
11
11
|
end
|
12
12
|
|
13
13
|
def attribute_setter(attribute_name)
|
@@ -16,7 +16,7 @@ module Glimmer
|
|
16
16
|
|
17
17
|
def attribute_getter(attribute_name)
|
18
18
|
attribute_name.to_s.underscore
|
19
|
-
end
|
19
|
+
end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -21,6 +21,7 @@ module Glimmer
|
|
21
21
|
@layout.margin_width = 0
|
22
22
|
@layout.margin_height = 0
|
23
23
|
self.minimum_size = Point.new(WIDTH_MIN, HEIGHT_MIN)
|
24
|
+
DisplayProxy.instance.shells << self
|
24
25
|
end
|
25
26
|
|
26
27
|
def element
|
@@ -207,6 +208,7 @@ module Glimmer
|
|
207
208
|
body_class = ([name] + css_classes.to_a).join(' ')
|
208
209
|
@dom ||= html {
|
209
210
|
div(id: body_id, class: body_class) {
|
211
|
+
# TODO support the idea of dynamic CSS building on close of shell that adds only as much CSS as needed for widgets that were mentioned
|
210
212
|
style(class: 'common-style') {
|
211
213
|
style_dom_css
|
212
214
|
}
|
@@ -246,6 +248,12 @@ module Glimmer
|
|
246
248
|
style(class: 'scrolled-composite-style') {
|
247
249
|
Glimmer::SWT::ScrolledCompositeProxy::STYLE
|
248
250
|
}
|
251
|
+
style(class: 'table-item-style') {
|
252
|
+
Glimmer::SWT::TableItemProxy::STYLE
|
253
|
+
}
|
254
|
+
style(class: 'table-column-style') {
|
255
|
+
Glimmer::SWT::TableColumnProxy::STYLE
|
256
|
+
}
|
249
257
|
}
|
250
258
|
}.to_s
|
251
259
|
end
|
@@ -4,10 +4,10 @@ module Glimmer
|
|
4
4
|
module SWT
|
5
5
|
class TabItemProxy < CompositeProxy
|
6
6
|
include Glimmer
|
7
|
-
attr_reader :text, :content_visible
|
7
|
+
attr_reader :text, :content_visible
|
8
8
|
|
9
|
-
def initialize(parent, args)
|
10
|
-
super(parent, args)
|
9
|
+
def initialize(parent, args, block)
|
10
|
+
super(parent, args, block)
|
11
11
|
content {
|
12
12
|
on_widget_selected {
|
13
13
|
@parent.hide_all_tab_content
|
@@ -35,7 +35,7 @@ module Glimmer
|
|
35
35
|
|
36
36
|
def selector
|
37
37
|
super + '-tab'
|
38
|
-
end
|
38
|
+
end
|
39
39
|
|
40
40
|
def observation_request_to_event_mapping
|
41
41
|
{
|
@@ -47,7 +47,7 @@ module Glimmer
|
|
47
47
|
|
48
48
|
def listener_path
|
49
49
|
tab_path
|
50
|
-
end
|
50
|
+
end
|
51
51
|
|
52
52
|
def tab_path
|
53
53
|
"#{parent.tabs_path} > ##{tab_id}"
|
@@ -72,13 +72,13 @@ module Glimmer
|
|
72
72
|
|
73
73
|
# This contains the tab content
|
74
74
|
def dom
|
75
|
-
tab_item_id = id
|
75
|
+
tab_item_id = id
|
76
76
|
tab_item_class_string = [name, 'hide'].join(' ')
|
77
77
|
@dom ||= html {
|
78
78
|
div(id: tab_item_id, class: tab_item_class_string) {
|
79
79
|
}
|
80
80
|
}.to_s
|
81
|
-
end
|
81
|
+
end
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|