glimmer-dsl-opal 0.3.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +48 -0
  3. data/README.md +690 -24
  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/glimmer-dsl-opal.rb +22 -10
  19. data/lib/glimmer-dsl-opal/ext/date.rb +38 -3
  20. data/lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb +23 -0
  21. data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox.rb +85 -0
  22. data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox_group.rb +68 -0
  23. data/lib/glimmer-dsl-opal/samples/hello/hello_combo.rb +5 -5
  24. data/lib/glimmer-dsl-opal/samples/hello/hello_custom_widget.rb +3 -3
  25. data/lib/glimmer-dsl-opal/samples/hello/hello_date_time.rb +63 -0
  26. data/lib/glimmer-dsl-opal/samples/hello/hello_group.rb +104 -0
  27. data/lib/glimmer-dsl-opal/samples/hello/hello_list_single_selection.rb +1 -1
  28. data/lib/glimmer-dsl-opal/samples/hello/hello_radio.rb +108 -0
  29. data/lib/glimmer-dsl-opal/samples/hello/hello_radio_group.rb +84 -0
  30. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/GPL-LICENSE.txt +278 -0
  31. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/MIT-LICENSE.txt +20 -0
  32. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/jquery.ui.timepicker.css +57 -0
  33. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/jquery.ui.timepicker.js +1496 -0
  34. data/lib/glimmer-dsl-opal/vendor/jquery-ui/AUTHORS.txt +333 -0
  35. data/lib/glimmer-dsl-opal/vendor/jquery-ui/LICENSE.txt +43 -0
  36. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_444444_256x240.png +0 -0
  37. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_555555_256x240.png +0 -0
  38. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_777620_256x240.png +0 -0
  39. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_777777_256x240.png +0 -0
  40. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_cc0000_256x240.png +0 -0
  41. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_ffffff_256x240.png +0 -0
  42. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.min.css +7 -0
  43. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.min.js +13 -0
  44. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.structure.min.css +5 -0
  45. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.theme.min.css +5 -0
  46. data/lib/glimmer-dsl-opal/vendor/jquery-ui/package.json +74 -0
  47. data/lib/glimmer-dsl-swt.rb +37 -0
  48. data/lib/glimmer/data_binding/element_binding.rb +2 -1
  49. data/lib/glimmer/dsl/opal/async_exec_expression.rb +23 -7
  50. data/lib/glimmer/dsl/opal/checkbox_group_selection_data_binding_expression.rb +61 -0
  51. data/lib/glimmer/dsl/opal/custom_widget_expression.rb +33 -16
  52. data/lib/glimmer/dsl/opal/display_expression.rb +40 -0
  53. data/lib/glimmer/dsl/opal/dsl.rb +6 -0
  54. data/lib/glimmer/dsl/opal/exec_expression.rb +55 -0
  55. data/lib/glimmer/dsl/opal/property_expression.rb +4 -3
  56. data/lib/glimmer/dsl/opal/radio_group_selection_data_binding_expression.rb +61 -0
  57. data/lib/glimmer/dsl/opal/shell_expression.rb +7 -1
  58. data/lib/glimmer/dsl/opal/sync_exec_expression.rb +33 -0
  59. data/lib/glimmer/dsl/opal/widget_expression.rb +6 -1
  60. data/lib/glimmer/engine.rb +9 -0
  61. data/lib/glimmer/swt.rb +3 -3
  62. data/lib/glimmer/swt/button_proxy.rb +16 -2
  63. data/lib/glimmer/swt/checkbox_proxy.rb +81 -0
  64. data/lib/glimmer/swt/color_proxy.rb +45 -45
  65. data/lib/glimmer/swt/combo_proxy.rb +6 -6
  66. data/lib/glimmer/swt/composite_proxy.rb +2 -2
  67. data/lib/glimmer/swt/custom/checkbox_group.rb +142 -0
  68. data/lib/glimmer/swt/custom/radio_group.rb +143 -0
  69. data/lib/glimmer/swt/date_time_proxy.rb +145 -0
  70. data/lib/glimmer/swt/display_proxy.rb +55 -1
  71. data/lib/glimmer/swt/fill_layout_proxy.rb +3 -3
  72. data/lib/glimmer/swt/grid_layout_proxy.rb +21 -10
  73. data/lib/glimmer/swt/group_proxy.rb +38 -0
  74. data/lib/glimmer/swt/label_proxy.rb +27 -7
  75. data/lib/glimmer/swt/layout_data_proxy.rb +40 -22
  76. data/lib/glimmer/swt/layout_proxy.rb +4 -4
  77. data/lib/glimmer/swt/list_proxy.rb +3 -3
  78. data/lib/glimmer/swt/make_shift_shell_proxy.rb +38 -0
  79. data/lib/glimmer/swt/message_box_proxy.rb +8 -7
  80. data/lib/glimmer/swt/radio_proxy.rb +82 -0
  81. data/lib/glimmer/swt/row_layout_proxy.rb +35 -12
  82. data/lib/glimmer/swt/scrolled_composite_proxy.rb +20 -0
  83. data/lib/glimmer/swt/shell_proxy.rb +23 -9
  84. data/lib/glimmer/swt/styled_text_proxy.rb +44 -0
  85. data/lib/glimmer/swt/tab_folder_proxy.rb +5 -5
  86. data/lib/glimmer/swt/tab_item_proxy.rb +7 -7
  87. data/lib/glimmer/swt/table_item_proxy.rb +6 -6
  88. data/lib/glimmer/swt/table_proxy.rb +12 -12
  89. data/lib/glimmer/swt/text_proxy.rb +2 -2
  90. data/lib/glimmer/swt/widget_proxy.rb +79 -36
  91. data/lib/glimmer/ui/custom_shell.rb +2 -1
  92. data/lib/glimmer/ui/custom_widget.rb +10 -9
  93. data/lib/{glimmer-dsl-opal/missing/net → net}/http.rb +0 -0
  94. data/lib/{glimmer-dsl-opal/missing/uri.rb → uri.rb} +2 -2
  95. metadata +56 -4
@@ -0,0 +1,20 @@
1
+ require 'glimmer/swt/grid_layout_proxy'
2
+ require 'glimmer/swt/widget_proxy'
3
+
4
+ module Glimmer
5
+ module SWT
6
+ class ScrolledCompositeProxy < CompositeProxy
7
+ STYLE = <<~CSS
8
+ .scrolled-composite {
9
+ }
10
+ CSS
11
+
12
+ # TODO set overflow-y and overflow-x based on :v_scroll and :h_scroll styles.... though consider also that it might not be needed in web browsers where scrollbars are always present
13
+ # height: 100px;
14
+ # overflow-y: auto;
15
+
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -1,4 +1,5 @@
1
1
  require 'glimmer/swt/widget_proxy'
2
+ require 'glimmer/swt/display_proxy'
2
3
  require 'glimmer/swt/point'
3
4
 
4
5
  module Glimmer
@@ -53,7 +54,7 @@ module Glimmer
53
54
  .selected, .tabs .tab.selected {
54
55
  background: rgb(80, 116, 211);
55
56
  color: white;
56
- }
57
+ }
57
58
  CSS
58
59
  end
59
60
 
@@ -121,11 +122,11 @@ module Glimmer
121
122
  /* Create an selected/current tablink class */
122
123
  .tabs .tab.selected {
123
124
  background-color: #ccc;
124
- }
125
+ }
125
126
  /* Change background color of buttons on hover */
126
127
  .tabs .tab:hover {
127
128
  background-color: #ddd;
128
- }
129
+ }
129
130
  /* Style the tab content */
130
131
  .tab-item {
131
132
  padding: 6px 12px;
@@ -189,14 +190,14 @@ module Glimmer
189
190
  end
190
191
 
191
192
  def style_dom_table_css
192
- <<~CSS
193
+ <<~CSS
193
194
  table {
194
195
  border-spacing: 0;
195
196
  }
196
197
 
197
198
  table tr th,td {
198
199
  cursor: default;
199
- }
200
+ }
200
201
  CSS
201
202
  end
202
203
 
@@ -217,14 +218,14 @@ module Glimmer
217
218
  }
218
219
  style(class: 'tab-style') {
219
220
  style_dom_tab_css
220
- }
221
+ }
221
222
  # style(class: 'tab-item-style') {
222
223
  # style_dom_tab_item_css
223
- # }
224
+ # }
224
225
  # style(class: 'modal-style') {
225
226
  # style_dom_modal_css
226
- # }
227
- style(class: 'table-style') {
227
+ # }
228
+ style(class: 'table-style') {
228
229
  style_dom_table_css
229
230
  }
230
231
  style(class: 'fill-layout-style') {
@@ -233,6 +234,18 @@ module Glimmer
233
234
  style(class: 'row-layout-style') {
234
235
  Glimmer::SWT::RowLayoutProxy::STYLE
235
236
  }
237
+ style(class: 'grid-layout-style') {
238
+ Glimmer::SWT::GridLayoutProxy::STYLE
239
+ }
240
+ style(class: 'checkbox-style') {
241
+ Glimmer::SWT::CheckboxProxy::STYLE
242
+ }
243
+ style(class: 'radio-style') {
244
+ Glimmer::SWT::RadioProxy::STYLE
245
+ }
246
+ style(class: 'scrolled-composite-style') {
247
+ Glimmer::SWT::ScrolledCompositeProxy::STYLE
248
+ }
236
249
  }
237
250
  }.to_s
238
251
  end
@@ -240,6 +253,7 @@ module Glimmer
240
253
  def open
241
254
  # TODO consider the idea of delaying rendering till the open method
242
255
  # TODO make it start as hidden and show shell upon open
256
+ Glimmer::SWT::DisplayProxy.instance.shells << self
243
257
  end
244
258
  end
245
259
  end
@@ -0,0 +1,44 @@
1
+ require 'glimmer/swt/widget_proxy'
2
+ require 'glimmer/swt/text_proxy'
3
+ require 'glimmer/swt/swt_proxy'
4
+
5
+ module Glimmer
6
+ module SWT
7
+ class StyledTextProxy < TextProxy
8
+ attr_reader :alignment, :right_margin, :editable, :caret
9
+
10
+ def alignment=(value)
11
+ @alignment = %w[left center right].detect {|alignment_value| SWTProxy[alignment_value] == value}
12
+ dom_element.css('text-align', @alignment)
13
+ end
14
+
15
+ def right_margin=(value)
16
+ @right_margin = value.to_i
17
+ dom_element.css('padding-right', @right_margin)
18
+ end
19
+
20
+ def editable=(value)
21
+ @editable = value
22
+ if !@editable
23
+ dom_element.attr('disabled', true)
24
+ dom_element.css('background', :white)
25
+ dom_element.css('border', 'solid 1px rgb(118, 118, 118)')
26
+ dom_element.css('border-radius', '3px')
27
+ # :hover {
28
+ # border-color: rgb(80, 80, 80);
29
+ # }
30
+ else
31
+ dom_element.prop('disabled', false)
32
+ dom_element.css('background', nil)
33
+ dom_element.css('border', nil)
34
+ dom_element.css('border-radius', nil)
35
+ end
36
+ end
37
+
38
+ def caret=(value)
39
+ @caret = value
40
+ # TODO implement (not needed for disabling caret though)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -2,17 +2,17 @@ require 'glimmer/swt/widget_proxy'
2
2
 
3
3
  module Glimmer
4
4
  module SWT
5
- class TabFolderProxy < WidgetProxy
5
+ class TabFolderProxy < WidgetProxy
6
6
  attr_reader :tabs
7
7
 
8
- def initialize(parent, args)
9
- super(parent, args)
8
+ def initialize(parent, args, block)
9
+ super(parent, args, block)
10
10
  @tabs = []
11
11
  end
12
12
 
13
- def add_child(child)
13
+ def post_initialize_child(child)
14
14
  unless @children.include?(child)
15
- @children << child
15
+ @children << child
16
16
  tabs_dom_element.append(child.tab_dom)
17
17
  child.render
18
18
  end
@@ -4,10 +4,10 @@ module Glimmer
4
4
  module SWT
5
5
  class TabItemProxy < CompositeProxy
6
6
  include Glimmer
7
- attr_reader :text, :content_visible
7
+ attr_reader :text, :content_visible
8
8
 
9
- def initialize(parent, args)
10
- super(parent, args)
9
+ def initialize(parent, args, block)
10
+ super(parent, args, block)
11
11
  content {
12
12
  on_widget_selected {
13
13
  @parent.hide_all_tab_content
@@ -35,7 +35,7 @@ module Glimmer
35
35
 
36
36
  def selector
37
37
  super + '-tab'
38
- end
38
+ end
39
39
 
40
40
  def observation_request_to_event_mapping
41
41
  {
@@ -47,7 +47,7 @@ module Glimmer
47
47
 
48
48
  def listener_path
49
49
  tab_path
50
- end
50
+ end
51
51
 
52
52
  def tab_path
53
53
  "#{parent.tabs_path} > ##{tab_id}"
@@ -72,13 +72,13 @@ module Glimmer
72
72
 
73
73
  # This contains the tab content
74
74
  def dom
75
- tab_item_id = id
75
+ tab_item_id = id
76
76
  tab_item_class_string = [name, 'hide'].join(' ')
77
77
  @dom ||= html {
78
78
  div(id: tab_item_id, class: tab_item_class_string) {
79
79
  }
80
80
  }.to_s
81
- end
81
+ end
82
82
  end
83
83
  end
84
84
  end
@@ -5,8 +5,8 @@ module Glimmer
5
5
  class TableItemProxy < WidgetProxy
6
6
  attr_reader :data
7
7
 
8
- def initialize(parent, args)
9
- super(parent, args)
8
+ def initialize(parent, args, block)
9
+ super(parent, args, block)
10
10
  on_widget_selected { |event|
11
11
  parent.select(parent.index_of(self), event.meta?)
12
12
  }
@@ -70,11 +70,11 @@ module Glimmer
70
70
  redraw
71
71
  end
72
72
  end
73
- table_item_edit_cancel_handler = lambda do |event|
73
+ table_item_edit_cancel_handler = lambda do |event|
74
74
  Async::Task.new do
75
75
  table_item_edit_handler.call(event, true)
76
76
  end
77
- end
77
+ end
78
78
  table_item_edit_key_handler = lambda do |event|
79
79
  Async::Task.new do
80
80
  if event.key_code == 13
@@ -91,7 +91,7 @@ module Glimmer
91
91
  Async::Task.new do
92
92
  table_item_input.focus
93
93
  table_item_input.on('keyup', &table_item_edit_key_handler)
94
- table_item_input.on('focusout', &table_item_edit_cancel_handler)
94
+ table_item_input.on('focusout', &table_item_edit_cancel_handler)
95
95
  end
96
96
  end
97
97
  end
@@ -132,7 +132,7 @@ module Glimmer
132
132
  tr(id: table_item_id, style: table_item_id_style, class: table_item_css_classes.to_a.join(' ')) {
133
133
  table_item_text_array.each_with_index do |table_item_text, column_index|
134
134
  td('data-column-index' => column_index) {
135
- if @edit_column_index == column_index
135
+ if @edit_column_index == column_index
136
136
  input(type: 'text', value: table_item_text, style: "max-width: #{table_item_max_width - 11}px;")
137
137
  else
138
138
  table_item_text
@@ -8,19 +8,19 @@ module Glimmer
8
8
  attr_accessor :column_properties
9
9
  alias items children
10
10
 
11
- def initialize(parent, args)
12
- super(parent, args)
11
+ def initialize(parent, args, block)
12
+ super(parent, args, block)
13
13
  @columns = []
14
14
  @children = []
15
15
  @selection = []
16
16
  end
17
17
 
18
18
  # Only table_columns may be added as children
19
- def add_child(child)
19
+ def post_initialize_child(child)
20
20
  if child.is_a?(TableColumnProxy)
21
21
  @columns << child
22
22
  else
23
- @children << child
23
+ @children << child
24
24
  end
25
25
  child.redraw
26
26
  end
@@ -36,14 +36,14 @@ module Glimmer
36
36
  changed.each(&:redraw)
37
37
  end
38
38
 
39
- def items=(new_items)
39
+ def items=(new_items)
40
40
  @children = new_items
41
41
  redraw
42
42
  end
43
43
 
44
44
  def search(&condition)
45
45
  items.select {|item| condition.nil? || condition.call(item)}
46
- end
46
+ end
47
47
 
48
48
  def index_of(item)
49
49
  items.index(item)
@@ -84,9 +84,9 @@ module Glimmer
84
84
  event.singleton_class.send(:define_method, :column_index) do
85
85
  (table_data || event.target).attr('data-column-index')
86
86
  end
87
- event_listener.call(event)
87
+ event_listener.call(event)
88
88
  }
89
- }
89
+ }
90
90
 
91
91
  {
92
92
  'on_mouse_down' => {
@@ -102,7 +102,7 @@ module Glimmer
102
102
 
103
103
  def redraw
104
104
  super()
105
- @columns.to_a.each(&:redraw)
105
+ @columns.to_a.each(&:redraw)
106
106
  end
107
107
 
108
108
  def element
@@ -125,7 +125,7 @@ module Glimmer
125
125
  Document.find(items_path)
126
126
  end
127
127
 
128
- def columns_dom
128
+ def columns_dom
129
129
  tr {
130
130
  }
131
131
  end
@@ -134,9 +134,9 @@ module Glimmer
134
134
  thead {
135
135
  columns_dom
136
136
  }
137
- end
137
+ end
138
138
 
139
- def items_dom
139
+ def items_dom
140
140
  tbody {
141
141
  }
142
142
  end
@@ -21,12 +21,12 @@ module Glimmer
21
21
  event_handler: -> (event_listener) {
22
22
  -> (event) {
23
23
  @text = event.target.value
24
- event_listener.call(event)
24
+ event_listener.call(event)
25
25
  }
26
26
  }
27
27
  }
28
28
  }
29
- end
29
+ end
30
30
 
31
31
  def dom
32
32
  text_text = @text
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 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
@@ -29,13 +29,13 @@ module Glimmer
29
29
  include Glimmer
30
30
  include PropertyOwner
31
31
 
32
- attr_reader :parent, :args, :path, :children, :enabled, :foreground, :background, :font
32
+ attr_reader :parent, :args, :path, :children, :enabled, :foreground, :background, :font, :focus
33
33
 
34
34
  class << self
35
35
  # Factory Method that translates a Glimmer DSL keyword into a WidgetProxy object
36
- def for(keyword, parent, args)
36
+ def for(keyword, parent, args, block)
37
37
  the_widget_class = widget_class(keyword)
38
- the_widget_class.new(parent, args)
38
+ the_widget_class.respond_to?(:create) ? the_widget_class.create(keyword, parent, args, block) : the_widget_class.new(parent, args, block)
39
39
  end
40
40
 
41
41
  def widget_class(keyword)
@@ -69,7 +69,7 @@ module Glimmer
69
69
 
70
70
  def underscored_widget_name(widget_proxy)
71
71
  widget_proxy.class.name.split(/::|\./).last.sub(/Proxy$/, '').underscore
72
- end
72
+ end
73
73
  end
74
74
 
75
75
  DEFAULT_INITIALIZERS = {
@@ -95,27 +95,39 @@ module Glimmer
95
95
  # "group" => lambda do |group_proxy|
96
96
  # group_proxy.layout = GridLayoutProxy.new(group_proxy, []) if group.layout.nil?
97
97
  # end,
98
- }
98
+ }
99
99
 
100
- def initialize(parent, args)
101
- @parent = parent
100
+ def initialize(parent, args, block)
101
+ @parent = parent
102
102
  @args = args
103
+ @block = block
103
104
  @children = Set.new # TODO consider moving to composite
104
105
  @enabled = true
105
106
  DEFAULT_INITIALIZERS[self.class.underscored_widget_name(self)]&.call(self)
106
- @parent.add_child(self) # TODO rename to post_initialize_child to be closer to glimmer-dsl-swt terminology
107
+ @parent.post_initialize_child(self) # TODO rename to post_initialize_child to be closer to glimmer-dsl-swt terminology
108
+ end
109
+
110
+ # Executes for the parent of a child that just got added
111
+ def post_initialize_child(child)
112
+ @children << child
113
+ child.render
114
+ end
115
+
116
+ # Executes at the closing of a parent widget curly braces after all children/properties have been added/set
117
+ def post_add_content
118
+ # No Op by default
107
119
  end
108
120
 
109
121
  def css_classes
110
122
  dom_element.attr('class').to_s.split
111
- end
123
+ end
112
124
 
113
125
  def dispose
114
126
  Document.find(path).remove
115
127
  end
116
128
 
117
129
  def path
118
- "#{parent_path} > #{element}##{id}.#{name}"
130
+ "#{parent_path} #{element}##{id}.#{name}"
119
131
  end
120
132
 
121
133
  # Root element representing widget. Must be overridden by subclasses if different from div
@@ -123,11 +135,6 @@ module Glimmer
123
135
  'div'
124
136
  end
125
137
 
126
- def add_child(child)
127
- @children << child
128
- child.render
129
- end
130
-
131
138
  def enabled=(value)
132
139
  @enabled = value
133
140
  dom_element.prop('disabled', !@enabled)
@@ -151,6 +158,16 @@ module Glimmer
151
158
  dom_element.css('font-size', "#{@font.height}px") unless @font.nil?
152
159
  end
153
160
 
161
+ def focus=(value)
162
+ @focus = value
163
+ dom_element.focus # TODO consider if a delay or async_exec is needed here
164
+ end
165
+
166
+ def set_focus
167
+ self.focus = true
168
+ end
169
+ alias setFocus set_focus
170
+
154
171
  def parent_path
155
172
  @parent.path
156
173
  end
@@ -172,14 +189,14 @@ module Glimmer
172
189
  end
173
190
  children.each do |child|
174
191
  child.render
175
- end
192
+ end
176
193
  end
177
194
  alias redraw render
178
195
 
179
196
  def build_dom
180
197
  @dom = nil
181
198
  @dom = dom
182
- @dom = @parent.layout.dom(@dom) if @parent.respond_to?(:layout) && @parent.layout
199
+ @dom = @parent.layout.dom(@dom) if @parent.respond_to?(:layout) && @parent.layout
183
200
  end
184
201
 
185
202
  def content(&block)
@@ -234,9 +251,12 @@ module Glimmer
234
251
  end
235
252
 
236
253
  def dom_element
254
+ # TODO consider making this pick an element in relation to its parent, allowing unhooked dom elements to be built if needed (unhooked to the visible page dom)
237
255
  Document.find(path)
238
256
  end
239
257
 
258
+ # TODO consider adding a default #dom method implementation for the common case, automatically relying on #element and other methods to build the dom html
259
+
240
260
  def style_element
241
261
  style_element_id = "#{id}-style"
242
262
  style_element_selector = "style##{style_element_id}"
@@ -259,7 +279,11 @@ module Glimmer
259
279
  path
260
280
  end
261
281
 
262
- def can_handle_observation_request?(observation_request)
282
+ def listener_dom_element
283
+ Document.find(listener_path)
284
+ end
285
+
286
+ def can_handle_observation_request?(observation_request)
263
287
  # TODO sort this out for Opal
264
288
  observation_request = observation_request.to_s
265
289
  if observation_request.start_with?('on_swt_')
@@ -270,7 +294,7 @@ module Glimmer
270
294
  # can_add_listener?(event) || can_handle_drag_observation_request?(observation_request) || can_handle_drop_observation_request?(observation_request)
271
295
  true # TODO filter by valid listeners only in the future
272
296
  end
273
- end
297
+ end
274
298
 
275
299
  def handle_observation_request(keyword, &event_listener)
276
300
  return unless observation_request_to_event_mapping.keys.include?(keyword)
@@ -282,16 +306,23 @@ module Glimmer
282
306
  @observation_requests[keyword] << event_listener
283
307
  event = mapping[:event]
284
308
  event_handler = mapping[:event_handler]
309
+ event_element_css_selector = mapping[:event_element_css_selector]
285
310
  potential_event_listener = event_handler&.call(event_listener)
286
311
  event_listener = potential_event_listener || event_listener
287
- delegate = Document.find(listener_path).on(event, &event_listener)
312
+ async_event_listener = lambda do |event|
313
+ Async::Task.new do
314
+ event_listener.call(event)
315
+ end
316
+ end
317
+ the_listener_dom_element = event_element_css_selector ? Element[event_element_css_selector] : listener_dom_element
318
+ delegate = the_listener_dom_element.on(event, &async_event_listener)
288
319
  end
289
320
  # TODO update code below for new WidgetProxy API
290
321
  EventListenerProxy.new(element_proxy: self, event: event, selector: selector, delegate: delegate)
291
322
  end
292
323
 
293
324
  def add_observer(observer, property_name)
294
- property_listener_installers = self.class.ancestors.map {|ancestor| widget_property_listener_installers[ancestor]}.compact
325
+ property_listener_installers = self.class&.ancestors&.to_a.map {|ancestor| widget_property_listener_installers[ancestor]}.compact
295
326
  widget_listener_installers = property_listener_installers.map{|installer| installer[property_name.to_s.to_sym]}.compact if !property_listener_installers.empty?
296
327
  widget_listener_installers.to_a.each do |widget_listener_installer|
297
328
  widget_listener_installer.call(observer)
@@ -352,9 +383,6 @@ module Glimmer
352
383
  # else
353
384
  # value
354
385
  # end
355
- # end,
356
- # :items => lambda do |value|
357
- # value.to_java :string
358
386
  # end,
359
387
  :text => lambda do |value|
360
388
  # if swt_widget.is_a?(Browser)
@@ -366,8 +394,8 @@ module Glimmer
366
394
  # :visible => lambda do |value|
367
395
  # !!value
368
396
  # end,
369
- }
370
- end
397
+ }
398
+ end
371
399
 
372
400
  def widget_property_listener_installers
373
401
  @swt_widget_property_listener_installers ||= {
@@ -446,13 +474,20 @@ module Glimmer
446
474
  # }
447
475
  # end,
448
476
  # },
449
- # Button => { #radio?
450
- # :selection => lambda do |observer|
451
- # on_widget_selected { |selection_event|
452
- # observer.call(getSelection)
453
- # }
454
- # end
455
- # },
477
+ DateTimeProxy => {
478
+ :date_time => lambda do |observer|
479
+ on_widget_selected { |selection_event|
480
+ observer.call(date_time)
481
+ }
482
+ end
483
+ },
484
+ RadioProxy => { #radio?
485
+ :selection => lambda do |observer|
486
+ on_widget_selected { |selection_event|
487
+ observer.call(selection)
488
+ }
489
+ end
490
+ },
456
491
  # Java::OrgEclipseSwtWidgets::MenuItem => {
457
492
  # :selection => lambda do |observer|
458
493
  # on_widget_selected { |selection_event|
@@ -477,14 +512,22 @@ end
477
512
  require 'glimmer/swt/browser_proxy'
478
513
  require 'glimmer/swt/button_proxy'
479
514
  require 'glimmer/swt/combo_proxy'
515
+ require 'glimmer/swt/checkbox_proxy'
480
516
  require 'glimmer/swt/composite_proxy'
517
+ require 'glimmer/swt/display_proxy'
518
+ require 'glimmer/swt/date_time_proxy'
519
+ require 'glimmer/swt/group_proxy'
481
520
  require 'glimmer/swt/label_proxy'
482
521
  require 'glimmer/swt/list_proxy'
522
+ require 'glimmer/swt/radio_proxy'
483
523
  require 'glimmer/swt/tab_folder_proxy'
484
524
  require 'glimmer/swt/tab_item_proxy'
485
525
  require 'glimmer/swt/table_column_proxy'
486
526
  require 'glimmer/swt/table_item_proxy'
487
527
  require 'glimmer/swt/table_proxy'
488
528
  require 'glimmer/swt/text_proxy'
529
+ require 'glimmer/swt/radio_proxy'
530
+ require 'glimmer/swt/scrolled_composite_proxy'
531
+ require 'glimmer/swt/styled_text_proxy'
489
532
 
490
533
  require 'glimmer/dsl/opal/widget_expression'