glimmer-dsl-opal 0.5.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +53 -0
  3. data/README.md +438 -17
  4. data/VERSION +1 -1
  5. data/app/assets/images/glimmer/images/calendar.gif +0 -0
  6. data/app/assets/images/glimmer/images/ui-icons_222222_256x240.png +0 -0
  7. data/app/assets/images/glimmer/images/ui-icons_444444_256x240.png +0 -0
  8. data/app/assets/images/glimmer/images/ui-icons_555555_256x240.png +0 -0
  9. data/app/assets/images/glimmer/images/ui-icons_777620_256x240.png +0 -0
  10. data/app/assets/images/glimmer/images/ui-icons_777777_256x240.png +0 -0
  11. data/app/assets/images/glimmer/images/ui-icons_cc0000_256x240.png +0 -0
  12. data/app/assets/images/glimmer/images/ui-icons_ffffff_256x240.png +0 -0
  13. data/app/assets/stylesheets/glimmer/glimmer.css +15 -0
  14. data/app/assets/stylesheets/glimmer/jquery-ui.css +1312 -0
  15. data/app/assets/stylesheets/glimmer/jquery-ui.structure.css +886 -0
  16. data/app/assets/stylesheets/glimmer/jquery-ui.theme.css +443 -0
  17. data/app/assets/stylesheets/glimmer/jquery.ui.timepicker.css +57 -0
  18. data/lib/display.rb +31 -0
  19. data/lib/file.rb +29 -0
  20. data/lib/glimmer-dsl-opal.rb +40 -8
  21. data/lib/glimmer-dsl-opal/ext/date.rb +49 -3
  22. data/lib/glimmer-dsl-opal/ext/struct.rb +37 -0
  23. data/lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb +23 -0
  24. data/lib/glimmer-dsl-opal/samples/hello/hello_date_time.rb +63 -0
  25. data/lib/glimmer-dsl-opal/samples/hello/hello_table.rb +283 -0
  26. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/GPL-LICENSE.txt +278 -0
  27. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/MIT-LICENSE.txt +20 -0
  28. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/jquery.ui.timepicker.css +57 -0
  29. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/jquery.ui.timepicker.js +1496 -0
  30. data/lib/glimmer-dsl-opal/vendor/jquery-ui/AUTHORS.txt +333 -0
  31. data/lib/glimmer-dsl-opal/vendor/jquery-ui/LICENSE.txt +43 -0
  32. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_444444_256x240.png +0 -0
  33. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_555555_256x240.png +0 -0
  34. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_777620_256x240.png +0 -0
  35. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_777777_256x240.png +0 -0
  36. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_cc0000_256x240.png +0 -0
  37. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_ffffff_256x240.png +0 -0
  38. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.min.css +7 -0
  39. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.min.js +13 -0
  40. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.structure.min.css +5 -0
  41. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.theme.min.css +5 -0
  42. data/lib/glimmer-dsl-opal/vendor/jquery-ui/package.json +74 -0
  43. data/lib/glimmer-dsl-swt.rb +20 -35
  44. data/lib/glimmer/data_binding/table_items_binding.rb +32 -19
  45. data/lib/glimmer/dsl/opal/block_property_expression.rb +41 -0
  46. data/lib/glimmer/dsl/opal/custom_widget_expression.rb +1 -1
  47. data/lib/glimmer/dsl/opal/dsl.rb +2 -0
  48. data/lib/glimmer/dsl/opal/shell_expression.rb +7 -2
  49. data/lib/glimmer/dsl/opal/widget_expression.rb +10 -1
  50. data/lib/glimmer/engine.rb +9 -0
  51. data/lib/glimmer/swt.rb +3 -3
  52. data/lib/glimmer/swt/button_proxy.rb +5 -5
  53. data/lib/glimmer/swt/checkbox_proxy.rb +1 -0
  54. data/lib/glimmer/swt/color_proxy.rb +45 -45
  55. data/lib/glimmer/swt/combo_proxy.rb +42 -3
  56. data/lib/glimmer/swt/composite_proxy.rb +7 -3
  57. data/lib/glimmer/swt/control_editor.rb +54 -0
  58. data/lib/glimmer/swt/date_time_proxy.rb +209 -0
  59. data/lib/glimmer/swt/display_proxy.rb +6 -2
  60. data/lib/glimmer/swt/fill_layout_proxy.rb +1 -1
  61. data/lib/glimmer/swt/label_proxy.rb +2 -2
  62. data/lib/glimmer/swt/layout_data_proxy.rb +13 -10
  63. data/lib/glimmer/swt/layout_proxy.rb +5 -5
  64. data/lib/glimmer/swt/list_proxy.rb +2 -2
  65. data/lib/glimmer/swt/make_shift_shell_proxy.rb +4 -4
  66. data/lib/glimmer/swt/message_box_proxy.rb +10 -8
  67. data/lib/glimmer/swt/property_owner.rb +2 -2
  68. data/lib/glimmer/swt/radio_proxy.rb +1 -0
  69. data/lib/glimmer/swt/shell_proxy.rb +8 -0
  70. data/lib/glimmer/swt/tab_folder_proxy.rb +5 -5
  71. data/lib/glimmer/swt/tab_item_proxy.rb +7 -7
  72. data/lib/glimmer/swt/table_column_proxy.rb +71 -12
  73. data/lib/glimmer/swt/table_editor.rb +65 -0
  74. data/lib/glimmer/swt/table_item_proxy.rb +50 -7
  75. data/lib/glimmer/swt/table_proxy.rb +595 -22
  76. data/lib/glimmer/swt/text_proxy.rb +51 -3
  77. data/lib/glimmer/swt/widget_proxy.rb +141 -27
  78. data/lib/glimmer/ui/custom_widget.rb +8 -8
  79. data/lib/net/http.rb +1 -5
  80. data/lib/os.rb +36 -0
  81. data/lib/uri.rb +3 -3
  82. metadata +49 -9
  83. data/lib/glimmer/data_binding/ext/observable_model.rb +0 -40
@@ -7,8 +7,8 @@ module Glimmer
7
7
  include Glimmer::DataBinding::ObservableElement
8
8
  attr_reader :text, :items
9
9
 
10
- def initialize(parent, args)
11
- super(parent, args)
10
+ def initialize(parent, args, block)
11
+ super(parent, args, block)
12
12
  @items = []
13
13
  end
14
14
 
@@ -45,7 +45,46 @@ module Glimmer
45
45
  event_listener.call(event)
46
46
  }
47
47
  }
48
- }
48
+ },
49
+ 'on_key_pressed' => {
50
+ event: 'keydown',
51
+ event_handler: -> (event_listener) {
52
+ -> (event) {
53
+ @last_key_pressed_event = event
54
+ @text = event.target.value
55
+ # TODO generalize this solution to all widgets that support key presses
56
+ # TODO support event.location once DOM3 is supported by opal-jquery
57
+ event.define_singleton_method(:keyCode) {event.which}
58
+ event.define_singleton_method(:key_code, &event.method(:keyCode))
59
+ event.define_singleton_method(:character) {event.which.chr}
60
+ event.define_singleton_method(:stateMask) do
61
+ state_mask = 0
62
+ state_mask |= SWTProxy[:alt] if event.alt_key
63
+ state_mask |= SWTProxy[:ctrl] if event.ctrl_key
64
+ state_mask |= SWTProxy[:shift] if event.shift_key
65
+ state_mask |= SWTProxy[:command] if event.meta_key
66
+ state_mask
67
+ end
68
+ event.define_singleton_method(:state_mask, &event.method(:stateMask))
69
+ doit = true
70
+ event.define_singleton_method(:doit=) do |value|
71
+ doit = value
72
+ end
73
+ event.define_singleton_method(:doit) { doit }
74
+ event_listener.call(event)
75
+
76
+ # TODO Fix doit false, it's not stopping input
77
+ unless doit
78
+ event.prevent
79
+ event.prevent_default
80
+ event.stop_propagation
81
+ event.stop_immediate_propagation
82
+ end
83
+
84
+ doit
85
+ }
86
+ }
87
+ },
49
88
  }
50
89
  end
51
90
 
@@ -6,9 +6,13 @@ module Glimmer
6
6
  class CompositeProxy < WidgetProxy
7
7
  attr_reader :layout
8
8
 
9
- def initialize(parent, args)
10
- super(parent, args)
11
- @layout = GridLayoutProxy.new(self, [])
9
+ def initialize(parent, args, block)
10
+ super(parent, args, block)
11
+ @layout = default_layout
12
+ end
13
+
14
+ def default_layout
15
+ GridLayoutProxy.new(self, [])
12
16
  end
13
17
 
14
18
  def dom
@@ -0,0 +1,54 @@
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.
21
+
22
+ module Glimmer
23
+ module SWT
24
+ # Emulates SWT's native org.eclipse.swt.custom.ControlEditor
25
+ class ControlEditor
26
+ # TODO implement behavior for all these attributes
27
+ ATTRIBUTES = [:grabHorizontal, :grabVertical, :horizontalAlignment, :verticalAlignment, :minimumWidth, :minimumHeight]
28
+ attr_accessor(*ATTRIBUTES)
29
+ ATTRIBUTES.each do |attribute|
30
+ alias_method attribute.underscore, attribute
31
+ alias_method "#{attribute.underscore}=", "#{attribute}="
32
+ end
33
+
34
+ # TODO consider supporting a java_attr_accessor to get around having to generate all the aliases manually
35
+ attr_accessor :editor
36
+ alias getEditor editor
37
+ alias get_editor editor
38
+ alias setEditor editor=
39
+ alias set_editor editor=
40
+
41
+ # TODO implement `#layout` method if needed
42
+
43
+ attr_reader :composite
44
+
45
+ def initialize(composite)
46
+ @composite = composite
47
+ end
48
+
49
+ # TODO implement showing editor for composite or canvas
50
+ # def editor=(widget)
51
+ # end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,209 @@
1
+ require 'glimmer/swt/widget_proxy'
2
+
3
+ module Glimmer
4
+ module SWT
5
+ class DateTimeProxy < WidgetProxy
6
+ class << self
7
+ def create(keyword, parent, args, block)
8
+ case keyword
9
+ when 'date'
10
+ args += [:date]
11
+ when 'date_drop_down'
12
+ args += [:date, :drop_down]
13
+ when 'time'
14
+ args += [:time]
15
+ when 'calendar'
16
+ args += [:calendar]
17
+ end
18
+ new(parent, args, block)
19
+ end
20
+ end
21
+
22
+ def initialize(parent, args, block)
23
+ super(parent, args, block)
24
+ post_add_content if block.nil?
25
+ end
26
+
27
+ def post_add_content
28
+ # TODO handle date_drop_down version
29
+ if time?
30
+ dom_element.timepicker({
31
+ showPeriod: true,
32
+ showLeadingZero: true,
33
+ showOn: 'both',
34
+ showNowButton: true,
35
+ showCloseButton: true,
36
+ button: "##{time_button_id}",
37
+ onClose: ->(v) {
38
+ @timepicker_done = true
39
+ dom_element.trigger('change')
40
+ },
41
+ })
42
+ else
43
+ options = {}
44
+ if drop_down?
45
+ options = {
46
+ showOn: 'both',
47
+ buttonImage: 'assets/glimmer/images/calendar.gif',
48
+ buttonImageOnly: true,
49
+ buttonText: 'Select date'
50
+ }
51
+ end
52
+ dom_element.datepicker(options)
53
+ end
54
+ date_time_value = self.date_time
55
+ @added_content = true
56
+ self.date_time = date_time_value
57
+ end
58
+
59
+ def date?
60
+ args.to_a.include?(:date)
61
+ end
62
+
63
+ def time?
64
+ args.to_a.include?(:time)
65
+ end
66
+
67
+ def drop_down?
68
+ args.to_a.include?(:drop_down)
69
+ end
70
+
71
+ def calendar?
72
+ args.to_a.include?(:calendar)
73
+ end
74
+
75
+ def date_time
76
+ if @added_content
77
+ default_date = DateTime.new if @date_time.nil?
78
+ default_year = @date_time&.year || default_date.year
79
+ default_month = @date_time&.month || default_date.month
80
+ default_day = @date_time&.day || default_date.day
81
+ default_hour = @date_time&.hour || default_date.hour
82
+ default_min = @date_time&.min || default_date.min
83
+ default_sec = @date_time&.sec || default_date.sec
84
+ if time?
85
+ @date_time = DateTime.new(default_year, default_month, default_day, dom_element.timepicker('getHour').to_i, dom_element.timepicker('getMinute').to_i, default_sec)
86
+ else
87
+ @date_time = DateTime.new(dom_element.datepicker('getDate')&.year.to_i, dom_element.datepicker('getDate')&.month.to_i, dom_element.datepicker('getDate')&.day.to_i, default_hour, default_min, default_sec)
88
+ end
89
+ @date_time = @date_time&.to_datetime
90
+ else
91
+ @initial_date_time
92
+ end
93
+ end
94
+
95
+ def date_time=(value)
96
+ if @added_content
97
+ @date_time = value&.to_datetime || DateTime.new
98
+ if time?
99
+ dom_element.timepicker('setTime', "#{@date_time.hour}:#{@date_time.min}")
100
+ else
101
+ dom_element.datepicker('setDate', @date_time.to_time)
102
+ end
103
+ else
104
+ @initial_date_time = value
105
+ end
106
+ end
107
+
108
+ # TODO add date, time, year, month, day, hours, minutes, seconds attribute methods
109
+
110
+ def observation_request_to_event_mapping
111
+ {
112
+ 'on_widget_selected' => [
113
+ {
114
+ event: 'change',
115
+ event_handler: -> (event_listener) {
116
+ -> (event) {
117
+ if @timepicker_done
118
+ @timepicker_done = false
119
+ event_listener.call(event)
120
+ end
121
+ }
122
+ }
123
+ },
124
+ ],
125
+ 'on_focus_lost' => [
126
+ {
127
+ event: 'blur',
128
+ event_handler: -> (event_listener) {
129
+ -> (event) {
130
+ if @timepicker_done
131
+ @timepicker_done = false
132
+ event_listener.call(event)
133
+ end
134
+ }
135
+ }
136
+ },
137
+ ],
138
+ 'on_key_pressed' => {
139
+ event: 'keydown',
140
+ event_handler: -> (event_listener) {
141
+ -> (event) {
142
+ # TODO generalize this solution to all widgets that support key presses
143
+ # TODO support event.location once DOM3 is supported by opal-jquery
144
+ event.define_singleton_method(:keyCode) {event.which}
145
+ event.define_singleton_method(:key_code, &event.method(:keyCode))
146
+ event.define_singleton_method(:character) {event.which.chr}
147
+ event.define_singleton_method(:stateMask) do
148
+ state_mask = 0
149
+ state_mask |= SWTProxy[:alt] if event.alt_key
150
+ state_mask |= SWTProxy[:ctrl] if event.ctrl_key
151
+ state_mask |= SWTProxy[:shift] if event.shift_key
152
+ state_mask |= SWTProxy[:command] if event.meta_key
153
+ state_mask
154
+ end
155
+ event.define_singleton_method(:state_mask, &event.method(:stateMask))
156
+ doit = true
157
+ event.define_singleton_method(:doit=) do |value|
158
+ doit = value
159
+ end
160
+ event.define_singleton_method(:doit) { doit }
161
+ event_listener.call(event)
162
+
163
+ # TODO Fix doit false, it's not stopping input
164
+ unless doit
165
+ event.prevent
166
+ event.prevent_default
167
+ event.stop_propagation
168
+ event.stop_immediate_propagation
169
+ end
170
+
171
+ doit
172
+ }
173
+ }
174
+ },
175
+ }
176
+ end
177
+
178
+ def time_button_id
179
+ "#{id}-time-button"
180
+ end
181
+
182
+ def time_button_class
183
+ "#{name}-time-button"
184
+ end
185
+
186
+ def element
187
+ calendar? ? 'div' : 'input'
188
+ end
189
+
190
+ def dom
191
+ @dom ||= html {
192
+ span {
193
+ send(element, type: 'text', id: id, class: name)
194
+ button(id: time_button_id, class: time_button_class, style: "border: none; background: url(assets/glimmer/images/ui-icons_222222_256x240.png) -80px, -96px; width: 16px; height: 16px;") if time?
195
+ }
196
+ }.to_s
197
+ end
198
+
199
+ end
200
+
201
+ # Aliases: `date`, `date_drop_down`, `time`, and `calendar`
202
+ DateProxy = DateTimeProxy
203
+ DateDropDownProxy = DateTimeProxy
204
+ TimeProxy = DateTimeProxy
205
+ CalendarProxy = DateTimeProxy
206
+
207
+ end
208
+
209
+ end
@@ -24,6 +24,10 @@ module Glimmer
24
24
  Document
25
25
  end
26
26
 
27
+ def shells
28
+ @shells ||= []
29
+ end
30
+
27
31
  def render
28
32
  # No rendering as body is rendered as part of ShellProxy.. this class only serves as an SWT Display utility
29
33
  end
@@ -66,10 +70,10 @@ module Glimmer
66
70
  event_listener.call(event) if event.key_code != 13 && (event.key_code == 127 || event.key_code <= 31)
67
71
  }
68
72
  }
69
- }
73
+ }
70
74
  ]
71
75
  }
72
- end
76
+ end
73
77
 
74
78
  def shells
75
79
  @shells ||= []
@@ -68,7 +68,7 @@ module Glimmer
68
68
  elsif vertical?
69
69
  margin_bottom "#{@spacing}px"
70
70
  end
71
- }
71
+ }
72
72
  s("##{@parent.id} > :last-child") {
73
73
  if horizontal?
74
74
  margin_right 0
@@ -6,8 +6,8 @@ module Glimmer
6
6
  class LabelProxy < WidgetProxy
7
7
  attr_reader :text, :background_image, :image, :alignment
8
8
 
9
- def initialize(parent, args)
10
- super(parent, args)
9
+ def initialize(parent, args, block)
10
+ super(parent, args, block)
11
11
  self.alignment = [:left, :center, :right].detect {|align| args.detect { |arg| SWTProxy[align] == arg } }
12
12
  end
13
13
 
@@ -3,15 +3,16 @@ require 'glimmer/swt/property_owner'
3
3
  module Glimmer
4
4
  module SWT
5
5
  class LayoutDataProxy
6
+ # TODO make this polymorphic as GridData or RowData subclasses
6
7
  include Glimmer::SWT::PropertyOwner
7
- attr_reader :parent,
8
- :args,
9
- :horizontal_alignment,
10
- :vertical_alignment,
11
- :horizontal_span,
12
- :vertical_span,
13
- :horizontal_indent,
14
- :vertical_indent,
8
+ attr_reader :parent,
9
+ :args,
10
+ :horizontal_alignment,
11
+ :vertical_alignment,
12
+ :horizontal_span,
13
+ :vertical_span,
14
+ :horizontal_indent,
15
+ :vertical_indent,
15
16
  :grab_excess_horizontal_space,
16
17
  :grab_excess_vertical_space,
17
18
  :width_hint,
@@ -48,6 +49,8 @@ module Glimmer
48
49
  @parent.dom_element.css('width', '100%') if width_hint.nil?
49
50
  else
50
51
  @parent.dom_element.css('text-align', @horizontal_alignment)
52
+ @parent.dom_element.css('margin-left', 'auto') if ['right', 'center'].include?(@horizontal_alignment.to_s)
53
+ @parent.dom_element.css('margin-right', 'auto') if ['left', 'center'].include?(@horizontal_alignment.to_s)
51
54
  end
52
55
  # TODO
53
56
  # reapply
@@ -85,13 +88,13 @@ module Glimmer
85
88
 
86
89
  def grab_excess_horizontal_space=(grab_excess_horizontal_space)
87
90
  @grab_excess_horizontal_space = grab_excess_horizontal_space
88
- @parent.dom_element.css('width', "100%") if @grab_excess_horizontal_space && width_hint.nil?
91
+ @parent.dom_element.css('width', "100%") if @grab_excess_horizontal_space && @horizontal_alignment == 'fill' && width_hint.nil?
89
92
  # reapply
90
93
  end
91
94
 
92
95
  def grab_excess_vertical_space=(grab_excess_vertical_space)
93
96
  @grab_excess_vertical_space = grab_excess_vertical_space
94
- @parent.dom_element.css('height', "100%") if @grab_excess_vertical_space && height_hint.nil?
97
+ @parent.dom_element.css('height', "100%") if @grab_excess_vertical_space && @vertical_alignment == 'fill' && height_hint.nil?
95
98
  # TODO
96
99
  # reapply
97
100
  end
@@ -18,28 +18,28 @@ module Glimmer
18
18
  a_layout_class = Glimmer::SWT.const_get(class_name_main.to_sym) rescue Glimmer::SWT.const_get(class_name_alternative.to_sym)
19
19
  a_layout_class if a_layout_class.ancestors.include?(Glimmer::SWT::LayoutProxy)
20
20
  rescue => e
21
- puts "Layout #{keyword} was not found!"
21
+ Glimmer::Config.logger.debug "Layout #{keyword} was not found!"
22
22
  nil
23
23
  end
24
24
 
25
25
  def layout_exists?(keyword)
26
26
  !!layout_class(keyword)
27
27
  end
28
- end
28
+ end
29
29
 
30
30
  attr_reader :parent, :args
31
31
 
32
- def initialize(parent, args)
32
+ def initialize(parent, args)
33
33
  @parent = parent
34
34
  @parent = parent.body_root if @parent.is_a?(Glimmer::UI::CustomWidget)
35
35
  @parent.css_classes.each do |css_class|
36
36
  @parent.remove_css_class(css_class) if css_class.include?('layout')
37
37
  end
38
- @args = args
38
+ @args = args
39
39
  @parent.add_css_class(css_class)
40
40
  @parent.layout = self
41
41
  self.margin_width = 15 if respond_to?(:margin_width=)
42
- self.margin_height = 15 if respond_to?(:margin_height=)
42
+ self.margin_height = 15 if respond_to?(:margin_height=)
43
43
  end
44
44
 
45
45
  def css_class