Class: Glimmer::SWT::WidgetProxy
- Inherits:
-
Object
- Object
- Glimmer::SWT::WidgetProxy
- Includes:
- Custom::Drawable, Packages, Properties
- 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
Direct Known Subclasses
DateTimeProxy, DirectoryDialogProxy, ExpandItemProxy, FileDialogProxy, MenuProxy, SashFormProxy, ScrolledCompositeProxy, ShellProxy, StyledTextProxy, TabItemProxy, TableColumnProxy, TableProxy, TreeProxy
Constant Summary collapse
- DEFAULT_STYLES =
{ 'arrow' => [:arrow], 'button' => [:push], 'canvas' => [:double_buffered], '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. = true scrolled_composite. = 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
-
#drag_source_proxy ⇒ Object
readonly
Returns the value of attribute drag_source_proxy.
-
#drag_source_style ⇒ Object
readonly
Returns the value of attribute drag_source_style.
-
#drag_source_transfer ⇒ Object
readonly
Returns the value of attribute drag_source_transfer.
-
#drop_target_proxy ⇒ Object
readonly
Returns the value of attribute drop_target_proxy.
-
#drop_target_transfer ⇒ Object
readonly
Returns the value of attribute drop_target_transfer.
-
#finished_add_content ⇒ Object
(also: #finished_add_content?)
readonly
Returns the value of attribute finished_add_content.
-
#parent_proxy ⇒ Object
readonly
Returns the value of attribute parent_proxy.
-
#swt_widget ⇒ Object
readonly
Returns the value of attribute swt_widget.
Attributes included from Custom::Drawable
#image_double_buffered, #requires_shape_disposal
Class Method Summary collapse
-
.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).
-
.flyweight_swt_widget_classes ⇒ Object
Flyweight Design Pattern memoization cache.
-
.swt_widget_class_for(underscored_widget_name) ⇒ Object
This supports widgets in and out of basic SWT.
-
.swt_widget_class_manual_entries ⇒ Object
Manual entries of SWT widget classes that conflict with Ruby classes.
- .underscored_widget_name(swt_widget) ⇒ Object
- .widget_exists?(underscored_widget_name) ⇒ Boolean
- .widget_proxy_class(keyword) ⇒ Object
Instance Method Summary collapse
-
#add_observer(observer, property_name) ⇒ Object
Used for data-binding only.
- #async_exec(&block) ⇒ Object
-
#can_add_observer?(property_name) ⇒ Boolean
TODO Consider renaming these methods as they are mainly used for data-binding.
- #can_handle_drag_observation_request?(observation_request) ⇒ Boolean
- #can_handle_drop_observation_request?(observation_request) ⇒ Boolean
-
#can_handle_observation_request?(observation_request) ⇒ Boolean
TODO eliminate duplication in the following methods perhaps by relying on exceptions.
- #content(&block) ⇒ Object
- #dispose ⇒ Object
- #disposed? ⇒ Boolean
- #ensure_drag_source_proxy(style = []) ⇒ Object
- #ensure_drop_target_proxy(style = []) ⇒ Object
- #extract_args(underscored_widget_name, args) ⇒ Object
- #finish_add_content! ⇒ Object
- #get_attribute(attribute_name) ⇒ Object
- #handle_observation_request(observation_request, &block) ⇒ Object
- #has_attribute?(attribute_name, *args) ⇒ Boolean
- #has_attribute_getter?(attribute_getter_name, *args) ⇒ Boolean
- #has_attribute_setter?(attribute_setter_name, *args) ⇒ Boolean
- #has_style?(style) ⇒ Boolean
-
#initialize(*init_args, swt_widget: nil) ⇒ WidgetProxy
constructor
Initializes a new SWT Widget.
- #method_missing(method, *args, &block) ⇒ Object
- #pack_same_size ⇒ Object
-
#post_add_content ⇒ Object
Subclasses may override to perform post add_content work.
-
#post_initialize_child(child) ⇒ Object
Subclasses may override to perform post initialization work on an added child.
- #remove_observer(observer, property_name) ⇒ Object
- #respond_to?(method, *args, &block) ⇒ Boolean
- #set_attribute(attribute_name, *args) ⇒ Object
- #sync_exec(&block) ⇒ Object
- #timer_exec(delay_in_millis, &block) ⇒ Object
- #widget_property_listener_installers ⇒ Object
Methods included from Custom::Drawable
#add_shape, #clear_shapes, #deregister_shape_painting, #image_buffered_shapes, #setup_shape_painting, #shapes
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
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
151 152 153 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 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 151 def initialize(*init_args, swt_widget: nil) @image_double_buffered = !!(init_args&.last&.include?(:image_double_buffered) && init_args&.last&.delete(:image_double_buffered)) if .nil? , parent, args = init_args @parent_proxy = parent styles, = extract_args(, args) = self.class.() @swt_widget = .new(@parent_proxy., style(, styles), *) else @swt_widget = = self.class.(@swt_widget) parent_proxy_class = self.class.(self.class.(@swt_widget.parent)) parent = .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[.to_s.to_sym]&.call(@swt_widget) @parent_proxy.post_initialize_child(self) end @keyword = .to_s if respond_to?(:on_widget_disposed) { clear_shapes deregister_shape_painting } end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 670 def method_missing(method, *args, &block) if can_handle_observation_request?(method) handle_observation_request(method, &block) elsif has_attribute_setter?(method, *args) set_attribute(method, *args) elsif has_attribute_getter?(method, *args) get_attribute(method, *args) else .send(method, *args, &block) end rescue => e Glimmer::Config.logger.debug { "Neither WidgetProxy nor #{.class.name} can handle the method ##{method}" } Glimmer::Config.logger.debug { e. } super # TODO consider get_attribute too end |
Instance Attribute Details
#drag_source_proxy ⇒ Object (readonly)
Returns the value of attribute drag_source_proxy.
140 141 142 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 140 def drag_source_proxy @drag_source_proxy end |
#drag_source_style ⇒ Object
Returns the value of attribute drag_source_style.
140 141 142 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 140 def drag_source_style @drag_source_style end |
#drag_source_transfer ⇒ Object
Returns the value of attribute drag_source_transfer.
140 141 142 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 140 def drag_source_transfer @drag_source_transfer end |
#drop_target_proxy ⇒ Object (readonly)
Returns the value of attribute drop_target_proxy.
140 141 142 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 140 def drop_target_proxy @drop_target_proxy end |
#drop_target_transfer ⇒ Object
Returns the value of attribute drop_target_transfer.
140 141 142 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 140 def drop_target_transfer @drop_target_transfer end |
#finished_add_content ⇒ Object (readonly) Also known as: finished_add_content?
Returns the value of attribute finished_add_content.
140 141 142 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 140 def finished_add_content @finished_add_content end |
#parent_proxy ⇒ Object (readonly)
Returns the value of attribute parent_proxy.
140 141 142 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 140 def parent_proxy @parent_proxy end |
#swt_widget ⇒ Object (readonly)
Returns the value of attribute swt_widget.
140 141 142 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 140 def @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)
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 114 def create(*init_args, swt_widget: nil) return .get_data('proxy') if &.get_data('proxy') keyword, parent, args = init_args = (keyword || ()) if init_args.empty? .new(swt_widget: ) else .new(*init_args) end end |
.flyweight_swt_widget_classes ⇒ Object
Flyweight Design Pattern memoization cache. Can be cleared if memory is needed.
545 546 547 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 545 def self. @flyweight_swt_widget_classes ||= {} end |
.swt_widget_class_for(underscored_widget_name) ⇒ Object
This supports widgets in and out of basic SWT
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 540 541 542 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 515 def self.() # TODO clear memoization for a keyword if a custom widget was defined with that keyword unless .keys.include?() begin = KEYWORD_ALIASES[] if KEYWORD_ALIASES[] = .camelcase(:upper) = eval() # TODO fix issue with not detecting DateTime because it's conflicting with the Ruby DateTime unless .ancestors.include?(org.eclipse.swt..Widget) = [] if .nil? Glimmer::Config.logger.debug {"Class #{} matching #{} is not a subclass of org.eclipse.swt.widgets.Widget"} return nil end end [] = rescue SyntaxError, NameError => e Glimmer::Config.logger.debug {e.} # Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"} nil rescue => e Glimmer::Config.logger.debug {e.} # Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"} nil end end [] end |
.swt_widget_class_manual_entries ⇒ Object
Manual entries of SWT widget classes that conflict with Ruby classes
508 509 510 511 512 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 508 def self. { 'date_time' => Java::OrgEclipseSwtWidgets::DateTime } end |
.underscored_widget_name(swt_widget) ⇒ Object
135 136 137 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 135 def () .class.name.split(/::|\./).last.underscore end |
.widget_exists?(underscored_widget_name) ⇒ Boolean
503 504 505 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 503 def self.() !!() end |
.widget_proxy_class(keyword) ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 125 def (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
581 582 583 584 585 586 587 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 581 def add_observer(observer, property_name) if !observer.respond_to?(:binding_options) || !observer.[:read_only] property_listener_installers = @swt_widget.class.ancestors.map {|ancestor| [ancestor]}.compact = property_listener_installers.map{|installer| installer[property_name.to_s.to_sym]}.compact if !property_listener_installers.empty? .to_a.first&.call(observer) end end |
#async_exec(&block) ⇒ Object
549 550 551 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 549 def async_exec(&block) DisplayProxy.instance.async_exec(&block) end |
#can_add_observer?(property_name) ⇒ Boolean
TODO Consider renaming these methods as they are mainly used for data-binding
576 577 578 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 576 def can_add_observer?(property_name) @swt_widget.class.ancestors.map {|ancestor| [ancestor]}.compact.map(&:keys).flatten.map(&:to_s).include?(property_name.to_s) end |
#can_handle_drag_observation_request?(observation_request) ⇒ Boolean
621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 621 def can_handle_drag_observation_request?(observation_request) return false unless .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..dispose @drag_source_proxy = nil end end rescue => e Glimmer::Config.logger.debug {e.} false end |
#can_handle_drop_observation_request?(observation_request) ⇒ Boolean
636 637 638 639 640 641 642 643 644 645 646 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 636 def can_handle_drop_observation_request?(observation_request) return false unless .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..dispose @drop_target_proxy = nil end end end |
#can_handle_observation_request?(observation_request) ⇒ Boolean
TODO eliminate duplication in the following methods perhaps by relying on exceptions
610 611 612 613 614 615 616 617 618 619 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 610 def can_handle_observation_request?(observation_request) observation_request = observation_request.to_s 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
666 667 668 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 666 def content(&block) Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::WidgetExpression.new, &block) end |
#dispose ⇒ Object
566 567 568 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 566 def dispose @swt_widget.dispose end |
#disposed? ⇒ Boolean
570 571 572 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 570 def disposed? @swt_widget.isDisposed end |
#ensure_drag_source_proxy(style = []) ⇒ Object
593 594 595 596 597 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 593 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
599 600 601 602 603 604 605 606 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 599 def ensure_drop_target_proxy(style=[]) @drop_target_proxy ||= self.class.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
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 196 def extract_args(, args) @arg_extractor_mapping ||= { 'menu_item' => lambda do |args| index = args.delete(args.last) if args.last.is_a?(Numeric) = [index].compact styles = args [styles, ] end, } if @arg_extractor_mapping[] @arg_extractor_mapping[].call(args) 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_last_index+1..-1] args = args[style_arg_start_index..style_arg_last_index] elsif args.first.is_a?(Integer) = args[1..-1] args = args[0..0] end [args, ] end end |
#finish_add_content! ⇒ Object
192 193 194 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 192 def finish_add_content! @finished_add_content = true end |
#get_attribute(attribute_name) ⇒ Object
262 263 264 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 262 def get_attribute(attribute_name) = [attribute_name.to_s] if if [:getter][:invoker] [:getter][:invoker].call(@swt_widget, []) else @swt_widget.send([:getter][:name]) end elsif @swt_widget.respond_to?(attribute_getter(attribute_name)) @swt_widget.send(attribute_getter(attribute_name)) elsif @swt_widget.respond_to?(ruby_attribute_getter(attribute_name)) @swt_widget.send(ruby_attribute_getter(attribute_name)) elsif @swt_widget.respond_to?(attribute_name) @swt_widget.send(attribute_name) elsif respond_to?(ruby_attribute_getter(attribute_name)) send(ruby_attribute_getter(attribute_name)) else send(attribute_name) end end |
#handle_observation_request(observation_request, &block) ⇒ Object
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 648 def handle_observation_request(observation_request, &block) observation_request = observation_request.to_s 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
237 238 239 240 241 242 243 244 245 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 237 def has_attribute?(attribute_name, *args) # TODO test that attribute getter responds too = [attribute_name.to_s] if @swt_widget.respond_to?([:setter][:name]) else @swt_widget.respond_to?(attribute_setter(attribute_name), args) || respond_to?(ruby_attribute_setter(attribute_name), args) end end |
#has_attribute_getter?(attribute_getter_name, *args) ⇒ Boolean
223 224 225 226 227 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 223 def has_attribute_getter?(attribute_getter_name, *args) attribute_getter_name = attribute_getter_name.to_s.underscore return false unless !attribute_getter_name.end_with?('=') && !attribute_getter_name.start_with?('set_') args.empty? && .respond_to?(attribute_getter_name) end |
#has_attribute_setter?(attribute_setter_name, *args) ⇒ Boolean
229 230 231 232 233 234 235 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 229 def has_attribute_setter?(attribute_setter_name, *args) attribute_setter_name = attribute_setter_name.to_s underscored_attribute_setter_name = attribute_setter_name.underscore return false unless attribute_setter_name.end_with?('=') || (attribute_setter_name.start_with?('set_') && !args.empty?) attribute_name = underscored_attribute_setter_name.sub(/^set_/, '').sub(/=$/, '') has_attribute?(attribute_name, *args) end |
#has_style?(style) ⇒ Boolean
561 562 563 564 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 561 def has_style?(style) comparison = interpret_style(style) (@swt_widget.style & comparison) == comparison end |
#pack_same_size ⇒ Object
283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 283 def pack_same_size 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 |
#post_add_content ⇒ Object
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.
188 189 190 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 188 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
181 182 183 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 181 def post_initialize_child(child) # No Op by default end |
#remove_observer(observer, property_name) ⇒ Object
589 590 591 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 589 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
687 688 689 690 691 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 687 def respond_to?(method, *args, &block) super || can_handle_observation_request?(method) || .respond_to?(method, *args, &block) end |
#set_attribute(attribute_name, *args) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# 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 = [attribute_name.to_s] apply_property_type_converters(normalized_attribute(attribute_name), args) if [:setter][:invoker].call(@swt_widget, args) elsif @swt_widget.respond_to?(attribute_setter(attribute_name)) @swt_widget.send(attribute_setter(attribute_name), *args) unless @swt_widget.send(attribute_getter(attribute_name)) == args.first elsif @swt_widget.respond_to?(ruby_attribute_setter(attribute_name)) @swt_widget.send(ruby_attribute_setter(attribute_name), args) else send(ruby_attribute_setter(attribute_name), args) end end |
#sync_exec(&block) ⇒ Object
553 554 555 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 553 def sync_exec(&block) DisplayProxy.instance.sync_exec(&block) end |
#timer_exec(delay_in_millis, &block) ⇒ Object
557 558 559 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 557 def timer_exec(delay_in_millis, &block) DisplayProxy.instance.timer_exec(delay_in_millis, &block) end |
#widget_property_listener_installers ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 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 |
# File 'lib/glimmer/swt/widget_proxy.rb', line 297 def @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| { |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::OrgEclipseSwtWidgets::Table => { :selection => lambda do |observer| { |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| { |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| { |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| { |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| { |selection_event| observer.call(@swt_widget.getSelection) } end }, Java::OrgEclipseSwtWidgets::MenuItem => { :selection => lambda do |observer| { |selection_event| observer.call(@swt_widget.getSelection) } end }, Java::OrgEclipseSwtWidgets::Spinner => { :selection => lambda do |observer| { |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| { |selection_event| observer.call(get_attribute(attribute)) } end ) end, } end |