glimmer-dsl-swt 4.17.8.1 → 4.17.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +41 -0
  3. data/README.md +249 -7
  4. data/VERSION +1 -1
  5. data/glimmer-dsl-swt.gemspec +12 -7
  6. data/lib/glimmer-dsl-swt.rb +4 -3
  7. data/lib/glimmer/data_binding/table_items_binding.rb +5 -5
  8. data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +3 -3
  9. data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +3 -3
  10. data/lib/glimmer/dsl/swt/table_items_data_binding_expression.rb +3 -3
  11. data/lib/glimmer/dsl/swt/widget_expression.rb +1 -0
  12. data/lib/glimmer/launcher.rb +9 -9
  13. data/lib/glimmer/swt/custom/checkbox_group.rb +29 -8
  14. data/lib/glimmer/swt/custom/code_text.rb +36 -34
  15. data/lib/glimmer/swt/custom/radio_group.rb +27 -6
  16. data/lib/glimmer/swt/date_time_proxy.rb +87 -0
  17. data/lib/glimmer/swt/display_proxy.rb +6 -6
  18. data/lib/glimmer/swt/dnd_proxy.rb +6 -10
  19. data/lib/glimmer/swt/message_box_proxy.rb +7 -7
  20. data/lib/glimmer/swt/sash_form_proxy.rb +3 -3
  21. data/lib/glimmer/swt/shell_proxy.rb +18 -3
  22. data/lib/glimmer/swt/style_constantizable.rb +5 -5
  23. data/lib/glimmer/swt/swt_proxy.rb +7 -8
  24. data/lib/glimmer/swt/tab_item_proxy.rb +9 -4
  25. data/lib/glimmer/swt/table_column_proxy.rb +13 -5
  26. data/lib/glimmer/swt/table_proxy.rb +187 -66
  27. data/lib/glimmer/swt/widget_listener_proxy.rb +4 -4
  28. data/lib/glimmer/swt/widget_proxy.rb +47 -3
  29. data/samples/elaborate/contact_manager.rb +3 -3
  30. data/samples/elaborate/meta_sample.rb +9 -9
  31. data/samples/hello/hello_browser.rb +3 -3
  32. data/samples/hello/hello_checkbox.rb +4 -4
  33. data/samples/hello/hello_checkbox_group.rb +6 -3
  34. data/samples/hello/hello_combo.rb +5 -5
  35. data/samples/hello/hello_date_time.rb +63 -0
  36. data/samples/hello/hello_group.rb +104 -0
  37. data/samples/hello/hello_menu_bar.rb +3 -3
  38. data/samples/hello/hello_pop_up_context_menu.rb +3 -3
  39. data/samples/hello/hello_radio.rb +6 -6
  40. data/samples/hello/hello_radio_group.rb +9 -6
  41. data/samples/hello/hello_sash_form.rb +3 -3
  42. data/samples/hello/hello_spinner.rb +69 -0
  43. data/samples/hello/hello_tab.rb +3 -3
  44. data/samples/hello/hello_table.rb +287 -0
  45. metadata +11 -6
@@ -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
@@ -40,7 +40,7 @@ module Glimmer
40
40
 
41
41
  def widget_remove_listener_method
42
42
  @widget_add_listener_method.sub('add', 'remove')
43
- end
43
+ end
44
44
 
45
45
  def unregister
46
46
  # TODO consider renaming to deregister (and in Observer too)
@@ -63,6 +63,9 @@ module Glimmer
63
63
  'tool_bar' => [:push],
64
64
  'tool_item' => [:push],
65
65
  'tree' => [:virtual, :border, :h_scroll, :v_scroll],
66
+ 'date_drop_down' => [:date, :drop_down],
67
+ 'time' => [:time],
68
+ 'calendar' => [:calendar],
66
69
  }
67
70
 
68
71
  DEFAULT_INITIALIZERS = {
@@ -96,6 +99,10 @@ module Glimmer
96
99
  'check' => 'button',
97
100
  'radio' => 'button',
98
101
  'toggle' => 'button',
102
+ 'date' => 'date_time',
103
+ 'date_drop_down' => 'date_time',
104
+ 'time' => 'date_time',
105
+ 'calendar' => 'date_time',
99
106
  }
100
107
 
101
108
  class << self
@@ -224,8 +231,10 @@ module Glimmer
224
231
  else
225
232
  @swt_widget.send(widget_custom_attribute[:getter][:name])
226
233
  end
227
- else
234
+ elsif @swt_widget.respond_to?(attribute_getter(attribute_name))
228
235
  @swt_widget.send(attribute_getter(attribute_name))
236
+ else
237
+ send(attribute_name)
229
238
  end
230
239
  end
231
240
 
@@ -272,6 +281,17 @@ module Glimmer
272
281
  }
273
282
  end,
274
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
+ },
275
295
  Java::OrgEclipseSwtWidgets::Text => {
276
296
  :text => lambda do |observer|
277
297
  on_modify_text { |modify_event|
@@ -408,21 +428,42 @@ module Glimmer
408
428
  }
409
429
  end
410
430
  },
431
+ Java::OrgEclipseSwtWidgets::DateTime =>
432
+ [:year, :month, :day, :hours, :minutes, :seconds, :date_time, :date, :time].reduce({}) do |hash, attribute|
433
+ hash.merge(
434
+ attribute => lambda do |observer|
435
+ on_widget_selected { |selection_event|
436
+ observer.call(get_attribute(attribute))
437
+ }
438
+ end
439
+ )
440
+ end,
411
441
  }
412
442
  end
413
443
 
414
444
  def self.widget_exists?(underscored_widget_name)
415
445
  !!swt_widget_class_for(underscored_widget_name)
416
446
  end
447
+
448
+ # Manual entries of SWT widget classes that conflict with Ruby classes
449
+ def self.swt_widget_class_manual_entries
450
+ {
451
+ 'date_time' => Java::OrgEclipseSwtWidgets::DateTime
452
+ }
453
+ end
417
454
 
418
455
  # This supports widgets in and out of basic SWT
419
456
  def self.swt_widget_class_for(underscored_widget_name)
420
457
  underscored_widget_name = KEYWORD_ALIASES[underscored_widget_name] if KEYWORD_ALIASES[underscored_widget_name]
421
458
  swt_widget_name = underscored_widget_name.camelcase(:upper)
422
459
  swt_widget_class = eval(swt_widget_name)
460
+ # TODO fix issue with not detecting DateTime because it's conflicting with the Ruby DateTime
423
461
  unless swt_widget_class.ancestors.include?(org.eclipse.swt.widgets.Widget)
424
- Glimmer::Config.logger.debug {"Class #{swt_widget_class} matching #{underscored_widget_name} is not a subclass of org.eclipse.swt.widgets.Widget"}
425
- return nil
462
+ swt_widget_class = swt_widget_class_manual_entries[underscored_widget_name]
463
+ if swt_widget_class.nil?
464
+ Glimmer::Config.logger.debug {"Class #{swt_widget_class} matching #{underscored_widget_name} is not a subclass of org.eclipse.swt.widgets.Widget"}
465
+ return nil
466
+ end
426
467
  end
427
468
  swt_widget_class
428
469
  rescue SyntaxError, NameError => e
@@ -792,6 +833,9 @@ module Glimmer
792
833
  end
793
834
  cursor_proxy ? cursor_proxy.swt_cursor : value
794
835
  end,
836
+ :enabled => lambda do |value|
837
+ !!value
838
+ end,
795
839
  :foreground => color_converter,
796
840
  :font => lambda do |value|
797
841
  if value.is_a?(Hash)
@@ -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
@@ -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
@@ -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
@@ -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,7 +41,7 @@ class HelloCheckbox
41
41
  person = Person.new
42
42
 
43
43
  shell {
44
- text 'Hello, Checkbox!'
44
+ text 'Hello, Checkbox!'
45
45
  row_layout :vertical
46
46
 
47
47
  label {
@@ -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
@@ -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)
@@ -0,0 +1,63 @@
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 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,104 @@
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 HelloGroup
23
+ class Person
24
+ attr_accessor :male, :female, :child, :teen, :adult, :senior
25
+
26
+ def initialize
27
+ reset
28
+ end
29
+
30
+ def reset
31
+ self.male = nil
32
+ self.female = nil
33
+ self.child = nil
34
+ self.teen = nil
35
+ self.adult = true
36
+ self.senior = nil
37
+ end
38
+ end
39
+
40
+ include Glimmer
41
+
42
+ def launch
43
+ person = Person.new
44
+
45
+ shell {
46
+ text 'Hello, Group!'
47
+ row_layout :vertical
48
+
49
+ group {
50
+ row_layout
51
+
52
+ text 'Gender'
53
+ font style: :bold
54
+
55
+ radio {
56
+ text 'Male'
57
+ selection bind(person, :male)
58
+ }
59
+
60
+ radio {
61
+ text 'Female'
62
+ selection bind(person, :female)
63
+ }
64
+ }
65
+
66
+ group {
67
+ row_layout
68
+
69
+ text 'Age Group'
70
+ font style: :bold
71
+
72
+ radio {
73
+ text 'Child'
74
+ selection bind(person, :child)
75
+ }
76
+
77
+ radio {
78
+ text 'Teen'
79
+ selection bind(person, :teen)
80
+ }
81
+
82
+ radio {
83
+ text 'Adult'
84
+ selection bind(person, :adult)
85
+ }
86
+
87
+ radio {
88
+ text 'Senior'
89
+ selection bind(person, :senior)
90
+ }
91
+ }
92
+
93
+ button {
94
+ text 'Reset'
95
+
96
+ on_widget_selected do
97
+ person.reset
98
+ end
99
+ }
100
+ }.open
101
+ end
102
+ end
103
+
104
+ HelloGroup.new.launch