Class: Glimmer::SWT::MenuProxy

Inherits:
WidgetProxy show all
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

Attributes inherited from WidgetProxy

#swt_widget

Instance Method Summary collapse

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

#method_missing

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.swt_widget.is_a?(Menu)
    styles = styles.unshift(:pop_up)
  end

  swt_widget_class = self.class.swt_widget_class_for('menu')
  if parent.swt_widget.is_a?(Menu)
    @menu_item_proxy = SWT::WidgetProxy.new('menu_item', parent, [:cascade] + [index].compact)
    @swt_menu_item = @menu_item_proxy.swt_widget
    @swt_widget = swt_widget_class.new(@menu_item_proxy.swt_widget)
    @swt_menu_item.setMenu(swt_widget)
  elsif parent.swt_widget.is_a?(Shell)
    @swt_widget = swt_widget_class.new(parent.swt_widget, style('menu', styles))
  else
    @swt_widget = swt_widget_class.new(parent.swt_widget)
  end
  DEFAULT_INITIALIZERS['menu']&.call(swt_widget)

  if styles.include?(:bar)
    parent.swt_widget.setMenuBar(swt_widget)
  elsif styles.include?(:pop_up)
    parent.swt_widget.setMenu(swt_widget)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer::DataBinding::ObservableWidget

Instance Attribute Details

Returns the value of attribute menu_item_proxy.



28
29
30
# File 'lib/glimmer/swt/menu_proxy.rb', line 28

def menu_item_proxy
  @menu_item_proxy
end

Returns the value of attribute menu_parent.



28
29
30
# File 'lib/glimmer/swt/menu_proxy.rb', line 28

def menu_parent
  @menu_parent
end

#swt_menu_itemObject (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
  @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

Returns:

  • (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