glimmer 0.5.11 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/README.markdown +129 -15
  3. data/lib/glimmer.rb +13 -1
  4. data/lib/glimmer/css/rule_set.rb +27 -0
  5. data/lib/glimmer/css/style_sheet.rb +20 -0
  6. data/lib/glimmer/dsl/css/css_expression.rb +21 -0
  7. data/lib/glimmer/dsl/css/dsl.rb +10 -0
  8. data/lib/glimmer/dsl/css/p_expression.rb +25 -0
  9. data/lib/glimmer/dsl/css/property_expression.rb +22 -0
  10. data/lib/glimmer/dsl/css/rule_set_expression.rb +25 -0
  11. data/lib/glimmer/dsl/css/s_expression.rb +26 -0
  12. data/lib/glimmer/dsl/engine.rb +90 -18
  13. data/lib/glimmer/dsl/expression.rb +9 -4
  14. data/lib/glimmer/dsl/static_expression.rb +13 -13
  15. data/lib/glimmer/dsl/swt/async_exec_expression.rb +14 -0
  16. data/lib/glimmer/dsl/swt/bind_expression.rb +37 -0
  17. data/lib/glimmer/dsl/swt/color_expression.rb +17 -0
  18. data/lib/glimmer/dsl/swt/column_properties_expression.rb +24 -0
  19. data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +42 -0
  20. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +36 -0
  21. data/lib/glimmer/dsl/swt/data_binding_expression.rb +34 -0
  22. data/lib/glimmer/dsl/swt/display_expression.rb +19 -0
  23. data/lib/glimmer/dsl/swt/dsl.rb +26 -0
  24. data/lib/glimmer/dsl/swt/exec_expression.rb +28 -0
  25. data/lib/glimmer/dsl/swt/layout_data_expression.rb +25 -0
  26. data/lib/glimmer/dsl/swt/layout_expression.rb +27 -0
  27. data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +44 -0
  28. data/lib/glimmer/dsl/swt/menu_bar_expression.rb +33 -0
  29. data/lib/glimmer/dsl/swt/menu_expression.rb +32 -0
  30. data/lib/glimmer/dsl/swt/observe_expression.rb +32 -0
  31. data/lib/glimmer/dsl/swt/property_expression.rb +22 -0
  32. data/lib/glimmer/dsl/swt/rgb_expression.rb +12 -0
  33. data/lib/glimmer/dsl/swt/rgba_expression.rb +12 -0
  34. data/lib/glimmer/dsl/swt/shell_expression.rb +20 -0
  35. data/lib/glimmer/dsl/swt/swt_expression.rb +25 -0
  36. data/lib/glimmer/dsl/swt/sync_exec_expression.rb +15 -0
  37. data/lib/glimmer/dsl/swt/tab_item_expression.rb +33 -0
  38. data/lib/glimmer/dsl/swt/table_items_data_binding_expression.rb +31 -0
  39. data/lib/glimmer/dsl/swt/tree_items_data_binding_expression.rb +31 -0
  40. data/lib/glimmer/dsl/swt/tree_properties_expression.rb +26 -0
  41. data/lib/glimmer/dsl/swt/widget_expression.rb +27 -0
  42. data/lib/glimmer/dsl/swt/widget_listener_expression.rb +32 -0
  43. data/lib/glimmer/dsl/top_level_expression.rb +7 -0
  44. data/lib/glimmer/dsl/xml/dsl.rb +11 -0
  45. data/lib/glimmer/dsl/xml/html_expression.rb +25 -0
  46. data/lib/glimmer/dsl/xml/meta_expression.rb +23 -0
  47. data/lib/glimmer/dsl/xml/name_space_expression.rb +37 -0
  48. data/lib/glimmer/dsl/xml/node_parent_expression.rb +33 -0
  49. data/lib/glimmer/dsl/xml/tag_expression.rb +29 -0
  50. data/lib/glimmer/dsl/xml/text_expression.rb +22 -0
  51. data/lib/glimmer/dsl/xml/xml_expression.rb +21 -0
  52. data/lib/glimmer/rake_task.rb +1 -1
  53. data/lib/glimmer/swt/shell_proxy.rb +1 -2
  54. data/lib/glimmer/swt/widget_proxy.rb +6 -3
  55. data/lib/glimmer/ui/custom_widget.rb +8 -4
  56. data/lib/glimmer/ui/video.rb +31 -28
  57. data/lib/glimmer/xml/depth_first_search_iterator.rb +22 -0
  58. data/lib/glimmer/xml/name_space_visitor.rb +21 -0
  59. data/lib/glimmer/xml/node.rb +75 -0
  60. data/lib/glimmer/xml/node_visitor.rb +13 -0
  61. data/lib/glimmer/xml/xml_visitor.rb +65 -0
  62. data/samples/gladiator.rb +52 -12
  63. metadata +55 -31
  64. data/lib/glimmer/dsl.rb +0 -26
  65. data/lib/glimmer/dsl/async_exec_expression.rb +0 -12
  66. data/lib/glimmer/dsl/bind_expression.rb +0 -35
  67. data/lib/glimmer/dsl/color_expression.rb +0 -22
  68. data/lib/glimmer/dsl/column_properties_expression.rb +0 -22
  69. data/lib/glimmer/dsl/combo_selection_data_binding_expression.rb +0 -40
  70. data/lib/glimmer/dsl/custom_widget_expression.rb +0 -33
  71. data/lib/glimmer/dsl/data_binding_expression.rb +0 -32
  72. data/lib/glimmer/dsl/display_expression.rb +0 -14
  73. data/lib/glimmer/dsl/exec_expression.rb +0 -23
  74. data/lib/glimmer/dsl/layout_data_expression.rb +0 -23
  75. data/lib/glimmer/dsl/layout_expression.rb +0 -25
  76. data/lib/glimmer/dsl/list_selection_data_binding_expression.rb +0 -42
  77. data/lib/glimmer/dsl/menu_bar_expression.rb +0 -31
  78. data/lib/glimmer/dsl/menu_expression.rb +0 -30
  79. data/lib/glimmer/dsl/observe_expression.rb +0 -27
  80. data/lib/glimmer/dsl/property_expression.rb +0 -20
  81. data/lib/glimmer/dsl/shell_expression.rb +0 -16
  82. data/lib/glimmer/dsl/swt_expression.rb +0 -23
  83. data/lib/glimmer/dsl/sync_exec_expression.rb +0 -13
  84. data/lib/glimmer/dsl/tab_item_expression.rb +0 -31
  85. data/lib/glimmer/dsl/table_items_data_binding_expression.rb +0 -29
  86. data/lib/glimmer/dsl/tree_items_data_binding_expression.rb +0 -29
  87. data/lib/glimmer/dsl/tree_properties_expression.rb +0 -24
  88. data/lib/glimmer/dsl/widget_expression.rb +0 -25
  89. data/lib/glimmer/dsl/widget_listener_expression.rb +0 -30
@@ -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 widget?(parent)
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,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,20 @@
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 interpret(parent, keyword, *args, &block)
14
+ args = [parent] + args unless parent.nil?
15
+ Glimmer::SWT::ShellProxy.send(:new, *args)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ 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 widget?(parent)
17
+ if initial_condition
18
+ if parent.swt_widget.is_a?(TabFolder)
19
+ return true
20
+ else
21
+ Glimmer.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
+ widget?(parent) 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 widget?(parent) 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
+ widget?(parent) 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
@@ -0,0 +1,27 @@
1
+ require 'glimmer'
2
+ require 'glimmer/dsl/expression'
3
+ require 'glimmer/dsl/parent_expression'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ module SWT
8
+ class WidgetExpression < Expression
9
+ include ParentExpression
10
+
11
+ EXCLUDED_KEYWORDS = %w[shell display tab_item]
12
+
13
+ def can_interpret?(parent, keyword, *args, &block)
14
+ !EXCLUDED_KEYWORDS.include?(keyword) and
15
+ widget?(parent) and #TODO change to composite?(parent)
16
+ Glimmer::SWT::WidgetProxy.widget_exists?(keyword)
17
+ end
18
+
19
+ def interpret(parent, keyword, *args, &block)
20
+ Glimmer::SWT::WidgetProxy.new(keyword, parent, args)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ require 'glimmer/swt/widget_proxy'
@@ -0,0 +1,32 @@
1
+ require 'glimmer/dsl/expression'
2
+ require 'glimmer/swt/display_proxy'
3
+
4
+ module Glimmer
5
+ module DSL
6
+ module SWT
7
+ class WidgetListenerExpression < Expression
8
+ include_package 'org.eclipse.swt.widgets'
9
+
10
+ def can_interpret?(parent, keyword, *args, &block)
11
+ Glimmer.logger&.debug "keyword starts with on_: #{keyword.start_with?('on_')}"
12
+ return false unless keyword.start_with?('on_')
13
+ widget_or_display_parentage = widget?(parent) || parent.is_a?(Glimmer::SWT::DisplayProxy)
14
+ Glimmer.logger&.debug "parent is a widget or display: #{widget_or_display_parentage}"
15
+ return false unless widget_or_display_parentage
16
+ Glimmer.logger&.debug "block exists?: #{!block.nil?}"
17
+ raise Glimmer::Error, "Listener is missing block for keyword: #{keyword}" unless block_given?
18
+ Glimmer.logger&.debug "args are empty?: #{args.empty?}"
19
+ raise Glimmer::Error, "Invalid listener arguments for keyword: #{keyword}(#{args})" unless args.empty?
20
+ result = parent.can_handle_observation_request?(keyword)
21
+ Glimmer.logger&.debug "can add listener? #{result}"
22
+ raise Glimmer::Error, "Invalid listener keyword: #{keyword}" unless result
23
+ true
24
+ end
25
+
26
+ def interpret(parent, keyword, *args, &block)
27
+ parent.handle_observation_request(keyword, &block)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ module Glimmer
2
+ module DSL
3
+ # Mixin that represents expressions that are always at the top with parent nil
4
+ module TopLevelExpression
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'glimmer/dsl/engine'
2
+ Dir[File.expand_path('../*_expression.rb', __FILE__)].each {|f| require f}
3
+
4
+ Glimmer::DSL::Engine.add_dynamic_expressions(
5
+ Glimmer::DSL::XML,
6
+ %w[
7
+ text
8
+ tag
9
+ xml
10
+ ]
11
+ )
@@ -0,0 +1,25 @@
1
+ require 'glimmer/dsl/xml/node_parent_expression'
2
+ require 'glimmer/dsl/xml/xml_expression'
3
+ require 'glimmer/dsl/static_expression'
4
+ require 'glimmer/dsl/top_level_expression'
5
+
6
+ module Glimmer
7
+ module DSL
8
+ module XML
9
+ # This static html expression flips the DSL switch on for
10
+ # XML DSL in Glimmer
11
+ class HtmlExpression < StaticExpression
12
+ include TopLevelExpression
13
+ include NodeParentExpression
14
+
15
+ def interpret(parent, keyword, *args, &block)
16
+ xml_expression.interpret(parent, keyword, *args, &block)
17
+ end
18
+
19
+ def xml_expression
20
+ @xml_expression ||= XmlExpression.new
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end