glimmer-dsl-opal 0.6.1 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +54 -0
  3. data/README.md +489 -16
  4. data/VERSION +1 -1
  5. data/lib/display.rb +31 -0
  6. data/lib/file.rb +29 -0
  7. data/lib/glimmer-dsl-opal.rb +31 -3
  8. data/lib/glimmer-dsl-opal/ext/date.rb +11 -0
  9. data/lib/glimmer-dsl-opal/ext/struct.rb +37 -0
  10. data/lib/glimmer-dsl-opal/samples/hello/hello_browser.rb +1 -1
  11. data/lib/glimmer-dsl-opal/samples/hello/hello_button.rb +46 -0
  12. data/lib/glimmer-dsl-opal/samples/hello/hello_custom_shell.rb +7 -7
  13. data/lib/glimmer-dsl-opal/samples/hello/hello_table.rb +283 -0
  14. data/lib/glimmer-dsl-swt.rb +20 -35
  15. data/lib/glimmer/data_binding/table_items_binding.rb +32 -19
  16. data/lib/glimmer/dsl/opal/block_property_expression.rb +41 -0
  17. data/lib/glimmer/dsl/opal/custom_widget_expression.rb +5 -0
  18. data/lib/glimmer/dsl/opal/dsl.rb +2 -0
  19. data/lib/glimmer/dsl/opal/widget_expression.rb +6 -2
  20. data/lib/glimmer/swt/combo_proxy.rb +40 -1
  21. data/lib/glimmer/swt/composite_proxy.rb +5 -1
  22. data/lib/glimmer/swt/control_editor.rb +54 -0
  23. data/lib/glimmer/swt/date_time_proxy.rb +66 -1
  24. data/lib/glimmer/swt/display_proxy.rb +4 -0
  25. data/lib/glimmer/swt/font_proxy.rb +4 -4
  26. data/lib/glimmer/swt/grid_layout_proxy.rb +7 -8
  27. data/lib/glimmer/swt/label_proxy.rb +11 -3
  28. data/lib/glimmer/swt/layout_data_proxy.rb +9 -3
  29. data/lib/glimmer/swt/layout_proxy.rb +1 -1
  30. data/lib/glimmer/swt/message_box_proxy.rb +3 -10
  31. data/lib/glimmer/swt/property_owner.rb +2 -2
  32. data/lib/glimmer/swt/shell_proxy.rb +8 -0
  33. data/lib/glimmer/swt/table_column_proxy.rb +71 -12
  34. data/lib/glimmer/swt/table_editor.rb +65 -0
  35. data/lib/glimmer/swt/table_item_proxy.rb +44 -1
  36. data/lib/glimmer/swt/table_proxy.rb +579 -12
  37. data/lib/glimmer/swt/text_proxy.rb +49 -1
  38. data/lib/glimmer/swt/widget_proxy.rb +106 -17
  39. data/lib/glimmer/ui/custom_shell.rb +9 -7
  40. data/lib/net/http.rb +1 -5
  41. data/lib/os.rb +36 -0
  42. data/lib/uri.rb +3 -3
  43. metadata +31 -9
  44. data/lib/glimmer/data_binding/ext/observable_model.rb +0 -40
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.7.4
@@ -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,3 +1,24 @@
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
24
  GLIMMER_DSL_OPAL_ROOT = File.expand_path('../..', __FILE__)
@@ -10,13 +31,17 @@ if RUBY_ENGINE == 'opal'
10
31
 
11
32
  # $LOAD_PATH.unshift(GLIMMER_DSL_OPAL_MISSING) # missing Ruby classes/methods
12
33
  # TODO look into making append_path work (causing some trouble right now)
13
- # Opal.append_path pd File.expand_path('../glimmer-dsl-opal/missing', __FILE__)
34
+ # Opal.append_path File.expand_path('../glimmer-dsl-opal/missing', __FILE__)
14
35
  # Opal.append_path GLIMMER_DSL_OPAL_MISSING
15
36
 
16
37
  require 'opal-parser'
17
38
  require 'native' # move this to opal-async
18
39
  require 'opal-async'
19
40
  require 'async/ext'
41
+ require 'to_collection'
42
+ require 'os'
43
+ require 'file'
44
+ require 'display'
20
45
  require 'glimmer-dsl-opal/vendor/jquery'
21
46
  require 'glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.min'
22
47
  require 'glimmer-dsl-opal/vendor/jquery-ui-timepicker/jquery.ui.timepicker'
@@ -24,8 +49,10 @@ if RUBY_ENGINE == 'opal'
24
49
  # require 'glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.structure.min.css'
25
50
  # require 'glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.theme.min.css'
26
51
  require 'opal-jquery'
27
- require 'glimmer'
52
+
28
53
  require 'facets/hash/symbolize_keys'
54
+ require 'glimmer-dsl-opal/ext/struct'
55
+ require 'glimmer'
29
56
  require 'glimmer-dsl-opal/ext/exception'
30
57
  require 'glimmer-dsl-opal/ext/date'
31
58
  require 'uri'
@@ -41,11 +68,11 @@ if RUBY_ENGINE == 'opal'
41
68
  # end
42
69
 
43
70
  require 'glimmer/dsl/opal/dsl'
44
- require 'glimmer/data_binding/ext/observable_model'
45
71
 
46
72
  require 'glimmer-dsl-xml'
47
73
  require 'glimmer-dsl-css'
48
74
  Element.alias_native :replace_with, :replaceWith
75
+ Element.alias_native :select
49
76
 
50
77
  # Glimmer::Config.loop_max_count = 20
51
78
 
@@ -55,6 +82,7 @@ if RUBY_ENGINE == 'opal'
55
82
  result ||= method == '<<'
56
83
  result ||= method == 'handle'
57
84
  end
85
+
58
86
  else
59
87
  require_relative 'glimmer/engine'
60
88
  end
@@ -41,6 +41,17 @@ class Date
41
41
  end
42
42
 
43
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
+
44
55
  def to_datetime
45
56
  # TODO support timezone
46
57
  DateTime.new(year, month, day, hour, min, sec)
@@ -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
@@ -3,6 +3,6 @@ include Glimmer
3
3
  shell {
4
4
  minimum_size 1024, 860
5
5
  browser {
6
- url 'http://brightonresort.com/about'
6
+ url 'https://brightonresort.com/about'
7
7
  }
8
8
  }.open
@@ -0,0 +1,46 @@
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
+
22
+ class HelloButton
23
+ include Glimmer
24
+
25
+ attr_accessor :count
26
+
27
+ def initialize
28
+ @count = 0
29
+ end
30
+
31
+ def launch
32
+ shell {
33
+ text 'Hello, Button!'
34
+
35
+ button {
36
+ text bind(self, :count) {|value| "Click To Increment: #{value} "}
37
+
38
+ on_widget_selected {
39
+ self.count += 1
40
+ }
41
+ }
42
+ }.open
43
+ end
44
+ end
45
+
46
+ HelloButton.new.launch
@@ -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
@@ -26,7 +26,7 @@ require 'date'
26
26
  class EmailShell
27
27
  include Glimmer::UI::CustomShell
28
28
 
29
- # multiple options without default values
29
+ # multiple options without default values
30
30
  options :date, :subject, :from, :message
31
31
 
32
32
  # single option with default value
@@ -41,7 +41,7 @@ class EmailShell
41
41
  shell(swt_style) {
42
42
  grid_layout(2, false)
43
43
 
44
- text subject
44
+ text subject
45
45
 
46
46
  label {
47
47
  text 'Date:'
@@ -78,7 +78,7 @@ class EmailShell
78
78
  }
79
79
 
80
80
  background :white
81
- text message
81
+ text message
82
82
  }
83
83
  }
84
84
  }
@@ -149,7 +149,7 @@ class HelloCustomShell
149
149
  }
150
150
  }
151
151
  }.open
152
- end
152
+ end
153
153
  end
154
154
 
155
155
  HelloCustomShell.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