glimmer 0.3.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/README.markdown +94 -32
  3. data/lib/glimmer.rb +4 -6
  4. data/lib/glimmer/command_handler.rb +10 -0
  5. data/lib/glimmer/command_handler_chain_factory.rb +32 -0
  6. data/lib/glimmer/command_handler_chain_link.rb +21 -0
  7. data/lib/{command_handlers.rb → glimmer/command_handlers.rb} +21 -17
  8. data/lib/glimmer/command_handlers/bind_command_handler.rb +51 -0
  9. data/lib/glimmer/command_handlers/color_command_handler.rb +26 -0
  10. data/lib/glimmer/command_handlers/combo_selection_data_binding_command_handler.rb +40 -0
  11. data/lib/glimmer/command_handlers/data_binding_command_handler.rb +69 -0
  12. data/lib/glimmer/command_handlers/display_command_handler.rb +16 -0
  13. data/lib/glimmer/command_handlers/list_selection_data_binding_command_handler.rb +45 -0
  14. data/lib/glimmer/command_handlers/models/g_color.rb +34 -0
  15. data/lib/glimmer/command_handlers/models/g_display.rb +26 -0
  16. data/lib/glimmer/command_handlers/models/g_font.rb +62 -0
  17. data/lib/glimmer/command_handlers/models/g_runnable.rb +13 -0
  18. data/lib/glimmer/command_handlers/models/g_shell.rb +27 -0
  19. data/lib/glimmer/command_handlers/models/g_swt.rb +22 -0
  20. data/lib/glimmer/command_handlers/models/g_tab_item_composite.rb +33 -0
  21. data/lib/glimmer/command_handlers/models/g_widget.rb +199 -0
  22. data/lib/glimmer/command_handlers/models/g_widget_listener.rb +11 -0
  23. data/lib/glimmer/command_handlers/models/list_selection_binding.rb +47 -0
  24. data/lib/glimmer/command_handlers/models/model_binding.rb +206 -0
  25. data/lib/glimmer/command_handlers/models/observable.rb +11 -0
  26. data/lib/glimmer/command_handlers/models/observable_array.rb +104 -0
  27. data/lib/glimmer/command_handlers/models/observable_model.rb +105 -0
  28. data/lib/glimmer/command_handlers/models/observer.rb +115 -0
  29. data/lib/glimmer/command_handlers/models/table_items_binding.rb +45 -0
  30. data/lib/glimmer/command_handlers/models/tree_items_binding.rb +49 -0
  31. data/lib/glimmer/command_handlers/models/widget_binding.rb +29 -0
  32. data/lib/glimmer/command_handlers/shell_command_handler.rb +17 -0
  33. data/lib/glimmer/command_handlers/tab_item_command_handler.rb +21 -0
  34. data/lib/glimmer/command_handlers/table_column_properties_data_binding_command_handler.rb +25 -0
  35. data/lib/glimmer/command_handlers/table_items_data_binding_command_handler.rb +30 -0
  36. data/lib/glimmer/command_handlers/tree_items_data_binding_command_handler.rb +29 -0
  37. data/lib/glimmer/command_handlers/tree_properties_data_binding_command_handler.rb +25 -0
  38. data/lib/glimmer/command_handlers/widget_command_handler.rb +22 -0
  39. data/lib/glimmer/command_handlers/widget_listener_command_handler.rb +39 -0
  40. data/lib/glimmer/command_handlers/widget_method_command_handler.rb +21 -0
  41. data/lib/glimmer/parent.rb +7 -0
  42. data/lib/{shine.rb → glimmer/shine.rb} +1 -1
  43. data/lib/glimmer/swt_packages.rb +13 -0
  44. data/lib/{xml_command_handlers.rb → glimmer/xml_command_handlers.rb} +10 -8
  45. data/lib/glimmer/xml_command_handlers/html_command_handler.rb +47 -0
  46. data/lib/glimmer/xml_command_handlers/models/depth_first_search_iterator.rb +19 -0
  47. data/lib/glimmer/xml_command_handlers/models/name_space_visitor.rb +20 -0
  48. data/lib/glimmer/xml_command_handlers/models/node.rb +82 -0
  49. data/lib/glimmer/xml_command_handlers/models/node_visitor.rb +11 -0
  50. data/lib/glimmer/xml_command_handlers/models/xml_visitor.rb +61 -0
  51. data/lib/glimmer/xml_command_handlers/xml_command_handler.rb +20 -0
  52. data/lib/glimmer/xml_command_handlers/xml_name_space_command_handler.rb +33 -0
  53. data/lib/glimmer/xml_command_handlers/xml_tag_command_handler.rb +25 -0
  54. data/lib/glimmer/xml_command_handlers/xml_text_command_handler.rb +21 -0
  55. metadata +53 -54
  56. data/lib/command_handler.rb +0 -8
  57. data/lib/command_handler_chain_factory.rb +0 -30
  58. data/lib/command_handler_chain_link.rb +0 -19
  59. data/lib/command_handlers/bind_command_handler.rb +0 -49
  60. data/lib/command_handlers/color_command_handler.rb +0 -24
  61. data/lib/command_handlers/combo_selection_data_binding_command_handler.rb +0 -38
  62. data/lib/command_handlers/data_binding_command_handler.rb +0 -67
  63. data/lib/command_handlers/list_selection_data_binding_command_handler.rb +0 -43
  64. data/lib/command_handlers/models/block_observer.rb +0 -14
  65. data/lib/command_handlers/models/list_selection_binding.rb +0 -45
  66. data/lib/command_handlers/models/model_binding.rb +0 -205
  67. data/lib/command_handlers/models/observable.rb +0 -9
  68. data/lib/command_handlers/models/observable_array.rb +0 -102
  69. data/lib/command_handlers/models/observable_model.rb +0 -103
  70. data/lib/command_handlers/models/observer.rb +0 -88
  71. data/lib/command_handlers/models/r_color.rb +0 -32
  72. data/lib/command_handlers/models/r_font.rb +0 -60
  73. data/lib/command_handlers/models/r_runnable.rb +0 -11
  74. data/lib/command_handlers/models/r_shell.rb +0 -24
  75. data/lib/command_handlers/models/r_swt.rb +0 -18
  76. data/lib/command_handlers/models/r_tab_item_composite.rb +0 -31
  77. data/lib/command_handlers/models/r_widget.rb +0 -183
  78. data/lib/command_handlers/models/r_widget_listener.rb +0 -9
  79. data/lib/command_handlers/models/table_items_binding.rb +0 -43
  80. data/lib/command_handlers/models/tree_items_binding.rb +0 -47
  81. data/lib/command_handlers/models/widget_binding.rb +0 -27
  82. data/lib/command_handlers/shell_command_handler.rb +0 -15
  83. data/lib/command_handlers/tab_item_command_handler.rb +0 -19
  84. data/lib/command_handlers/table_column_properties_data_binding_command_handler.rb +0 -23
  85. data/lib/command_handlers/table_items_data_binding_command_handler.rb +0 -28
  86. data/lib/command_handlers/tree_items_data_binding_command_handler.rb +0 -27
  87. data/lib/command_handlers/tree_properties_data_binding_command_handler.rb +0 -23
  88. data/lib/command_handlers/widget_command_handler.rb +0 -20
  89. data/lib/command_handlers/widget_listener_command_handler.rb +0 -37
  90. data/lib/command_handlers/widget_method_command_handler.rb +0 -19
  91. data/lib/parent.rb +0 -5
  92. data/lib/string.rb +0 -8
  93. data/lib/swt_packages.rb +0 -11
  94. data/lib/symbol.rb +0 -10
  95. data/lib/xml_command_handlers/html_command_handler.rb +0 -45
  96. data/lib/xml_command_handlers/models/depth_first_search_iterator.rb +0 -17
  97. data/lib/xml_command_handlers/models/name_space_visitor.rb +0 -18
  98. data/lib/xml_command_handlers/models/node.rb +0 -80
  99. data/lib/xml_command_handlers/models/node_visitor.rb +0 -9
  100. data/lib/xml_command_handlers/models/xml_visitor.rb +0 -59
  101. data/lib/xml_command_handlers/xml_command_handler.rb +0 -18
  102. data/lib/xml_command_handlers/xml_name_space_command_handler.rb +0 -31
  103. data/lib/xml_command_handlers/xml_tag_command_handler.rb +0 -23
  104. data/lib/xml_command_handlers/xml_text_command_handler.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 425d16ab524a7ca569aad23a16f90be2d191e30f9718ccc29829eadc4d479b73
4
- data.tar.gz: 5b23ea4769c1921379f6a3314a9e5496e1b339dd3ea43b12bfef58678cf17be2
3
+ metadata.gz: '039508d9d31dec60207c13aa5ab20abe07af71d5e1d06fa2e26694151e06a124'
4
+ data.tar.gz: 402f7855f32fa23a157d044dd5f080b7ab4a9c16c353ed209a14d46565ab2c9b
5
5
  SHA512:
6
- metadata.gz: 5415bc5431a2ea2b4368c58bb97212cf6aea9f2711df08bd7757a5ee9c6eb84931616c082b023039d59dcea8140408e870973bf0043d07607667fa9e12381de6
7
- data.tar.gz: 71678e659abb1776861c6f054520be42631b72e8013f0d5c3bbf399dedf09b9a2e0681155dda4ef327a73d7298a7c4628dd98076cb286ee0a8b2054dcf055c9d
6
+ metadata.gz: 07ae480ae5c8807d663bead2005fd303f53238c3b8684e70b8e87c30341c119faf2a3420e25fa75037cd44019fc8ed7f09f7d0bb58bbe395e8fa353b29a5bbbf
7
+ data.tar.gz: cf4866df36d0fcd4dd75192e246edbf77bde8c63bd741adb5fc5969202415e22430b15091bac5b53a4dd9778f0f15679666d52f2cee2648b49836d1ac8ad4ee0
data/README.markdown CHANGED
@@ -42,7 +42,7 @@ shell {
42
42
  (1..3).each { |row|
43
43
  (1..3).each { |column|
44
44
  button {
45
- layout_data GridData.new(RSwt[:fill], RSwt[:fill], true, true)
45
+ layout_data GridData.new(GSWT[:fill], GSWT[:fill], true, true)
46
46
  text bind(@tic_tac_toe_board.box(row, column), :sign)
47
47
  enabled bind(@tic_tac_toe_board.box(row, column), :empty)
48
48
  on_widget_selected {
@@ -102,14 +102,14 @@ Please follow these instructions to make the `glimmer` command available on your
102
102
 
103
103
  Run this command to install directly:
104
104
  ```
105
- jgem install glimmer -v 0.3.5
105
+ jgem install glimmer -v 0.4.0
106
106
  ```
107
107
 
108
108
  ### Option 2: Bundler
109
109
 
110
110
  Add the following to `Gemfile`:
111
111
  ```
112
- gem 'glimmer', '~> 0.3.5'
112
+ gem 'glimmer', '~> 0.4.0'
113
113
  ```
114
114
 
115
115
  And, then run:
@@ -198,13 +198,13 @@ Glimmer ships with SWT style **smart defaults** so you wouldn't have to set them
198
198
 
199
199
  You may check out all available `SWT` styles here:
200
200
 
201
- https://help.eclipse.org/2019-12/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/SWT.html
201
+ https://help.eclipse.org/2019-12/nftopic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/SWT.html
202
202
 
203
203
  **Final Note** (advanced case outside of standard Glimmer DSL):
204
204
 
205
205
  When building a widget-related SWT object manually (e.g. `GridData.new(...)`), you are expected to use `SWT::CONSTANT` directly or BIT-OR a few SWT constants together like `SWT::BORDER | SWT::V_SCROLL`.
206
206
 
207
- Glimmer facilitates that with `RSwt` class by allowing you to pass multiple styles as an argument array of symbols instead of dealing with BIT-OR. For example: `RSwt[:border, :v_scroll]`
207
+ Glimmer facilitates that with `GSWT` class by allowing you to pass multiple styles as an argument array of symbols instead of dealing with BIT-OR. For example: `GSWT[:border, :v_scroll]`
208
208
 
209
209
  ### Widget Properties
210
210
 
@@ -257,9 +257,9 @@ label {
257
257
  }
258
258
  ```
259
259
 
260
- You may check out all available standard colors in `SWT` over here:
260
+ You may check out all available standard colors in `SWT` over here (having `COLOR_` prefix):
261
261
 
262
- https://help.eclipse.org/2019-12/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/SWT.html
262
+ https://help.eclipse.org/2019-12/nftopic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/SWT.html
263
263
 
264
264
  ### Fonts
265
265
 
@@ -314,36 +314,69 @@ You may learn more about Glimmer's syntax by reading the Eclipse Zone Tutorial m
314
314
 
315
315
  Glimmer comes with `Observer` module, which is used internally for data-binding, but can also be used externally for custom use of the Observer Pattern.
316
316
 
317
- In summary, the class that needs to observe an object, must include Observer and implement `#update(changed_value)` method. The class to be observed doesn't need to do anything. It will automatically be enhanced by Glimmer for observation.
317
+ In summary, the class that needs to observe an object, must include Observer and implement `#call(new_value)` method. The class to be observed doesn't need to do anything. It will automatically be enhanced by Glimmer for observation.
318
318
 
319
- Observers can be a good mechanism for displaying dialog messages with Glimmer (using SWT's `MessageBox`).
320
-
321
- Look at `samples/tictactoe/tic_tac_toe.rb` for an `Observer` dialog message example.
319
+ To register observer, one has to call the `#observe` method and pass in the observable and the property(ies) to observe.
322
320
 
323
321
  ```ruby
324
- observe(@tic_tac_toe_board, "game_status")
322
+ class TicTacToe
323
+ include Glimmer
324
+ include Observer
325
+
326
+ def initialize
327
+ # ...
328
+ observe(@tic_tac_toe_board, "game_status")
329
+ end
330
+
331
+ def call(game_status)
332
+ display_win_message if game_status == TicTacToeBoard::WIN
333
+ display_draw_message if game_status == TicTacToeBoard::DRAW
334
+ end
335
+ # ...
336
+ end
325
337
  ```
326
338
 
339
+ Alternatively, one can use a default Observer::Proc implementation via Observer#proc method:
327
340
  ```ruby
328
- def update(game_status)
329
- display_win_message if game_status == TicTacToeBoard::WIN
330
- display_draw_message if game_status == TicTacToeBoard::DRAW
331
- end
341
+ observer = Observer.proc { |new_value| puts new_value }
342
+ observer.observe(@tic_tac_toe_board, "game_status")
343
+ ```
332
344
 
333
- def display_win_message
334
- display_game_over_message("Player #{@tic_tac_toe_board.winning_sign} has won!")
335
- end
345
+ Observers can be a good mechanism for displaying dialog messages with Glimmer (using SWT's `MessageBox`).
336
346
 
337
- def display_draw_message
338
- display_game_over_message("Draw!")
339
- end
347
+ Look at `samples/tictactoe/tic_tac_toe.rb` for an `Observer` dialog message example (sample below).
340
348
 
341
- def display_game_over_message(message)
342
- message_box = MessageBox.new(@shell.widget)
343
- message_box.setText("Game Over")
344
- message_box.setMessage(message)
345
- message_box.open
346
- @tic_tac_toe_board.reset
349
+ ```ruby
350
+ class TicTacToe
351
+ include Glimmer
352
+ include Observer
353
+
354
+ def initialize
355
+ # ...
356
+ observe(@tic_tac_toe_board, "game_status")
357
+ end
358
+
359
+ def call(game_status)
360
+ display_win_message if game_status == TicTacToeBoard::WIN
361
+ display_draw_message if game_status == TicTacToeBoard::DRAW
362
+ end
363
+
364
+ def display_win_message
365
+ display_game_over_message("Player #{@tic_tac_toe_board.winning_sign} has won!")
366
+ end
367
+
368
+ def display_draw_message
369
+ display_game_over_message("Draw!")
370
+ end
371
+
372
+ def display_game_over_message(message)
373
+ message_box = MessageBox.new(@shell.widget)
374
+ message_box.setText("Game Over")
375
+ message_box.setMessage(message)
376
+ message_box.open
377
+ @tic_tac_toe_board.reset
378
+ end
379
+ # ...
347
380
  end
348
381
  ```
349
382
 
@@ -361,6 +394,10 @@ glimmer samples/hello_world.rb
361
394
 
362
395
  https://www.eclipse.org/swt/docs.php
363
396
 
397
+ Here is the SWT API:
398
+
399
+ https://help.eclipse.org/2019-12/nftopic/org.eclipse.platform.doc.isv/reference/api/index.html
400
+
364
401
  Here is a list of SWT widgets:
365
402
 
366
403
  https://help.eclipse.org/2019-12/topic/org.eclipse.platform.doc.isv/guide/swt_widgets_controls.htm?cp=2_0_7_0_0
@@ -373,7 +410,7 @@ https://wiki.eclipse.org/SWT_Widget_Style_Bits
373
410
 
374
411
  Glimmer automatically imports all SWT Java packages upon adding `include Glimmer` to a class or module.
375
412
 
376
- Still, if you'd like to import manually elsewhere, you may add the following lines to your code:
413
+ Still, if you'd like to import manually elsewhere, you may add the following lines to your code import a SWT Java package using `include_package`:
377
414
 
378
415
  ```ruby
379
416
  include_package 'org.eclipse.swt'
@@ -382,9 +419,15 @@ include_package 'org.eclipse.swt.layout'
382
419
  include_package 'org.eclipse.swt.graphics'
383
420
  ```
384
421
 
385
- This allows you to call Java SWT classes from Ruby without indicating the package explicitly.
422
+ Or only import a specific SWT Java class using `java_import`:
423
+
424
+ ```ruby
425
+ java_import 'org.eclipse.swt.SWT'
426
+ ```
427
+
428
+ This allows you to call SWT Java classes from Ruby without mentioning package namespaces.
386
429
 
387
- For example, `org.eclipse.swt.graphics.Color` becomes `Color`
430
+ For example, after imports, `org.eclipse.swt.graphics.Color` can be referred to by just `Color`
388
431
 
389
432
  ## Girb (Glimmer irb)
390
433
 
@@ -458,9 +501,28 @@ a new component and extend the DSL with it
458
501
  - Avoid disposing display when disposing a shell to allow recycling
459
502
  - Provide a display builder method to use independently of shell
460
503
  - Supported a single computed data binding as a string (not array)
461
- - Disallow use of SWT::CONSTANTs with ORing since it's not intuitive at all
462
504
  - Support data binding translator option via a block
463
505
  - Center windows upon launching
506
+ - Add TruffleRuby support
507
+ - Make Shell automatically use last instantiated Display if not disposed
508
+ - Allow ability to instantiate Display independently of Shell
509
+
510
+ ## Release Notes
511
+
512
+ [RELEASE.md](https://github.com/AndyObtiva/glimmer/blob/master/RELEASE.md)
513
+
514
+ ## Contributing
515
+
516
+ - Clone repo
517
+ - Setup pre-requisites (installing JRuby via RVM on the Mac)
518
+ - cd into project again to activiate RVM glimmer gemset
519
+ - gem install bundler
520
+ - bundle
521
+ - rake # runs specs (ensure they finish successfully)
522
+ - rake install # builds/installs glimmer gem to be able to run samples via (glimmer samples/**)
523
+
524
+ To run a specific spec, run:
525
+ `rake SPEC=spec_file_path`
464
526
 
465
527
  ## Contributors
466
528
 
data/lib/glimmer.rb CHANGED
@@ -7,10 +7,8 @@ require "rubygems"
7
7
  require "facets"
8
8
  require "logger"
9
9
  require "java"
10
- require_relative "string"
11
- require_relative "symbol"
12
- require_relative "parent"
13
- require_relative "swt_packages"
10
+ require_relative "glimmer/parent"
11
+ require_relative "glimmer/swt_packages"
14
12
 
15
13
  module Glimmer
16
14
  #TODO make it configurable to include or not include
@@ -63,5 +61,5 @@ module Glimmer
63
61
  end
64
62
 
65
63
  # Command handlers may rely on Glimmer, so this is put here to avoid an infinite loop.
66
- require File.dirname(__FILE__) + "/xml_command_handlers"
67
- require File.dirname(__FILE__) + "/command_handlers"
64
+ require File.dirname(__FILE__) + "/glimmer/xml_command_handlers"
65
+ require File.dirname(__FILE__) + "/glimmer/command_handlers"
@@ -0,0 +1,10 @@
1
+ module Glimmer
2
+ module CommandHandler
3
+ def can_handle?(parent, command_symbol, *args, &block)
4
+ raise "must be implemented by a class"
5
+ end
6
+ def do_handle(parent, command_symbol, *args, &block)
7
+ raise "must be implemented by a class"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + "/command_handler_chain_link"
2
+
3
+ module Glimmer
4
+ class CommandHandlerChainFactory
5
+ @@dsls = {}
6
+
7
+ def self.def_dsl(dsl, *command_handler_array)
8
+ @@last_chain_link = nil
9
+ @@chain = nil
10
+ command_handler_array.each do |command_handler|
11
+ Glimmer.logger.debug "Loading #{command_handler.class.to_s}..."
12
+ chain_link = CommandHandlerChainLink.new(command_handler)
13
+ @@last_chain_link.chain_to(chain_link) if @@last_chain_link
14
+ @@last_chain_link = chain_link
15
+ @@chain = chain_link unless @@chain
16
+ end
17
+ @@dsls[dsl] = {
18
+ :last_chain_link => @@last_chain_link,
19
+ :chain => @@chain
20
+ }
21
+ end
22
+
23
+ def self.select_dsl(dsl)
24
+ @@last_chain_link = @@dsls[dsl][:last_chain_link]
25
+ @@chain = @@dsls[dsl][:chain]
26
+ end
27
+
28
+ def self.chain
29
+ @@chain
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ module Glimmer
2
+ class CommandHandlerChainLink
3
+ def initialize(command_handler)
4
+ @command_handler = command_handler
5
+ end
6
+ def chain_to(next_chain_link)
7
+ @next_chain_link = next_chain_link
8
+ end
9
+ def handle(parent, command_symbol, *args, &block)
10
+ if (@command_handler.can_handle?(parent, command_symbol, *args, &block))
11
+ Glimmer.logger.debug "#{@command_handler.class.to_s} will handle command: #{command_symbol} with arguments #{args}"
12
+ return @command_handler.do_handle(parent, command_symbol, *args, &block)
13
+ elsif @next_chain_link
14
+ return @next_chain_link.handle(parent, command_symbol, *args, &block)
15
+ else
16
+ Glimmer.logger.debug "Command: #{command_symbol} cannot be handled!"
17
+ return nil
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,6 @@
1
1
  require_relative "command_handler_chain_factory"
2
2
  require_relative "command_handlers/color_command_handler"
3
+ require_relative "command_handlers/display_command_handler"
3
4
  require_relative "command_handlers/shell_command_handler"
4
5
  require_relative "command_handlers/widget_listener_command_handler"
5
6
  require_relative "command_handlers/bind_command_handler"
@@ -14,20 +15,23 @@ require_relative "command_handlers/data_binding_command_handler"
14
15
  require_relative "command_handlers/widget_method_command_handler"
15
16
  require_relative "command_handlers/widget_command_handler"
16
17
 
17
- # edit to add more command handlers and extend Glimmer
18
- CommandHandlerChainFactory.def_dsl(:swt,
19
- ShellCommandHandler.new,
20
- WidgetListenerCommandHandler.new,
21
- BindCommandHandler.new,
22
- TabItemCommandHandler.new,
23
- ComboSelectionDataBindingCommandHandler.new,
24
- ListSelectionDataBindingCommandHandler.new,
25
- TreeItemsDataBindingCommandHandler.new,
26
- TreePropertiesDataBindingCommandHandler.new,
27
- TableItemsDataBindingCommandHandler.new,
28
- TableColumnPropertiesDataBindingCommandHandler.new,
29
- DataBindingCommandHandler.new,
30
- ColorCommandHandler.new,
31
- WidgetMethodCommandHandler.new,
32
- WidgetCommandHandler.new
33
- )
18
+ module Glimmer
19
+ # edit to add more command handlers and extend Glimmer
20
+ CommandHandlerChainFactory.def_dsl(:swt,
21
+ DisplayCommandHandler.new,
22
+ ShellCommandHandler.new,
23
+ WidgetListenerCommandHandler.new,
24
+ BindCommandHandler.new,
25
+ TabItemCommandHandler.new,
26
+ ComboSelectionDataBindingCommandHandler.new,
27
+ ListSelectionDataBindingCommandHandler.new,
28
+ TreeItemsDataBindingCommandHandler.new,
29
+ TreePropertiesDataBindingCommandHandler.new,
30
+ TableItemsDataBindingCommandHandler.new,
31
+ TableColumnPropertiesDataBindingCommandHandler.new,
32
+ DataBindingCommandHandler.new,
33
+ ColorCommandHandler.new,
34
+ WidgetMethodCommandHandler.new,
35
+ WidgetCommandHandler.new
36
+ )
37
+ end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + "/../command_handler"
2
+ require File.dirname(__FILE__) + "/models/g_widget"
3
+ require File.dirname(__FILE__) + "/models/model_binding"
4
+
5
+ module Glimmer
6
+ # Responsible for setting up the return value of the bind keyword (command symbol)
7
+ # as a ModelBinding. It is then used by another command handler like
8
+ # DataBindingCommandHandler for text and selection properties on Text and Spinner
9
+ # or TableItemsDataBindingCommandHandler for items in a Table
10
+ class BindCommandHandler
11
+ include CommandHandler
12
+
13
+ include_package 'org.eclipse.swt.widgets'
14
+
15
+ def can_handle?(parent, command_symbol, *args, &block)
16
+ (
17
+ parent.is_a?(GWidget) and
18
+ command_symbol.to_s == "bind" and
19
+ (
20
+ (
21
+ (args.size == 2) and
22
+ (
23
+ args[1].is_a?(Symbol) or
24
+ args[1].is_a?(String)
25
+ )
26
+ ) or
27
+ (
28
+ (args.size == 3) and
29
+ (args[1].is_a?(Symbol) or args[1].is_a?(String)) and
30
+ (args[2].is_a?(Symbol) or args[2].is_a?(String) or args[2].is_a?(Hash))
31
+ ) or
32
+ (
33
+ (args.size == 4) and
34
+ (args[1].is_a?(Symbol) or args[1].is_a?(String)) and
35
+ (args[2].is_a?(Symbol) or args[2].is_a?(String)) and
36
+ (args[3].is_a?(Hash))
37
+ )
38
+ ) and
39
+ block == nil
40
+ )
41
+ end
42
+
43
+ def do_handle(parent, command_symbol, *args, &block)
44
+ property_type = args[2] if (args.size == 3) && !args[2].is_a?(Hash)
45
+ binding_options = args[2] if args[2].is_a?(Hash)
46
+ binding_options = args[3] if args[3].is_a?(Hash)
47
+ ModelBinding.new(args[0], args[1].to_s, property_type, binding_options)
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,26 @@
1
+ require_relative '../command_handler'
2
+ require_relative 'models/g_color'
3
+
4
+ module Glimmer
5
+ class ColorCommandHandler
6
+ include CommandHandler
7
+
8
+ include_package 'org.eclipse.swt.widgets'
9
+
10
+ def can_handle?(parent, command_symbol, *args, &block)
11
+ ['rgba', 'rgb'].include?(command_symbol.to_s) and
12
+ (3..5).include?(args.count)
13
+ end
14
+
15
+ def do_handle(parent, command_symbol, *args, &block)
16
+ if args.first.is_a?(Display) || args.first.nil?
17
+ display = args.delete_at(0)
18
+ elsif parent.is_a?(GWidget)
19
+ display = parent.widget.display
20
+ else
21
+ display = nil
22
+ end
23
+ GColor.new(display, *args)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + "/../command_handler"
2
+ require File.dirname(__FILE__) + "/models/g_widget"
3
+
4
+ module Glimmer
5
+ class ComboSelectionDataBindingCommandHandler
6
+ include CommandHandler
7
+ include Glimmer
8
+
9
+ include_package 'org.eclipse.swt.widgets'
10
+
11
+ def can_handle?(parent, command_symbol, *args, &block)
12
+ parent.is_a?(GWidget) and
13
+ parent.widget.is_a?(Combo) and
14
+ command_symbol.to_s == "selection" and
15
+ args.size == 1 and
16
+ args[0].is_a?(ModelBinding) and
17
+ args[0].evaluate_options_property.is_a?(Array) and
18
+ block == nil
19
+ end
20
+
21
+ def do_handle(parent, command_symbol, *args, &block)
22
+ model_binding = args[0]
23
+ widget_binding = WidgetBinding.new(parent, "items")
24
+ widget_binding.call(model_binding.evaluate_options_property)
25
+ model = model_binding.base_model
26
+ widget_binding.observe(model, model_binding.options_property_name)
27
+
28
+ widget_binding = WidgetBinding.new(parent, "text")
29
+ widget_binding.call(model_binding.evaluate_property)
30
+ widget_binding.observe(model, model_binding.property_name_expression)
31
+
32
+ add_contents(parent) {
33
+ on_widget_selected {
34
+ model_binding.call(widget_binding.evaluate_property)
35
+ }
36
+ }
37
+ end
38
+
39
+ end
40
+ end