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
@@ -1,23 +0,0 @@
1
- require File.dirname(__FILE__) + "/../command_handler"
2
- require File.dirname(__FILE__) + "/models/r_widget"
3
-
4
- # Responsible for providing a readable keyword (command symbol) to capture
5
- # and return tree properties for use in TreeItemsDataBindingCommandHandler
6
- class TreePropertiesDataBindingCommandHandler
7
- include CommandHandler
8
-
9
- include_package 'org.eclipse.swt'
10
- include_package 'org.eclipse.swt.widgets'
11
-
12
- def can_handle?(parent, command_symbol, *args, &block)
13
- parent.is_a?(RWidget) and
14
- parent.widget.is_a?(Tree) and
15
- command_symbol.to_s == "tree_properties" and
16
- block == nil
17
- end
18
-
19
- def do_handle(parent, command_symbol, *args, &block)
20
- args
21
- end
22
-
23
- end
@@ -1,20 +0,0 @@
1
- require File.dirname(__FILE__) + "/../command_handler"
2
- require File.dirname(__FILE__) + "/models/r_widget"
3
-
4
- class WidgetCommandHandler
5
- include CommandHandler
6
-
7
- include_package 'org.eclipse.swt.widgets'
8
-
9
- def can_handle?(parent, command_symbol, *args, &block)
10
- parent.is_a?(RWidget) and
11
- command_symbol.to_s != "shell" and
12
- RWidget.widget_exists?(command_symbol.to_s)
13
- end
14
-
15
- def do_handle(parent, command_symbol, *args, &block)
16
- Glimmer.logger.debug "widget styles are: " + args.inspect
17
- RWidget.new(command_symbol.to_s, parent.widget, args)
18
- end
19
-
20
- end
@@ -1,37 +0,0 @@
1
- require File.dirname(__FILE__) + "/../command_handler"
2
- require File.dirname(__FILE__) + "/models/r_widget"
3
-
4
- class WidgetListenerCommandHandler
5
- include CommandHandler
6
-
7
- include_package 'org.eclipse.swt.widgets'
8
-
9
- def can_handle?(parent, command_symbol, *args, &block)
10
- Glimmer.logger.debug "parent is a widget: " + (parent.is_a?(RWidget)).to_s
11
- return unless parent.is_a?(RWidget)
12
- Glimmer.logger.debug "on listener?: " + (command_symbol.to_s[0,3] == "on_").to_s
13
- return unless command_symbol.to_s[0,3] == "on_"
14
- Glimmer.logger.debug "command symbol is longer than 3: " + (command_symbol.to_s.length > 3).to_s
15
- return unless command_symbol.to_s.length > 3
16
- Glimmer.logger.debug "args are 0?: " + (args.size == 0).to_s
17
- return unless args.size == 0
18
- Glimmer.logger.debug "can add listener? " + (parent.can_add_listener?(command_symbol.to_s[3, command_symbol.to_s.length])).to_s
19
- parent.can_add_listener?(command_symbol.to_s[3, command_symbol.to_s.length])
20
- end
21
-
22
- def do_handle(parent, command_symbol, *args, &block)
23
- parent.add_listener(command_symbol.to_s[3, command_symbol.to_s.length], &block)
24
- ListenerParent.new #TODO refactor and move to models
25
- end
26
-
27
- #TODO refactor and move to separate file
28
- class ListenerParent
29
- include Parent
30
-
31
- def process_block(block)
32
- #NOOP
33
- end
34
-
35
- end
36
-
37
- end
@@ -1,19 +0,0 @@
1
- require File.dirname(__FILE__) + "/../command_handler"
2
- require File.dirname(__FILE__) + "/models/r_widget"
3
-
4
- class WidgetMethodCommandHandler
5
- include CommandHandler
6
-
7
- def can_handle?(parent, command_symbol, *args, &block)
8
- parent.is_a?(RWidget) and
9
- args.size > 0 and
10
- block == nil and
11
- parent.has_attribute?(command_symbol, *args)
12
- end
13
-
14
- def do_handle(parent, command_symbol, *args, &block)
15
- parent.set_attribute(command_symbol, *args)
16
- nil
17
- end
18
-
19
- end
data/lib/parent.rb DELETED
@@ -1,5 +0,0 @@
1
- module Parent
2
- def process_block(block)
3
- raise "must be implemented by a class"
4
- end
5
- end
data/lib/string.rb DELETED
@@ -1,8 +0,0 @@
1
- class String
2
- def swt_widget
3
- org.eclipse.swt.widgets.__send__(camelcase(:upper))
4
- end
5
- def swt_constant
6
- org.eclipse.swt.__send__("SWT").class_eval(upcase)
7
- end
8
- end
data/lib/swt_packages.rb DELETED
@@ -1,11 +0,0 @@
1
- # edit to add more packages and support custom widgets
2
- module SwtPackages
3
- def self.included(klass)
4
- klass.class_eval do
5
- include_package 'org.eclipse.swt'
6
- include_package 'org.eclipse.swt.widgets'
7
- include_package 'org.eclipse.swt.layout'
8
- include_package 'org.eclipse.swt.graphics'
9
- end
10
- end
11
- end
data/lib/symbol.rb DELETED
@@ -1,10 +0,0 @@
1
- require File.dirname(__FILE__) + "/string"
2
-
3
- class Symbol
4
- def swt_widget
5
- to_s.swt_widget
6
- end
7
- def swt_constant
8
- to_s.swt_constant
9
- end
10
- end
@@ -1,45 +0,0 @@
1
- require File.dirname(__FILE__) + "/../command_handler"
2
- require File.dirname(__FILE__) + "/models/node"
3
-
4
- class HtmlCommandHandler
5
- include CommandHandler
6
-
7
- def can_handle?(parent, command_symbol, *args, &block)
8
- (parent == nil or parent.is_a?(Node)) and
9
- (args.size == 0 or ((args.size == 1) and ((args[0].is_a?(Hash)) or (args[0].is_a?(Hash)))))
10
- end
11
-
12
- def do_handle(parent, command_symbol, *args, &block)
13
- attributes = Hash.new
14
- attributes = args[0] if (args.size == 1)
15
- append_id_and_class_attributes(command_symbol.to_s, attributes)
16
- tag_name = parse_tag_name(command_symbol.to_s)
17
- Node.new(parent, tag_name, attributes, &block)
18
- end
19
-
20
- def parse_tag_name(command)
21
- match_data = command.match("_")
22
- if (match_data.to_a.size > 0)
23
- command.match("_").pre_match
24
- else
25
- command
26
- end
27
- end
28
-
29
- def append_id_and_class_attributes(command, attributes)
30
- class_only_match = command.match("__.+").to_s
31
- if class_only_match.length > 0
32
- class_value = class_only_match[2, class_only_match.length]
33
- else
34
- match_data = command.match("_[^_]+")
35
- return unless match_data
36
- match = match_data.to_s
37
- id_value = match[1, match.length] if match.length > 0
38
- attributes[:id] = id_value if id_value
39
- match2 = match_data.post_match.match("_[^_]+").to_s if match_data.post_match
40
- class_value = match2[1, match2.length] if match2.length > 0
41
- end
42
- attributes[:class] = class_value if class_value
43
- end
44
-
45
- end
@@ -1,17 +0,0 @@
1
- class DepthFirstSearchIterator
2
- def initialize(node, node_visitor)
3
- @node = node
4
- @node_visitor = node_visitor
5
- end
6
-
7
- def iterate
8
- process(@node)
9
- end
10
-
11
- def process(node)
12
- @node_visitor.process_before_children(node)
13
- node.children.each { |child| process(child) } unless node.is_a?(String)
14
- @node_visitor.process_after_children(node)
15
- end
16
-
17
- end
@@ -1,18 +0,0 @@
1
- require File.dirname(__FILE__) + "/node_visitor"
2
-
3
- class NameSpaceVisitor < NodeVisitor
4
-
5
- def initialize(name_space_name)
6
- @name_space_name = name_space_name
7
- end
8
-
9
- def process_before_children(node)
10
- return if node.is_a?(String)
11
- node.name_space = Node.new(nil, @name_space_name, nil) if node and !node.name_space
12
- end
13
-
14
- def process_after_children(node)
15
- #NOOP
16
- end
17
-
18
- end
@@ -1,80 +0,0 @@
1
- require File.dirname(__FILE__) + "/depth_first_search_iterator"
2
- require File.dirname(__FILE__) + "/xml_visitor"
3
-
4
- class Node
5
- include Parent, Glimmer
6
-
7
- attr_accessor :children, :name, :contents, :attributes, :is_name_space, :is_attribute, :name_space, :parent
8
-
9
- def initialize(parent, name, attributes, &contents)
10
- @is_name_space = false
11
- @children = []
12
- @parent = parent
13
- if (parent and parent.is_name_space)
14
- @name_space = parent
15
- @parent = @name_space.parent
16
- end
17
- @parent.children << self if @parent
18
- @name = name
19
- @contents = contents
20
- @attributes = attributes
21
- if @attributes
22
- @attributes.each_key do |attribute|
23
- if attribute.is_a?(Node)
24
- attribute.is_attribute = true
25
- attribute.parent.children.delete(attribute) if attribute.parent
26
- attribute.parent = nil #attributes do not usually have parents
27
- end
28
- end
29
- Glimmer.logger.debug(attributes)
30
- end
31
- end
32
-
33
- def method_missing(symbol, *args, &block)
34
- @is_name_space = true
35
- parent.children.delete(self) if parent
36
- Glimmer.add_contents(self) {@tag = super}
37
- @tag
38
- end
39
-
40
- def to_xml
41
- xml_visitor = XmlVisitor.new
42
- DepthFirstSearchIterator.new(self, xml_visitor).iterate
43
- xml_visitor.document
44
- end
45
-
46
- def process_block(block)
47
- return_value = block.call(@widget)
48
- if return_value.is_a?(String) and !@children.include?(return_value)
49
- text = return_value
50
- first_match = text.match(/[#][^{]+[{][^}]+[}]/)
51
- match = first_match
52
- while (match)
53
- Glimmer.module_eval(text_command(match.pre_match))
54
- tag_text = match.to_s
55
- Glimmer.module_eval(rubyize(tag_text))
56
- text = tag_text
57
- post_match = match.post_match
58
- match = text.match(/[#]\w+[{]\w+[}]/)
59
- end
60
- Glimmer.module_eval(text_command(post_match)) if post_match
61
- @children << return_value unless first_match
62
- end
63
- end
64
-
65
- def text_command(text)
66
- "text \"#{text}\""
67
- end
68
-
69
- def rubyize(text)
70
- text = text.gsub(/[}]/, '"}')
71
- text = text.gsub(/[{]/, '{"')
72
- text = text.gsub(/[#]/, '')
73
- end
74
-
75
- #override Object default id method and route it to Glimmer engine
76
- def id
77
- method_missing(:id)
78
- end
79
-
80
- end
@@ -1,9 +0,0 @@
1
- class NodeVisitor
2
- def process_before_children
3
- raise "must be implemented by a class"
4
- end
5
-
6
- def process_after_children
7
- raise "must be implemented by a class"
8
- end
9
- end
@@ -1,59 +0,0 @@
1
- require File.dirname(__FILE__) + "/node_visitor"
2
-
3
- class XmlVisitor < NodeVisitor
4
-
5
- attr_reader :document
6
-
7
- def initialize
8
- @document = ""
9
- end
10
-
11
- def process_before_children(node)
12
- if (node.is_a?(String))
13
- @document << node
14
- return
15
- end
16
- begin_open_tag(node)
17
- append_attributes(node) if node.attributes
18
- end_open_tag(node)
19
- end
20
-
21
- def process_after_children(node)
22
- return if (node.is_a?(String))
23
- append_close_tag(node)
24
- end
25
-
26
- def begin_open_tag(node)
27
- @document << "<"
28
- @document << "#{node.name_space.name}:" if node.name_space
29
- @document << node.name
30
- end
31
-
32
- def end_open_tag(node)
33
- if (node.contents)
34
- @document << ">"
35
- else
36
- @document << " " if node.attributes.keys.size > 0
37
- @document << "/>"
38
- end
39
- end
40
-
41
- def append_close_tag(node)
42
- if (node.contents)
43
- @document << "</"
44
- @document << "#{node.name_space.name}:" if node.name_space
45
- @document << "#{node.name}>"
46
- end
47
- end
48
-
49
- def append_attributes(node)
50
- Glimmer.logger.debug "Take 3"
51
- Glimmer.logger.debug(node.attributes)
52
- node.attributes.each_key do |attribute|
53
- attribute_name = attribute
54
- attribute_name = "#{attribute.name_space.name}:#{attribute.name}" if attribute.is_a?(Node)
55
- @document << " #{attribute_name}=\"#{node.attributes[attribute]}\""
56
- end
57
- end
58
-
59
- end
@@ -1,18 +0,0 @@
1
- require File.dirname(__FILE__) + "/../command_handler"
2
- require File.dirname(__FILE__) + "/models/node"
3
-
4
- class XmlCommandHandler
5
- include CommandHandler
6
-
7
- def can_handle?(parent, command_symbol, *args, &block)
8
- (parent == nil or parent.is_a?(Node)) and
9
- (args.size == 0 or ((args.size == 1) and ((args[0].is_a?(Hash)) or (args[0].is_a?(Hash)))))
10
- end
11
-
12
- def do_handle(parent, command_symbol, *args, &block)
13
- attributes = Hash.new
14
- attributes = args[0] if (args.size == 1)
15
- Node.new(parent, command_symbol.to_s, attributes, &block)
16
- end
17
-
18
- end
@@ -1,31 +0,0 @@
1
- require File.dirname(__FILE__) + "/../command_handler"
2
- require File.dirname(__FILE__) + "/models/node"
3
- require File.dirname(__FILE__) + "/models/depth_first_search_iterator"
4
- require File.dirname(__FILE__) + "/models/name_space_visitor"
5
-
6
- class XmlNameSpaceCommandHandler
7
- include CommandHandler, Glimmer
8
-
9
- def can_handle?(parent, command_symbol, *args, &block)
10
- (parent == nil or parent.is_a?(Node)) and
11
- (command_symbol.to_s == "name_space")
12
- (args.size == 1) and
13
- (args[0].is_a?(Symbol)) and
14
- block
15
- end
16
-
17
- def do_handle(parent, command_symbol, *args, &block)
18
- node = block.call
19
- unless node.is_a?(String)
20
- name_space_visitor = NameSpaceVisitor.new(args[0].to_s)
21
- DepthFirstSearchIterator.new(node, name_space_visitor).iterate
22
- def node.process_block(block)
23
- Glimmer.logger.debug 'block'
24
- #NOOP
25
- end
26
- end
27
- parent.children << node if parent and !parent.children.include?(node)
28
- node
29
- end
30
-
31
- end
@@ -1,23 +0,0 @@
1
- require "facets"
2
- require File.dirname(__FILE__) + "/../command_handler"
3
- require File.dirname(__FILE__) + "/models/node"
4
-
5
- class XmlTagCommandHandler
6
- include CommandHandler
7
-
8
- def can_handle?(parent, command_symbol, *args, &block)
9
- (parent == nil or parent.is_a?(Node)) and
10
- (command_symbol.to_s == "tag") and
11
- ((args.size == 1) and ((args[0].is_a?(Hash)) or (args[0].is_a?(Hash)))) and
12
- args[0].include?(:_name)
13
- end
14
-
15
- def do_handle(parent, command_symbol, *args, &block)
16
- attributes = nil
17
- attributes = args[0] if (args.size == 1)
18
- tag_name = attributes[:_name]
19
- attributes.delete(:_name)
20
- Node.new(parent, tag_name, attributes, &block)
21
- end
22
-
23
- end