glimmer-dsl-opal 0.2.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -0
  3. data/README.md +1022 -190
  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.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 +23 -8
  19. data/lib/glimmer-dsl-opal/ext/date.rb +48 -0
  20. data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox.rb +85 -0
  21. data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox_group.rb +68 -0
  22. data/lib/glimmer-dsl-opal/samples/hello/hello_combo.rb +5 -5
  23. data/lib/glimmer-dsl-opal/samples/hello/hello_custom_shell.rb +3 -3
  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 +42 -5
  52. data/lib/glimmer/dsl/opal/display_expression.rb +40 -0
  53. data/lib/glimmer/dsl/opal/dsl.rb +7 -0
  54. data/lib/glimmer/dsl/opal/exec_expression.rb +55 -0
  55. data/lib/glimmer/dsl/opal/layout_expression.rb +1 -1
  56. data/lib/glimmer/dsl/opal/property_expression.rb +4 -3
  57. data/lib/glimmer/dsl/opal/radio_group_selection_data_binding_expression.rb +61 -0
  58. data/lib/glimmer/dsl/opal/shell_expression.rb +23 -1
  59. data/lib/glimmer/dsl/opal/swt_expression.rb +1 -1
  60. data/lib/glimmer/dsl/opal/sync_exec_expression.rb +33 -0
  61. data/lib/glimmer/dsl/opal/widget_expression.rb +5 -0
  62. data/lib/glimmer/engine.rb +9 -0
  63. data/lib/glimmer/swt.rb +3 -3
  64. data/lib/glimmer/swt/button_proxy.rb +15 -1
  65. data/lib/glimmer/swt/checkbox_proxy.rb +81 -0
  66. data/lib/glimmer/swt/combo_proxy.rb +4 -4
  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 +144 -0
  70. data/lib/glimmer/swt/display_proxy.rb +55 -1
  71. data/lib/glimmer/swt/fill_layout_proxy.rb +2 -2
  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 +59 -6
  76. data/lib/glimmer/swt/layout_proxy.rb +2 -1
  77. data/lib/glimmer/swt/list_proxy.rb +2 -2
  78. data/lib/glimmer/swt/make_shift_shell_proxy.rb +38 -0
  79. data/lib/glimmer/swt/message_box_proxy.rb +7 -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 +25 -10
  84. data/lib/glimmer/swt/styled_text_proxy.rb +44 -0
  85. data/lib/glimmer/swt/tab_folder_proxy.rb +3 -3
  86. data/lib/glimmer/swt/table_proxy.rb +10 -10
  87. data/lib/glimmer/swt/text_proxy.rb +2 -2
  88. data/lib/glimmer/swt/widget_proxy.rb +67 -33
  89. data/lib/glimmer/ui/custom_shell.rb +21 -2
  90. data/lib/glimmer/ui/custom_widget.rb +3 -1
  91. data/lib/{glimmer-dsl-opal/missing/net → net}/http.rb +0 -0
  92. data/lib/uri.rb +64 -0
  93. metadata +57 -4
  94. data/lib/glimmer-dsl-opal/missing/uri.rb +0 -26
@@ -0,0 +1,144 @@
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)
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)
19
+ end
20
+ end
21
+
22
+ def initialize(parent, args)
23
+ super(parent, args)
24
+ end
25
+
26
+ def post_add_content
27
+ # TODO handle date_drop_down version
28
+ if time?
29
+ dom_element.timepicker({
30
+ showPeriod: true,
31
+ showLeadingZero: true,
32
+ showOn: 'both',
33
+ button: "##{time_button_id}",
34
+ })
35
+ else
36
+ options = {}
37
+ if drop_down?
38
+ options = {
39
+ showOn: 'both',
40
+ buttonImage: 'assets/glimmer/images/calendar.gif',
41
+ buttonImageOnly: true,
42
+ buttonText: 'Select date'
43
+ }
44
+ end
45
+ dom_element.datepicker(options)
46
+ end
47
+ date_time_value = self.date_time
48
+ @added_content = true
49
+ self.date_time = date_time_value
50
+ end
51
+
52
+ def date?
53
+ args.to_a.include?(:date)
54
+ end
55
+
56
+ def time?
57
+ args.to_a.include?(:time)
58
+ end
59
+
60
+ def drop_down?
61
+ args.to_a.include?(:drop_down)
62
+ end
63
+
64
+ def calendar?
65
+ args.to_a.include?(:calendar)
66
+ end
67
+
68
+ def date_time
69
+ if @added_content
70
+ default_date = DateTime.new if @date_time.nil?
71
+ default_year = @date_time&.year || default_date.year
72
+ default_month = @date_time&.month || default_date.month
73
+ default_day = @date_time&.day || default_date.day
74
+ default_hour = @date_time&.hour || default_date.hour
75
+ default_min = @date_time&.min || default_date.min
76
+ default_sec = @date_time&.sec || default_date.sec
77
+ if time?
78
+ @date_time = DateTime.new(default_year, default_month, default_day, dom_element.timepicker('getHour').to_i, dom_element.timepicker('getMinute').to_i, default_sec)
79
+ else
80
+ @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)
81
+ end
82
+ @date_time = @date_time&.to_datetime
83
+ else
84
+ @initial_date_time
85
+ end
86
+ end
87
+
88
+ def date_time=(value)
89
+ if @added_content
90
+ @date_time = value&.to_datetime || DateTime.new
91
+ if time?
92
+ dom_element.timepicker('setTime', "#{@date_time.hour}:#{@date_time.min}")
93
+ else
94
+ dom_element.datepicker('setDate', @date_time.to_time)
95
+ end
96
+ else
97
+ @initial_date_time = value
98
+ end
99
+ end
100
+
101
+ # TODO add date, time, year, month, day, hours, minutes, seconds attribute methods
102
+
103
+ def observation_request_to_event_mapping
104
+ {
105
+ 'on_widget_selected' => [
106
+ {
107
+ event: 'change'
108
+ },
109
+ ],
110
+ }
111
+ end
112
+
113
+ def time_button_id
114
+ "#{id}-time-button"
115
+ end
116
+
117
+ def time_button_class
118
+ "#{name}-time-button"
119
+ end
120
+
121
+ def element
122
+ calendar? ? 'div' : 'input'
123
+ end
124
+
125
+ def dom
126
+ @dom ||= html {
127
+ span {
128
+ send(element, type: 'text', id: id, class: name)
129
+ 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?
130
+ }
131
+ }.to_s
132
+ end
133
+
134
+ end
135
+
136
+ # Aliases: `date`, `date_drop_down`, `time`, and `calendar`
137
+ DateProxy = DateTimeProxy
138
+ DateDropDownProxy = DateTimeProxy
139
+ TimeProxy = DateTimeProxy
140
+ CalendarProxy = DateTimeProxy
141
+
142
+ end
143
+
144
+ 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)
@@ -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
@@ -1,30 +1,50 @@
1
1
  require 'glimmer/swt/widget_proxy'
2
+ # require 'glimmer/swt/image_proxy'
2
3
 
3
4
  module Glimmer
4
5
  module SWT
5
6
  class LabelProxy < WidgetProxy
6
- attr_reader :text
7
+ attr_reader :text, :background_image, :image, :alignment
8
+
9
+ def initialize(parent, args)
10
+ super(parent, args)
11
+ self.alignment = [:left, :center, :right].detect {|align| args.detect { |arg| SWTProxy[align] == arg } }
12
+ end
7
13
 
8
14
  def text=(value)
9
15
  @text = value
10
16
  dom_element.html(value)
11
17
  end
12
18
 
19
+ def background_image=(*image_options)
20
+ # TODO consider if there is a difference between background_image and image in label and to have one reuse the other
21
+ # TODO finish implementation
22
+ # @background_image = Glimmer::SWT::ImageProxy.create(*image_options)
23
+ # dom_element.css('background-image', @background_image.image_data.dom_element.src)
24
+ end
25
+
26
+ def image=(*image_options)
27
+ # TODO finish implementation
28
+ # @image = Glimmer::SWT::ImageProxy.create(*image_options)
29
+ # dom_element.css('background-image', @image.image_data.dom_element.src)
30
+ end
31
+
13
32
  def element
14
33
  'label'
15
34
  end
16
-
17
- def alignment
18
- [:left, :center, :right].detect {|value| args.detect { |arg| SWTProxy[value] == arg } }
35
+
36
+ def alignment=(value)
37
+ # TODO consider storing swt value in the future instead
38
+ @alignment = value
39
+ dom_element.css('text-align', @alignment.to_s)
19
40
  end
20
41
 
21
- def dom
42
+ def dom
22
43
  label_text = @text
23
44
  label_id = id
24
- label_style = "text-align: #{alignment};"
25
45
  label_class = name
26
46
  @dom ||= html {
27
- label(id: label_id, style: label_style, class: label_class) {
47
+ label(id: label_id, class: label_class) {
28
48
  label_text
29
49
  }
30
50
  }.to_s
@@ -8,39 +8,92 @@ module Glimmer
8
8
  :args,
9
9
  :horizontal_alignment,
10
10
  :vertical_alignment,
11
+ :horizontal_span,
12
+ :vertical_span,
13
+ :horizontal_indent,
14
+ :vertical_indent,
11
15
  :grab_excess_horizontal_space,
12
16
  :grab_excess_vertical_space,
17
+ :width_hint,
13
18
  :height_hint
14
19
 
15
20
  def initialize(parent, args)
16
21
  @parent = parent
17
22
  @args = args
18
- reapply
23
+ self.horizontal_alignment = @args[0] if @args[0]
24
+ self.vertical_alignment = @args[1] if @args[1]
25
+ self.grab_excess_horizontal_space = @args[2] if @args[2]
26
+ self.grab_excess_vertical_space = @args[3] if @args[3]
27
+ # TODO spread args correctly as per SWT LayoutData API
28
+ # TODO avoid using reapply
29
+ # reapply
30
+ end
31
+
32
+ def width_hint=(width_hint)
33
+ @width_hint = width_hint
34
+ @parent.dom_element.css('width', "#{@width_hint}px")
35
+ # reapply
19
36
  end
20
37
 
21
38
  def height_hint=(height_hint)
22
39
  @height_hint = height_hint
23
- reapply
40
+ @parent.dom_element.css('height', "#{@height_hint}px")
41
+ # reapply
24
42
  end
25
43
 
26
44
  def horizontal_alignment=(horizontal_alignment)
27
45
  @horizontal_alignment = horizontal_alignment
28
- reapply
46
+ return if @horizontal_alignment.nil?
47
+ if @horizontal_alignment == 'fill'
48
+ @parent.dom_element.css('width', '100%') if width_hint.nil?
49
+ else
50
+ @parent.dom_element.css('text-align', @horizontal_alignment)
51
+ end
52
+ # TODO
53
+ # reapply
29
54
  end
30
55
 
31
56
  def vertical_alignment=(vertical_alignment)
32
57
  @vertical_alignment = vertical_alignment
33
- reapply
58
+ # TODO
59
+ # reapply
60
+ end
61
+
62
+ def horizontal_span=(value)
63
+ @horizontal_span = value
64
+ @parent.dom_element.css('grid-column-start', "span #{@horizontal_span}")
65
+ # reapply
66
+ end
67
+
68
+ def vertical_span=(value)
69
+ @vertical_span = value
70
+ @parent.dom_element.css('grid-row-start', "span #{@vertical_span}")
71
+ # reapply
72
+ end
73
+
74
+ def horizontal_indent=(value)
75
+ @horizontal_indent = value
76
+ @parent.dom_element.css('padding-left', @horizontal_indent)
77
+ # reapply
78
+ end
79
+
80
+ def vertical_indent=(value)
81
+ @vertical_indent = value
82
+ @parent.dom_element.css('padding-top', @vertical_indent)
83
+ # reapply
34
84
  end
35
85
 
36
86
  def grab_excess_horizontal_space=(grab_excess_horizontal_space)
37
87
  @grab_excess_horizontal_space = grab_excess_horizontal_space
38
- reapply
88
+ @parent.dom_element.css('width', "100%") if @grab_excess_horizontal_space && width_hint.nil?
89
+ # reapply
39
90
  end
40
91
 
41
92
  def grab_excess_vertical_space=(grab_excess_vertical_space)
42
93
  @grab_excess_vertical_space = grab_excess_vertical_space
43
- reapply
94
+ @parent.dom_element.css('height', "100%") if @grab_excess_vertical_space && height_hint.nil?
95
+ # TODO
96
+ # reapply
44
97
  end
45
98
 
46
99
  def reapply