glimmer-dsl-swt 4.17.9.0 → 4.17.10.4

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.
@@ -234,7 +234,6 @@ module Glimmer
234
234
  elsif @swt_widget.respond_to?(attribute_getter(attribute_name))
235
235
  @swt_widget.send(attribute_getter(attribute_name))
236
236
  else
237
- pd attribute_name
238
237
  send(attribute_name)
239
238
  end
240
239
  end
@@ -282,6 +281,17 @@ module Glimmer
282
281
  }
283
282
  end,
284
283
  },
284
+ Java::OrgEclipseSwtWidgets::Table => {
285
+ :selection => lambda do |observer|
286
+ on_widget_selected { |selection_event|
287
+ if has_style?(:multi)
288
+ observer.call(@swt_widget.getSelection.map(&:get_data))
289
+ else
290
+ observer.call(@swt_widget.getSelection.first&.get_data)
291
+ end
292
+ }
293
+ end,
294
+ },
285
295
  Java::OrgEclipseSwtWidgets::Text => {
286
296
  :text => lambda do |observer|
287
297
  on_modify_text { |modify_event|
@@ -347,35 +357,52 @@ module Glimmer
347
357
  }
348
358
  end,
349
359
  :caret_position => lambda do |observer|
360
+ on_caret_moved { |event|
361
+ observer.call(@swt_widget.getSelection.x) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
362
+ }
350
363
  on_swt_keyup { |event|
351
- observer.call(@swt_widget.getCaretOffset)
364
+ observer.call(@swt_widget.getSelection.x) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
352
365
  }
353
366
  on_swt_mouseup { |event|
354
- observer.call(@swt_widget.getCaretOffset)
367
+ observer.call(@swt_widget.getSelection.x) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
355
368
  }
356
369
  end,
357
370
  :caret_offset => lambda do |observer|
371
+ on_caret_moved { |event|
372
+ observer.call(@swt_widget.getCaretOffset) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
373
+ }
374
+ end,
375
+ :selection => lambda do |observer|
376
+ on_widget_selected { |event|
377
+ observer.call(@swt_widget.getSelection) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
378
+ }
358
379
  on_swt_keyup { |event|
359
- observer.call(@swt_widget.getCaretOffset)
380
+ observer.call(@swt_widget.getSelection) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
360
381
  }
361
382
  on_swt_mouseup { |event|
362
- observer.call(@swt_widget.getCaretOffset)
383
+ observer.call(@swt_widget.getSelection) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
363
384
  }
364
385
  end,
365
- :selection => lambda do |observer|
386
+ :selection_count => lambda do |observer|
387
+ on_widget_selected { |event|
388
+ observer.call(@swt_widget.getSelectionCount) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
389
+ }
366
390
  on_swt_keyup { |event|
367
- observer.call(@swt_widget.getSelection) unless @swt_widget.getSelection.x == 0 && @swt_widget.getSelection.y == 0
391
+ observer.call(@swt_widget.getSelectionCount) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
368
392
  }
369
393
  on_swt_mouseup { |event|
370
- observer.call(@swt_widget.getSelection) unless @swt_widget.getSelection.x == 0 && @swt_widget.getSelection.y == 0
394
+ observer.call(@swt_widget.getSelectionCount) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
371
395
  }
372
396
  end,
373
- :selection_count => lambda do |observer|
397
+ :selection_range => lambda do |observer|
398
+ on_widget_selected { |event|
399
+ observer.call(@swt_widget.getSelectionRange) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
400
+ }
374
401
  on_swt_keyup { |event|
375
- observer.call(@swt_widget.getSelectionCount)
402
+ observer.call(@swt_widget.getSelectionRange) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
376
403
  }
377
404
  on_swt_mouseup { |event|
378
- observer.call(@swt_widget.getSelectionCount)
405
+ observer.call(@swt_widget.getSelectionRange) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
379
406
  }
380
407
  end,
381
408
  :top_index => lambda do |observer|
@@ -447,6 +474,7 @@ module Glimmer
447
474
  underscored_widget_name = KEYWORD_ALIASES[underscored_widget_name] if KEYWORD_ALIASES[underscored_widget_name]
448
475
  swt_widget_name = underscored_widget_name.camelcase(:upper)
449
476
  swt_widget_class = eval(swt_widget_name)
477
+ # TODO fix issue with not detecting DateTime because it's conflicting with the Ruby DateTime
450
478
  unless swt_widget_class.ancestors.include?(org.eclipse.swt.widgets.Widget)
451
479
  swt_widget_class = swt_widget_class_manual_entries[underscored_widget_name]
452
480
  if swt_widget_class.nil?
@@ -703,14 +731,17 @@ module Glimmer
703
731
  setter: {name: 'setFocus', invoker: lambda { |widget, args| @swt_widget.setFocus if args.first }},
704
732
  },
705
733
  'caret_position' => {
706
- getter: {name: 'getCaretPosition', invoker: lambda { |widget, args| @swt_widget.respond_to?(:getCaretPosition) ? @swt_widget.getCaretPosition : @swt_widget.getCaretOffset}},
707
- setter: {name: 'setSelection', invoker: lambda { |widget, args| @swt_widget.setSelection(args.first) if args.first }},
734
+ getter: {name: 'getCaretPosition', invoker: lambda { |widget, args| @swt_widget.respond_to?(:getCaretPosition) ? @swt_widget.getCaretPosition : @swt_widget.getSelection.x}},
735
+ setter: {name: 'setSelection', invoker: lambda { |widget, args| @swt_widget.setSelection(args.first, args.first + @swt_widget.getSelectionCount) if args.first }},
708
736
  },
709
737
  'selection_count' => {
710
738
  getter: {name: 'getSelectionCount'},
711
739
  setter: {name: 'setSelection', invoker: lambda { |widget, args|
712
- caret_position = @swt_widget.respond_to?(:getCaretPosition) ? @swt_widget.getCaretPosition : @swt_widget.getCaretOffset
713
- @swt_widget.setSelection(caret_position, caret_position + args.first) if args.first
740
+ if args.first
741
+ caret_position = @swt_widget.respond_to?(:getCaretPosition) ? @swt_widget.getCaretPosition : @swt_widget.getSelection.x
742
+ # TODO handle negative length
743
+ @swt_widget.setSelection(caret_position, caret_position + args.first)
744
+ end
714
745
  }},
715
746
  },
716
747
  }
@@ -822,6 +853,9 @@ module Glimmer
822
853
  end
823
854
  cursor_proxy ? cursor_proxy.swt_cursor : value
824
855
  end,
856
+ :enabled => lambda do |value|
857
+ !!value
858
+ end,
825
859
  :foreground => color_converter,
826
860
  :font => lambda do |value|
827
861
  if value.is_a?(Hash)
@@ -8,7 +8,7 @@ class Sample
8
8
 
9
9
  def name
10
10
  if @name.nil?
11
- @name = File.basename(file, '.rb').split('_').map(&:capitalize).join(' ')
11
+ @name = File.basename(file, '.rb').split('_').map(&:capitalize).join(' ')
12
12
  if @name.start_with?('Hello')
13
13
  name_parts = @name.split
14
14
  name_parts[0] = name_parts.first + ','
@@ -38,11 +38,11 @@ class SampleDirectory
38
38
  select { |file| File.directory?(file) }.
39
39
  map { |file| SampleDirectory.new(file) }
40
40
  glimmer_gems = Gem.find_latest_files("glimmer-*-*")
41
- sample_directories = glimmer_gems.map do |lib|
41
+ sample_directories = glimmer_gems.map do |lib|
42
42
  File.dirname(File.dirname(lib))
43
- end.select do |gem|
43
+ end.select do |gem|
44
44
  Dir.exist?(File.join(gem, 'samples'))
45
- end.map do |gem|
45
+ end.map do |gem|
46
46
  Dir.glob(File.join(gem, 'samples', '*')).select {|file_or_dir| Dir.exist?(file_or_dir)}
47
47
  end.flatten.uniq.reverse
48
48
  if Dir.exist?('samples')
@@ -51,14 +51,14 @@ class SampleDirectory
51
51
  end
52
52
  end
53
53
  sample_directories = sample_directories.uniq {|dir| File.basename(dir)}
54
- @sample_directories = sample_directories.map { |file| SampleDirectory.new(file) }
54
+ @sample_directories = sample_directories.map { |file| SampleDirectory.new(file) }
55
55
  end
56
56
  @sample_directories
57
57
  end
58
58
 
59
59
  def all_samples
60
60
  @all_samples ||= sample_directories.map(&:samples).reduce(:+)
61
- end
61
+ end
62
62
  end
63
63
 
64
64
  include Glimmer # used for observe syntax
@@ -117,7 +117,7 @@ class MetaSampleApplication
117
117
  text 'Glimmer Meta-Sample (The Sample of Samples)'
118
118
 
119
119
  on_swt_show {
120
- SampleDirectory.selected_sample = SampleDirectory.all_samples.first
120
+ SampleDirectory.selected_sample = SampleDirectory.all_samples.first
121
121
  }
122
122
 
123
123
  sash_form {
@@ -153,7 +153,7 @@ class MetaSampleApplication
153
153
  on_widget_selected {
154
154
  SampleDirectory.selected_sample.launch
155
155
  }
156
- }
156
+ }
157
157
  }
158
158
 
159
159
  code_text {
@@ -163,7 +163,7 @@ class MetaSampleApplication
163
163
  }
164
164
 
165
165
  weights 4, 9
166
- }
166
+ }
167
167
  }.open
168
168
  end
169
169
  end
@@ -19,6 +19,9 @@
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 `checkbox_group` (aka `check_group`) in Glimmer, which provides terser syntax
23
+ # than HelloCheckbox for representing multiple checkbox buttons (`button(:check)`) by relying on data-binding to
24
+ # automatically spawn the `checkbox` widgets (`button(:check)`) based on available options on the model.
22
25
  class HelloCheckboxGroup
23
26
  class Person
24
27
  attr_accessor :activities
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-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
@@ -41,9 +41,9 @@ class HelloCombo
41
41
  shell {
42
42
  row_layout(:vertical) {
43
43
  pack false
44
- }
44
+ }
45
45
 
46
- text 'Hello, Combo!'
46
+ text 'Hello, Combo!'
47
47
 
48
48
  combo(:read_only) {
49
49
  selection bind(person, :country)
@@ -19,6 +19,9 @@
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
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-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
@@ -0,0 +1,69 @@
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 HelloSpinner
23
+ class Person
24
+ attr_accessor :donation
25
+ end
26
+
27
+ include Glimmer
28
+
29
+ def initialize
30
+ @person = Person.new
31
+ @person.donation = 500
32
+ end
33
+
34
+ def launch
35
+ shell {
36
+ grid_layout
37
+
38
+ text 'Hello, Spinner!'
39
+
40
+ label {
41
+ text 'Please select the amount you would like to donate to the poor:'
42
+ }
43
+
44
+ composite {
45
+ grid_layout 3, false
46
+
47
+ label {
48
+ text 'Amount:'
49
+ font style: :bold
50
+ }
51
+
52
+ label {
53
+ text '$'
54
+ }
55
+
56
+ spinner {
57
+ digits 2 # digits after the decimal point
58
+ minimum 500 # minimum value (including digits after the decimal point)
59
+ maximum 15000 # maximum value (including digits after the decimal point)
60
+ increment 500 # increment on up and down (including digits after the decimal point)
61
+ page_increment 5000 # page increment on page up and page down (including digits after the decimal point)
62
+ selection bind(@person, :donation) # selection must be set last if other properties are configured to ensure value is within bounds
63
+ }
64
+ }
65
+ }.open
66
+ end
67
+ end
68
+
69
+ HelloSpinner.new.launch
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-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
@@ -22,19 +22,79 @@
22
22
  class HelloTable
23
23
  class BaseballGame
24
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
+
25
96
  def schedule
26
- @schedule ||= [
27
- new(Time.new(2037, 10, 6, 12, 0), 'Chicago Cubs', 'Milwaukee Brewers', 5, 7),
28
- new(Time.new(2037, 10, 7, 12, 0), 'Chicago Cubs', 'Milwaukee Brewers', 11, 7),
29
- new(Time.new(2037, 10, 8, 12, 0), 'Milwaukee Brewers', 'Chicago Cubs', 2, 3),
30
- new(Time.new(2037, 10, 9, 12, 0), 'Milwaukee Brewers', 'Chicago Cubs', 1, 0),
31
- new(Time.new(2037, 10, 10, 12, 0), 'Milwaukee Brewers', 'Chicago Cubs', 9, 10),
32
- new(Time.new(2037, 10, 6, 18, 0), 'Chicago White Sox', 'St Louis Cardinals', 2, 4),
33
- new(Time.new(2037, 10, 7, 18, 0), 'Chicago White Sox', 'St Louis Cardinals', 5, 6),
34
- new(Time.new(2037, 10, 8, 18, 0), 'St Louis Cardinals', 'Chicago White Sox', 0, 7),
35
- new(Time.new(2037, 10, 9, 18, 0), 'St Louis Cardinals', 'Chicago White Sox', 3, 4),
36
- new(Time.new(2037, 10, 10, 18, 0), 'St Louis Cardinals', 'Chicago White Sox', 11, 13),
37
- ]
97
+ @schedule ||= all_playoff_games[playoff_type]
38
98
  end
39
99
 
40
100
  def schedule=(new_schedule)
@@ -42,23 +102,31 @@ class HelloTable
42
102
  end
43
103
  end
44
104
 
105
+ include Glimmer
45
106
  include Glimmer::DataBinding::ObservableModel
46
107
 
47
108
  TEAM_BALLPARKS = {
109
+ 'Boston Red Sox' => 'Fenway Park',
48
110
  'Chicago Cubs' => 'Wrigley Field',
49
- 'Chicago White Sox' => 'Guaranteed Rate Field',
111
+ 'Cincinnati Reds' => 'Great American Ball Park',
112
+ 'Cleveland Indians' => 'Progressive Field',
113
+ 'Houston Astros' => 'Minute Maid Park',
50
114
  'Milwaukee Brewers' => 'Miller Park',
51
- 'St Louis Cardinals' => 'Busch Stadium'
115
+ 'New York Yankees' => 'Yankee Stadium',
116
+ 'St Louis Cardinals' => 'Busch Stadium',
52
117
  }
53
118
 
54
- attr_accessor :home_team, :away_team, :date_time, :ballpark, :home_team_runs, :away_team_runs
119
+ attr_accessor :date_time, :home_team, :away_team, :ballpark, :promotion
55
120
 
56
- def initialize(date_time, home_team, away_team, home_team_runs, away_team_runs)
121
+ def initialize(date_time, home_team, away_team, promotion = 'N/A')
57
122
  self.date_time = date_time
58
123
  self.home_team = home_team
59
124
  self.away_team = away_team
60
- self.home_team_runs = home_team_runs
61
- self.away_team_runs = away_team_runs
125
+ self.promotion = promotion
126
+ observe(self, :date_time) do |new_value|
127
+ notify_observers(:game_date)
128
+ notify_observers(:game_time)
129
+ end
62
130
  end
63
131
 
64
132
  def home_team=(home_team_value)
@@ -74,8 +142,20 @@ class HelloTable
74
142
  end
75
143
  end
76
144
 
77
- def game_date_time
78
- date_time.strftime("%Y-%m-%d %I:%M %p")
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")
79
159
  end
80
160
 
81
161
  def home_team_options
@@ -85,52 +165,117 @@ class HelloTable
85
165
  def away_team_options
86
166
  TEAM_BALLPARKS.keys
87
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
88
180
  end
89
181
 
90
182
  include Glimmer
91
183
 
92
184
  def launch
93
185
  shell {
186
+ grid_layout
187
+
94
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
+
95
203
  table(:editable) { |table_proxy|
204
+ layout_data :fill, :fill, true, true
205
+
96
206
  table_column {
97
- text 'Game Date/Time'
207
+ text 'Game Date'
98
208
  width 150
99
- sort_property :date_time # ensure sorting by real date value (not `game_date_time` string specified in items below)
100
- editor :none
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
101
211
  }
102
212
  table_column {
103
- text 'Home Team'
213
+ text 'Game Time'
104
214
  width 150
105
- editor :combo, :read_only
215
+ sort_property :time # ensure sorting by real time value (not `game_time` string specified in items below)
216
+ editor :time, property: :date_time
106
217
  }
107
218
  table_column {
108
- text 'Home Team Runs'
109
- width 100
110
- editor :spinner
219
+ text 'Ballpark'
220
+ width 180
221
+ editor :none
111
222
  }
112
223
  table_column {
113
- text 'Away Team'
224
+ text 'Home Team'
114
225
  width 150
115
- editor :combo, :read_only
226
+ editor :combo, :read_only # read_only is simply an SWT style passed to combo widget
116
227
  }
117
228
  table_column {
118
- text 'Away Team Runs'
119
- width 100
120
- editor :spinner
229
+ text 'Away Team'
230
+ width 150
231
+ editor :combo, :read_only # read_only is simply an SWT style passed to combo widget
121
232
  }
122
233
  table_column {
123
- text 'Ballpark'
234
+ text 'Promotion'
124
235
  width 150
125
- editor :none
236
+ # default text editor is used here
126
237
  }
127
238
 
128
239
  # Data-bind table items (rows) to a model collection property, specifying column properties ordering per nested model
129
- items bind(BaseballGame, :schedule), column_properties(:game_date_time, :home_team, :home_team_runs, :away_team, :away_team_runs, :ballpark)
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
130
247
 
131
- # Sort by these additional properties after handling the main column sort the user selected
132
- additional_sort_properties :date_time, :home_team, :away_team, :ballpark, :home_team_runs, :away_team_runs
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
+ }
133
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!
134
279
  }.open
135
280
  end
136
281
  end