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
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
Instance Method Summary collapse
- #get_attribute(attribute_name) ⇒ 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_observation_request?, #content, #dispose, #extract_args, #handle_observation_request, #has_style?, #pack_same_size, #remove_observer, swt_widget_class_for, #sync_exec, widget_exists?, #widget_property_listener_installers
Methods included from DataBinding::ObservableWidget
Constructor Details
#initialize(parent, args) ⇒ MenuProxy
Returns a new instance of MenuProxy.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 30 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::DataBinding::ObservableWidget
Instance Attribute Details
#menu_item_proxy ⇒ Object (readonly)
Returns the value of attribute menu_item_proxy.
28 29 30 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 28 def @menu_item_proxy end |
#menu_parent ⇒ Object (readonly)
Returns the value of attribute menu_parent.
28 29 30 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 28 def @menu_parent end |
#swt_menu_item ⇒ Object (readonly)
Returns the value of attribute swt_menu_item.
28 29 30 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 28 def @swt_menu_item end |
Instance Method Details
#get_attribute(attribute_name) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 75 def get_attribute(attribute_name) if attribute_name.to_s == "text" @swt_menu_item.getText else super(attribute_name) end end |
#has_attribute?(attribute_name, *args) ⇒ Boolean
57 58 59 60 61 62 63 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 57 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
65 66 67 68 69 70 71 72 73 |
# File 'lib/glimmer/swt/menu_proxy.rb', line 65 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 |