Class: Glimmer::SWT::WidgetProxy

Inherits:
Object
  • Object
show all
Includes:
Custom::Drawable, Packages, ProxyProperties
Defined in:
lib/glimmer/swt/widget_proxy.rb

Overview

Proxy for SWT Widget objects

Sets default SWT styles to widgets upon inititalizing as per DEFAULT_STYLES

Also, auto-initializes widgets as per initializer blocks in DEFAULT_INITIALIZERS (e.g. setting Composite default layout)

Follows the Proxy Design Pattern

Constant Summary collapse

DEFAULT_STYLES =
{
  'arrow'               => [:arrow],
  'button'              => [:push],
  'canvas'              => ([:double_buffered] unless OS.mac?),
  'ccombo'              => [:border],
  'checkbox'            => [:check],
  'check'               => [:check],
  'drag_source'         => [:drop_copy],
  'drop_target'         => [:drop_copy],
  'expand_bar'          => [:v_scroll],
  'list'                => [:border, :v_scroll],
  'menu_item'           => [:push],
  'radio'               => [:radio],
  'scrolled_composite'  => [:border, :h_scroll, :v_scroll],
  'spinner'             => [:border],
  'styled_text'         => [:border, :multi, :v_scroll, :h_scroll],
  'table'               => [:virtual, :border, :full_selection],
  'text'                => [:border],
  'toggle'              => [:toggle],
  'tool_bar'            => [:push],
  'tool_item'           => [:push],
  'tree'                => [:virtual, :border, :h_scroll, :v_scroll],
  'date_drop_down'      => [:date, :drop_down],
  'time'                => [:time],
  'calendar'            => [:calendar],
}
DEFAULT_INITIALIZERS =
{
  composite: lambda do |composite|
    composite.layout = GridLayout.new if composite.get_layout.nil?
  end,
  canvas: lambda do |canvas|
    canvas.layout = nil if canvas.respond_to?('layout=') && !canvas.get_layout.nil?
  end,
  scrolled_composite: lambda do |scrolled_composite|
    scrolled_composite.expand_horizontal = true
    scrolled_composite.expand_vertical = true
  end,
  table: lambda do |table|
    table.setHeaderVisible(true)
    table.setLinesVisible(true)
  end,
  table_column: lambda do |table_column|
    table_column.setWidth(80)
  end,
  group: lambda do |group|
    group.layout = GridLayout.new if group.get_layout.nil?
  end,
}
KEYWORD_ALIASES =
{
  'arrow'          => 'button',
  'checkbox'       => 'button',
  'check'          => 'button',
  'radio'          => 'button',
  'toggle'         => 'button',
  'date'           => 'date_time',
  'date_drop_down' => 'date_time',
  'time'           => 'date_time',
  'calendar'       => 'date_time',
}

Instance Attribute Summary collapse

Attributes included from Custom::Drawable

#image_double_buffered, #requires_shape_disposal

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Custom::Drawable

#add_shape, #clear_shapes, #deregister_shape_painting, #expanded_shapes, #image_buffered_shapes, #paint_pixel_by_pixel, #setup_shape_painting, #shape_at_location, #shapes, #swt_drawable

Methods included from ProxyProperties

#has_attribute_getter?, #has_attribute_setter?

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

Methods included from Packages

included

Constructor Details

#initialize(*init_args, swt_widget: nil) ⇒ WidgetProxy

Initializes a new SWT Widget

It is preferred to use ‘::create` method instead since it instantiates the right subclass per widget keyword

keyword, parent, swt_widget_args (including styles)

Styles is a comma separate list of symbols representing SWT styles in lower case



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/glimmer/swt/widget_proxy.rb', line 154

def initialize(*init_args, swt_widget: nil)
  auto_exec do
    @image_double_buffered = !!(init_args&.last&.include?(:image_double_buffered) && init_args&.last&.delete(:image_double_buffered))
    if swt_widget.nil?
      underscored_widget_name, parent, args = init_args
      @parent_proxy = parent
      styles, extra_options = extract_args(underscored_widget_name, args)
      swt_widget_class = self.class.swt_widget_class_for(underscored_widget_name)
      @swt_widget = swt_widget_class.new(@parent_proxy.swt_widget, style(underscored_widget_name, styles), *extra_options)
    else
      @swt_widget = swt_widget
      underscored_widget_name = self.class.underscored_widget_name(@swt_widget)
      parent_proxy_class = self.class.widget_proxy_class(self.class.underscored_widget_name(@swt_widget.parent))
      parent = swt_widget.parent
      @parent_proxy = parent&.get_data('proxy') || parent_proxy_class.new(swt_widget: parent)
    end
    if @swt_widget&.get_data('proxy').nil?
      @swt_widget.set_data('proxy', self)
      DEFAULT_INITIALIZERS[underscored_widget_name.to_s.to_sym]&.call(@swt_widget)
      @parent_proxy.post_initialize_child(self)
    end
    @keyword = underscored_widget_name.to_s
    if respond_to?(:on_widget_disposed)
      on_widget_disposed {
        clear_shapes
        deregister_shape_painting
      }
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



730
731
732
733
734
735
736
737
# File 'lib/glimmer/swt/widget_proxy.rb', line 730

def method_missing(method, *args, &block)
  # TODO push most of this logic down to Properties (and perhaps create Listeners module as well)
  if can_handle_observation_request?(method)
    handle_observation_request(method, &block)
  else
    super
  end
end

Instance Attribute Details

#drag_source_proxyObject (readonly)

Returns the value of attribute drag_source_proxy.



143
144
145
# File 'lib/glimmer/swt/widget_proxy.rb', line 143

def drag_source_proxy
  @drag_source_proxy
end

#drag_source_styleObject

Returns the value of attribute drag_source_style.



143
144
145
# File 'lib/glimmer/swt/widget_proxy.rb', line 143

def drag_source_style
  @drag_source_style
end

#drag_source_transferObject

Returns the value of attribute drag_source_transfer.



143
144
145
# File 'lib/glimmer/swt/widget_proxy.rb', line 143

def drag_source_transfer
  @drag_source_transfer
end

#drop_target_proxyObject (readonly)

Returns the value of attribute drop_target_proxy.



143
144
145
# File 'lib/glimmer/swt/widget_proxy.rb', line 143

def drop_target_proxy
  @drop_target_proxy
end

#drop_target_transferObject

Returns the value of attribute drop_target_transfer.



143
144
145
# File 'lib/glimmer/swt/widget_proxy.rb', line 143

def drop_target_transfer
  @drop_target_transfer
end

#finished_add_contentObject (readonly) Also known as: finished_add_content?

Returns the value of attribute finished_add_content.



143
144
145
# File 'lib/glimmer/swt/widget_proxy.rb', line 143

def finished_add_content
  @finished_add_content
end

#parent_proxyObject (readonly)

Returns the value of attribute parent_proxy.



143
144
145
# File 'lib/glimmer/swt/widget_proxy.rb', line 143

def parent_proxy
  @parent_proxy
end

#swt_widgetObject (readonly)

Returns the value of attribute swt_widget.



143
144
145
# File 'lib/glimmer/swt/widget_proxy.rb', line 143

def swt_widget
  @swt_widget
end

Class Method Details

.create(*init_args, swt_widget: nil) ⇒ Object

Instantiates the right WidgetProxy subclass for passed in keyword Args are: keyword, parent, swt_widget_args (including styles)



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/glimmer/swt/widget_proxy.rb', line 115

def create(*init_args, swt_widget: nil)
  DisplayProxy.instance.auto_exec do
    return swt_widget.get_data('proxy') if swt_widget&.get_data('proxy')
    keyword, parent, args = init_args
    selected_widget_proxy_class = widget_proxy_class(keyword || underscored_widget_name(swt_widget))
    if init_args.empty?
      selected_widget_proxy_class.new(swt_widget: swt_widget)
    else
      selected_widget_proxy_class.new(*init_args)
    end
  end
end

.flyweight_swt_widget_classesObject

Flyweight Design Pattern memoization cache. Can be cleared if memory is needed.



583
584
585
# File 'lib/glimmer/swt/widget_proxy.rb', line 583

def self.flyweight_swt_widget_classes
  @flyweight_swt_widget_classes ||= {}
end

.swt_widget_class_for(underscored_widget_name) ⇒ Object

This supports widgets in and out of basic SWT



553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'lib/glimmer/swt/widget_proxy.rb', line 553

def self.swt_widget_class_for(underscored_widget_name)
  # TODO clear memoization for a keyword if a custom widget was defined with that keyword
  unless flyweight_swt_widget_classes.keys.include?(underscored_widget_name)
    begin
      underscored_widget_name = KEYWORD_ALIASES[underscored_widget_name] if KEYWORD_ALIASES[underscored_widget_name]
      swt_widget_name = underscored_widget_name.camelcase(:upper)
      swt_widget_class = eval(swt_widget_name)
      # TODO fix issue with not detecting DateTime because it's conflicting with the Ruby DateTime
      unless swt_widget_class.ancestors.include?(org.eclipse.swt.widgets.Widget)
        swt_widget_class = swt_widget_class_manual_entries[underscored_widget_name]
        if swt_widget_class.nil?
          Glimmer::Config.logger.debug {"Class #{swt_widget_class} matching #{underscored_widget_name} is not a subclass of org.eclipse.swt.widgets.Widget"}
          return nil
        end
      end
      flyweight_swt_widget_classes[underscored_widget_name] = swt_widget_class
    rescue SyntaxError, NameError => e
      Glimmer::Config.logger.debug {e.full_message}
      # Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
      nil
    rescue => e
      Glimmer::Config.logger.debug {e.full_message}
      # Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
      nil
    end
  end
  flyweight_swt_widget_classes[underscored_widget_name]
end

.swt_widget_class_manual_entriesObject

Manual entries of SWT widget classes that conflict with Ruby classes



546
547
548
549
550
# File 'lib/glimmer/swt/widget_proxy.rb', line 546

def self.swt_widget_class_manual_entries
  {
    'date_time' => Java::OrgEclipseSwtWidgets::DateTime
  }
end

.underscored_widget_name(swt_widget) ⇒ Object



138
139
140
# File 'lib/glimmer/swt/widget_proxy.rb', line 138

def underscored_widget_name(swt_widget)
  swt_widget.class.name.split(/::|\./).last.underscore
end

.widget_exists?(underscored_widget_name) ⇒ Boolean

Returns:

  • (Boolean)


541
542
543
# File 'lib/glimmer/swt/widget_proxy.rb', line 541

def self.widget_exists?(underscored_widget_name)
  !!swt_widget_class_for(underscored_widget_name)
end

.widget_proxy_class(keyword) ⇒ Object



128
129
130
131
132
133
134
135
136
# File 'lib/glimmer/swt/widget_proxy.rb', line 128

def widget_proxy_class(keyword)
  begin
    keyword = KEYWORD_ALIASES[keyword] if KEYWORD_ALIASES[keyword]
    class_name = "#{keyword.camelcase(:upper)}Proxy".to_sym
    Glimmer::SWT.const_get(class_name)
  rescue
    Glimmer::SWT::WidgetProxy
  end
end

Instance Method Details

#add_observer(observer, property_name) ⇒ Object

Used for data-binding only. Consider renaming or improving to avoid the confusion it causes



633
634
635
636
637
638
639
640
641
# File 'lib/glimmer/swt/widget_proxy.rb', line 633

def add_observer(observer, property_name)
  if !observer.respond_to?(:binding_options) || !observer.binding_options[:read_only]
    auto_exec do
      property_listener_installers = @swt_widget.class.ancestors.map {|ancestor| widget_property_listener_installers[ancestor]}.compact
      widget_listener_installers = property_listener_installers.map{|installer| installer[property_name.to_s.to_sym]}.compact if !property_listener_installers.empty?
      widget_listener_installers.to_a.first&.call(observer)
    end
  end
end

#async_exec(&block) ⇒ Object

delegates to DisplayProxy



588
589
590
# File 'lib/glimmer/swt/widget_proxy.rb', line 588

def async_exec(&block)
  DisplayProxy.instance.async_exec(&block)
end

#auto_exec(override_sync_exec: nil, override_async_exec: nil, &block) ⇒ Object

delegates to DisplayProxy



603
604
605
# File 'lib/glimmer/swt/widget_proxy.rb', line 603

def auto_exec(override_sync_exec: nil, override_async_exec: nil, &block)
  DisplayProxy.instance.auto_exec(override_sync_exec: override_sync_exec, override_async_exec: override_async_exec, &block)
end

#can_add_observer?(property_name) ⇒ Boolean

TODO Consider renaming these methods as they are mainly used for data-binding

Returns:

  • (Boolean)


626
627
628
629
630
# File 'lib/glimmer/swt/widget_proxy.rb', line 626

def can_add_observer?(property_name)
  auto_exec do
    @swt_widget.class.ancestors.map {|ancestor| widget_property_listener_installers[ancestor]}.compact.map(&:keys).flatten.map(&:to_s).include?(property_name.to_s)
  end
end

#can_handle_drag_observation_request?(observation_request) ⇒ Boolean

Returns:

  • (Boolean)


675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
# File 'lib/glimmer/swt/widget_proxy.rb', line 675

def can_handle_drag_observation_request?(observation_request)
  auto_exec do
    return false unless swt_widget.is_a?(Control)
    potential_drag_source = @drag_source_proxy.nil?
    ensure_drag_source_proxy
    @drag_source_proxy.can_handle_observation_request?(observation_request).tap do |result|
      if potential_drag_source && !result
        @drag_source_proxy.swt_widget.dispose
        @drag_source_proxy = nil
      end
    end
  end
rescue => e
  Glimmer::Config.logger.debug {e.full_message}
  false
end

#can_handle_drop_observation_request?(observation_request) ⇒ Boolean

Returns:

  • (Boolean)


692
693
694
695
696
697
698
699
700
701
702
703
704
# File 'lib/glimmer/swt/widget_proxy.rb', line 692

def can_handle_drop_observation_request?(observation_request)
  auto_exec do
    return false unless swt_widget.is_a?(Control)
    potential_drop_target = @drop_target_proxy.nil?
    ensure_drop_target_proxy
    @drop_target_proxy.can_handle_observation_request?(observation_request).tap do |result|
      if potential_drop_target && !result
        @drop_target_proxy.swt_widget.dispose
        @drop_target_proxy = nil
      end
    end
  end
end

#can_handle_observation_request?(observation_request) ⇒ Boolean

TODO eliminate duplication in the following methods perhaps by relying on exceptions

Returns:

  • (Boolean)


664
665
666
667
668
669
670
671
672
673
# File 'lib/glimmer/swt/widget_proxy.rb', line 664

def can_handle_observation_request?(observation_request)
  observation_request = normalize_observation_request(observation_request)
  if observation_request.start_with?('on_swt_')
    constant_name = observation_request.sub(/^on_swt_/, '')
    SWTProxy.has_constant?(constant_name)
  elsif observation_request.start_with?('on_')
    event = observation_request.sub(/^on_/, '')
    can_add_listener?(event) || can_handle_drag_observation_request?(observation_request) || can_handle_drop_observation_request?(observation_request)
  end
end

#content(&block) ⇒ Object



724
725
726
727
728
# File 'lib/glimmer/swt/widget_proxy.rb', line 724

def content(&block)
  auto_exec do
    Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::WidgetExpression.new, @keyword, &block)
  end
end

#disposeObject



614
615
616
617
618
# File 'lib/glimmer/swt/widget_proxy.rb', line 614

def dispose
  auto_exec do
    @swt_widget.dispose
  end
end

#disposed?Boolean

Returns:

  • (Boolean)


620
621
622
# File 'lib/glimmer/swt/widget_proxy.rb', line 620

def disposed?
  @swt_widget.isDisposed
end

#ensure_drag_source_proxy(style = []) ⇒ Object



647
648
649
650
651
# File 'lib/glimmer/swt/widget_proxy.rb', line 647

def ensure_drag_source_proxy(style=[])
  @drag_source_proxy ||= self.class.new('drag_source', self, style).tap do |proxy|
    proxy.set_attribute(:transfer, :text)
  end
end

#ensure_drop_target_proxy(style = []) ⇒ Object



653
654
655
656
657
658
659
660
# File 'lib/glimmer/swt/widget_proxy.rb', line 653

def ensure_drop_target_proxy(style=[])
  @drop_target_proxy ||= WidgetProxy.new('drop_target', self, style).tap do |proxy|
    proxy.set_attribute(:transfer, :text)
    proxy.on_drag_enter { |event|
      event.detail = DNDProxy[:drop_copy]
    }
  end
end

#extract_args(underscored_widget_name, args) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/glimmer/swt/widget_proxy.rb', line 201

def extract_args(underscored_widget_name, args)
  @arg_extractor_mapping ||= {
    'menu_item' => lambda do |args|
      index = args.delete(args.last) if args.last.is_a?(Numeric)
      extra_options = [index].compact
      styles = args
      [styles, extra_options]
    end,
  }
  if @arg_extractor_mapping[underscored_widget_name]
    @arg_extractor_mapping[underscored_widget_name].call(args)
  else
    extra_options = []
    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)
      extra_options = args[style_arg_last_index+1..-1]
      args = args[style_arg_start_index..style_arg_last_index]
    elsif args.first.is_a?(Integer)
      extra_options = args[1..-1]
      args = args[0..0]
    end
    [args, extra_options]
  end
end

#finish_add_content!Object



197
198
199
# File 'lib/glimmer/swt/widget_proxy.rb', line 197

def finish_add_content!
  @finished_add_content = true
end

#get_attribute(attribute_name) ⇒ Object



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/glimmer/swt/widget_proxy.rb', line 265

def get_attribute(attribute_name)
  widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
  swt_widget_operation = false
  result = nil
  auto_exec do
    result = if widget_custom_attribute
      swt_widget_operation = true
      if widget_custom_attribute[:getter][:invoker]
        widget_custom_attribute[:getter][:invoker].call(@swt_widget, [])
      else
        @swt_widget.send(widget_custom_attribute[:getter][:name])
      end
    end
  end
  result = super unless swt_widget_operation
  result
end

#handle_observation_request(observation_request, &block) ⇒ Object



706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
# File 'lib/glimmer/swt/widget_proxy.rb', line 706

def handle_observation_request(observation_request, &block)
  observation_request = normalize_observation_request(observation_request)
  if observation_request.start_with?('on_swt_')
    constant_name = observation_request.sub(/^on_swt_/, '')
    add_swt_event_listener(constant_name, &block)
  elsif observation_request.start_with?('on_')
    event = observation_request.sub(/^on_/, '')
    if can_add_listener?(event)
      event = observation_request.sub(/^on_/, '')
      add_listener(event, &block)
    elsif can_handle_drag_observation_request?(observation_request)
      @drag_source_proxy&.handle_observation_request(observation_request, &block)
    elsif can_handle_drop_observation_request?(observation_request)
      @drop_target_proxy&.handle_observation_request(observation_request, &block)
    end
  end
end

#has_attribute?(attribute_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/glimmer/swt/widget_proxy.rb', line 232

def has_attribute?(attribute_name, *args)
  # TODO test that attribute getter responds too
  widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
  property_type_converter = property_type_converters[attribute_name.to_s.to_sym]
  auto_exec do
    if widget_custom_attribute
      @swt_widget.respond_to?(widget_custom_attribute[:setter][:name])
    elsif property_type_converter
      true
    else
      super
    end
  end
end

#has_style?(style) ⇒ Boolean

Returns:

  • (Boolean)


607
608
609
610
611
612
# File 'lib/glimmer/swt/widget_proxy.rb', line 607

def has_style?(style)
  comparison = interpret_style(style)
  auto_exec do
    (@swt_widget.style & comparison) == comparison
  end
end

#heightObject



311
312
313
# File 'lib/glimmer/swt/widget_proxy.rb', line 311

def height
  bounds.height
end

#pack_same_sizeObject



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/glimmer/swt/widget_proxy.rb', line 283

def pack_same_size
  auto_exec do
    bounds = @swt_widget.getBounds
    listener = on_control_resized {
      @swt_widget.setSize(bounds.width, bounds.height)
      @swt_widget.setLocation(bounds.x, bounds.y)
    }
    if @swt_widget.is_a?(Composite)
      @swt_widget.layout(true, true)
    else
      @swt_widget.pack(true)
    end
    @swt_widget.removeControlListener(listener.swt_listener)
  end
end

#post_add_contentObject

Subclasses may override to perform post add_content work. Make sure its logic detects if it ran before since it could run multiple times when adding content multiple times post creation.



193
194
195
# File 'lib/glimmer/swt/widget_proxy.rb', line 193

def post_add_content
  # No Op by default
end

#post_initialize_child(child) ⇒ Object

Subclasses may override to perform post initialization work on an added child



186
187
188
# File 'lib/glimmer/swt/widget_proxy.rb', line 186

def post_initialize_child(child)
  # No Op by default
end

#proxy_source_objectObject



228
229
230
# File 'lib/glimmer/swt/widget_proxy.rb', line 228

def proxy_source_object
  @swt_widget
end

#remove_observer(observer, property_name) ⇒ Object



643
644
645
# File 'lib/glimmer/swt/widget_proxy.rb', line 643

def remove_observer(observer, property_name)
  # TODO consider implementing if remove_observer is needed (consumers can remove listener via SWT API)
end

#respond_to?(method, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


739
740
741
742
743
744
745
# File 'lib/glimmer/swt/widget_proxy.rb', line 739

def respond_to?(method, *args, &block)
  result = super
  return true if result
  auto_exec do
    can_handle_observation_request?(method)
  end
end

#set_attribute(attribute_name, *args) ⇒ Object



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/glimmer/swt/widget_proxy.rb', line 247

def set_attribute(attribute_name, *args)
  # TODO Think about widget subclasses overriding set_attribute to add more attributes vs adding as Ruby attributes directly
  widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
  auto_exec do
    apply_property_type_converters(normalized_attribute(attribute_name), args)
  end
  swt_widget_operation = false
  result = nil
  auto_exec do
    result = if widget_custom_attribute
      swt_widget_operation = true
      widget_custom_attribute[:setter][:invoker].call(@swt_widget, args)
    end
  end
  result = super unless swt_widget_operation
  result
end

#sync_exec(&block) ⇒ Object

delegates to DisplayProxy



593
594
595
# File 'lib/glimmer/swt/widget_proxy.rb', line 593

def sync_exec(&block)
  DisplayProxy.instance.sync_exec(&block)
end

#timer_exec(delay_in_millis, &block) ⇒ Object

delegates to DisplayProxy



598
599
600
# File 'lib/glimmer/swt/widget_proxy.rb', line 598

def timer_exec(delay_in_millis, &block)
  DisplayProxy.instance.timer_exec(delay_in_millis, &block)
end

#widget_property_listener_installersObject

these work in tandem with the property_type_converters sometimes, they are specified in subclasses instead



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
# File 'lib/glimmer/swt/widget_proxy.rb', line 317

def widget_property_listener_installers
  @swt_widget_property_listener_installers ||= {
    Java::OrgEclipseSwtWidgets::Control => {
      :focus => lambda do |observer|
        on_focus_gained { |focus_event|
          observer.call(true)
        }
        on_focus_lost { |focus_event|
          observer.call(false)
        }
      end,
      :selection => lambda do |observer|
        on_widget_selected { |selection_event|
          observer.call(@swt_widget.getSelection)
        } if can_handle_observation_request?(:on_widget_selected)
      end,
      :text => lambda do |observer|
        on_modify_text { |modify_event|
          observer.call(@swt_widget.getText)
        } if can_handle_observation_request?(:on_modify_text)
      end,
    },
    Java::OrgEclipseSwtWidgets::Combo => {
      :text => lambda do |observer|
        on_modify_text { |modify_event|
          observer.call(@swt_widget.getText)
        }
      end,
    },
    Java::OrgEclipseSwtCustom::CCombo => {
      :text => lambda do |observer|
        on_modify_text { |modify_event|
          observer.call(@swt_widget.getText)
        }
      end,
    },
    Java::OrgEclipseSwtWidgets::Table => {
      :selection => lambda do |observer|
        on_widget_selected { |selection_event|
          if has_style?(:multi)
            observer.call(@swt_widget.getSelection.map(&:get_data))
          else
            observer.call(@swt_widget.getSelection.first&.get_data)
          end
        }
      end,
    },
    Java::OrgEclipseSwtWidgets::Tree => {
      :selection => lambda do |observer|
        on_widget_selected { |selection_event|
          if has_style?(:multi)
            observer.call(@swt_widget.getSelection.map(&:get_data))
          else
            observer.call(@swt_widget.getSelection.first&.get_data)
          end
        }
      end,
    },
    Java::OrgEclipseSwtWidgets::Text => {
      :text => lambda do |observer|
        on_modify_text { |modify_event|
          observer.call(@swt_widget.getText)
        }
      end,
      :caret_position => lambda do |observer|
        on_swt_keydown { |event|
          observer.call(@swt_widget.getCaretPosition)
        }
        on_swt_keyup { |event|
          observer.call(@swt_widget.getCaretPosition)
        }
        on_swt_mousedown { |event|
          observer.call(@swt_widget.getCaretPosition)
        }
        on_swt_mouseup { |event|
          observer.call(@swt_widget.getCaretPosition)
        }
      end,
      :selection => lambda do |observer|
        on_swt_keydown { |event|
          observer.call(@swt_widget.getSelection)
        }
        on_swt_keyup { |event|
          observer.call(@swt_widget.getSelection)
        }
        on_swt_mousedown { |event|
          observer.call(@swt_widget.getSelection)
        }
        on_swt_mouseup { |event|
          observer.call(@swt_widget.getSelection)
        }
      end,
      :selection_count => lambda do |observer|
        on_swt_keydown { |event|
          observer.call(@swt_widget.getSelectionCount)
        }
        on_swt_keyup { |event|
          observer.call(@swt_widget.getSelectionCount)
        }
        on_swt_mousedown { |event|
          observer.call(@swt_widget.getSelectionCount)
        }
        on_swt_mouseup { |event|
          observer.call(@swt_widget.getSelectionCount)
        }
      end,
      :top_index => lambda do |observer|
        @last_top_index = @swt_widget.getTopIndex
        on_paint_control { |event|
          if @swt_widget.getTopIndex != @last_top_index
            @last_top_index = @swt_widget.getTopIndex
            observer.call(@last_top_index)
          end
        }
      end,
    },
    Java::OrgEclipseSwtCustom::StyledText => {
      :text => lambda do |observer|
        on_modify_text { |modify_event|
          observer.call(@swt_widget.getText)
        }
      end,
      :caret_position => lambda do |observer|
        on_caret_moved { |event|
          observer.call(@swt_widget.getSelection.x) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
        }
        on_swt_keyup { |event|
          observer.call(@swt_widget.getSelection.x) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
        }
        on_swt_mouseup { |event|
          observer.call(@swt_widget.getSelection.x) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
        }
      end,
      :caret_offset => lambda do |observer|
        on_caret_moved { |event|
          observer.call(@swt_widget.getCaretOffset) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
        }
      end,
      :selection => lambda do |observer|
        on_widget_selected { |event|
          observer.call(@swt_widget.getSelection) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
        }
        on_swt_keyup { |event|
          observer.call(@swt_widget.getSelection) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
        }
        on_swt_mouseup { |event|
          observer.call(@swt_widget.getSelection) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
        }
      end,
      :selection_count => lambda do |observer|
        on_widget_selected { |event|
          observer.call(@swt_widget.getSelectionCount) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
        }
        on_swt_keyup { |event|
          observer.call(@swt_widget.getSelectionCount) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
        }
        on_swt_mouseup { |event|
          observer.call(@swt_widget.getSelectionCount) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
        }
      end,
      :selection_range => lambda do |observer|
        on_widget_selected { |event|
          observer.call(@swt_widget.getSelectionRange) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
        }
        on_swt_keyup { |event|
          observer.call(@swt_widget.getSelectionRange) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
        }
        on_swt_mouseup { |event|
          observer.call(@swt_widget.getSelectionRange) unless @swt_widget.getCaretOffset == 0 && @last_modify_text != text
        }
      end,
      :top_index => lambda do |observer|
        @last_top_index = @swt_widget.getTopIndex
        on_paint_control { |event|
          if @swt_widget.getTopIndex != @last_top_index
            @last_top_index = @swt_widget.getTopIndex
            observer.call(@last_top_index)
          end
        }
      end,
      :top_pixel => lambda do |observer|
        @last_top_pixel = @swt_widget.getTopPixel
        on_paint_control { |event|
          if @swt_widget.getTopPixel != @last_top_pixel
            @last_top_pixel = @swt_widget.getTopPixel
            observer.call(@last_top_pixel)
          end
        }
      end,
    },
    Java::OrgEclipseSwtWidgets::Button => {
      :selection => lambda do |observer|
        on_widget_selected { |selection_event|
          observer.call(@swt_widget.getSelection)
        }
      end
    },
    Java::OrgEclipseSwtWidgets::MenuItem => {
      :selection => lambda do |observer|
        on_widget_selected { |selection_event|
          observer.call(@swt_widget.getSelection)
        }
      end
    },
    Java::OrgEclipseSwtWidgets::Spinner => {
      :selection => lambda do |observer|
        on_widget_selected { |selection_event|
          observer.call(@swt_widget.getSelection)
        }
      end
    },
    Java::OrgEclipseSwtWidgets::DateTime =>
      [:year, :month, :day, :hours, :minutes, :seconds, :date_time, :date, :time].reduce({}) do |hash, attribute|
        hash.merge(
          attribute => lambda do |observer|
            on_widget_selected { |selection_event|
              observer.call(get_attribute(attribute))
            }
          end
        )
      end,
  }
end

#widthObject



307
308
309
# File 'lib/glimmer/swt/widget_proxy.rb', line 307

def width
  bounds.width
end

#xObject



299
300
301
# File 'lib/glimmer/swt/widget_proxy.rb', line 299

def x
  bounds.x
end

#yObject



303
304
305
# File 'lib/glimmer/swt/widget_proxy.rb', line 303

def y
  bounds.y
end