glimmer-dsl-swt 4.17.8.2 → 4.17.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -1
  3. data/README.md +228 -7
  4. data/VERSION +1 -1
  5. data/glimmer-dsl-swt.gemspec +11 -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/table_items_data_binding_expression.rb +3 -3
  9. data/lib/glimmer/dsl/swt/widget_expression.rb +1 -0
  10. data/lib/glimmer/launcher.rb +9 -9
  11. data/lib/glimmer/swt/custom/code_text.rb +36 -34
  12. data/lib/glimmer/swt/date_time_proxy.rb +87 -0
  13. data/lib/glimmer/swt/display_proxy.rb +6 -6
  14. data/lib/glimmer/swt/dnd_proxy.rb +6 -10
  15. data/lib/glimmer/swt/message_box_proxy.rb +7 -7
  16. data/lib/glimmer/swt/sash_form_proxy.rb +3 -3
  17. data/lib/glimmer/swt/shell_proxy.rb +18 -3
  18. data/lib/glimmer/swt/style_constantizable.rb +5 -5
  19. data/lib/glimmer/swt/styled_text_proxy.rb +8 -13
  20. data/lib/glimmer/swt/swt_proxy.rb +7 -8
  21. data/lib/glimmer/swt/tab_item_proxy.rb +6 -1
  22. data/lib/glimmer/swt/table_column_proxy.rb +13 -5
  23. data/lib/glimmer/swt/table_proxy.rb +187 -66
  24. data/lib/glimmer/swt/widget_listener_proxy.rb +4 -4
  25. data/lib/glimmer/swt/widget_proxy.rb +70 -24
  26. data/samples/elaborate/contact_manager.rb +3 -3
  27. data/samples/elaborate/meta_sample.rb +9 -9
  28. data/samples/hello/hello_browser.rb +3 -3
  29. data/samples/hello/hello_checkbox_group.rb +3 -0
  30. data/samples/hello/hello_combo.rb +5 -5
  31. data/samples/hello/hello_date_time.rb +63 -0
  32. data/samples/hello/hello_group.rb +1 -1
  33. data/samples/hello/hello_menu_bar.rb +3 -3
  34. data/samples/hello/hello_pop_up_context_menu.rb +3 -3
  35. data/samples/hello/hello_radio_group.rb +3 -0
  36. data/samples/hello/hello_sash_form.rb +3 -3
  37. data/samples/hello/hello_spinner.rb +69 -0
  38. data/samples/hello/hello_tab.rb +3 -3
  39. data/samples/hello/hello_table.rb +287 -0
  40. metadata +10 -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|
@@ -337,35 +357,34 @@ module Glimmer
337
357
  }
338
358
  end,
339
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
+ }
340
363
  on_swt_keyup { |event|
341
- observer.call(@swt_widget.getCaretOffset)
364
+ observer.call(@swt_widget.getSelection.x) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
342
365
  }
343
366
  on_swt_mouseup { |event|
344
- observer.call(@swt_widget.getCaretOffset)
367
+ observer.call(@swt_widget.getSelection.x) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
345
368
  }
346
369
  end,
347
370
  :caret_offset => lambda do |observer|
348
- on_swt_keyup { |event|
349
- observer.call(@swt_widget.getCaretOffset)
350
- }
351
- on_swt_mouseup { |event|
352
- observer.call(@swt_widget.getCaretOffset)
371
+ on_caret_moved { |event|
372
+ observer.call(@swt_widget.getCaretOffset) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
353
373
  }
354
374
  end,
355
375
  :selection => lambda do |observer|
356
- on_swt_keyup { |event|
357
- observer.call(@swt_widget.getSelection) unless @swt_widget.getSelection.x == 0 && @swt_widget.getSelection.y == 0
358
- }
359
- on_swt_mouseup { |event|
360
- observer.call(@swt_widget.getSelection) unless @swt_widget.getSelection.x == 0 && @swt_widget.getSelection.y == 0
376
+ on_widget_selected { |event|
377
+ observer.call(@swt_widget.getSelection) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
361
378
  }
362
379
  end,
363
380
  :selection_count => lambda do |observer|
364
- on_swt_keyup { |event|
365
- observer.call(@swt_widget.getSelectionCount)
381
+ on_widget_selected { |event|
382
+ observer.call(@swt_widget.getSelectionCount) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
366
383
  }
367
- on_swt_mouseup { |event|
368
- observer.call(@swt_widget.getSelectionCount)
384
+ end,
385
+ :selection_range => lambda do |observer|
386
+ on_widget_selected { |event|
387
+ observer.call(@swt_widget.getSelectionRange) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
369
388
  }
370
389
  end,
371
390
  :top_index => lambda do |observer|
@@ -408,21 +427,42 @@ module Glimmer
408
427
  }
409
428
  end
410
429
  },
430
+ Java::OrgEclipseSwtWidgets::DateTime =>
431
+ [:year, :month, :day, :hours, :minutes, :seconds, :date_time, :date, :time].reduce({}) do |hash, attribute|
432
+ hash.merge(
433
+ attribute => lambda do |observer|
434
+ on_widget_selected { |selection_event|
435
+ observer.call(get_attribute(attribute))
436
+ }
437
+ end
438
+ )
439
+ end,
411
440
  }
412
441
  end
413
442
 
414
443
  def self.widget_exists?(underscored_widget_name)
415
444
  !!swt_widget_class_for(underscored_widget_name)
416
445
  end
446
+
447
+ # Manual entries of SWT widget classes that conflict with Ruby classes
448
+ def self.swt_widget_class_manual_entries
449
+ {
450
+ 'date_time' => Java::OrgEclipseSwtWidgets::DateTime
451
+ }
452
+ end
417
453
 
418
454
  # This supports widgets in and out of basic SWT
419
455
  def self.swt_widget_class_for(underscored_widget_name)
420
456
  underscored_widget_name = KEYWORD_ALIASES[underscored_widget_name] if KEYWORD_ALIASES[underscored_widget_name]
421
457
  swt_widget_name = underscored_widget_name.camelcase(:upper)
422
458
  swt_widget_class = eval(swt_widget_name)
459
+ # TODO fix issue with not detecting DateTime because it's conflicting with the Ruby DateTime
423
460
  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
461
+ swt_widget_class = swt_widget_class_manual_entries[underscored_widget_name]
462
+ if swt_widget_class.nil?
463
+ Glimmer::Config.logger.debug {"Class #{swt_widget_class} matching #{underscored_widget_name} is not a subclass of org.eclipse.swt.widgets.Widget"}
464
+ return nil
465
+ end
426
466
  end
427
467
  swt_widget_class
428
468
  rescue SyntaxError, NameError => e
@@ -673,14 +713,17 @@ module Glimmer
673
713
  setter: {name: 'setFocus', invoker: lambda { |widget, args| @swt_widget.setFocus if args.first }},
674
714
  },
675
715
  'caret_position' => {
676
- getter: {name: 'getCaretPosition', invoker: lambda { |widget, args| @swt_widget.respond_to?(:getCaretPosition) ? @swt_widget.getCaretPosition : @swt_widget.getCaretOffset}},
677
- setter: {name: 'setSelection', invoker: lambda { |widget, args| @swt_widget.setSelection(args.first) if args.first }},
716
+ getter: {name: 'getCaretPosition', invoker: lambda { |widget, args| @swt_widget.respond_to?(:getCaretPosition) ? @swt_widget.getCaretPosition : @swt_widget.getSelection.x}},
717
+ setter: {name: 'setSelection', invoker: lambda { |widget, args| @swt_widget.setSelection(args.first, args.first + @swt_widget.getSelectionCount) if args.first }},
678
718
  },
679
719
  'selection_count' => {
680
720
  getter: {name: 'getSelectionCount'},
681
721
  setter: {name: 'setSelection', invoker: lambda { |widget, args|
682
- caret_position = @swt_widget.respond_to?(:getCaretPosition) ? @swt_widget.getCaretPosition : @swt_widget.getCaretOffset
683
- @swt_widget.setSelection(caret_position, caret_position + args.first) if args.first
722
+ if args.first
723
+ caret_position = @swt_widget.respond_to?(:getCaretPosition) ? @swt_widget.getCaretPosition : @swt_widget.getSelection.x
724
+ # TODO handle negative length
725
+ @swt_widget.setSelection(caret_position, caret_position + args.first)
726
+ end
684
727
  }},
685
728
  },
686
729
  }
@@ -792,6 +835,9 @@ module Glimmer
792
835
  end
793
836
  cursor_proxy ? cursor_proxy.swt_cursor : value
794
837
  end,
838
+ :enabled => lambda do |value|
839
+ !!value
840
+ end,
795
841
  :foreground => color_converter,
796
842
  :font => lambda do |value|
797
843
  if value.is_a?(Hash)
@@ -841,4 +887,4 @@ module Glimmer
841
887
  end
842
888
  end
843
889
  end
844
- end
890
+ 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
@@ -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
@@ -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
@@ -43,7 +43,7 @@ class HelloGroup
43
43
  person = Person.new
44
44
 
45
45
  shell {
46
- text 'Hello, Radio!'
46
+ text 'Hello, Group!'
47
47
  row_layout :vertical
48
48
 
49
49
  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