glimmer-dsl-swt 0.6.1 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -2
  3. data/VERSION +1 -1
  4. data/bin/girb +1 -1
  5. data/bin/glimmer +5 -1
  6. data/icons/scaffold_app.png +0 -0
  7. data/lib/ext/glimmer/config.rb +13 -1
  8. data/lib/glimmer-dsl-swt.rb +5 -9
  9. data/lib/glimmer/Rakefile +5 -0
  10. data/lib/glimmer/data_binding/table_items_binding.rb +4 -1
  11. data/lib/glimmer/dsl/swt/cursor_expression.rb +1 -4
  12. data/lib/glimmer/dsl/swt/dsl.rb +1 -0
  13. data/lib/glimmer/dsl/swt/font_expression.rb +3 -1
  14. data/lib/glimmer/dsl/swt/image_expression.rb +21 -0
  15. data/lib/glimmer/dsl/swt/message_box_expression.rb +9 -1
  16. data/lib/glimmer/dsl/swt/widget_expression.rb +7 -7
  17. data/lib/glimmer/launcher.rb +59 -20
  18. data/lib/glimmer/package.rb +26 -9
  19. data/lib/glimmer/rake_task.rb +115 -5
  20. data/lib/glimmer/scaffold.rb +65 -32
  21. data/lib/glimmer/swt/display_proxy.rb +13 -2
  22. data/lib/glimmer/swt/image_proxy.rb +16 -23
  23. data/lib/glimmer/swt/layout_proxy.rb +2 -0
  24. data/lib/glimmer/swt/message_box_proxy.rb +23 -5
  25. data/lib/glimmer/swt/scrolled_composite_proxy.rb +6 -11
  26. data/lib/glimmer/swt/shell_proxy.rb +0 -1
  27. data/lib/glimmer/swt/table_proxy.rb +60 -2
  28. data/lib/glimmer/swt/widget_proxy.rb +72 -18
  29. data/samples/elaborate/contact_manager.rb +121 -0
  30. data/samples/elaborate/contact_manager/contact.rb +11 -0
  31. data/samples/elaborate/contact_manager/contact_manager_presenter.rb +26 -0
  32. data/samples/elaborate/contact_manager/contact_repository.rb +244 -0
  33. data/samples/elaborate/login.rb +108 -0
  34. data/samples/elaborate/tic_tac_toe.rb +55 -0
  35. data/samples/elaborate/tic_tac_toe/board.rb +124 -0
  36. data/samples/elaborate/tic_tac_toe/cell.rb +27 -0
  37. data/samples/elaborate/user_profile.rb +55 -0
  38. data/samples/hello/hello_browser.rb +8 -0
  39. data/samples/hello/hello_combo.rb +38 -0
  40. data/samples/hello/hello_computed.rb +69 -0
  41. data/samples/hello/hello_computed/contact.rb +21 -0
  42. data/samples/hello/hello_drag_and_drop.rb +29 -0
  43. data/samples/hello/hello_list_multi_selection.rb +48 -0
  44. data/samples/hello/hello_list_single_selection.rb +37 -0
  45. data/samples/hello/hello_menu_bar.rb +64 -0
  46. data/samples/hello/hello_message_box.rb +15 -0
  47. data/samples/hello/hello_pop_up_context_menu.rb +36 -0
  48. data/samples/hello/hello_tab.rb +24 -0
  49. data/samples/hello/hello_world.rb +8 -0
  50. metadata +66 -8
@@ -22,21 +22,40 @@ module Glimmer
22
22
  include Packages
23
23
 
24
24
  DEFAULT_STYLES = {
25
- "text" => [:border],
26
- "table" => [:virtual, :border, :full_selection],
27
- "tree" => [:virtual, :border, :h_scroll, :v_scroll],
28
- "spinner" => [:border],
29
- "styled_text" => [:border],
30
- "list" => [:border, :v_scroll],
31
- "button" => [:push],
32
- "menu_item" => [:push],
33
- "drag_source" => [:drop_copy],
34
- "drop_target" => [:drop_copy],
25
+ "arrow" => [:arrow],
26
+ "button" => [:push],
27
+ "checkbox" => [:check],
28
+ "check" => [:check],
29
+ "drag_source" => [:drop_copy],
30
+ "drop_target" => [:drop_copy],
31
+ "list" => [:border, :v_scroll],
32
+ "menu_item" => [:push],
33
+ "radio" => [:radio],
34
+ "scrolled_composite" => [:border, :h_scroll, :v_scroll],
35
+ "spinner" => [:border],
36
+ "styled_text" => [:border],
37
+ "table" => [:virtual, :border, :full_selection],
38
+ "text" => [:border],
39
+ "toggle" => [:toggle],
40
+ "tree" => [:virtual, :border, :h_scroll, :v_scroll],
35
41
  }
36
42
 
37
43
  DEFAULT_INITIALIZERS = {
38
44
  "composite" => lambda do |composite|
39
- composite.setLayout(GridLayout.new)
45
+ layout = GridLayout.new
46
+ layout.marginWidth = 15
47
+ layout.marginHeight = 15
48
+ composite.layout = layout
49
+ end,
50
+ "scrolled_composite" => lambda do |scrolled_composite|
51
+ scrolled_composite.expand_horizontal = true
52
+ scrolled_composite.expand_vertical = true
53
+ end,
54
+ "shell" => lambda do |shell|
55
+ layout = FillLayout.new
56
+ layout.marginWidth = 15
57
+ layout.marginHeight = 15
58
+ shell.layout = layout
40
59
  end,
41
60
  "table" => lambda do |table|
42
61
  table.setHeaderVisible(true)
@@ -49,19 +68,47 @@ module Glimmer
49
68
  group.setLayout(GridLayout.new)
50
69
  end,
51
70
  }
71
+
72
+ class << self
73
+ def create(keyword, parent, args)
74
+ widget_proxy_class(keyword).new(keyword, parent, args)
75
+ end
76
+
77
+ def widget_proxy_class(keyword)
78
+ begin
79
+ class_name = "#{keyword.camelcase(:upper)}Proxy".to_sym
80
+ Glimmer::SWT.const_get(class_name)
81
+ rescue
82
+ Glimmer::SWT::WidgetProxy
83
+ end
84
+ end
85
+
86
+ def underscored_widget_name(swt_widget)
87
+ swt_widget.class.name.split(/::|\./).last.underscore
88
+ end
89
+ end
52
90
 
53
- attr_reader :swt_widget, :drag_source_proxy, :drop_target_proxy, :drag_source_style, :drag_source_transfer, :drop_target_transfer
91
+ attr_reader :parent_proxy, :swt_widget, :drag_source_proxy, :drop_target_proxy, :drag_source_style, :drag_source_transfer, :drop_target_transfer
54
92
 
55
93
  # Initializes a new SWT Widget
56
94
  #
57
95
  # Styles is a comma separate list of symbols representing SWT styles in lower case
58
- def initialize(underscored_widget_name, parent, args)
59
- styles, extra_options = extract_args(underscored_widget_name, args)
60
- swt_widget_class = self.class.swt_widget_class_for(underscored_widget_name)
61
- @swt_widget = swt_widget_class.new(parent.swt_widget, style(underscored_widget_name, styles), *extra_options)
62
- @swt_widget.set_data('proxy', self)
96
+ def initialize(*init_args, swt_widget: nil)
97
+ if swt_widget.nil?
98
+ underscored_widget_name, parent, args = init_args
99
+ @parent_proxy = parent
100
+ styles, extra_options = extract_args(underscored_widget_name, args)
101
+ swt_widget_class = self.class.swt_widget_class_for(underscored_widget_name)
102
+ @swt_widget = swt_widget_class.new(@parent_proxy.swt_widget, style(underscored_widget_name, styles), *extra_options)
103
+ else
104
+ @swt_widget = swt_widget
105
+ underscored_widget_name = self.class.underscored_widget_name(@swt_widget)
106
+ parent_proxy_class = self.class.widget_proxy_class(self.class.underscored_widget_name(@swt_widget.parent))
107
+ @parent_proxy = parent_proxy_class.new(swt_widget: swt_widget.parent)
108
+ end
109
+ @swt_widget.set_data('proxy', self)
63
110
  DEFAULT_INITIALIZERS[underscored_widget_name]&.call(@swt_widget)
64
- parent.post_initialize_child(self)
111
+ @parent_proxy.post_initialize_child(self)
65
112
  end
66
113
 
67
114
  # Subclasses may override to perform post initialization work on an added child
@@ -69,6 +116,11 @@ module Glimmer
69
116
  # No Op by default
70
117
  end
71
118
 
119
+ # Subclasses may override to perform post add_content work
120
+ def post_add_content
121
+ # No Op by default
122
+ end
123
+
72
124
  def extract_args(underscored_widget_name, args)
73
125
  @arg_extractor_mapping ||= {
74
126
  'menu_item' => lambda do |args|
@@ -264,6 +316,7 @@ module Glimmer
264
316
 
265
317
  # This supports widgets in and out of basic SWT
266
318
  def self.swt_widget_class_for(underscored_widget_name)
319
+ underscored_widget_name = 'button' if %w[radio checkbox check toggle arrow].include?(underscored_widget_name)
267
320
  swt_widget_name = underscored_widget_name.camelcase(:upper)
268
321
  swt_widget_class = eval(swt_widget_name)
269
322
  unless swt_widget_class.ancestors.include?(org.eclipse.swt.widgets.Widget)
@@ -405,6 +458,7 @@ module Glimmer
405
458
  rescue => e
406
459
  Glimmer::Config.logger.debug {"Neither WidgetProxy nor #{swt_widget.class.name} can handle the method ##{method}"}
407
460
  super
461
+ # TODO consider get_attribute too
408
462
  end
409
463
 
410
464
  def respond_to?(method, *args, &block)
@@ -0,0 +1,121 @@
1
+ require_relative "contact_manager/contact_manager_presenter"
2
+
3
+ class ContactManager
4
+ include Glimmer
5
+
6
+ def initialize
7
+ @contact_manager_presenter = ContactManagerPresenter.new
8
+ @contact_manager_presenter.list
9
+ end
10
+
11
+ def launch
12
+ shell {
13
+ text "Contact Manager"
14
+ composite {
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
+ }
29
+ text {
30
+ layout_data :fill, :center, true, false
31
+ text bind(@contact_manager_presenter, :first_name)
32
+ on_key_pressed {|key_event|
33
+ @contact_manager_presenter.find if key_event.keyCode == swt(:cr)
34
+ }
35
+ }
36
+
37
+ label {
38
+ layout_data :right, :center, false, false
39
+ text "&Last Name: "
40
+ font height: 16
41
+ }
42
+ text {
43
+ layout_data :fill, :center, true, false
44
+ text bind(@contact_manager_presenter, :last_name)
45
+ on_key_pressed {|key_event|
46
+ @contact_manager_presenter.find if key_event.keyCode == swt(:cr)
47
+ }
48
+ }
49
+
50
+ label {
51
+ layout_data :right, :center, false, false
52
+ text "&Email: "
53
+ font height: 16
54
+ }
55
+ text {
56
+ layout_data :fill, :center, true, false
57
+ text bind(@contact_manager_presenter, :email)
58
+ on_key_pressed {|key_event|
59
+ @contact_manager_presenter.find if key_event.keyCode == swt(:cr)
60
+ }
61
+ }
62
+
63
+ composite {
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
+
72
+ button {
73
+ text "&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)
77
+ }
78
+ }
79
+
80
+ button {
81
+ text "&List All"
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)
85
+ }
86
+ }
87
+ }
88
+ }
89
+
90
+ table(:multi) { |table_proxy|
91
+ layout_data {
92
+ horizontal_alignment :fill
93
+ vertical_alignment :fill
94
+ grab_excess_horizontal_space true
95
+ grab_excess_vertical_space true
96
+ height_hint 200
97
+ }
98
+ table_column {
99
+ text "First Name"
100
+ width 80
101
+ }
102
+ table_column {
103
+ text "Last Name"
104
+ width 80
105
+ }
106
+ table_column {
107
+ text "Email"
108
+ width 200
109
+ }
110
+ items bind(@contact_manager_presenter, :results),
111
+ column_properties(:first_name, :last_name, :email)
112
+ on_mouse_up { |event|
113
+ table_proxy.edit_table_item(event.table_item, event.column_index)
114
+ }
115
+ }
116
+ }
117
+ }.open
118
+ end
119
+ end
120
+
121
+ ContactManager.new.launch
@@ -0,0 +1,11 @@
1
+ class ContactManager
2
+ class Contact
3
+ attr_accessor :first_name, :last_name, :email
4
+
5
+ def initialize(attribute_map)
6
+ @first_name = attribute_map[:first_name]
7
+ @last_name = attribute_map[:last_name]
8
+ @email = attribute_map[:email]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ require_relative "contact_repository"
2
+
3
+ class ContactManager
4
+ class ContactManagerPresenter
5
+ attr_accessor :results
6
+ @@contact_attributes = [:first_name, :last_name, :email]
7
+ @@contact_attributes.each {|attribute_name| attr_accessor attribute_name}
8
+
9
+ def initialize(contact_repository = nil)
10
+ @contact_repository = contact_repository || ContactRepository.new
11
+ @results = []
12
+ end
13
+
14
+ def list
15
+ self.results = @contact_repository.find({})
16
+ end
17
+
18
+ def find
19
+ filter_map = {}
20
+ @@contact_attributes.each do |attribute_name|
21
+ filter_map[attribute_name] = self.send(attribute_name) if self.send(attribute_name)
22
+ end
23
+ self.results = @contact_repository.find(filter_map)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,244 @@
1
+ require_relative "contact"
2
+
3
+ class ContactManager
4
+ class ContactRepository
5
+ NAMES_FIRST = %w[
6
+ Liam
7
+ Noah
8
+ William
9
+ James
10
+ Oliver
11
+ Benjamin
12
+ Elijah
13
+ Lucas
14
+ Mason
15
+ Logan
16
+ Alexander
17
+ Ethan
18
+ Jacob
19
+ Michael
20
+ Daniel
21
+ Henry
22
+ Jackson
23
+ Sebastian
24
+ Aiden
25
+ Matthew
26
+ Samuel
27
+ David
28
+ Joseph
29
+ Carter
30
+ Owen
31
+ Wyatt
32
+ John
33
+ Jack
34
+ Luke
35
+ Jayden
36
+ Dylan
37
+ Grayson
38
+ Levi
39
+ Isaac
40
+ Gabriel
41
+ Julian
42
+ Mateo
43
+ Anthony
44
+ Jaxon
45
+ Lincoln
46
+ Joshua
47
+ Christopher
48
+ Andrew
49
+ Theodore
50
+ Caleb
51
+ Ryan
52
+ Asher
53
+ Nathan
54
+ Thomas
55
+ Leo
56
+ Isaiah
57
+ Charles
58
+ Josiah
59
+ Hudson
60
+ Christian
61
+ Hunter
62
+ Connor
63
+ Eli
64
+ Ezra
65
+ Aaron
66
+ Landon
67
+ Adrian
68
+ Jonathan
69
+ Nolan
70
+ Jeremiah
71
+ Easton
72
+ Elias
73
+ Colton
74
+ Cameron
75
+ Carson
76
+ Robert
77
+ Angel
78
+ Maverick
79
+ Nicholas
80
+ Dominic
81
+ Jaxson
82
+ Greyson
83
+ Adam
84
+ Ian
85
+ Austin
86
+ Santiago
87
+ Jordan
88
+ Cooper
89
+ Brayden
90
+ Roman
91
+ Evan
92
+ Ezekiel
93
+ Xaviar
94
+ Jose
95
+ Jace
96
+ Jameson
97
+ Leonardo
98
+ Axel
99
+ Everett
100
+ Kayden
101
+ Miles
102
+ Sawyer
103
+ Jason
104
+ Emma
105
+ Olivia
106
+ Ava
107
+ Isabella
108
+ Sophia
109
+ Charlotte
110
+ Mia
111
+ Amelia
112
+ Harper
113
+ Evelyn
114
+ Abigail
115
+ Emily
116
+ Elizabeth
117
+ Mila
118
+ Ella
119
+ Avery
120
+ Sofia
121
+ Camila
122
+ Aria
123
+ Scarlett
124
+ Victoria
125
+ Madison
126
+ Luna
127
+ Grace
128
+ Chloe
129
+ Penelope
130
+ Layla
131
+ Riley
132
+ Zoey
133
+ Nora
134
+ Lily
135
+ Eleanor
136
+ Hannah
137
+ Lillian
138
+ Addison
139
+ Aubrey
140
+ Ellie
141
+ Stella
142
+ Natalie
143
+ Zoe
144
+ Leah
145
+ Hazel
146
+ Violet
147
+ Aurora
148
+ Savannah
149
+ Audrey
150
+ Brooklyn
151
+ Bella
152
+ Claire
153
+ Skylar
154
+ Lucy
155
+ Paisley
156
+ Everly
157
+ Anna
158
+ Caroline
159
+ Nova
160
+ Genesis
161
+ Emilia
162
+ Kennedy
163
+ Samantha
164
+ Maya
165
+ Willow
166
+ Kinsley
167
+ Naomi
168
+ Aaliyah
169
+ Elena
170
+ Sarah
171
+ Ariana
172
+ Allison
173
+ Gabriella
174
+ Alice
175
+ Madelyn
176
+ Cora
177
+ Ruby
178
+ Eva
179
+ Serenity
180
+ Autumn
181
+ Adeline
182
+ Hailey
183
+ Gianna
184
+ Valentina
185
+ Isla
186
+ Eliana
187
+ Quinn
188
+ Nevaeh
189
+ Ivy
190
+ Sadie
191
+ Piper
192
+ Lydia
193
+ Alexa
194
+ Josephine
195
+ Emery
196
+ Julia
197
+ Delilah
198
+ Arianna
199
+ Vivian
200
+ Kaylee
201
+ Sophie
202
+ Brielle
203
+ Madeline
204
+ ]
205
+ NAMES_LAST = %w[
206
+ Smith
207
+ Johnson
208
+ Williams
209
+ Brown
210
+ Jones
211
+ Miller
212
+ Davis
213
+ Wilson
214
+ Anderson
215
+ Taylor
216
+ ]
217
+ def initialize(contacts = nil)
218
+ @contacts = contacts || 1000.times.map do |n|
219
+ random_first_name_index = (rand*NAMES_FIRST.size).to_i
220
+ random_last_name_index = (rand*NAMES_LAST.size).to_i
221
+ first_name = NAMES_FIRST[random_first_name_index]
222
+ last_name = NAMES_LAST[random_last_name_index]
223
+ email = "#{first_name}@#{last_name}.com".downcase
224
+ Contact.new(
225
+ first_name: first_name,
226
+ last_name: last_name,
227
+ email: email
228
+ )
229
+ end
230
+ end
231
+
232
+ def find(attribute_filter_map)
233
+ @contacts.find_all do |contact|
234
+ match = true
235
+ attribute_filter_map.keys.each do |attribute_name|
236
+ contact_value = contact.send(attribute_name).downcase
237
+ filter_value = attribute_filter_map[attribute_name].downcase
238
+ match = false unless contact_value.match(filter_value)
239
+ end
240
+ match
241
+ end
242
+ end
243
+ end
244
+ end