glimmer-dsl-swt 4.17.6.0 → 4.17.8.3

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +34 -2
  3. data/README.md +211 -82
  4. data/VERSION +1 -1
  5. data/glimmer-dsl-swt.gemspec +14 -3
  6. data/lib/glimmer/data_binding/tree_items_binding.rb +20 -2
  7. data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +61 -0
  8. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +1 -0
  9. data/lib/glimmer/dsl/swt/dialog_expression.rb +1 -0
  10. data/lib/glimmer/dsl/swt/directory_dialog_expression.rb +48 -0
  11. data/lib/glimmer/dsl/swt/dsl.rb +1 -0
  12. data/lib/glimmer/dsl/swt/file_dialog_expression.rb +48 -0
  13. data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +3 -3
  14. data/lib/glimmer/dsl/swt/shell_expression.rb +3 -3
  15. data/lib/glimmer/dsl/swt/widget_expression.rb +8 -8
  16. data/lib/glimmer/swt/custom/checkbox_group.rb +181 -0
  17. data/lib/glimmer/swt/custom/code_text.rb +43 -33
  18. data/lib/glimmer/swt/custom/radio_group.rb +94 -19
  19. data/lib/glimmer/swt/directory_dialog_proxy.rb +65 -0
  20. data/lib/glimmer/swt/expand_item_proxy.rb +0 -1
  21. data/lib/glimmer/swt/file_dialog_proxy.rb +66 -0
  22. data/lib/glimmer/swt/menu_proxy.rb +3 -3
  23. data/lib/glimmer/swt/shell_proxy.rb +5 -5
  24. data/lib/glimmer/swt/tab_item_proxy.rb +3 -3
  25. data/lib/glimmer/swt/table_proxy.rb +25 -25
  26. data/lib/glimmer/swt/widget_listener_proxy.rb +4 -4
  27. data/lib/glimmer/swt/widget_proxy.rb +27 -27
  28. data/lib/glimmer/ui/custom_shell.rb +3 -3
  29. data/samples/elaborate/contact_manager.rb +3 -3
  30. data/samples/elaborate/meta_sample.rb +24 -19
  31. data/samples/hello/hello_browser.rb +3 -3
  32. data/samples/hello/hello_checkbox.rb +18 -18
  33. data/samples/hello/hello_checkbox_group.rb +68 -0
  34. data/samples/hello/hello_combo.rb +12 -12
  35. data/samples/hello/hello_directory_dialog.rb +60 -0
  36. data/samples/hello/hello_expand_bar.rb +3 -1
  37. data/samples/hello/hello_file_dialog.rb +60 -0
  38. data/samples/hello/hello_group.rb +104 -0
  39. data/samples/hello/hello_list_multi_selection.rb +23 -23
  40. data/samples/hello/hello_list_single_selection.rb +18 -17
  41. data/samples/hello/hello_menu_bar.rb +3 -3
  42. data/samples/hello/hello_pop_up_context_menu.rb +3 -3
  43. data/samples/hello/hello_radio.rb +20 -20
  44. data/samples/hello/hello_radio_group.rb +25 -25
  45. data/samples/hello/hello_table.rb +130 -0
  46. data/samples/hello/hello_world.rb +3 -3
  47. metadata +13 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.17.6.0
1
+ 4.17.8.3
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: glimmer-dsl-swt 4.17.6.0 ruby lib
5
+ # stub: glimmer-dsl-swt 4.17.8.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "glimmer-dsl-swt".freeze
9
- s.version = "4.17.6.0"
9
+ s.version = "4.17.8.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["AndyMaleh".freeze]
14
- s.date = "2020-10-28"
14
+ s.date = "2020-11-05"
15
15
  s.description = "Glimmer DSL for SWT (JRuby Desktop Development GUI Library)".freeze
16
16
  s.email = "andy.am@gmail.com".freeze
17
17
  s.executables = ["glimmer".freeze, "girb".freeze]
@@ -45,6 +45,7 @@ Gem::Specification.new do |s|
45
45
  "lib/glimmer/dsl/swt/async_exec_expression.rb",
46
46
  "lib/glimmer/dsl/swt/bind_expression.rb",
47
47
  "lib/glimmer/dsl/swt/block_property_expression.rb",
48
+ "lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb",
48
49
  "lib/glimmer/dsl/swt/color_expression.rb",
49
50
  "lib/glimmer/dsl/swt/column_properties_expression.rb",
50
51
  "lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb",
@@ -52,11 +53,13 @@ Gem::Specification.new do |s|
52
53
  "lib/glimmer/dsl/swt/custom_widget_expression.rb",
53
54
  "lib/glimmer/dsl/swt/data_binding_expression.rb",
54
55
  "lib/glimmer/dsl/swt/dialog_expression.rb",
56
+ "lib/glimmer/dsl/swt/directory_dialog_expression.rb",
55
57
  "lib/glimmer/dsl/swt/display_expression.rb",
56
58
  "lib/glimmer/dsl/swt/dnd_expression.rb",
57
59
  "lib/glimmer/dsl/swt/dsl.rb",
58
60
  "lib/glimmer/dsl/swt/exec_expression.rb",
59
61
  "lib/glimmer/dsl/swt/expand_item_expression.rb",
62
+ "lib/glimmer/dsl/swt/file_dialog_expression.rb",
60
63
  "lib/glimmer/dsl/swt/font_expression.rb",
61
64
  "lib/glimmer/dsl/swt/image_expression.rb",
62
65
  "lib/glimmer/dsl/swt/layout_data_expression.rb",
@@ -86,11 +89,14 @@ Gem::Specification.new do |s|
86
89
  "lib/glimmer/rake_task/scaffold.rb",
87
90
  "lib/glimmer/swt/color_proxy.rb",
88
91
  "lib/glimmer/swt/cursor_proxy.rb",
92
+ "lib/glimmer/swt/custom/checkbox_group.rb",
89
93
  "lib/glimmer/swt/custom/code_text.rb",
90
94
  "lib/glimmer/swt/custom/radio_group.rb",
95
+ "lib/glimmer/swt/directory_dialog_proxy.rb",
91
96
  "lib/glimmer/swt/display_proxy.rb",
92
97
  "lib/glimmer/swt/dnd_proxy.rb",
93
98
  "lib/glimmer/swt/expand_item_proxy.rb",
99
+ "lib/glimmer/swt/file_dialog_proxy.rb",
94
100
  "lib/glimmer/swt/font_proxy.rb",
95
101
  "lib/glimmer/swt/image_proxy.rb",
96
102
  "lib/glimmer/swt/layout_data_proxy.rb",
@@ -125,13 +131,17 @@ Gem::Specification.new do |s|
125
131
  "samples/elaborate/user_profile.rb",
126
132
  "samples/hello/hello_browser.rb",
127
133
  "samples/hello/hello_checkbox.rb",
134
+ "samples/hello/hello_checkbox_group.rb",
128
135
  "samples/hello/hello_combo.rb",
129
136
  "samples/hello/hello_computed.rb",
130
137
  "samples/hello/hello_computed/contact.rb",
131
138
  "samples/hello/hello_custom_shell.rb",
132
139
  "samples/hello/hello_custom_widget.rb",
140
+ "samples/hello/hello_directory_dialog.rb",
133
141
  "samples/hello/hello_drag_and_drop.rb",
134
142
  "samples/hello/hello_expand_bar.rb",
143
+ "samples/hello/hello_file_dialog.rb",
144
+ "samples/hello/hello_group.rb",
135
145
  "samples/hello/hello_list_multi_selection.rb",
136
146
  "samples/hello/hello_list_single_selection.rb",
137
147
  "samples/hello/hello_menu_bar.rb",
@@ -142,6 +152,7 @@ Gem::Specification.new do |s|
142
152
  "samples/hello/hello_sash_form.rb",
143
153
  "samples/hello/hello_styled_text.rb",
144
154
  "samples/hello/hello_tab.rb",
155
+ "samples/hello/hello_table.rb",
145
156
  "samples/hello/hello_world.rb",
146
157
  "vendor/swt/linux/swt.jar",
147
158
  "vendor/swt/mac/swt.jar",
@@ -33,7 +33,7 @@ module Glimmer
33
33
 
34
34
  include_package 'org.eclipse.swt'
35
35
  include_package 'org.eclipse.swt.widgets'
36
-
36
+
37
37
  def initialize(parent, model_binding, tree_properties)
38
38
  @tree = parent
39
39
  @model_binding = model_binding
@@ -53,13 +53,19 @@ module Glimmer
53
53
 
54
54
  def call(new_value=nil)
55
55
  @model_tree_root_node = @model_binding.evaluate_property
56
+ old_tree_items = @tree.all_tree_items
57
+ old_model_tree_nodes = old_tree_items.map(&:get_data)
58
+ new_model_tree_nodes = []
59
+ recursive_depth_first_search(@model_tree_root_node, @tree_properties, new_model_tree_nodes)
60
+ return if old_model_tree_nodes == new_model_tree_nodes && old_tree_items.map(&:text) == new_model_tree_nodes.map {|model_tree_node| model_tree_node.send(@tree_properties[:text])}
56
61
  populate_tree(@model_tree_root_node, @tree, @tree_properties)
57
62
  end
58
63
 
59
64
  def populate_tree(model_tree_root_node, parent, tree_properties)
65
+ # TODO get rid of model_tree_root_node, parent, tree_properties as an argument given it is stored as an instance variable
60
66
  # TODO make it change things by delta instead of removing all
61
- selected_tree_item_model = parent.swt_widget.getSelection.map(&:getData).first
62
67
  old_tree_items = parent.all_tree_items
68
+ selected_tree_item_model = parent.swt_widget.getSelection.map(&:get_data).first
63
69
  old_tree_item_expansion_by_data = old_tree_items.reduce({}) {|hash, ti| hash.merge(ti.getData => ti.getExpanded)}
64
70
  old_tree_items.each do |tree_item|
65
71
  tree_item.getData('observer_registrations').each(&:unregister)
@@ -78,6 +84,7 @@ module Glimmer
78
84
  observer_registrations = @tree_properties.reduce([]) do |array, key_value_pair|
79
85
  array + [observe(model_tree_node, key_value_pair.last)]
80
86
  end
87
+
81
88
  tree_item.setData('observer_registrations', observer_registrations)
82
89
  tree_item.setData(model_tree_node)
83
90
  tree_item.setText((model_tree_node && model_tree_node.send(tree_properties[:text])).to_s)
@@ -85,6 +92,17 @@ module Glimmer
85
92
  populate_tree_node(child, tree_item, tree_properties)
86
93
  end
87
94
  end
95
+
96
+ def recursive_depth_first_search(model_tree_node, tree_properties, collection)
97
+ return if model_tree_node.nil?
98
+ collection << model_tree_node
99
+ model_tree_node.send(tree_properties[:children]).to_a.each do |child_model_tree_node|
100
+ recursive_depth_first_search(child_model_tree_node, tree_properties, collection)
101
+ end
102
+ end
103
+
88
104
  end
105
+
89
106
  end
107
+
90
108
  end
@@ -0,0 +1,61 @@
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
+ require 'glimmer/dsl/expression'
23
+ require 'glimmer/data_binding/model_binding'
24
+ require 'glimmer/data_binding/widget_binding'
25
+
26
+ module Glimmer
27
+ module DSL
28
+ module SWT
29
+ class CheckboxGroupSelectionDataBindingExpression < Expression
30
+
31
+ def can_interpret?(parent, keyword, *args, &block)
32
+ keyword == 'selection' and
33
+ block.nil? and
34
+ (parent.is_a?(Glimmer::SWT::Custom::CheckboxGroup) or (parent.is_a?(Glimmer::UI::CustomWidget) and parent.body_root.is_a?(Glimmer::SWT::Custom::CheckboxGroup)) ) and
35
+ args.size == 1 and
36
+ args[0].is_a?(DataBinding::ModelBinding) and
37
+ args[0].evaluate_options_property.is_a?(Array)
38
+ end
39
+
40
+ def interpret(parent, keyword, *args, &block)
41
+ model_binding = args[0]
42
+
43
+ #TODO make this options observer dependent and all similar observers in widget specific data binding handlers
44
+ # TODO consider delegating some of this work
45
+ widget_binding = DataBinding::WidgetBinding.new(parent, 'items')
46
+ widget_binding.call(model_binding.evaluate_options_property)
47
+ model = model_binding.base_model
48
+ widget_binding.observe(model, model_binding.options_property_name)
49
+
50
+ widget_binding = DataBinding::WidgetBinding.new(parent, 'selection')
51
+ widget_binding.call(model_binding.evaluate_property)
52
+ widget_binding.observe(model, model_binding.property_name_expression)
53
+
54
+ parent.on_widget_selected do
55
+ model_binding.call(widget_binding.evaluate_property)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -27,6 +27,7 @@ require 'glimmer/ui/custom_widget'
27
27
  require 'glimmer/ui/custom_shell'
28
28
  require 'glimmer/swt/custom/code_text'
29
29
  require 'glimmer/swt/custom/radio_group'
30
+ require 'glimmer/swt/custom/checkbox_group'
30
31
 
31
32
  module Glimmer
32
33
  module DSL
@@ -37,6 +37,7 @@ module Glimmer
37
37
  end
38
38
 
39
39
  def interpret(parent, keyword, *args, &block)
40
+ # TODO reconcile this with the actual org.eclipse.swt.widgets.Dialog widget (maybe rename this as dialog_shell)
40
41
  args = [parent] + args unless parent.nil?
41
42
  args += [:dialog_trim, :application_modal]
42
43
  Glimmer::SWT::ShellProxy.send(:new, *args)
@@ -0,0 +1,48 @@
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
+ require 'glimmer/dsl/static_expression'
23
+ require 'glimmer/dsl/parent_expression'
24
+ require 'glimmer/dsl/top_level_expression'
25
+ require 'glimmer/swt/directory_dialog_proxy'
26
+
27
+ module Glimmer
28
+ module DSL
29
+ module SWT
30
+ class DirectoryDialogExpression < StaticExpression
31
+ include TopLevelExpression
32
+ include ParentExpression
33
+
34
+ include_package 'org.eclipse.swt.widgets'
35
+
36
+ def can_interpret?(parent, keyword, *args, &block)
37
+ keyword == 'directory_dialog' and
38
+ (parent.nil? or parent.is_a?(Shell) or parent.is_a?(Glimmer::SWT::ShellProxy))
39
+ end
40
+
41
+ def interpret(parent, keyword, *args, &block)
42
+ args = [parent] + args unless parent.nil?
43
+ Glimmer::SWT::DirectoryDialogProxy.send(:new, *args)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -41,6 +41,7 @@ module Glimmer
41
41
  layout
42
42
  widget_listener
43
43
  combo_selection_data_binding
44
+ checkbox_group_selection_data_binding
44
45
  radio_group_selection_data_binding
45
46
  list_selection_data_binding
46
47
  tree_items_data_binding
@@ -0,0 +1,48 @@
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
+ require 'glimmer/dsl/static_expression'
23
+ require 'glimmer/dsl/parent_expression'
24
+ require 'glimmer/dsl/top_level_expression'
25
+ require 'glimmer/swt/file_dialog_proxy'
26
+
27
+ module Glimmer
28
+ module DSL
29
+ module SWT
30
+ class FileDialogExpression < StaticExpression
31
+ include TopLevelExpression
32
+ include ParentExpression
33
+
34
+ include_package 'org.eclipse.swt.widgets'
35
+
36
+ def can_interpret?(parent, keyword, *args, &block)
37
+ keyword == 'file_dialog' and
38
+ (parent.nil? or parent.is_a?(Shell) or parent.is_a?(Glimmer::SWT::ShellProxy))
39
+ end
40
+
41
+ def interpret(parent, keyword, *args, &block)
42
+ args = [parent] + args unless parent.nil?
43
+ Glimmer::SWT::FileDialogProxy.send(:new, *args)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ 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
@@ -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
@@ -28,24 +28,24 @@ module Glimmer
28
28
  module SWT
29
29
  class WidgetExpression < Expression
30
30
  include ParentExpression
31
-
31
+
32
32
  EXCLUDED_KEYWORDS = %w[shell display tab_item]
33
-
33
+
34
34
  def can_interpret?(parent, keyword, *args, &block)
35
35
  !EXCLUDED_KEYWORDS.include?(keyword) and
36
36
  parent.respond_to?(:swt_widget) and #TODO change to composite?(parent)
37
37
  Glimmer::SWT::WidgetProxy.widget_exists?(keyword)
38
38
  end
39
-
39
+
40
40
  def interpret(parent, keyword, *args, &block)
41
41
  Glimmer::SWT::WidgetProxy.create(keyword, parent, args)
42
42
  end
43
-
43
+
44
44
  def add_content(parent, &block)
45
45
  super
46
46
  parent.post_add_content
47
47
  end
48
-
48
+
49
49
  end
50
50
  end
51
51
  end
@@ -0,0 +1,181 @@
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
+ require 'glimmer/ui/custom_widget'
23
+
24
+ module Glimmer
25
+ module SWT
26
+ module Custom
27
+ # A custom widget rendering a group of checkboxes generated via data-binding
28
+ class CheckboxGroup
29
+ include Glimmer::UI::CustomWidget
30
+
31
+ body {
32
+ composite # just an empty composite to hold checkboxs upon data-binding `selection`
33
+ }
34
+
35
+ def items=(text_array)
36
+ selection_value = selection
37
+ @items = Array[*text_array]
38
+ build_checkboxes
39
+ end
40
+
41
+ def items
42
+ @items || []
43
+ end
44
+
45
+ def selection=(selection_texts)
46
+ items.count.times do |index|
47
+ checkbox = checkboxes[index]
48
+ item = items[index]
49
+ label_text = labels[index]&.text
50
+ checkbox.selection = selection_texts.to_a.include?(label_text)
51
+ end
52
+ selection_texts
53
+ end
54
+
55
+ def selection
56
+ selection_indices.map do |selection_index|
57
+ labels[selection_index]&.text
58
+ end
59
+ end
60
+
61
+ def selection_indices=(indices)
62
+ self.selection=(indices.to_a.map {|index| items[index]})
63
+ end
64
+ alias select selection_indices=
65
+
66
+ def selection_indices
67
+ checkboxes.each_with_index.map do |checkbox, index|
68
+ index if checkbox.selection
69
+ end.to_a.compact
70
+ end
71
+
72
+ def checkboxes
73
+ @checkboxes ||= []
74
+ end
75
+ alias checks checkboxes
76
+
77
+ def labels
78
+ @labels ||= []
79
+ end
80
+
81
+ def can_handle_observation_request?(observation_request)
82
+ checkboxes.first&.can_handle_observation_request?(observation_request) || super(observation_request)
83
+ end
84
+
85
+ def handle_observation_request(observation_request, &block)
86
+ observation_requests << [observation_request, block]
87
+ delegate_observation_request_to_checkboxes(observation_request, &block)
88
+ super
89
+ end
90
+
91
+ def delegate_observation_request_to_checkboxes(observation_request, &block)
92
+ if observation_request != 'on_widget_disposed'
93
+ checkboxes.count.times do |index|
94
+ checkbox = checkboxes[index]
95
+ label = labels[index]
96
+ listener_block = lambda do |event|
97
+ event.widget = self.swt_widget
98
+ block.call(event)
99
+ end
100
+ if observation_request == 'on_widget_selected'
101
+ checkbox.handle_observation_request(observation_request, &listener_block) if checkbox.can_handle_observation_request?(observation_request)
102
+ label.handle_observation_request('on_mouse_up', &listener_block)
103
+ else
104
+ checkbox.handle_observation_request(observation_request, &listener_block) if checkbox.can_handle_observation_request?(observation_request)
105
+ label.handle_observation_request(observation_request, &listener_block) if label.can_handle_observation_request?(observation_request)
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ def observation_requests
112
+ @observation_requests ||= Set.new
113
+ end
114
+
115
+ def has_attribute?(attribute_name, *args)
116
+ (@composites.to_a + @checkboxes.to_a + @labels.to_a).map do |widget_proxy|
117
+ return true if widget_proxy.has_attribute?(attribute_name, *args)
118
+ end
119
+ super
120
+ end
121
+
122
+ def set_attribute(attribute_name, *args)
123
+ excluded_attributes = ['selection']
124
+ unless excluded_attributes.include?(attribute_name.to_s)
125
+ (@composites.to_a + @checkboxes.to_a + @labels.to_a).each do |widget_proxy|
126
+ widget_proxy.set_attribute(attribute_name, *args) if widget_proxy.has_attribute?(attribute_name, *args)
127
+ end
128
+ end
129
+ super
130
+ end
131
+
132
+ private
133
+
134
+ def build_checkboxes
135
+ current_selection = selection
136
+ @composites.to_a.each(&:dispose)
137
+ @checkboxes = []
138
+ @labels = []
139
+ @composites = []
140
+ items.each do |item|
141
+ body_root.content {
142
+ @composites << composite {
143
+ grid_layout(2, false) {
144
+ margin_width 0
145
+ margin_height 0
146
+ horizontal_spacing 0
147
+ vertical_spacing 0
148
+ }
149
+ checkboxes << checkbox { |checkbox_proxy|
150
+ on_widget_selected {
151
+ self.selection_indices = checkboxes.each_with_index.map {|cb, i| i if cb.selection}.to_a.compact
152
+ }
153
+ }
154
+ labels << label { |label_proxy|
155
+ layout_data :fill, :center, true, false
156
+ text item
157
+ on_mouse_up { |event|
158
+ found_text = labels.each_with_index.detect {|l, i| event.widget == l.swt_widget}[0]&.text
159
+ selection_values = self.selection
160
+ if selection_values.include?(found_text)
161
+ selection_values.delete(found_text)
162
+ else
163
+ selection_values << found_text
164
+ end
165
+ self.selection = selection_values
166
+ }
167
+ }
168
+ }
169
+ }
170
+ end
171
+ observation_requests.to_a.each do |observation_request, block|
172
+ delegate_observation_request_to_checkboxes(observation_request, &block)
173
+ end
174
+ self.selection = current_selection
175
+ end
176
+ end
177
+
178
+ CheckGroup = CheckboxGroup
179
+ end
180
+ end
181
+ end