glimmer-dsl-opal 0.5.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +53 -0
  3. data/README.md +438 -17
  4. data/VERSION +1 -1
  5. data/app/assets/images/glimmer/images/calendar.gif +0 -0
  6. data/app/assets/images/glimmer/images/ui-icons_222222_256x240.png +0 -0
  7. data/app/assets/images/glimmer/images/ui-icons_444444_256x240.png +0 -0
  8. data/app/assets/images/glimmer/images/ui-icons_555555_256x240.png +0 -0
  9. data/app/assets/images/glimmer/images/ui-icons_777620_256x240.png +0 -0
  10. data/app/assets/images/glimmer/images/ui-icons_777777_256x240.png +0 -0
  11. data/app/assets/images/glimmer/images/ui-icons_cc0000_256x240.png +0 -0
  12. data/app/assets/images/glimmer/images/ui-icons_ffffff_256x240.png +0 -0
  13. data/app/assets/stylesheets/glimmer/glimmer.css +15 -0
  14. data/app/assets/stylesheets/glimmer/jquery-ui.css +1312 -0
  15. data/app/assets/stylesheets/glimmer/jquery-ui.structure.css +886 -0
  16. data/app/assets/stylesheets/glimmer/jquery-ui.theme.css +443 -0
  17. data/app/assets/stylesheets/glimmer/jquery.ui.timepicker.css +57 -0
  18. data/lib/display.rb +31 -0
  19. data/lib/file.rb +29 -0
  20. data/lib/glimmer-dsl-opal.rb +40 -8
  21. data/lib/glimmer-dsl-opal/ext/date.rb +49 -3
  22. data/lib/glimmer-dsl-opal/ext/struct.rb +37 -0
  23. data/lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb +23 -0
  24. data/lib/glimmer-dsl-opal/samples/hello/hello_date_time.rb +63 -0
  25. data/lib/glimmer-dsl-opal/samples/hello/hello_table.rb +283 -0
  26. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/GPL-LICENSE.txt +278 -0
  27. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/MIT-LICENSE.txt +20 -0
  28. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/jquery.ui.timepicker.css +57 -0
  29. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/jquery.ui.timepicker.js +1496 -0
  30. data/lib/glimmer-dsl-opal/vendor/jquery-ui/AUTHORS.txt +333 -0
  31. data/lib/glimmer-dsl-opal/vendor/jquery-ui/LICENSE.txt +43 -0
  32. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_444444_256x240.png +0 -0
  33. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_555555_256x240.png +0 -0
  34. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_777620_256x240.png +0 -0
  35. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_777777_256x240.png +0 -0
  36. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_cc0000_256x240.png +0 -0
  37. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_ffffff_256x240.png +0 -0
  38. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.min.css +7 -0
  39. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.min.js +13 -0
  40. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.structure.min.css +5 -0
  41. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.theme.min.css +5 -0
  42. data/lib/glimmer-dsl-opal/vendor/jquery-ui/package.json +74 -0
  43. data/lib/glimmer-dsl-swt.rb +20 -35
  44. data/lib/glimmer/data_binding/table_items_binding.rb +32 -19
  45. data/lib/glimmer/dsl/opal/block_property_expression.rb +41 -0
  46. data/lib/glimmer/dsl/opal/custom_widget_expression.rb +1 -1
  47. data/lib/glimmer/dsl/opal/dsl.rb +2 -0
  48. data/lib/glimmer/dsl/opal/shell_expression.rb +7 -2
  49. data/lib/glimmer/dsl/opal/widget_expression.rb +10 -1
  50. data/lib/glimmer/engine.rb +9 -0
  51. data/lib/glimmer/swt.rb +3 -3
  52. data/lib/glimmer/swt/button_proxy.rb +5 -5
  53. data/lib/glimmer/swt/checkbox_proxy.rb +1 -0
  54. data/lib/glimmer/swt/color_proxy.rb +45 -45
  55. data/lib/glimmer/swt/combo_proxy.rb +42 -3
  56. data/lib/glimmer/swt/composite_proxy.rb +7 -3
  57. data/lib/glimmer/swt/control_editor.rb +54 -0
  58. data/lib/glimmer/swt/date_time_proxy.rb +209 -0
  59. data/lib/glimmer/swt/display_proxy.rb +6 -2
  60. data/lib/glimmer/swt/fill_layout_proxy.rb +1 -1
  61. data/lib/glimmer/swt/label_proxy.rb +2 -2
  62. data/lib/glimmer/swt/layout_data_proxy.rb +13 -10
  63. data/lib/glimmer/swt/layout_proxy.rb +5 -5
  64. data/lib/glimmer/swt/list_proxy.rb +2 -2
  65. data/lib/glimmer/swt/make_shift_shell_proxy.rb +4 -4
  66. data/lib/glimmer/swt/message_box_proxy.rb +10 -8
  67. data/lib/glimmer/swt/property_owner.rb +2 -2
  68. data/lib/glimmer/swt/radio_proxy.rb +1 -0
  69. data/lib/glimmer/swt/shell_proxy.rb +8 -0
  70. data/lib/glimmer/swt/tab_folder_proxy.rb +5 -5
  71. data/lib/glimmer/swt/tab_item_proxy.rb +7 -7
  72. data/lib/glimmer/swt/table_column_proxy.rb +71 -12
  73. data/lib/glimmer/swt/table_editor.rb +65 -0
  74. data/lib/glimmer/swt/table_item_proxy.rb +50 -7
  75. data/lib/glimmer/swt/table_proxy.rb +595 -22
  76. data/lib/glimmer/swt/text_proxy.rb +51 -3
  77. data/lib/glimmer/swt/widget_proxy.rb +141 -27
  78. data/lib/glimmer/ui/custom_widget.rb +8 -8
  79. data/lib/net/http.rb +1 -5
  80. data/lib/os.rb +36 -0
  81. data/lib/uri.rb +3 -3
  82. metadata +49 -9
  83. data/lib/glimmer/data_binding/ext/observable_model.rb +0 -40
@@ -0,0 +1,31 @@
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
+ class Display
23
+ class << self
24
+ def setAppName(app_name)
25
+ # No Op in Opal
26
+ end
27
+ def setAppVersion(version)
28
+ # No Op in Opal
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
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
+ class File
23
+ class << self
24
+ def read(*args, &block)
25
+ # TODO implement via asset downloads in the future
26
+ # No Op in Opal
27
+ end
28
+ end
29
+ end
@@ -1,14 +1,37 @@
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
+
1
22
  require 'opal'
2
23
 
3
- if RUBY_PLATFORM == 'opal'
4
- GLIMMER_DSL_OPAL_ROOT = File.expand_path('../..', __FILE__)
5
- GLIMMER_DSL_OPAL_LIB = File.join(GLIMMER_DSL_OPAL_ROOT, 'lib')
24
+ GLIMMER_DSL_OPAL_ROOT = File.expand_path('../..', __FILE__)
25
+ GLIMMER_DSL_OPAL_LIB = File.join(GLIMMER_DSL_OPAL_ROOT, 'lib')
26
+
27
+ $LOAD_PATH.unshift(GLIMMER_DSL_OPAL_LIB)
28
+
29
+ if RUBY_ENGINE == 'opal'
6
30
  # GLIMMER_DSL_OPAL_MISSING = File.join(GLIMMER_DSL_OPAL_ROOT, 'lib', 'glimmer-dsl-opal', 'missing')
7
31
 
8
- $LOAD_PATH.unshift(GLIMMER_DSL_OPAL_LIB)
9
32
  # $LOAD_PATH.unshift(GLIMMER_DSL_OPAL_MISSING) # missing Ruby classes/methods
10
33
  # TODO look into making append_path work (causing some trouble right now)
11
- # Opal.append_path pd File.expand_path('../glimmer-dsl-opal/missing', __FILE__)
34
+ # Opal.append_path File.expand_path('../glimmer-dsl-opal/missing', __FILE__)
12
35
  # Opal.append_path GLIMMER_DSL_OPAL_MISSING
13
36
 
14
37
  require 'opal-parser'
@@ -16,9 +39,16 @@ if RUBY_PLATFORM == 'opal'
16
39
  require 'opal-async'
17
40
  require 'async/ext'
18
41
  require 'glimmer-dsl-opal/vendor/jquery'
42
+ require 'glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.min'
43
+ require 'glimmer-dsl-opal/vendor/jquery-ui-timepicker/jquery.ui.timepicker'
44
+ # require 'glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.min.css'
45
+ # require 'glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.structure.min.css'
46
+ # require 'glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.theme.min.css'
19
47
  require 'opal-jquery'
48
+
49
+ require 'facets/hash/symbolize_keys'
50
+ require 'glimmer-dsl-opal/ext/struct'
20
51
  require 'glimmer'
21
- require 'facets/hash/symbolize_keys'
22
52
  require 'glimmer-dsl-opal/ext/exception'
23
53
  require 'glimmer-dsl-opal/ext/date'
24
54
  require 'uri'
@@ -31,14 +61,14 @@ if RUBY_PLATFORM == 'opal'
31
61
  # Async::Timeout.new 10000 do
32
62
  # __original_add(*args)
33
63
  # end
34
- # end
64
+ # end
35
65
 
36
66
  require 'glimmer/dsl/opal/dsl'
37
- require 'glimmer/data_binding/ext/observable_model'
38
67
 
39
68
  require 'glimmer-dsl-xml'
40
69
  require 'glimmer-dsl-css'
41
70
  Element.alias_native :replace_with, :replaceWith
71
+ Element.alias_native :select
42
72
 
43
73
  # Glimmer::Config.loop_max_count = 20
44
74
 
@@ -49,4 +79,6 @@ if RUBY_PLATFORM == 'opal'
49
79
  result ||= method == 'handle'
50
80
  end
51
81
 
82
+ else
83
+ require_relative 'glimmer/engine'
52
84
  end
@@ -4,10 +4,56 @@ require 'time'
4
4
  class DateTime < Date
5
5
  def initialize(*args, &block)
6
6
  @time = Time.new(*args, &block)
7
- @time.methods.each do |method|
7
+ methods_to_exclude = [:to_date, :to_time, :==, :eql?, :class]
8
+ methods_to_define = @time.methods - methods_to_exclude
9
+ methods_to_define.each do |method|
8
10
  singleton_class.define_method(method) do |*args, &block|
9
11
  @time.send(method, *args, &block)
10
12
  end
11
- end
12
- end
13
+ end
14
+ end
15
+
16
+ def to_date
17
+ @time.to_date
18
+ end
19
+
20
+ def to_time
21
+ @time
22
+ end
23
+
24
+ def ==(other)
25
+ return false if other.class != self.class
26
+ year == other.year and
27
+ month == other.month and
28
+ day == other.day and
29
+ hour == other.hour and
30
+ min == other.min and
31
+ sec == other.sec
32
+ end
33
+ alias eql? ==
34
+ end
35
+
36
+ class Date
37
+ def to_datetime
38
+ # TODO support timezone
39
+ DateTime.new(year, month, day, hour, min, sec)
40
+ end
41
+ end
42
+
43
+ class Time
44
+ class << self
45
+ alias new_original new
46
+ def new(*args)
47
+ if args.size >= 7
48
+ Glimmer::Config.logger.debug "Dropped timezone #{args[6]} from Time.new(#{args.map(&:to_s)}) constructor arguments since Opal does not support it!"
49
+ args = args[0...6]
50
+ end
51
+ new_original(*args)
52
+ end
53
+ end
54
+
55
+ def to_datetime
56
+ # TODO support timezone
57
+ DateTime.new(year, month, day, hour, min, sec)
58
+ end
13
59
  end
@@ -0,0 +1,37 @@
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
+ class Struct
23
+ class << self
24
+ alias new_original new
25
+ def new(*args, &block)
26
+ new_original(*args, &block).tap do |struct_class|
27
+ if args.size >= 2 && args.last.is_a?(Hash) && args.last[:keyword_init]
28
+ struct_class.define_method(:initialize) do |struct_class_keyword_args|
29
+ struct_class_keyword_args.each do |attribute, value|
30
+ send("#{attribute}=", value)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,24 @@
1
+ # Copyright (c) 2007-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
+
1
22
  require_relative "tic_tac_toe/board"
2
23
 
3
24
  class TicTacToe
@@ -7,6 +28,7 @@ class TicTacToe
7
28
  @tic_tac_toe_board = Board.new
8
29
  @shell = shell {
9
30
  text "Tic-Tac-Toe"
31
+ minimum_size 150, 178
10
32
  composite {
11
33
  grid_layout 3, true
12
34
  (1..3).each { |row|
@@ -15,6 +37,7 @@ class TicTacToe
15
37
  layout_data :fill, :fill, true, true
16
38
  text bind(@tic_tac_toe_board[row, column], :sign)
17
39
  enabled bind(@tic_tac_toe_board[row, column], :empty)
40
+ font style: :bold, height: 20
18
41
  on_widget_selected {
19
42
  @tic_tac_toe_board.mark(row, column)
20
43
  }
@@ -0,0 +1,63 @@
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
+ class HelloDateTime
23
+ class Person
24
+ attr_accessor :date_of_birth
25
+ end
26
+
27
+ include Glimmer
28
+
29
+ def launch
30
+ person = Person.new
31
+ person.date_of_birth = DateTime.new(2013, 7, 12, 18, 37, 23)
32
+
33
+ shell {
34
+ row_layout :vertical
35
+
36
+ text 'Hello, Date Time!'
37
+ minimum_size 180, 180
38
+
39
+ label {
40
+ text 'Date of Birth'
41
+ font height: 16, style: :bold
42
+ }
43
+
44
+ date { # alias for date_time(:date)
45
+ date_time bind(person, :date_of_birth)
46
+ }
47
+
48
+ date_drop_down { # alias for date_time(:date, :drop_down)
49
+ date_time bind(person, :date_of_birth)
50
+ }
51
+
52
+ time { # alias for date_time(:time)
53
+ date_time bind(person, :date_of_birth)
54
+ }
55
+
56
+ calendar { # alias for date_time(:calendar)
57
+ date_time bind(person, :date_of_birth)
58
+ }
59
+ }.open
60
+ end
61
+ end
62
+
63
+ HelloDateTime.new.launch
@@ -0,0 +1,283 @@
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
+ class HelloTable
23
+ class BaseballGame
24
+ class << self
25
+ attr_accessor :selected_game
26
+
27
+ def all_playoff_games
28
+ @all_playoff_games ||= {
29
+ 'NLDS' => [
30
+ new(Time.new(2037, 10, 6, 12, 0), 'Chicago Cubs', 'Milwaukee Brewers', 'Free Bobblehead'),
31
+ new(Time.new(2037, 10, 7, 12, 0), 'Chicago Cubs', 'Milwaukee Brewers'),
32
+ new(Time.new(2037, 10, 8, 12, 0), 'Milwaukee Brewers', 'Chicago Cubs'),
33
+ new(Time.new(2037, 10, 9, 12, 0), 'Milwaukee Brewers', 'Chicago Cubs'),
34
+ new(Time.new(2037, 10, 10, 12, 0), 'Milwaukee Brewers', 'Chicago Cubs', 'Free Umbrella'),
35
+ new(Time.new(2037, 10, 6, 18, 0), 'Cincinnati Reds', 'St Louis Cardinals', 'Free Bobblehead'),
36
+ new(Time.new(2037, 10, 7, 18, 0), 'Cincinnati Reds', 'St Louis Cardinals'),
37
+ new(Time.new(2037, 10, 8, 18, 0), 'St Louis Cardinals', 'Cincinnati Reds'),
38
+ new(Time.new(2037, 10, 9, 18, 0), 'St Louis Cardinals', 'Cincinnati Reds'),
39
+ new(Time.new(2037, 10, 10, 18, 0), 'St Louis Cardinals', 'Cincinnati Reds', 'Free Umbrella'),
40
+ ],
41
+ 'ALDS' => [
42
+ new(Time.new(2037, 10, 6, 12, 0), 'New York Yankees', 'Boston Red Sox', 'Free Bobblehead'),
43
+ new(Time.new(2037, 10, 7, 12, 0), 'New York Yankees', 'Boston Red Sox'),
44
+ new(Time.new(2037, 10, 8, 12, 0), 'Boston Red Sox', 'New York Yankees'),
45
+ new(Time.new(2037, 10, 9, 12, 0), 'Boston Red Sox', 'New York Yankees'),
46
+ new(Time.new(2037, 10, 10, 12, 0), 'Boston Red Sox', 'New York Yankees', 'Free Umbrella'),
47
+ new(Time.new(2037, 10, 6, 18, 0), 'Houston Astros', 'Cleveland Indians', 'Free Bobblehead'),
48
+ new(Time.new(2037, 10, 7, 18, 0), 'Houston Astros', 'Cleveland Indians'),
49
+ new(Time.new(2037, 10, 8, 18, 0), 'Cleveland Indians', 'Houston Astros'),
50
+ new(Time.new(2037, 10, 9, 18, 0), 'Cleveland Indians', 'Houston Astros'),
51
+ new(Time.new(2037, 10, 10, 18, 0), 'Cleveland Indians', 'Houston Astros', 'Free Umbrella'),
52
+ ],
53
+ 'NLCS' => [
54
+ new(Time.new(2037, 10, 12, 12, 0), 'Chicago Cubs', 'Cincinnati Reds', 'Free Towel'),
55
+ new(Time.new(2037, 10, 13, 12, 0), 'Chicago Cubs', 'Cincinnati Reds'),
56
+ new(Time.new(2037, 10, 14, 12, 0), 'Cincinnati Reds', 'Chicago Cubs'),
57
+ new(Time.new(2037, 10, 15, 18, 0), 'Cincinnati Reds', 'Chicago Cubs'),
58
+ new(Time.new(2037, 10, 16, 18, 0), 'Cincinnati Reds', 'Chicago Cubs'),
59
+ new(Time.new(2037, 10, 17, 18, 0), 'Chicago Cubs', 'Cincinnati Reds'),
60
+ new(Time.new(2037, 10, 18, 12, 0), 'Chicago Cubs', 'Cincinnati Reds', 'Free Poncho'),
61
+ ],
62
+ 'ALCS' => [
63
+ new(Time.new(2037, 10, 12, 12, 0), 'Houston Astros', 'Boston Red Sox', 'Free Towel'),
64
+ new(Time.new(2037, 10, 13, 12, 0), 'Houston Astros', 'Boston Red Sox'),
65
+ new(Time.new(2037, 10, 14, 12, 0), 'Boston Red Sox', 'Houston Astros'),
66
+ new(Time.new(2037, 10, 15, 18, 0), 'Boston Red Sox', 'Houston Astros'),
67
+ new(Time.new(2037, 10, 16, 18, 0), 'Boston Red Sox', 'Houston Astros'),
68
+ new(Time.new(2037, 10, 17, 18, 0), 'Houston Astros', 'Boston Red Sox'),
69
+ new(Time.new(2037, 10, 18, 12, 0), 'Houston Astros', 'Boston Red Sox', 'Free Poncho'),
70
+ ],
71
+ 'World Series' => [
72
+ new(Time.new(2037, 10, 20, 18, 0), 'Chicago Cubs', 'Boston Red Sox', 'Free Baseball Cap'),
73
+ new(Time.new(2037, 10, 21, 18, 0), 'Chicago Cubs', 'Boston Red Sox'),
74
+ new(Time.new(2037, 10, 22, 18, 0), 'Boston Red Sox', 'Chicago Cubs'),
75
+ new(Time.new(2037, 10, 23, 18, 0), 'Boston Red Sox', 'Chicago Cubs'),
76
+ new(Time.new(2037, 10, 24, 18, 0), 'Boston Red Sox', 'Chicago Cubs'),
77
+ new(Time.new(2037, 10, 25, 18, 0), 'Chicago Cubs', 'Boston Red Sox'),
78
+ new(Time.new(2037, 10, 26, 18, 0), 'Chicago Cubs', 'Boston Red Sox', 'Free World Series Polo'),
79
+ ]
80
+ }
81
+ end
82
+
83
+ def playoff_type
84
+ @playoff_type ||= 'World Series'
85
+ end
86
+
87
+ def playoff_type=(new_playoff_type)
88
+ @playoff_type = new_playoff_type
89
+ self.schedule=(all_playoff_games[@playoff_type])
90
+ end
91
+
92
+ def playoff_type_options
93
+ all_playoff_games.keys
94
+ end
95
+
96
+ def schedule
97
+ @schedule ||= all_playoff_games[playoff_type]
98
+ end
99
+
100
+ def schedule=(new_schedule)
101
+ @schedule = new_schedule
102
+ end
103
+ end
104
+
105
+ include Glimmer
106
+ include Glimmer::DataBinding::ObservableModel
107
+
108
+ TEAM_BALLPARKS = {
109
+ 'Boston Red Sox' => 'Fenway Park',
110
+ 'Chicago Cubs' => 'Wrigley Field',
111
+ 'Cincinnati Reds' => 'Great American Ball Park',
112
+ 'Cleveland Indians' => 'Progressive Field',
113
+ 'Houston Astros' => 'Minute Maid Park',
114
+ 'Milwaukee Brewers' => 'Miller Park',
115
+ 'New York Yankees' => 'Yankee Stadium',
116
+ 'St Louis Cardinals' => 'Busch Stadium',
117
+ }
118
+
119
+ attr_accessor :date_time, :home_team, :away_team, :ballpark, :promotion
120
+
121
+ def initialize(date_time, home_team, away_team, promotion = 'N/A')
122
+ self.date_time = date_time
123
+ self.home_team = home_team
124
+ self.away_team = away_team
125
+ self.promotion = promotion
126
+ observe(self, :date_time) do |new_value|
127
+ notify_observers(:game_date)
128
+ notify_observers(:game_time)
129
+ end
130
+ end
131
+
132
+ def home_team=(home_team_value)
133
+ if home_team_value != away_team
134
+ @home_team = home_team_value
135
+ self.ballpark = TEAM_BALLPARKS[@home_team]
136
+ end
137
+ end
138
+
139
+ def away_team=(away_team_value)
140
+ if away_team_value != home_team
141
+ @away_team = away_team_value
142
+ end
143
+ end
144
+
145
+ def date
146
+ Date.new(date_time.year, date_time.month, date_time.day)
147
+ end
148
+
149
+ def time
150
+ Time.new(0, 1, 1, date_time.hour, date_time.min, date_time.sec, '+00:00')
151
+ end
152
+
153
+ def game_date
154
+ date_time.strftime("%m/%d/%Y")
155
+ end
156
+
157
+ def game_time
158
+ date_time.strftime("%I:%M %p")
159
+ end
160
+
161
+ def home_team_options
162
+ TEAM_BALLPARKS.keys
163
+ end
164
+
165
+ def away_team_options
166
+ TEAM_BALLPARKS.keys
167
+ end
168
+
169
+ def ballpark_options
170
+ [TEAM_BALLPARKS[@home_team], TEAM_BALLPARKS[@away_team]]
171
+ end
172
+
173
+ def to_s
174
+ "#{home_team} vs #{away_team} at #{ballpark} on #{game_date} #{game_time}"
175
+ end
176
+
177
+ def book!
178
+ "Thank you for booking #{to_s}"
179
+ end
180
+ end
181
+
182
+ include Glimmer
183
+
184
+ def launch
185
+ shell {
186
+ grid_layout
187
+
188
+ text 'Hello, Table!'
189
+
190
+ label {
191
+ layout_data :center, :center, true, false
192
+
193
+ text 'Baseball Playoff Schedule'
194
+ font height: 30, style: :bold
195
+ }
196
+
197
+ combo(:read_only) {
198
+ layout_data :center, :center, true, false
199
+ selection bind(BaseballGame, :playoff_type)
200
+ font height: 16
201
+ }
202
+
203
+ table(:editable) { |table_proxy|
204
+ layout_data :fill, :fill, true, true
205
+
206
+ table_column {
207
+ text 'Game Date'
208
+ width 150
209
+ sort_property :date # ensure sorting by real date value (not `game_date` string specified in items below)
210
+ editor :date_drop_down, property: :date_time
211
+ }
212
+ table_column {
213
+ text 'Game Time'
214
+ width 150
215
+ sort_property :time # ensure sorting by real time value (not `game_time` string specified in items below)
216
+ editor :time, property: :date_time
217
+ }
218
+ table_column {
219
+ text 'Ballpark'
220
+ width 180
221
+ editor :none
222
+ }
223
+ table_column {
224
+ text 'Home Team'
225
+ width 150
226
+ editor :combo, :read_only # read_only is simply an SWT style passed to combo widget
227
+ }
228
+ table_column {
229
+ text 'Away Team'
230
+ width 150
231
+ editor :combo, :read_only # read_only is simply an SWT style passed to combo widget
232
+ }
233
+ table_column {
234
+ text 'Promotion'
235
+ width 150
236
+ # default text editor is used here
237
+ }
238
+
239
+ # 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)
241
+
242
+ # Data-bind table selection
243
+ selection bind(BaseballGame, :selected_game)
244
+
245
+ # Default initial sort property
246
+ sort_property :date
247
+
248
+ # Sort by these additional properties after handling sort by the column the user clicked
249
+ additional_sort_properties :date, :time, :home_team, :away_team, :ballpark, :promotion
250
+
251
+ # menu {
252
+ # menu_item {
253
+ # text 'Book'
254
+ #
255
+ # on_widget_selected {
256
+ # book_selected_game
257
+ # }
258
+ # }
259
+ # }
260
+ }
261
+
262
+ button {
263
+ text 'Book Selected Game'
264
+ layout_data :center, :center, true, false
265
+ font height: 16
266
+ enabled bind(BaseballGame, :selected_game)
267
+
268
+ on_widget_selected {
269
+ book_selected_game
270
+ }
271
+ }
272
+ }.open
273
+ end
274
+
275
+ def book_selected_game
276
+ message_box {
277
+ text 'Baseball Game Booked!'
278
+ message BaseballGame.selected_game.book!
279
+ }.open
280
+ end
281
+ end
282
+
283
+ HelloTable.new.launch