Class: Glimmer::SWT::MenuProxy
- Inherits:
-
WidgetProxy
- Object
- WidgetProxy
- Glimmer::SWT::MenuProxy
- Defined in:
- lib/glimmer/swt/menu_proxy.rb
Overview
Proxy for org.eclipse.swt.widgets.Menu
Functions differently from other widget proxies.
Glimmer automatically detects if this is a drop down menu or pop up menu from its parent if no SWT style is passed in.
There are 3 possibilities:
-
SWT :bar style is passed in: Menu Bar
-
Parent is ShellProxy: Pop Up Menu (having style :pop_up)
-
Parent is another Menu: Drop Down Menu (having style :drop_down)
In order to get the SWT Menu object, one must call ‘#swt_widget`.
In the case of a Drop Down menu, this automatically creates an SWT MenuItem object with style :cascade
In order to retrieve the menu item widget proxy, one must call ‘#menu_item_proxy`
Follows the Proxy Design Pattern
Constant Summary
Constants inherited from WidgetProxy
WidgetProxy::DEFAULT_INITIALIZERS, WidgetProxy::DEFAULT_STYLES, WidgetProxy::KEYWORD_ALIASES
Instance Attribute Summary collapse
-
#menu_item_proxy ⇒ Object
readonly
Returns the value of attribute menu_item_proxy.
-
#menu_parent ⇒ Object
readonly
Returns the value of attribute menu_parent.
-
#swt_menu_item ⇒ Object
readonly
Returns the value of attribute swt_menu_item.
Attributes inherited from WidgetProxy
#drag_source_proxy, #drag_source_style, #drag_source_transfer, #drop_target_proxy, #drop_target_transfer, #parent_proxy, #swt_widget
Instance Method Summary collapse
- #can_handle_observation_request?(observation_request, super_only: false) ⇒ Boolean
- #get_attribute(attribute_name) ⇒ Object
- #handle_observation_request(observation_request, &block) ⇒ Object
- #has_attribute?(attribute_name, *args) ⇒ Boolean
-
#initialize(parent, args) ⇒ MenuProxy
constructor
A new instance of MenuProxy.
- #set_attribute(attribute_name, *args) ⇒ Object
Methods inherited from WidgetProxy
#add_observer, #async_exec, #can_add_observer?, #can_handle_drag_observation_request?, #can_handle_drop_observation_request?, #content, create, #dispose, #ensure_drag_source_proxy, #ensure_drop_target_proxy, #extract_args, #has_style?, #method_missing, #pack_same_size, #post_add_content, #post_initialize_child, #remove_observer, #respond_to?, swt_widget_class_for, #sync_exec, underscored_widget_name, widget_exists?, #widget_property_listener_installers, widget_proxy_class
Methods included from Packages
Constructor Details
#initialize(parent, args) ⇒ MenuProxy
Returns a new instance of MenuProxy.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 51 def initialize(parent, args) index = args.delete(args.last) if args.last.is_a?(Numeric) styles = args.map(&:to_sym) if !styles.include?(:bar) && !parent..is_a?(Menu) styles = styles.unshift(:pop_up) end = self.class.('menu') if parent..is_a?(Menu) @menu_item_proxy = SWT::WidgetProxy.new('menu_item', parent, [:cascade] + [index].compact) @swt_menu_item = @menu_item_proxy. @swt_widget = .new(@menu_item_proxy.) @swt_menu_item.setMenu() elsif parent..is_a?(Shell) @swt_widget = .new(parent., style('menu', styles)) else @swt_widget = .new(parent.) end DEFAULT_INITIALIZERS['menu']&.call() if styles.include?(:bar) parent..setMenuBar() elsif styles.include?(:pop_up) parent..setMenu() end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Glimmer::SWT::WidgetProxy
Instance Attribute Details
#menu_item_proxy ⇒ Object (readonly)
Returns the value of attribute menu_item_proxy.
49 50 51 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 49 def @menu_item_proxy end |
#menu_parent ⇒ Object (readonly)
Returns the value of attribute menu_parent.
49 50 51 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 49 def @menu_parent end |
#swt_menu_item ⇒ Object (readonly)
Returns the value of attribute swt_menu_item.
49 50 51 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 49 def @swt_menu_item end |
Instance Method Details
#can_handle_observation_request?(observation_request, super_only: false) ⇒ Boolean
104 105 106 107 108 109 110 111 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 104 def can_handle_observation_request?(observation_request, super_only: false) super_result = super(observation_request) if observation_request.start_with?('on_') && !super_result && !super_only return .can_handle_observation_request?(observation_request) else super_result end end |
#get_attribute(attribute_name) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 96 def get_attribute(attribute_name) if attribute_name.to_s == "text" @swt_menu_item.getText else super(attribute_name) end end |
#handle_observation_request(observation_request, &block) ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 113 def handle_observation_request(observation_request, &block) if can_handle_observation_request?(observation_request, super_only: true) super else .handle_observation_request(observation_request, &block) end end |
#has_attribute?(attribute_name, *args) ⇒ Boolean
78 79 80 81 82 83 84 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 78 def has_attribute?(attribute_name, *args) if attribute_name.to_s == "text" true else super(attribute_name, *args) end end |
#set_attribute(attribute_name, *args) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 86 def set_attribute(attribute_name, *args) attribute_name if attribute_name.to_s == "text" text_value = args[0] @swt_menu_item.setText text_value else super(attribute_name, *args) end end |