Class: Glimmer::SWT::DialogProxy

Inherits:
Object
  • Object
show all
Includes:
ProxyProperties
Defined in:
lib/glimmer/swt/dialog_proxy.rb

Overview

Proxy for org.eclipse.swt.widgets.Dialog superclass of dialogs like FileDialog, DirectoryDialog, ColorDialog, and FontDialog

(if you’re seeking the ‘dialog` keyword, that’s just a ‘shell` variation under ShellProxy instead.

Automatically uses the current shell if one is open. Otherwise, it instantiates a new shell parent

Optionally takes a shell as an argument

Follows the Proxy Design Pattern

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ProxyProperties

#get_attribute, #has_attribute?, #has_attribute_getter?, #has_attribute_setter?, #method_missing, #respond_to?, #set_attribute

Methods included from Properties

attribute_getter, #attribute_getter, attribute_setter, #attribute_setter, normalized_attribute, #normalized_attribute, ruby_attribute_getter, #ruby_attribute_setter, ruby_attribute_setter

Constructor Details

#initialize(keyword, *args, swt_dialog: nil) ⇒ DialogProxy

Returns a new instance of DialogProxy.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/glimmer/swt/dialog_proxy.rb', line 64

def initialize(keyword, *args, swt_dialog: nil)
  DisplayProxy.instance.auto_exec do
    dialog_class = self.class.dialog_class(keyword)
    if swt_dialog
      @swt_dialog = swt_dialog
    else
      style_args = args.select {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}
      if style_args.any?
        style_arg_start_index = args.index(style_args.first)
        style_arg_last_index = args.index(style_args.last)
        args[style_arg_start_index..style_arg_last_index] = SWTProxy[style_args]
      end
      if args.first.respond_to?(:swt_widget) && args.first.swt_widget.is_a?(Shell)
        args[0] = args[0].swt_widget
      end
      if !args.first.is_a?(Shell)
        current_shell = DisplayProxy.instance.swt_display.shells.first
        args.unshift(current_shell.nil? ? ShellProxy.new : current_shell)
      end
      parent = args[0]
      @parent_proxy = parent.is_a?(Shell) ? ShellProxy.new(swt_widget: parent) : parent
      @swt_dialog = dialog_class.new(*args)
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer::SWT::ProxyProperties

Instance Attribute Details

#swt_dialogObject (readonly)

Returns the value of attribute swt_dialog.



62
63
64
# File 'lib/glimmer/swt/dialog_proxy.rb', line 62

def swt_dialog
  @swt_dialog
end

Class Method Details

.dialog_class(keyword) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/glimmer/swt/dialog_proxy.rb', line 52

def dialog_class(keyword)
  the_class = eval(keyword.camelcase(:upper))
  the_class if the_class.ancestors.include?(org.eclipse.swt.widgets.Dialog)
rescue => e
  Glimmer::Config.logger.debug {"Dialog for keyword #{keyword} not found!"}
  Glimmer::Config.logger.debug { e.full_message }
  nil
end

Instance Method Details

#proxy_source_objectObject



90
91
92
# File 'lib/glimmer/swt/dialog_proxy.rb', line 90

def proxy_source_object
  @swt_dialog
end