glimmer-dsl-opal 0.7.0 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +41 -0
  3. data/README.md +290 -53
  4. data/VERSION +1 -1
  5. data/lib/display.rb +31 -0
  6. data/lib/file.rb +29 -0
  7. data/lib/glimmer-dsl-opal.rb +30 -1
  8. data/lib/glimmer-dsl-opal/ext/date.rb +1 -1
  9. data/lib/glimmer-dsl-opal/ext/struct.rb +37 -0
  10. data/lib/glimmer-dsl-opal/samples/elaborate/contact_manager.rb +50 -23
  11. data/lib/glimmer-dsl-opal/samples/elaborate/login.rb +22 -5
  12. data/lib/glimmer-dsl-opal/samples/hello/hello_browser.rb +1 -1
  13. data/lib/glimmer-dsl-opal/samples/hello/hello_button.rb +46 -0
  14. data/lib/glimmer-dsl-opal/samples/hello/hello_custom_shell.rb +7 -7
  15. data/lib/glimmer-dsl-opal/samples/hello/hello_table.rb +5 -5
  16. data/lib/glimmer-dsl-swt.rb +20 -35
  17. data/lib/glimmer/data_binding/table_items_binding.rb +6 -4
  18. data/lib/glimmer/dsl/opal/custom_widget_expression.rb +6 -0
  19. data/lib/glimmer/dsl/opal/widget_expression.rb +6 -2
  20. data/lib/glimmer/swt/combo_proxy.rb +40 -1
  21. data/lib/glimmer/swt/composite_proxy.rb +5 -1
  22. data/lib/glimmer/swt/control_editor.rb +54 -0
  23. data/lib/glimmer/swt/date_time_proxy.rb +66 -1
  24. data/lib/glimmer/swt/font_proxy.rb +4 -4
  25. data/lib/glimmer/swt/grid_layout_proxy.rb +20 -12
  26. data/lib/glimmer/swt/label_proxy.rb +11 -3
  27. data/lib/glimmer/swt/layout_data_proxy.rb +10 -7
  28. data/lib/glimmer/swt/layout_proxy.rb +1 -1
  29. data/lib/glimmer/swt/message_box_proxy.rb +2 -10
  30. data/lib/glimmer/swt/table_column_proxy.rb +9 -0
  31. data/lib/glimmer/swt/table_editor.rb +65 -0
  32. data/lib/glimmer/swt/table_item_proxy.rb +36 -0
  33. data/lib/glimmer/swt/table_proxy.rb +375 -17
  34. data/lib/glimmer/swt/text_proxy.rb +1 -1
  35. data/lib/glimmer/swt/widget_proxy.rb +99 -21
  36. data/lib/glimmer/ui/custom_shell.rb +9 -7
  37. data/lib/os.rb +36 -0
  38. metadata +25 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.5
@@ -0,0 +1,31 @@
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
+ class Display
23
+ class << self
24
+ def setAppName(app_name)
25
+ # No Op in Opal
26
+ end
27
+ def setAppVersion(version)
28
+ # No Op in Opal
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
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
+ class File
23
+ class << self
24
+ def read(*args, &block)
25
+ # TODO implement via asset downloads in the future
26
+ # No Op in Opal
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,24 @@
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
+
1
22
  require 'opal'
2
23
 
3
24
  GLIMMER_DSL_OPAL_ROOT = File.expand_path('../..', __FILE__)
@@ -17,6 +38,10 @@ if RUBY_ENGINE == 'opal'
17
38
  require 'native' # move this to opal-async
18
39
  require 'opal-async'
19
40
  require 'async/ext'
41
+ require 'to_collection'
42
+ require 'os'
43
+ require 'file'
44
+ require 'display'
20
45
  require 'glimmer-dsl-opal/vendor/jquery'
21
46
  require 'glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.min'
22
47
  require 'glimmer-dsl-opal/vendor/jquery-ui-timepicker/jquery.ui.timepicker'
@@ -24,8 +49,10 @@ if RUBY_ENGINE == 'opal'
24
49
  # require 'glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.structure.min.css'
25
50
  # require 'glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.theme.min.css'
26
51
  require 'opal-jquery'
27
- require 'glimmer'
52
+
28
53
  require 'facets/hash/symbolize_keys'
54
+ require 'glimmer-dsl-opal/ext/struct'
55
+ require 'glimmer'
29
56
  require 'glimmer-dsl-opal/ext/exception'
30
57
  require 'glimmer-dsl-opal/ext/date'
31
58
  require 'uri'
@@ -45,6 +72,7 @@ if RUBY_ENGINE == 'opal'
45
72
  require 'glimmer-dsl-xml'
46
73
  require 'glimmer-dsl-css'
47
74
  Element.alias_native :replace_with, :replaceWith
75
+ Element.alias_native :select
48
76
 
49
77
  # Glimmer::Config.loop_max_count = 20
50
78
 
@@ -54,6 +82,7 @@ if RUBY_ENGINE == 'opal'
54
82
  result ||= method == '<<'
55
83
  result ||= method == 'handle'
56
84
  end
85
+
57
86
  else
58
87
  require_relative 'glimmer/engine'
59
88
  end
@@ -45,7 +45,7 @@ class Time
45
45
  alias new_original new
46
46
  def new(*args)
47
47
  if args.size >= 7
48
- puts "Dropped timezone #{args[6]} from Time.new(#{args.map(&:to_s)}) constructor arguments since Opal does not support it!"
48
+ Glimmer::Config.logger.debug "Dropped timezone #{args[6]} from Time.new(#{args.map(&:to_s)}) constructor arguments since Opal does not support it!"
49
49
  args = args[0...6]
50
50
  end
51
51
  new_original(*args)
@@ -0,0 +1,37 @@
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
+ class Struct
23
+ class << self
24
+ alias new_original new
25
+ def new(*args, &block)
26
+ new_original(*args, &block).tap do |struct_class|
27
+ if args.size >= 2 && args.last.is_a?(Hash) && args.last[:keyword_init]
28
+ struct_class.define_method(:initialize) do |struct_class_keyword_args|
29
+ struct_class_keyword_args.each do |attribute, value|
30
+ send("#{attribute}=", value)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -12,41 +12,76 @@ class ContactManager
12
12
  shell {
13
13
  text "Contact Manager"
14
14
  composite {
15
- composite {
16
- grid_layout 2, false
17
- label {text "First &Name: "}
15
+ group {
16
+ grid_layout(2, false) {
17
+ margin_width 0
18
+ margin_height 0
19
+ }
20
+ layout_data :fill, :center, true, false
21
+ text 'Lookup Contacts'
22
+ font height: 24
23
+
24
+ label {
25
+ layout_data :right, :center, false, false
26
+ text "First &Name: "
27
+ font height: 16
28
+ }
18
29
  text {
30
+ layout_data :fill, :center, true, false
19
31
  text bind(@contact_manager_presenter, :first_name)
20
32
  on_key_pressed {|key_event|
21
- @contact_manager_presenter.find if key_event.keyCode == Glimmer::SWT::SWTProxy[:cr]
33
+ @contact_manager_presenter.find if key_event.keyCode == swt(:cr)
22
34
  }
23
35
  }
24
- label {text "&Last Name: "}
36
+
37
+ label {
38
+ layout_data :right, :center, false, false
39
+ text "&Last Name: "
40
+ font height: 16
41
+ }
25
42
  text {
43
+ layout_data :fill, :center, true, false
26
44
  text bind(@contact_manager_presenter, :last_name)
27
45
  on_key_pressed {|key_event|
28
- @contact_manager_presenter.find if key_event.keyCode == Glimmer::SWT::SWTProxy[:cr]
46
+ @contact_manager_presenter.find if key_event.keyCode == swt(:cr)
29
47
  }
30
48
  }
31
- label {text "&Email: "}
49
+
50
+ label {
51
+ layout_data :right, :center, false, false
52
+ text "&Email: "
53
+ font height: 16
54
+ }
32
55
  text {
56
+ layout_data :fill, :center, true, false
33
57
  text bind(@contact_manager_presenter, :email)
34
58
  on_key_pressed {|key_event|
35
- @contact_manager_presenter.find if key_event.keyCode == Glimmer::SWT::SWTProxy[:cr]
59
+ @contact_manager_presenter.find if key_event.keyCode == swt(:cr)
36
60
  }
37
61
  }
62
+
38
63
  composite {
39
- grid_layout 2, false
64
+ row_layout {
65
+ margin_width 0
66
+ margin_height 0
67
+ }
68
+ layout_data(:right, :center, false, false) {
69
+ horizontal_span 2
70
+ }
71
+
40
72
  button {
41
73
  text "&Find"
42
- on_widget_selected {
43
- @contact_manager_presenter.find
74
+ on_widget_selected { @contact_manager_presenter.find }
75
+ on_key_pressed {|key_event|
76
+ @contact_manager_presenter.find if key_event.keyCode == swt(:cr)
44
77
  }
45
78
  }
79
+
46
80
  button {
47
81
  text "&List All"
48
- on_widget_selected {
49
- @contact_manager_presenter.list
82
+ on_widget_selected { @contact_manager_presenter.list }
83
+ on_key_pressed {|key_event|
84
+ @contact_manager_presenter.list if key_event.keyCode == swt(:cr)
50
85
  }
51
86
  }
52
87
  }
@@ -63,25 +98,17 @@ class ContactManager
63
98
  table_column {
64
99
  text "First Name"
65
100
  width 80
66
- on_widget_selected {
67
- @contact_manager_presenter.toggle_sort(:first_name)
68
- }
69
101
  }
70
102
  table_column {
71
103
  text "Last Name"
72
104
  width 80
73
- on_widget_selected {
74
- @contact_manager_presenter.toggle_sort(:last_name)
75
- }
76
105
  }
77
106
  table_column {
78
107
  text "Email"
79
108
  width 200
80
- on_widget_selected {
81
- @contact_manager_presenter.toggle_sort(:email)
82
- }
83
109
  }
84
- items bind(@contact_manager_presenter, :results), column_properties(:first_name, :last_name, :email)
110
+ items bind(@contact_manager_presenter, :results),
111
+ column_properties(:first_name, :last_name, :email)
85
112
  on_mouse_up { |event|
86
113
  table_proxy.edit_table_item(event.table_item, event.column_index)
87
114
  }
@@ -1,6 +1,5 @@
1
1
  require "observer"
2
2
 
3
- #Presents login screen data
4
3
  class LoginPresenter
5
4
 
6
5
  attr_accessor :user_name
@@ -16,10 +15,13 @@ class LoginPresenter
16
15
  def status=(status)
17
16
  @status = status
18
17
 
19
- #TODO add feature to bind dependent properties to master property (2017-07-25 nested data binding)
20
18
  notify_observers("logged_in")
21
19
  notify_observers("logged_out")
22
20
  end
21
+
22
+ def valid?
23
+ !@user_name.to_s.strip.empty? && !@password.to_s.strip.empty?
24
+ end
23
25
 
24
26
  def logged_in
25
27
  self.status == "Logged In"
@@ -30,6 +32,7 @@ class LoginPresenter
30
32
  end
31
33
 
32
34
  def login
35
+ return unless valid?
33
36
  self.status = "Logged In"
34
37
  end
35
38
 
@@ -41,7 +44,6 @@ class LoginPresenter
41
44
 
42
45
  end
43
46
 
44
- #Login screen
45
47
  class Login
46
48
  include Glimmer
47
49
 
@@ -53,15 +55,21 @@ class Login
53
55
  grid_layout 2, false #two columns with differing widths
54
56
 
55
57
  label { text "Username:" } # goes in column 1
56
- text { # goes in column 2
58
+ @user_name_text = text { # goes in column 2
57
59
  text bind(presenter, :user_name)
58
60
  enabled bind(presenter, :logged_out)
61
+ on_key_pressed { |event|
62
+ @password_text.set_focus if event.keyCode == swt(:cr)
63
+ }
59
64
  }
60
65
 
61
66
  label { text "Password:" }
62
- text(:password, :border) {
67
+ @password_text = text(:password, :border) {
63
68
  text bind(presenter, :password)
64
69
  enabled bind(presenter, :logged_out)
70
+ on_key_pressed { |event|
71
+ presenter.login if event.keyCode == swt(:cr)
72
+ }
65
73
  }
66
74
 
67
75
  label { text "Status:" }
@@ -71,12 +79,21 @@ class Login
71
79
  text "Login"
72
80
  enabled bind(presenter, :logged_out)
73
81
  on_widget_selected { presenter.login }
82
+ on_key_pressed { |event|
83
+ presenter.login if event.keyCode == swt(:cr)
84
+ }
74
85
  }
75
86
 
76
87
  button {
77
88
  text "Logout"
78
89
  enabled bind(presenter, :logged_in)
79
90
  on_widget_selected { presenter.logout }
91
+ on_key_pressed { |event|
92
+ if event.keyCode == swt(:cr)
93
+ presenter.logout
94
+ @user_name_text.set_focus
95
+ end
96
+ }
80
97
  }
81
98
  }
82
99
  }
@@ -3,6 +3,6 @@ include Glimmer
3
3
  shell {
4
4
  minimum_size 1024, 860
5
5
  browser {
6
- url 'http://brightonresort.com/about'
6
+ url 'https://brightonresort.com/about'
7
7
  }
8
8
  }.open
@@ -0,0 +1,46 @@
1
+ # Copyright (c) 2007-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
+ class HelloButton
23
+ include Glimmer
24
+
25
+ attr_accessor :count
26
+
27
+ def initialize
28
+ @count = 0
29
+ end
30
+
31
+ def launch
32
+ shell {
33
+ text 'Hello, Button!'
34
+
35
+ button {
36
+ text bind(self, :count) {|value| "Click To Increment: #{value} "}
37
+
38
+ on_widget_selected {
39
+ self.count += 1
40
+ }
41
+ }
42
+ }.open
43
+ end
44
+ end
45
+
46
+ HelloButton.new.launch
@@ -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 @@ require 'date'
26
26
  class EmailShell
27
27
  include Glimmer::UI::CustomShell
28
28
 
29
- # multiple options without default values
29
+ # multiple options without default values
30
30
  options :date, :subject, :from, :message
31
31
 
32
32
  # single option with default value
@@ -41,7 +41,7 @@ class EmailShell
41
41
  shell(swt_style) {
42
42
  grid_layout(2, false)
43
43
 
44
- text subject
44
+ text subject
45
45
 
46
46
  label {
47
47
  text 'Date:'
@@ -78,7 +78,7 @@ class EmailShell
78
78
  }
79
79
 
80
80
  background :white
81
- text message
81
+ text message
82
82
  }
83
83
  }
84
84
  }
@@ -149,7 +149,7 @@ class HelloCustomShell
149
149
  }
150
150
  }
151
151
  }.open
152
- end
152
+ end
153
153
  end
154
154
 
155
155
  HelloCustomShell.new.launch