glimmer-dsl-swt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +20 -0
  3. data/README.md +47 -0
  4. data/RUBY_VERSION +1 -0
  5. data/VERSION +1 -0
  6. data/bin/girb +10 -0
  7. data/bin/girb_runner.rb +13 -0
  8. data/bin/glimmer +5 -0
  9. data/icons/scaffold_app.icns +0 -0
  10. data/lib/ext/glimmer.rb +13 -0
  11. data/lib/ext/glimmer/config.rb +18 -0
  12. data/lib/glimmer-dsl-swt.rb +12 -0
  13. data/lib/glimmer/data_binding/list_selection_binding.rb +52 -0
  14. data/lib/glimmer/data_binding/model_binding.rb +248 -0
  15. data/lib/glimmer/data_binding/observable.rb +21 -0
  16. data/lib/glimmer/data_binding/observable_array.rb +107 -0
  17. data/lib/glimmer/data_binding/observable_model.rb +108 -0
  18. data/lib/glimmer/data_binding/observable_widget.rb +17 -0
  19. data/lib/glimmer/data_binding/observer.rb +124 -0
  20. data/lib/glimmer/data_binding/shine.rb +23 -0
  21. data/lib/glimmer/data_binding/table_items_binding.rb +56 -0
  22. data/lib/glimmer/data_binding/tree_items_binding.rb +71 -0
  23. data/lib/glimmer/data_binding/widget_binding.rb +33 -0
  24. data/lib/glimmer/dsl/swt/async_exec_expression.rb +14 -0
  25. data/lib/glimmer/dsl/swt/bind_expression.rb +37 -0
  26. data/lib/glimmer/dsl/swt/color_expression.rb +19 -0
  27. data/lib/glimmer/dsl/swt/column_properties_expression.rb +24 -0
  28. data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +42 -0
  29. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +39 -0
  30. data/lib/glimmer/dsl/swt/data_binding_expression.rb +34 -0
  31. data/lib/glimmer/dsl/swt/dialog_expression.rb +26 -0
  32. data/lib/glimmer/dsl/swt/display_expression.rb +19 -0
  33. data/lib/glimmer/dsl/swt/dsl.rb +34 -0
  34. data/lib/glimmer/dsl/swt/exec_expression.rb +28 -0
  35. data/lib/glimmer/dsl/swt/layout_data_expression.rb +25 -0
  36. data/lib/glimmer/dsl/swt/layout_expression.rb +27 -0
  37. data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +44 -0
  38. data/lib/glimmer/dsl/swt/menu_bar_expression.rb +33 -0
  39. data/lib/glimmer/dsl/swt/menu_expression.rb +32 -0
  40. data/lib/glimmer/dsl/swt/message_box_expression.rb +29 -0
  41. data/lib/glimmer/dsl/swt/observe_expression.rb +32 -0
  42. data/lib/glimmer/dsl/swt/property_expression.rb +22 -0
  43. data/lib/glimmer/dsl/swt/rgb_expression.rb +12 -0
  44. data/lib/glimmer/dsl/swt/rgba_expression.rb +12 -0
  45. data/lib/glimmer/dsl/swt/shell_expression.rb +25 -0
  46. data/lib/glimmer/dsl/swt/swt_expression.rb +25 -0
  47. data/lib/glimmer/dsl/swt/sync_exec_expression.rb +15 -0
  48. data/lib/glimmer/dsl/swt/tab_item_expression.rb +33 -0
  49. data/lib/glimmer/dsl/swt/table_items_data_binding_expression.rb +31 -0
  50. data/lib/glimmer/dsl/swt/tree_items_data_binding_expression.rb +31 -0
  51. data/lib/glimmer/dsl/swt/tree_properties_expression.rb +26 -0
  52. data/lib/glimmer/dsl/swt/widget_expression.rb +35 -0
  53. data/lib/glimmer/dsl/swt/widget_listener_expression.rb +32 -0
  54. data/lib/glimmer/launcher.rb +196 -0
  55. data/lib/glimmer/package.rb +57 -0
  56. data/lib/glimmer/rake_task.rb +62 -0
  57. data/lib/glimmer/scaffold.rb +582 -0
  58. data/lib/glimmer/swt/color_proxy.rb +53 -0
  59. data/lib/glimmer/swt/display_proxy.rb +88 -0
  60. data/lib/glimmer/swt/font_proxy.rb +72 -0
  61. data/lib/glimmer/swt/layout_data_proxy.rb +84 -0
  62. data/lib/glimmer/swt/layout_proxy.rb +82 -0
  63. data/lib/glimmer/swt/menu_proxy.rb +101 -0
  64. data/lib/glimmer/swt/message_box_proxy.rb +48 -0
  65. data/lib/glimmer/swt/packages.rb +13 -0
  66. data/lib/glimmer/swt/shell_proxy.rb +152 -0
  67. data/lib/glimmer/swt/swt_proxy.rb +106 -0
  68. data/lib/glimmer/swt/tab_item_proxy.rb +65 -0
  69. data/lib/glimmer/swt/table_proxy.rb +150 -0
  70. data/lib/glimmer/swt/tree_proxy.rb +120 -0
  71. data/lib/glimmer/swt/widget_listener_proxy.rb +34 -0
  72. data/lib/glimmer/swt/widget_proxy.rb +489 -0
  73. data/lib/glimmer/ui/custom_shell.rb +45 -0
  74. data/lib/glimmer/ui/custom_widget.rb +244 -0
  75. data/lib/glimmer/util/proc_tracker.rb +16 -0
  76. data/vendor/swt/linux/swt.jar +0 -0
  77. data/vendor/swt/mac/swt.jar +0 -0
  78. data/vendor/swt/windows/swt.jar +0 -0
  79. metadata +307 -0
@@ -0,0 +1,27 @@
1
+ require 'glimmer'
2
+ require 'glimmer/dsl/expression'
3
+ require 'glimmer/dsl/parent_expression'
4
+ require 'glimmer/swt/layout_proxy'
5
+
6
+ module Glimmer
7
+ module DSL
8
+ module SWT
9
+ class LayoutExpression < Expression
10
+ include ParentExpression
11
+
12
+ include_package 'org.eclipse.swt.widgets'
13
+
14
+ def can_interpret?(parent, keyword, *args, &block)
15
+ keyword.to_s.end_with?('_layout') and
16
+ parent.respond_to?(:swt_widget) and
17
+ parent.swt_widget.is_a?(Composite) and
18
+ Glimmer::SWT::LayoutProxy.layout_exists?(keyword.to_s)
19
+ end
20
+
21
+ def interpret(parent, keyword, *args, &block)
22
+ Glimmer::SWT::LayoutProxy.new(keyword, parent, args)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,44 @@
1
+ require 'glimmer/dsl/expression'
2
+ require 'glimmer/data_binding/model_binding'
3
+ require 'glimmer/data_binding/widget_binding'
4
+ require 'glimmer/data_binding/list_selection_binding'
5
+
6
+ module Glimmer
7
+ module DSL
8
+ module SWT
9
+ class ListSelectionDataBindingExpression < Expression
10
+ include_package 'org.eclipse.swt.widgets'
11
+
12
+ def can_interpret?(parent, keyword, *args, &block)
13
+ keyword == 'selection' and
14
+ block.nil? and
15
+ parent.respond_to?(:swt_widget) and
16
+ parent.swt_widget.is_a?(List) and
17
+ args.size == 1 and
18
+ args[0].is_a?(DataBinding::ModelBinding) and
19
+ args[0].evaluate_options_property.is_a?(Array)
20
+ end
21
+
22
+ def interpret(parent, keyword, *args, &block)
23
+ model_binding = args[0]
24
+ widget_binding = DataBinding::WidgetBinding.new(parent, 'items')
25
+ widget_binding.call(model_binding.evaluate_options_property)
26
+ model = model_binding.base_model
27
+ #TODO make this options observer dependent and all similar observers in widget specific data binding interpretrs
28
+ widget_binding.observe(model, model_binding.options_property_name)
29
+
30
+ property_type = :string
31
+ property_type = :array if parent.has_style?(:multi)
32
+ list_selection_binding = DataBinding::ListSelectionBinding.new(parent, property_type)
33
+ list_selection_binding.call(model_binding.evaluate_property)
34
+ #TODO check if nested data binding works for list widget and other widgets that need custom data binding
35
+ list_selection_binding.observe(model, model_binding.property_name_expression)
36
+
37
+ parent.on_widget_selected do
38
+ model_binding.call(list_selection_binding.evaluate_property)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,33 @@
1
+ require 'glimmer'
2
+ require 'glimmer/dsl/static_expression'
3
+ require 'glimmer/dsl/parent_expression'
4
+ require 'glimmer/swt/menu_proxy'
5
+
6
+ module Glimmer
7
+ module DSL
8
+ module SWT
9
+ class MenuBarExpression < StaticExpression
10
+ include ParentExpression
11
+
12
+ include_package 'org.eclipse.swt.widgets'
13
+
14
+ def can_interpret?(parent, keyword, *args, &block)
15
+ initial_condition = (keyword == 'menu_bar')
16
+ if initial_condition
17
+ if parent.swt_widget.is_a?(Shell)
18
+ return true
19
+ else
20
+ raise Glimmer::Error, "menu_bar may only be nested under a shell!"
21
+ end
22
+ end
23
+ false
24
+ end
25
+
26
+ def interpret(parent, keyword, *args, &block)
27
+ args = args.unshift(:bar)
28
+ Glimmer::SWT::MenuProxy.new(parent, args)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ require 'glimmer'
2
+ require 'glimmer/dsl/static_expression'
3
+ require 'glimmer/dsl/parent_expression'
4
+ require 'glimmer/swt/menu_proxy'
5
+
6
+ module Glimmer
7
+ module DSL
8
+ module SWT
9
+ class MenuExpression < StaticExpression
10
+ include ParentExpression
11
+
12
+ include_package 'org.eclipse.swt.widgets'
13
+
14
+ def can_interpret?(parent, keyword, *args, &block)
15
+ initial_condition = (keyword == 'menu')
16
+ if initial_condition
17
+ if parent.respond_to?(:swt_widget)
18
+ return true
19
+ else
20
+ raise Glimmer::Error, "menu may only be nested under a widget (like shell or another menu)!"
21
+ end
22
+ end
23
+ false
24
+ end
25
+
26
+ def interpret(parent, keyword, *args, &block)
27
+ Glimmer::SWT::MenuProxy.new(parent, args)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,29 @@
1
+ require 'glimmer/dsl/static_expression'
2
+ require 'glimmer/dsl/parent_expression'
3
+ require 'glimmer/dsl/top_level_expression'
4
+ require 'glimmer/swt/shell_proxy'
5
+ require 'glimmer/swt/message_box_proxy'
6
+ require 'glimmer/swt/swt_proxy'
7
+
8
+ module Glimmer
9
+ module DSL
10
+ module SWT
11
+ class MessageBoxExpression < StaticExpression
12
+ include TopLevelExpression
13
+ include ParentExpression
14
+
15
+ include_package 'org.eclipse.swt.widgets'
16
+
17
+ def can_interpret?(parent, keyword, *args, &block)
18
+ keyword == 'message_box'
19
+ end
20
+
21
+ def interpret(parent, keyword, *args, &block)
22
+ potential_parent = args.first
23
+ parent = args.shift if potential_parent.is_a?(Shell) || (potential_parent.respond_to?(:swt_widget) && potential_parent.swt_widget.is_a?(Shell))
24
+ Glimmer::SWT::MessageBoxProxy.new(parent, Glimmer::SWT::SWTProxy[args])
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ require 'glimmer/dsl/static_expression'
2
+ require 'glimmer/dsl/top_level_expression'
3
+ require 'glimmer/data_binding/observer'
4
+ require 'glimmer/data_binding/model_binding'
5
+
6
+ module Glimmer
7
+ module DSL
8
+ module SWT
9
+ class ObserveExpression < StaticExpression
10
+ include TopLevelExpression
11
+
12
+ REGEX_NESTED_OR_INDEXED_PROPERTY = /([^\[]+)(\[[^\]]+\])?/
13
+
14
+ def can_interpret?(parent, keyword, *args, &block)
15
+ keyword == 'observe' and
16
+ block_given? and
17
+ (args.size == 2) and
18
+ textual?(args[1])
19
+ end
20
+
21
+ def interpret(parent, keyword, *args, &block)
22
+ observer = DataBinding::Observer.proc(&block)
23
+ if args[1].to_s.match(REGEX_NESTED_OR_INDEXED_PROPERTY)
24
+ observer.observe(DataBinding::ModelBinding.new(args[0], args[1]))
25
+ else
26
+ observer.observe(args[0], args[1])
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ require 'glimmer/dsl/expression'
2
+
3
+ module Glimmer
4
+ module DSL
5
+ module SWT
6
+ class PropertyExpression < Expression
7
+ def can_interpret?(parent, keyword, *args, &block)
8
+ block.nil? and
9
+ args.size > 0 and
10
+ parent.respond_to?(:set_attribute) and
11
+ parent.respond_to?(:has_attribute?) and
12
+ parent.has_attribute?(keyword, *args)
13
+ end
14
+
15
+ def interpret(parent, keyword, *args, &block)
16
+ parent.set_attribute(keyword, *args)
17
+ nil
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ require 'glimmer/dsl/swt/color_expression'
2
+ require 'glimmer/swt/color_proxy'
3
+ require 'glimmer/swt/display_proxy'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ module SWT
8
+ class RgbExpression < ColorExpression
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'glimmer/dsl/swt/color_expression'
2
+ require 'glimmer/swt/color_proxy'
3
+ require 'glimmer/swt/display_proxy'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ module SWT
8
+ class RgbaExpression < ColorExpression
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ require 'glimmer/dsl/static_expression'
2
+ require 'glimmer/dsl/parent_expression'
3
+ require 'glimmer/dsl/top_level_expression'
4
+ require 'glimmer/swt/shell_proxy'
5
+
6
+ module Glimmer
7
+ module DSL
8
+ module SWT
9
+ class ShellExpression < StaticExpression
10
+ include TopLevelExpression
11
+ include ParentExpression
12
+
13
+ def can_interpret?(parent, keyword, *args, &block)
14
+ keyword == 'shell' and
15
+ (parent.nil? or parent.is_a?(Glimmer::SWT::ShellProxy))
16
+ end
17
+
18
+ def interpret(parent, keyword, *args, &block)
19
+ args = [parent] + args unless parent.nil?
20
+ Glimmer::SWT::ShellProxy.send(:new, *args)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'glimmer/dsl/static_expression'
2
+ require 'glimmer/swt/swt_proxy'
3
+
4
+ # TODO consider turning static keywords like bind into methods
5
+
6
+ module Glimmer
7
+ module DSL
8
+ module SWT
9
+ # Responsible for returning SWT constant values
10
+ #
11
+ # Named SwtExpression (not SWTExpression) so that the DSL engine
12
+ # discovers quickly by convention
13
+ class SwtExpression < StaticExpression
14
+ def can_interpret?(parent, keyword, *args, &block)
15
+ block.nil? &&
16
+ args.size > 0
17
+ end
18
+
19
+ def interpret(parent, keyword, *args, &block)
20
+ Glimmer::SWT::SWTProxy[*args]
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ require 'glimmer/dsl/static_expression'
2
+ require 'glimmer/dsl/swt/exec_expression'
3
+
4
+ module Glimmer
5
+ module DSL
6
+ module SWT
7
+ # Synchronously executes code block against the SWT Event Loop
8
+ # to manipulate SWT UI objects on the UI thread safely with
9
+ # immediate priority when needed.
10
+ class SyncExecExpression < StaticExpression
11
+ include ExecExpression
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ require 'glimmer'
2
+ require 'glimmer/dsl/static_expression'
3
+ require 'glimmer/dsl/parent_expression'
4
+ require 'glimmer/swt/widget_proxy'
5
+ require 'glimmer/swt/tab_item_proxy'
6
+
7
+ module Glimmer
8
+ module DSL
9
+ module SWT
10
+ class TabItemExpression < StaticExpression
11
+ include ParentExpression
12
+
13
+ include_package 'org.eclipse.swt.widgets'
14
+
15
+ def can_interpret?(parent, keyword, *args, &block)
16
+ initial_condition = (keyword == 'tab_item') and parent.respond_to?(:swt_widget)
17
+ if initial_condition
18
+ if parent.swt_widget.is_a?(TabFolder)
19
+ return true
20
+ else
21
+ Glimmer::Config.logger&.error "tab_item widget may only be used directly under a tab_folder widget!"
22
+ end
23
+ end
24
+ false
25
+ end
26
+
27
+ def interpret(parent, keyword, *args, &block)
28
+ Glimmer::SWT::TabItemProxy.new(parent, args)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ require 'glimmer/dsl/expression'
2
+ require 'glimmer/data_binding/model_binding'
3
+ require 'glimmer/data_binding/table_items_binding'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ module SWT
8
+ #Depends on BindCommandHandler and TableColumnPropertiesDataBindingCommandHandler
9
+ class TableItemsDataBindingExpression < Expression
10
+ include_package 'org.eclipse.swt.widgets'
11
+
12
+ def can_interpret?(parent, keyword, *args, &block)
13
+ keyword == "items" and
14
+ block.nil? and
15
+ parent.respond_to?(:swt_widget) and
16
+ parent.swt_widget.is_a?(Table) and
17
+ args.size == 2 and
18
+ args[0].is_a?(DataBinding::ModelBinding) and
19
+ args[0].evaluate_property.is_a?(Array) and
20
+ args[1].is_a?(Array)
21
+ end
22
+
23
+ def interpret(parent, keyword, *args, &block)
24
+ model_binding = args[0]
25
+ column_properties = args[1]
26
+ DataBinding::TableItemsBinding.new(parent, model_binding, column_properties)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require 'glimmer/dsl/expression'
2
+ require 'glimmer/data_binding/model_binding'
3
+ require 'glimmer/data_binding/tree_items_binding'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ module SWT
8
+ class TreeItemsDataBindingExpression < Expression
9
+ include_package 'org.eclipse.swt.widgets'
10
+
11
+ def can_interpret?(parent, keyword, *args, &block)
12
+ initial_condition = ((keyword == "items") and block.nil? and parent.respond_to?(:swt_widget) and parent.swt_widget.is_a?(Tree))
13
+ return false unless initial_condition
14
+ raise Glimmer::Error, 'Tree items args must be 2' unless args.size == 2
15
+ raise Glimmer::Error, 'Tree items first arg must be a bind expression' unless args[0].is_a?(DataBinding::ModelBinding)
16
+ raise Glimmer::Error, 'Tree items data-binding initial value must not be an array yet a single item representing tree root' unless !args[0].evaluate_property.is_a?(Array)
17
+ raise Glimmer::Error, 'Tree items second arg must be an array' unless args[1].is_a?(Array)
18
+ raise Glimmer::Error, 'Tree items second arg must not be empty' unless !args[1].empty?
19
+ raise Glimmer::Error, 'Tree items second arg array elements must be of type hash' unless args[1].first.is_a?(Hash)
20
+ true
21
+ end
22
+
23
+ def interpret(parent, keyword, *args, &block)
24
+ model_binding = args[0]
25
+ tree_properties = args[1]
26
+ DataBinding::TreeItemsBinding.new(parent, model_binding, tree_properties)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ require 'glimmer/dsl/static_expression'
2
+ require 'glimmer/data_binding/model_binding'
3
+ require 'glimmer/data_binding/tree_items_binding'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ module SWT
8
+ # Responsible for providing a readable keyword (command symbol) to capture
9
+ # and return tree properties for use in TreeItemsDataBindingCommandHandler
10
+ class TreePropertiesExpression < StaticExpression
11
+ include_package 'org.eclipse.swt.widgets'
12
+
13
+ def can_interpret?(parent, keyword, *args, &block)
14
+ keyword == "tree_properties" and
15
+ block.nil? and
16
+ parent.respond_to?(:swt_widget) and
17
+ parent.swt_widget.is_a?(Tree)
18
+ end
19
+
20
+ def interpret(parent, keyword, *args, &block)
21
+ args
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end