glimmer-dsl-swt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +20 -0
  3. data/README.md +47 -0
  4. data/RUBY_VERSION +1 -0
  5. data/VERSION +1 -0
  6. data/bin/girb +10 -0
  7. data/bin/girb_runner.rb +13 -0
  8. data/bin/glimmer +5 -0
  9. data/icons/scaffold_app.icns +0 -0
  10. data/lib/ext/glimmer.rb +13 -0
  11. data/lib/ext/glimmer/config.rb +18 -0
  12. data/lib/glimmer-dsl-swt.rb +12 -0
  13. data/lib/glimmer/data_binding/list_selection_binding.rb +52 -0
  14. data/lib/glimmer/data_binding/model_binding.rb +248 -0
  15. data/lib/glimmer/data_binding/observable.rb +21 -0
  16. data/lib/glimmer/data_binding/observable_array.rb +107 -0
  17. data/lib/glimmer/data_binding/observable_model.rb +108 -0
  18. data/lib/glimmer/data_binding/observable_widget.rb +17 -0
  19. data/lib/glimmer/data_binding/observer.rb +124 -0
  20. data/lib/glimmer/data_binding/shine.rb +23 -0
  21. data/lib/glimmer/data_binding/table_items_binding.rb +56 -0
  22. data/lib/glimmer/data_binding/tree_items_binding.rb +71 -0
  23. data/lib/glimmer/data_binding/widget_binding.rb +33 -0
  24. data/lib/glimmer/dsl/swt/async_exec_expression.rb +14 -0
  25. data/lib/glimmer/dsl/swt/bind_expression.rb +37 -0
  26. data/lib/glimmer/dsl/swt/color_expression.rb +19 -0
  27. data/lib/glimmer/dsl/swt/column_properties_expression.rb +24 -0
  28. data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +42 -0
  29. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +39 -0
  30. data/lib/glimmer/dsl/swt/data_binding_expression.rb +34 -0
  31. data/lib/glimmer/dsl/swt/dialog_expression.rb +26 -0
  32. data/lib/glimmer/dsl/swt/display_expression.rb +19 -0
  33. data/lib/glimmer/dsl/swt/dsl.rb +34 -0
  34. data/lib/glimmer/dsl/swt/exec_expression.rb +28 -0
  35. data/lib/glimmer/dsl/swt/layout_data_expression.rb +25 -0
  36. data/lib/glimmer/dsl/swt/layout_expression.rb +27 -0
  37. data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +44 -0
  38. data/lib/glimmer/dsl/swt/menu_bar_expression.rb +33 -0
  39. data/lib/glimmer/dsl/swt/menu_expression.rb +32 -0
  40. data/lib/glimmer/dsl/swt/message_box_expression.rb +29 -0
  41. data/lib/glimmer/dsl/swt/observe_expression.rb +32 -0
  42. data/lib/glimmer/dsl/swt/property_expression.rb +22 -0
  43. data/lib/glimmer/dsl/swt/rgb_expression.rb +12 -0
  44. data/lib/glimmer/dsl/swt/rgba_expression.rb +12 -0
  45. data/lib/glimmer/dsl/swt/shell_expression.rb +25 -0
  46. data/lib/glimmer/dsl/swt/swt_expression.rb +25 -0
  47. data/lib/glimmer/dsl/swt/sync_exec_expression.rb +15 -0
  48. data/lib/glimmer/dsl/swt/tab_item_expression.rb +33 -0
  49. data/lib/glimmer/dsl/swt/table_items_data_binding_expression.rb +31 -0
  50. data/lib/glimmer/dsl/swt/tree_items_data_binding_expression.rb +31 -0
  51. data/lib/glimmer/dsl/swt/tree_properties_expression.rb +26 -0
  52. data/lib/glimmer/dsl/swt/widget_expression.rb +35 -0
  53. data/lib/glimmer/dsl/swt/widget_listener_expression.rb +32 -0
  54. data/lib/glimmer/launcher.rb +196 -0
  55. data/lib/glimmer/package.rb +57 -0
  56. data/lib/glimmer/rake_task.rb +62 -0
  57. data/lib/glimmer/scaffold.rb +582 -0
  58. data/lib/glimmer/swt/color_proxy.rb +53 -0
  59. data/lib/glimmer/swt/display_proxy.rb +88 -0
  60. data/lib/glimmer/swt/font_proxy.rb +72 -0
  61. data/lib/glimmer/swt/layout_data_proxy.rb +84 -0
  62. data/lib/glimmer/swt/layout_proxy.rb +82 -0
  63. data/lib/glimmer/swt/menu_proxy.rb +101 -0
  64. data/lib/glimmer/swt/message_box_proxy.rb +48 -0
  65. data/lib/glimmer/swt/packages.rb +13 -0
  66. data/lib/glimmer/swt/shell_proxy.rb +152 -0
  67. data/lib/glimmer/swt/swt_proxy.rb +106 -0
  68. data/lib/glimmer/swt/tab_item_proxy.rb +65 -0
  69. data/lib/glimmer/swt/table_proxy.rb +150 -0
  70. data/lib/glimmer/swt/tree_proxy.rb +120 -0
  71. data/lib/glimmer/swt/widget_listener_proxy.rb +34 -0
  72. data/lib/glimmer/swt/widget_proxy.rb +489 -0
  73. data/lib/glimmer/ui/custom_shell.rb +45 -0
  74. data/lib/glimmer/ui/custom_widget.rb +244 -0
  75. data/lib/glimmer/util/proc_tracker.rb +16 -0
  76. data/vendor/swt/linux/swt.jar +0 -0
  77. data/vendor/swt/mac/swt.jar +0 -0
  78. data/vendor/swt/windows/swt.jar +0 -0
  79. metadata +307 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d7caca40c9a1207a97846a5c5511fe24a07f4689979e57d54c395a33b3b341ba
4
+ data.tar.gz: 4b41ad30f7e63cd67bc87e88668cfb7f5b2d49b3d4cb7081bcfa04b6dcfefa90
5
+ SHA512:
6
+ metadata.gz: 2f41fda28c273df8bb93810f68c7841f60346b3469b7afeea9992bdf34f06dae28912af64dcce1ebcc6604832383de7a3082d3f4fe7238d5fa6563476792246d
7
+ data.tar.gz: 92e0b7e06ebcf4e7af47bfbc22189449d5161ebda431bd4be5973c4447ba622bac139bf31d4cbaaf5e92658d6695a49e522086e54f8a4303cd394fd9bdef2e65
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2020 Andy Maleh
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # Glimmer DSL for SWT 0.1.0 (Desktop GUI)
2
+ [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
3
+ [![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
4
+
5
+ [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for SWT enables desktop development with Glimmer.
6
+
7
+ You may find full setup/usage instructions at the main Glimmer project page:
8
+ [https://github.com/AndyObtiva/glimmer](https://github.com/AndyObtiva/glimmer)
9
+
10
+ ## Help
11
+
12
+ ### Issues
13
+
14
+ You may submit [issues](https://github.com/AndyObtiva/glimmer/issues) on [GitHub](https://github.com/AndyObtiva/glimmer/issues).
15
+
16
+ [Click here to submit an issue.](https://github.com/AndyObtiva/glimmer/issues)
17
+
18
+ ### IRC Channel
19
+
20
+ If you need live help, try the [#glimmer](http://widget.mibbit.com/?settings=7514b8a196f8f1de939a351245db7aa8&server=irc.mibbit.net&channel=%23glimmer) IRC channel on [irc.mibbit.net](http://widget.mibbit.com/?settings=7514b8a196f8f1de939a351245db7aa8&server=irc.mibbit.net&channel=%23glimmer). If no one was available, you may [leave a GitHub issue](https://github.com/AndyObtiva/glimmer/issues) to schedule a meetup on IRC.
21
+
22
+ [Click here to connect to #glimmer IRC channel immediately via a web interface.](http://widget.mibbit.com/?settings=7514b8a196f8f1de939a351245db7aa8&server=irc.mibbit.net&channel=%23glimmer)
23
+
24
+ ## Feature Suggestions
25
+
26
+ These features have been suggested. You might see them in a future version of Glimmer. You are welcome to contribute more feature suggestions.
27
+
28
+ [TODO.md](TODO.md)
29
+
30
+ ## Change Log
31
+
32
+ [CHANGELOG.md](CHANGELOG.md)
33
+
34
+ ## Contributing
35
+
36
+ [CONTRIBUTING.md](CONTRIBUTING.md)
37
+
38
+ ## Contributors
39
+
40
+ * [Andy Maleh](https://github.com/AndyObtiva) (Founder)
41
+
42
+ [Click here to view contributor commits.](https://github.com/AndyObtiva/glimmer-dsl-swt/graphs/contributors)
43
+
44
+ ## License
45
+
46
+ Copyright (c) 2020 Andy Maleh.
47
+ See LICENSE.txt for further details.
@@ -0,0 +1 @@
1
+ jruby-9.2.11.1
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ trap "SIGINT" do
4
+ # No Op for irb
5
+ end
6
+
7
+ require_relative '../lib/glimmer/launcher'
8
+
9
+ girb_runner = File.expand_path('../girb_runner.rb', __FILE__)
10
+ Glimmer::Launcher.new(["irb -r #{girb_runner}"] + ARGV).launch
@@ -0,0 +1,13 @@
1
+ require 'puts_debuggerer'
2
+
3
+ include Glimmer
4
+
5
+ # Hijack Shell#start_event_loop default behavior to ensure disposing a display upon closing a shell inside girb
6
+
7
+ Glimmer::SWT::ShellProxy.class_eval do
8
+ alias start_event_loop_original start_event_loop
9
+ def start_event_loop
10
+ start_event_loop_original
11
+ Glimmer::SWT::DisplayProxy.instance.dispose
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/glimmer/launcher'
4
+
5
+ Glimmer::Launcher.new(ARGV).launch
Binary file
@@ -0,0 +1,13 @@
1
+ require 'glimmer/swt/packages'
2
+
3
+ module Glimmer
4
+ class << self
5
+ def included(klass)
6
+ if Config.import_swt_packages
7
+ klass.include(SWT::Packages)
8
+ klass.extend(SWT::Packages)
9
+ klass.extend(Glimmer)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ module Glimmer
2
+ module Config
3
+ class << self
4
+ # Tells Glimmer to import SWT packages into including class (default: true)
5
+ def import_swt_packages=(value)
6
+ @@import_swt_packages = !!value
7
+ end
8
+
9
+ # Returns whether Glimmer will import SWT packages into including class
10
+ def import_swt_packages
11
+ unless defined? @@import_swt_packages
12
+ @@import_swt_packages = true
13
+ end
14
+ @@import_swt_packages
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
2
+
3
+ # External requires
4
+ require 'java'
5
+ require 'nested_inherited_jruby_include_package'
6
+ require 'super_module'
7
+ require 'glimmer'
8
+
9
+ # Internal requires
10
+ require 'ext/glimmer/config'
11
+ require 'ext/glimmer'
12
+ require 'glimmer/dsl/swt/dsl'
@@ -0,0 +1,52 @@
1
+ require 'glimmer'
2
+ require 'glimmer/data_binding/observable'
3
+ require 'glimmer/data_binding/observer'
4
+
5
+ module Glimmer
6
+ module DataBinding
7
+ # SWT List widget selection binding
8
+ class ListSelectionBinding
9
+ include Glimmer
10
+ include Observable
11
+ include Observer
12
+
13
+ attr_reader :widget_proxy
14
+
15
+ PROPERTY_TYPE_UPDATERS = {
16
+ :string => lambda { |widget_proxy, value| widget_proxy.swt_widget.select(widget_proxy.swt_widget.index_of(value.to_s)) },
17
+ :array => lambda { |widget_proxy, value| widget_proxy.swt_widget.selection=(value || []).to_java(:string) }
18
+ }
19
+
20
+ PROPERTY_EVALUATORS = {
21
+ :string => lambda do |selection_array|
22
+ return nil if selection_array.empty?
23
+ selection_array[0]
24
+ end,
25
+ :array => lambda do |selection_array|
26
+ selection_array
27
+ end
28
+ }
29
+
30
+ # Initialize with list widget and property_type
31
+ # property_type :string represents default list single selection
32
+ # property_type :array represents list multi selection
33
+ def initialize(widget_proxy, property_type)
34
+ property_type = :string if property_type.nil? or property_type == :undefined
35
+ @widget_proxy = widget_proxy
36
+ @property_type = property_type
37
+ @widget_proxy.on_widget_disposed do |dispose_event|
38
+ unregister_all_observables
39
+ end
40
+ end
41
+
42
+ def call(value)
43
+ PROPERTY_TYPE_UPDATERS[@property_type].call(@widget_proxy, value) unless evaluate_property == value
44
+ end
45
+
46
+ def evaluate_property
47
+ selection_array = @widget_proxy.swt_widget.send('selection').to_a #TODO refactor send('selection') into proper method invocation
48
+ PROPERTY_EVALUATORS[@property_type].call(selection_array)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,248 @@
1
+ require 'glimmer/data_binding/observable'
2
+ require 'glimmer/data_binding/observer'
3
+
4
+ module Glimmer
5
+ module DataBinding
6
+ class ModelBinding
7
+ include Observable
8
+ include Observer
9
+
10
+ attr_reader :binding_options
11
+
12
+ def initialize(base_model, property_name_expression, binding_options = nil)
13
+ @base_model = base_model
14
+ @property_name_expression = property_name_expression
15
+ @binding_options = binding_options || {}
16
+ if computed?
17
+ @computed_model_bindings = computed_by.map do |computed_by_property_expression|
18
+ self.class.new(base_model, computed_by_property_expression)
19
+ end
20
+ end
21
+ end
22
+
23
+ def model
24
+ nested_property? ? nested_model : base_model
25
+ end
26
+
27
+ # e.g. person.address.state returns [person, person.address]
28
+ def nested_models
29
+ @nested_models = [base_model]
30
+ model_property_names.reduce(base_model) do |reduced_model, nested_model_property_name|
31
+ if reduced_model.nil?
32
+ nil
33
+ else
34
+ invoke_property_reader(reduced_model, nested_model_property_name).tap do |new_reduced_model|
35
+ @nested_models << new_reduced_model
36
+ end
37
+ end
38
+ end
39
+ @nested_models
40
+ end
41
+
42
+ def nested_model
43
+ nested_models.last
44
+ end
45
+
46
+ def base_model
47
+ @base_model
48
+ end
49
+
50
+ def property_name
51
+ nested_property? ? nested_property_name : property_name_expression
52
+ end
53
+
54
+ def convert_on_read(value)
55
+ apply_converter(@binding_options[:on_read], value)
56
+ end
57
+
58
+ def convert_on_write(value)
59
+ apply_converter(@binding_options[:on_write], value)
60
+ end
61
+
62
+ def apply_converter(converter, value)
63
+ if converter.nil?
64
+ value
65
+ elsif converter.is_a?(String) || converter.is_a?(Symbol)
66
+ if value.respond_to?(converter)
67
+ value.send(converter)
68
+ else
69
+ raise Glimmer::Error, "Unsupported bind converter: #{converter.inspect}"
70
+ end
71
+ elsif converter.respond_to?(:call, value)
72
+ converter.call(value)
73
+ else
74
+ raise Glimmer::Error, "Unsupported bind converter: #{converter.inspect}"
75
+ end
76
+ end
77
+
78
+ # All nested property names
79
+ # e.g. property name expression "address.state" gives ['address', 'state']
80
+ # If there are any indexed property names, this returns indexes as properties.
81
+ # e.g. property name expression "addresses[1].state" gives ['addresses', '[1]', 'state']
82
+ def nested_property_names
83
+ @nested_property_names ||= property_name_expression.split(".").map {|pne| pne.match(/([^\[]+)(\[[^\]]+\])?/).to_a.drop(1)}.flatten.compact
84
+ end
85
+
86
+ # Final nested property name
87
+ # e.g. property name expression "address.state" gives :state
88
+ def nested_property_name
89
+ nested_property_names.last
90
+ end
91
+
92
+ # Model representing nested property names
93
+ # e.g. property name expression "address.state" gives [:address]
94
+ def model_property_names
95
+ nested_property_names[0...-1]
96
+ end
97
+
98
+ def nested_property?
99
+ property_name_expression.match(/[.\[]/)
100
+ end
101
+
102
+ def property_name_expression
103
+ @property_name_expression
104
+ end
105
+
106
+ def computed?
107
+ !computed_by.empty?
108
+ end
109
+
110
+ def computed_by
111
+ [@binding_options[:computed_by]].flatten.compact
112
+ end
113
+
114
+ def nested_property_observers_for(observer)
115
+ @nested_property_observers_collection ||= {}
116
+ unless @nested_property_observers_collection.has_key?(observer)
117
+ @nested_property_observers_collection[observer] = nested_property_names.reduce({}) do |output, property_name|
118
+ output.merge(
119
+ property_name => Observer.proc do |new_value|
120
+ # Ensure reattaching observers when a higher level nested property is updated (e.g. person.address changes reattaches person.address.street observer)
121
+ add_observer(observer)
122
+ observer.call(evaluate_property)
123
+ end
124
+ )
125
+ end
126
+ end
127
+ @nested_property_observers_collection[observer]
128
+ end
129
+
130
+ def add_observer(observer)
131
+ if computed?
132
+ add_computed_observers(observer)
133
+ elsif nested_property?
134
+ add_nested_observers(observer)
135
+ else
136
+ model_binding_observer = Observer.proc do |new_value|
137
+ observer.call(evaluate_property)
138
+ end
139
+ observer_registration = model_binding_observer.observe(model, property_name)
140
+ my_registration = observer.registration_for(self)
141
+ observer.add_dependent(my_registration => observer_registration)
142
+ end
143
+ end
144
+
145
+ def remove_observer(observer)
146
+ if computed?
147
+ @computed_model_bindings.each do |computed_model_binding|
148
+ computed_observer_for(observer).unobserve(computed_model_binding)
149
+ end
150
+ @computed_observer_collection.delete(observer)
151
+ elsif nested_property?
152
+ nested_property_observers_for(observer).clear
153
+ else
154
+ observer.unobserve(model, property_name)
155
+ end
156
+ end
157
+
158
+ def computed_observer_for(observer)
159
+ @computed_observer_collection ||= {}
160
+ unless @computed_observer_collection.has_key?(observer)
161
+ @computed_observer_collection[observer] = Observer.proc do |new_value|
162
+ observer.call(evaluate_property)
163
+ end
164
+ end
165
+ @computed_observer_collection[observer]
166
+ end
167
+
168
+ def add_computed_observers(observer)
169
+ @computed_model_bindings.each do |computed_model_binding|
170
+ observer_registration = computed_observer_for(observer).observe(computed_model_binding)
171
+ my_registration = observer.registration_for(self)
172
+ observer.add_dependent(my_registration => observer_registration)
173
+ end
174
+ end
175
+
176
+ def add_nested_observers(observer)
177
+ nested_property_observers = nested_property_observers_for(observer)
178
+ nested_models.zip(nested_property_names).each_with_index do |zip, i|
179
+ model, property_name = zip
180
+ nested_property_observer = nested_property_observers[property_name]
181
+ previous_index = i - 1
182
+ parent_model = previous_index.negative? ? self : nested_models[previous_index]
183
+ parent_property_name = previous_index.negative? ? nil : nested_property_names[previous_index]
184
+ parent_observer = previous_index.negative? ? observer : nested_property_observers[parent_property_name]
185
+ parent_property_name = nil if parent_property_name.to_s.start_with?('[')
186
+ unless model.nil?
187
+ if property_indexed?(property_name)
188
+ # TODO figure out a way to deal with this more uniformly
189
+ observer_registration = nested_property_observer.observe(model)
190
+ else
191
+ observer_registration = nested_property_observer.observe(model, property_name)
192
+ end
193
+ parent_registration = parent_observer.registration_for(parent_model, parent_property_name)
194
+ parent_observer.add_dependent(parent_registration => observer_registration)
195
+ end
196
+ end
197
+ end
198
+
199
+ def call(value)
200
+ return if model.nil?
201
+ converted_value = value
202
+ invoke_property_writer(model, "#{property_name}=", converted_value) unless evaluate_property == converted_value
203
+ end
204
+
205
+ def evaluate_property
206
+ value = nil
207
+ value = invoke_property_reader(model, property_name) unless model.nil?
208
+ convert_on_read(value)
209
+ end
210
+
211
+ def evaluate_options_property
212
+ model.send(options_property_name) unless model.nil?
213
+ end
214
+
215
+ def options_property_name
216
+ self.property_name + "_options"
217
+ end
218
+
219
+ def property_indexed?(property_expression)
220
+ property_expression.to_s.start_with?('[')
221
+ end
222
+
223
+ def invoke_property_reader(object, property_expression)
224
+ if property_indexed?(property_expression)
225
+ property_method = '[]'
226
+ property_argument = property_expression[1...-1]
227
+ property_argument = property_argument.to_i if property_argument.match(/\d+/)
228
+ object.send(property_method, property_argument)
229
+ else
230
+ object.send(property_expression)
231
+ end
232
+ end
233
+
234
+ def invoke_property_writer(object, property_expression, value)
235
+ return if @binding_options[:read_only]
236
+ value = convert_on_write(value)
237
+ if property_indexed?(property_expression)
238
+ property_method = '[]='
239
+ property_argument = property_expression[1...-2]
240
+ property_argument = property_argument.to_i if property_argument.match(/\d+/)
241
+ object.send(property_method, property_argument, value)
242
+ else
243
+ object.send(property_expression, value)
244
+ end
245
+ end
246
+ end
247
+ end
248
+ end