glimmer-dsl-opal 0.5.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -0
  3. data/README.md +390 -29
  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 +73 -8
  19. data/lib/glimmer-dsl-opal/ext/date.rb +49 -3
  20. data/lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb +23 -0
  21. data/lib/glimmer-dsl-opal/samples/hello/hello_combo.rb +5 -5
  22. data/lib/glimmer-dsl-opal/samples/hello/hello_date_time.rb +63 -0
  23. data/lib/glimmer-dsl-opal/samples/hello/hello_list_single_selection.rb +1 -1
  24. data/lib/glimmer-dsl-opal/samples/hello/hello_table.rb +283 -0
  25. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/GPL-LICENSE.txt +278 -0
  26. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/MIT-LICENSE.txt +20 -0
  27. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/jquery.ui.timepicker.css +57 -0
  28. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/jquery.ui.timepicker.js +1496 -0
  29. data/lib/glimmer-dsl-opal/vendor/jquery-ui/AUTHORS.txt +333 -0
  30. data/lib/glimmer-dsl-opal/vendor/jquery-ui/LICENSE.txt +43 -0
  31. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_444444_256x240.png +0 -0
  32. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_555555_256x240.png +0 -0
  33. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_777620_256x240.png +0 -0
  34. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_777777_256x240.png +0 -0
  35. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_cc0000_256x240.png +0 -0
  36. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_ffffff_256x240.png +0 -0
  37. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.min.css +7 -0
  38. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.min.js +13 -0
  39. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.structure.min.css +5 -0
  40. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.theme.min.css +5 -0
  41. data/lib/glimmer-dsl-opal/vendor/jquery-ui/package.json +74 -0
  42. data/lib/glimmer-dsl-swt.rb +20 -35
  43. data/lib/glimmer/data_binding/table_items_binding.rb +31 -18
  44. data/lib/glimmer/dsl/opal/block_property_expression.rb +41 -0
  45. data/lib/glimmer/dsl/opal/custom_widget_expression.rb +1 -1
  46. data/lib/glimmer/dsl/opal/dsl.rb +2 -0
  47. data/lib/glimmer/dsl/opal/shell_expression.rb +7 -2
  48. data/lib/glimmer/dsl/opal/widget_expression.rb +10 -1
  49. data/lib/glimmer/engine.rb +9 -0
  50. data/lib/glimmer/swt.rb +3 -3
  51. data/lib/glimmer/swt/button_proxy.rb +5 -5
  52. data/lib/glimmer/swt/checkbox_proxy.rb +1 -0
  53. data/lib/glimmer/swt/color_proxy.rb +45 -45
  54. data/lib/glimmer/swt/combo_proxy.rb +2 -2
  55. data/lib/glimmer/swt/composite_proxy.rb +7 -3
  56. data/lib/glimmer/swt/control_editor.rb +53 -0
  57. data/lib/glimmer/swt/date_time_proxy.rb +145 -0
  58. data/lib/glimmer/swt/display_proxy.rb +6 -2
  59. data/lib/glimmer/swt/fill_layout_proxy.rb +1 -1
  60. data/lib/glimmer/swt/label_proxy.rb +2 -2
  61. data/lib/glimmer/swt/layout_data_proxy.rb +8 -8
  62. data/lib/glimmer/swt/layout_proxy.rb +5 -5
  63. data/lib/glimmer/swt/list_proxy.rb +2 -2
  64. data/lib/glimmer/swt/make_shift_shell_proxy.rb +4 -4
  65. data/lib/glimmer/swt/message_box_proxy.rb +10 -8
  66. data/lib/glimmer/swt/property_owner.rb +2 -2
  67. data/lib/glimmer/swt/radio_proxy.rb +1 -0
  68. data/lib/glimmer/swt/row_layout_proxy.rb +1 -1
  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 +42 -7
  75. data/lib/glimmer/swt/table_proxy.rb +575 -20
  76. data/lib/glimmer/swt/text_proxy.rb +50 -2
  77. data/lib/glimmer/swt/widget_proxy.rb +120 -23
  78. data/lib/glimmer/ui/custom_widget.rb +8 -8
  79. data/lib/net/http.rb +1 -5
  80. data/lib/uri.rb +3 -3
  81. metadata +45 -9
  82. 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
 
@@ -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,53 @@
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
+ ATTRIBUTES = [:grabHorizontal, :grabVertical, :horizontalAlignment, :verticalAlignment, :minimumWidth, :minimumHeight]
27
+ attr_accessor *ATTRIBUTES
28
+ ATTRIBUTES.each do |attribute|
29
+ alias_method attribute.underscore, attribute
30
+ alias_method "#{attribute.underscore}=", "#{attribute}="
31
+ end
32
+
33
+ # TODO consider supporting a java_attr_accessor to get around having to generate all the aliases manually
34
+ attr_accessor :editor
35
+ alias getEditor editor
36
+ alias get_editor editor
37
+ alias setEditor editor=
38
+ alias set_editor editor=
39
+
40
+ # TODO implement `#layout` method if needed
41
+
42
+ attr_reader :composite
43
+
44
+ def initialize(composite)
45
+ @composite = composite
46
+ end
47
+
48
+ # TODO implement showing editor for composite or canvas
49
+ # def editor=(widget)
50
+ # end
51
+ end
52
+ end
53
+ 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
@@ -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
 
@@ -4,14 +4,14 @@ module Glimmer
4
4
  module SWT
5
5
  class LayoutDataProxy
6
6
  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,
7
+ attr_reader :parent,
8
+ :args,
9
+ :horizontal_alignment,
10
+ :vertical_alignment,
11
+ :horizontal_span,
12
+ :vertical_span,
13
+ :horizontal_indent,
14
+ :vertical_indent,
15
15
  :grab_excess_horizontal_space,
16
16
  :grab_excess_vertical_space,
17
17
  :width_hint,
@@ -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
@@ -6,8 +6,8 @@ module Glimmer
6
6
  ITEM_EMPTY = '_____'
7
7
  attr_reader :items, :selection
8
8
 
9
- def initialize(parent, args)
10
- super(parent, args)
9
+ def initialize(parent, args, block)
10
+ super(parent, args, block)
11
11
  @selection = []
12
12
  end
13
13
 
@@ -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
@@ -26,7 +26,7 @@ module Glimmer
26
26
  # No Op
27
27
  end
28
28
 
29
- def add_child(child)
29
+ def post_initialize_child(child)
30
30
  # No Op
31
31
  end
32
32
 
@@ -1,14 +1,16 @@
1
1
  require 'glimmer/swt/widget_proxy'
2
+ require 'glimmer/swt/display_proxy'
2
3
 
3
4
  module Glimmer
4
5
  module SWT
5
6
  class MessageBoxProxy < WidgetProxy
6
7
  attr_reader :text, :message
7
8
 
8
- def initialize(parent, args)
9
+ def initialize(parent, args, block)
9
10
  i = 0
10
- @parent = parent
11
+ @parent = parent || DisplayProxy.instance.shells.first
11
12
  @args = args
13
+ @block = block
12
14
  @children = Set.new
13
15
  @enabled = true
14
16
  content do
@@ -37,7 +39,7 @@ module Glimmer
37
39
  end
38
40
 
39
41
  def open
40
- document.add_child(self)
42
+ document.post_initialize_child(self)
41
43
  end
42
44
 
43
45
  def hide
@@ -53,11 +55,11 @@ module Glimmer
53
55
  end
54
56
 
55
57
  def selector
56
- super + ' .close'
58
+ super + ' .close'
57
59
  end
58
60
 
59
61
  def listener_path
60
- path + ' .close'
62
+ path + ' .close'
61
63
  end
62
64
 
63
65
  def observation_request_to_event_mapping
@@ -66,7 +68,7 @@ module Glimmer
66
68
  event: 'click'
67
69
  },
68
70
  }
69
- end
71
+ end
70
72
 
71
73
  def style_dom_modal_css
72
74
  <<~CSS
@@ -119,11 +121,11 @@ module Glimmer
119
121
  modal_text = text
120
122
  modal_message = message
121
123
  modal_class = ['modal', name].join(' ')
122
- @dom ||= html {
124
+ @dom ||= html {
123
125
  div(id: modal_id, style: modal_style, class: modal_class) {
124
126
  style(class: 'modal-style') {
125
127
  style_dom_modal_css #.split("\n").map(&:strip).join(' ')
126
- }
128
+ }
127
129
  div(class: 'modal-content') {
128
130
  header(class: 'text') {
129
131
  modal_text
@@ -7,7 +7,7 @@ module Glimmer
7
7
  end
8
8
 
9
9
  def set_attribute(attribute_name, *args)
10
- send(attribute_setter(attribute_name), *args) unless send(attribute_getter(attribute_name)) == args.first
10
+ send(attribute_setter(attribute_name), *args) unless args.size == 1 && send(attribute_getter(attribute_name)) == args.first
11
11
  end
12
12
 
13
13
  def attribute_setter(attribute_name)
@@ -16,7 +16,7 @@ module Glimmer
16
16
 
17
17
  def attribute_getter(attribute_name)
18
18
  attribute_name.to_s.underscore
19
- end
19
+ end
20
20
  end
21
21
  end
22
22
  end