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,143 @@
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
+ require 'glimmer/ui/custom_widget'
23
+
24
+ module Glimmer
25
+ module SWT
26
+ module Custom
27
+ # A custom widget rendering a group of radios generated via data-binding
28
+ class RadioGroup
29
+ include Glimmer::UI::CustomWidget
30
+
31
+ body {
32
+ composite # just an empty composite to hold radios upon data-binding `selection`
33
+ }
34
+
35
+ def items=(text_array)
36
+ selection_value = selection
37
+ @items = Array[*text_array]
38
+ build_radios
39
+ end
40
+
41
+ def items
42
+ @items || []
43
+ end
44
+
45
+ def selection=(text)
46
+ radios.count.times do |index|
47
+ radio = radios[index]
48
+ item = items[index]
49
+ radio.selection = item == text
50
+ end
51
+ end
52
+
53
+ def selection
54
+ selection_value = radios[selection_index]&.text unless selection_index == -1
55
+ selection_value.to_s
56
+ end
57
+
58
+ def selection_index=(index)
59
+ self.selection=(items[index])
60
+ end
61
+ alias select selection_index=
62
+
63
+ def selection_index
64
+ radios.index(radios.detect(&:selection)) || -1
65
+ end
66
+
67
+ def radios
68
+ @radios ||= []
69
+ end
70
+
71
+ def observation_request_to_event_mapping
72
+ # TODO method might not be needed
73
+ {
74
+ 'on_widget_selected' => {
75
+ event: 'change'
76
+ },
77
+ }
78
+ end
79
+
80
+ def can_handle_observation_request?(observation_request)
81
+ radios.first&.can_handle_observation_request?(observation_request) || super(observation_request)
82
+ end
83
+
84
+ def handle_observation_request(observation_request, &block)
85
+ observation_requests << [observation_request, block]
86
+ delegate_observation_request_to_radios(observation_request, &block)
87
+ super
88
+ end
89
+
90
+ def delegate_observation_request_to_radios(observation_request, &block)
91
+ if observation_request != 'on_widget_disposed'
92
+ radios.count.times do |index|
93
+ radio = radios[index]
94
+ radio.handle_observation_request(observation_request, &block) if radio.can_handle_observation_request?(observation_request)
95
+ end
96
+ end
97
+ end
98
+
99
+ def observation_requests
100
+ @observation_requests ||= Set.new
101
+ end
102
+
103
+ def has_attribute?(attribute_name, *args)
104
+ @radios.to_a.map do |widget_proxy|
105
+ return true if widget_proxy.has_attribute?(attribute_name, *args)
106
+ end
107
+ super
108
+ end
109
+
110
+ def set_attribute(attribute_name, *args)
111
+ excluded_attributes = ['selection']
112
+ unless excluded_attributes.include?(attribute_name.to_s)
113
+ @radios.to_a.each do |widget_proxy|
114
+ widget_proxy.set_attribute(attribute_name, *args) if widget_proxy.has_attribute?(attribute_name, *args)
115
+ end
116
+ end
117
+ super
118
+ end
119
+
120
+ private
121
+
122
+ def build_radios
123
+ current_selection = selection
124
+ @radios = []
125
+ items.each do |item|
126
+ body_root.content {
127
+ radios << radio { |radio_proxy|
128
+ text item
129
+ on_widget_selected {
130
+ self.selection = items[radios.index(radio_proxy)]
131
+ }
132
+ }
133
+ }
134
+ end
135
+ observation_requests.to_a.each do |observation_request, block|
136
+ delegate_observation_request_to_radios(observation_request, &block)
137
+ end
138
+ self.selection = current_selection
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,145 @@
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
+ button: "##{time_button_id}",
35
+ })
36
+ else
37
+ options = {}
38
+ if drop_down?
39
+ options = {
40
+ showOn: 'both',
41
+ buttonImage: 'assets/glimmer/images/calendar.gif',
42
+ buttonImageOnly: true,
43
+ buttonText: 'Select date'
44
+ }
45
+ end
46
+ dom_element.datepicker(options)
47
+ end
48
+ date_time_value = self.date_time
49
+ @added_content = true
50
+ self.date_time = date_time_value
51
+ end
52
+
53
+ def date?
54
+ args.to_a.include?(:date)
55
+ end
56
+
57
+ def time?
58
+ args.to_a.include?(:time)
59
+ end
60
+
61
+ def drop_down?
62
+ args.to_a.include?(:drop_down)
63
+ end
64
+
65
+ def calendar?
66
+ args.to_a.include?(:calendar)
67
+ end
68
+
69
+ def date_time
70
+ if @added_content
71
+ default_date = DateTime.new if @date_time.nil?
72
+ default_year = @date_time&.year || default_date.year
73
+ default_month = @date_time&.month || default_date.month
74
+ default_day = @date_time&.day || default_date.day
75
+ default_hour = @date_time&.hour || default_date.hour
76
+ default_min = @date_time&.min || default_date.min
77
+ default_sec = @date_time&.sec || default_date.sec
78
+ if time?
79
+ @date_time = DateTime.new(default_year, default_month, default_day, dom_element.timepicker('getHour').to_i, dom_element.timepicker('getMinute').to_i, default_sec)
80
+ else
81
+ @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)
82
+ end
83
+ @date_time = @date_time&.to_datetime
84
+ else
85
+ @initial_date_time
86
+ end
87
+ end
88
+
89
+ def date_time=(value)
90
+ if @added_content
91
+ @date_time = value&.to_datetime || DateTime.new
92
+ if time?
93
+ dom_element.timepicker('setTime', "#{@date_time.hour}:#{@date_time.min}")
94
+ else
95
+ dom_element.datepicker('setDate', @date_time.to_time)
96
+ end
97
+ else
98
+ @initial_date_time = value
99
+ end
100
+ end
101
+
102
+ # TODO add date, time, year, month, day, hours, minutes, seconds attribute methods
103
+
104
+ def observation_request_to_event_mapping
105
+ {
106
+ 'on_widget_selected' => [
107
+ {
108
+ event: 'change'
109
+ },
110
+ ],
111
+ }
112
+ end
113
+
114
+ def time_button_id
115
+ "#{id}-time-button"
116
+ end
117
+
118
+ def time_button_class
119
+ "#{name}-time-button"
120
+ end
121
+
122
+ def element
123
+ calendar? ? 'div' : 'input'
124
+ end
125
+
126
+ def dom
127
+ @dom ||= html {
128
+ span {
129
+ send(element, type: 'text', id: id, class: name)
130
+ 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?
131
+ }
132
+ }.to_s
133
+ end
134
+
135
+ end
136
+
137
+ # Aliases: `date`, `date_drop_down`, `time`, and `calendar`
138
+ DateProxy = DateTimeProxy
139
+ DateDropDownProxy = DateTimeProxy
140
+ TimeProxy = DateTimeProxy
141
+ CalendarProxy = DateTimeProxy
142
+
143
+ end
144
+
145
+ end
@@ -1,12 +1,33 @@
1
1
  module Glimmer
2
2
  module SWT
3
- class DisplayProxy
3
+ class DisplayProxy < WidgetProxy
4
4
  class << self
5
5
  def instance
6
6
  @instance ||= new
7
7
  end
8
8
  end
9
9
 
10
+ def initialize
11
+ # Do not call super
12
+ end
13
+
14
+ def path
15
+ "html body"
16
+ end
17
+
18
+ # Root element representing widget. Must be overridden by subclasses if different from div
19
+ def element
20
+ 'body'
21
+ end
22
+
23
+ def listener_dom_element
24
+ Document
25
+ end
26
+
27
+ def render
28
+ # No rendering as body is rendered as part of ShellProxy.. this class only serves as an SWT Display utility
29
+ end
30
+
10
31
  def async_exec(&block)
11
32
  executer = lambda do
12
33
  if Document.find('.modal').to_a.empty?
@@ -20,6 +41,39 @@ module Glimmer
20
41
  end
21
42
  # sync_exec kept for API compatibility reasons
22
43
  alias sync_exec async_exec
44
+
45
+ def observation_request_to_event_mapping
46
+ {
47
+ 'on_swt_keydown' => [
48
+ {
49
+ event: 'keypress',
50
+ event_handler: -> (event_listener) {
51
+ -> (event) {
52
+ event.singleton_class.define_method(:character) do
53
+ which || key_code
54
+ end
55
+ event_listener.call(event)
56
+ }
57
+ }
58
+ },
59
+ {
60
+ event: 'keydown',
61
+ event_handler: -> (event_listener) {
62
+ -> (event) {
63
+ event.singleton_class.define_method(:character) do
64
+ which || key_code
65
+ end
66
+ event_listener.call(event) if event.key_code != 13 && (event.key_code == 127 || event.key_code <= 31)
67
+ }
68
+ }
69
+ }
70
+ ]
71
+ }
72
+ end
73
+
74
+ def shells
75
+ @shells ||= []
76
+ end
23
77
  end
24
78
  end
25
79
  end
@@ -54,8 +54,8 @@ module Glimmer
54
54
 
55
55
  def margin_height=(pixels)
56
56
  @margin_height = pixels
57
- @parent.dom_element.css('margin-top', @margin_height)
58
- @parent.dom_element.css('margin-bottom', @margin_height)
57
+ @parent.dom_element.css('padding-top', @margin_height)
58
+ @parent.dom_element.css('padding-bottom', @margin_height)
59
59
  end
60
60
 
61
61
  def spacing=(spacing)
@@ -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
@@ -3,6 +3,15 @@ require 'glimmer/swt/layout_proxy'
3
3
  module Glimmer
4
4
  module SWT
5
5
  class GridLayoutProxy < LayoutProxy
6
+ STYLE = <<~CSS
7
+ .grid-layout {
8
+ display: grid;
9
+ grid-template-rows: min-content;
10
+ justify-content: start;
11
+ place-content: start;
12
+ align-items: stretch;
13
+ }
14
+ CSS
6
15
  attr_reader :num_columns, :make_columns_equal_width, :horizontal_spacing, :vertical_spacing, :margin_width, :margin_height
7
16
 
8
17
  def initialize(parent, args)
@@ -47,24 +56,26 @@ module Glimmer
47
56
 
48
57
  def margin_height=(pixels)
49
58
  @margin_height = pixels
50
- @parent.dom_element.css('margin-top', @margin_height)
51
- @parent.dom_element.css('margin-bottom', @margin_height)
59
+ @parent.dom_element.css('padding-top', @margin_height)
60
+ @parent.dom_element.css('padding-bottom', @margin_height)
52
61
  end
53
62
 
54
63
  def reapply
64
+ # TODO get rid of this method
55
65
  layout_css = <<~CSS
56
- display: grid;
57
66
  grid-template-columns: #{'auto ' * @num_columns.to_i};
58
- grid-template-rows: min-content;
59
67
  grid-row-gap: #{@vertical_spacing}px;
60
68
  grid-column-gap: #{@horizontal_spacing}px;
61
- justify-content: start;
62
- align-items: start;
63
- align-content: start;
64
69
  CSS
65
- layout_css.split(";").map(&:strip).map {|l| l.split(':').map(&:strip)}.each do |key, value|
66
- @parent.dom_element.css(key, value) unless key.nil?
67
- end
70
+ if @parent.css_classes.include?('grid-layout')
71
+ layout_css.split(";").map(&:strip).map {|l| l.split(':').map(&:strip)}.each do |key, value|
72
+ @parent.dom_element.css(key, value) unless key.nil?
73
+ end
74
+ else
75
+ layout_css.split(";").map(&:strip).map {|l| l.split(':').map(&:strip)}.each do |key, value|
76
+ @parent.dom_element.css(key, 'initial') unless key.nil?
77
+ end
78
+ end
68
79
  end
69
80
  end
70
81
  end
@@ -0,0 +1,38 @@
1
+ require 'glimmer/swt/widget_proxy'
2
+
3
+ module Glimmer
4
+ module SWT
5
+ # Adapter for org.eclipse.swt.widgets.Group
6
+ #
7
+ # Follows Adapter Pattern
8
+ class GroupProxy < CompositeProxy
9
+ attr_reader :text
10
+
11
+ def text=(value)
12
+ @text = value
13
+ if @text.nil?
14
+ legend_dom_element.add_class('hide')
15
+ else
16
+ legend_dom_element.remove_class('hide')
17
+ end
18
+ legend_dom_element.html(@text)
19
+ end
20
+
21
+ def element
22
+ 'fieldset'
23
+ end
24
+
25
+ def legend_dom_element
26
+ dom_element.find('legend')
27
+ end
28
+
29
+ def dom
30
+ @dom ||= html {
31
+ fieldset(id: id, class: name) {
32
+ legend(class: 'hide') { text }
33
+ }
34
+ }.to_s
35
+ end
36
+ end
37
+ end
38
+ end