glimmer-dsl-opal 0.10.3 → 0.15.1

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +257 -0
  3. data/README.md +188 -1300
  4. data/VERSION +1 -1
  5. data/app/controllers/glimmer/application_controller.rb +4 -0
  6. data/app/controllers/glimmer/image_paths_controller.rb +41 -0
  7. data/app/views/glimmer/image_paths/index.html.erb +1 -0
  8. data/{lib/glimmer-dsl-opal/samples/hello/hello_computed/contact.rb → config/routes.rb} +2 -20
  9. data/lib/display.rb +3 -0
  10. data/lib/glimmer-dsl-opal.rb +8 -3
  11. data/lib/glimmer-dsl-opal/ext/file.rb +31 -0
  12. data/lib/glimmer-dsl-opal/ext/glimmer/dsl/engine.rb +1 -1
  13. data/lib/glimmer-dsl-opal/samples/elaborate/contact_manager.rb +15 -13
  14. data/lib/glimmer-dsl-opal/samples/elaborate/login.rb +55 -28
  15. data/lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb +2 -2
  16. data/lib/glimmer-dsl-opal/samples/elaborate/weather.rb +157 -0
  17. data/lib/glimmer-dsl-opal/samples/hello/hello_button.rb +8 -8
  18. data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox.rb +16 -14
  19. data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox_group.rb +14 -9
  20. data/lib/glimmer-dsl-opal/samples/hello/hello_combo.rb +24 -22
  21. data/lib/glimmer-dsl-opal/samples/hello/hello_computed.rb +32 -14
  22. data/lib/glimmer-dsl-opal/samples/hello/hello_custom_shell.rb +16 -12
  23. data/lib/glimmer-dsl-opal/samples/hello/hello_custom_widget.rb +1 -1
  24. data/lib/glimmer-dsl-opal/samples/hello/hello_date_time.rb +4 -4
  25. data/lib/glimmer-dsl-opal/samples/hello/hello_group.rb +6 -6
  26. data/lib/glimmer-dsl-opal/samples/hello/hello_list_multi_selection.rb +1 -1
  27. data/lib/glimmer-dsl-opal/samples/hello/hello_list_single_selection.rb +1 -1
  28. data/lib/glimmer-dsl-opal/samples/hello/hello_radio.rb +18 -16
  29. data/lib/glimmer-dsl-opal/samples/hello/hello_radio_group.rb +17 -12
  30. data/lib/glimmer-dsl-opal/samples/hello/hello_table.rb +31 -23
  31. data/lib/glimmer-dsl-opal/samples/hello/hello_table/baseball_park.png +0 -0
  32. data/lib/glimmer/data_binding/table_items_binding.rb +3 -2
  33. data/lib/glimmer/dsl/opal/bind_expression.rb +24 -25
  34. data/lib/glimmer/dsl/opal/custom_widget_expression.rb +7 -7
  35. data/lib/glimmer/dsl/opal/dsl.rb +2 -0
  36. data/lib/glimmer/dsl/opal/menu_expression.rb +1 -1
  37. data/lib/glimmer/dsl/opal/property_expression.rb +2 -1
  38. data/lib/glimmer/dsl/opal/shape_expression.rb +1 -1
  39. data/lib/glimmer/dsl/opal/shell_expression.rb +1 -1
  40. data/lib/glimmer/dsl/opal/shine_data_binding_expression.rb +49 -0
  41. data/lib/glimmer/dsl/opal/table_items_data_binding_expression.rb +2 -2
  42. data/lib/glimmer/dsl/opal/widget_expression.rb +1 -1
  43. data/lib/glimmer/engine.rb +21 -0
  44. data/lib/glimmer/swt/combo_proxy.rb +1 -0
  45. data/lib/glimmer/swt/composite_proxy.rb +34 -0
  46. data/lib/glimmer/swt/dialog_proxy.rb +1 -1
  47. data/lib/glimmer/swt/display_proxy.rb +1 -0
  48. data/lib/glimmer/swt/layout_proxy.rb +23 -3
  49. data/lib/glimmer/swt/message_box_proxy.rb +1 -1
  50. data/lib/glimmer/swt/shell_proxy.rb +43 -0
  51. data/lib/glimmer/swt/table_item_proxy.rb +3 -0
  52. data/lib/glimmer/swt/table_proxy.rb +19 -3
  53. data/lib/glimmer/swt/widget_proxy.rb +3 -4
  54. data/lib/glimmer/ui/custom_shell.rb +13 -10
  55. data/lib/glimmer/ui/custom_widget.rb +11 -2
  56. data/lib/net/http.rb +15 -6
  57. metadata +20 -12
@@ -59,7 +59,7 @@ class HelloListMultiSelection
59
59
  text 'Hello, List Multi Selection!'
60
60
 
61
61
  list(:multi) {
62
- selection bind(person, :provinces)
62
+ selection <=> [person, :provinces]
63
63
  }
64
64
 
65
65
  button {
@@ -44,7 +44,7 @@ class HelloListSingleSelection
44
44
  text 'Hello, List Single Selection!'
45
45
 
46
46
  list {
47
- selection bind(person, :country)
47
+ selection <=> [person, :country]
48
48
  }
49
49
 
50
50
  button {
@@ -24,10 +24,10 @@ class HelloRadio
24
24
  attr_accessor :male, :female, :child, :teen, :adult, :senior
25
25
 
26
26
  def initialize
27
- reset
27
+ reset!
28
28
  end
29
29
 
30
- def reset
30
+ def reset!
31
31
  self.male = nil
32
32
  self.female = nil
33
33
  self.child = nil
@@ -37,11 +37,13 @@ class HelloRadio
37
37
  end
38
38
  end
39
39
 
40
- include Glimmer
40
+ include Glimmer::UI::CustomShell
41
41
 
42
- def launch
43
- person = Person.new
44
-
42
+ before_body {
43
+ @person = Person.new
44
+ }
45
+
46
+ body {
45
47
  shell {
46
48
  text 'Hello, Radio!'
47
49
  row_layout :vertical
@@ -56,12 +58,12 @@ class HelloRadio
56
58
 
57
59
  radio {
58
60
  text 'Male'
59
- selection bind(person, :male)
61
+ selection <=> [@person, :male]
60
62
  }
61
63
 
62
64
  radio {
63
65
  text 'Female'
64
- selection bind(person, :female)
66
+ selection <=> [@person, :female]
65
67
  }
66
68
  }
67
69
 
@@ -75,22 +77,22 @@ class HelloRadio
75
77
 
76
78
  radio {
77
79
  text 'Child'
78
- selection bind(person, :child)
80
+ selection <=> [@person, :child]
79
81
  }
80
82
 
81
83
  radio {
82
84
  text 'Teen'
83
- selection bind(person, :teen)
85
+ selection <=> [@person, :teen]
84
86
  }
85
87
 
86
88
  radio {
87
89
  text 'Adult'
88
- selection bind(person, :adult)
90
+ selection <=> [@person, :adult]
89
91
  }
90
92
 
91
93
  radio {
92
94
  text 'Senior'
93
- selection bind(person, :senior)
95
+ selection <=> [@person, :senior]
94
96
  }
95
97
  }
96
98
 
@@ -98,11 +100,11 @@ class HelloRadio
98
100
  text 'Reset'
99
101
 
100
102
  on_widget_selected do
101
- person.reset
103
+ @person.reset!
102
104
  end
103
105
  }
104
- }.open
105
- end
106
+ }
107
+ }
106
108
  end
107
109
 
108
- HelloRadio.new.launch
110
+ HelloRadio.launch
@@ -19,12 +19,15 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
+ # This sample demonstrates the use of a `radio_group` in Glimmer, which provides terser syntax
23
+ # than HelloRadio for representing multiple radio buttons by relying on data-binding to
24
+ # automatically spawn the `radio` widgets based on available options on the model.
22
25
  class HelloRadioGroup
23
26
  class Person
24
27
  attr_accessor :gender, :age_group
25
28
 
26
29
  def initialize
27
- reset
30
+ reset!
28
31
  end
29
32
 
30
33
  def gender_options
@@ -35,17 +38,19 @@ class HelloRadioGroup
35
38
  ['Child', 'Teen', 'Adult', 'Senior']
36
39
  end
37
40
 
38
- def reset
41
+ def reset!
39
42
  self.gender = nil
40
43
  self.age_group = 'Adult'
41
44
  end
42
45
  end
43
46
 
44
- include Glimmer
47
+ include Glimmer::UI::CustomShell
45
48
 
46
- def launch
47
- person = Person.new
48
-
49
+ before_body {
50
+ @person = Person.new
51
+ }
52
+
53
+ body {
49
54
  shell {
50
55
  text 'Hello, Radio Group!'
51
56
  row_layout :vertical
@@ -57,7 +62,7 @@ class HelloRadioGroup
57
62
 
58
63
  radio_group {
59
64
  row_layout :horizontal
60
- selection bind(person, :gender)
65
+ selection <=> [@person, :gender]
61
66
  }
62
67
 
63
68
  label {
@@ -67,18 +72,18 @@ class HelloRadioGroup
67
72
 
68
73
  radio_group {
69
74
  row_layout :horizontal
70
- selection bind(person, :age_group)
75
+ selection <=> [@person, :age_group]
71
76
  }
72
77
 
73
78
  button {
74
79
  text 'Reset'
75
80
 
76
81
  on_widget_selected do
77
- person.reset
82
+ @person.reset!
78
83
  end
79
84
  }
80
- }.open
81
- end
85
+ }
86
+ }
82
87
  end
83
88
 
84
- HelloRadioGroup.new.launch
89
+ HelloRadioGroup.launch
@@ -179,25 +179,33 @@ class HelloTable
179
179
  end
180
180
  end
181
181
 
182
- include Glimmer
183
-
184
- def launch
182
+ include Glimmer::UI::CustomShell
183
+
184
+ before_body {
185
+ Display.app_name = 'Hello, Table!'
186
+ }
187
+
188
+ body {
185
189
  shell {
186
190
  grid_layout
187
191
 
188
192
  text 'Hello, Table!'
193
+ background_image File.expand_path('hello_table/baseball_park.png', __dir__)
194
+ image File.expand_path('hello_table/baseball_park.png', __dir__)
189
195
 
190
196
  label {
191
197
  layout_data :center, :center, true, false
192
198
 
193
- text 'Baseball Playoff Schedule'
194
- font height: 30, style: :bold
199
+ text 'BASEBALL PLAYOFF SCHEDULE'
200
+ background :transparent if OS.windows?
201
+ foreground rgb(94, 107, 103)
202
+ font name: 'Optima', height: 38, style: :bold
195
203
  }
196
204
 
197
205
  combo(:read_only) {
198
206
  layout_data :center, :center, true, false
199
- selection bind(BaseballGame, :playoff_type)
200
- font height: 16
207
+ selection <=> [BaseballGame, :playoff_type]
208
+ font height: 14
201
209
  }
202
210
 
203
211
  table(:editable) { |table_proxy|
@@ -237,10 +245,10 @@ class HelloTable
237
245
  }
238
246
 
239
247
  # Data-bind table items (rows) to a model collection property, specifying column properties ordering per nested model
240
- items bind(BaseballGame, :schedule), column_properties(:game_date, :game_time, :ballpark, :home_team, :away_team, :promotion)
248
+ items <=> [BaseballGame, :schedule, column_attributes: [:game_date, :game_time, :ballpark, :home_team, :away_team, :promotion]]
241
249
 
242
250
  # Data-bind table selection
243
- selection bind(BaseballGame, :selected_game)
251
+ selection <=> [BaseballGame, :selected_game]
244
252
 
245
253
  # Default initial sort property
246
254
  sort_property :date
@@ -248,29 +256,29 @@ class HelloTable
248
256
  # Sort by these additional properties after handling sort by the column the user clicked
249
257
  additional_sort_properties :date, :time, :home_team, :away_team, :ballpark, :promotion
250
258
 
251
- # menu {
252
- # menu_item {
253
- # text 'Book'
254
- #
255
- # on_widget_selected {
256
- # book_selected_game
257
- # }
258
- # }
259
- # }
259
+ menu {
260
+ menu_item {
261
+ text 'Book'
262
+
263
+ on_widget_selected {
264
+ book_selected_game
265
+ }
266
+ }
267
+ }
260
268
  }
261
269
 
262
270
  button {
263
271
  text 'Book Selected Game'
264
272
  layout_data :center, :center, true, false
265
- font height: 16
266
- enabled bind(BaseballGame, :selected_game)
273
+ font height: 14
274
+ enabled <= [BaseballGame, :selected_game]
267
275
 
268
276
  on_widget_selected {
269
277
  book_selected_game
270
278
  }
271
279
  }
272
- }.open
273
- end
280
+ }
281
+ }
274
282
 
275
283
  def book_selected_game
276
284
  message_box {
@@ -280,4 +288,4 @@ class HelloTable
280
288
  end
281
289
  end
282
290
 
283
- HelloTable.new.launch
291
+ HelloTable.launch
@@ -11,11 +11,12 @@ module Glimmer
11
11
  include DataBinding::Observable
12
12
  include DataBinding::Observer
13
13
 
14
- def initialize(parent, model_binding, column_properties)
14
+ def initialize(parent, model_binding, column_properties = nil)
15
15
  @last_populated_model_collection = nil
16
16
  @table = parent
17
17
  @model_binding = model_binding
18
- @column_properties = column_properties
18
+ @column_properties = model_binding.binding_options[:column_attributes] || model_binding.binding_options[:column_properties] || column_properties # TODO
19
+ @table.editable = false if model_binding.binding_options[:read_only]
19
20
  @table.data = @model_binding
20
21
  ##@table.on_widget_disposed do |dispose_event| # doesn't seem needed within Opal
21
22
  ## unregister_all_observables
@@ -1,36 +1,35 @@
1
+ # Copyright (c) 2020-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
+
1
22
  require 'glimmer/dsl/static_expression'
23
+ require 'glimmer/dsl/bind_expression'
2
24
  require 'glimmer/data_binding/model_binding'
3
25
 
4
26
  module Glimmer
5
27
  module DSL
6
28
  module Opal
7
29
  # Responsible for setting up the return value of the bind keyword (command symbol)
8
- # as a ModelBinding. It is then used by another command handler like
9
- # DataBindingCommandHandler for text and selection properties on Text and Spinner
10
- # or TableItemsDataBindingCommandHandler for items in a Table
30
+ # as a ModelBinding. It is then used by other data-binding expressions
11
31
  class BindExpression < StaticExpression
12
- def can_interpret?(parent, keyword, *args, &block)
13
- (
14
- keyword == 'bind' and
15
- (
16
- (
17
- (args.size == 2) and
18
- textual?(args[1])
19
- ) ||
20
- (
21
- (args.size == 3) and
22
- textual?(args[1]) and
23
- (args[2].is_a?(Hash))
24
- )
25
- )
26
- )
27
- end
28
-
29
- def interpret(parent, keyword, *args, &block)
30
- binding_options = args[2] || {}
31
- binding_options[:on_read] = binding_options.delete(:on_read) || binding_options.delete('on_read') || block
32
- DataBinding::ModelBinding.new(args[0], args[1].to_s, binding_options)
33
- end
32
+ include Glimmer::DSL::BindExpression
34
33
  end
35
34
  end
36
35
  end
@@ -80,15 +80,15 @@ module Glimmer
80
80
  end
81
81
  end
82
82
 
83
- def add_content(parent, &content)
84
- content.call(parent) if parent.is_a?(Glimmer::SWT::ShellProxy) || parent.is_a?(Glimmer::UI::CustomShell)
85
- end
86
-
83
+ # TODO delete if no longer needed
84
+ # def add_content(parent, &content)
85
+ # content.call(parent) if parent.is_a?(Glimmer::SWT::ShellProxy) || parent.is_a?(Glimmer::UI::CustomShell)
86
+ # end
87
87
 
88
- def add_content(parent, &block)
88
+ def add_content(parent, keyword, *args, &block)
89
89
  return unless parent.is_a?(Glimmer::UI::CustomWidget)
90
- # TODO consider avoiding source_location
91
- if block.source_location == parent.content&.__getobj__.source_location
90
+ # TODO consider avoiding source_location since it does not work in Opal
91
+ if block.source_location && (block.source_location == parent.content&.__getobj__&.source_location)
92
92
  parent.content.call(parent) unless parent.content.called?
93
93
  else
94
94
  super
@@ -29,6 +29,7 @@ require 'glimmer/dsl/opal/block_property_expression'
29
29
  require 'glimmer/dsl/opal/menu_expression'
30
30
  require 'glimmer/dsl/opal/dialog_expression'
31
31
  require 'glimmer/dsl/opal/shape_expression'
32
+ require 'glimmer/dsl/opal/shine_data_binding_expression'
32
33
 
33
34
  module Glimmer
34
35
  module DSL
@@ -48,6 +49,7 @@ module Glimmer
48
49
  layout
49
50
  block_property
50
51
  property
52
+ shine_data_binding
51
53
  shape
52
54
  widget
53
55
  ]
@@ -47,7 +47,7 @@ module Glimmer
47
47
  Glimmer::SWT::MenuProxy.new(parent, args)
48
48
  end
49
49
 
50
- def add_content(parent, &block)
50
+ def add_content(parent, keyword, *args, &block)
51
51
  super(parent, &block)
52
52
  parent.post_add_content
53
53
  end
@@ -6,8 +6,9 @@ module Glimmer
6
6
  class PropertyExpression < StaticExpression
7
7
  include TopLevelExpression
8
8
 
9
- def can_interpret?(parent, keyword, *args, &block)
9
+ def can_interpret?(parent, keyword, *args, &block)
10
10
  parent and
11
+ (!args.empty?) and
11
12
  parent.respond_to?(:set_attribute) and
12
13
  parent.respond_to?(keyword, *args) and
13
14
  keyword and
@@ -17,7 +17,7 @@ module Glimmer
17
17
  # TODO
18
18
  end
19
19
 
20
- def add_content(parent, &block)
20
+ def add_content(parent, keyword, *args, &block)
21
21
  # TODO
22
22
  end
23
23
  end
@@ -27,7 +27,7 @@ module Glimmer
27
27
  end
28
28
  end
29
29
 
30
- def add_content(parent, &block)
30
+ def add_content(parent, keyword, *args, &block)
31
31
  super(parent, &block)
32
32
  parent.post_add_content
33
33
  end
@@ -0,0 +1,49 @@
1
+ # Copyright (c) 2020-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/dsl/expression'
23
+ require 'glimmer/data_binding/model_binding'
24
+ require 'glimmer/swt/table_proxy'
25
+ require 'glimmer/data_binding/shine'
26
+
27
+ module Glimmer
28
+ module DSL
29
+ module Opal
30
+ class ShineDataBindingExpression < Expression
31
+ def can_interpret?(parent, keyword, *args, &block)
32
+ args.size == 0 and
33
+ block.nil? and
34
+ (
35
+ (parent.respond_to?(:set_attribute) and parent.respond_to?(keyword)) or
36
+ (parent.is_a?(Glimmer::SWT::TableProxy)) # TODO support tree element
37
+ )
38
+ # TODO support canvas elements
39
+ # and
40
+ # !(parent.respond_to?(:swt_widget) && parent.swt_widget.class == org.eclipse.swt.widgets.Canvas && keyword == 'image')
41
+ end
42
+
43
+ def interpret(parent, keyword, *args, &block)
44
+ Glimmer::DataBinding::Shine.new(parent, keyword)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end